3 #include "tao/ORB_Core.h"
4 #include "Client_ORBInitializer.h"
5 #include "tao/ORBInitializer_Registry.h"
6 #include "tao/RTCORBA/RTCORBA.h"
7 #include "tao/RTCORBA/Priority_Mapping_Manager.h"
8 #include "ace/Get_Opt.h"
9 #include "../check_supported_priorities.cpp"
11 const ACE_TCHAR
*ior
= ACE_TEXT("file://test.ior");
14 parse_args (int argc
, ACE_TCHAR
*argv
[])
16 ACE_Get_Opt
get_opts (argc
, argv
, "k:");
19 while ((c
= get_opts ()) != -1)
23 ior
= get_opts
.opt_arg ();
27 ACE_ERROR_RETURN ((LM_ERROR
,
38 class Task
: public ACE_Task_Base
42 Task (ACE_Thread_Manager
&thread_manager
,
50 Task::Task (ACE_Thread_Manager
&thread_manager
,
52 : ACE_Task_Base (&thread_manager
),
53 orb_ (CORBA::ORB::_duplicate (orb
))
64 CORBA::Object_var object
=
65 this->orb_
->string_to_object (ior
);
68 Test::_narrow (object
.in ());
70 if (CORBA::is_nil (server
.in ()))
72 ACE_ERROR_RETURN ((LM_ERROR
,
73 "ERROR: Object reference <%s> is nil\n",
78 // Check that the object is configured with CLIENT_PROPAGATED
79 // PriorityModelPolicy.
80 CORBA::Policy_var policy
=
81 server
->_get_policy (RTCORBA::PRIORITY_MODEL_POLICY_TYPE
);
83 RTCORBA::PriorityModelPolicy_var priority_policy
=
84 RTCORBA::PriorityModelPolicy::_narrow (policy
.in ());
86 if (CORBA::is_nil (priority_policy
.in ()))
87 ACE_ERROR_RETURN ((LM_ERROR
,
88 "ERROR: Priority Model Policy not exposed!\n"),
91 RTCORBA::PriorityModel priority_model
=
92 priority_policy
->priority_model ();
94 if (priority_model
!= RTCORBA::CLIENT_PROPAGATED
)
95 ACE_ERROR_RETURN ((LM_ERROR
,
96 "ERROR: priority_model != "
97 "RTCORBA::CLIENT_PROPAGATED!\n"),
100 // Make several invocations, changing the priority of this thread
103 this->orb_
->resolve_initial_references ("RTCurrent");
105 RTCORBA::Current_var current
=
106 RTCORBA::Current::_narrow (object
.in ());
108 object
= this->orb_
->resolve_initial_references ("PriorityMappingManager");
110 RTCORBA::PriorityMappingManager_var mapping_manager
=
111 RTCORBA::PriorityMappingManager::_narrow (object
.in ());
113 RTCORBA::PriorityMapping
*pm
=
114 mapping_manager
->mapping ();
117 this->orb_
->orb_core ()->orb_params ()->ace_sched_policy ();
120 ACE_Sched_Params::priority_max (sched_policy
);
122 ACE_Sched_Params::priority_min (sched_policy
);
124 CORBA::Short native_priority
=
125 (max_priority
- min_priority
) / 2;
127 CORBA::Short desired_priority
= 0;
129 for (int i
= 0; i
< 3; ++i
)
131 if (pm
->to_CORBA (native_priority
, desired_priority
) == 0)
133 ACE_ERROR ((LM_ERROR
,
134 "ERROR: Cannot convert native priority %d to corba priority\n",
140 current
->the_priority (desired_priority
);
142 CORBA::Short priority
=
143 current
->the_priority ();
145 if (desired_priority
!= priority
)
147 ACE_ERROR ((LM_ERROR
,
148 "ERROR: No exception setting the priority but mismatch between requested and returned value from Current. "
149 "Set to %d but Current::the_priority returns %d\n", desired_priority
, priority
));
154 server
->test_method (priority
);
159 // Shut down Server ORB.
162 catch (const CORBA::DATA_CONVERSION
& ex
)
164 ex
._tao_print_exception (
165 "Most likely, this is due to the in-ability "
166 "to set the thread priority.");
169 catch (const CORBA::Exception
& ae
)
171 ae
._tao_print_exception (
172 "Caught exception:");
180 ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
185 // Register the interceptors to check for the RTCORBA
186 // service contexts in the reply messages.
187 PortableInterceptor::ORBInitializer_ptr temp_initializer
;
189 ACE_NEW_RETURN (temp_initializer
,
190 Client_ORBInitializer
,
191 -1); // No exceptions yet!
192 PortableInterceptor::ORBInitializer_var initializer
=
195 PortableInterceptor::register_orb_initializer (initializer
.in ());
197 // Initialize and obtain reference to the Test object.
199 CORBA::ORB_init (argc
, argv
);
201 if (parse_args (argc
, argv
) != 0)
204 // Make sure we can support multiple priorities that are required
206 if (!check_supported_priorities (orb
.in ()))
209 // Thread Manager for managing task.
210 ACE_Thread_Manager thread_manager
;
213 Task
task (thread_manager
,
216 // Task activation flags.
220 orb
->orb_core ()->orb_params ()->thread_creation_flags ();
224 task
.activate (flags
);
229 ACE_ERROR_RETURN ((LM_ERROR
,
230 "Cannot create thread with scheduling policy %s\n"
231 "because the user does not have the appropriate privileges, terminating program....\n"
232 "Check svc.conf options and/or run as root\n",
233 sched_policy_name (orb
->orb_core ()->orb_params ()->ace_sched_policy ())),
238 ACE_ERROR_RETURN ((LM_ERROR
,
239 "ERROR: Cannot create thread. errno = %d\n",
244 // Wait for task to exit.
246 thread_manager
.wait ();
248 catch (const CORBA::Exception
& ae
)
250 ae
._tao_print_exception (
251 "Caught exception:");