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
41 Task (ACE_Thread_Manager
&thread_manager
,
49 Task::Task (ACE_Thread_Manager
&thread_manager
,
51 : ACE_Task_Base (&thread_manager
),
52 orb_ (CORBA::ORB::_duplicate (orb
))
62 CORBA::Object_var object
=
63 this->orb_
->string_to_object (ior
);
66 Test::_narrow (object
.in ());
68 if (CORBA::is_nil (server
.in ()))
70 ACE_ERROR_RETURN ((LM_ERROR
,
71 "ERROR: Object reference <%s> is nil\n",
76 // Check that the object is configured with CLIENT_PROPAGATED
77 // PriorityModelPolicy.
78 CORBA::Policy_var policy
=
79 server
->_get_policy (RTCORBA::PRIORITY_MODEL_POLICY_TYPE
);
81 RTCORBA::PriorityModelPolicy_var priority_policy
=
82 RTCORBA::PriorityModelPolicy::_narrow (policy
.in ());
84 if (CORBA::is_nil (priority_policy
.in ()))
85 ACE_ERROR_RETURN ((LM_ERROR
,
86 "ERROR: Priority Model Policy not exposed!\n"),
89 RTCORBA::PriorityModel priority_model
=
90 priority_policy
->priority_model ();
92 if (priority_model
!= RTCORBA::CLIENT_PROPAGATED
)
93 ACE_ERROR_RETURN ((LM_ERROR
,
94 "ERROR: priority_model != "
95 "RTCORBA::CLIENT_PROPAGATED!\n"),
98 // Make several invocations, changing the priority of this thread
101 this->orb_
->resolve_initial_references ("RTCurrent");
103 RTCORBA::Current_var current
=
104 RTCORBA::Current::_narrow (object
.in ());
106 object
= this->orb_
->resolve_initial_references ("PriorityMappingManager");
108 RTCORBA::PriorityMappingManager_var mapping_manager
=
109 RTCORBA::PriorityMappingManager::_narrow (object
.in ());
111 RTCORBA::PriorityMapping
*pm
=
112 mapping_manager
->mapping ();
115 this->orb_
->orb_core ()->orb_params ()->ace_sched_policy ();
118 ACE_Sched_Params::priority_max (sched_policy
);
120 ACE_Sched_Params::priority_min (sched_policy
);
122 CORBA::Short native_priority
=
123 (max_priority
- min_priority
) / 2;
125 CORBA::Short desired_priority
= 0;
127 for (int i
= 0; i
< 3; ++i
)
129 if (pm
->to_CORBA (native_priority
, desired_priority
) == 0)
131 ACE_ERROR ((LM_ERROR
,
132 "ERROR: Cannot convert native priority %d to corba priority\n",
138 current
->the_priority (desired_priority
);
140 CORBA::Short priority
=
141 current
->the_priority ();
143 if (desired_priority
!= priority
)
145 ACE_ERROR ((LM_ERROR
,
146 "ERROR: No exception setting the priority but mismatch between requested and returned value from Current. "
147 "Set to %d but Current::the_priority returns %d\n", desired_priority
, priority
));
152 server
->test_method (priority
);
157 // Shut down Server ORB.
160 catch (const CORBA::DATA_CONVERSION
& ex
)
162 ex
._tao_print_exception (
163 "Most likely, this is due to the in-ability "
164 "to set the thread priority.");
167 catch (const CORBA::Exception
& ae
)
169 ae
._tao_print_exception (
170 "Caught exception:");
178 ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
183 // Register the interceptors to check for the RTCORBA
184 // service contexts in the reply messages.
185 PortableInterceptor::ORBInitializer_ptr temp_initializer
;
187 ACE_NEW_RETURN (temp_initializer
,
188 Client_ORBInitializer
,
189 -1); // No exceptions yet!
190 PortableInterceptor::ORBInitializer_var initializer
=
193 PortableInterceptor::register_orb_initializer (initializer
.in ());
195 // Initialize and obtain reference to the Test object.
197 CORBA::ORB_init (argc
, argv
);
199 if (parse_args (argc
, argv
) != 0)
202 // Make sure we can support multiple priorities that are required
204 if (!check_supported_priorities (orb
.in ()))
207 // Thread Manager for managing task.
208 ACE_Thread_Manager thread_manager
;
211 Task
task (thread_manager
,
214 // Task activation flags.
218 orb
->orb_core ()->orb_params ()->thread_creation_flags ();
222 task
.activate (flags
);
227 ACE_ERROR_RETURN ((LM_ERROR
,
228 "Cannot create thread with scheduling policy %s\n"
229 "because the user does not have the appropriate privileges, terminating program....\n"
230 "Check svc.conf options and/or run as root\n",
231 sched_policy_name (orb
->orb_core ()->orb_params ()->ace_sched_policy ())),
236 ACE_ERROR_RETURN ((LM_ERROR
,
237 "ERROR: Cannot create thread. errno = %d\n",
242 // Wait for task to exit.
244 thread_manager
.wait ();
246 catch (const CORBA::Exception
& ae
)
248 ae
._tao_print_exception (
249 "Caught exception:");