00001 // -*- C++ -*- 00018 #ifndef RTC_EXTTRIGEXECUTIONCONTEXT_H 00019 #define RTC_EXTTRIGEXECUTIONCONTEXT_H 00020 00021 #include <rtm/RTC.h> 00022 00023 #include <coil/Mutex.h> 00024 #include <coil/Condition.h> 00025 #include <coil/Task.h> 00026 00027 #include <rtm/ExecutionContextBase.h> 00028 00029 #ifdef WIN32 00030 #pragma warning( disable : 4290 ) 00031 #endif 00032 00033 namespace RTC 00034 { 00057 class ExtTrigExecutionContext 00058 : public virtual POA_OpenRTM::ExtTrigExecutionContextService, 00059 public virtual PortableServer::RefCountServantBase, 00060 public RTC::ExecutionContextBase, 00061 public coil::Task 00062 { 00063 typedef coil::Mutex Mutex; 00064 typedef coil::Condition<Mutex> Condition; 00065 typedef coil::Guard<coil::Mutex> Guard; 00066 public: 00080 ExtTrigExecutionContext(); 00081 00095 virtual ~ExtTrigExecutionContext(void); 00096 00121 virtual int open(void *args); 00122 00143 virtual int svc(void); 00144 00172 virtual int close(unsigned long flags); 00173 00174 //============================================================ 00175 // ExtTrigExecutionContextService 00176 //============================================================ 00190 virtual void tick() 00191 throw (CORBA::SystemException); 00192 00193 //============================================================ 00194 // ExecutionContextService 00195 //============================================================ 00220 virtual CORBA::Boolean is_running(void) 00221 throw (CORBA::SystemException); 00222 00250 virtual RTC::ReturnCode_t start(void) 00251 throw (CORBA::SystemException); 00252 00279 virtual RTC::ReturnCode_t stop(void) 00280 throw (CORBA::SystemException); 00281 00302 virtual CORBA::Double get_rate(void) 00303 throw (CORBA::SystemException); 00304 00334 virtual RTC::ReturnCode_t set_rate(CORBA::Double rate) 00335 throw (CORBA::SystemException); 00336 00370 virtual RTC::ReturnCode_t 00371 activate_component(RTC::LightweightRTObject_ptr comp) 00372 throw (CORBA::SystemException); 00373 00406 virtual RTC::ReturnCode_t 00407 deactivate_component(RTC::LightweightRTObject_ptr comp) 00408 throw (CORBA::SystemException); 00409 00441 virtual RTC::ReturnCode_t 00442 reset_component(RTC::LightweightRTObject_ptr comp) 00443 throw (CORBA::SystemException); 00444 00471 virtual RTC::LifeCycleState 00472 get_component_state(RTC::LightweightRTObject_ptr comp) 00473 throw (CORBA::SystemException); 00474 00494 virtual RTC::ExecutionKind get_kind(void) 00495 throw (CORBA::SystemException); 00496 00528 virtual RTC::ReturnCode_t add_component(RTC::LightweightRTObject_ptr comp) 00529 throw (CORBA::SystemException); 00530 00561 virtual RTC::ReturnCode_t 00562 remove_component(RTC::LightweightRTObject_ptr comp) 00563 throw (CORBA::SystemException); 00564 00584 virtual RTC::ExecutionContextProfile* get_profile(void) 00585 throw (CORBA::SystemException); 00586 00587 protected: 00591 virtual RTC::ReturnCode_t onStarted(); 00595 virtual RTC::ReturnCode_t 00596 onWaitingActivated(RTC_impl::RTObjectStateMachine* comp, long int count); 00600 virtual RTC::ReturnCode_t 00601 onWaitingDeactivated(RTC_impl::RTObjectStateMachine* comp, long int count); 00605 virtual RTC::ReturnCode_t 00606 onWaitingReset(RTC_impl::RTObjectStateMachine* comp, long int count); 00607 00608 private: 00609 bool threadRunning() 00610 { 00611 Guard guard(m_svcmutex); 00612 return m_svc; 00613 } 00621 RTC::Logger rtclog; 00622 00630 bool m_svc; 00631 Mutex m_svcmutex; 00632 00640 struct Worker 00641 { 00642 Worker() : cond_(mutex_), ticked_(false) {}; 00643 Mutex mutex_; 00644 Condition cond_; 00645 bool ticked_; 00646 }; 00647 // A condition variable for external triggered worker 00648 Worker m_worker; 00649 }; // class ExtTrigExecutionContext 00650 }; // namespace RTC 00651 00652 #ifdef WIN32 00653 #pragma warning( default : 4290 ) 00654 #endif 00655 00656 00657 extern "C" 00658 { 00674 void ExtTrigExecutionContextInit(RTC::Manager* manager); 00675 }; 00676 00677 #endif // RTC_EXTTRIGEXECUTIONCONTEXT_H