2 //=============================================================================
6 * This is the client for the UDP test.
8 * @author Michael Kircher <Michael.Kircher@mchp.siemens.de>
10 //=============================================================================
16 #include "UDP_Client_i.h"
18 #include "tao/debug.h"
20 #include "ace/Get_Opt.h"
23 // The following include file forces DIOP to be linked into the
24 // executable and initialized for static builds.
25 #include "tao/Strategies/advanced_resource.h"
27 const ACE_TCHAR
*ior
= ACE_TEXT("file://test.ior");
28 unsigned int msec
= 500;
29 unsigned int iterations
= 1;
32 parse_args (int argc
, ACE_TCHAR
*argv
[])
34 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("dk:t:i:"));
37 while ((c
= get_opts ()) != -1)
44 ior
= get_opts
.opt_arg ();
47 msec
= ACE_OS::atoi (get_opts
.opt_arg ());
50 iterations
= ACE_OS::atoi (get_opts
.opt_arg ());
54 ACE_ERROR_RETURN ((LM_ERROR
,
64 // Indicates successful parsing of the command line
69 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
74 CORBA::ORB_init (argc
, argv
);
76 if (parse_args (argc
, argv
) != 0)
79 CORBA::Object_var object
=
80 orb
->string_to_object (ior
);
83 UDP::_narrow (object
.in ());
85 if (CORBA::is_nil (udp_var
.in ()))
86 ACE_ERROR_RETURN ((LM_ERROR
,
87 "Object reference <%s> is nil.\n",
91 // Activate POA to handle the call back.
93 CORBA::Object_var poa_object
=
94 orb
->resolve_initial_references("RootPOA");
96 if (CORBA::is_nil (poa_object
.in ()))
97 ACE_ERROR_RETURN ((LM_ERROR
,
98 " (%P|%t) Unable to initialize the POA.\n"),
101 PortableServer::POA_var root_poa
=
102 PortableServer::POA::_narrow (poa_object
.in ());
104 PortableServer::POAManager_var poa_manager
=
105 root_poa
->the_POAManager ();
107 poa_manager
->activate ();
109 // Instantiate reply handler
110 UDP_i
udp_i (orb
.in ());
112 PortableServer::ObjectId_var id
=
113 root_poa
->activate_object (&udp_i
);
115 CORBA::Object_var object_act
= root_poa
->id_to_reference (id
.in ());
117 UDP_var udpHandler_var
=
118 UDP::_narrow (object_act
.in ());
120 // Instantiate client
121 UDP_Client_i
*client
= new UDP_Client_i (orb
.in (),
123 udpHandler_var
.in (),
127 // let the client run in a separate thread
130 // ORB loop, will be shut down by our client thread
134 ACE_DEBUG ((LM_DEBUG
, "event loop finished\n"));
136 root_poa
->destroy (true, // ethernalize objects
137 false); // wait for completion
142 // it is save to delete the client, because the client was actually
143 // the one calling orb->shutdown () triggering the end of the ORB
147 catch (const CORBA::Exception
& ex
)
149 ex
._tao_print_exception ("Caught exception:");