DUECA/DUSIME
|
This is an activity that uses one of two GenericCallback objects to allow your module to do something. More...
#include <CriticalActivity.hxx>
Public Member Functions | |
CriticalActivity (Module *owner, const char *my_name, GenericCallback *fwork, GenericCallback *fsafe, const PrioritySpec &spec) | |
Constructor. | |
~CriticalActivity () | |
Destructor. | |
void | switchWork (const TimeSpec &time) |
Specify the time from which the activity will be switched to working mode. | |
void | switchSafe (const TimeSpec &time) |
Specify the time from which the activity will be switched to safe mode. | |
bool | isWorking (const TimeSpec &ts) const |
Query whether this activity is in work mode. | |
bool | Working (const TimeSpec &ts) const __attribute__((deprecated)) |
Obsolete version of the above. | |
TimeSpec | trimToWorkPeriod (const TimeSpec &ts) |
Trim a time spec to the work period. | |
void | criticalError () |
Flag an error for this activity. | |
bool | stoppedByError () |
Check whether we were stopped by error or just stopped. | |
void | resetErrorCondition () |
Reset the error condition. | |
bool | firstWorkCycle (const TimeSpec &ts) |
Is this the first run after the activity has been switched to normal work? | |
bool | lastWorkCycle (const TimeSpec &ts) |
Indicates whether this is the last cycle before the activity will be switched to safe mode. | |
Public Member Functions inherited from dueca::Activity | |
Activity (const GlobalId &owner, const char *my_name, const PrioritySpec &s) | |
Constructor. | |
virtual | ~Activity () |
Destructor. | |
void | switchOn (const TimeTickType &time=0) |
Specify the time from which the Activity is switched on. | |
void | switchOff (const TimeTickType &time=0) |
Specify the time when this Activity should be switched off. | |
void | switchOn (const TimeSpec &time) |
Specify the time from which the Activity is switched on. | |
void | switchOff (const TimeSpec &time) |
Specify the time when this Activity should be switched off. | |
void | setTimeSpec (const TimeSpec &ts) |
Supply a periodic time specification to the activity. | |
void | changePriority (const PrioritySpec &s) |
Change the priority spec. | |
void | print (ostream &os) |
Print to stream, for debugging purposes. | |
int | noScheduledBehind () const |
Find out how many more instances of this activity are scheduled. | |
int | numScheduledBehind () const |
Find out how many more instances of this activity are scheduled. | |
TimingCheck * | getCheck () |
Return a pointer to the check associated with this activity. | |
const vstring & | getName () const |
Return the name of the activity. | |
const std::string & | getTargetName () const |
As an activity target. | |
void | logBlockingWait () |
If your activity does blocking waits (file io etc.), it might be neat to report that, so that logging facilities can correctly interpret run times. | |
void | logBlockingWaitOver () |
Report that the blocking wait is over. | |
bool | firstCycle (const TimeSpec &ts=TimeSpec(0, 0)) |
Is this the first run after the activity has been switched on? | |
bool | lastCycle (const TimeSpec &ts=TimeSpec(0, 0)) |
Is this the last cycle before the activity will be switched off? | |
bool | isBraking () |
Indicate that the system has been commanded to stop. | |
Static Public Member Functions | |
static bool | criticalErrorNodeWide () |
Flag a global critical error. | |
Friends | |
class | Environment |
Environment may set the node to safe. | |
class | ActivityItem |
Only an ActivityItem may use despatch. | |
Additional Inherited Members | |
Public Types inherited from dueca::Activity | |
enum | RunState { Off , Last , Ready , Braking , Running , ReadyWork , FirstWork , RunningWork , BrakingWork , LastWork } |
To track the run state, and signal about first/last/work etc. More... | |
Public Attributes inherited from dueca::Activity | |
GlobalId | owner |
Owner of this activity. | |
int | activity_id |
Integer handle, unique within a node. | |
PrioritySpec | prio_spec |
Priority of the activity. | |
RunState | run_state |
Runstate of the activity, to save cycles on switch logic. | |
TimeTickType | switch_on |
Indicates the time from which this activity is switched on. | |
TimeTickType | switch_off |
Indicates the time until which this activity is switched on. | |
PeriodicTimeSpec * | time_spec |
Periodic timing specification for this activity. | |
TimingCheck * | check |
Pointer to a TimingCheck object. | |
ActivityManager * | my_manager |
A pointer to this activity's ActivityManager. | |
int | no_schedules |
Count of the number of times the activity has been scheduled. | |
int | no_despatches |
Count of the number of times the activity has been run. | |
vstring | name |
string format name. | |
Protected Member Functions inherited from dueca::Activity | |
int | getOrder () const |
Return the "order" part of the priority. | |
const GlobalId & | getOwner () |
Return the id of the owner of the activity. | |
bool | isInRunPeriod (const DataTimeSpec &ts) |
Test whether activation is appropriate. | |
DataTimeSpec | trimToRunPeriod (const DataTimeSpec &ts) |
Trim a time spec to the run period. | |
unsigned int | getDescriptionId () const |
Return the id of the activity. | |
void | trigger (const DataTimeSpec &t, unsigned idx) |
Override of the trigger method from the TriggerTarget class. | |
This is an activity that uses one of two GenericCallback objects to allow your module to do something.
The primary activity is useful in the simulation, the secondary activity is necessary for safety. Use this if you have to control a device.
Use objects of this class if you want to "do" something in a DUECA process. The common use is to create Callback objects which call back functions in your class, and then create a CriticalActivity object that takes the Callback objects as an argument. Then, as needed, switch the Activity on and off, and supply a PeriodicTimeSpec to your own taste.
In your header
In the initialisation list of your constructor:
Where OneOfMyFunctions has to have the following type:
Commonly used member functions are:
dueca::CriticalActivity::CriticalActivity | ( | Module * | owner, |
const char * | my_name, | ||
GenericCallback * | fwork, | ||
GenericCallback * | fsafe, | ||
const PrioritySpec & | spec ) |
Constructor.
Constructing an ActivityCallback object is a metafor for allocating/requesting thread of control from DUECA.
owner | A pointer to your module, use the "this" pointer. |
my_name | A name (character string) for the Activity. |
fsafe | GenericCallback object that points to your "safe" function. |
fwork | GenericCallback object that points to your simulation work function. |
spec | Priority specification. |
Specify the time from which the activity will be switched to safe mode.
Do not use this call in case of emergency (error or otherwise), because the switch might take place in the future. Use CriticalActivity::criticalError() instead.
void dueca::CriticalActivity::criticalError | ( | ) |
Flag an error for this activity.
This will switch the activity immediately to safe state, and set the "stopped by error" variable. The move to safe state is limited to this activity only.
Flag a global critical error.
This will set all critical activities to run in safe mode.
|
inline |
Check whether we were stopped by error or just stopped.
Once this activity has been stopped by error, it will only execute safe mode; the application will have to reset the error condition to get back into production again.
|
inline |
Reset the error condition.
Use with utmost care, or don't use at all! Note that your application will only run in safe mode once stopped.
Is this the first run after the activity has been switched to normal work?
Note that this tests on the TimeSpec, it works with clock or stream channel driven activities with regular activation, it might mis-fire on activities driven by event channels.
Indicates whether this is the last cycle before the activity will be switched to safe mode.
Note that this tests on the TimeSpec, it works with clock or stream channel driven activities with regular activation, it might mis-fire on activities driven by event channels.