Public Member Functions | Protected Attributes | List of all members
RTT::Activity Class Reference

An Activity executes a RunnableInterface object in a (periodic) thread. More...

#include <Activity.hpp>

Inheritance diagram for RTT::Activity:
Inheritance graph
[legend]

Public Member Functions

 Activity (base::RunnableInterface *r=0, const std::string &name="Activity")
 Create a not real-time Activity. This creates a not real-time, non-periodic thread, with priority equal to RTT::os::LowestPriority. More...
 
 Activity (int priority, base::RunnableInterface *r=0, const std::string &name="Activity")
 Create a real-time Activity with a given priority. The thread is run in the ORO_SCHED_RT scheduler. More...
 
 Activity (int priority, Seconds period, base::RunnableInterface *r=0, const std::string &name="Activity")
 Create a real-time Activity with a given priority and period. The thread is run in the ORO_SCHED_RT scheduler. More...
 
 Activity (int scheduler, int priority, base::RunnableInterface *r=0, const std::string &name="Activity")
 Create an Activity with a given scheduler type and priority. More...
 
 Activity (int scheduler, int priority, Seconds period, base::RunnableInterface *r=0, const std::string &name="Activity")
 Create an Activity with a given scheduler type, priority and period. More...
 
 Activity (int scheduler, int priority, Seconds period, unsigned cpu_affinity, base::RunnableInterface *r=0, const std::string &name="Activity")
 Create an Activity with a given scheduler type, priority, period and cpu affinity. More...
 
virtual bool breakLoop ()
 
virtual bool execute ()
 
virtual void finalize ()
 
virtual unsigned getCpuAffinity () const
 
virtual Seconds getPeriod () const
 
virtual bool initialize ()
 
virtual bool isActive () const
 
virtual bool isPeriodic () const
 
virtual bool isRunning () const
 
virtual void loop ()
 
virtual bool setCpuAffinity (unsigned cpu)
 
virtual bool setPeriod (Seconds period)
 
void setWaitPeriodPolicy (int p)
 
virtual bool start ()
 
virtual void step ()
 
virtual bool stop ()
 
virtual os::ThreadInterfacethread ()
 
virtual bool timeout ()
 
virtual bool trigger ()
 
virtual void work (base::RunnableInterface::WorkReason reason)
 
virtual ~Activity ()
 
- Public Member Functions inherited from RTT::base::ActivityInterface
 ActivityInterface ()
 
 ActivityInterface (RunnableInterface *run)
 
virtual RunnableInterfacegetRunner () const
 
virtual bool run (RunnableInterface *r)
 
virtual ~ActivityInterface ()
 
- Public Member Functions inherited from RTT::os::Thread
virtual int getMaxOverrun () const
 
virtual const char * getName () const
 
void getPeriod (secs &s, nsecs &ns) const
 
virtual nsecs getPeriodNS () const
 
virtual unsigned int getPid () const
 
virtual int getPriority () const
 
virtual int getScheduler () const
 
Seconds getStopTimeout () const
 
virtual RTOS_TASKgetTask ()
 
virtual const RTOS_TASKgetTask () const
 
virtual void setMaxOverrun (int m)
 
bool setPeriod (Seconds s)
 
bool setPeriod (secs s, nsecs ns)
 
bool setPeriod (TIME_SPEC p)
 
virtual bool setPriority (int priority)
 
virtual bool setScheduler (int sched_type)
 
void setStopTimeout (Seconds s)
 
 Thread (int scheduler, int priority, double period, unsigned cpu_affinity, const std::string &name)
 
virtual void yield ()
 
virtual ~Thread ()
 
- Public Member Functions inherited from RTT::os::ThreadInterface
bool isSelf () const
 
 ThreadInterface ()
 
unsigned int threadNumber () const
 
virtual ~ThreadInterface ()
 

Protected Attributes

os::Condition msg_cond
 
os::Mutex msg_lock
 
bool mstopRequested
 
bool mtimeout
 
int mwaitpolicy
 
double update_period
 
- Protected Attributes inherited from RTT::base::ActivityInterface
RunnableInterfacerunner
 
- Protected Attributes inherited from RTT::os::Thread
bool active
 
MutexRecursive breaker
 
