Revert "Use a variable on the stack to not have a temporary in the call"
[ACE_TAO.git] / TAO / tests / Bug_1361_Regression / client.cpp
blob9ece8d2188f21f3067dbf5ec40aaffe82873c38f
1 #include "Echo.h"
2 #include "ORB_Task.h"
3 #include "tao/ORB_Core.h"
4 #include "ace/Get_Opt.h"
5 #include "ace/Reactor.h"
6 #include "ace/OS_NS_signal.h"
8 const ACE_TCHAR *ior = ACE_TEXT("file://test.ior");
9 int serverthreads = 4;
11 int
12 parse_args (int argc, ACE_TCHAR *argv[]);
14 class Client_Timer : public ACE_Event_Handler
16 public:
17 /// Constructor
18 Client_Timer (ACE_Reactor * reactor)
19 : ACE_Event_Handler (reactor)
21 this->reference_counting_policy ().value (
22 ACE_Event_Handler::Reference_Counting_Policy::ENABLED);
25 void activate ()
27 ACE_Time_Value tv (150, 0);
28 this->reactor()->schedule_timer (this, 0, tv, tv);
31 /// Thread entry point
32 int handle_timeout (ACE_Time_Value const & , void const *)
34 this->reactor ()->cancel_timer (this);
35 // kill the application
36 ACE::terminate_process (ACE_OS::getpid ());
37 return 0;
41 int
42 ACE_TMAIN(int argc, ACE_TCHAR *argv[])
44 try
46 CORBA::ORB_var orb =
47 CORBA::ORB_init (argc, argv);
49 CORBA::Object_var poa_object =
50 orb->resolve_initial_references ("RootPOA");
52 PortableServer::POA_var root_poa =
53 PortableServer::POA::_narrow (poa_object.in ());
55 if (CORBA::is_nil (root_poa.in ()))
56 ACE_ERROR_RETURN ((LM_ERROR,
57 " (%P|%t) Panic: nil RootPOA\n"),
58 1);
60 PortableServer::POAManager_var poa_manager =
61 root_poa->the_POAManager ();
63 if (parse_args (argc, argv) != 0)
64 return 1;
66 PortableServer::ServantBase_var impl;
68 Echo * tmp = 0;
69 // ACE_NEW_RETURN is the worst possible way to handle
70 // exceptions (think: what if the constructor allocates memory
71 // and fails?), but I'm not in the mood to fight for a more
72 // reasonable way to handle allocation errors in ACE.
73 ACE_NEW_RETURN (tmp,
74 Echo(orb.in(), 1000 / serverthreads),
75 1);
76 impl = tmp;
79 PortableServer::ObjectId_var id =
80 root_poa->activate_object (impl.in ());
82 CORBA::Object_var object_act = root_poa->id_to_reference (id.in ());
84 Test::Echo_var echo =
85 Test::Echo::_narrow (object_act.in ());
87 CORBA::Object_var tmp =
88 orb->string_to_object(ior);
90 Test::Echo_Caller_var server =
91 Test::Echo_Caller::_narrow(tmp.in ());
93 if (CORBA::is_nil (server.in ()))
95 ACE_ERROR_RETURN ((LM_DEBUG,
96 "Nil Test::Echo_Caller reference <%s>\n",
97 ior),
98 1);
101 poa_manager->activate ();
103 ORB_Task worker (orb.in());
104 worker.activate (THR_NEW_LWP | THR_JOINABLE,
105 serverthreads);
109 for(int i = serverthreads; i; --i)
111 server->start_task(echo.in());
114 catch (...)
118 Client_Timer * task = new Client_Timer (orb->orb_core()->reactor());
119 task->activate ();
120 task->remove_reference ();
122 orb->run ();
124 worker.wait ();
126 ACE_DEBUG ((LM_DEBUG,
127 "(%P|%t) client - event loop finished\n"));
129 // Actually the code here should never be reached.
130 root_poa->destroy (true, true);
132 orb->destroy ();
134 catch (const CORBA::Exception& ex)
136 ex._tao_print_exception ("Exception caught:");
137 return 1;
140 return 0;
144 parse_args (int argc, ACE_TCHAR *argv[])
146 ACE_Get_Opt get_opts (argc, argv, ACE_TEXT("k:t:"));
147 int c;
149 while ((c = get_opts ()) != -1)
150 switch (c)
152 case 'k':
153 ior = get_opts.opt_arg ();
154 break;
155 case 't':
156 serverthreads = ACE_OS::atoi(get_opts.opt_arg ());
157 break;
159 case '?':
160 default:
161 ACE_ERROR_RETURN ((LM_ERROR,
162 "usage: %s "
163 "-k <ior> "
164 "-t threads "
165 "\n",
166 argv [0]),
167 -1);
169 // Indicates successful parsing of the command line
170 return 0;