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 (0);
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
104 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");
141 RTCORBA::RTORB_var rt_orb
= RTCORBA::RTORB::_narrow (object
.in ());
145 this->orb_
->resolve_initial_references ("RTCurrent");
147 RTCORBA::Current_var current
=
148 RTCORBA::Current::_narrow (object
.in ());
150 // Create POA with CLIENT_PROPAGATED PriorityModelPolicy,
151 // and register Test object with it.
152 CORBA::PolicyList poa_policy_list
;
153 poa_policy_list
.length (1);
155 rt_orb
->create_priority_model_policy (RTCORBA::CLIENT_PROPAGATED
,
158 PortableServer::POA_var child_poa
=
159 root_poa
->create_POA ("Child_POA",
163 Test_i
server_impl (this->orb_
.in ());
165 PortableServer::ObjectId_var id
=
166 child_poa
->activate_object (&server_impl
);
168 CORBA::Object_var server
=
169 child_poa
->id_to_reference (id
.in ());
172 CORBA::String_var ior
=
173 this->orb_
->object_to_string (server
.in ());
175 ACE_DEBUG ((LM_DEBUG
, "Activated as <%s>\n\n", ior
.in ()));
177 if (ior_output_file
!= 0)
179 FILE *output_file
= ACE_OS::fopen (ior_output_file
, "w");
180 if (output_file
== 0)
181 ACE_ERROR_RETURN ((LM_ERROR
,
182 "Cannot open output file for writing IOR: %s",
185 ACE_OS::fprintf (output_file
, "%s", ior
.in ());
186 ACE_OS::fclose (output_file
);
189 // Get the initial priority of the current thread.
190 CORBA::Short initial_thread_priority
=
191 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(
221 "Exception caught:");
229 ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
235 // Standard initialization:
236 // parse arguments and get all the references (ORB,
237 // RootPOA, RTORB, RTCurrent, POAManager).
239 CORBA::ORB_init (argc
, argv
);
241 if (parse_args (argc
, argv
) != 0)
244 // Make sure we can support multiple priorities that are required
246 if (!check_supported_priorities (orb
.in ()))
249 // Thread Manager for managing task.
250 ACE_Thread_Manager thread_manager
;
253 Task
task (thread_manager
,
256 // Task activation flags.
260 orb
->orb_core ()->orb_params ()->thread_creation_flags ();
264 task
.activate (flags
);
269 ACE_ERROR_RETURN ((LM_ERROR
,
270 "Cannot create thread with scheduling policy %s\n"
271 "because the user does not have the appropriate privileges, terminating program....\n"
272 "Check svc.conf options and/or run as root\n",
273 sched_policy_name (orb
->orb_core ()->orb_params ()->ace_sched_policy ())),
278 ACE_ERROR_RETURN ((LM_ERROR
,
279 "ERROR: Cannot create thread. errno = %d\n",
284 // Wait for task to exit.
286 thread_manager
.wait ();
288 catch (const ::CORBA::Exception
& ex
)
290 ex
._tao_print_exception(
291 "Exception caught:");