1#ifndef _DRAMA2_MESSAGEHANDLER_INC
2#define _DRAMA2_MESSAGEHANDLER_INC
35#include "drama/action.hh"
39#include "DitsMsgOut.h"
56 class SdsListToUserObj :
public sds::PrintObjectCR {
58 MessageHandler *_handler;
66 void Print(
const std::string &
line)
const override;
125 void InvokeActionEnd(std::weak_ptr<Task>
task, Action *
action,
133 std::weak_ptr<Task> _theTask;
187#ifdef RUNNING_DOXYGEN
276 template<
typename...
Types>
284 std::stringstream
sstrm;
320 virtual std::shared_ptr<Task>
GetTask()
const {
321 return std::shared_ptr<Task>(_theTask);
467 std::string GetActionName()
const {
470 "Tried to GetActionName when not in action.");
472 return _action->GetActionName();
501 "Tried to SetReturnArg when not in action.");
534 "Tried to SetReturnArg when not in action.");
545 id = arg->COut(
true, &free, &del, &readfree);
574 "Tried to change Obey handler when not in action.");
575 _action->PutObeyHandler(
obj);
593 "Tried to change Kick handler when not in action.");
594 _action->PutKickHandler(
obj);
655 class MessageHandlerViaFunctor :
public MessageHandler {
727 class MessageUserStreamBuf :
public std::streambuf {
745 _actionObj.MessageUser(std::string(_buffer));
763 if (flushBuffer() ==
EOF)
771 virtual int sync()
override {
772 if (flushBuffer() ==
EOF) {
814 fprintf(
stderr,
"DRAMA Exception thrown by drama::~MessageUserStreamBuf()\n");
817 static_cast<long int>(
e.dramaStatus()),
818 e.dramaStatusStr().c_str());
825#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:164
drama::Request MessageReceived() override
Invoke function.
Definition messagehandler.hh:700
MessageHandlerViaFunctor(const MessageReceiveFunction func)
Initialize object with the specified function, which meets the MessageReceiveFunction prototype.
Definition messagehandler.hh:691
This class is used to creating MessageHandler objects referring to functions.
Definition messagehandler.hh:682
virtual void PutObeyHandler(MessageHandlerPtr obj)
Put a message handler object for the next Obey reschedule event.
Definition messagehandler.hh:598
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:335
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:347
void GrabEntryInfo()
Fetch the DRAMA Entry information.
Definition messagehandler.hh:666
virtual void PutKickHandler(MessageHandlerPtr obj)
Put a message handler object for the next Kick event.
Definition messagehandler.hh:617
void SetReturnArg(sds::Id *arg)
Set the argument to be sent as part of the action completion message.
Definition messagehandler.hh:558
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:487
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:174
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:304
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:524
A class which implements a DRAMA Message Handler.
Definition messagehandler.hh:138
virtual ~MessageUserStreamBuf()
Destroy the MessgaeUserStream, any remaining output is sent.
Definition messagehandler.hh:827
MessageUserStreamBuf(T &actionObj)
Construct a MessageUserStreamBuf object.
Definition messagehandler.hh:814
Implement a streambuf sub-class that can write messages via the DRAMA MessageUser interface.
Definition messagehandler.hh:754
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:83
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:2323
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:93
void CreateRunDramaTask()
Create and run a DRAMA task, with standard exception handling.
Definition task.hh:1322
std::shared_ptr< MessageHandler > MessageHandlerPtr
This type is used for passing MessageHandler object addresses around.
Definition messagehandler.hh:101
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:111
The drama namespace contains all the classes, types etc of the DRAMA 2 implementation.
Definition drama.hh:93
DRAMA 2 include file - Request class definition.
DRAMA 2 include file - Task class definition.