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
));
68 this->orb_
->shutdown (false);
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
105 Task (ACE_Thread_Manager
&thread_manager
,
113 Task::Task (ACE_Thread_Manager
&thread_manager
,
115 : ACE_Task_Base (&thread_manager
),
116 orb_ (CORBA::ORB::_duplicate (orb
))
125 CORBA::Object_var object
=
126 this->orb_
->resolve_initial_references("RootPOA");
128 PortableServer::POA_var root_poa
=
129 PortableServer::POA::_narrow (object
.in ());
131 if (CORBA::is_nil (root_poa
.in ()))
132 ACE_ERROR_RETURN ((LM_ERROR
,
133 "ERROR: Panic <RootPOA> is nil\n"),
136 PortableServer::POAManager_var poa_manager
=
137 root_poa
->the_POAManager ();
139 object
= this->orb_
->resolve_initial_references ("RTORB");
140 RTCORBA::RTORB_var rt_orb
= RTCORBA::RTORB::_narrow (object
.in ());
143 this->orb_
->resolve_initial_references ("RTCurrent");
144 RTCORBA::Current_var current
=
145 RTCORBA::Current::_narrow (object
.in ());
147 // Create POA with CLIENT_PROPAGATED PriorityModelPolicy,
148 // and register Test object with it.
149 CORBA::PolicyList poa_policy_list
;
150 poa_policy_list
.length (1);
152 rt_orb
->create_priority_model_policy (RTCORBA::CLIENT_PROPAGATED
,
155 PortableServer::POA_var child_poa
=
156 root_poa
->create_POA ("Child_POA",
160 Test_i
server_impl (this->orb_
.in ());
162 PortableServer::ObjectId_var id
=
163 child_poa
->activate_object (&server_impl
);
165 CORBA::Object_var server
=
166 child_poa
->id_to_reference (id
.in ());
169 CORBA::String_var ior
=
170 this->orb_
->object_to_string (server
.in ());
172 ACE_DEBUG ((LM_DEBUG
, "Activated as <%s>\n\n", ior
.in ()));
174 if (ior_output_file
!= 0)
176 FILE *output_file
= ACE_OS::fopen (ior_output_file
, "w");
177 if (output_file
== 0)
178 ACE_ERROR_RETURN ((LM_ERROR
,
179 "Cannot open output file for writing IOR: %s",
182 ACE_OS::fprintf (output_file
, "%s", ior
.in ());
183 ACE_OS::fclose (output_file
);
186 // Get the initial priority of the current thread.
187 // Note that it is an error to access the priority via the current in a thread that it
188 // where it hasn't been set following the fix for tao681.
189 CORBA::Short initial_thread_priority
190 = 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 ("Exception caught:");
225 ACE_TMAIN(int argc
, ACE_TCHAR
*argv
[])
229 // Standard initialization:
230 // parse arguments and get all the references (ORB,
231 // RootPOA, RTORB, RTCurrent, POAManager).
233 CORBA::ORB_init (argc
, argv
);
235 if (parse_args (argc
, argv
) != 0)
238 // Make sure we can support multiple priorities that are required
240 if (!check_supported_priorities (orb
.in ()))
243 // Thread Manager for managing task.
244 ACE_Thread_Manager thread_manager
;
247 Task
task (thread_manager
,
250 // Task activation flags.
254 orb
->orb_core ()->orb_params ()->thread_creation_flags ();
258 task
.activate (flags
);
263 ACE_ERROR_RETURN ((LM_ERROR
,
264 "Cannot create thread with scheduling policy %s\n"
265 "because the user does not have the appropriate privileges, terminating program....\n"
266 "Check svc.conf options and/or run as root\n",
267 sched_policy_name (orb
->orb_core ()->orb_params ()->ace_sched_policy ())),
275 // Wait for task to exit.
277 thread_manager
.wait ();
278 ACE_ASSERT (result
!= -1);
280 catch (const CORBA::Exception
& ex
)
282 ex
._tao_print_exception ("Exception caught");