OpenRTM-aist  2.1.0
PeriodicExecutionContext.h
Go to the documentation of this file.
1 // -*- C++ -*-
19 #ifndef RTC_PERIODICEXECUTIONCONTEXT2_H
20 #define RTC_PERIODICEXECUTIONCONTEXT2_H
21 
22 #include <coil/Task.h>
23 #include <condition_variable>
24 #include <coil/Affinity.h>
25 
27 
28 #include <vector>
29 #include <iostream>
30 
31 #define NUM_OF_LIFECYCLESTATE 4
32 
33 namespace RTC_exp
34 {
56  : public virtual POA_RTC::ExecutionContextService,
57  public virtual PortableServer::RefCountServantBase,
59  public coil::Task
60  {
61  public:
82 
97 
111  void init(coil::Properties& props) override;
112 
137  int open(void *args) override;
138 
158  int svc() override;
159 
187  int close(unsigned long flags) override;
188 
189  //============================================================
190  // ExecutionContext
191  //============================================================
216  CORBA::Boolean is_running() override;
217 
245  RTC::ReturnCode_t start() override;
246 
273  RTC::ReturnCode_t stop() override;
274 
295  CORBA::Double get_rate() override;
296 
326  RTC::ReturnCode_t set_rate(CORBA::Double rate) override;
327 
361  RTC::ReturnCode_t
363 
396  RTC::ReturnCode_t
398 
430  RTC::ReturnCode_t
432 
459  RTC::LifeCycleState
461 
481  RTC::ExecutionKind get_kind() override;
482 
514  RTC::ReturnCode_t add_component(RTC::LightweightRTObject_ptr comp) override;
515 
546  RTC::ReturnCode_t
548 
568  RTC::ExecutionContextProfile* get_profile() override;
569 
570  protected:
571  template <class T>
572  void getProperty(coil::Properties& prop, const char* key, T& value)
573  {
574  if (prop.findNode(key) != nullptr)
575  {
576  T tmp;
577  if (coil::stringTo(tmp, prop[key].c_str()))
578  {
579  value = tmp;
580  }
581  }
582  }
586  RTC::ReturnCode_t onStarted() override;
590  RTC::ReturnCode_t onStopping() override;
591  // template virtual functions adding/removing component
595  RTC::ReturnCode_t
600  RTC::ReturnCode_t
602 
606  RTC::ReturnCode_t
607  onWaitingActivated(RTC_impl::RTObjectStateMachine* comp, long int count) override;
611  RTC::ReturnCode_t
612  onActivated(RTC_impl::RTObjectStateMachine* comp, long int count) override;
616  RTC::ReturnCode_t
617  onWaitingDeactivated(RTC_impl::RTObjectStateMachine* comp, long int count) override;
621  RTC::ReturnCode_t
622  onDeactivated(RTC_impl::RTObjectStateMachine* comp, long int count) override;
626  RTC::ReturnCode_t
627  onWaitingReset(RTC_impl::RTObjectStateMachine* comp, long int count) override;
631  RTC::ReturnCode_t
632  onReset(RTC_impl::RTObjectStateMachine* comp, long int count) override;
633 
637  virtual void setCpuAffinity(coil::Properties& props);
638 
640  {
641  std::lock_guard<std::mutex> guard(m_svcmutex);
642  return m_svc;
643  }
644  protected:
652  RTC::Logger rtclog{"periodic_ec"};
653 
661  bool m_svc{false};
662  std::mutex m_svcmutex;
663 
672  {
674  std::mutex mutex_;
675  std::condition_variable cond_;
676  bool running_{false};
677  };
678 
687 
696  bool m_nowait{false};
697 
701  coil::CpuMask m_cpu;
702 
703  }; // class PeriodicExecutionContext
704 } // namespace RTC_exp
705 
706 
707 extern "C"
708 {
717 }
718 
719 #endif // RTC_PERIODICEXECUTIONCONTEXT_H
ExecutionContext base class.
void PeriodicExecutionContextInit(RTC::Manager *manager)
Initialization function to register to ECFactory.
A base class for ExecutionContext.
Definition: ExecutionContextBase.h:366
Logger class.
Definition: SystemLogger.h:101
Manager class.
Definition: Manager.h:91
PeriodicExecutionContext class.
Definition: PeriodicExecutionContext.h:60
bool m_svc
The thread running flag of ExecutionContext.
Definition: PeriodicExecutionContext.h:661
std::mutex m_svcmutex
Definition: PeriodicExecutionContext.h:662
RTC::ExecutionContextProfile * get_profile() override
Get the ExecutionContextProfile.
coil::CpuMask m_cpu
CPU affinity mask list.
Definition: PeriodicExecutionContext.h:701
RTC::ReturnCode_t activate_component(RTC::LightweightRTObject_ptr comp) override
Activate an RT-component.
RTC::ReturnCode_t start() override
Start the ExecutionContext.
RTC::ReturnCode_t onReset(RTC_impl::RTObjectStateMachine *comp, long int count) override
onReset() template function
PeriodicExecutionContext()
Default Constructor.
RTC::ReturnCode_t onRemovedComponent(RTC::LightweightRTObject_ptr rtobj) override
onRemovedComponent() template function
bool threadRunning()
Definition: PeriodicExecutionContext.h:639
RTC::ReturnCode_t add_component(RTC::LightweightRTObject_ptr comp) override
Add an RT-component.
~PeriodicExecutionContext() override
Destructor.
void init(coil::Properties &props) override
Initialize the ExecutionContext.
void getProperty(coil::Properties &prop, const char *key, T &value)
Definition: PeriodicExecutionContext.h:572
WorkerThreadCtrl m_workerthread
A condition variable for external triggered worker.
Definition: PeriodicExecutionContext.h:686
CORBA::Boolean is_running() override
Check for ExecutionContext running state.
RTC::ReturnCode_t set_rate(CORBA::Double rate) override
Set execution rate(Hz) of ExecutionContext.
CORBA::Double get_rate() override
Get execution rate(Hz) of ExecutionContext.
RTC::LifeCycleState get_component_state(RTC::LightweightRTObject_ptr comp) override
Get RT-component's state.
RTC::ReturnCode_t stop() override
Stop the ExecutionContext.
RTC::ReturnCode_t onAddedComponent(RTC::LightweightRTObject_ptr rtobj) override
onAddedComponent() template function
RTC::ReturnCode_t deactivate_component(RTC::LightweightRTObject_ptr comp) override
Deactivate an RT-component.
RTC::ReturnCode_t onActivated(RTC_impl::RTObjectStateMachine *comp, long int count) override
onActivated() template function
RTC::ReturnCode_t remove_component(RTC::LightweightRTObject_ptr comp) override
Remove the RT-Component from participant list.
RTC::ReturnCode_t reset_component(RTC::LightweightRTObject_ptr comp) override
Reset the RT-component.
int close(unsigned long flags) override
Thread execution function for ExecutionContext.
RTC::ExecutionKind get_kind() override
Get the ExecutionKind.
RTC::Logger rtclog
Logger stream.
Definition: PeriodicExecutionContext.h:652
bool m_nowait
Flag of ExecutionContext to run immediately (to run without waiting)
Definition: PeriodicExecutionContext.h:696
RTC::ReturnCode_t onWaitingDeactivated(RTC_impl::RTObjectStateMachine *comp, long int count) override
onWaitingDeactivated() template function
RTC::ReturnCode_t onStopping() override
onStopping() template function
RTC::ReturnCode_t onWaitingReset(RTC_impl::RTObjectStateMachine *comp, long int count) override
onWaitingReset() template function
RTC::ReturnCode_t onStarted() override
onStarted() template function
virtual void setCpuAffinity(coil::Properties &props)
setting CPU affinity from given properties
RTC::ReturnCode_t onWaitingActivated(RTC_impl::RTObjectStateMachine *comp, long int count) override
onWaitingActivated() template function
int svc() override
Thread execution function for ExecutionContext.
int open(void *args) override
Generate internal activity thread for ExecutionContext.
RTC::ReturnCode_t onDeactivated(RTC_impl::RTObjectStateMachine *comp, long int count) override
onDeactivated() template function
Definition: RTObjectStateMachine.h:43
Definition: MultilayerCompositeEC.h:28
RTC::LightweightRTObject_ptr LightweightRTObject_ptr
Definition: ExecutionContextWorker.h:37
coil::Properties Properties
Definition: RTC.h:72
Condition variable class for worker.
Definition: PeriodicExecutionContext.h:672
std::mutex mutex_
Definition: PeriodicExecutionContext.h:674
WorkerThreadCtrl()
Definition: PeriodicExecutionContext.h:673
std::condition_variable cond_
Definition: PeriodicExecutionContext.h:675
bool running_
Definition: PeriodicExecutionContext.h:676