AAO DRAMA/DRAMA2 C++ Interface
DRAMA C++11 and later interface
drama::Task Class Reference

Detailed Description

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).

Warning
Only one of these objects can exist in a program, any only one thread can call Task::RunDrama() at a given time.
See also
drama::CreateRunDramaTask for an easy way of creating and dealing with exceptions etc.
Example dramahello.cpp
Author
Tony Farrell, AAO $Revision$ $Date$
Examples
dramahello.cpp, gitpathtest.cpp, monitor1.cpp, monitor2.cpp, threadbasic.cpp, and tocker.cpp.

#include "task.hh"

Inheritance diagram for drama::Task:
drama::git::Task

Public Types

typedef drama::Request(Task::* ActionMethod) (drama::MessageHandler *mh)
 This type is for methods the task which implement actions.
 
typedef std::lock_guard< mutexTypeguardType
 Defines the type of a lock guard using our mutex type.
 
typedef std::recursive_timed_mutex mutexType
 Defines the type of our mutex.
 
typedef void(Task::* ThreadActionMethod) (drama::thread::TAction *taction, const drama::sds::Id &id)
 This type is for methods of the task which implement threaded actions.
 
typedef std::unique_lock< mutexTypeuniqueLockType
 Defines the type of a unique_lock type using our mutex type.
 

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.
 
virtual ~Task ()
 Destructor - shut down the DRAMA task.
 
virtual void _MessageUser (const std::string &text) const
 Use DRAMA to send a message to the user.
 
virtual void Add (const std::string &name, MessageHandler *obj, const std::string &descr="")
 Add an action to the task.
 
virtual void Add (const std::string &name, MessageHandlerPtr obj, const std::string &descr="")
 Add an action to the task.
 
virtual void Add (const std::string &name, MessageReceiveFunction func, const std::string &descr="")
 Add an action to the task.
 
template<typename T >
void AddMth (const std::string &actionName, T method, const std::string &descr="")
 Add an action to the task, implemented by a method.
 
template<typename T >
void AddMthThd (const std::string &actionName, T method, const std::string &descr="")
 Add an action to the task, implemented by a method.
 
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.
 
virtual void AddSpawnable (const std::string &name, Spawnable *obj, const std::string &descr="")
 Add an action to the task.
 
virtual void AddSpawnable (const std::string &name, SpawnablePtr obj, const std::string &descr="")
 Add a spawnable action to the task.
 
virtual void AddTA (const std::string &name, thread::ThreadActionFunction func, const std::string &descr="")
 Add an threaded action to the task.
 
void CancelNotifyOnRunDramaExit (RunDramaExitNotifier *notifier)
 Cancel notification for when the DRAMA RunDrama() exits.
 
virtual double GetJoinTimeout () const
 Get the thread join timeout.
 
std::thread::id GetTaskCreThreadId () const
 Return the thread ID of the thread on which the Task object was created.
 
std::string GetTaskDescription (const std::string &taskName) const
 Get the description of a task.
 
std::thread::id GetTaskRunThreadId () const
 Return the thread ID of the thread running RunDrama()
 
int GetTaskType (const std::string &taskName) const
 Get the type of a task.
 
mutexTypeLock ()
 Reference the DRAMA Task lock.
 
logging::LoggerLogger ()
 Reference to DRAMA 2 Logger.
 
void NotifyOnRunDramaExit (RunDramaExitNotifier *notifier)
 Arrange notification for when the DRAMA RunDrama() exits.
 
virtual void RunDrama ()
 Run the DRAMA message loop in the current thread.
 
void SeparateThreadRunsDrama ()
 Tell the task we are expecting a separate thread to run the DRAMA message loop.
 
void SetDetails (const std::string &descr, int type=0)
 Set task details.
 
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.
 
void Signal (long int index, sds::Id *arg=nullptr, void *data=nullptr)
 Trigger the rescheduling of an action, specifying the index of the action.
 
std::string TaskName () const
 Return task name.
 
std::weak_ptr< TaskTaskPtr ()
 Returns a weak pointer to the task.
 
template<typename T >
std::shared_ptr< T > TaskPtrAs ()
 Returns a shared pointer to the task, dynamically cast to the template type.
 

Static Public Attributes

static const int DefBufSize
 Default (minimum) global buffer size.
 
static const int DefSelfBufSize
 Default (minimum) self buffer size.
 

Protected Member Functions

virtual void OrphanHandler (const OrphanDetails &details)
 Orphan transaction handler.
 

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