AAO DRAMA/DRAMA2 C++ Interface
DRAMA C++11 and later interface
task.hh
Go to the documentation of this file.
1#ifndef _DRAMA2_TASK_INC
2#define _DRAMA2_TASK_INC
3
13/*
14 * History:
15 07-Jan-2014 - TJF - Original version
16 23-Mar-2018 - TJF - Add CheckLockTaken static method;
17 18-Jan-2018 - TJF - Add SeparateThreadRunsDrama() method and properly support
18 this by maining IDs for both the thread that created
19 DRAMA and that which is running the message loop.
20 Replace GetTaskThreadId() by GetTaskCreThreadId() and
21 GetTaskRunThreadId() as part of this.
22
23 * The above ID is for Doxygen, this one has the format ACMM is looking for.
24 * "@(#) $Id$"
25 */
26
27#include "DitsTypes.h"
28#include <string>
29#include <DitsSys.h>
30
32#include "drama/spawnable.hh"
33#include "drama/logger.hh"
34
35#include <thread>
36#include <mutex>
37#include <set>
38
39#include <memory> // For shared_ptr.
40#include <iostream>
41#include <deque>
42#include <type_traits>
43#include <functional>
44
45/*
46 * This file uses DOXYGEN comments - the following is placed into the
47 * index page. note that the @file block says to include the typedefs,
48 * functions etc from this file into the documentation.
49 */
50
55namespace drama {
56
57 class Task;
58
59 namespace thread {
60 /*
61 * These declarations are needed to allow
62 * AddTA(const std::string &name, thread::ThreadActionFunction func) to
63 * be defined.
64 *
65 * See threadaction.hh for full details of these.
66 */
67 class TAction; // Class used for threaded action implementations
68 /* Function used to implementation actions */
69 using ThreadActionFunction = std::function<void (TAction *, const sds::Id &)> ;
70 /* Function from threadaction.cpp used to wrap up using a function
71 * to implement a threaded action
72 */
73 void AddActionFunction(Task *,
74 const std::string &name,
76 const std::string &descr);
77
78 } // namespace thread;
79
86 struct nodel
87 {
90 void operator()(void const *) const
91 {
92 }
93 };
94
95
101 struct TransEvtInfo {
104 std::string entryName;
105 std::string loadErrText;
106 bool complete;
108 };
109
120 class OrphanDetails : public TransEvtInfo {
121
122 public:
135 sds::IdPtr arg,
139 argument(arg),
140 path (thePath),
141 transId(tid) {
142 }
143
144
145 };
146 /* @internal
147 * A queue of OrphanDetails.
148 *
149 * A std::queue would be a better representation of this
150 * then "std::deque", but we do want to clear the queue and
151 * std::queue does not support that.
152 */
153 typedef std::deque<OrphanDetails> OrphanDetailsQueue;
154
155
156
157
160 typedef std::shared_ptr<MessageHandler> MessageHandlerPtr;
162#ifndef RUNNING_DOXYGEN
163
164 /*
165 * If defined, we use our own sub-class of a std::recursive_mutex
166 * such that we can implement checks around use of locks. This
167 * is the normal default and DRAMA is not well tested without
168 * it being defined
169 */
170#define DRAMA2_LOCK_DEBUG
171
172 /*
173 * If defined, then we create a task specific file which records
174 * lock calls. This is rather complicated, but might be useful in
175 * tracking deadlock situations. The files written are named
176 * DramaLock-<pid>.log.
177 */
178//#define DRAMA2_LOCK_DEBUG2
179
180#endif // defined(RUNNING_DOXYGEN)
181
182#ifdef DRAMA2_LOCK_DEBUG2
183
184 /*
185 * If DEBUG2 is enabled, we need DEBUG.
186 */
187#ifndef DRAMA2_LOCK_DEBUG
188#define DRAMA2_LOCK_DEBUG
189#endif
190 /*
191 * The DRAMA2_TASK_CPP macro is set by the task.cpp file. We use
192 * this to trigger a warning if DEBUG2 debugging is enabled.
193 */
194#ifdef DRAMA2_TASK_CPP
195#warning "Lock debugging level 2 enabled - will slow things down"
196#endif
197
198 /* This macro allows to do stuff only when this logging is enabled*/
199#define DRAMA2_LOCK_DEBUG2_Only(_A_) _A_
200#else // !defined(DRAMA2_LOCK_DEBUG2)
201#define DRAMA2_LOCK_DEBUG2_Only(_A_) /*_A_*/
202
203#endif // !defined(DRAMA2_LOCK_DEBUG2)
204
205#ifdef DRAMA2_LOCK_DEBUG
206 /* Wrapper for a recursive timed mutex which allows us to
207 * work out if it has been taken and if so, by who
208 *
209 */
210 //class LockWithInfo : public std::recursive_timed_mutex {
211 class LockWithInfo : public std::recursive_mutex {
212 private:
213 bool _taken; /* Has the mutex been taken */
214 unsigned _count; /* Number of times a thread has taken it*/
215 std::thread::id _takenBy;/* Thread which has it */
216#ifdef DRAMA2_LOCK_DEBUG2
217 static std::ofstream _debugFile; /* Lock log file, process specific */
218 static unsigned _lockCount; /* How many locks in the process */
219 char _code = '_'; /* This lock's prefix */
220 /* Write time and thread details for the debug file to a stream */
221 void TimeNowAndThreadToStream(std::ostream &stream);
222#endif
223 public:
232 LockWithInfo(const std::string &whichLock);
233 /*
234 * Destroy the lock. If DEBUG2 is defined, and this
235 * is the last lock, close the log file.
236 */
238
239 /* Overload parent class lock() method, do our
240 * stuff after taking the lock.
241 */
242 void lock();
243 /* Overload parent class try_lock() method, do our
244 * stuff after taking the lock.
245 */
246 bool try_lock() noexcept;
247
248 /* Overload parent class unlock() method, do our
249 * stuff before releasing the lock.
250 */
251 void unlock();
252 /*
253 * Ensure the current thread has taken the lock. Throw
254 * an exception if not.
255 *
256 * func, file and lineNum are used in constructing the
257 * exception so you know the source of the call.
258 *
259 * @param func Name of the function where the call was made
260 * @param file Name of the file in which the call was made
261 * @param lineNum Line number where the call was made.
262 */
263 void CheckTaken(const std::string &func,
264 const std::string &file,
265 const int lineNum) const;
266 /*
267 * Ensure the current thread has taken the lock and that
268 * it is the specified thread. Throw an exception if not.
269 *
270 * This is typically used to ensure the DRAMA thread is the
271 * current thread and has the lock.
272 *
273 * func, file and lineNum are used in constructing the
274 * exception so you know the source of the call.
275 *
276 * @param t The thread which should be the current thread.
277 * @param func Name of the function where the call was made
278 * @param file Name of the file in which the call was made
279 * @param lineNum Line number where the call was made
280 */
281 void CheckTakenBy(std::thread::id t,
282 const std::string &func,
283 const std::string &file,
284 const int lineNum) const;
285 /*
286 * Ensure the current thread has taken the lock and that
287 * it is the DRAMA task thread. Throw an exception if not.
288 *
289 * This is typically used to ensure the DRAMA thread is the
290 * current thread and has the lock.
291 *
292 * func, file and lineNum are used in constructing the
293 * exception so you know the source of the call.
294 *
295 * @param task Reference to the drama task.
296 * @param func Name of the function where the call was made.
297 * @param file Name of the file in which the call was made.
298 * @param lineNum Line number where the call was made.
299 */
300 void CheckTakenBy(std::weak_ptr<Task> task,
301 const std::string &func,
302 const std::string &file,
303 const int lineNum) const;
304 /*
305 * Ensure the current thread has taken the lock and that
306 * it is the DRAMA task thread. Throw an exception if not.
307 *
308 * This is typically used to ensure the DRAMA thread is the
309 * current thread and has the lock.
310 *
311 * func, file and lineNum are used in constructing the
312 * exception so you know the source of the call.
313 *
314 * @param task Reference to the drama task.
315 * @param func Name of the function where the call was made.
316 * @param file Name of the file in which the call was made
317 * @param lineNum Line number where the call was made.
318 */
319 void CheckTakenBy(Task * task,
320 const std::string &func,
321 const std::string &file,
322 const int lineNum) const;
323
324 /*
325 * Ensure the current thread has not taken the lock. Throws
326 * an exception if it has.
327 *
328 * func, file and lineNum are used in constructing the
329 * exception so you know the source of the call.
330 *
331 * @param func Name of the function where the call was made.
332 * @param file Name of the file in which the call was made.
333 * @param lineNum Line number where the call was made.
334 */
335 void CheckNotTakenBy(const std::string func,
336 const std::string &file,
337 const int lineNum) const;
338 /*
339 * Show the status of the lock - output to std::cerr.
340 */
341 void Show() const;
342 }; // class LockWithInfo
343#endif /* if defined DRAMA2_LOCK_DEBUG */
344
361 public:
362 /*
363 * Constructor
364 */
375 virtual int RunDramaHasExited() = 0;
376
387 virtual bool JoinThreads(std::chrono::steady_clock::time_point until) = 0;
388
389 virtual ~RunDramaExitNotifier() {}
390 };
391
419 class Task : public std::enable_shared_from_this<Task> {
420 public:
430#ifdef DRAMA2_LOCK_DEBUG
431 typedef LockWithInfo mutexType;
432#else
433 typedef std::recursive_timed_mutex mutexType;
434#endif
435 //typedef std::mutex mutexType;
438 typedef std::lock_guard<mutexType> guardType;
441 typedef std::unique_lock<mutexType> uniqueLockType;
442
448 typedef drama::Request (Task::*ActionMethod)(drama::MessageHandler *mh);
455 typedef void (Task::*ThreadActionMethod)(
456 drama::thread::TAction *taction,
457 const drama::sds::Id& id);
458
459 private:
460 std::string _name;
461
462 std::thread::id _taskCreThreadId; // Id of thread that created task.
463 std::thread::id _taskRunThreadId; // Id of thread running the message loop.
464 /*
465 * This mutex is the main lock around DRAMA operations when
466 * running in threaded mode.
467 */
468 mutexType _dramaLock;
469
470 /*
471 * A set of the RunDRamaExitNotifier objects.
472 */
473 typedef std::set<RunDramaExitNotifier *> RunDramaExitNotifierSetType;
474
476 /*
477 * This mutex locks DRAMA message notifications. Unclear if it is
478 * actually needed. We don't take the _dramaLock when waiting
479 * for messages, since we want other threads to be able to
480 * execute DRAMA calls.
481 */
482 mutexType _dramaMsgNotifyLock;
483
487 OrphanDetailsQueue _orphanQueue;
488
493 static void HandleDitsOrphan(StatusType *status);
494 /*
495 * Unfortunately, DitsPutOrphanHandler() does not allow
496 * a clientData item to be passed to the handler routine.
497 * We must maintain the address of our task in a static
498 * so we can invoke methods on the right task. Fortunately,
499 * we can only have one task running - the DRAMA registration
500 * process ensures that.
501 */
502 static Task *orphanTask;
503
504 /*
505 * Handle messages for orphaned transactions. Non-static
506 * method invoked by HandleDitsOrphan.
507 */
508 void HandleOrphanMes(StatusType *status);
509
510
511 /* Invoked when a DRAMA message is available, processes it.
512 */
513 void ProcessMessage(long *exitFlag, StatusType *status);
514
515 /*
516 * A vector of notifiers to be invoked when the RunDrama() exits.
517 */
518 RunDramaExitNotifierSetType _loopExitNotifiers;
519
520 /*
521 * The task logger. Only used if opened.
522 */
523 std::unique_ptr<logging::Logger> _taskLogger;
524
525 /*
526 * Add an action to the task. Unlike the pubic interfaces, takes
527 * a spawnable argument and an ActionHandlerPtr.
528 *
529 * This is invoked by all the public interfaces to add an
530 * action to the DRAMA2 task.
531 */
532 virtual void AddAction(const std::string &name, bool spawnable,
533 ActionHandlerPtr obj,
534 const std::string &descr);
535
536 /*
537 * Shared pointer to self. This for std::shared<Task> operator.
538 */
539 std::shared_ptr<Task> _sharedSelf = nullptr;
540 /*
541 * Handling of shared pointers, as returned by TaskPtr() has
542 * been initialised.
543 */
544 bool _sharedInit = false;
545 /*
546 * Will be set true if it is found by TaskPtr() that our object
547 * already has a shared pointer.
548 */
549 bool _amShared = false;
550
551 /*
552 * If this is set true, then we don't complain if a separate thread
553 * is being used to run DRAMA.
554 */
555 bool _sepThreadToRunDramaOK = false;
556
557
558
561 Task& operator=(const Task &rhs) = delete;
564 Task(const Task &source) = delete;
565
566 /* Method used to implement AddMth */
567 void AddMethodAction(
568 const std::string &actionName,
570 const std::string &descr);
571 /* Method used to implement AddMthThd */
572 void AddMethodAction(
573 const std::string &actionName,
575 const std::string &descr);
576
577
578
579
580 protected:
608 virtual void OrphanHandler(const OrphanDetails &details);
609
610 public:
611
612 static const int DefBufSize=20000;
613 static const int DefSelfBufSize=2000;
637 Task(const std::string &name, int buffer=DefBufSize,
638 int flags=0, int selfBytes=DefSelfBufSize);
642 virtual void RunDrama();
643
655 _sepThreadToRunDramaOK = true;
656 }
657
658
674 virtual void Add(const std::string &name, MessageHandlerPtr obj,
675 const std::string &descr ="") {
676 AddAction(name, false, obj,descr);
677 }
678
693 virtual void Add(const std::string &name, MessageHandler *obj,
694 const std::string &descr ="") {
696 }
697
714 virtual void Add(const std::string &name, MessageReceiveFunction func,
715 const std::string &descr ="") {
716
717 Add(name, std::make_shared<MessageHandlerViaFunctor>(func), descr);
718 }
719
736 /* For some reason, this is ambigous with the above in some cases, so we need a different name */
737 virtual void AddTA(const std::string &name, thread::ThreadActionFunction func,
738 const std::string &descr ="") {
739 thread::AddActionFunction(this, name, func, descr);
740 }
742
759 virtual void AddSpawnable(const std::string &name, SpawnablePtr obj,
760 const std::string &descr ="") {
761 AddAction(name, true, obj, descr);
762 }
763
778 virtual void AddSpawnable(const std::string &name, Spawnable *obj,
779 const std::string &descr ="") {
780 AddAction(name, true, SpawnablePtr(obj), descr);
781 }
782
799 template <typename T>
800 void AddMth(
801 const std::string &actionName,
802 T method,
803 const std::string &descr ="") {
804
805 //The important thing here is that we must allow a sub-class
806 // of drama::Task to invoke specify its own methods. This
807 // cast allows that to happen. The cast will fail if
808 // the method doesn't have the right format.
809 AddMethodAction(actionName,
810 static_cast<drama::Task::ActionMethod>(method), descr);
811 }
829 template <typename T>
830 void AddMthThd(
831 const std::string &actionName,
832 T method,
833 const std::string &descr ="") {
834
835 //The important thing here is that we must allow a sub-class
836 // of drama::Task to invoke specify its own methods. This
837 // cast allows that to happen. The cast will fail if
838 // the method doesn't have the right format.
839 AddMethodAction(actionName,
841 }
849 mutexType & Lock() {
850 return _dramaLock;
851 }
861 std::thread::id GetTaskCreThreadId() const {
862 return _taskCreThreadId;
863 }
873 std::thread::id GetTaskRunThreadId() const {
874 return _taskRunThreadId;
875 }
889 return *_taskLogger;
890 }
891
896 std::string TaskName() const {
897 return _name;
898 }
899
906 void NotifyOnRunDramaExit(RunDramaExitNotifier *notifier);
911 void CancelNotifyOnRunDramaExit(RunDramaExitNotifier *notifier);
912
922 void AddOrphanToQueue(const OrphanDetails &orphan) {
923#ifdef DRAMA2_LOCK_DEBUG // If debugging, check we have the lock.
924 Lock().CheckTaken(__func__, __FILE__,__LINE__);
925#endif
926 _orphanQueue.push_front(orphan);
927 }
928
929
953 std::weak_ptr<Task> TaskPtr() {
954
955 guardType guard(_dramaLock);
956 /*
957 * This function initialises internal items on the
958 * first time through - can't be done in constructor
959 * as shared_from_this() will always fail there.
960 *
961 * Note - shared_from_this() comes from std::enable_shared_from_this,
962 * which we inherit.
963 */
964 //std::thread::id thisThread = std::this_thread::get_id();
965
966 //std::cerr << thisThread << "::TaskPtr() invoked, ";
967 if (_sharedInit)
968 {
969 //std::cerr << "_shareInit is true, ";
970 if (_amShared)
971 {
972 //std::cerr << "_amShared, " << std::endl;
973 return shared_from_this();
974 }
975 else
976 {
977 //std::cerr << "using _sharedSelf, " << std::endl;
978 return _sharedSelf;
979 }
981 // Only get here if not initialised
982 try
983 {
984 //std::cerr << "trying for shared_from_this(), ";
985
986 std::shared_ptr<Task> p = shared_from_this();
987 // If we have not thrown, then we are a shared pointer object.
988 _sharedInit = true;
989 _amShared = true;
990 //std::cerr << "got it, am shared" << std::endl;
991 return p;
992 }
993 /*
994 * According to http://en.cppreference.com's page on std::enable_shared_from_this,
995 * this is actually undefined behaviour this is not already a shared pointer, until
996 * c++17. It does at least seem to work for gnu C++ and Clang++ at c++11.
997 */
998 catch (const std::bad_weak_ptr &e)
999 {
1000
1001 //std::cerr << "Am not created from a shared, will init _sharedSelf" << std::endl;
1002
1003 _sharedSelf = std::shared_ptr<Task>(this, drama::nodel());
1004 _amShared = false;
1005 _sharedInit = true;
1006 return _sharedSelf;
1007 }
1008
1009 }
1010
1021 template <typename T>
1022 std::shared_ptr<T> TaskPtrAs() {
1023 return std::dynamic_pointer_cast<T>(std::shared_ptr<Task>(TaskPtr()));
1024 }
1025
1036 virtual double GetJoinTimeout() const;
1037
1042 virtual ~Task();
1043
1079 void Signal(const std::string &name, sds::Id *arg=nullptr, void *data=nullptr);
1080
1117 void Signal(long int index, sds::Id *arg=nullptr, void *data=nullptr);
1118
1119
1135 virtual void _MessageUser(const std::string &text) const;
1136
1158 void SetDetails(const std::string &descr, int type = 0);
1159
1168 std::string GetTaskDescription(const std::string &taskName) const;
1169
1178 int GetTaskType(const std::string &taskName) const;
1179
1180
1181 /*
1182 * Ensure the current thread has taken the DRAMA task lock.
1183 * Throw an exception if not.
1184 *
1185 * This won't do anything unless DRAMA was compiled with
1186 * the DRAMA2_LOCK_DEBUG macro defined.
1187 *
1188 * This method is static and uses an internal static variable
1189 * to find the drama::Task object.
1190 *
1191 * func, file and lineNum are used in constructing the
1192 * exception so you know the source of the call.
1193 *
1194 * @param func Name of the function where the call was made
1195 * @param file Name of the file in which the call was made
1196 * @param lineNum Line number where the call was made.
1197 */
1198 static void CheckLockTaken(const std::string &func,
1199 const std::string &file,
1200 const int lineNum) ;
1201
1202
1203
1204 }; // Class Task.
1234 template <class TaskClass, typename... ParamTypes >
1236
1237 static_assert(std::is_base_of<Task, TaskClass>(), "TaskClass must be a sub-class of drama::task");
1238
1239 try
1240 {
1241 /* Create and run the task */
1242 TaskClass task(std::forward<ParamTypes>(taskPars)...);
1243 task.RunDrama();
1244 }
1245 catch (const drama::Exception &e)
1246 {
1247 std::cerr << "CreateRunDramaTask():drama::Exception thrown"
1248 << std::endl
1249 << e.toString(true) // Outputs all the exception details.
1250 << std::endl;
1251
1252 exit (e.statusAsSysExitCode());
1253 }
1254 catch (const std::exception &e)
1255 {
1256 std::cerr << "CreateRunDramaTask():std::exception thrown."
1257 << std::endl
1258 << e.what()
1259 << std::endl;
1260 exit(1);
1261 }
1262 catch (...)
1263 {
1264 std::cerr << "CreateRunDramaTask():Non-standard exception thrown."
1265 << std::endl;
1266 throw; // Rethrow to get any core dump etc
1267
1268 }
1269 } // CreateRunDramaTask()
1270#if 1
1299 template <class TaskClass>
1300 void CreateRunDramaTask() {
1301
1302 static_assert(std::is_base_of<Task, TaskClass>(), "TaskClass must be a sub-class of drama::task");
1303 try
1304 {
1305 /* Create and run the task */
1307 task.RunDrama();
1308 }
1309 catch (const drama::Exception &e)
1310 {
1311 std::cerr << "CreateRunDramaTask():drama::Exception thrown"
1312 << std::endl
1313 << e.toString(true) // Outputs all the exception details.
1314 << std::endl;
1315
1316 exit (e.statusAsSysExitCode());
1317 }
1318 catch (const std::exception &e)
1319 {
1320 std::cerr << "CreateRunDramaTask():std::exception thrown."
1321 << std::endl
1322 << e.what()
1323 << std::endl;
1324 exit(1);
1325 }
1326 catch (...)
1328 std::cerr << "CreateRunDramaTask():Non-standard excepton thrown."
1329 << std::endl;
1330 throw; // Rethrow to get any core dump etc
1331
1332 }
1333 } // CreateRunDramaTask()
1334#endif
1335} // namespace drama
1336
1337#endif
An Exception class for exceptions thrown by DRAMA V2 classes.
Definition exception.hh:162
A class which implements a DRAMA Message Handler.
Definition messagehandler.hh:138
DitsPathType path
The DITS path the transaction was sent to.
Definition task.hh:151
OrphanDetails(TransEvtInfo evtInfo, sds::IdPtr arg, DitsPathType thePath, DitsTransIdType tid)
Construct an OrphanDetails item.
Definition task.hh:161
sds::IdPtr argument
The Argument to the transaction.
Definition task.hh:150
DitsTransIdType transId
The DITS Transaction ID.
Definition task.hh:152
Structure which maintains details on orphan transactions.
Definition task.hh:147
Class used by Obey and Kick handlers to indicate rescheduling requirements.
Definition request.hh:78
virtual bool JoinThreads(std::chrono::steady_clock::time_point until)=0
Invoked by DRAMA when the run loop exists.
virtual int RunDramaHasExited()=0
Invoked by DRAMA when the run loop exits.
Class used to arrange for notifications when the RunDrama exits.
Definition task.hh:387
A class which implements a Spawnable DRAMA Message Handler.
Definition spawnable.hh:84
static const int DefBufSize
Default (minimum) global buffer size.
Definition task.hh:639
std::shared_ptr< T > TaskPtrAs()
Returns a shared pointer to the task, dynamically cast to the template type.
Definition task.hh:1049
virtual void Add(const std::string &name, MessageHandlerPtr obj, const std::string &descr="")
Add an action to the task.
Definition task.hh:701
virtual void AddTA(const std::string &name, thread::ThreadActionFunction func, const std::string &descr="")
Add an threaded action to the task.
Definition task.hh:764
Task(const std::string &name, int buffer=DefBufSize, int flags=0, int selfBytes=DefSelfBufSize)
Create a new DRAMA task of the specified name.
virtual void AddSpawnable(const std::string &name, SpawnablePtr obj, const std::string &descr="")
Add a spawnable action to the task.
Definition task.hh:786
void(Task::* ThreadActionMethod)(drama::thread::TAction *taction, const drama::sds::Id &id)
This type is for methods of the task which implement threaded actions.
Definition task.hh:482
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::unique_lock< mutexType > uniqueLockType
Defines the type of a unique_lock type using our mutex type.
Definition task.hh:468
virtual void RunDrama()
Run the DRAMA message loop in the current thread.
virtual double GetJoinTimeout() const
Get the thread join timeout.
std::string GetTaskDescription(const std::string &taskName) const
Get the description of a task.
std::string TaskName() const
Return task name.
Definition task.hh:923
void AddMth(const std::string &actionName, T method, const std::string &descr="")
Add an action to the task, implemented by a method.
Definition task.hh:827
mutexType & Lock()
Reference the DRAMA Task lock.
Definition task.hh:876
std::thread::id GetTaskRunThreadId() const
Return the thread ID of the thread running RunDrama()
Definition task.hh:900
virtual void Add(const std::string &name, MessageReceiveFunction func, const std::string &descr="")
Add an action to the task.
Definition task.hh:741
std::recursive_timed_mutex mutexType
Defines the type of our mutex.
Definition task.hh:460
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.
Definition task.hh:949
void SeparateThreadRunsDrama()
Tell the task we are expecting a separate thread to run the DRAMA message loop.
Definition task.hh:681
logging::Logger & Logger()
Reference to DRAMA 2 Logger.
Definition task.hh:915
int GetTaskType(const std::string &taskName) const
Get the type of a task.
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.
virtual void _MessageUser(const std::string &text) const
Use DRAMA to send a message to the user.
virtual void AddSpawnable(const std::string &name, Spawnable *obj, const std::string &descr="")
Add an action to the task.
Definition task.hh:805
void CancelNotifyOnRunDramaExit(RunDramaExitNotifier *notifier)
Cancel notification for when the DRAMA RunDrama() exits.
std::lock_guard< mutexType > guardType
Defines the type of a lock guard using our mutex type.
Definition task.hh:465
virtual void OrphanHandler(const OrphanDetails &details)
Orphan transaction handler.
void AddMthThd(const std::string &actionName, T method, const std::string &descr="")
Add an action to the task, implemented by a method.
Definition task.hh:857
virtual void Add(const std::string &name, MessageHandler *obj, const std::string &descr="")
Add an action to the task.
Definition task.hh:720
std::weak_ptr< Task > TaskPtr()
Returns a weak pointer to the task.
Definition task.hh:980
std::thread::id GetTaskCreThreadId() const
Return the thread ID of the thread on which the Task object was created.
Definition task.hh:888
static const int DefSelfBufSize
Default (minimum) self buffer size.
Definition task.hh:640
virtual ~Task()
Destructor - shut down the DRAMA task.
drama::Request(Task::* ActionMethod)(drama::MessageHandler *mh)
This type is for methods the task which implement actions.
Definition task.hh:475
void SetDetails(const std::string &descr, int type=0)
Set task details.
void NotifyOnRunDramaExit(RunDramaExitNotifier *notifier)
Arrange notification for when the DRAMA RunDrama() exits.
A class which implements a DRAMA task.
Definition task.hh:446
Implementation of a Class supporting Logging within an AAO DRAMA Task.
Definition logger.hh:790
A C++ Interface to the handling SDS structures.
Definition sds.hh:428
A class which implements a DRAMA Action with runs a thread.
Definition threadaction.hh:199
Header file for a DRAMA 2 class which implements Logging.
DRAMA 2 include file - Message Handler class definition.
std::shared_ptr< Id > IdPtr
A shared pointer for sds::Id items.
Definition sds.hh:3484
std::function< void(TAction *, const sds::Id &)> ThreadActionFunction
Type used for functions specified drama::Task::Add().
Definition task.hh:96
void CreateRunDramaTask()
Create and run a DRAMA task, with standard exception handling.
Definition task.hh:1327
std::shared_ptr< Spawnable > SpawnablePtr
This type is used for passing Spawnable object addresses around.
Definition spawnable.hh:200
EntryCode
Entry type code - indicates the type of a DRAMA event.
Definition entryinfo.hh:67
@ Signal
Signal message received.
std::shared_ptr< MessageHandler > MessageHandlerPtr
This type is used for passing MessageHandler object addresses around.
Definition messagehandler.hh:101
void CheckLockTaken(const std::string func, const std::string &file, const int lineNum)
Ensure the current thread has taken the DRAMA task lock.
std::function< Request(MessageHandler *)> MessageReceiveFunction
Type used for functions specified to drama::MessageHandler::PutObeyHandler(), drama::MessageHandler::...
Definition messagehandler.hh:111
The drama namespace contains all the classes, types etc of the DRAMA 2 implementation.
Definition drama.hh:93
DRAMA 2 include file - Spawnable action implementation.
DitsBulkInfoType bulkInfo
Details on bulk data transfer.
Definition task.hh:134
EntryCode entryReason
Reason for entry.
Definition task.hh:129
StatusType entryStatus
Entry status value.
Definition task.hh:130
std::string entryName
Name with entry.
Definition task.hh:131
std::string loadErrText
Load error text
Definition task.hh:132
bool complete
IS transaction complete.
Definition task.hh:133
Structure is used to store details about a DRAMA reschedule message relating to a transaction,...
Definition task.hh:128
void operator()(void const *) const
Invoked to delete the memory used.
Definition task.hh:117
Declare an operator to be used as a deletion operator by std::shared_ptr.
Definition task.hh:114