bool inloop
 
int maxOverRun
 
int msched_type
 
NANO_TIME period
 
bool prepareForExit
 
RTOS_TASK rtos_task
 
bool running
 
rt_sem_t sem
 
double stopTimeout
 
- Protected Attributes inherited from RTT::os::ThreadInterface
int threadnb
 

Additional Inherited Members

- Public Types inherited from RTT::base::ActivityInterface
typedef boost::shared_ptr< ActivityInterfaceshared_ptr
 
- Static Public Member Functions inherited from RTT::os::Thread
static void setLockTimeoutNoPeriod (double timeout_in_s)
 
static void setLockTimeoutPeriodFactor (double factor)
 
static void setStackSize (unsigned int ssize)
 
- Protected Member Functions inherited from RTT::base::ActivityInterface
void disableRun (RunnableInterface *caller)
 
- Protected Member Functions inherited from RTT::os::Thread
void emergencyStop ()
 
void terminate ()
 
- Static Protected Attributes inherited from RTT::os::Thread
static unsigned int default_stack_size = 0
 
static double lock_timeout_no_period_in_s = 1.0
 
static double lock_timeout_period_factor = 10.0
 

Detailed Description

An Activity executes a RunnableInterface object in a (periodic) thread.

This object implements the base::ActivityInterface and maps that to an OS thread, using the RTT::os::Thread class. One Activity object maps to one OS thread. It can execute periodically the step() function or the loop() function in case of non-periodic execution.

When provided one, it will execute a base::RunnableInterface object, or the equivalent methods in it's own interface when none is given.

For a periodic Activity, when it misses its deadline because user code take too long to execute, it will skip the required number of periodic execution steps in order to be back on time. This is the ORO_WAIT_REL wait policy and can be changed by calling setWaitPeriodPolicy(ORO_WAIT_ABS)

Definition at line 70 of file Activity.hpp.

Constructor & Destructor Documentation

Activity::Activity ( base::RunnableInterface r = 0,
const std::string &  name = "Activity" 
)

Create a not real-time Activity. This creates a not real-time, non-periodic thread, with priority equal to RTT::os::LowestPriority.

Parameters
_rThe optional runner, if null, this->loop() is called.
nameThe name of the underlying thread.

Definition at line 57 of file Activity.cpp.

Activity::Activity ( int  priority,
base::RunnableInterface r = 0,
const std::string &  name = "Activity" 
)

Create a real-time Activity with a given priority. The thread is run in the ORO_SCHED_RT scheduler.

Parameters
priorityThe priority of this activity.
rThe optional base::RunnableInterface to run exclusively within this Activity
nameThe name of the underlying thread.

Definition at line 63 of file Activity.cpp.

Activity::Activity ( int  priority,
Seconds  period,
base::RunnableInterface r = 0,
const std::string &  name = "Activity" 
)

Create a real-time Activity with a given priority and period. The thread is run in the ORO_SCHED_RT scheduler.

Parameters
priorityThe priority of this activity.
periodThe periodicity of the Activity. A zero is interpreted as non periodic.
rThe optional base::RunnableInterface to run exclusively within this Activity
nameThe name of the underlying thread.

Definition at line 69 of file Activity.cpp.

Activity::Activity ( int  scheduler,
int  priority,
base::RunnableInterface r = 0,
const std::string &  name = "Activity" 
)

Create an Activity with a given scheduler type and priority.

Parameters
schedulerThe scheduler in which the activity's thread must run. Use ORO_SCHED_OTHER or ORO_SCHED_RT.
priorityThe priority of this activity.
rThe optional base::RunnableInterface to run exclusively within this Activity
nameThe name of the underlying thread.

Definition at line 79 of file Activity.cpp.

Activity::Activity ( int  scheduler,
int  priority,
Seconds  period,
base::RunnableInterface r = 0,
const std::string &  name = "Activity" 
)

Create an Activity with a given scheduler type, priority and period.

Parameters
schedulerThe scheduler in which the activity's thread must run. Use ORO_SCHED_OTHER or ORO_SCHED_RT.
priorityThe priority of this activity.
periodThe periodicity of the Activity
rThe optional base::RunnableInterface to run exclusively within this Activity
nameThe name of the underlying thread.

