1#ifndef _DRAMA2_THREAD_INC
2#define _DRAMA2_THREAD_INC
28#include <condition_variable>
48 struct WaitEventData {
50 TransEvtInfo eventInfo;
56 typedef std::queue<WaitEventData> WaitEventDataQueue;
62 typedef std::shared_ptr<std::condition_variable_any>
69 struct WaitEventDetails {
70 std::thread::id _thread;
72 WaitEventDataQueue _dataQueue;
73 WaitEventCondPtrType _condition;
80 std::string _messName;
83 explicit WaitEventDetails(
86 bool DataAvail()
const {
87 return !_dataQueue.empty();
92 "WaitEvenDetails destructor - transid %p, this %p\n",
93 static_cast<void *
>(_transId),
94 static_cast<void *
>(
this));
103 typedef std::map<std::thread::id, WaitEventDetails> WaitEventMapType;
104 typedef WaitEventMapType::iterator WaitEventMapIter;
105 typedef WaitEventMapType::const_iterator WaitEventMapIterConst;
113 unsigned WaitEventMapGetEvents(std::weak_ptr<Task>
theTask,
122 std::shared_ptr<TMessHandler> _handler;
123 std::shared_ptr<Path> _pathObj;
125 const std::string _messName;
135 const WaitEventDetails &
details) :
190 class TransEvtProcessor {
245 virtual bool WaitTimeout(std::chrono::steady_clock::time_point *
until);
248 virtual ~TransEvtProcessor() {}
257 TMessHandler *_handler;
268 void Print(
const std::string &
line)
const override;
362 template<
typename...
Types>
370 std::stringstream
sstrm;
433 const std::chrono::steady_clock::time_point &
until,
450 virtual std::shared_ptr<Task>
GetTask()
const = 0;
476 virtual void ClearWait(
bool complete) = 0;
480 virtual WaitEventDetails *FindWaitEventDetails(std::thread::id) = 0;
488 WaitEventDetails * WaitForTransactionStart();
504 void WaitForTransactionFinish(
559 class SignalBlocker {
574 extern void BlockSignals();
680 const std::string &fileName,
682 const std::string &
node=
"",
788 const std::string &fileName,
790 const std::string &
node=
"",
A Class which provides access to DRAMA's message sending facilities.
Definition path.hh:689
std::recursive_timed_mutex mutexType
Defines the type of our mutex.
Definition task.hh:455
std::lock_guard< mutexType > guardType
Defines the type of a lock guard using our mutex type.
Definition task.hh:460
Abstract class which is sub-classed to print SDS item listings.
Definition sds.hh:310
AccessDrama(const TMessHandler &messHandler)
Access the DRAMA context of a particular message handler object.
AccessDrama(Task::mutexType &taskLock)
Takes the DRAMA lock and saves the current context.
A class used by threads to access and enable the DRAMA context of an action or of a particular UFACE ...
Definition thread.hh:562
const Path & GetPath() const
Return the Path along which the message was sent.
Definition thread.hh:184
const std::string & GetMessName() const
Return the message name (Action name etc).
Definition thread.hh:208
DitsMsgType GetMessType() const
Return the type of the message that was sent.
Definition thread.hh:191
ProcessInfo(std::shared_ptr< TMessHandler > handler, const WaitEventDetails &details)
Construct one of these objects.
Definition thread.hh:161
const TMessHandler & GetHandler() const
Return the DRAMA Message handler object that was used to send the message.
Definition thread.hh:177
const char * GetMessTypeCStr() const
Return the type of the message that was sent as a C string.
Definition thread.hh:201
A class with information used by the TransEvtProcessor methods.
Definition thread.hh:147
SignalBlocker()
Constructor - Block signals in the current thread.
~SignalBlocker()
Destructor - read the signal mask settings to that when the constructor was run.
Constructing an object of this type will block all blockable UNIX signals in the current thread.
Definition thread.hh:586
void MessageUser(const char *format, Types... args)
Use DRAMA to send a message to the user - safe format.
Definition thread.hh:390
virtual ~TMessHandler()
Destructor.
Definition thread.hh:488
virtual Dits___CurActType GetMessageContext() const =0
Get the DRAMA Context associated with the action/UFACE event.
virtual void SetupWaitEvent(DitsTransIdType tid, drama::Path *pathObj)=0
Sets up a wait event for this thread.
TMessHandler(const TMessHandler &source)=delete
Copy constructor - deleted.
virtual bool WaitForTransactionUntil(std::weak_ptr< Task > theTask, TransEvtInfo *const eventInfo, TransEvtProcessor *const eventProcessor, const std::chrono::steady_clock::time_point &until, sds::IdPtr *const arg=nullptr)
Block the current thread until a message for the transaction specified to SetupWaitEvent() occurs or ...
TMessHandler & operator=(const TMessHandler &rhs)=delete
Assignment operator - deleted.
virtual const sds::PrintObjectCR & SdsListToUser() const
Get a reference to an SDS printer object which can be used to list an SDS object using MessageUser.
virtual void WaitForTransaction(std::weak_ptr< Task > theTask, TransEvtInfo *const eventInfo, TransEvtProcessor *const eventProcessor, sds::IdPtr *const arg=nullptr)
Block the current thread until a message for the transaction specified to SetupWaitEvent() occurs.
virtual std::shared_ptr< Task > GetTask() const =0
Get a reference to the DRAMA task we are part of.
virtual void MessageUser(const std::string &text) const =0
Use DRAMA to send a message to the user.
virtual Task::mutexType & Lock() const =0
Reference the DRAMA Task lock.
This interface class must be implemented by classes which have threads waiting for messages.
Definition thread.hh:308
void Print(const std::string &line) const override
Prints one line of an SDS listing.
TSdsListToUserObj(TMessHandler *messageHandler)
Constructor.
Object used to print SDS objects using MessageUser from TMessHandler objects.
Definition thread.hh:282
DRAMA 2 include file - Message Handler class definition.
std::shared_ptr< Id > IdPtr
A shared pointer for sds::Id items.
Definition sds.hh:3318
bool RunProgramWaitUntil(std::chrono::steady_clock::time_point until, TMessHandler *messHandler, const std::string &fileName, const std::string &arguments="", const std::string &node="", int priority=0, bool absPriority=false, bool setNames=true, unsigned stackBytes=0)
Load and run a program using the DRAMA loading mechanisms.
void RunProgram(TMessHandler *messHandler, const std::string &fileName, const std::string &arguments="", const std::string &node="", int priority=0, bool absPriority=false, bool setNames=true, unsigned stackBytes=0)
Load and run a program using the DRAMA loading mechanisms.
void CreateRunDramaTask()
Create and run a DRAMA task, with standard exception handling.
Definition task.hh:1322
void SafePrintf(std::ostream &ostream, const char *str)
Safe formatted write to a stream.
The drama namespace contains all the classes, types etc of the DRAMA 2 implementation.
Definition drama.hh:93
Structure is used to store details about a DRAMA reschedule message relating to a transaction,...
Definition task.hh:128
Declare an operator to be used as a deletion operator by std::shared_ptr.
Definition task.hh:114