00001
00002
00003 #include "orbsvcs/Event/EC_Kokyu_Dispatching.h"
00004 #include "orbsvcs/Event/EC_Event_Channel_Base.h"
00005 #include "orbsvcs/Event/EC_ProxySupplier.h"
00006 #include "orbsvcs/Event/EC_QOS_Info.h"
00007
00008 #include "orbsvcs/Event_Service_Constants.h"
00009 #include "orbsvcs/RtecSchedulerC.h"
00010 #include "tao/ORB_Constants.h"
00011
00012 #include "ace/Sched_Params.h"
00013 #include "ace/Malloc_Allocator.h"
00014
00015 #include "Kokyu/Kokyu.h"
00016
00017 #if ! defined (__ACE_INLINE__)
00018 #include "orbsvcs/Event/EC_Kokyu_Dispatching.inl"
00019 #endif
00020
00021 ACE_RCSID (Event,
00022 EC_Kokyu_Dispatching,
00023 "$Id: EC_Kokyu_Dispatching.cpp 76626 2007-01-26 13:50:03Z elliott_c $")
00024
00025 TAO_BEGIN_VERSIONED_NAMESPACE_DECL
00026
00027 TAO_EC_Kokyu_Dispatching::TAO_EC_Kokyu_Dispatching (TAO_EC_Event_Channel_Base *ec, int sched_policy, int sched_scope)
00028 :allocator_ (0),
00029 dispatcher_ (0),
00030 lanes_setup_ (0),
00031 disp_sched_policy_ (sched_policy),
00032 disp_sched_scope_ (sched_scope)
00033 {
00034 CORBA::Object_var tmp = ec->scheduler ();
00035 this->scheduler_ = RtecScheduler::Scheduler::_narrow (tmp.in ());
00036
00037
00038 if (this->allocator_ == 0)
00039 {
00040 this->allocator_ = ACE_Allocator::instance ();
00041 }
00042 }
00043
00044 void
00045 TAO_EC_Kokyu_Dispatching::activate (void)
00046 {
00047 if (!lanes_setup_)
00048 setup_lanes ();
00049
00050 this->dispatcher_->activate ();
00051
00052
00053 }
00054
00055 void
00056 TAO_EC_Kokyu_Dispatching::setup_lanes (void)
00057 {
00058
00059 RtecScheduler::Config_Info_Set_var configs;
00060 try
00061 {
00062 this->scheduler_->get_config_infos(configs.out());
00063 }
00064 catch (const CORBA::Exception&)
00065 {
00066
00067 }
00068
00069
00070
00071
00072
00073 Kokyu::ConfigInfoSet kconfigs(configs->length());
00074 for(CORBA::ULong i=0; i<configs->length(); ++i) {
00075 kconfigs[i].preemption_priority_ = configs[i].preemption_priority;
00076 kconfigs[i].thread_priority_ = configs[i].thread_priority;
00077 switch (configs[i].dispatching_type) {
00078 case RtecScheduler::STATIC_DISPATCHING:
00079 kconfigs[i].dispatching_type_ = Kokyu::FIFO_DISPATCHING;
00080 break;
00081 case RtecScheduler::DEADLINE_DISPATCHING:
00082 kconfigs[i].dispatching_type_ = Kokyu::DEADLINE_DISPATCHING;
00083 break;
00084 case RtecScheduler::LAXITY_DISPATCHING:
00085 kconfigs[i].dispatching_type_ = Kokyu::LAXITY_DISPATCHING;
00086 break;
00087 }
00088 }
00089
00090 Kokyu::Dispatcher_Attributes attrs;
00091 attrs.config_info_set_ = kconfigs;
00092 attrs.sched_policy (disp_sched_policy_);
00093 attrs.sched_scope (disp_sched_scope_);
00094
00095
00096 Kokyu::Dispatcher_Auto_Ptr
00097 tmp(Kokyu::Dispatcher_Factory::create_dispatcher(attrs));
00098 this->dispatcher_ = tmp;
00099 this->lanes_setup_ = 1;
00100
00101
00102 }
00103
00104 void
00105 TAO_EC_Kokyu_Dispatching::shutdown (void)
00106 {
00107 this->dispatcher_->shutdown();
00108 }
00109
00110 void
00111 TAO_EC_Kokyu_Dispatching::push (TAO_EC_ProxyPushSupplier* proxy,
00112 RtecEventComm::PushConsumer_ptr consumer,
00113 const RtecEventComm::EventSet& event,
00114 TAO_EC_QOS_Info& qos_info)
00115 {
00116 RtecEventComm::EventSet event_copy = event;
00117 this->push_nocopy (proxy, consumer, event_copy, qos_info);
00118 }
00119
00120 void
00121 TAO_EC_Kokyu_Dispatching::push_nocopy (TAO_EC_ProxyPushSupplier* proxy,
00122 RtecEventComm::PushConsumer_ptr consumer,
00123 RtecEventComm::EventSet& event,
00124 TAO_EC_QOS_Info& qos_info)
00125 {
00126 if (this->dispatcher_.get () == 0)
00127 this->setup_lanes ();
00128
00129 void* buf =
00130 this->allocator_->malloc (sizeof (TAO_EC_Kokyu_Push_Command ));
00131
00132 if (buf == 0)
00133 throw CORBA::NO_MEMORY (TAO::VMCID, CORBA::COMPLETED_NO);
00134
00135
00136 TAO_EC_Kokyu_Push_Command *cmd =
00137 new (buf) TAO_EC_Kokyu_Push_Command (proxy,
00138 consumer,
00139 event, this->allocator_);
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149 RtecScheduler::RT_Info *rt_info =
00150 this->scheduler_->get(qos_info.rt_info);
00151
00152 Kokyu::QoSDescriptor qosd;
00153 qosd.preemption_priority_ = rt_info->preemption_priority;
00154 qosd.deadline_ = rt_info->period;
00155 ORBSVCS_Time::TimeT_to_Time_Value (qosd.execution_time_,
00156 rt_info->worst_case_execution_time);
00157
00158 this->dispatcher_->dispatch(cmd,qosd);
00159 }
00160
00161
00162
00163 TAO_EC_Kokyu_Shutdown_Command::~TAO_EC_Kokyu_Shutdown_Command(void)
00164 {
00165 }
00166
00167 int
00168 TAO_EC_Kokyu_Shutdown_Command::execute(void)
00169 {
00170 return -1;
00171 }
00172
00173
00174
00175 TAO_EC_Kokyu_Push_Command::~TAO_EC_Kokyu_Push_Command(void)
00176 {
00177 this->proxy_->_decr_refcnt ();
00178 }
00179
00180 int
00181 TAO_EC_Kokyu_Push_Command::execute ()
00182 {
00183
00184 try
00185 {
00186
00187
00188
00189 this->proxy_->push_to_consumer (this->consumer_.in (),
00190 this->event_);
00191 }
00192 catch (const CORBA::Exception&)
00193 {
00194 return -1;
00195 }
00196
00197 return 0;
00198 }
00199
00200 TAO_END_VERSIONED_NAMESPACE_DECL