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
356 public:
357 /*
358 * Constructor
359 */
370 virtual int RunDramaHasExited() = 0;
371
382 virtual bool JoinThreads(std::chrono::steady_clock::time_point until) = 0;
383
384 virtual ~RunDramaExitNotifier() {}
385 };
386
414 class Task : public std::enable_shared_from_this<Task> {
415 public:
425#ifdef DRAMA2_LOCK_DEBUG
426 typedef LockWithInfo mutexType;
427#else
428 typedef std::recursive_timed_mutex mutexType;
429#endif
430 //typedef std::mutex mutexType;
433 typedef std::lock_guard<mutexType> guardType;
436 typedef std::unique_lock<mutexType> uniqueLockType;
437
443 typedef drama::Request (Task::*ActionMethod)(drama::MessageHandler *mh);
450 typedef void (Task::*ThreadActionMethod)(
451 drama::thread::TAction *taction,
452 const drama::sds::Id& id);
453
454 private:
455 std::string _name;
456
457 std::thread::id _taskCreThreadId; // Id of thread that created task.
458 std::thread::id _taskRunThreadId; // Id of thread running the message loop.
459 /*
460 * This mutex is the main lock around DRAMA operations when
461 * running in threaded mode.
462 */
463 mutexType _dramaLock;
464
465 /*
466 * A set of the RunDRamaExitNotifier objects.
467 */
468 typedef std::set<RunDramaExitNotifier *> RunDramaExitNotifierSetType;
469
471 /*
472 * This mutex locks DRAMA message notifications. Unclear if it is
473 * actually needed. We don't take the _dramaLock when waiting
474 * for messages, since we want other threads to be able to
475 * execute DRAMA calls.
476 */
477 mutexType _dramaMsgNotifyLock;
478
482 OrphanDetailsQueue _orphanQueue;
483
488 static void HandleDitsOrphan(StatusType *status);
489 /*
490 * Unfortunately, DitsPutOrphanHandler() does not allow
491 * a clientData item to be passed to the handler routine.
492 * We must maintain the address of our task in a static
493 * so we can invoke methods on the right task. Fortunately,
494 * we can only have one task running - the DRAMA registration
495 * process ensures that.
496 */
497 static Task *orphanTask;
498
499 /*
500 * Handle messages for orphaned transactions. Non-static
501 * method invoked by HandleDitsOrphan.
502 */
503 void HandleOrphanMes(StatusType *status);
504
505
506 /* Invoked when a DRAMA message is available, processes it.
507 */
508 void ProcessMessage(long *exitFlag, StatusType *status);
509
510 /*
511 * A vector of notifiers to be invoked when the RunDrama() exits.
512 */
513 RunDramaExitNotifierSetType _loopExitNotifiers;
514
515 /*
516 * The task logger. Only used if opened.
517 */
518 std::unique_ptr<logging::Logger> _taskLogger;
519
520 /*
521 * Add an action to the task. Unlike the pubic interfaces, takes
522 * a spawnable argument and an ActionHandlerPtr.
523 *
524 * This is invoked by all the public interfaces to add an
525 * action to the DRAMA2 task.
526 */
527 virtual void AddAction(const std::string &name, bool spawnable,
528 ActionHandlerPtr obj,
529 const std::string &descr);
530
531 /*
532 * Shared pointer to self. This for std::shared<Task> operator.
533 */
534 std::shared_ptr<Task> _sharedSelf = nullptr;
535 /*
536 * Handling of shared pointers, as returned by TaskPtr() has
537 * been initialised.
538 */
539 bool _sharedInit = false;
540 /*
541 * Will be set true if it is found by TaskPtr() that our object
542 * already has a shared pointer.
543 */
544 bool _amShared = false;
545
546 /*
547 * If this is set true, then we don't complain if a separate thread
548 * is being used to run DRAMA.
549 */
550 bool _sepThreadToRunDramaOK = false;
551
552
553
556 Task& operator=(const Task &rhs) = delete;
559 Task(const Task &source) = delete;
560
561 /* Method used to implement AddMth */
562 void AddMethodAction(
563 const std::string &actionName,
565 const std::string &descr);
566 /* Method used to implement AddMthThd */
567 void AddMethodAction(
568 const std::string &actionName,
570 const std::string &descr);
571
572
573
574
575 protected:
603 virtual void OrphanHandler(const OrphanDetails &details);
604
605 public:
606
607 static const int DefBufSize=20000;
608 static const int DefSelfBufSize=2000;
632 Task(const std::string &name, int buffer=DefBufSize,
633 int flags=0, int selfBytes=DefSelfBufSize);
637 virtual void RunDrama();
638
650 _sepThreadToRunDramaOK = true;
651 }
652
653
669 virtual void Add(const std::string &name, MessageHandlerPtr obj,
670 const std::string &descr ="") {
671 AddAction(name, false, obj,descr);
672 }
673
688 virtual void Add(const std::string &name, MessageHandler *obj,
689 const std::string &descr ="") {
691 }
692
709 virtual void Add(const std::string &name, MessageReceiveFunction func,
710 const std::string &descr ="") {
711
712 Add(name, std::make_shared<MessageHandlerViaFunctor>(func), descr);
713 }
714
731 /* For some reason, this is ambigous with the above in some cases, so we need a different name */
732 virtual void AddTA(const std::string &name, thread::ThreadActionFunction func,
733 const std::string &descr ="") {
734 thread::AddActionFunction(this, name, func, descr);
735 }
737
754 virtual void AddSpawnable(const std::string &name, SpawnablePtr obj,
755 const std::string &descr ="") {
756 AddAction(name, true, obj, descr);
757 }
758
773 virtual void AddSpawnable(const std::string &name, Spawnable *obj,
774 const std::string &descr ="") {
775 AddAction(name, true, SpawnablePtr(obj), descr);
776 }
777
794 template <typename T>
795 void AddMth(
796 const std::string &actionName,
797 T method,
798 const std::string &descr ="") {
799
800 //The important thing here is that we must allow a sub-class
801 // of drama::Task to invoke specify its own methods. This
802 // cast allows that to happen. The cast will fail if
803 // the method doesn't have the right format.
804 AddMethodAction(actionName,
805 static_cast<drama::Task::ActionMethod>(method), descr);
806 }
824 template <typename T>
825 void AddMthThd(
826 const std::string &actionName,
827 T method,
828 const std::string &descr ="") {
829
830 //The important thing here is that we must allow a sub-class
831 // of drama::Task to invoke specify its own methods. This
832 // cast allows that to happen. The cast will fail if
833 // the method doesn't have the right format.
834 AddMethodAction(actionName,
836 }
844 mutexType & Lock() {
845 return _dramaLock;
846 }
856 std::thread::id GetTaskCreThreadId() const {
857 return _taskCreThreadId;
858 }
868 std::thread::id GetTaskRunThreadId() const {
869 return _taskRunThreadId;
870 }
884 return *_taskLogger;
885 }
886
891 std::string TaskName() const {
892 return _name;
893 }
894
901 void NotifyOnRunDramaExit(RunDramaExitNotifier *notifier);
906 void CancelNotifyOnRunDramaExit(RunDramaExitNotifier *notifier);
907
917 void AddOrphanToQueue(const OrphanDetails &orphan) {
918#ifdef DRAMA2_LOCK_DEBUG // If debugging, check we have the lock.
919 Lock().CheckTaken(__func__, __FILE__,__LINE__);
920#endif
921 _orphanQueue.push_front(orphan);
922 }
923
924
948 std::weak_ptr<Task> TaskPtr() {
949
950 guardType guard(_dramaLock);
951 /*
952 * This function initialises internal items on the
953 * first time through - can't be done in constructor
954 * as shared_from_this() will always fail there.
955 *
956 * Note - shared_from_this() comes from std::enable_shared_from_this,
957 * which we inherit.
958 */
959 //std::thread::id thisThread = std::this_thread::get_id();
960
961 //std::cerr << thisThread << "::TaskPtr() invoked, ";
962 if (_sharedInit)
963 {
964 //std::cerr << "_shareInit is true, ";
965 if (_amShared)
966 {
967 //std::cerr << "_amShared, " << std::endl;
968 return shared_from_this();
969 }
970 else
971 {
972 //std::cerr << "using _sharedSelf, " << std::endl;
973 return _sharedSelf;
974 }
976 // Only get here if not initialised
977 try
978 {
979 //std::cerr << "trying for shared_from_this(), ";
980
981 std::shared_ptr<Task> p = shared_from_this();
982 // If we have not thrown, then we are a shared pointer object.
983 _sharedInit = true;
984 _amShared = true;
985 //std::cerr << "got it, am shared" << std::endl;
986 return p;
987 }
988 /*
989 * According to http://en.cppreference.com's page on std::enable_shared_from_this,
990 * this is actually undefined behaviour this is not already a shared pointer, until
991 * c++17. It does at least seem to work for gnu C++ and Clang++ at c++11.
992 */
993 catch (const std::bad_weak_ptr &e)
994 {
995
996 //std::cerr << "Am not created from a shared, will init _sharedSelf" << std::endl;
997
998 _sharedSelf = std::shared_ptr<Task>(this, drama::nodel());
999 _amShared = false;
1000 _sharedInit = true;
1001 return _sharedSelf;
1002 }
1003
1004 }
1005
1016 template <typename T>
1017 std::shared_ptr<T> TaskPtrAs() {
1018 return std::dynamic_pointer_cast<T>(std::shared_ptr<Task>(TaskPtr()));
1019 }
1020
1031 virtual double GetJoinTimeout() const;
1032
1037 virtual ~Task();
1038
1074 void Signal(const std::string &name, sds::Id *arg=nullptr, void *data=nullptr);
1075
1112 void Signal(long int index, sds::Id *arg=nullptr, void *data=nullptr);
1113
1114
1130 virtual void _MessageUser(const std::string &text) const;
1131
1153 void SetDetails(const std::string &descr, int type = 0);
1154
1163 std::string GetTaskDescription(const std::string &taskName) const;
1164
1173 int GetTaskType(const std::string &taskName) const;
1174
1175
1176 /*
1177 * Ensure the current thread has taken the DRAMA task lock.
1178 * Throw an exception if not.
1179 *
1180 * This won't do anything unless DRAMA was compiled with
1181 * the DRAMA2_LOCK_DEBUG macro defined.
1182 *
1183 * This method is static and uses an internal static variable
1184 * to find the drama::Task object.
1185 *
1186 * func, file and lineNum are used in constructing the
1187 * exception so you know the source of the call.
1188 *
1189 * @param func Name of the function where the call was made
1190 * @param file Name of the file in which the call was made
1191 * @param lineNum Line number where the call was made.
1192 */
1193 static void CheckLockTaken(const std::string &func,
1194 const std::string &file,
1195 const int lineNum) ;
1196
1197
1198
1199 }; // Class Task.
1229 template <class TaskClass, typename... ParamTypes >
1231
1232 static_assert(std::is_base_of<Task, TaskClass>(), "TaskClass must be a sub-class of drama::task");
1233
1234 try
1235 {
1236 /* Create and run the task */
1237 TaskClass task(std::forward<ParamTypes>(taskPars)...);
1238 task.RunDrama();
1239 }
1240 catch (const drama::Exception &e)
1241 {
1242 std::cerr << "CreateRunDramaTask():drama::Exception thrown"
1243 << std::endl
1244 << e // Outputs all the exception details.
1245 << std::endl;
1246
1247 exit (e.statusAsSysExitCode());
1248 }
1249 catch (const std::exception &e)
1250 {
1251 std::cerr << "CreateRunDramaTask():std::exception thrown."
1252 << std::endl
1253 << e.what()
1254 << std::endl;
1255 exit(1);
1256 }
1257 catch (...)
1258 {
1259 std::cerr << "CreateRunDramaTask():Non-standard exception thrown."
1260 << std::endl;
1261 throw; // Rethrow to get any core dump etc
1262
1263 }
1264 } // CreateRunDramaTask()
1265#if 1
1294 template <class TaskClass>
1295 void CreateRunDramaTask() {
1296
1297 static_assert(std::is_base_of<Task, TaskClass>(), "TaskClass must be a sub-class of drama::task");
1298 try
1299 {
1300 /* Create and run the task */
1302 task.RunDrama();
1303 }
1304 catch (const drama::Exception &e)
1305 {
1306 std::cerr << "CreateRunDramaTask():drama::Exception thrown"
1307 << std::endl
1308 << e // Outputs all the exception details.
1309 << std::endl;
1310
1311 exit (e.statusAsSysExitCode());
1312 }
1313 catch (const std::exception &e)
1314 {
1315 std::cerr << "CreateRunDramaTask():std::exception thrown."
1316 << std::endl
1317 << e.what()
1318 << std::endl;
1319 exit(1);
1320 }
1321 catch (...)
1323 std::cerr << "CreateRunDramaTask():Non-standard excepton thrown."
1324 << std::endl;
1325 throw; // Rethrow to get any core dump etc
1326
1327 }
1328 } // CreateRunDramaTask()
1329#endif
1330} // namespace drama
1331
1332#endif
An Exception class for exceptions thrown by DRAMA V2 classes.
Definition exception.hh:164
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:382
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:634
std::shared_ptr< T > TaskPtrAs()
Returns a shared pointer to the task, dynamically cast to the template type.
Definition task.hh:1044
virtual void Add(const std::string &name, MessageHandlerPtr obj, const std::string &descr="")
Add an action to the task.
Definition task.hh:696
virtual void AddTA(const std::string &name, thread::ThreadActionFunction func, const std::string &descr="")
Add an threaded action to the task.
Definition task.hh:759
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:781
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:477
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:463
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:918
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:822
mutexType & Lock()
Reference the DRAMA Task lock.
Definition task.hh:871
std::thread::id GetTaskRunThreadId() const
Return the thread ID of the thread running RunDrama()
Definition task.hh:895
virtual void Add(const std::string &name, MessageReceiveFunction func, const std::string &descr="")
Add an action to the task.
Definition task.hh:736
std::recursive_timed_mutex mutexType
Defines the type of our mutex.
Definition task.hh:455
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:944
void SeparateThreadRunsDrama()
Tell the task we are expecting a separate thread to run the DRAMA message loop.
Definition task.hh:676
logging::Logger & Logger()
Reference to DRAMA 2 Logger.
Definition task.hh:910
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:800
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:460
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:852
virtual void Add(const std::string &name, MessageHandler *obj, const std::string &descr="")
Add an action to the task.
Definition task.hh:715
std::weak_ptr< Task > TaskPtr()
Returns a weak pointer to the task.
Definition task.hh:975
std::thread::id GetTaskCreThreadId() const
Return the thread ID of the thread on which the Task object was created.
Definition task.hh:883
static const int DefSelfBufSize
Default (minimum) self buffer size.
Definition task.hh:635
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:470
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:441
Implementation of a Class supporting Logging within an AAO DRAMA Task.
Definition logger.hh:769
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:3318
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:1322
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