00001
00018 #ifndef RTC_EXECUTIONCONTEXTBASE_H
00019 #define RTC_EXECUTIONCONTEXTBASE_H
00020
00021 #include <coil/Factory.h>
00022
00023 #include <rtm/idl/RTCSkel.h>
00024 #include <rtm/idl/OpenRTMSkel.h>
00025 #include <rtm/Factory.h>
00026 #include <rtm/ExecutionContextProfile.h>
00027 #include <rtm/ExecutionContextWorker.h>
00028
00029 #ifdef WIN32
00030 #pragma warning( disable : 4290 )
00031 #endif
00032
00033 #define DEFAULT_EXECUTION_RATE 1000
00034
00035 namespace coil
00036 {
00037 class Properties;
00038 }
00039
00040 namespace RTC
00041 {
00362 class ExecutionContextBase
00363 {
00364 public:
00378 ExecutionContextBase(const char* name);
00379
00393 virtual ~ExecutionContextBase(void);
00394
00408 virtual void init(coil::Properties& props);
00409
00423 virtual RTC::ReturnCode_t bindComponent(RTC::RTObject_impl* rtc);
00424
00425
00426
00427
00451 CORBA::Boolean isRunning();
00452
00480 RTC::ReturnCode_t start(void);
00481
00508 virtual RTC::ReturnCode_t stop(void);
00509
00530 double getRate(void) const;
00531 coil::TimeValue getPeriod(void) const;
00532
00566 RTC::ReturnCode_t setRate(double rate);
00567
00599 RTC::ReturnCode_t addComponent(RTC::LightweightRTObject_ptr comp);
00600
00631 RTC::ReturnCode_t removeComponent(RTC::LightweightRTObject_ptr comp);
00632
00666 RTC::ReturnCode_t activateComponent(RTC::LightweightRTObject_ptr comp);
00667
00708 RTC::ReturnCode_t deactivateComponent(RTC::LightweightRTObject_ptr comp);
00709
00741 RTC::ReturnCode_t resetComponent(RTC::LightweightRTObject_ptr comp);
00742
00769 RTC::LifeCycleState getComponentState(RTC::LightweightRTObject_ptr comp);
00770 const char* getStateString(RTC::LifeCycleState state);
00771
00791 RTC::ExecutionKind getKind(void) const;
00792
00815 RTC::ExecutionContextProfile* getProfile(void);
00816
00817
00818
00819
00839 void setObjRef(RTC::ExecutionContextService_ptr ec_ptr);
00840
00859 RTC::ExecutionContextService_ptr getObjRef(void) const;
00860
00883 const char* getKindString(RTC::ExecutionKind kind) const;
00884
00903 RTC::ReturnCode_t setKind(RTC::ExecutionKind kind);
00904
00922 RTC::ReturnCode_t setOwner(RTC::LightweightRTObject_ptr comp);
00923
00940 const RTC::RTObject_ptr getOwner() const;
00941
00960 const RTC::RTCList& getComponentList() const;
00961
00982 void setProperties(coil::Properties& props);
00983
01003 const coil::Properties getProperties() const;
01004
01022 const RTC::ExecutionContextProfile& getProfile(void) const;
01023
01024
01025
01026
01027
01028
01029 bool isAllCurrentState(RTC::LifeCycleState state)
01030 {
01031 return m_worker.isAllCurrentState(state);
01032 };
01033 bool isAllNextState(RTC::LifeCycleState state)
01034 {
01035 return m_worker.isAllNextState(state);
01036 };
01037 bool isOneOfCurrentState(RTC::LifeCycleState state)
01038 {
01039 return m_worker.isOneOfCurrentState(state);
01040 };
01041 bool isOneOfNextState(RTC::LifeCycleState state)
01042 {
01043 return m_worker.isOneOfNextState(state);
01044 };
01045
01046 void invokeWorker() { m_worker.invokeWorker(); }
01047 void invokeWorkerPreDo() { m_worker.invokeWorkerPreDo(); }
01048 void invokeWorkerDo() { m_worker.invokeWorkerDo(); }
01049 void invokeWorkerPostDo() { m_worker.invokeWorkerPostDo(); }
01050
01051
01052 protected:
01053
01054 virtual bool onIsRunning(bool running) { return running; }
01055 virtual RTC::ReturnCode_t onStarting() { return RTC::RTC_OK; }
01056 virtual RTC::ReturnCode_t onStarted() { return RTC::RTC_OK; }
01057 virtual RTC::ReturnCode_t onStopping() { return RTC::RTC_OK; }
01058 virtual RTC::ReturnCode_t onStopped() { return RTC::RTC_OK; }
01059
01060
01061 virtual double onGetRate(double rate) const { return rate; }
01062 virtual double onSettingRate(double rate) { return rate; }
01063 virtual RTC::ReturnCode_t onSetRate(double rate) { return RTC::RTC_OK; }
01064
01065
01066 virtual RTC::ReturnCode_t
01067 onAddingComponent(RTC::LightweightRTObject_ptr rtobj)
01068 {
01069 return RTC::RTC_OK;
01070 }
01071 virtual RTC::ReturnCode_t
01072 onAddedComponent(RTC::LightweightRTObject_ptr rtobj)
01073 {
01074 return RTC::RTC_OK;
01075 }
01076 virtual RTC::ReturnCode_t
01077 onRemovingComponent(RTC::LightweightRTObject_ptr rtobj)
01078 {
01079 return RTC::RTC_OK;
01080 }
01081 virtual RTC::ReturnCode_t
01082 onRemovedComponent(RTC::LightweightRTObject_ptr rtobj)
01083 {
01084 return RTC::RTC_OK;
01085 }
01086
01087
01088 virtual RTC::ReturnCode_t
01089 onActivating(RTC::LightweightRTObject_ptr comp)
01090 {
01091 return RTC::RTC_OK;
01092 }
01093 virtual RTC::ReturnCode_t
01094 onWaitingActivated(RTC_impl::RTObjectStateMachine* comp, long int count)
01095 {
01096 return RTC::RTC_OK;
01097 }
01098 virtual RTC::ReturnCode_t
01099 onActivated(RTC_impl::RTObjectStateMachine* comp,
01100 long int count)
01101 {
01102 return RTC::RTC_OK;
01103 }
01104 virtual RTC::ReturnCode_t
01105 onDeactivating(RTC::LightweightRTObject_ptr comp)
01106 {
01107 return RTC::RTC_OK;
01108 }
01109 virtual RTC::ReturnCode_t
01110 onWaitingDeactivated(RTC_impl::RTObjectStateMachine* comp, long int count)
01111 {
01112 return RTC::RTC_OK;
01113 }
01114 virtual RTC::ReturnCode_t
01115 onDeactivated(RTC_impl::RTObjectStateMachine* comp, long int count)
01116 {
01117 return RTC::RTC_OK;
01118 }
01119 virtual RTC::ReturnCode_t onResetting(RTC::LightweightRTObject_ptr comp)
01120 {
01121 return RTC::RTC_OK;
01122 }
01123 virtual RTC::ReturnCode_t
01124 onWaitingReset(RTC_impl::RTObjectStateMachine* comp, long int count)
01125 {
01126 return RTC::RTC_OK;
01127 }
01128 virtual RTC::ReturnCode_t
01129 onReset(RTC_impl::RTObjectStateMachine* comp, long int count)
01130 {
01131 return RTC::RTC_OK;
01132 }
01133
01134 virtual RTC::LifeCycleState
01135 onGetComponentState(RTC::LifeCycleState state)
01136 {
01137 return state;
01138 }
01139 virtual RTC::ExecutionKind
01140 onGetKind(RTC::ExecutionKind kind) const
01141 {
01142 return kind;
01143 }
01144 virtual RTC::ExecutionContextProfile*
01145 onGetProfile(RTC::ExecutionContextProfile*& profile)
01146 {
01147 return profile;
01148 }
01149
01150 private:
01158 bool setExecutionRate(coil::Properties& props);
01166 bool setTransitionMode(coil::Properties& props,
01167 const char* key, bool& flag);
01175 bool setTimeout(coil::Properties& props, const char* key,
01176 coil::TimeValue& timevalue);
01177
01178 RTC::ReturnCode_t waitForActivated(RTC_impl::RTObjectStateMachine* rtobj);
01179 RTC::ReturnCode_t waitForDeactivated(RTC_impl::RTObjectStateMachine* rtobj);
01180 RTC::ReturnCode_t waitForReset(RTC_impl::RTObjectStateMachine* rtobj);
01181
01182 protected:
01183 mutable RTC::Logger rtclog;
01184
01185 RTC_impl::ExecutionContextWorker m_worker;
01186 RTC_impl::ExecutionContextProfile m_profile;
01187
01188 coil::TimeValue m_activationTimeout;
01189 coil::TimeValue m_deactivationTimeout;
01190 coil::TimeValue m_resetTimeout;
01191
01192 bool m_syncActivation;
01193 bool m_syncDeactivation;
01194 bool m_syncReset;
01195 };
01196
01197 typedef coil::GlobalFactory<ExecutionContextBase> ExecutionContextFactory;
01198
01199 #if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__)
01200 EXTERN template class DLL_PLUGIN coil::GlobalFactory<ExecutionContextBase>;
01201 #endif
01202 };
01203
01204 #ifdef WIN32
01205 #pragma warning( default : 4290 )
01206 #endif
01207
01208 #endif // RTC_EXECUTIONCONTEXTBASE_H