Merge pull request #2316 from jwillemsen/jwi-taskcommenttypo
[ACE_TAO.git] / TAO / examples / PluggableUDP / tests / Performance / client.cpp
blob6bd848410e21c9374404eef827bf90c71b5f0b8c
2 //=============================================================================
3 /**
4 * @file client.cpp
6 * This is the client for the UDP performance test.
8 * @author Michael Kircher <Michael.Kircher@mchp.siemens.de>
9 */
10 //=============================================================================
13 #include "ace/Get_Opt.h"
14 #include "ace/Task.h"
16 #include "UDPC.h"
18 #include "UDP_i.h"
19 #include "UDP_PerformanceClient.h"
21 // The following include file forces DIOP to be linked into the
22 // executable and initialized for static builds.
23 #include "tao/Strategies/advanced_resource.h"
26 const ACE_TCHAR *ior = ACE_TEXT("file://test.ior");
27 ACE_UINT32 burst_messages = 1000;
29 unsigned char performance_test = 0;
31 int
32 parse_args (int argc, ACE_TCHAR *argv[])
34 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("k:t:"));
35 int c;
37 while ((c = get_opts ()) != -1)
38 switch (c)
40 case 'k':
41 ior = get_opts.opt_arg ();
42 break;
43 case 't':
44 burst_messages = ACE_OS::atoi (get_opts.opt_arg ());
45 break;
46 case '?':
47 default:
48 ACE_ERROR_RETURN ((LM_ERROR,
49 "usage: %s "
50 "-k <ior> "
51 "-t <burst_messages> "
52 "\n",
53 argv [0]),
54 -1);
56 // Indicates successful parsing of the command line
57 return 0;
60 int
61 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
63 try
65 CORBA::ORB_var orb =
66 CORBA::ORB_init (argc, argv, "PerformanceClient");
68 if (parse_args (argc, argv) != 0)
69 return 1;
71 CORBA::Object_var object =
72 orb->string_to_object (ior);
74 UDP_var udp_var =
75 UDP::_narrow (object.in ());
77 if (CORBA::is_nil (udp_var.in ()))
79 ACE_ERROR_RETURN ((LM_ERROR,
80 "Object reference <%s> is nil.\n",
81 ior),
82 1);
85 // Activate POA to handle the call back.
86 CORBA::Object_var poa_object =
87 orb->resolve_initial_references("RootPOA");
89 if (CORBA::is_nil (poa_object.in ()))
90 ACE_ERROR_RETURN ((LM_ERROR,
91 " (%P|%t) Unable to initialize the POA.\n"),
92 1);
94 PortableServer::POA_var root_poa =
95 PortableServer::POA::_narrow (poa_object.in ());
97 PortableServer::POAManager_var poa_manager =
98 root_poa->the_POAManager ();
100 poa_manager->activate ();
102 // Instantiate reply handler
103 UDP_i udp_i;
105 // let it remember our ORB
106 udp_i.orb (orb.in ());
108 UDP_var udpHandler_var =
109 udp_i._this ();
111 // Instantiate client
112 ACE_Task_Base* client = new UDP_PerformanceClient (orb.in (),
113 udp_var.in (),
114 &udp_i,
115 burst_messages);
117 // let the client run in a separate thread
118 client->activate ();
120 // ORB loop, will be shut down by our client thread
121 orb->run (); // Fetch responses
123 ACE_DEBUG ((LM_DEBUG, "ORB finished\n"));
125 client->wait ();
127 root_poa->destroy (true, // ethernalize objects
128 false); // wait for completion
130 orb->destroy ();
132 // it is save to delete the client, because the client was actually
133 // the one calling orb->shutdown () triggering the end of the ORB
134 // event loop.
135 delete client;
137 catch (const CORBA::Exception& ex)
139 ex._tao_print_exception ("Caught exception:");
140 return 1;
143 return 0;