2 //=============================================================================
6 * A client, which uses the AMI callback model and timeouts.
8 * @author Michael Kircher <Michael.Kircher@mchp.siemens.de>
10 //=============================================================================
13 #include "timeout_client.h"
15 #include "tao/debug.h"
17 #include "ace/Get_Opt.h"
19 const ACE_TCHAR
*ior
= ACE_TEXT("file://test.ior");
20 unsigned int msec
= 50;
23 parse_args (int argc
, ACE_TCHAR
*argv
[])
25 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("dk:t:"));
28 while ((c
= get_opts ()) != -1)
35 ior
= get_opts
.opt_arg ();
38 msec
= ACE_OS::atoi (get_opts
.opt_arg ());
42 ACE_ERROR_RETURN ((LM_ERROR
,
51 // Indicates successful parsing of the command line
56 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
61 CORBA::ORB_init (argc
, argv
);
63 if (parse_args (argc
, argv
) != 0)
66 CORBA::Object_var object
=
67 orb
->string_to_object (ior
);
69 TimeoutObj_var timeout_var
=
70 TimeoutObj::_narrow (object
.in ());
72 if (CORBA::is_nil (timeout_var
.in ()))
74 ACE_ERROR_RETURN ((LM_ERROR
,
75 "Object reference <%s> is nil.\n",
80 // Activate POA to handle the call back.
82 CORBA::Object_var poa_object
=
83 orb
->resolve_initial_references ("RootPOA");
85 if (CORBA::is_nil (poa_object
.in ()))
86 ACE_ERROR_RETURN ((LM_ERROR
,
87 " (%P|%t) Unable to initialize the POA.\n"),
90 PortableServer::POA_var root_poa
=
91 PortableServer::POA::_narrow (poa_object
.in ());
93 PortableServer::POAManager_var poa_manager
=
94 root_poa
->the_POAManager ();
96 poa_manager
->activate ();
98 // Instantiate reply handler
99 TimeoutHandler_i timeoutHandler_i
;
101 PortableServer::ObjectId_var id
=
102 root_poa
->activate_object (&timeoutHandler_i
);
104 CORBA::Object_var object_act
= root_poa
->id_to_reference (id
.in ());
106 AMI_TimeoutObjHandler_var timeoutHandler_var
=
107 AMI_TimeoutObjHandler::_narrow (object_act
.in ());
109 // Instantiate client
110 TimeoutClient
client (orb
.in (),
112 timeoutHandler_var
.in (),
119 orb
->run (); // Fetch responses
121 root_poa
->destroy (1, // ethernalize objects
122 0 // wait for completion
125 // Wait for all the threads to finish before destroying the
127 (void) client
.thr_mgr ()->wait ();
131 ACE_DEBUG ((LM_DEBUG
, "ORB finished\n"));
134 catch (const CORBA::Exception
& ex
)
136 ex
._tao_print_exception ("Caught exception:");