1 #include "FP_Scheduler.h"
2 #include "Kokyu_qosC.h"
4 #include "tao/ORB_Constants.h"
5 #include "tao/CodecFactory/CodecFactory.h"
6 #include "tao/RTScheduling/Request_Interceptor.h"
8 FP_Segment_Sched_Param_Policy::FP_Segment_Sched_Param_Policy ()
12 FP_Segment_Sched_Param_Policy::FP_Segment_Sched_Param_Policy (
13 const FP_Segment_Sched_Param_Policy
&rhs
)
16 FP_Scheduling::SegmentSchedulingParameterPolicy (),
17 CORBA::LocalObject (),
22 FP_Scheduling::SegmentSchedulingParameter
23 FP_Segment_Sched_Param_Policy::value (void)
29 FP_Segment_Sched_Param_Policy::value (
30 const FP_Scheduling::SegmentSchedulingParameter
& value
)
36 FP_Segment_Sched_Param_Policy::copy (void)
38 FP_Segment_Sched_Param_Policy
* tmp
= 0;
39 ACE_NEW_THROW_EX (tmp
, FP_Segment_Sched_Param_Policy (*this),
40 CORBA::NO_MEMORY (TAO::VMCID
,
41 CORBA::COMPLETED_NO
));
47 FP_Segment_Sched_Param_Policy::policy_type (void)
53 FP_Segment_Sched_Param_Policy::destroy (void)
57 Fixed_Priority_Scheduler::Fixed_Priority_Scheduler (
59 Kokyu::DSRT_Dispatcher_Impl_t disp_impl_type
,
62 : orb_ (CORBA::ORB::_duplicate (orb
)),
63 disp_impl_type_ (disp_impl_type
),
64 ace_sched_policy_ (ace_sched_policy
),
65 ace_sched_scope_ (ace_sched_scope
)
68 Kokyu::DSRT_ConfigInfo config
;
70 config
.impl_type_
= this->disp_impl_type_
;
71 config
.sched_policy_
= ace_sched_policy_
;
72 config
.sched_scope_
= ace_sched_scope_
;
74 Kokyu::DSRT_Dispatcher_Factory
<FP_Scheduler_Traits
>::DSRT_Dispatcher_Auto_Ptr
75 tmp( Kokyu::DSRT_Dispatcher_Factory
<FP_Scheduler_Traits
>::
76 create_DSRT_dispatcher (config
) );
77 kokyu_dispatcher_
= tmp
;
79 CORBA::Object_var object
=
80 orb
->resolve_initial_references ("RTScheduler_Current");
83 RTScheduling::Current::_narrow (object
.in ());
85 IOP::CodecFactory_var codec_factory
;
86 CORBA::Object_var obj
=
87 orb
->resolve_initial_references ("CodecFactory");
89 if (CORBA::is_nil(obj
.in ()))
91 ACE_ERROR ((LM_ERROR
, "Nil Codec factory\n"));
95 codec_factory
= IOP::CodecFactory::_narrow (obj
.in ());
98 IOP::Encoding encoding
;
99 encoding
.format
= IOP::ENCODING_CDR_ENCAPS
;
100 encoding
.major_version
= 1;
101 encoding
.minor_version
= 2;
103 codec_
= codec_factory
->create_codec (encoding
);
106 Fixed_Priority_Scheduler::~Fixed_Priority_Scheduler (void)
108 // delete kokyu_dispatcher_;
112 Fixed_Priority_Scheduler::shutdown (void)
114 kokyu_dispatcher_
->shutdown ();
115 ACE_DEBUG ((LM_DEBUG
, "kokyu DSRT dispatcher shutdown\n"));
118 FP_Scheduling::SegmentSchedulingParameterPolicy_ptr
119 Fixed_Priority_Scheduler::create_segment_scheduling_parameter (
120 const FP_Scheduling::SegmentSchedulingParameter
& value
123 FP_Scheduling::SegmentSchedulingParameterPolicy_ptr
124 segment_sched_param_policy
;
125 ACE_NEW_THROW_EX (segment_sched_param_policy
,
126 FP_Segment_Sched_Param_Policy
,
128 CORBA::SystemException::_tao_minor_code (
131 CORBA::COMPLETED_NO
));
133 segment_sched_param_policy
->value (value
);
135 return segment_sched_param_policy
;
140 Fixed_Priority_Scheduler::begin_new_scheduling_segment (const RTScheduling::Current::IdType
& guid
,
142 CORBA::Policy_ptr sched_policy
,
145 #ifdef KOKYU_DSRT_LOGGING
146 ACE_DEBUG ((LM_DEBUG
,
147 "(%t|%T):FP_Scheduler::begin_new_scheduling_segment enter\n"));
150 #ifdef KOKYU_DSRT_LOGGING
152 ACE_OS::memcpy (&int_guid
,
155 ACE_DEBUG ((LM_DEBUG
, "(%t|%T): guid is %d\n", int_guid
));
158 FP_Scheduler_Traits::QoSDescriptor_t qos
;
159 FP_Scheduling::SegmentSchedulingParameterPolicy_var sched_param_policy
=
160 FP_Scheduling::SegmentSchedulingParameterPolicy::_narrow (sched_policy
);
162 FP_Scheduling::SegmentSchedulingParameter sched_param
= sched_param_policy
->value ();
163 RTCORBA::Priority desired_priority
= sched_param
.base_priority
;
164 qos
.priority_
= desired_priority
;
165 kokyu_dispatcher_
->schedule (guid
, qos
);
167 #ifdef KOKYU_DSRT_LOGGING
168 ACE_DEBUG ((LM_DEBUG
,
169 "(%t|%T):FP_Scheduler::begin_new_scheduling_segment exit\n"));
174 Fixed_Priority_Scheduler::begin_nested_scheduling_segment (const RTScheduling::Current::IdType
&guid
,
176 CORBA::Policy_ptr sched_param
,
177 CORBA::Policy_ptr implicit_sched_param
)
179 this->begin_new_scheduling_segment (guid
,
182 implicit_sched_param
);
186 Fixed_Priority_Scheduler::update_scheduling_segment (const RTScheduling::Current::IdType
&guid
,
188 CORBA::Policy_ptr sched_policy
,
189 CORBA::Policy_ptr implicit_sched_param
)
191 ACE_UNUSED_ARG ((name
));
192 ACE_UNUSED_ARG ((implicit_sched_param
));
194 #ifdef KOKYU_DSRT_LOGGING
196 ACE_OS::memcpy (&int_guid
,
199 ACE_DEBUG ((LM_DEBUG
, "(%t|%T): update_sched_seg::guid is %d\n", int_guid
));
202 FP_Scheduling::SegmentSchedulingParameterPolicy_var sched_param_policy
=
203 FP_Scheduling::SegmentSchedulingParameterPolicy::_narrow (sched_policy
);
205 FP_Scheduling::SegmentSchedulingParameter sched_param
=
206 sched_param_policy
->value ();
208 RTCORBA::Priority desired_priority
= sched_param
.base_priority
;
210 FP_Scheduler_Traits::QoSDescriptor_t qos
;
211 qos
.priority_
= desired_priority
;
213 kokyu_dispatcher_
->update_schedule (guid
, qos
);
217 Fixed_Priority_Scheduler::end_scheduling_segment (const RTScheduling::Current::IdType
&guid
,
220 #ifdef KOKYU_DSRT_LOGGING
222 ACE_OS::memcpy (&int_guid
,
225 ACE_DEBUG ((LM_DEBUG
, "(%t|%T) call to end_sched_segment for guid %d\n", int_guid
));
228 kokyu_dispatcher_
->cancel_schedule (guid
);
232 Fixed_Priority_Scheduler::end_nested_scheduling_segment (const RTScheduling::Current::IdType
&,
241 Fixed_Priority_Scheduler::send_request (PortableInterceptor::ClientRequestInfo_ptr ri
)
243 Kokyu::Svc_Ctxt_DSRT_QoS sc_qos
;
245 CORBA::String_var operation
= ri
->operation ();
247 #ifdef KOKYU_DSRT_LOGGING
248 ACE_DEBUG ((LM_DEBUG
,
249 "(%t|%T): send_request "
253 // Make the context to send the context to the target
254 IOP::ServiceContext sc
;
255 sc
.context_id
= Client_Interceptor::SchedulingInfo
;
257 CORBA::Policy_var sched_policy
=
258 this->current_
->scheduling_parameter();
260 RTScheduling::Current::IdType_var guid
= this->current_
->id ();
262 ACE_OS::memcpy (&guid,
266 RTCORBA::Priority desired_priority
;
267 if (CORBA::is_nil (sched_policy
.in ()))
269 desired_priority
= 0;
273 FP_Scheduling::SegmentSchedulingParameterPolicy_var sched_param_policy
=
274 FP_Scheduling::SegmentSchedulingParameterPolicy::_narrow (sched_policy
.in ());
276 FP_Scheduling::SegmentSchedulingParameter sched_param
=
277 sched_param_policy
->value ();
279 desired_priority
= sched_param
.base_priority
;
281 #ifdef KOKYU_DSRT_LOGGING
283 ACE_OS::memcpy (&int_guid
,
286 ACE_DEBUG ((LM_DEBUG
,
287 ACE_TEXT ("(%t): send_request desired_priority from current = %d, guid = %d\n"),
288 desired_priority
, int_guid
));
291 //Fill the guid in the SC Qos struct
292 sc_qos
.guid
.length (guid
->length ());
293 guid_copy (sc_qos
.guid
, guid
.in ());
294 sc_qos
.desired_priority
= desired_priority
;
295 CORBA::Any sc_qos_as_any
;
296 sc_qos_as_any
<<= sc_qos
;
298 CORBA::OctetSeq_var cdtmp
= codec_
->encode (sc_qos_as_any
);
299 sc
.context_data
= cdtmp
.in ();
301 #ifdef KOKYU_DSRT_LOGGING
302 ACE_DEBUG ((LM_DEBUG
,
303 ACE_TEXT ("(%t|%T): send_request : about to add sched SC\n")));
306 // Add this context to the service context list.
307 ri
->add_request_service_context (sc
, 0);
311 #ifdef KOKYU_DSRT_LOGGING
312 ACE_DEBUG ((LM_DEBUG
,
313 ACE_TEXT ("(%t|%T): send_request : ")
314 ACE_TEXT ("about to call scheduler to inform block\n")));
317 kokyu_dispatcher_
->update_schedule (guid
.in (),
320 #ifdef KOKYU_DSRT_LOGGING
321 ACE_DEBUG ((LM_DEBUG
,
322 ACE_TEXT ("(%t|%T): send_request interceptor done\n")));
327 Fixed_Priority_Scheduler::receive_request (PortableInterceptor::ServerRequestInfo_ptr ri
,
328 RTScheduling::Current::IdType_out guid_out
,
329 CORBA::String_out
/*name*/,
330 CORBA::Policy_out sched_param_out
,
331 CORBA::Policy_out
/*implicit_sched_param_out*/)
333 const Kokyu::Svc_Ctxt_DSRT_QoS
* sc_qos_ptr
= 0;
335 #ifdef KOKYU_DSRT_LOGGING
336 ACE_DEBUG ((LM_DEBUG
, "(%t|%T):entered FP_Scheduler::receive_request\n"));
339 RTScheduling::Current::IdType guid
;
341 CORBA::String_var operation
= ri
->operation ();
343 #ifdef KOKYU_DSRT_LOGGING
344 ACE_DEBUG ((LM_DEBUG
,
345 "(%t|%T): receive_request from "
350 // Ignore the "_is_a" operation since it may have been invoked
351 // locally on the server side as a side effect of another call,
352 // meaning that the client hasn't added the service context yet.
353 if (ACE_OS::strcmp ("_is_a", operation
.in ()) == 0)
356 IOP::ServiceContext_var sc
=
357 ri
->get_request_service_context (Server_Interceptor::SchedulingInfo
);
359 RTCORBA::Priority desired_priority
;
363 desired_priority
= 0;
367 CORBA::OctetSeq oc_seq
= CORBA::OctetSeq (sc
->context_data
.length (),
368 sc
->context_data
.length (),
369 sc
->context_data
.get_buffer (),
371 CORBA::Any sc_qos_as_any
;
372 CORBA::Any_var scqostmp
= codec_
->decode (oc_seq
);
373 sc_qos_as_any
= scqostmp
.in ();
374 //Don't store in a _var, since >>= returns a pointer to an
375 //internal buffer and we are not supposed to free it.
376 sc_qos_as_any
>>= sc_qos_ptr
;
378 desired_priority
= sc_qos_ptr
->desired_priority
;
379 guid
.length (sc_qos_ptr
->guid
.length ());
380 guid_copy (guid
, sc_qos_ptr
->guid
);
382 ACE_NEW (guid_out
.ptr (),
383 RTScheduling::Current::IdType
);
384 guid_out
.ptr ()->length (guid
.length ());
385 *(guid_out
.ptr ()) = guid
;
387 #ifdef KOKYU_DSRT_LOGGING
389 ACE_OS::memcpy (&int_guid
,
392 ACE_DEBUG ((LM_DEBUG
,
393 "(%t|%T): Desired_Priority = %d, guid = %d in recvd service context\n",
398 FP_Scheduling::SegmentSchedulingParameter sched_param
;
399 sched_param
.base_priority
= desired_priority
;
400 sched_param_out
= this->create_segment_scheduling_parameter (sched_param
);
403 FP_Scheduler_Traits::QoSDescriptor_t qos
;
404 qos
.priority_
= desired_priority
;
405 this->kokyu_dispatcher_
->schedule (guid
, qos
);
407 #ifdef KOKYU_DSRT_LOGGING
408 ACE_DEBUG ((LM_DEBUG
, "(%t|%T): receive_request interceptor done\n"));
414 Fixed_Priority_Scheduler::send_poll (PortableInterceptor::ClientRequestInfo_ptr
)
419 Fixed_Priority_Scheduler::send_reply (PortableInterceptor::ServerRequestInfo_ptr ri
)
421 RTCORBA::Priority desired_priority
= 0;
422 Kokyu::Svc_Ctxt_DSRT_QoS sc_qos
;
424 CORBA::String_var operation
= ri
->operation ();
426 #ifdef KOKYU_DSRT_LOGGING
427 ACE_DEBUG ((LM_DEBUG
,
428 "(%t|%T): send_reply from \"%s\"\n",
432 // Make the context to send the context to the target
433 IOP::ServiceContext sc
;
434 sc
.context_id
= Server_Interceptor::SchedulingInfo
;
436 ACE_DEBUG ((LM_DEBUG
, "in send_reply: before accessing current_->sched_param\n"));
437 CORBA::Policy_var sched_policy
=
438 this->current_
->scheduling_parameter();
440 RTScheduling::Current::IdType_var guid
= this->current_
->id ();
442 if (CORBA::is_nil (sched_policy
.in ()))
444 ACE_DEBUG ((LM_DEBUG
, "sched_policy nil. desired_priority not set in sched params\n"));
445 desired_priority
= 0;
449 ACE_DEBUG ((LM_DEBUG
, "sched_policy not nil. desired_priority set in sched params\n"));
451 FP_Scheduling::SegmentSchedulingParameterPolicy_var sched_param_policy
=
452 FP_Scheduling::SegmentSchedulingParameterPolicy::_narrow (sched_policy
.in ());
454 FP_Scheduling::SegmentSchedulingParameter sched_param
=
455 sched_param_policy
->value ();
457 desired_priority
= sched_param
.base_priority
;
459 //Fill the guid in the SC Qos struct
460 sc_qos
.guid
.length (guid
->length ());
461 guid_copy (sc_qos
.guid
, guid
.in ());
462 sc_qos
.desired_priority
= desired_priority
;
463 CORBA::Any sc_qos_as_any
;
464 sc_qos_as_any
<<= sc_qos
;
466 CORBA::OctetSeq_var cdtmp
= codec_
->encode (sc_qos_as_any
);
467 sc
.context_data
= cdtmp
.in ();
469 // Add this context to the service context list.
470 ri
->add_reply_service_context (sc
, 1);
472 #ifdef KOKYU_DSRT_LOGGING
473 ACE_DEBUG ((LM_DEBUG
, "(%t|%T):reply sc added\n"));
477 kokyu_dispatcher_
->update_schedule (guid
.in (),
480 #ifdef KOKYU_DSRT_LOGGING
481 ACE_DEBUG ((LM_DEBUG
, "(%t|%T): send_reply interceptor done\n"));
486 Fixed_Priority_Scheduler::send_exception (PortableInterceptor::ServerRequestInfo_ptr ri
)
492 Fixed_Priority_Scheduler::send_other (PortableInterceptor::ServerRequestInfo_ptr ri
)
498 Fixed_Priority_Scheduler::receive_reply (PortableInterceptor::ClientRequestInfo_ptr ri
)
500 RTScheduling::Current::IdType guid
;
501 RTCORBA::Priority desired_priority
=0;
503 CORBA::String_var operation
= ri
->operation ();
505 CORBA::Object_var target
= ri
->target ();
507 ACE_CString opname
= operation
.in ();
508 #ifdef KOKYU_DSRT_LOGGING
509 ACE_DEBUG ((LM_DEBUG
,
510 "(%t|%T):receive_reply from "
515 // Check that the reply service context was received as
517 IOP::ServiceContext_var sc
=
518 ri
->get_reply_service_context (Client_Interceptor::SchedulingInfo
);
522 desired_priority
= 0;
526 CORBA::OctetSeq oc_seq
= CORBA::OctetSeq (sc
->context_data
.length (),
527 sc
->context_data
.length (),
528 sc
->context_data
.get_buffer (),
531 //Don't store in a _var, since >>= returns a pointer to an internal buffer
532 //and we are not supposed to free it.
533 const Kokyu::Svc_Ctxt_DSRT_QoS
* sc_qos_ptr
= 0;
534 CORBA::Any sc_qos_as_any
;
535 CORBA::Any_var scqostmp
= codec_
->decode (oc_seq
);
536 sc_qos_as_any
= scqostmp
.in ();
537 sc_qos_as_any
>>= sc_qos_ptr
;
539 desired_priority
= sc_qos_ptr
->desired_priority
;
540 guid
.length (sc_qos_ptr
->guid
.length ());
541 guid_copy (guid
, sc_qos_ptr
->guid
);
543 #ifdef KOKYU_DSRT_LOGGING
544 ACE_DEBUG ((LM_DEBUG
,
545 "(%t): Desired_Priority = %d in recvd service context\n",
550 FP_Scheduler_Traits::QoSDescriptor_t qos
;
551 qos
.priority_
= desired_priority
;
552 this->kokyu_dispatcher_
->schedule (guid
, qos
);
556 Fixed_Priority_Scheduler::receive_exception (PortableInterceptor::ClientRequestInfo_ptr ri
)
562 Fixed_Priority_Scheduler::receive_other (PortableInterceptor::ClientRequestInfo_ptr ri
)
568 Fixed_Priority_Scheduler::cancel (const RTScheduling::Current::IdType
&)
570 throw CORBA::NO_IMPLEMENT ();
574 Fixed_Priority_Scheduler::scheduling_policies (void)
576 throw CORBA::NO_IMPLEMENT ();
580 Fixed_Priority_Scheduler::scheduling_policies (const CORBA::PolicyList
&)
582 throw CORBA::NO_IMPLEMENT ();
586 Fixed_Priority_Scheduler::poa_policies (void)
588 throw CORBA::NO_IMPLEMENT ();
592 Fixed_Priority_Scheduler::scheduling_discipline_name (void)
594 throw CORBA::NO_IMPLEMENT ();
597 RTScheduling::ResourceManager_ptr
598 Fixed_Priority_Scheduler::create_resource_manager (const char *,
601 throw CORBA::NO_IMPLEMENT ();
605 Fixed_Priority_Scheduler::set_scheduling_parameter (PortableServer::Servant
&,
609 throw CORBA::NO_IMPLEMENT ();