DUECA/DUSIME
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Friends | List of all members
dueca::CriticalActivity Class Reference

This is an activity that uses one of two GenericCallback objects to allow your module to do something. More...

#include <CriticalActivity.hxx>

Inheritance diagram for dueca::CriticalActivity:
Inheritance graph
[legend]
Collaboration diagram for dueca::CriticalActivity:
Collaboration graph
[legend]

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.
 
TimingCheckgetCheck ()
 Return a pointer to the check associated with this activity.
 
const vstringgetName () 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.
 
PeriodicTimeSpectime_spec
 Periodic timing specification for this activity.
 
TimingCheckcheck
 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 GlobalIdgetOwner ()
 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.
 

Detailed Description

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

CriticalActivity my_activity;
This is an activity that uses one of two GenericCallback objects to allow your module to do something...
Definition CriticalActivity.hxx:64
This is a "light weight object" that enables you to read the latest set of data on a StreamChannelEnd...
Definition StreamReaderLatest.hxx:43

In the initialisation list of your constructor:

cbwork(this, &MyClass::OneOfMyFunctions),
cbsafe(this, &MyClass::AnotherOfMyFunctions),
my_activity(this, "my activity", &cbwork, &cbsafe, priority_spec),

Where OneOfMyFunctions has to have the following type:

void OneOfMyFunctions(const TimeSpec& ts);
A TimeSpec is a specification for a time interval.
Definition TimeSpec.hxx:71

Commonly used member functions are:

Constructor & Destructor Documentation

◆ CriticalActivity()

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.

Parameters
ownerA pointer to your module, use the "this" pointer.
my_nameA name (character string) for the Activity.
fsafeGenericCallback object that points to your "safe" function.
fworkGenericCallback object that points to your simulation work function.
specPriority specification.

Member Function Documentation

◆ switchSafe()

void dueca::CriticalActivity::switchSafe ( const TimeSpec & time)

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.

◆ criticalError()

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.

◆ criticalErrorNodeWide()

static bool dueca::CriticalActivity::criticalErrorNodeWide ( )
static

Flag a global critical error.

This will set all critical activities to run in safe mode.

◆ stoppedByError()

bool dueca::CriticalActivity::stoppedByError ( )
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.

◆ resetErrorCondition()

void dueca::CriticalActivity::resetErrorCondition ( )
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.

◆ firstWorkCycle()

bool dueca::CriticalActivity::firstWorkCycle ( const TimeSpec & ts)
inline

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.

◆ lastWorkCycle()

bool dueca::CriticalActivity::lastWorkCycle ( const TimeSpec & ts)
inline

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.


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