Merge pull request #2303 from jwillemsen/jwi-803
[ACE_TAO.git] / TAO / tests / DIOP / client.cpp
blob2a635b9ecc78692aa7edf24e727fd9593fc4a385
2 //=============================================================================
3 /**
4 * @file client.cpp
6 * This is the client for the UDP test.
8 * @author Michael Kircher <Michael.Kircher@mchp.siemens.de>
9 */
10 //=============================================================================
13 #include "UDPC.h"
15 #include "UDP_i.h"
16 #include "UDP_Client_i.h"
18 #include "tao/debug.h"
20 #include "ace/Get_Opt.h"
21 #include "ace/Task.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;
31 int
32 parse_args (int argc, ACE_TCHAR *argv[])
34 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("dk:t:i:"));
35 int c;
37 while ((c = get_opts ()) != -1)
38 switch (c)
40 case 'd':
41 ++TAO_debug_level;
42 break;
43 case 'k':
44 ior = get_opts.opt_arg ();
45 break;
46 case 't':
47 msec = ACE_OS::atoi (get_opts.opt_arg ());
48 break;
49 case 'i':
50 iterations = ACE_OS::atoi (get_opts.opt_arg ());
51 break;
52 case '?':
53 default:
54 ACE_ERROR_RETURN ((LM_ERROR,
55 "usage: %s "
56 "-d "
57 "-k <ior> "
58 "-t <timeout in ms> "
59 "-i <iterations> "
60 "\n",
61 argv [0]),
62 -1);
64 // Indicates successful parsing of the command line
65 return 0;
68 int
69 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
71 try
73 CORBA::ORB_var orb =
74 CORBA::ORB_init (argc, argv);
76 if (parse_args (argc, argv) != 0)
77 return 1;
79 CORBA::Object_var object =
80 orb->string_to_object (ior);
82 UDP_var udp_var =
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",
88 ior),
89 1);
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"),
99 1);
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 (),
122 udp_var.in (),
123 udpHandler_var.in (),
124 msec,
125 iterations);
127 // let the client run in a separate thread
128 client->activate ();
130 // ORB loop, will be shut down by our client thread
132 orb->run ();
134 ACE_DEBUG ((LM_DEBUG, "event loop finished\n"));
136 root_poa->destroy (true, // ethernalize objects
137 false); // wait for completion
139 orb->destroy ();
141 client->wait ();
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
144 // event loop.
145 delete client;
147 catch (const CORBA::Exception& ex)
149 ex._tao_print_exception ("Caught exception:");
150 return 1;
153 return 0;