Revert "Use a variable on the stack to not have a temporary in the call"
[ACE_TAO.git] / TAO / tests / AMI_Timeouts / client.cpp
blob401f345bb5a0cebc98de3fa81e822c30fa4bbb24
2 //=============================================================================
3 /**
4 * @file client.cpp
6 * A client, which uses the AMI callback model and timeouts.
8 * @author Michael Kircher <Michael.Kircher@mchp.siemens.de>
9 */
10 //=============================================================================
12 #include "timeout_client.h"
14 #include "tao/debug.h"
16 #include "ace/Get_Opt.h"
18 const ACE_TCHAR *ior = ACE_TEXT("file://test.ior");
19 unsigned int msec = 50;
21 int
22 parse_args (int argc, ACE_TCHAR *argv[])
24 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("dk:t:"));
25 int c;
27 while ((c = get_opts ()) != -1)
28 switch (c)
30 case 'd':
31 TAO_debug_level++;
32 break;
33 case 'k':
34 ior = get_opts.opt_arg ();
35 break;
36 case 't':
37 msec = ACE_OS::atoi (get_opts.opt_arg ());
38 break;
39 case '?':
40 default:
41 ACE_ERROR_RETURN ((LM_ERROR,
42 "usage: %s "
43 "-d "
44 "-k <ior> "
45 "-t <timeout in ms> "
46 "\n",
47 argv [0]),
48 -1);
50 // Indicates successful parsing of the command line
51 return 0;
54 int
55 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
57 try
59 CORBA::ORB_var orb =
60 CORBA::ORB_init (argc, argv);
62 if (parse_args (argc, argv) != 0)
63 return 1;
65 CORBA::Object_var object =
66 orb->string_to_object (ior);
68 TimeoutObj_var timeout_var =
69 TimeoutObj::_narrow (object.in ());
71 if (CORBA::is_nil (timeout_var.in ()))
73 ACE_ERROR_RETURN ((LM_ERROR,
74 "Object reference <%s> is nil.\n",
75 ior),
76 1);
79 // Activate POA to handle the call back.
81 CORBA::Object_var poa_object =
82 orb->resolve_initial_references ("RootPOA");
84 if (CORBA::is_nil (poa_object.in ()))
85 ACE_ERROR_RETURN ((LM_ERROR,
86 " (%P|%t) Unable to initialize the POA.\n"),
87 1);
89 PortableServer::POA_var root_poa =
90 PortableServer::POA::_narrow (poa_object.in ());
92 PortableServer::POAManager_var poa_manager =
93 root_poa->the_POAManager ();
95 poa_manager->activate ();
97 // Instantiate reply handler
98 TimeoutHandler_i timeoutHandler_i;
100 PortableServer::ObjectId_var id =
101 root_poa->activate_object (&timeoutHandler_i);
103 CORBA::Object_var object_act = root_poa->id_to_reference (id.in ());
105 AMI_TimeoutObjHandler_var timeoutHandler_var =
106 AMI_TimeoutObjHandler::_narrow (object_act.in ());
108 // Instantiate client
109 TimeoutClient client (orb.in (),
110 timeout_var.in (),
111 timeoutHandler_var.in (),
112 &timeoutHandler_i,
113 msec);
115 client.activate ();
117 // ORB loop.
118 orb->run (); // Fetch responses
120 root_poa->destroy (true, // ethernalize objects
121 false); // wait for completion
123 // Wait for all the threads to finish before destroying the
124 // ORB.
125 (void) client.thr_mgr ()->wait ();
127 orb->destroy ();
129 ACE_DEBUG ((LM_DEBUG, "ORB finished\n"));
131 catch (const CORBA::Exception& ex)
133 ex._tao_print_exception ("Caught exception:");
134 return 1;
137 return 0;