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
);
21 //FUZZ: disable check_for_lack_ACE_OS
23 //FUZZ: enable check_for_lack_ACE_OS
30 Test_i::Test_i (CORBA::ORB_ptr orb
)
31 : orb_ (CORBA::ORB::_duplicate (orb
))
36 Test_i::test_method (CORBA::Short priority
)
38 // Use RTCurrent to find out the CORBA priority of the current
41 CORBA::Object_var obj
=
42 this->orb_
->resolve_initial_references ("RTCurrent");
44 RTCORBA::Current_var current
=
45 RTCORBA::Current::_narrow (obj
.in ());
47 if (CORBA::is_nil (obj
.in ()))
48 throw CORBA::INTERNAL ();
50 CORBA::Short servant_thread_priority
=
51 current
->the_priority ();
53 // Print out the info.
54 if (servant_thread_priority
!= priority
)
56 "ERROR: servant thread priority is not equal "
57 "to method argument.\n"));
60 "Client priority: %d "
61 "Servant thread priority: %d\n",
62 priority
, servant_thread_priority
));
66 Test_i::shutdown (void)
68 this->orb_
->shutdown (0);
71 //*************************************************************************
73 const ACE_TCHAR
*ior_output_file
= ACE_TEXT("test.ior");
75 // Parse command-line arguments.
77 parse_args (int argc
, ACE_TCHAR
*argv
[])
79 ACE_Get_Opt
get_opts (argc
, argv
, ACE_TEXT("o:"));
82 while ((c
= get_opts ()) != -1)
86 ior_output_file
= get_opts
.opt_arg ();
91 ACE_ERROR_RETURN ((LM_ERROR
,
102 class Task
: public ACE_Task_Base
106 Task (ACE_Thread_Manager
&thread_manager
,
115 Task::Task (ACE_Thread_Manager
&thread_manager
,
117 : ACE_Task_Base (&thread_manager
),
118 orb_ (CORBA::ORB::_duplicate (orb
))
127 CORBA::Object_var object
=
128 this->orb_
->resolve_initial_references("RootPOA");
130 PortableServer::POA_var root_poa
=
131 PortableServer::POA::_narrow (object
.in ());
133 if (CORBA::is_nil (root_poa
.in ()))
134 ACE_ERROR_RETURN ((LM_ERROR
,
135 "ERROR: Panic <RootPOA> is nil\n"),
138 PortableServer::POAManager_var poa_manager
=
139 root_poa
->the_POAManager ();
141 object
= this->orb_
->resolve_initial_references ("RTORB");
142 RTCORBA::RTORB_var rt_orb
= RTCORBA::RTORB::_narrow (object
.in ());
145 this->orb_
->resolve_initial_references ("RTCurrent");
146 RTCORBA::Current_var current
=
147 RTCORBA::Current::_narrow (object
.in ());
149 // Create POA with CLIENT_PROPAGATED PriorityModelPolicy,
150 // and register Test object with it.
151 CORBA::PolicyList poa_policy_list
;
152 poa_policy_list
.length (1);
154 rt_orb
->create_priority_model_policy (RTCORBA::CLIENT_PROPAGATED
,
157 PortableServer::POA_var child_poa
=
158 root_poa
->create_POA ("Child_POA",
162 Test_i
server_impl (this->orb_
.in ());
164 PortableServer::ObjectId_var id
=
165 child_poa
->activate_object (&server_impl
);
167 CORBA::Object_var server
=
168 child_poa
->id_to_reference (id
.in ());
171 CORBA::String_var ior
=
172 this->orb_
->object_to_string (server
.in ());
174 ACE_DEBUG ((LM_DEBUG
, "Activated as <%s>\n\n", ior
.in ()));
176 if (ior_output_file
!= 0)
178 FILE *output_file
= ACE_OS::fopen (ior_output_file
, "w");
179 if (output_file
== 0)
180 ACE_ERROR_RETURN ((LM_ERROR
,
181 "Cannot open output file for writing IOR: %s",
184 ACE_OS::fprintf (output_file
, "%s", ior
.in ());
185 ACE_OS::fclose (output_file
);
188 // Get the initial priority of the current thread.
189 // Note that it is an error to access the priority via the current in a thread that it
190 // where it hasn't been set following the fix for tao681.
191 CORBA::Short initial_thread_priority
192 = get_implicit_thread_CORBA_priority (this->orb_
.in ());
193 current
->the_priority (initial_thread_priority
);
195 // Run ORB Event loop.
196 poa_manager
->activate ();
200 ACE_DEBUG ((LM_DEBUG
, "Server ORB event loop finished\n"));
202 // Get the final priority of the current thread.
203 CORBA::Short final_thread_priority
=
204 current
->the_priority ();
206 if (final_thread_priority
!= initial_thread_priority
)
207 ACE_DEBUG ((LM_DEBUG
,
208 "ERROR: Priority of the servant thread "
209 "has been permanently changed!\n"
210 "Initial priority: %d Final priority: %d\n",
211 initial_thread_priority
, final_thread_priority
));
213 ACE_DEBUG ((LM_DEBUG
,
214 "Final priority of the servant thread"
215 " = its initial priority\n"));
218 catch (const CORBA::Exception
& ex
)
220 ex
._tao_print_exception ("Exception caught:");
228 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 ())),
278 // Wait for task to exit.
280 thread_manager
.wait ();
281 ACE_ASSERT (result
!= -1);
283 catch (const CORBA::Exception
& ex
)
285 ex
._tao_print_exception ("Exception caught");