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.i"
00019 #endif
00020
00021 ACE_RCSID (Event,
00022 EC_Kokyu_Dispatching,
00023 "EC_Kokyu_Dispatching.cpp,v 1.21 2006/03/14 06:14:25 jtc Exp")
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 ACE_DECLARE_NEW_CORBA_ENV;
00059
00060 RtecScheduler::Config_Info_Set_var configs;
00061 ACE_TRY
00062 {
00063 this->scheduler_->get_config_infos(configs.out());
00064 ACE_TRY_CHECK;
00065 }
00066 ACE_CATCHANY
00067 {
00068
00069 }
00070 ACE_ENDTRY;
00071
00072
00073
00074
00075
00076 Kokyu::ConfigInfoSet kconfigs(configs->length());
00077 for(CORBA::ULong i=0; i<configs->length(); ++i) {
00078 kconfigs[i].preemption_priority_ = configs[i].preemption_priority;
00079 kconfigs[i].thread_priority_ = configs[i].thread_priority;
00080 switch (configs[i].dispatching_type) {
00081 case RtecScheduler::STATIC_DISPATCHING:
00082 kconfigs[i].dispatching_type_ = Kokyu::FIFO_DISPATCHING;
00083 break;
00084 case RtecScheduler::DEADLINE_DISPATCHING:
00085 kconfigs[i].dispatching_type_ = Kokyu::DEADLINE_DISPATCHING;
00086 break;
00087 case RtecScheduler::LAXITY_DISPATCHING:
00088 kconfigs[i].dispatching_type_ = Kokyu::LAXITY_DISPATCHING;
00089 break;
00090 }
00091 }
00092
00093 Kokyu::Dispatcher_Attributes attrs;
00094 attrs.config_info_set_ = kconfigs;
00095 attrs.sched_policy (disp_sched_policy_);
00096 attrs.sched_scope (disp_sched_scope_);
00097
00098
00099 Kokyu::Dispatcher_Auto_Ptr
00100 tmp(Kokyu::Dispatcher_Factory::create_dispatcher(attrs));
00101 this->dispatcher_ = tmp;
00102 this->lanes_setup_ = 1;
00103
00104
00105 }
00106
00107 void
00108 TAO_EC_Kokyu_Dispatching::shutdown (void)
00109 {
00110 this->dispatcher_->shutdown();
00111 }
00112
00113 void
00114 TAO_EC_Kokyu_Dispatching::push (TAO_EC_ProxyPushSupplier* proxy,
00115 RtecEventComm::PushConsumer_ptr consumer,
00116 const RtecEventComm::EventSet& event,
00117 TAO_EC_QOS_Info& qos_info
00118 ACE_ENV_ARG_DECL)
00119 {
00120 RtecEventComm::EventSet event_copy = event;
00121 this->push_nocopy (proxy, consumer, event_copy, qos_info ACE_ENV_ARG_PARAMETER);
00122 }
00123
00124 void
00125 TAO_EC_Kokyu_Dispatching::push_nocopy (TAO_EC_ProxyPushSupplier* proxy,
00126 RtecEventComm::PushConsumer_ptr consumer,
00127 RtecEventComm::EventSet& event,
00128 TAO_EC_QOS_Info& qos_info
00129 ACE_ENV_ARG_DECL)
00130 {
00131 if (this->dispatcher_.get () == 0)
00132 this->setup_lanes ();
00133
00134 void* buf =
00135 this->allocator_->malloc (sizeof (TAO_EC_Kokyu_Push_Command ));
00136
00137 if (buf == 0)
00138 ACE_THROW (CORBA::NO_MEMORY (TAO::VMCID,
00139 CORBA::COMPLETED_NO));
00140
00141
00142 TAO_EC_Kokyu_Push_Command *cmd =
00143 new (buf) TAO_EC_Kokyu_Push_Command (proxy,
00144 consumer,
00145 event, this->allocator_);
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155 RtecScheduler::RT_Info *rt_info =
00156 this->scheduler_->get(qos_info.rt_info);
00157
00158 Kokyu::QoSDescriptor qosd;
00159 qosd.preemption_priority_ = rt_info->preemption_priority;
00160 qosd.deadline_ = rt_info->period;
00161 ORBSVCS_Time::TimeT_to_Time_Value (qosd.execution_time_,
00162 rt_info->worst_case_execution_time);
00163
00164 this->dispatcher_->dispatch(cmd,qosd);
00165 }
00166
00167
00168
00169 TAO_EC_Kokyu_Shutdown_Command::~TAO_EC_Kokyu_Shutdown_Command(void)
00170 {
00171 }
00172
00173 int
00174 TAO_EC_Kokyu_Shutdown_Command::execute(void)
00175 {
00176 return -1;
00177 }
00178
00179
00180
00181 TAO_EC_Kokyu_Push_Command::~TAO_EC_Kokyu_Push_Command(void)
00182 {
00183 this->proxy_->_decr_refcnt ();
00184 }
00185
00186 int
00187 TAO_EC_Kokyu_Push_Command::execute ()
00188 {
00189 ACE_DECLARE_NEW_CORBA_ENV;
00190
00191 ACE_TRY
00192 {
00193
00194
00195
00196 this->proxy_->push_to_consumer (this->consumer_.in (),
00197 this->event_
00198 ACE_ENV_ARG_PARAMETER);
00199 ACE_TRY_CHECK;
00200 }
00201 ACE_CATCHANY
00202 {
00203 return -1;
00204 }
00205 ACE_ENDTRY;
00206
00207 return 0;
00208 }
00209
00210 TAO_END_VERSIONED_NAMESPACE_DECL