00001
00019 #ifndef RTC_EXECUTIONCONTEXTWORKER_H
00020 #define RTC_EXECUTIONCONTEXTWORKER_H
00021
00022 #include <coil/Mutex.h>
00023 #include <coil/Condition.h>
00024 #include <vector>
00025
00026 #include <rtm/idl/RTCSkel.h>
00027 #include <rtm/SystemLogger.h>
00028
00029
00030
00031 #define NUM_OF_LIFECYCLESTATE 4
00032
00033 #ifdef WIN32
00034 #pragma warning( disable : 4290 )
00035 #endif
00036
00037 namespace RTC
00038 {
00039 class RTObject_impl;
00040 };
00041 namespace RTC_impl
00042 {
00043 class RTObjectStateMachine;
00044 typedef RTC::LightweightRTObject_ptr LightweightRTObject_ptr;
00045 typedef RTC::LightweightRTObject_var LightweightRTObject_var;
00066 class ExecutionContextWorker
00067 {
00068 typedef coil::Guard<coil::Mutex> Guard;
00069
00070 public:
00090 ExecutionContextWorker();
00091
00092
00106 virtual ~ExecutionContextWorker(void);
00107
00108
00109
00110
00111 void setECRef(RTC::ExecutionContextService_ptr ref);
00112 RTC::ExecutionContextService_ptr getECRef();
00113
00114
00115
00116
00141 CORBA::Boolean isRunning(void);
00142
00170 RTC::ReturnCode_t start(void);
00171
00198 RTC::ReturnCode_t stop(void);
00199
00233 RTC::ReturnCode_t activateComponent(RTC::LightweightRTObject_ptr comp,
00234 RTObjectStateMachine*& rtobj);
00235 RTC::ReturnCode_t waitActivateComplete(RTObjectStateMachine*& rtobj,
00236 coil::TimeValue timeout = 1.0,
00237 long int cycle = 1000);
00270 RTC::ReturnCode_t deactivateComponent(RTC::LightweightRTObject_ptr comp,
00271 RTObjectStateMachine*& rtobj);
00272 RTC::ReturnCode_t waitDeactivateComplete(RTObjectStateMachine*& rtobj,
00273 coil::TimeValue timeout = 1.0,
00274 long int cycle = 1000);
00275
00307 RTC::ReturnCode_t resetComponent(RTC::LightweightRTObject_ptr com,
00308 RTObjectStateMachine*& rtobj);
00309 RTC::ReturnCode_t waitResetComplete(RTObjectStateMachine*& rtobj,
00310 coil::TimeValue timeout = 1.0,
00311 long int cycle = 1000);
00312
00339 RTC::LifeCycleState getComponentState(RTC::LightweightRTObject_ptr comp);
00340 const char* getStateString(RTC::LifeCycleState state)
00341 {
00342 const char* st[] = {
00343 "CREATED_STATE",
00344 "INACTIVE_STATE",
00345 "ACTIVE_STATE",
00346 "ERROR_STATE"
00347 };
00348 return state >= RTC::CREATED_STATE && state <= RTC::ERROR_STATE ?
00349 st[state] : "";
00350 }
00382 RTC::ReturnCode_t addComponent(RTC::LightweightRTObject_ptr comp);
00383
00401 RTC::ReturnCode_t bindComponent(RTC::RTObject_impl* rtc);
00402
00433 RTC::ReturnCode_t removeComponent(RTC::LightweightRTObject_ptr comp);
00434 RTObjectStateMachine* findComponent(RTC::LightweightRTObject_ptr comp);
00435
00436 bool isAllCurrentState(RTC::LifeCycleState state);
00437 bool isAllNextState(RTC::LifeCycleState state);
00438 bool isOneOfCurrentState(RTC::LifeCycleState state);
00439 bool isOneOfNextState(RTC::LifeCycleState state);
00440
00441 void invokeWorker();
00442 void invokeWorkerPreDo();
00443 void invokeWorkerDo();
00444 void invokeWorkerPostDo();
00445
00446
00447 protected:
00448 void updateComponentList();
00449
00450
00451
00459
00460
00461
00462
00463
00464
00465
00466
00467
00468
00469
00470
00471
00472 protected:
00480 RTC::Logger rtclog;
00481
00482 RTC::ExecutionContextService_var m_ref;
00483
00493 bool m_running;
00494
00502 std::vector<RTC_impl::RTObjectStateMachine*> m_comps;
00503 mutable coil::Mutex m_mutex;
00504 std::vector<RTC_impl::RTObjectStateMachine*> m_addedComps;
00505 mutable coil::Mutex m_addedMutex;
00506 std::vector<RTC_impl::RTObjectStateMachine*> m_removedComps;
00507 mutable coil::Mutex m_removedMutex;
00508 typedef std::vector<RTC_impl::RTObjectStateMachine*>::iterator CompItr;
00509
00510 };
00511 };
00512
00513 #ifdef WIN32
00514 #pragma warning( default : 4290 )
00515 #endif
00516
00517 #endif // RTC_PERIODICEXECUTIONCONTEXT_H