OpenRTM-aist  1.2.1
RTObjectStateMachine.h
[詳解]
1 // -*- C++ -*-
19 #ifndef RTC_IMPL_RTOBJECTSTATEMACHINE_H
20 #define RTC_IMPL_RTOBJECTSTATEMACHINE_H
21 
22 #include <stdlib.h>
23 #include <rtm/SystemLogger.h>
24 #include <coil/NonCopyable.h>
25 #include <coil/TimeMeasure.h>
26 #include <rtm/idl/RTCSkel.h>
27 #include <rtm/StateMachine.h>
28 #include <assert.h>
29 #include <iostream>
30 
31 #define NUM_OF_LIFECYCLESTATE 4
32 
33 #ifdef WIN32
34 #pragma warning( disable : 4290 )
35 #endif
36 namespace RTC
37 {
38  class RTObject_impl;
39 }
40 namespace RTC_impl
41 {
42  typedef RTC::ExecutionContextHandle_t Ecid;
43  typedef RTC::LifeCycleState ExecContextState;
45 
47  : private coil::NonCopyable
48  {
49  public:
50  RTObjectStateMachine(RTC::ExecutionContextHandle_t id,
52  virtual ~RTObjectStateMachine(void);
53 // RTObjectStateMachine(const RTObjectStateMachine& rtobjsm);
54 // RTObjectStateMachine& operator=(const RTObjectStateMachine& rtobjsm);
55 // void swap(RTObjectStateMachine& rtobjsm) throw();
56 
57  // functions for stored RTObject reference
58  RTC::LightweightRTObject_ptr getRTObject();
59  bool isEquivalent(RTC::LightweightRTObject_ptr comp);
60 
61  RTC::ExecutionContextHandle_t getExecutionContextHandle();
62 
63  // RTC::ComponentAction operations
64  void onStartup(void);
65  void onShutdown(void);
66  void onActivated(const ExecContextStates& st);
67  void onDeactivated(const ExecContextStates& st);
68  void onAborting(const ExecContextStates& st);
69  void onError(const ExecContextStates& st);
70  void onReset(const ExecContextStates& st);
71 
72  // RTC::DataflowComponentAction
73  void onExecute(const ExecContextStates& st);
74  void onStateUpdate(const ExecContextStates& st);
75  RTC::ReturnCode_t onRateChanged(void);
76 
77  // FsmParticipantAction
78  void onAction(const ExecContextStates& st);
79 
80  // MultiModeComponentAction
81  void onModeChanged(const ExecContextStates& st);
82 
83  // Getting state of the context
84  ExecContextState getState(void);
85  ExecContextStates getStates(void);
86  bool isCurrentState(ExecContextState state);
87  bool isNextState(ExecContextState state);
88  void goTo(ExecContextState state);
89 
90  // Workers
91  void workerPreDo(void);
92  void workerDo(void);
93  void workerPostDo(void);
94 
95  bool activate();
96  bool deactivate();
97  bool reset();
98 
99  protected:
100  void setComponentAction(const RTC::LightweightRTObject_ptr comp);
101  void setDataFlowComponentAction(const RTC::LightweightRTObject_ptr comp);
102  void setFsmParticipantAction(const RTC::LightweightRTObject_ptr comp);
103  void setMultiModeComponentAction(const RTC::LightweightRTObject_ptr comp);
104  void updateState();
105 
106  private: // member variables
107  RTC::Logger rtclog;
108  // ExecutionContext id
109  RTC::ExecutionContextHandle_t m_id;
110  // Associated RTObject reference
112  // State machine
114  RTObjectStateMachine> m_sm;
115  bool m_ca;
116  bool m_dfc;
117  bool m_fsm;
118  bool m_mode;
119  RTC::ComponentAction_var m_caVar;
120  RTC::DataFlowComponentAction_var m_dfcVar;
121  RTC::FsmParticipantAction_var m_fsmVar;
122  RTC::MultiModeComponentAction_var m_modeVar;
123  RTC::RTObject_impl* m_rtobjPtr;
124  bool m_measure;
125 
126  // char dara[1000];
127  // Component action invoker
128  coil::TimeMeasure m_svtMeasure;
129  coil::TimeMeasure m_refMeasure;
130 
131  bool m_activation;
132  bool m_deactivation;
133  bool m_reset;
134  };
135 }; // namespace RTC
136 
137 #ifdef WIN32
138 #pragma warning( default : 4290 )
139 #endif
140 
141 #endif // RTC_RTOBJECTSTATEMACHINE_H
RTC::ReturnCode_t reset(RTC::RTObject_ptr rtc, RTC::UniqueId ec_id=0)
RTCを指定した実行コンテキストでリセットする
RTコンポーネント
Non Copyable mixin class.
RT component logger class.
Definition: ExecutionContextProfile.h:34
RTC::ReturnCode_t activate(RTC::RTObject_ptr rtc, RTC::UniqueId ec_id=0)
RTCを指定した実行コンテキストでアクティベーションする
RTコンポーネントクラス
Definition: RTObject.h:89
Periodic time measurement class.
状態マシンクラス
Definition: StateMachine.h:264
RTC::ExecutionContextHandle_t Ecid
Definition: RTObjectStateMachine.h:42
RTC::LightweightRTObject_var LightweightRTObject_var
Definition: ExecutionContextWorker.h:45
RTC::LifeCycleState ExecContextState
Definition: RTObjectStateMachine.h:43
Logger クラス
Definition: SystemLogger.h:99
Definition: RTObjectStateMachine.h:46
RTC::ReturnCode_t deactivate(RTC::RTObject_ptr rtc, RTC::UniqueId ec_id=0)
RTCを指定した実行コンテキストで非アクティベーションする
RTC_Utils::StateHolder< ExecContextState > ExecContextStates
Definition: RTObjectStateMachine.h:44
RTC::LightweightRTObject_ptr LightweightRTObject_ptr
Definition: ExecutionContextWorker.h:43
TimeMeasure クラス
Definition: TimeMeasure.h:49
コピー禁止ミックスイン
Definition: NonCopyable.h:53
State machine template class.