Use =default for skeleton copy constructor
[ACE_TAO.git] / TAO / tests / Muxed_GIOP_Versions / client.cpp
blob4858f2709222f5b03fb64bac32e27e975a2371cc
1 #include "testC.h"
2 #include "tao/debug.h"
3 #include "ace/Get_Opt.h"
4 #include "ace/Task.h"
6 const ACE_TCHAR *ior = ACE_TEXT("file://test.ior");
7 const ACE_TCHAR *corbaloc_arg = ACE_TEXT("corbaloc:iiop:1.0@localhost:12000/ObjectName");
8 int nthreads = 5;
9 int niterations = 5;
10 int server_shutdown = 0;
12 int
13 parse_args (int argc, ACE_TCHAR *argv[])
15 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("l:k:n:i:x"));
16 int c;
18 while ((c = get_opts ()) != -1)
19 switch (c)
21 case 'k':
22 ior = get_opts.opt_arg ();
23 break;
24 case 'l':
25 corbaloc_arg = get_opts.opt_arg ();
26 break;
27 case 'n':
28 nthreads = ACE_OS::atoi (get_opts.opt_arg ());
29 break;
30 case 'i':
31 niterations = ACE_OS::atoi (get_opts.opt_arg ());
32 break;
33 case 'x':
34 server_shutdown = 1;
35 break;
36 case '?':
37 default:
38 ACE_ERROR_RETURN ((LM_ERROR,
39 "usage: %s "
40 "-k <ior> "
41 "-n <nthreads> "
42 "-i <niterations> "
43 "\n",
44 argv [0]),
45 -1);
47 // Indicates successful parsing of the command line
48 return 0;
51 class Client : public ACE_Task_Base
53 // = TITLE
54 // Run the client thread
56 // = DESCRIPTION
57 // Use the ACE_Task_Base class to run the client threads.
59 public:
60 Client (Simple_Server_ptr server, int niterations);
61 // ctor
63 virtual int svc ();
64 // The thread entry point.
66 private:
67 void validate_connection ();
68 // Validate the connection
70 private:
71 Simple_Server_var server_;
72 // The server.
74 int niterations_;
75 // The number of iterations on each client thread.
78 int
79 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
81 try
83 CORBA::ORB_var orb =
84 CORBA::ORB_init (argc, argv);
86 if (parse_args (argc, argv) != 0)
87 return 1;
89 CORBA::Object_var object =
90 orb->string_to_object (ior);
92 Simple_Server_var server =
93 Simple_Server::_narrow (object.in ());
95 if (CORBA::is_nil (server.in ()))
97 ACE_ERROR_RETURN ((LM_ERROR,
98 "Object reference <%s> is nil.\n",
99 ior),
103 Client client (server.in (), niterations);
104 if (client.activate (THR_NEW_LWP | THR_JOINABLE,
105 nthreads) != 0)
106 ACE_ERROR_RETURN ((LM_ERROR,
107 "Cannot activate client threads\n"),
110 // While those threads are busy sending 1.2 messages
111 // send some corba loc requests, don't really care if there is an
112 // object there to find
113 if (!server_shutdown)
115 ACE_DEBUG ((LM_DEBUG,
116 "starting string_to_object %s\n",
117 corbaloc_arg));
119 for (int c = 0; c < (niterations * 2); c++)
123 CORBA::Object_var probably_not_exist =
124 orb->string_to_object(corbaloc_arg);
127 if (CORBA::is_nil(probably_not_exist.in()))
129 ACE_DEBUG ((LM_DEBUG, "not found\n", corbaloc_arg));
131 else
133 Simple_Server_var newserver =
134 Simple_Server::_narrow (probably_not_exist.in ());
136 // should throw an exception
137 if (CORBA::is_nil(newserver.in()))
139 ACE_DEBUG ((LM_DEBUG, "not found it\n", corbaloc_arg));
141 else
143 ACE_DEBUG ((LM_DEBUG, "found it\n", corbaloc_arg));
147 catch (const CORBA::Exception&)
149 // ACE_DEBUG ((LM_DEBUG, "caught exception\n", corbaloc_arg));
153 ACE_DEBUG ((LM_DEBUG,
154 "(%P|%t) waiting for threads\n"));
156 client.thr_mgr ()->wait ();
158 ACE_DEBUG ((LM_DEBUG,
159 "(%P|%t) threads finished\n"));
161 if (server_shutdown)
163 server->shutdown ();
166 orb->destroy ();
168 catch (const CORBA::Exception& ex)
170 ex._tao_print_exception ("Caught exception:");
171 return 1;
174 return 0;
177 // ****************************************************************
179 Client::Client (Simple_Server_ptr server,
180 int niterations)
181 : server_ (Simple_Server::_duplicate (server)),
182 niterations_ (niterations)
186 void
187 Client::validate_connection ()
189 // Ping the object 100 times, ignoring all exceptions.
190 // It would be better to use validate_connection() but the test must
191 // run on minimum CORBA builds too!
192 for (int j = 0; j != 100; ++j)
196 this->server_->test_method (j);
198 catch (const CORBA::Exception&){}
203 Client::svc ()
207 this->validate_connection ();
209 for (int i = 0; i < this->niterations_; ++i)
211 this->server_->test_method (i);
213 if (TAO_debug_level > 0 && i % 100 == 0)
214 ACE_DEBUG ((LM_DEBUG, "(%P|%t) iteration = %d\n",
215 i));
218 catch (const CORBA::Exception& ex)
220 ex._tao_print_exception ("MT_Client: exception raised");
222 return 0;