2 #include "ace/Get_Opt.h"
4 #include "tao/ORB_Core.h"
5 #include "tao/RTCORBA/RTCORBA.h"
6 #include "tao/RTPortableServer/RTPortableServer.h"
7 #include "../check_supported_priorities.cpp"
9 class Test_i
: public POA_Test
12 // An implementation for the Test interface in test.idl
15 Test_i (CORBA::ORB_ptr orb
);
18 // = The Test methods.
19 void test_method (CORBA::Short priority
);
28 Test_i::Test_i (CORBA::ORB_ptr orb
)
29 : orb_ (CORBA::ORB::_duplicate (orb
))
34 Test_i::test_method (CORBA::Short priority
)
36 // Use RTCurrent to find out the CORBA priority of the current
39 CORBA::Object_var obj
=
40 this->orb_
->resolve_initial_references ("RTCurrent");
42 RTCORBA::Current_var current
=
43 RTCORBA::Current::_narrow (obj
.in ());
45 if (CORBA::is_nil (obj
.in ()))
46 throw CORBA::INTERNAL ();
48 CORBA::Short servant_thread_priority
=
49 current
->the_priority ();
51 // Print out the info.
52 if (servant_thread_priority
!= priority
)
54 "ERROR: servant thread priority is not equal "
55 "to method argument.\n"));
58 "Client priority: %d "
59 "Servant thread priority: %d\n",
60 priority
, servant_thread_priority
));
66 this->orb_
->shutdown (false);
69 //*************************************************************************
71 const ACE_TCHAR
*ior_output_file
= ACE_TEXT("test.ior");
73 // Parse command-line arguments.
75 parse_args (int argc
, ACE_TCHAR
*argv
[])
77 ACE_Get_Opt
get_opts (argc
, argv
, "o:");
80 while ((c
= get_opts ()) != -1)
84 ior_output_file
= get_opts
.opt_arg ();
89 ACE_ERROR_RETURN ((LM_ERROR
,
100 class Task
: public ACE_Task_Base
103 Task (ACE_Thread_Manager
&thread_manager
,
111 Task::Task (ACE_Thread_Manager
&thread_manager
,
113 : ACE_Task_Base (&thread_manager
),
114 orb_ (CORBA::ORB::_duplicate (orb
))
123 CORBA::Object_var object
=
124 this->orb_
->resolve_initial_references("RootPOA");
126 PortableServer::POA_var root_poa
=
127 PortableServer::POA::_narrow (object
.in ());
129 if (CORBA::is_nil (root_poa
.in ()))
130 ACE_ERROR_RETURN ((LM_ERROR
,
131 "ERROR: Panic <RootPOA> is nil\n"),
134 PortableServer::POAManager_var poa_manager
=
135 root_poa
->the_POAManager ();
137 object
= this->orb_
->resolve_initial_references ("RTORB");
139 RTCORBA::RTORB_var rt_orb
= RTCORBA::RTORB::_narrow (object
.in ());
143 this->orb_
->resolve_initial_references ("RTCurrent");
145 RTCORBA::Current_var current
=
146 RTCORBA::Current::_narrow (object
.in ());
148 // Create POA with CLIENT_PROPAGATED PriorityModelPolicy,
149 // and register Test object with it.
150 CORBA::PolicyList poa_policy_list
;
151 poa_policy_list
.length (1);
153 rt_orb
->create_priority_model_policy (RTCORBA::CLIENT_PROPAGATED
,
156 PortableServer::POA_var child_poa
=
157 root_poa
->create_POA ("Child_POA",
161 Test_i
server_impl (this->orb_
.in ());
163 PortableServer::ObjectId_var id
=
164 child_poa
->activate_object (&server_impl
);
166 CORBA::Object_var server
=
167 child_poa
->id_to_reference (id
.in ());
170 CORBA::String_var ior
=
171 this->orb_
->object_to_string (server
.in ());
173 ACE_DEBUG ((LM_DEBUG
, "Activated as <%s>\n\n", ior
.in ()));
175 if (ior_output_file
!= 0)
177 FILE *output_file
= ACE_OS::fopen (ior_output_file
, "w");
178 if (output_file
== 0)
179 ACE_ERROR_RETURN ((LM_ERROR
,
180 "Cannot open output file for writing IOR: %s",
183 ACE_OS::fprintf (output_file
, "%s", ior
.in ());
184 ACE_OS::fclose (output_file
);
187 // Get the initial priority of the current thread.
188 CORBA::Short initial_thread_priority
=
189 get_implicit_thread_CORBA_priority (this->orb_
.in ());
191 current
->the_priority (initial_thread_priority
);
193 // Run ORB Event loop.
194 poa_manager
->activate ();
198 ACE_DEBUG ((LM_DEBUG
, "Server ORB event loop finished\n"));
200 // Get the final priority of the current thread.
201 CORBA::Short final_thread_priority
=
202 current
->the_priority ();
204 if (final_thread_priority
!= initial_thread_priority
)
205 ACE_DEBUG ((LM_DEBUG
,
206 "ERROR: Priority of the servant thread "
207 "has been permanently changed!\n"
208 "Initial priority: %d Final priority: %d\n",
209 initial_thread_priority
, final_thread_priority
));
211 ACE_DEBUG ((LM_DEBUG
,
212 "Final priority of the servant thread"
213 " == its initial priority\n"));
215 catch (const ::CORBA::Exception
& ex
)
217 ex
._tao_print_exception(
218 "Exception caught:");
226 ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
232 // Standard initialization:
233 // parse arguments and get all the references (ORB,
234 // RootPOA, RTORB, RTCurrent, POAManager).
236 CORBA::ORB_init (argc
, argv
);
238 if (parse_args (argc
, argv
) != 0)
241 // Make sure we can support multiple priorities that are required
243 if (!check_supported_priorities (orb
.in ()))
246 // Thread Manager for managing task.
247 ACE_Thread_Manager thread_manager
;
250 Task
task (thread_manager
,
253 // Task activation flags.
257 orb
->orb_core ()->orb_params ()->thread_creation_flags ();
261 task
.activate (flags
);
266 ACE_ERROR_RETURN ((LM_ERROR
,
267 "Cannot create thread with scheduling policy %s\n"
268 "because the user does not have the appropriate privileges, terminating program....\n"
269 "Check svc.conf options and/or run as root\n",
270 sched_policy_name (orb
->orb_core ()->orb_params ()->ace_sched_policy ())),
275 ACE_ERROR_RETURN ((LM_ERROR
,
276 "ERROR: Cannot create thread. errno = %d\n",
281 // Wait for task to exit.
283 thread_manager
.wait ();
285 catch (const ::CORBA::Exception
& ex
)
287 ex
._tao_print_exception(
288 "Exception caught:");