AAO DRAMA/DRAMA2 C++ Interface
Public Member Functions | List of all members
drama::thread::KickNotifier Class Reference

Detailed Description

An object used to obtain notifications of kicks.

A KickNotifier object is used to allow blocking threaded action code to be notified if a Kick message is received for the action. This must be executed from a threaded action or a child thread of such an action.

The constructor will create a child thread which will wait for the DRAMA action (specified to the constructor) to be kicked. When kicked, the Kicked() method is invoked (in the context of the child thread). User code can sub-class and override Kicked() as required, or poll via the WasKicked() method to determine if the action has been kicked.

The destructor will destroy the child thread.

#include "threadaction.hh"

Public Member Functions

 KickNotifier (TAction *action)
 KickNotifier constructor. More...
 
 KickNotifier (const KickNotifier &source)=delete
 Copy constructor - deleted. More...
 
virtual ~KickNotifier ()
 Destructor. More...
 
virtual bool Kicked (const sds::Id &arg)
 Method invoked when a Kick occurs. More...
 
KickNotifieroperator= (const KickNotifier &rhs)=delete
 Assignment operator - deleted. More...
 
bool WasKicked ()
 Indicates if the action was kicked. More...
 

Constructor & Destructor Documentation

drama::thread::KickNotifier::KickNotifier ( TAction action)

KickNotifier constructor.

Constructs a KickNotifier object, used to allow blocking action code to be notified if a Kick is received by the action. This must be executed from a threaded action or a child thread of such an action.

User code should ensure an object of this type or a sub-class is constructed before the blocking code, and destroyed after it is finished.

The constructor will create a thread that will wait for notification from DRAMA that the action has been kicked. When a kick occurs, the Kicked() method with will be invoked. A sub-class code can override the Kicked() method to do something appropriate to cause the blocked code to unblock.

Alternatively, user code can invoke the WasKicked() method to determine if a kick has occurred.

virtual drama::thread::KickNotifier::~KickNotifier ( )
virtual

Destructor.

Ensure the thread is unblocked and then join it.

drama::thread::KickNotifier::KickNotifier ( const KickNotifier source)
delete

Copy constructor - deleted.

Member Function Documentation

virtual bool drama::thread::KickNotifier::Kicked ( const sds::Id arg)
virtual

Method invoked when a Kick occurs.

User code can override this in a sub-class to arrange to be notified when a kick occurs.

A sub-class author must determine the sensible thing to do when this is invoked, which will depend on why the action code is blocked. They may need to cancel I/O or break out of a CPU intensive operation. The most dramatic approach would be to use setjmp() and longjmp(), but in that case care must be taken over the management of resources (i.e. don't jump such as to avoid running destructors, ensure the KickNotifier destructor is run.).

Note
Will be run in a separate thread from the thread that constructed the KickNotifier object.
Returns
Return true to indicate we should wait for another kick. Return false to indicate the notifier thread should complete, normally this means the blocked code has been unblocked.
Parameters
argArgument to the kick, if any.
KickNotifier& drama::thread::KickNotifier::operator= ( const KickNotifier rhs)
delete

Assignment operator - deleted.

bool drama::thread::KickNotifier::WasKicked ( )
inline

Indicates if the action was kicked.

References drama::thread::TAction::GetTask().


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

Click here for the DRAMA home page and here for the AAO home page.

For more information, contact tjf@aao.gov.au 

Generated on Mon Feb 22 2016 15:57:53 for AAO DRAMA/DRAMA2 C++ Interface by doxygen 1.8.10