AAO DRAMA/DRAMA2 C++ Interface
|
A class which implements a DRAMA task.
Create one of these objects to turn your program into a DRAMA task. The normal approach is to subclass drama::Task and add actions, parameters and other features within the sub-class.
Use the Task::Add and Task::AddSpawnable methods to add actions to your task. Create drama::Parameter objects to add DRAMA Parameters to your task. Execute Task::RunDrama() to run your DRAMA task (read and dispatch messages).
#include "task.hh"
Public Types | |
typedef std::lock_guard< mutexType > | guardType |
Defines the type of a lock guard using our mutex type. More... | |
typedef std::recursive_timed_mutex | mutexType |
Defines the type of our mutex. More... | |
typedef std::unique_lock< mutexType > | uniqueLockType |
Defines the type of a unique_lock type using our mutex type. More... | |
Public Member Functions | |
Task (const std::string &name, int buffer=DefBufSize, int flags=0, int selfBytes=DefSelfBufSize) | |
Create a new DRAMA task of the specified name. More... | |
virtual | ~Task () |
Destructor - shut down the DRAMA task. More... | |
virtual void | _MessageUser (const std::string &text) const |
Use DRAMA to send a message to the user. More... | |
virtual void | Add (const std::string &name, MessageHandlerPtr obj) |
Add an action to the task. More... | |
virtual void | Add (const std::string &name, MessageHandler *obj) |
Add an action to the task. More... | |
virtual void | Add (const std::string &name, MessageReceiveFunction func) |
Add an action to the task. More... | |
void | AddOrphanToQueue (const OrphanDetails &orphan) |
Add an orphan to the queue of orphans to be processed before we next look at the DRAMA message queue. More... | |
virtual void | AddSpawnable (const std::string &name, SpawnablePtr obj) |
Add a spawnable action to the task. More... | |
virtual void | AddSpawnable (const std::string &name, Spawnable *obj) |
Add an action to the task. More... | |
void | CancelNotifyOnRunDramaExit (RunDramaExitNotifier *notifier) |
Cancel notification for when the DRAMA RunDrama() exits. More... | |
virtual double | GetJoinTimeout () const |
Get the thread join timeout. More... | |
std::thread::id | GetTaskThreadId () const |
Return the thread ID of the thread running RunDrama() More... | |
mutexType & | Lock () |
Reference the DRAMA Task lock. More... | |
logging::Logger & | Logger () |
Reference to DRAMA 2 Logger. More... | |
void | NotifyOnRunDramaExit (RunDramaExitNotifier *notifier) |
Arrange notification for when the DRAMA RunDrama() exits. More... | |
virtual void | RunDrama () |
Run the DRAMA message loop in the current thread. More... | |
void | Signal (const std::string &name, sds::Id *arg=nullptr, void *data=nullptr) |
Trigger the rescheduling of an action, specifing the name of the action. More... | |
void | Signal (long int index, sds::Id *arg=nullptr, void *data=nullptr) |
Trigger the rescheduling of an action, specifying the index of the action. More... | |
std::string | TaskName () const |
Return task name. More... | |
std::weak_ptr< Task > | TaskPtr () |
Returns a weak pointer to the task. More... | |
template<typename T > | |
std::shared_ptr< T > | TaskPtrAs () |
Returns a shared pointer to the task, dynamically case to the template type. More... | |
Static Public Attributes | |
static const int | DefBufSize =20000 |
Default global buffer size. More... | |
static const int | DefSelfBufSize =2000 |
Default self buffer size. More... | |
Protected Member Functions | |
virtual void | OrphanHandler (const OrphanDetails &details) |
Orphan transaction handler. More... | |
typedef std::lock_guard<mutexType> drama::Task::guardType |
Defines the type of a lock guard using our mutex type.
typedef std::recursive_timed_mutex drama::Task::mutexType |
Defines the type of our mutex.
It is recursive, since we might call it as the result of calls that have it locked.
If the macro DRAMA2_LOCK_DEBUG is defined, we use our "LockWithInfo", a slower lock that does give us some details on what is happening with the lock. Expected to only be used whilst debugging locking and all of DRAMA must be compiled with that macro defined.
typedef std::unique_lock<mutexType> drama::Task::uniqueLockType |
Defines the type of a unique_lock type using our mutex type.
drama::Task::Task | ( | const std::string & | name, |
int | buffer = DefBufSize , |
||
int | flags = 0 , |
||
int | selfBytes = DefSelfBufSize |
||
) |
Create a new DRAMA task of the specified name.
name | The name for the task. |
buffer | The DRAMA Task global message buffer size (bytes). Defaults to DefBufSize (20000) which should be enough for small tasks. See DitsAppInit(). |
flags | DRAMA Initialization flags. See DitsAppInit() for possible values. |
selfBytes | Size for the message buffer used to send messages to self. Only used if the DITS_M_SELF_BYTES flag is set. Default is DefSelBufSize (2000) bytes which enough for normal uses of DitsSignal() and releated functions. |
|
virtual |
Destructor - shut down the DRAMA task.
Other tasks will be notified that this task has shut down.
Reimplemented in drama::git::Task.
|
virtual |
Use DRAMA to send a message to the user.
This version MessageUser() should not normally be invoked by user code. They should prefer the drama::MessageHandler and drama::Thread methods. The results of this version are not well defined, but it is used to implement the high level versions.
The supplied text is send to the user using
If the message contains line feed characters (\n), then they are used to break the message up.
|
inlinevirtual |
Add an action to the task.
An action of the specified name is added to the task. The MessageHandler pointed to by obj is used to handle the messages.
name | Action name. |
obj | MessageHandler object pointer, passed by std::shared_ptr(). |
|
inlinevirtual |
Add an action to the task.
An action of the specified name is added to the task. The MessageHandler pointed to by obj is used to handle the messages.
name | Action name. |
obj | MessageHandler object. |
|
inlinevirtual |
Add an action to the task.
An action of the specified name is added to the task. The function specified is invoked to handle messages.
name | Action name. |
func | A function to be invoked to handle messages. The argument to this function is a drama::MessageHandler object which can be used communicate with DRAMA. The function must return a reschedule request. |
|
inline |
Add an orphan to the queue of orphans to be processed before we next look at the DRAMA message queue.
Thread/Lock Entry Info: Probably not running in DRAMA message thread. DRAMA Lock Taken.
orphan | The details on the orphan. |
|
inlinevirtual |
|
inlinevirtual |
void drama::Task::CancelNotifyOnRunDramaExit | ( | RunDramaExitNotifier * | notifier | ) |
Cancel notification for when the DRAMA RunDrama() exits.
notifier | The object to no longer be notified. |
|
virtual |
Get the thread join timeout.
This timeout value is specified when waiting to join outstanding threads when the task is shutting down. See the TUface/TAction implementations of RunDramaExitNotifier::JoinThreads.
Sub-classes can override this to provide a different value.
|
inline |
Return the thread ID of the thread running RunDrama()
|
inline |
|
inline |
Reference to DRAMA 2 Logger.
You can use this reference to make explicit log calls.
Alternatively, you could use DitsLogMsg(), which would make your code independent of the DRAMA 2 system.
void drama::Task::NotifyOnRunDramaExit | ( | RunDramaExitNotifier * | notifier | ) |
Arrange notification for when the DRAMA RunDrama() exits.
notifier | The object to be notified, its RunDramaHasExited() method will be invoked when the loop exits. |
|
protectedvirtual |
Orphan transaction handler.
This this is invoked to handle orphan transactions.
Orphaned transactions are those transactions which were not complete when their parent action (or UFACE thread) completed. This method will be invoked for each such transaction.
Subclasses can override this method to handle orphans in there preferred way. The base implementation will output a message to stderr.
The context of this call is that the DRAMA lock is taken, you are running in the thread that called RunDrama() and are in, but are not in any action context. At this point, to send messages, you must enable UFACE context in the traditional (C) DRAMA style.
It should also be noted that the transaction that triggered this call may have already been deleted by DRAMA, that is, the transaction ID in the details structure is referring to an invalid transaction ID. It will not have been reallocated as yet. You should only be using this value as a lookup, not as an argument to DRAMA calls.
details | Details of the orphaned transaction. |
|
virtual |
Run the DRAMA message loop in the current thread.
void drama::Task::Signal | ( | const std::string & | name, |
sds::Id * | arg = nullptr , |
||
void * | data = nullptr |
||
) |
Trigger the rescheduling of an action, specifing the name of the action.
The method allows an action to trigger the rescheduling of another action in the current task.
This method can be used from an action or when there is no action context (such as in a thread).
The target action may be awaiting rescheduling for any reason (having put a request of RequestCode::Wait, RequestCode::Sleep, or RequestCode::Stage.
Since this routine is often used for communication between interrupt routines and main line code, the message is sent as a high priority message and will thus be put a the begining of the incoming message buffer.
Note, as this routine is often used to allow non-DRAMA parts of a program to communicate with a DRAMA program, applications often get into trouble if this fail. Ensure exceptions are at least reported.
@param name The name of the action to signal @param arg An argument to the action. The drama::sds::Id::COut() method will be applied with its outlives argument set true. The underlying SDS id is passed to the action and the underlying SDS structure will be deleted when the action entry completes. Pass nullptr if there is no argument. @param data A pointer which will be assoicated with the signal. The action can fetch this using
void drama::Task::Signal | ( | long int | index, |
sds::Id * | arg = nullptr , |
||
void * | data = nullptr |
||
) |
Trigger the rescheduling of an action, specifying the index of the action.
The method allows an action to trigger the rescheduling of another action in the current task.
This method can be used from an action or when there is no action context (such as in a thread).
The target action may be awaiting rescheduling for any reason (having put a request of RequestCode::Wait, RequestCode::Sleep, or RequestCode::Stage.
Since this routine is often used for communication between interrupt routines and main line code, the message is sent as a high priority message and will thus be put a the begining of the incoming message buffer.
Note, as this routine is often used to allow non-DRAMA parts of a program to communicate with a DRAMA program, applications often get into trouble if this fail. Ensure exceptions are at least reported.
@param index The action index. (WHO TO GET THIS?) @param arg An argument to the action. The drama::sds::Id::COut() method will be applied with its outlives argument set true. The underlying SDS id is passed to the action and the underlying SDS structure will be deleted when the action entry completes. Pass nullptr if there is no argument. @param data A pointer which will be assoicated with the signal. The action can fetch this using
|
inline |
Return task name.
|
inline |
Returns a weak pointer to the task.
This operator allows references to the task to be passed around various locations and used as needed.
If the Task object itself was created as a std::shared_pnt, then the return values will be linked to that pointer. If it is not, then an internal shared_pnt will be created.
|
inline |
Returns a shared pointer to the task, dynamically case to the template type.
It is often required to downcast from drama::Task to one of its subclasses before accessing methods. This method uses std::dynamic_pointer_cast to do that safely.
T | A sub-class of drama::Task. |
|
static |
Default global buffer size.
|
static |
Default self buffer size.
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