Revert "Use a variable on the stack to not have a temporary in the call"
[ACE_TAO.git] / TAO / orbsvcs / tests / Bug_2377_Regression / uipmc_test.cpp
blobc76f9a61566787df8daef11af1e16cff721b1d6c
2 #include "ace/Task.h"
3 #include "ace/Mutex.h"
4 #include "Hello_Impl.h"
5 #include "orbsvcs/PortableGroup/GOA.h"
6 #include "ace/Get_Opt.h"
7 #include "ace/Manual_Event.h"
8 #include "tao/Policy_Manager.h"
10 #define CLIENT_SLEEP_TIME 1000 /* in microseconds */
11 #define CLIENT_THREAD_NUMBER 32
12 #define HELLO_CALL_NUMBER 100
14 const ACE_TCHAR *uipmc_url = 0;
15 const ACE_TCHAR *client_uipmc_url = 0;
17 void
18 test_sleep (int microsec)
20 ACE_Time_Value tv (microsec / 1000000, microsec % 1000000);
22 ACE_OS::sleep ((const ACE_Time_Value &) tv);
25 int
26 parse_args (int argc, ACE_TCHAR *argv[])
28 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("u:c:"));
29 const unsigned char full_success = 0x03;
30 unsigned char success = 0;
34 int c = get_opts ();
35 if (success == full_success && c == -1)
36 break;
38 if (c == -1)
39 ACE_ERROR_RETURN ((LM_ERROR,
40 "usage: %s"
41 " -u <url>"
42 " -c <client_url>"
43 "\n",
44 argv [0]),
45 -1);
47 switch (c)
49 case 'u':
50 uipmc_url = get_opts.opt_arg ();
51 success |= 0x01;
52 break;
53 case 'c':
54 client_uipmc_url = get_opts.opt_arg ();
55 success |= 0x02;
56 break;
59 while (true);
61 // Indicates successful parsing of the command line
62 return 0;
66 class ORBThread
67 : public ACE_Task_Base
69 public:
70 ORBThread (CORBA::ORB_ptr orb, ACE_Manual_Event& me, ACE_Thread_Manager *thr_mgr)
71 : ACE_Task_Base (thr_mgr)
72 , orb_ (CORBA::ORB::_duplicate (orb))
73 , me_ (me)
77 virtual int
78 svc ()
80 try
82 this->me_.signal ();
83 this->orb_->run ();
85 catch (const CORBA::Exception& ex)
87 ex._tao_print_exception ("Exception caught in ORBThread:");
88 return -1;
91 return 0;
94 private:
95 CORBA::ORB_var orb_;
96 ACE_Manual_Event& me_;
100 class ClientThread
101 : public ACE_Task_Base
103 public:
104 ClientThread (Test::Hello_ptr hello, MessageLog *log, int calls)
105 : hello_ (Test::Hello::_duplicate (hello))
106 , logger_ (log)
107 , call_count_ (calls)
108 , count_ (0)
112 virtual int
113 svc ()
117 while (true)
119 int c = 0;
121 ACE_GUARD_RETURN (ACE_Mutex, ace_mon, this->mutex_, 0);
122 c = this->count_++;
125 if (c >= this->call_count_)
126 break;
128 this->hello_->say_hello (c);
130 this->logger_->register_message_send (c);
132 test_sleep (CLIENT_SLEEP_TIME);
135 catch (const CORBA::Exception& ex)
137 ex._tao_print_exception ("Exception caught in ClientThread:");
138 return -1;
141 return 0;
144 private:
145 ACE_Mutex mutex_;
146 Test::Hello_var hello_;
147 MessageLog *logger_;
148 int call_count_;
149 int count_;
154 ACE_TMAIN (int argc, ACE_TCHAR *argv[])
156 MessageLog logger (HELLO_CALL_NUMBER);
160 CORBA::ORB_var orb =
161 CORBA::ORB_init (argc, argv);
163 CORBA::Object_var poa_object =
164 orb->resolve_initial_references("RootPOA");
166 PortableGroup::GOA_var root_poa =
167 PortableGroup::GOA::_narrow (poa_object.in ());
169 if (CORBA::is_nil (root_poa.in ()))
170 ACE_ERROR_RETURN ((LM_ERROR,
171 " (%P|%t) Panic: nil RootPOA\n"),
174 PortableServer::POAManager_var poa_manager =
175 root_poa->the_POAManager ();
177 Hello_Impl* hello_impl;
178 ACE_NEW_RETURN (hello_impl,
179 Hello_Impl (orb.in (), &logger),
181 PortableServer::ServantBase_var owner_transfer (hello_impl);
183 if (parse_args (argc, argv) != 0)
184 return 2;
186 // create UIPMC reference
187 CORBA::String_var multicast_url =
188 CORBA::string_dup (ACE_TEXT_ALWAYS_CHAR(uipmc_url));
189 CORBA::Object_var miop_ref =
190 orb->string_to_object (multicast_url.in ());
192 // create UIPMC reference for client access
193 CORBA::String_var client_multicast_url =
194 CORBA::string_dup (ACE_TEXT_ALWAYS_CHAR(client_uipmc_url));
195 CORBA::Object_var client_miop_ref =
196 orb->string_to_object (client_multicast_url.in ());
198 // create ids
199 PortableServer::ObjectId_var id =
200 root_poa->create_id_for_reference (miop_ref.in ());
201 PortableServer::ObjectId_var client_id =
202 root_poa->create_id_for_reference (client_miop_ref.in ());
204 // activate Hello Object
205 root_poa->activate_object_with_id (id.in (),
206 hello_impl);
208 // create Hello reference
209 Test::Hello_var hello =
210 Test::Hello::_unchecked_narrow (client_miop_ref.in ());
212 poa_manager->activate ();
215 // start orb thread
216 ACE_Manual_Event me;
217 ORBThread orb_thr (orb.in (), me, ACE_Thread_Manager::instance ());
218 orb_thr.activate (THR_NEW_LWP | THR_JOINABLE, 1, 1);
219 me.wait ();
221 // start clients
222 ClientThread cln_thr (hello.in (), &logger, HELLO_CALL_NUMBER);
223 cln_thr.activate (THR_NEW_LWP | THR_JOINABLE, CLIENT_THREAD_NUMBER);
224 cln_thr.wait ();
226 // shutdown the server, after 10 invocations of shutdown() we can be
227 // more or less sure that server actually received that call
228 for (int i = 0; i < 10; i++)
229 hello->shutdown ();
230 orb_thr.wait ();
233 if (logger.report_statistics () == HELLO_CALL_NUMBER)
234 ACE_ERROR_RETURN ((LM_ERROR,
235 "\n (%P|%t) No single call got through to the server\n"),
238 root_poa->destroy (true, true);
240 orb->destroy ();
242 catch (const CORBA::Exception& ex)
244 ex._tao_print_exception ("Exception caught in main ():");
245 return 4;
248 ACE_DEBUG ((LM_DEBUG,
249 "\n (%P|%t) uipmc_test is successful..\n"));
250 return 0;