// $Id$ #include "Default_Dispatcher_Impl.h" #include "ace/Sched_Params.h" #if ! defined (__ACE_INLINE__) #include "Default_Dispatcher_Impl.i" #endif /* __ACE_INLINE__ */ ACE_RCSID(Kokyu, Dispatcher_Impl, "$Id$") namespace Kokyu { int Default_Dispatcher_Impl::init_i (const ConfigInfoSet& config_info_set) { //create and init the dispatcher tasks here ACE_DEBUG ((LM_DEBUG, "entering init_t\n" )); int size; size = config_info_set.size (); if (size == 0) return -1; this->ntasks_ = size; Dispatcher_Task_Auto_Ptr * tasks_array=0; ACE_NEW_RETURN (tasks_array, Dispatcher_Task_Auto_Ptr[ntasks_], -1); ACE_DEBUG ((LM_DEBUG, "after new on task array\n" )); tasks_.reset(tasks_array); ACE_DEBUG ((LM_DEBUG, "task array auto_ptr set\n" )); ConfigInfoSet& config_set = const_cast (config_info_set); ConfigInfoSet::ITERATOR iter(config_set); int i=0; ConfigInfo* config; for (;i tmp_task_auto_ptr (task); tasks_[i++] = tmp_task_auto_ptr; //I couldn't use reset because MSVC++ auto_ptr does not have reset method. //So in configurations where the auto_ptr maps to the std::auto_ptr instead //of ACE auto_ptr, this would be a problem. //tasks_[i++].reset (task); } this->activate (); curr_config_info_ = config_info_set; return 0; } int Default_Dispatcher_Impl::activate () { int i; for(i=0; iget_curr_config_info ().thread_priority_; if (this->tasks_[i]->activate (flags, 1, 1, priority) == -1) { flags = THR_BOUND; priority = ACE_Sched_Params::priority_min (ACE_SCHED_OTHER, ACE_SCOPE_THREAD); if (this->tasks_[i]->activate (flags, 1, 1, priority) == -1) ACE_ERROR ((LM_ERROR, "EC (%P|%t) cannot activate queue %d", i)); } } return 0; } Dispatcher_Task* Default_Dispatcher_Impl::find_task_with_preemption_prio (Priority_t prio) { int i; if (prio >=0) { for( i=0; ipreemption_priority () == prio) return tasks_[i].get(); } } return 0; } int Default_Dispatcher_Impl::dispatch_i (const Dispatch_Command* cmd, const QoSDescriptor& qos_info) { //delegate to the appropriate task if (qos_info.preemption_priority_ < 0) return -1; Dispatcher_Task* task = find_task_with_preemption_prio (qos_info.preemption_priority_); if (task != 0) task->enqueue (cmd, qos_info); else tasks_[0]->enqueue (cmd, qos_info); return 0; } int Default_Dispatcher_Impl::shutdown_i () { //post shutdown command to all tasks int i; for(i=0; ienqueue (shutdown_cmd, qos_info); } return 0; } }