00001
00019 #ifndef RTC_PERIODICEXECUTIONCONTEXT2_H
00020 #define RTC_PERIODICEXECUTIONCONTEXT2_H
00021
00022 #include <vector>
00023 #include <iostream>
00024
00025 #include <coil/Task.h>
00026 #include <coil/Mutex.h>
00027 #include <coil/Condition.h>
00028
00029 #include <rtm/ExecutionContextBase.h>
00030
00031 #define NUM_OF_LIFECYCLESTATE 4
00032
00033 #ifdef WIN32
00034 #pragma warning( disable : 4290 )
00035 #endif
00036
00037 namespace RTC_exp
00038 {
00059 class PeriodicExecutionContext
00060 : public virtual POA_RTC::ExecutionContextService,
00061 public virtual PortableServer::RefCountServantBase,
00062 public RTC::ExecutionContextBase,
00063 public coil::Task
00064 {
00065 typedef coil::Guard<coil::Mutex> Guard;
00066 public:
00086 PeriodicExecutionContext();
00087
00101 virtual ~PeriodicExecutionContext(void);
00102
00127 virtual int open(void *args);
00128
00148 virtual int svc(void);
00149
00177 virtual int close(unsigned long flags);
00178
00179
00180
00181
00206 virtual CORBA::Boolean is_running(void)
00207 throw (CORBA::SystemException);
00208
00236 virtual RTC::ReturnCode_t start(void)
00237 throw (CORBA::SystemException);
00238
00265 virtual RTC::ReturnCode_t stop(void)
00266 throw (CORBA::SystemException);
00267
00288 virtual CORBA::Double get_rate(void)
00289 throw (CORBA::SystemException);
00290
00320 virtual RTC::ReturnCode_t set_rate(CORBA::Double rate)
00321 throw (CORBA::SystemException);
00322
00356 virtual RTC::ReturnCode_t
00357 activate_component(RTC::LightweightRTObject_ptr comp)
00358 throw (CORBA::SystemException);
00359
00392 virtual RTC::ReturnCode_t
00393 deactivate_component(RTC::LightweightRTObject_ptr comp)
00394 throw (CORBA::SystemException);
00395
00427 virtual RTC::ReturnCode_t
00428 reset_component(RTC::LightweightRTObject_ptr comp)
00429 throw (CORBA::SystemException);
00430
00457 virtual RTC::LifeCycleState
00458 get_component_state(RTC::LightweightRTObject_ptr comp)
00459 throw (CORBA::SystemException);
00460
00480 virtual RTC::ExecutionKind get_kind(void)
00481 throw (CORBA::SystemException);
00482
00514 virtual RTC::ReturnCode_t add_component(RTC::LightweightRTObject_ptr comp)
00515 throw (CORBA::SystemException);
00516
00547 virtual RTC::ReturnCode_t
00548 remove_component(RTC::LightweightRTObject_ptr comp)
00549 throw (CORBA::SystemException);
00550
00570 virtual RTC::ExecutionContextProfile* get_profile(void)
00571 throw (CORBA::SystemException);
00572
00573 protected:
00577 virtual RTC::ReturnCode_t onStarted();
00581 virtual RTC::ReturnCode_t onStopping();
00585 virtual RTC::ReturnCode_t
00586 onWaitingActivated(RTC_impl::RTObjectStateMachine* comp, long int count);
00590 virtual RTC::ReturnCode_t
00591 onActivated(RTC_impl::RTObjectStateMachine* comp, long int count);
00595 virtual RTC::ReturnCode_t
00596 onWaitingDeactivated(RTC_impl::RTObjectStateMachine* comp, long int count);
00600 virtual RTC::ReturnCode_t
00601 onDeactivated(RTC_impl::RTObjectStateMachine* comp, long int count);
00605 virtual RTC::ReturnCode_t
00606 onWaitingReset(RTC_impl::RTObjectStateMachine* comp, long int count);
00610 virtual RTC::ReturnCode_t
00611 onReset(RTC_impl::RTObjectStateMachine* comp, long int count);
00612
00613 bool threadRunning()
00614 {
00615 Guard guard(m_svcmutex);
00616 return m_svc;
00617 }
00618 protected:
00626 RTC::Logger rtclog;
00627
00635 bool m_svc;
00636 coil::Mutex m_svcmutex;
00637
00645 struct WorkerThreadCtrl
00646 {
00647 WorkerThreadCtrl() : cond_(mutex_), running_(false) {};
00648 coil::Mutex mutex_;
00649 coil::Condition<coil::Mutex> cond_;
00650 bool running_;
00651 };
00652
00660 WorkerThreadCtrl m_workerthread;
00661
00670 bool m_nowait;
00671
00672 };
00673 };
00674
00675 #ifdef WIN32
00676 #pragma warning( default : 4290 )
00677 #endif
00678
00679
00680 extern "C"
00681 {
00689 void PeriodicExecutionContextInit(RTC::Manager* manager);
00690 };
00691
00692 #endif // RTC_PERIODICEXECUTIONCONTEXT_H