1 #include "ace/Sched_Params.h"
2 #include "ace/Get_Opt.h"
4 #include "AMH_Servant.h"
5 #include "Base_Server.h"
6 #include "tao/Strategies/advanced_resource.h"
10 #if !defined (__ACE_INLINE__)
11 # include "Base_Server.inl"
12 #endif /* __ACE_INLINE__ */
14 Base_Server::Base_Server (int &argc
, ACE_TCHAR
**argv
)
17 , ior_output_file_ (ACE_TEXT("test.ior"))
21 Base_Server::~Base_Server (void)
26 Base_Server::parse_args (void)
28 // *** To get correct behaviour, set ** POSIXLY_CORECT=1 ** on Linux
30 ACE_Get_Opt
get_opts (this->argc_
, this->argv_
, ACE_TEXT("o:"));
34 while ((c
= get_opts ()) != -1)
41 this->ior_output_file_
= get_opts
.opt_arg ();
43 // Remove the option '-o' from argv []
44 // to avoid any confusion that might result.
46 for (int i
= count_argv
; i
<= this->argc_
; ++i
)
47 this->argv_
[i
] = this->argv_
[i
+2];
50 // Decrement the value of this->argc_ to reflect the removal
52 this->argc_
= this->argc_
- 2;
67 Base_Server::try_RT_scheduling (void)
70 (ACE_Sched_Params::priority_min (ACE_SCHED_FIFO
)
71 + ACE_Sched_Params::priority_max (ACE_SCHED_FIFO
)) / 2;
72 priority
= ACE_Sched_Params::next_priority (ACE_SCHED_FIFO
,
75 // Enable FIFO scheduling, e.g., RT scheduling class on Solaris.
76 if (ACE_OS::sched_params (ACE_Sched_Params (ACE_SCHED_FIFO
,
78 ACE_SCOPE_PROCESS
)) != 0)
83 "server (%P|%t): user is not superuser, "
84 "test runs in time-shared class\n"));
88 "server (%P|%t): sched_params failed\n"));
93 Base_Server::shutdown_orb_and_poa (void)
97 this->root_poa_
->destroy (1, 1);
98 this->root_poa_
= PortableServer::POA::_nil ();
100 this->orb_
->destroy ();
101 this->orb_
= CORBA::ORB::_nil ();
103 catch (const CORBA::Exception
& ex
)
105 ex
._tao_print_exception ("Exception raised shutting down ORB or POA");
109 // If we have got to this point, everything has gone well. return
115 Base_Server::start_orb_and_poa (void)
119 this->orb_
= CORBA::ORB_init (this->argc_
, this->argv_
);
121 CORBA::Object_var poa_object
=
122 this->orb_
->resolve_initial_references("RootPOA");
124 if (CORBA::is_nil (poa_object
.in ()))
125 ACE_ERROR_RETURN ((LM_ERROR
,
126 " (%P|%t) Unable to initialize the POA.\n"),
129 this->root_poa_
= PortableServer::POA::_narrow (poa_object
.in ());
131 PortableServer::POAManager_var poa_manager
=
132 this->root_poa_
->the_POAManager ();
134 poa_manager
->activate ();
136 catch (const CORBA::Exception
& ex
)
138 ex
._tao_print_exception ("Exception raised initialising ORB or POA");
142 // If we have got to this point, everything has gone well. return
148 Base_Server::register_servant (AMH_Servant
*servant
)
152 Test::Roundtrip_var roundtrip
=
155 CORBA::String_var ior
=
156 this->orb_
->object_to_string (roundtrip
.in ());
158 (void) this->write_ior_to_file (ior
.in ());
160 catch (const CORBA::Exception
& ex
)
162 ex
._tao_print_exception ("Exception raised while registering servant");
168 Base_Server::run_event_loop (void)
172 ACE_Time_Value
period (0, 11000);
175 // @@ Mayur, where's the work_pending() call?
177 // Mayur: Nope. There is purposely no work_pending call. The
178 // reactor doesn't acknowledge expired timers as work. The
179 // reactor only thinks I/O events as work. Thus, timers
180 // that have expired after all the client requests are made
181 // are never handled. This results in the server not sending
182 // (some) replies to the client and the client just ends up
183 // waiting (forever) for them.
184 this->orb_
->perform_work (period
);
187 catch (const CORBA::Exception
& ex
)
189 ex
._tao_print_exception (
190 "Caught exceptionin Base_Server::run_event_loop");
195 Base_Server::write_ior_to_file (const char * ior
)
197 // If the ior_output_file exists, output the ior to it
199 ACE_OS::fopen (this->ior_output_file_
, "w");
201 if (output_file
== 0)
203 ACE_ERROR ((LM_ERROR
,
204 "Cannot open output file for writing IOR: %s",
205 this->ior_output_file_
));
209 ACE_OS::fprintf (output_file
, "%s", ior
);
210 ACE_OS::fclose (output_file
);