Definition at line 85 of file Activity.cpp.

Activity::Activity ( int  scheduler,
int  priority,
Seconds  period,
unsigned  cpu_affinity,
base::RunnableInterface r = 0,
const std::string &  name = "Activity" 
)

Create an Activity with a given scheduler type, priority, period and cpu affinity.

Parameters
schedulerThe scheduler in which the activity's thread must run. Use ORO_SCHED_OTHER or ORO_SCHED_RT.
priorityThe priority of this activity.
periodThe periodicity of the Activity
cpu_affinityThe prefered cpu to run on (a mask)
rThe optional base::RunnableInterface to run exclusively within this Activity
nameThe name of the underlying thread.

Definition at line 95 of file Activity.cpp.

Activity::~Activity ( )
virtual

Stops and terminates a Activity

Definition at line 105 of file Activity.cpp.

Member Function Documentation

bool Activity::breakLoop ( )
virtual
bool Activity::execute ( )
virtual

Execute this activity such that it executes a step or loop of the RunnableInterface. When you invoke execute() you intend to call the step() or loop() methods. Some activity implementations allow a user controlled execute, others ignore it, in which case execute() returns false.

Semantics: If execute() returns true, the activity has been executed exactly once during execute().

Return values
trueWhen this->isActive() and the implementation allows external executes.
falseWhen !this->isActive() or the implementation does not allow external updating.
See also
trigger() for use in callbacks which want execute() to be executed.

Implements RTT::base::ActivityInterface.

Definition at line 157 of file Activity.cpp.

void Activity::finalize ( )
virtual
See also
base::RunnableInterface::finalize()

Reimplemented from RTT::os::Thread.

Reimplemented in RTT::corba::OrbRunner.

Definition at line 269 of file Activity.cpp.

unsigned Activity::getCpuAffinity ( ) const
virtual

Get the cpu affinity of this activity

Returns
The cpu affinity of this activity.

Implements RTT::base::ActivityInterface.

Definition at line 340 of file Activity.cpp.

Seconds Activity::getPeriod ( ) const
virtual

Get the periodicity of this activity in Seconds

Returns
The execution period of this activity (zero if !this->isPeriodic() ).

Implements RTT::base::ActivityInterface.

Reimplemented in RTT::extras::FileDescriptorActivity.

Definition at line 143 of file Activity.cpp.

bool Activity::initialize ( )
virtual
See also
base::RunnableInterface::initialize()

Reimplemented from RTT::os::Thread.

Reimplemented in RTT::corba::CorbaDispatcher, and RTT::mqueue::Dispatcher.

Definition at line 118 of file Activity.cpp.

bool Activity::isActive ( ) const
virtual

Query if the activity is started. This is less strict than isRunning(), it is true during initialize(), step() or loop() and finalize(). Use this method to check if an activity was start()ed.

Returns
true if it is active, false otherwise

Implements RTT::base::ActivityInterface.

Definition at line 332 of file Activity.cpp.

bool Activity::isPeriodic ( ) const
virtual

Inspect if this activity is periodic. If so, it will call RunnableInterface::step(). If the activity is not periodic, it will call RunnableInterface::loop().

Returns
true if periodic.

Implements RTT::base::ActivityInterface.

Definition at line 336 of file Activity.cpp.

bool Activity::isRunning ( ) const
virtual

Query if the activity is initialized and executing. This is more strict than isActive(), it is only true after initialize() is executed and before finalize() is executed. More-over, an Activity may decide to be temporarily not running (not executing code), waiting for a signal to proceed. If this->isActive() and !this->isRunning() then the Activity is in a waiting state.

Returns
true if it is running, false otherwise

Implements RTT::base::ActivityInterface.

Reimplemented in RTT::extras::FileDescriptorActivity.

Definition at line 328 of file Activity.cpp.

void Activity::loop ( )
virtual
bool Activity::setCpuAffinity ( unsigned  cpu)
virtual

Set the cpu affinity of this activity.

Returns
true if it could be updated, false otherwise.

Implements RTT::base::ActivityInterface.

Definition at line 345 of file Activity.cpp.

bool Activity::setPeriod ( Seconds  s)
virtual

