1#ifndef _DRAMA2_MESSAGEHANDLER_INC
2#define _DRAMA2_MESSAGEHANDLER_INC
29#include "drama/action.hh"
31#include "drama/fmt/format.h"
34#include "DitsMsgOut.h"
51 class SdsListToUserObj :
public sds::PrintObjectCR {
53 MessageHandler *_handler;
61 void Print(
const std::string &
line)
const override;
114 class MessageHandler :
public ActionHandler {
122 Request MessageEvent(std::weak_ptr<Task>
task, Action *
action)
128 void InvokeActionEnd(std::weak_ptr<Task>
task, Action *
action,
136 std::weak_ptr<Task> _theTask;
138 EntryInfo _entryInfo;
190#ifdef RUNNING_DOXYGEN
293 template<
typename...
Types>
294#ifndef RUNNING_DOXYGEN
295 D2_FMT_DEPRECATED(
"Replace MessageUser() by MessageUserF(). See MessageUserF() page for details.")
304 std::stringstream
sstrm;
376 template<
typename...
Args>
400 virtual const EntryInfo &
GetEntry() {
412 virtual std::shared_ptr<Task>
GetTask()
const {
413 return std::shared_ptr<Task>(_theTask);
559 std::string GetActionName()
const {
562 "Tried to GetActionName when not in action.");
564 return _action->GetActionName();
593 "Tried to SetReturnArg when not in action.");
626 "Tried to SetReturnArg when not in action.");
637 id = arg->COut(
true, &free, &del, &readfree);
666 "Tried to change Obey handler when not in action.");
667 _action->PutObeyHandler(
obj);
685 "Tried to change Kick handler when not in action.");
686 _action->PutKickHandler(
obj);
732 _entryInfo.SetFromDits();
747 class MessageHandlerViaFunctor :
public MessageHandler {
819 class MessageUserStreamBuf :
public std::streambuf {
837 _actionObj.MessageUser(std::string(_buffer));
855 if (flushBuffer() ==
EOF)
863 virtual int sync()
override {
864 if (flushBuffer() ==
EOF) {
906 fprintf(
stderr,
"DRAMA Exception thrown by drama::~MessageUserStreamBuf()\n");
909 static_cast<long int>(
e.dramaStatus()),
910 e.dramaStatusStr().c_str());
917#ifdef D2_PROVIDE_LOG_STREAM
DRAMA 2 include file - Bulk Data support.
Defines and optionally creates a shared memory section containing an SDS structure.
Definition bulkdata.hh:434
Defines and optionally creates a shared memory section.
Definition bulkdata.hh:121
void SetFromDits()
Grab the information of interest from DITS.
Definition entryinfo.hh:123
The EntryInfo class is used to access details about a DRAMA message event (and entry to an action).
Definition entryinfo.hh:106
An Exception class for exceptions thrown by DRAMA V2 classes.
Definition exception.hh:183
drama::Request MessageReceived() override
Invoke function.
Definition messagehandler.hh:792
MessageHandlerViaFunctor(const MessageReceiveFunction func)
Initialize object with the specified function, which meets the MessageReceiveFunction prototype.
Definition messagehandler.hh:783
This class is used to creating MessageHandler objects referring to functions.
Definition messagehandler.hh:774
void MessageUserF(const fmt::format_string< Args... > fmt, Args &&... args)
Use DRAMA to send a message to the user - format using fmt::format.
Definition messagehandler.hh:404
virtual void PutObeyHandler(MessageHandlerPtr obj)
Put a message handler object for the next Obey reschedule event.
Definition messagehandler.hh:690
virtual void ActionEnd(bool taskExiting, StatusType actionEndStatus)
Method Invoked when the action completes.
virtual const EntryInfo & GetEntry()
Return the action entry details.
Definition messagehandler.hh:427
virtual Request MessageReceived()=0
Method invoked by DRAMA to handle the message.
MessageHandler & operator=(const MessageHandler &rhs)=delete
Copy operator deleted.
MessageHandler(MessageHandler &&source)=default
Move assignment operator.
virtual std::shared_ptr< Task > GetTask() const
Returns a pointer to the task.
Definition messagehandler.hh:439
void GrabEntryInfo()
Fetch the DRAMA Entry information.
Definition messagehandler.hh:758
virtual void PutKickHandler(MessageHandlerPtr obj)
Put a message handler object for the next Kick event.
Definition messagehandler.hh:709
void SetReturnArg(sds::Id *arg)
Set the argument to be sent as part of the action completion message.
Definition messagehandler.hh:650
void SendBulkTrigger(BulkData *arg, DitsTransIdType *transId, bool isSds, unsigned notifyBytes=1024 *1024)
Send a bulk data trigger message to the parent action.
void SendBulkTrigger(BulkDataSds *arg, DitsTransIdType *transId, unsigned notifyBytes=1024 *1024)
Send a bulk data trigger message to the parent action.
Definition messagehandler.hh:579
virtual void MessageUser(const std::string &text) const
Use DRAMA to send a message to the user.
virtual ~MessageHandler()
MessageHandler destructor.
virtual void PutKickHandler(MessageReceiveFunction func)
Put a message handler function for the next Kick event.
MessageHandler()
Create a DRAMA action/message handler object.
Definition messagehandler.hh:177
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 PutObeyHandler(MessageReceiveFunction func)
Put a message handler function for the next Obey reschedule event.
MessageHandler & operator=(MessageHandler &&rhs)=default
Move operator.
void MessageUser(const char *format, Types... args)
Use DRAMA to send a message to the user - safe format.
Definition messagehandler.hh:324
void SendTrigger(const sds::Id &arg) const
Send a trigger message to the parent action.
MessageHandler(const MessageHandler &source)=delete
Assignment operator deleted.
void SetReturnArg(const sds::Id &arg, bool copy=true)
Set the argument to be sent as part of the action completion message.
Definition messagehandler.hh:616
A class which implements a DRAMA Message Handler.
Definition messagehandler.hh:141
virtual ~MessageUserStreamBuf()
Destroy the MessgaeUserStream, any remaining output is sent.
Definition messagehandler.hh:919
MessageUserStreamBuf(T &actionObj)
Construct a MessageUserStreamBuf object.
Definition messagehandler.hh:906
Implement a streambuf sub-class that can write messages via the DRAMA MessageUser interface.
Definition messagehandler.hh:846
Class used by Obey and Kick handlers to indicate rescheduling requirements.
Definition request.hh:78
SdsListToUserObj(MessageHandler *)
Constructor.
void Print(const std::string &line) const override
Prints one line of an SDS listing.
Object used to print SDS objects using MessageUser from MessageHandler objects.
Definition messagehandler.hh:78
A class which implements a Spawnable DRAMA Message Handler.
Definition spawnable.hh:84
virtual SdsIdType COut(const bool outlives, bool *const free=0, bool *const del=0, bool *const readfree=0)
Return this item as an SdsIdType for return to C code.
Definition sds.hh:2490
A C++ Interface to the handling SDS structures.
Definition sds.hh:428
Abstract class which is sub-classed to print SDS item listings.
Definition sds.hh:310
DRAMA 2 include file - implements a class providing access to details on an action entry.
#define DramaTHROW(status_, message_)
Throw a Drama exception.
Definition exception.hh:90
void CreateRunDramaTask()
Create and run a DRAMA task, with standard exception handling.
Definition task.hh:1339
std::shared_ptr< MessageHandler > MessageHandlerPtr
This type is used for passing MessageHandler object addresses around.
Definition messagehandler.hh:96
void SafePrintf(std::ostream &ostream, const char *str)
Safe formatted write to a stream.
Request SimpleExitAction(drama::MessageHandler *messageHandler)
A function which implements a simple exit action.
std::function< Request(MessageHandler *)> MessageReceiveFunction
Type used for functions specified to drama::MessageHandler::PutObeyHandler(), drama::MessageHandler::...
Definition messagehandler.hh:106
The drama namespace contains all the classes, types etc of the DRAMA 2 implementation.
Definition drama.hh:99
DRAMA 2 include file - Request class definition.
DRAMA 2 include file - Task class definition.