2 #include "ace/Get_Opt.h"
3 #include "ace/OS_NS_stdio.h"
6 #include "tao/ORBInitializer_Registry.h"
8 #include "Current_Test_Impl.h"
9 #include "Server_Request_Interceptor.h"
10 #include "Server_ORBInitializer.h"
12 const ACE_TCHAR
*ior_output_file
= ACE_TEXT ("server.ior");
14 int use_collocated_call
= 1;
17 parse_args (int argc
, ACE_TCHAR
*argv
[])
19 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("t:o:n:c:"));
22 while ((c
= get_opts ()) != -1)
26 use_collocated_call
= ACE_OS::atoi (get_opts
.opt_arg ());
29 ior_output_file
= get_opts
.opt_arg ();
32 nthreads
= ACE_OS::atoi (get_opts
.opt_arg ());
34 case 'n': // Does nothing. Added just for symetry with the client.
37 ACE_ERROR_RETURN ((LM_ERROR
,
41 "-n n (ignored, if provided) "
42 "-c make_collocated_calls "
48 // Indicates successful parsing of the command line
52 /// A helper class to encapsulate a task
53 class Worker
: public ACE_Task_Base
56 Worker (CORBA::ORB_ptr
);
57 virtual int svc (void);
66 Worker::Worker (CORBA::ORB_ptr orb
)
67 : orb_ (CORBA::ORB::_duplicate (orb
))
71 /// Test referencing the TC data *inside* the context of a client-side
80 catch (const CORBA::Exception
& ex
)
82 ex
._tao_print_exception ("Server: exception raised");
92 server_main (int argc
,
94 Test::Server_Request_Interceptor
*cri
)
97 #if TAO_HAS_TRANSPORT_CURRENT == 1
101 PortableInterceptor::ORBInitializer_ptr temp_initializer
= 0;
102 ACE_NEW_RETURN (temp_initializer
,
103 Test::Server_ORBInitializer (cri
),
104 -1); // No exceptions yet!
106 PortableInterceptor::ORBInitializer_var
orb_initializer (temp_initializer
);
108 PortableInterceptor::register_orb_initializer (orb_initializer
.in ());
111 CORBA::ORB_var orb
= CORBA::ORB_init (argc
,
115 CORBA::Object_var obj
=
116 orb
->resolve_initial_references ("RootPOA");
118 PortableServer::POA_var root_poa
=
119 PortableServer::POA::_narrow (obj
.in ());
121 if (CORBA::is_nil (root_poa
.in ()))
122 ACE_ERROR_RETURN ((LM_ERROR
,
123 ACE_TEXT ("Server (%P|%t) Unable to obtain")
124 ACE_TEXT (" RootPOA reference.\n")),
127 PortableServer::POAManager_var poa_manager
=
128 root_poa
->the_POAManager ();
130 poa_manager
->activate ();
132 if (parse_args (argc
, argv
) != 0)
135 Current_Test_Impl
server_impl (orb
.in (),
137 use_collocated_call
);
139 obj
= server_impl
._this ();
141 Test::Transport::CurrentTest_var server
=
142 Test::Transport::CurrentTest::_narrow (obj
.in ());
144 if (CORBA::is_nil (server
.in ()))
145 ACE_ERROR_RETURN ((LM_ERROR
,
146 ACE_TEXT ("Server (%P|%t) Unable to obtain ")
147 ACE_TEXT ("reference to CurrentTest object.\n")),
150 CORBA::String_var ior
=
151 orb
->object_to_string (server
.in ());
153 // If the ior_output_file exists, output the IOR to it.
154 if (ior_output_file
!= 0)
156 FILE *output_file
= ACE_OS::fopen (ior_output_file
, "w");
157 if (output_file
== 0)
158 ACE_ERROR_RETURN ((LM_ERROR
,
159 "Server (%P|%t) Cannot write file %s "
164 ACE_OS::fprintf (output_file
, "%s", ior
.in ());
165 ACE_OS::fclose (output_file
);
168 // Spawn a number of clients doing the same thing for a
169 // predetermined number of times
170 Worker
worker (orb
.in ());
172 #if defined (ACE_HAS_THREADS)
173 if (worker
.activate (THR_NEW_LWP
| THR_JOINABLE
,
175 ACE_ERROR_RETURN ((LM_ERROR
,
176 ACE_TEXT ("Server (%P|%t) Cannot activate %d threads\n"),
179 worker
.thr_mgr ()->wait ();
182 ACE_ERROR ((LM_WARNING
,
183 ACE_TEXT ("Server (%P|%t) Cannot use threads other than ")
184 ACE_TEXT ("the only one available.\n")));
188 if (TAO_debug_level
>= 1)
189 ACE_DEBUG ((LM_INFO
, ACE_TEXT ("Server (%P|%t) Event loop finished.\n")));
191 if (!cri
->self_test ())
192 ACE_ERROR ((LM_ERROR
,
193 ACE_TEXT ("Server (%P|%t) ERROR: Interceptor self_test failed\n")));
200 catch (const CORBA::Exception
& ex
)
202 ex
._tao_print_exception (ACE_TEXT ("Server (%P|%t) ERROR: "));
207 ACE_DEBUG ((LM_INFO
, ACE_TEXT ("Server (%P|%t) Completed successfuly.\n")));
209 #else /* TAO_HAS_TRANSPORT_CURRENT == 1 */
210 ACE_DEBUG ((LM_INFO
, ACE_TEXT ("Server (%P|%t) Need TAO_HAS_TRANSPORT_CURRENT enabled to run.\n")));
212 #endif /* TAO_HAS_TRANSPORT_CURRENT == 1 */