An Activity executes a RunnableInterface object in a (periodic) thread. More...
#include <Activity.hpp>
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::ThreadInterface * | thread () |
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 RunnableInterface * | getRunner () 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_TASK * | getTask () |
virtual const RTOS_TASK * | getTask () 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 | |
RunnableInterface * | runner |
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< ActivityInterface > | shared_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 |
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.
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.
_r | The optional runner, if null, this->loop() is called. |
name | The 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.
priority | The priority of this activity. |
r | The optional base::RunnableInterface to run exclusively within this Activity |
name | The 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.
priority | The priority of this activity. |
period | The periodicity of the Activity. A zero is interpreted as non periodic. |
r | The optional base::RunnableInterface to run exclusively within this Activity |
name | The 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.
scheduler | The scheduler in which the activity's thread must run. Use ORO_SCHED_OTHER or ORO_SCHED_RT. |
priority | The priority of this activity. |
r | The optional base::RunnableInterface to run exclusively within this Activity |
name | The 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.
scheduler | The scheduler in which the activity's thread must run. Use ORO_SCHED_OTHER or ORO_SCHED_RT. |
priority | The priority of this activity. |
period | The periodicity of the Activity |
r | The optional base::RunnableInterface to run exclusively within this Activity |
name | The 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.
scheduler | The scheduler in which the activity's thread must run. Use ORO_SCHED_OTHER or ORO_SCHED_RT. |
priority | The priority of this activity. |
period | The periodicity of the Activity |
cpu_affinity | The prefered cpu to run on (a mask) |
r | The optional base::RunnableInterface to run exclusively within this Activity |
name | The name of the underlying thread. |
Definition at line 95 of file Activity.cpp.
|
virtual |
Stops and terminates a Activity
Definition at line 105 of file Activity.cpp.
|
virtual |
Reimplemented from RTT::os::Thread.
Reimplemented in ConcurrencyPortsTestFixture::PortConnectorThread, ConcurrencyPortsTestFixture::PortReaderThread< T >, ConcurrencyPortsTestFixture::PortWriterThread< T >, RTT::corba::OrbRunner, RTT::extras::FileDescriptorActivity, RTT::corba::CorbaDispatcher, and RTT::mqueue::Dispatcher.
Definition at line 263 of file Activity.cpp.
|
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().
true | When this->isActive() and the implementation allows external executes. |
false | When !this->isActive() or the implementation does not allow external updating. |
Implements RTT::base::ActivityInterface.
Definition at line 157 of file Activity.cpp.
|
virtual |
Reimplemented from RTT::os::Thread.
Reimplemented in RTT::corba::OrbRunner.
Definition at line 269 of file Activity.cpp.
|
virtual |
Get the cpu affinity of this activity
Implements RTT::base::ActivityInterface.
Definition at line 340 of file Activity.cpp.
|
virtual |
Get the periodicity of this activity in Seconds
Implements RTT::base::ActivityInterface.
Reimplemented in RTT::extras::FileDescriptorActivity.
Definition at line 143 of file Activity.cpp.
|
virtual |
Reimplemented from RTT::os::Thread.
Reimplemented in RTT::corba::CorbaDispatcher, and RTT::mqueue::Dispatcher.
Definition at line 118 of file Activity.cpp.
|
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.
Implements RTT::base::ActivityInterface.
Definition at line 332 of file Activity.cpp.
|
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().
Implements RTT::base::ActivityInterface.
Definition at line 336 of file Activity.cpp.
|
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.
Implements RTT::base::ActivityInterface.
Reimplemented in RTT::extras::FileDescriptorActivity.
Definition at line 328 of file Activity.cpp.
|
virtual |
Reimplemented from RTT::os::Thread.
Reimplemented in RTT::corba::OrbRunner, RTT::extras::FileDescriptorActivity, RTT::corba::CorbaDispatcher, and RTT::mqueue::Dispatcher.
Definition at line 173 of file Activity.cpp.
|
virtual |
Set the cpu affinity of this activity.
Implements RTT::base::ActivityInterface.
Definition at line 345 of file Activity.cpp.
|
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.
Implements RTT::base::ActivityInterface.
Reimplemented in RTT::extras::FileDescriptorActivity.
Definition at line 134 of file Activity.cpp.
|
virtual |
Set the wait policy of a periodic thread
The | wait 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.
|
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.
Implements RTT::base::ActivityInterface.
Reimplemented in RTT::extras::FileDescriptorActivity, and RTT::extras::IRQActivity.
Definition at line 275 of file Activity.cpp.
|
virtual |
Reimplemented from RTT::os::Thread.
Reimplemented in ConcurrencyPortsTestFixture::PortConnectorThread, ConcurrencyPortsTestFixture::PortReaderThread< T >, ConcurrencyPortsTestFixture::PortWriterThread< T >, and RTT::extras::FileDescriptorActivity.
Definition at line 124 of file Activity.cpp.
|
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.
Implements RTT::base::ActivityInterface.
Reimplemented in RTT::extras::FileDescriptorActivity.
Definition at line 280 of file Activity.cpp.
|
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.
|
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.
|
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.
true | When this->isActive() and the implementation allows external triggers. |
false | When !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.
|
virtual |
Reimplemented in RTT::extras::FileDescriptorActivity.
Definition at line 129 of file Activity.cpp.
|
protected |
Definition at line 224 of file Activity.hpp.
|
protected |
Definition at line 223 of file Activity.hpp.
|
protected |
Definition at line 234 of file Activity.hpp.
|
protected |
When set to true, a next cycle will be a TimeOut cycle.
Definition at line 233 of file Activity.hpp.
|
protected |
Definition at line 235 of file Activity.hpp.
|
protected |
The period at which the Activity steps().
Definition at line 228 of file Activity.hpp.