Set the periodicity of this activity in Seconds. Note that not all activity implementation support periods. A period of s == 0 indicates non periodic. A non supported setting returns false.

Returns
true if it could be updated, false otherwise.

Implements RTT::base::ActivityInterface.

Reimplemented in RTT::extras::FileDescriptorActivity.

Definition at line 134 of file Activity.cpp.

void Activity::setWaitPeriodPolicy ( int  p)
virtual

Set the wait policy of a periodic thread

Parameters
Thewait policy can be ORO_WAIT_ABS (absolute wait) and ORO_WAIT_REL (relative wait, with respect to current time)

Reimplemented from RTT::os::Thread.

Definition at line 350 of file Activity.cpp.

bool Activity::start ( )
virtual

Start the activity. This will call RunnableInterface::initialize() and upon success, effectively start the activity, by running the RunnableInterface::step() or RunnableInterface::loop() in a thread.

See also
isPeriodic()
Returns
true if the activity is started, false otherwise

Implements RTT::base::ActivityInterface.

Reimplemented in RTT::extras::FileDescriptorActivity, and RTT::extras::IRQActivity.

Definition at line 275 of file Activity.cpp.

void Activity::step ( )
virtual
bool Activity::stop ( )
virtual

Stop the activity This will stop the activity by removing it from the 'run-queue' of a thread or call RunnableInterface::breakLoop(). If no errors occured, RunnableInterface::finalize() is called.

See also
isPeriodic()
Returns
true if the activity is stopped, false otherwise

Implements RTT::base::ActivityInterface.

Reimplemented in RTT::extras::FileDescriptorActivity.

Definition at line 280 of file Activity.cpp.

os::ThreadInterface * Activity::thread ( )
virtual

Returns a pointer to the thread which will run this activity. Will not be null.

Implements RTT::base::ActivityInterface.

Definition at line 114 of file Activity.cpp.

bool Activity::timeout ( )
virtual

Requests this Activity to wakeup and call step() + work(Timeout). Will be ignored for periodic activities, since they use an internal timing mechanism, but can be used for non-periodic activities which want to emulate a timeout happening towards the base::RunnableInterface.

Implements RTT::base::ActivityInterface.

Reimplemented in RTT::extras::FileDescriptorActivity.

Definition at line 162 of file Activity.cpp.

bool Activity::trigger ( )
virtual

Trigger that work has to be done. When you invoke trigger(), you intend to notify the mechanism that calls execute(), that execute() should be called. This allows a separation between actually executing code (execute()) and notifying that code must be executed (trigger()). A trigger may be ignored by the implementation, in which case trigger returns false.

Semantics: If trigger() returns true, the activity will be executed at least once from the moment trigger() is called.

Requests this Activity to wakeup and call step() + work(Trigger). If the thread is periodic, it will continue sleeping for the remainder of the time after the work() has finished.

Return values
trueWhen this->isActive() and the implementation allows external triggers.
falseWhen !this->isActive() or the implementation does not allow external triggering.

Implements RTT::base::ActivityInterface.

Reimplemented in RTT::extras::FileDescriptorActivity.

Definition at line 147 of file Activity.cpp.

void Activity::work ( base::RunnableInterface::WorkReason  reason)
virtual

Reimplemented in RTT::extras::FileDescriptorActivity.

Definition at line 129 of file Activity.cpp.

Member Data Documentation

os::Condition RTT::Activity::msg_cond
protected

Definition at line 224 of file Activity.hpp.

os::Mutex RTT::Activity::msg_lock
protected

Definition at line 223 of file Activity.hpp.

bool RTT::Activity::mstopRequested
protected

Definition at line 234 of file Activity.hpp.

bool RTT::Activity::mtimeout
protected

When set to true, a next cycle will be a TimeOut cycle.

Definition at line 233 of file Activity.hpp.

int RTT::Activity::mwaitpolicy
protected

Definition at line 235 of file Activity.hpp.

double RTT::Activity::update_period
protected

The period at which the Activity steps().

Definition at line 228 of file Activity.hpp.


The documentation for this class was generated from the following files:


rtt
Author(s): RTT Developers
autogenerated on Tue Jun 25 2019 19:33:41