2 //=============================================================================
6 * A client, which uses the AMI callback model and timeouts.
8 * @author Michael Kircher <Michael.Kircher@mchp.siemens.de>
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;
22 parse_args (int argc
, ACE_TCHAR
*argv
[])
24 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("dk:t:"));
27 while ((c
= get_opts ()) != -1)
34 ior
= get_opts
.opt_arg ();
37 msec
= ACE_OS::atoi (get_opts
.opt_arg ());
41 ACE_ERROR_RETURN ((LM_ERROR
,
50 // Indicates successful parsing of the command line
55 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
60 CORBA::ORB_init (argc
, argv
);
62 if (parse_args (argc
, argv
) != 0)
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",
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"),
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 (),
111 timeoutHandler_var
.in (),
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
125 (void) client
.thr_mgr ()->wait ();
129 ACE_DEBUG ((LM_DEBUG
, "ORB finished\n"));
131 catch (const CORBA::Exception
& ex
)
133 ex
._tao_print_exception ("Caught exception:");