AAO DRAMA/DRAMA2 C++ Interface
DRAMA C++11 and later interface
threaddispatch.hh
Go to the documentation of this file.
1#ifndef _DRAMA2_THREADDISPATCH_INC
2#define _DRAMA2_THREADDISPATCH_INC
3
17/*
18 * History:
19 29-Sep-2020 - TJF - Original version
20
21 * The above ID is for Doxygen, this one has the format ACMM is looking for.
22 * "@(#) $Id$"
23 */
24#include "drama.hh"
25#include "drama/path.hh"
26namespace drama {
27
39 class ThreadDispatcher {
40
41 private:
42
43 drama::Task *_theTask; /* DRAMA Task reference */
44 std::string _threadName; /* For log messages */
45 std::string _messageName; /* Message name */
46 std::future<void> _future; /* Used to manage the thread */
47 bool _running = false; /* Is the thread running? */
48
49 std::string _targetTaskName; /* Name of the task we are sending message to */
50
51 /*
52 * Invoked to run the thread.
53 */
55 drama::Path *path,
56 sds::IdPtr arg);
57
63 virtual void SendMessage(drama::thread::TMessHandler *messHandler,
64 const std::string &messageName,
65 drama::Path *path,
66 sds::IdPtr arg) = 0;
67
74 virtual std::string MessageTypeName() const = 0;
75 public:
86 const std::string &threadName,
87 const std::string &messageName) :
88 _theTask(theTask), _threadName(threadName), _messageName(messageName) {}
89
96 virtual ~ThreadDispatcher() {}
97
108 bool IsRunning() { return _running; }
109
136
156 drama::Path *path,
157 sds::IdPtr arg = nullptr);
158 };
159
164
165 public:
167 private:
174 const std::string &messageName,
175 drama::Path *path,
176 sds::IdPtr arg) override;
177
186 virtual std::string MessageTypeName() const override;
187
188
189 };
191} // namespace drama
192
193#endif
Implement a ThreadDispatcher which sends Obey messages.
Definition threaddispatch.hh:190
A Class which provides access to DRAMA's message sending facilities.
Definition path.hh:689
A class which implements a DRAMA task.
Definition task.hh:441
virtual ~ThreadDispatcher()
Destructor.
Definition threaddispatch.hh:123
bool CheckResult(StatusType *status)
Check the result of the thread.
bool IsRunning()
Returns true if the thread is running.
Definition threaddispatch.hh:135
void Send(drama::thread::TMessHandler *messHandler, drama::Path *path, sds::IdPtr arg=nullptr)
Send a message using a new thread.
ThreadDispatcher(drama::Task *theTask, const std::string &threadName, const std::string &messageName)
Construct a thread dispatcher.
Definition threaddispatch.hh:112
A class to dispatch message sending to another thread.
Definition threaddispatch.hh:66
This interface class must be implemented by classes which have threads waiting for messages.
Definition thread.hh:308
DRAMA 2 main include file.
std::shared_ptr< Id > IdPtr
A shared pointer for sds::Id items.
Definition sds.hh:3318
void CreateRunDramaTask()
Create and run a DRAMA task, with standard exception handling.
Definition task.hh:1322
The drama namespace contains all the classes, types etc of the DRAMA 2 implementation.
Definition drama.hh:93
DRAMA 2 include file.