OpenRTM-aist 2.0.2
Loading...
Searching...
No Matches
ExecutionContextBase.h
Go to the documentation of this file.
1// -*- C++ -*-
18#ifndef RTC_EXECUTIONCONTEXTBASE_H
19#define RTC_EXECUTIONCONTEXTBASE_H
20
21#include <coil/Factory.h>
22
23#include <rtm/idl/RTCSkel.h>
24#include <rtm/idl/OpenRTMSkel.h>
25#include <rtm/Factory.h>
28
29#define DEFAULT_EXECUTION_RATE 1000
30
31namespace coil
32{
33 class Properties;
34} // namespace coil
35
36namespace RTC
37{
366 {
367 public:
381 explicit ExecutionContextBase(const char* name);
382
397
411 virtual void init(coil::Properties& props);
412
426 virtual RTC::ReturnCode_t bindComponent(RTC::RTObject_impl* rtc);
427
428 //============================================================
429 // implementation functions for EC's CORBA operation
430 //============================================================
454 CORBA::Boolean isRunning();
455
483 RTC::ReturnCode_t start();
484
511 virtual RTC::ReturnCode_t stop();
512
533 double getRate() const;
534 std::chrono::nanoseconds getPeriod() const;
535
569 RTC::ReturnCode_t setRate(double rate);
570
602 RTC::ReturnCode_t addComponent(RTC::LightweightRTObject_ptr comp);
603
634 RTC::ReturnCode_t removeComponent(RTC::LightweightRTObject_ptr comp);
635
669 RTC::ReturnCode_t activateComponent(RTC::LightweightRTObject_ptr comp);
670
711 RTC::ReturnCode_t deactivateComponent(RTC::LightweightRTObject_ptr comp);
712
744 RTC::ReturnCode_t resetComponent(RTC::LightweightRTObject_ptr comp);
745
772 RTC::LifeCycleState getComponentState(RTC::LightweightRTObject_ptr comp);
773 static const char* getStateString(RTC::LifeCycleState state);
774
794 RTC::ExecutionKind getKind() const;
795
818 RTC::ExecutionContextProfile* getProfile();
819
820 //============================================================
821 // Delegated functions to ExecutionContextProfile
822 //============================================================
842 void setObjRef(RTC::ExecutionContextService_ptr ec_ptr);
843
862 RTC::ExecutionContextService_ptr getObjRef() const;
863
886 static const char* getKindString(RTC::ExecutionKind kind) ;
887
906 RTC::ReturnCode_t setKind(RTC::ExecutionKind kind);
907
925 RTC::ReturnCode_t setOwner(RTC::LightweightRTObject_ptr comp);
926
943 RTC::RTObject_ptr getOwner() const;
944
963#ifndef ORB_IS_RTORB
964 const RTC::RTCList& getComponentList() const;
965#else
966 const RTC_RTCList& getComponentList() const;
967#endif
968
989 void setProperties(coil::Properties& props);
990
1010 coil::Properties getProperties() const;
1011
1029 const RTC::ExecutionContextProfile& getProfile() const;
1030 // end of delegated functions to ExecutionContextProfile
1031 //============================================================
1032
1033 //============================================================
1034 // Delegated functions to ExecutionContextWorker
1035 //============================================================
1036 bool isAllCurrentState(RTC::LifeCycleState state)
1037 {
1038 return m_worker.isAllCurrentState(state);
1039 }
1040 bool isAllNextState(RTC::LifeCycleState state)
1041 {
1042 return m_worker.isAllNextState(state);
1043 }
1044 bool isOneOfCurrentState(RTC::LifeCycleState state)
1045 {
1046 return m_worker.isOneOfCurrentState(state);
1047 }
1048 bool isOneOfNextState(RTC::LifeCycleState state)
1049 {
1050 return m_worker.isOneOfNextState(state);
1051 }
1052
1057
1058
1059 protected:
1060 // template virtual functions related to start/stop
1061 virtual bool onIsRunning(bool running) { return running; }
1062 virtual RTC::ReturnCode_t onStarting() { return RTC::RTC_OK; }
1063 virtual RTC::ReturnCode_t onStarted() { return RTC::RTC_OK; }
1064 virtual RTC::ReturnCode_t onStopping() { return RTC::RTC_OK; }
1065 virtual RTC::ReturnCode_t onStopped() { return RTC::RTC_OK; }
1066
1067 // template virtual functions getting/setting execution rate
1068 virtual double onGetRate(double rate) const { return rate; }
1069 virtual double onSettingRate(double rate) { return rate; }
1070 virtual RTC::ReturnCode_t onSetRate(double /*rate*/) { return RTC::RTC_OK; }
1071
1072 // template virtual functions adding/removing component
1073 virtual RTC::ReturnCode_t
1074 onAddingComponent(RTC::LightweightRTObject_ptr /*rtobj*/)
1075 {
1076 return RTC::RTC_OK;
1077 }
1078 virtual RTC::ReturnCode_t
1079 onAddedComponent(RTC::LightweightRTObject_ptr /*rtobj*/)
1080 {
1081 return RTC::RTC_OK;
1082 }
1083 virtual RTC::ReturnCode_t
1084 onRemovingComponent(RTC::LightweightRTObject_ptr /*rtobj*/)
1085 {
1086 return RTC::RTC_OK;
1087 }
1088 virtual RTC::ReturnCode_t
1089 onRemovedComponent(RTC::LightweightRTObject_ptr /*rtobj*/)
1090 {
1091 return RTC::RTC_OK;
1092 }
1093
1094 // template virtual functions related to activation/deactivation/reset
1095 virtual RTC::ReturnCode_t
1096 onActivating(RTC::LightweightRTObject_ptr /*comp*/)
1097 {
1098 return RTC::RTC_OK;
1099 }
1100 virtual RTC::ReturnCode_t
1102 {
1103 return RTC::RTC_OK;
1104 }
1105 virtual RTC::ReturnCode_t
1107 long int /*count*/)
1108 {
1109 return RTC::RTC_OK;
1110 }
1111 virtual RTC::ReturnCode_t
1112 onDeactivating(RTC::LightweightRTObject_ptr /*comp*/)
1113 {
1114 return RTC::RTC_OK;
1115 }
1116 virtual RTC::ReturnCode_t
1118 {
1119 return RTC::RTC_OK;
1120 }
1121 virtual RTC::ReturnCode_t
1122 onDeactivated(RTC_impl::RTObjectStateMachine* /*comp*/, long int /*count*/)
1123 {
1124 return RTC::RTC_OK;
1125 }
1126 virtual RTC::ReturnCode_t onResetting(RTC::LightweightRTObject_ptr /*comp*/)
1127 {
1128 return RTC::RTC_OK;
1129 }
1130 virtual RTC::ReturnCode_t
1131 onWaitingReset(RTC_impl::RTObjectStateMachine* /*comp*/, long int /*count*/)
1132 {
1133 return RTC::RTC_OK;
1134 }
1135 virtual RTC::ReturnCode_t
1136 onReset(RTC_impl::RTObjectStateMachine* /*comp*/, long int /*count*/)
1137 {
1138 return RTC::RTC_OK;
1139 }
1140
1141 virtual RTC::LifeCycleState
1142 onGetComponentState(RTC::LifeCycleState state)
1143 {
1144 return state;
1145 }
1146 virtual RTC::ExecutionKind
1147 onGetKind(RTC::ExecutionKind kind) const
1148 {
1149 return kind;
1150 }
1151 virtual RTC::ExecutionContextProfile*
1152 onGetProfile(RTC::ExecutionContextProfile*& profile)
1153 {
1154 return profile;
1155 }
1156
1157 private:
1165 bool setExecutionRate(coil::Properties& props);
1173 bool setTransitionMode(coil::Properties& props,
1174 const char* key, bool& flag);
1182 bool setTimeout(coil::Properties& props, const char* key,
1183 std::chrono::nanoseconds& timevalue);
1184
1185 RTC::ReturnCode_t waitForActivated(RTC_impl::RTObjectStateMachine* rtobj);
1186 RTC::ReturnCode_t waitForDeactivated(RTC_impl::RTObjectStateMachine* rtobj);
1187 RTC::ReturnCode_t waitForReset(RTC_impl::RTObjectStateMachine* rtobj);
1188
1189 protected:
1191
1194
1195 std::chrono::nanoseconds m_activationTimeout;
1196 std::chrono::nanoseconds m_deactivationTimeout;
1197 std::chrono::nanoseconds m_resetTimeout;
1198
1202 }; // class ExecutionContextBase
1203
1204 using ExecutionContextFactory = coil::GlobalFactory<ExecutionContextBase>;
1205} // namespace RTC
1206
1207#ifdef WIN32
1208EXTERN template class DLL_PLUGIN coil::GlobalFactory<RTC::ExecutionContextBase>;
1209#elif defined(__GNUC__)
1210EXTERN template class coil::GlobalFactory<RTC::ExecutionContextBase>;
1211#endif
1212
1213#endif // RTC_EXECUTIONCONTEXTBASE_H
ExecutionContextProfile class.
ExecutionContext's state machine worker class.
RT-Component factory class.
A base class for ExecutionContext.
Definition ExecutionContextBase.h:366
RTC::RTObject_ptr getOwner() const
Getting a reference of the owner component.
RTC_impl::ExecutionContextProfile m_profile
Definition ExecutionContextBase.h:1193
virtual RTC::ReturnCode_t onActivated(RTC_impl::RTObjectStateMachine *, long int)
Definition ExecutionContextBase.h:1106
RTC::ExecutionKind getKind() const
Get the ExecutionKind.
RTC::Logger rtclog
Definition ExecutionContextBase.h:1190
static const char * getKindString(RTC::ExecutionKind kind)
Converting ExecutionKind enum to string.
const RTC::RTCList & getComponentList() const
Getting participant RTC list.
RTC::ReturnCode_t setRate(double rate)
Set execution rate(Hz) of ExecutionContext.
std::chrono::nanoseconds getPeriod() const
RTC::ReturnCode_t activateComponent(RTC::LightweightRTObject_ptr comp)
Activate an RT-component.
RTC::ReturnCode_t removeComponent(RTC::LightweightRTObject_ptr comp)
Remove the RT-Component from participant list.
coil::Properties getProperties() const
Setting Properties.
bool isAllCurrentState(RTC::LifeCycleState state)
Definition ExecutionContextBase.h:1036
bool isOneOfCurrentState(RTC::LifeCycleState state)
Definition ExecutionContextBase.h:1044
void invokeWorkerPreDo()
Definition ExecutionContextBase.h:1054
CORBA::Boolean isRunning()
Check for ExecutionContext running state.
void setProperties(coil::Properties &props)
Setting Properties.
virtual ~ExecutionContextBase()
Virtual Destructor.
virtual RTC::ReturnCode_t onStarting()
Definition ExecutionContextBase.h:1062
virtual RTC::ReturnCode_t onStarted()
Definition ExecutionContextBase.h:1063
RTC::ReturnCode_t addComponent(RTC::LightweightRTObject_ptr comp)
Add an RT-component.
virtual RTC::ReturnCode_t stop()
Stop the ExecutionContext.
virtual RTC::ExecutionContextProfile * onGetProfile(RTC::ExecutionContextProfile *&profile)
Definition ExecutionContextBase.h:1152
virtual RTC::LifeCycleState onGetComponentState(RTC::LifeCycleState state)
Definition ExecutionContextBase.h:1142
std::chrono::nanoseconds m_deactivationTimeout
Definition ExecutionContextBase.h:1196
virtual RTC::ReturnCode_t onStopped()
Definition ExecutionContextBase.h:1065
RTC::ExecutionContextProfile * getProfile()
Getting Profile.
bool isAllNextState(RTC::LifeCycleState state)
Definition ExecutionContextBase.h:1040
virtual RTC::ReturnCode_t onResetting(RTC::LightweightRTObject_ptr)
Definition ExecutionContextBase.h:1126
virtual double onGetRate(double rate) const
Definition ExecutionContextBase.h:1068
double getRate() const
Get execution rate(Hz) of ExecutionContext.
const RTC::ExecutionContextProfile & getProfile() const
Getting Profile.
virtual RTC::ReturnCode_t onAddedComponent(RTC::LightweightRTObject_ptr)
Definition ExecutionContextBase.h:1079
RTC::ReturnCode_t start()
Start the ExecutionContext.
static const char * getStateString(RTC::LifeCycleState state)
virtual RTC::ReturnCode_t onWaitingDeactivated(RTC_impl::RTObjectStateMachine *, long int)
Definition ExecutionContextBase.h:1117
RTC::LifeCycleState getComponentState(RTC::LightweightRTObject_ptr comp)
Get RT-component's state.
virtual RTC::ReturnCode_t bindComponent(RTC::RTObject_impl *rtc)
Bind the component.
void invokeWorker()
Definition ExecutionContextBase.h:1053
virtual RTC::ReturnCode_t onAddingComponent(RTC::LightweightRTObject_ptr)
Definition ExecutionContextBase.h:1074
RTC_impl::ExecutionContextWorker m_worker
Definition ExecutionContextBase.h:1192
bool m_syncActivation
Definition ExecutionContextBase.h:1199
virtual RTC::ReturnCode_t onSetRate(double)
Definition ExecutionContextBase.h:1070
virtual RTC::ReturnCode_t onReset(RTC_impl::RTObjectStateMachine *, long int)
Definition ExecutionContextBase.h:1136
std::chrono::nanoseconds m_activationTimeout
Definition ExecutionContextBase.h:1195
RTC::ReturnCode_t deactivateComponent(RTC::LightweightRTObject_ptr comp)
Deactivate an RT-component.
void invokeWorkerPostDo()
Definition ExecutionContextBase.h:1056
virtual double onSettingRate(double rate)
Definition ExecutionContextBase.h:1069
virtual RTC::ExecutionKind onGetKind(RTC::ExecutionKind kind) const
Definition ExecutionContextBase.h:1147
virtual RTC::ReturnCode_t onRemovingComponent(RTC::LightweightRTObject_ptr)
Definition ExecutionContextBase.h:1084
bool m_syncDeactivation
Definition ExecutionContextBase.h:1200
bool isOneOfNextState(RTC::LifeCycleState state)
Definition ExecutionContextBase.h:1048
RTC::ReturnCode_t setOwner(RTC::LightweightRTObject_ptr comp)
Setting owner component of the execution context.
RTC::ReturnCode_t resetComponent(RTC::LightweightRTObject_ptr comp)
Reset the RT-component.
virtual bool onIsRunning(bool running)
Definition ExecutionContextBase.h:1061
virtual void init(coil::Properties &props)
Initialize the ExecutionContext.
std::chrono::nanoseconds m_resetTimeout
Definition ExecutionContextBase.h:1197
virtual RTC::ReturnCode_t onWaitingActivated(RTC_impl::RTObjectStateMachine *, long int)
Definition ExecutionContextBase.h:1101
virtual RTC::ReturnCode_t onDeactivated(RTC_impl::RTObjectStateMachine *, long int)
Definition ExecutionContextBase.h:1122
virtual RTC::ReturnCode_t onDeactivating(RTC::LightweightRTObject_ptr)
Definition ExecutionContextBase.h:1112
void setObjRef(RTC::ExecutionContextService_ptr ec_ptr)
Get the reference to the CORBA object.
virtual RTC::ReturnCode_t onRemovedComponent(RTC::LightweightRTObject_ptr)
Definition ExecutionContextBase.h:1089
RTC::ReturnCode_t setKind(RTC::ExecutionKind kind)
Set the ExecutionKind.
virtual RTC::ReturnCode_t onStopping()
Definition ExecutionContextBase.h:1064
RTC::ExecutionContextService_ptr getObjRef() const
virtual RTC::ReturnCode_t onActivating(RTC::LightweightRTObject_ptr)
Definition ExecutionContextBase.h:1096
void invokeWorkerDo()
Definition ExecutionContextBase.h:1055
ExecutionContextBase(const char *name)
Constructor.
virtual RTC::ReturnCode_t onWaitingReset(RTC_impl::RTObjectStateMachine *, long int)
Definition ExecutionContextBase.h:1131
bool m_syncReset
Definition ExecutionContextBase.h:1201
Logger class.
Definition SystemLogger.h:101
RT-Component class.
Definition RTObject.h:93
ExecutionContextProfile class.
Definition ExecutionContextProfile.h:51
ExecutionContextWorker class.
Definition ExecutionContextWorker.h:112
bool isAllNextState(RTC::LifeCycleState state)
bool isAllCurrentState(RTC::LifeCycleState state)
bool isOneOfNextState(RTC::LifeCycleState state)
bool isOneOfCurrentState(RTC::LifeCycleState state)
Definition RTObjectStateMachine.h:43
RT-Component.
coil::GlobalFactory< ExecutionContextBase > ExecutionContextFactory
Definition ExecutionContextBase.h:1204
Definition DefaultPeriodicTask.h:24