OpenRTM-aist  1.2.1
ExecutionContextWorker.h
Go to the documentation of this file.
1 // -*- C++ -*-
19 #ifndef RTC_EXECUTIONCONTEXTWORKER_H
20 #define RTC_EXECUTIONCONTEXTWORKER_H
21 
22 #include <coil/Mutex.h>
23 #include <coil/Condition.h>
24 #include <vector>
25 
26 #include <rtm/idl/RTCSkel.h>
27 #include <rtm/SystemLogger.h>
28 //#include <rtm/StateMachine.h>
29 //#include <rtm/RTObjectStateMachine.h>
30 
31 #define NUM_OF_LIFECYCLESTATE 4
32 
33 #ifdef WIN32
34 #pragma warning( disable : 4290 )
35 #endif
36 
37 namespace RTC
38 {
39  class RTObject_impl;
40 };
41 namespace RTC_impl
42 {
119  {
121 
122  public:
143 
144 
158  virtual ~ExecutionContextWorker(void);
159 
160  //============================================================
161  // Object reference to EC
162  //============================================================
163  void setECRef(RTC::ExecutionContextService_ptr ref);
164  RTC::ExecutionContextService_ptr getECRef();
165 
166  //============================================================
167  // ExecutionContext
168  //============================================================
193  CORBA::Boolean isRunning(void);
194 
222  RTC::ReturnCode_t start(void);
223 
250  RTC::ReturnCode_t stop(void);
251 
252  RTC::ReturnCode_t startThread(void);
253 
254  RTC::ReturnCode_t stopThread(void);
255 
256 
284  RTC::ReturnCode_t rateChanged();
285 
319  RTC::ReturnCode_t activateComponent(RTC::LightweightRTObject_ptr comp,
320  RTObjectStateMachine*& rtobj);
321  RTC::ReturnCode_t waitActivateComplete(RTObjectStateMachine*& rtobj,
322  coil::TimeValue timeout = 1.0,
323  long int cycle = 1000);
356  RTC::ReturnCode_t deactivateComponent(RTC::LightweightRTObject_ptr comp,
357  RTObjectStateMachine*& rtobj);
358  RTC::ReturnCode_t waitDeactivateComplete(RTObjectStateMachine*& rtobj,
359  coil::TimeValue timeout = 1.0,
360  long int cycle = 1000);
361 
393  RTC::ReturnCode_t resetComponent(RTC::LightweightRTObject_ptr com,
394  RTObjectStateMachine*& rtobj);
395  RTC::ReturnCode_t waitResetComplete(RTObjectStateMachine*& rtobj,
396  coil::TimeValue timeout = 1.0,
397  long int cycle = 1000);
398 
425  RTC::LifeCycleState getComponentState(RTC::LightweightRTObject_ptr comp);
426  const char* getStateString(RTC::LifeCycleState state)
427  {
428  const char* st[] = {
429  "CREATED_STATE",
430  "INACTIVE_STATE",
431  "ACTIVE_STATE",
432  "ERROR_STATE"
433  };
434  return state >= RTC::CREATED_STATE && state <= RTC::ERROR_STATE ?
435  st[state] : "";
436  }
480  RTC::ReturnCode_t addComponent(RTC::LightweightRTObject_ptr comp);
481 
508  RTC::ReturnCode_t bindComponent(RTC::RTObject_impl* rtc);
509 
540  RTC::ReturnCode_t removeComponent(RTC::LightweightRTObject_ptr comp);
542 
543  bool isAllCurrentState(RTC::LifeCycleState state);
544  bool isAllNextState(RTC::LifeCycleState state);
545  bool isOneOfCurrentState(RTC::LifeCycleState state);
546  bool isOneOfNextState(RTC::LifeCycleState state);
547 
548  void invokeWorker();
549  void invokeWorkerPreDo();
550  void invokeWorkerDo();
551  void invokeWorkerPostDo();
552 
560  void updateComponentList();
561 
562  //------------------------------------------------------------
563  // member variables
564  protected:
573 
574  RTC::ExecutionContextService_var m_ref;
575 
585  bool m_running;
586 
594  std::vector<RTC_impl::RTObjectStateMachine*> m_comps;
596  std::vector<RTC_impl::RTObjectStateMachine*> m_addedComps;
598  std::vector<RTC_impl::RTObjectStateMachine*> m_removedComps;
600  typedef std::vector<RTC_impl::RTObjectStateMachine*>::iterator CompItr;
601 
602  }; // class PeriodicExecutionContext
603 }; // namespace RTC
604 
605 #ifdef WIN32
606 #pragma warning( default : 4290 )
607 #endif
608 
609 #endif // RTC_PERIODICEXECUTIONCONTEXT_H
bool m_running
The running state of ExecutionContext true: running, false: stopped.
Definition: ExecutionContextWorker.h:585
RT-Component.
const char * getStateString(RTC::LifeCycleState state)
Definition: ExecutionContextWorker.h:426
Mutex class.
Definition: Mutex.h:40
RT component logger class.
Definition: ExecutionContextProfile.h:34
std::vector< RTC_impl::RTObjectStateMachine * > m_comps
List of the participating component.
Definition: ExecutionContextWorker.h:594
std::vector< RTC_impl::RTObjectStateMachine * >::iterator CompItr
Definition: ExecutionContextWorker.h:600
coil::Mutex m_addedMutex
Definition: ExecutionContextWorker.h:597
RT-Component class.
Definition: RTObject.h:89
std::vector< RTC_impl::RTObjectStateMachine * > m_addedComps
Definition: ExecutionContextWorker.h:596
coil::Guard< coil::Mutex > Guard
Definition: LocalServiceAdmin.h:36
TimeValue class.
Definition: TimeValue.h:40
coil::Mutex m_removedMutex
Definition: ExecutionContextWorker.h:599
RTC::LightweightRTObject_var LightweightRTObject_var
Definition: ExecutionContextWorker.h:45
Logger class.
Definition: SystemLogger.h:99
RTC::ExecutionContextService_var m_ref
Definition: ExecutionContextWorker.h:574
Definition: RTObjectStateMachine.h:46
std::vector< RTC_impl::RTObjectStateMachine * > m_removedComps
Definition: ExecutionContextWorker.h:598
ExecutionContextWorker class.
Definition: ExecutionContextWorker.h:118
RTC::Logger rtclog
Logger stream.
Definition: ExecutionContextWorker.h:572
RTC::LightweightRTObject_ptr LightweightRTObject_ptr
Definition: ExecutionContextWorker.h:43
coil::Mutex m_mutex
Definition: ExecutionContextWorker.h:595