20 #include <coil/Time.h> 21 #include <coil/TimeValue.h> 27 #define DEEFAULT_PERIOD 0.000001 39 : rtclog(
"periodic_ec"), m_running(false), m_svc(true), m_nowait(false)
41 RTC_TRACE((
"PeriodicExecutionContext()"));
44 RTC_DEBUG((
"Actual rate: %d [sec], %d [usec]",
48 m_ref = this->_this();
70 RTC_TRACE((
"PeriodicExecutionContext(owner, rate = %f)", rate));
75 RTC_DEBUG((
"Actual rate: %d [sec], %d [usec]",
79 m_ref = this->_this();
98 RTC_TRACE((
"~PeriodicExecutionContext()"));
163 RTC_PARANOID((
"Sleep: %f [s]", (
double)(m_period - (t1 - t0))));
212 throw (CORBA::SystemException)
226 throw (CORBA::SystemException)
256 throw (CORBA::SystemException)
282 throw (CORBA::SystemException)
297 throw (CORBA::SystemException)
309 RTC_DEBUG((
"Actual rate: %d [sec], %d [usec]",
325 throw (CORBA::SystemException)
342 #else // ORB_IS_RTORB 343 for (
int i(0); i < (int)
m_comps.size() ; ++i)
345 if(
m_comps.at(i)._ref->_is_equivalent(comp))
357 #endif // ORB_IS_RTORB 369 throw (CORBA::SystemException)
385 const double usec_per_sec(1.0e6);
386 double sleeptime(10.0 * usec_per_sec /
get_rate());
394 RTC_ERROR((
"The component is not responding."));
401 RTC_TRACE((
"The component has been properly deactivated."));
404 RTC_ERROR((
"The component could not be deactivated."));
406 #else // ORB_IS_RTORB 407 for (
int i(0); i < (int)
m_comps.size(); ++i)
409 if(
m_comps.at(i)._ref->_is_equivalent(comp))
417 const double usec_per_sec(1.0e6);
418 double sleeptime(usec_per_sec /
get_rate());
422 RTC_TRACE((
"Waiting to be the INACTIVE state"));
427 RTC_ERROR((
"The component is not responding."));
434 RTC_TRACE((
"The component has been properly deactivated."));
437 RTC_ERROR((
"The component could not be deactivated."));
442 #endif // ORB_IS_RTORB 454 throw (CORBA::SystemException)
479 throw (CORBA::SystemException)
491 return it->_sm.m_sm.getState();
492 #else // ORB_IS_RTORB 493 for (
int i(0); i < (int)
m_comps.size(); ++i)
495 if(
m_comps.at(i)._ref->_is_equivalent(comp))
497 return m_comps.at(i)._sm.m_sm.getState();
501 #endif // ORB_IS_RTORB 512 throw (CORBA::SystemException)
527 throw (CORBA::SystemException)
534 OpenRTM::DataFlowComponent_var dfp;
535 dfp = OpenRTM::DataFlowComponent::_narrow(comp);
536 RTC::RTObject_var rtc;
537 rtc = RTC::RTObject::_narrow(comp);
539 if(CORBA::is_nil(dfp) || CORBA::is_nil(rtc))
544 id = dfp->attach_context(
m_ref);
549 catch (CORBA::Exception& e)
562 LightweightRTObject_var comp = RTC::RTObject::_duplicate(rtc->
getObjRef());
563 OpenRTM::DataFlowComponent_var dfp;
564 dfp = OpenRTM::DataFlowComponent::_narrow(comp);
570 RTC_ERROR((
"bindContext returns invalid id: %d",
id));
573 RTC_DEBUG((
"bindContext returns id = %d",
id));
577 m_profile.owner = RTC::RTObject::_duplicate(dfp);
591 throw (CORBA::SystemException)
599 RTC_TRACE((
"remove_component(): no RTC found in this context."));
605 c.
_ref = RTC::LightweightRTObject::_nil();
607 RTC_TRACE((
"remove_component(): an RTC removed from this context."));
610 RTObject_var rtcomp = RTObject::_narrow(comp);
611 if (CORBA::is_nil(rtcomp))
613 RTC_ERROR((
"Invalid object reference."));
635 throw (CORBA::SystemException)
638 ExecutionContextProfile_var p;
659 RTC::ECCreate<RTC::PeriodicExecutionContext>,
660 RTC::ECDelete<RTC::PeriodicExecutionContext>);
#define RTC_ERROR(fmt)
Error log output macro.
EXECUTION_HANDLE_TYPE_NATIVE ExecutionContextHandle_t
virtual ReturnCode_t remove_component(LightweightRTObject_ptr comp)
Remove the RT-Component from participant list.
long int sec() const
Get value of second time scale.
unsigned int sleep(unsigned int seconds)
Stop a processing at specified second time.
UniqueId bindContext(ExecutionContext_ptr exec_context)
std::vector< Comp > m_comps
List of the participating component.
virtual RTC::ReturnCode_t bindComponent(RTObject_impl *rtc)
Bind the component.
The structure for the component management.
bool m_svc
The thread running flag of ExecutionContext.
DFP< OpenRTM::DataFlowComponent_var > _sm
virtual ReturnCode_t add_component(LightweightRTObject_ptr comp)
Add an RT-component.
void PeriodicExecutionContextInit(RTC::Manager *manager)
Initialization function to register to ECFactory.
virtual CORBA::Boolean is_running(void)
Check for ExecutionContext running state.
virtual int open(void *args)
Generate internal activity thread for ExecutionContext.
Functor to invoke worker.
virtual int close(unsigned long flags)
Thread execution function for ExecutionContext.
PeriodicExecutionContext()
Default Constructor.
Worker m_worker
A condition variable for external triggered worker.
#define RTC_PARANOID(fmt)
Paranoid level log output macro.
virtual int wait(void)
Waiting for the thread terminate.
int gettimeofday(struct timeval *tv, struct timezone *tz)
Get the time and timezone.
bool m_nowait
Flag of ExecutionContext to run immediately (to run without waiting)
#define RTC_DEBUG(fmt)
Debug level log output macro.
Functor to invoke on_rate_changed.
virtual ReturnCode_t start(void)
Start the ExecutionContext.
coil::Mutex m_profileMutex
Functor to invoke on_startup.
virtual ReturnCode_t activate_component(LightweightRTObject_ptr comp)
Activate an RT-component.
void erase_if(CorbaSequence &seq, Functor f)
Remove an element of a sequence according to a predicate.
coil::Condition< coil::Mutex > cond_
virtual ReturnCode_t reset_component(LightweightRTObject_ptr comp)
Reset the RT-component.
bool registerECFactory(const char *name, ECNewFunc new_func, ECDeleteFunc delete_func)
Register ExecutionContext Factory.
virtual ReturnCode_t stop(void)
Stop the ExecutionContext.
virtual ReturnCode_t deactivate_component(LightweightRTObject_ptr comp)
Deactivate an RT-component.
virtual ~PeriodicExecutionContext(void)
Destructor.
virtual ReturnCode_t set_rate(CORBA::Double rate)
Set execution rate(Hz) of ExecutionContext.
Logger rtclog
Logger stream.
virtual ExecutionKind get_kind(void)
Get the ExecutionKind.
ExecutionContextProfile m_profile
ExecutionContextProfile.
PeriodicExecutionContext class.
std::vector< Comp >::iterator CompItr
virtual int svc(void)
Thread execution function for ExecutionContext.
void push_back(CorbaSequence &seq, SequenceElement elem)
Push the new element back to the CORBA sequence.
ExecutionContextService_var m_ref
Reference to ExecutionContextService object.
ExecutionContextHandle_t ec_id
ID of participating ExecutionContext.
long int usec() const
Get value of micro second time scale.
bool m_running
The running state of ExecutionContext true: running, false: stopped.
virtual LifeCycleState get_component_state(LightweightRTObject_ptr comp)
Get RT-component's state.
LightweightRTObject_var _ref
virtual CORBA::Double get_rate(void)
Get execution rate(Hz) of ExecutionContext.
Functor to invoke on_shutdown.
coil::TimeValue m_period
Execution cycle of ExecutionContext.
Functor to find the component.
Functor for_each(CorbaSequence &seq, Functor f)
Apply the functor to all CORBA sequence elements.
virtual ExecutionContextProfile * get_profile(void)
Get the ExecutionContextProfile.
RTC::Local::ExecutionContextProfile ExecutionContextProfile
RTObject_ptr getObjRef() const
[local interface] Get the object reference
int usleep(useconds_t usec)
Stop a processing at specified micro second time.
virtual void activate()
Create a thread.