3 #include "ace/Get_Opt.h"
5 #include "tao/Messaging/Messaging.h"
8 // The test is quiet...
10 static const ACE_TCHAR
*ior_file
= ACE_TEXT ("test.ior");
11 // File of file to which the ior is written
13 static int number_of_threads
= 1;
14 // Number of server threads.
16 class Server_Task
: public ACE_Task_Base
19 Server_Task (CORBA::ORB_ptr orb
);
26 Server_Task::Server_Task (CORBA::ORB_ptr orb
)
27 : orb_ (CORBA::ORB::_duplicate (orb
))
36 CORBA::Object_var object
=
37 this->orb_
->resolve_initial_references ("PolicyCurrent");
39 CORBA::PolicyCurrent_var policy_current
=
40 CORBA::PolicyCurrent::_narrow (object
.in ());
42 TimeBase::TimeT timeout_period
= 100 * 100000;
44 CORBA::Any timeout_as_any
;
45 timeout_as_any
<<= timeout_period
;
47 CORBA::PolicyList
policy_list (1);
48 policy_list
.length (1);
50 this->orb_
->create_policy (Messaging::RELATIVE_RT_TIMEOUT_POLICY_TYPE
,
53 policy_current
->set_policy_overrides (policy_list
,
56 policy_list
[0]->destroy();
60 catch (const CORBA::Exception
&)
68 write_ior_to_file (const char *ior
)
70 FILE *output_file
= ACE_OS::fopen (ior_file
, "w");
73 ACE_ERROR_RETURN ((LM_ERROR
, "Cannot open output files for writing IOR: %s\n",
79 result
= ACE_OS::fprintf (output_file
,
83 static_cast<size_t> (result
) != ACE_OS::strlen (ior
))
84 ACE_ERROR_RETURN ((LM_ERROR
,
85 "ACE_OS::fprintf failed while writing %C to %s\n",
90 ACE_OS::fclose (output_file
);
99 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("q:f:t:"));
102 while ((c
= get_opts ()) != -1)
110 number_of_threads
= ACE_OS::atoi (get_opts
.opt_arg ());
114 ior_file
= get_opts
.opt_arg ();
119 ACE_ERROR_RETURN ((LM_ERROR
,
121 " [-t number of threads]"
133 ACE_TMAIN (int argc
, ACE_TCHAR
**argv
)
139 CORBA::ORB_var orb
= CORBA::ORB_init (argc
, argv
);
141 result
= parse_args (argc
, argv
);
145 CORBA::Object_var object
= orb
->resolve_initial_references ("RootPOA");
147 PortableServer::POA_var root_poa
=
148 PortableServer::POA::_narrow (object
.in ());
150 PortableServer::POAManager_var poa_manager
=
151 root_poa
->the_POAManager ();
153 poa_manager
->activate ();
155 server_i
server_servant (quiet
,
158 PortableServer::ObjectId_var id
=
159 root_poa
->activate_object (&server_servant
);
161 CORBA::Object_var object_act
= root_poa
->id_to_reference (id
.in ());
163 server_var server_object
= server::_narrow (object_act
.in ());
165 CORBA::String_var ior
= orb
->object_to_string (server_object
.in ());
167 result
= write_ior_to_file (ior
.in ());
171 Server_Task
server_tasks (orb
.in ());
173 result
= server_tasks
.activate (THR_BOUND
,
179 result
= ACE_Thread_Manager::instance ()->wait ();
184 root_poa
->destroy (true, true);
186 if (!server_servant
.exception ())
191 catch (const CORBA::Exception
& ex
)
193 ex
._tao_print_exception ("server::main");