MessageArgument Class
The MessageArgument
is a class used to add configurable Message receive and send capability to Operators and Components. More...
Header: | #include <CDPSystem/Base/MessageArgument.h> |
Inherits: | CDPBaseObject |
Public Functions
MessageArgument() | |
MessageArgument(const std::function<int( const MessageArgument &, void * ) > &handler) | |
MessageArgument(const std::function<int( const MessageArgument & arg, const MessagePacketHandle & handle ) > &handler) | |
unsigned int | Command() const |
std::string | GetPayload(void *message) const |
bool | IsConnected() const |
bool | IsForward() const |
bool | IsInput() const |
std::string | RoutingList() const |
unsigned int | SendMessage(Message *message) |
unsigned int | SendMessage(const std::string &command, const std::string ¶meter = "", unsigned int origin = 0) |
unsigned int | SendMessage(const MessagePacketHandle &handle) |
unsigned int | SendPayload(const std::string &payload) |
void | SetForward(bool forward) |
void | SetHandler(std::function<int( const MessageArgument & arg, void * message ) > handler) |
void | SetHandler(std::function<int( const MessageArgument & arg, const MessagePacketHandle & handle ) > handler) |
void | SetRoutingList(const std::string &routingList) |
std::string | TextCommand() const |
bool | operator==(const MessageArgument &rhs) const |
Reimplemented Public Functions
virtual void | Configure(XMLPrimitive *pObjectElement) override |
virtual void | Create(const char *shortName, CDPBaseObject *pParentObject) override |
virtual void | ReportFailedRecieve(const MessagePacketHandle &handle, const std::string &source) override |
- 46 public functions inherited from CDPBaseObject
- 26 public functions inherited from CDP::StudioAPI::CDPNode
- 22 public functions inherited from CDP::StudioAPI::ICDPNode
Additional Inherited Members
- 1 static public member inherited from CDPBaseObject
- 1 protected function inherited from CDP::StudioAPI::CDPNode
- 9 protected variables inherited from CDPBaseObject
Detailed Description
The MessageArgument
is a class used to add configurable Message receive and send capability to Operators and Components.
See configuration information and properties in Configure - MessageArgument
Usage
The MessageArgument
purpose is to simplify setting up receiving, handling and sending messages in configuration. The class takes handler std::function
during construction that is called when a message is received by the given MessageArgument
object.
The prototype of the function is std::function<int(const MessageArgument&, void*)>
handler
Example:
auto arg = new MessageArgument([&](const MessageArgument& arg, void* message)->int { auto msg = static_cast<Message*>(message); // handle message in msg return 1; }); //... arg->SendMessage("MyCommand", "MyValue=7");
Member Function Documentation
MessageArgument::MessageArgument()
Constructs a MessageArgument with no handler.
Default MessageArgument will only forward recieved message to any routings set.
MessageArgument::MessageArgument(const std::function<int( const MessageArgument &, void * ) > &handler)
Constructs a MessageArgument.
Argument handler is the std::function
callback the is called when message is received.
It is possible to pass in either a C++ lambda function as handler or use std::bind
to bind an existing function from the using class as the handler.
MessageArgument::MessageArgument(const std::function<int( const MessageArgument & arg, const MessagePacketHandle & handle ) > &handler)
Copy constructor.
unsigned int MessageArgument::Command() const
Gets the configured Command value
Returns Command value
[override virtual]
void MessageArgument::Configure(XMLPrimitive *pObjectElement)
Reimplemented from CDPBaseObject::Configure().
Registers to receive messages defined by Command and TextCommand properties and connects to RoutingList objects when provided.
[override virtual]
void MessageArgument::Create(const char *shortName, CDPBaseObject *pParentObject)
Reimplemented from CDPBaseObject::Create().
Adds the current MessageArgument
to CDPEngine as possible target for messages.
std::string MessageArgument::GetPayload(void *message) const
bool MessageArgument::IsConnected() const
Gets the connected status
Returns true if MessageArgument
is connected to all objects indicated in the RoutingList property
bool MessageArgument::IsForward() const
Get the state of auto message forwarding.
Returns true if MessageArgument
will forward all recieved messages to all connected objects indicated in the RoutingList property
bool MessageArgument::IsInput() const
Gets the value of Input property
Returns true if MessageArgument
is an input
[override virtual]
void MessageArgument::ReportFailedRecieve(const MessagePacketHandle &handle, const std::string &source)
Reimplemented from CDPBaseObject::ReportFailedRecieve().
std::string MessageArgument::RoutingList() const
Gets the configured RoutingList value
Returns RoutingList value
unsigned int MessageArgument::SendMessage(Message *message)
Sends Message object passed in as message argument
Depending on Command and TextCommand values SendMessage
my override those fields in the message.
Note that application local messages are sent without retry and acknowledge option.
Returns 1 when send was possible to all targets and 0 when some targets were not connected yet.
unsigned int MessageArgument::SendMessage(const std::string &command, const std::string ¶meter = "", unsigned int origin = 0)
Sends message based on MessageArgument
Command and TextCommand properties and passed in arguments
When Command is 0x20100
(CM_TEXTCOMMAND
) and TextCommand is empty, it will use the provided command as the text command string and parameter as parameter data.
When Command is 0x20100
(CM_TEXTCOMMAND
) and TextCommand is set, it will use TextCommand instead of command as the text command string and parameter as parameter data.
When Command is not 0x20100
(CM_TEXTCOMMAND
), it will ignore all arguments besides origin and use Command as the sent binary command.
Returns 1 on success or 0 when some targets were not connected.
unsigned int MessageArgument::SendMessage(const MessagePacketHandle &handle)
unsigned int MessageArgument::SendPayload(const std::string &payload)
Sends Message with default settings using payload as message data.
Depending on Command value SendPayload
will send either text or binary command.
Note that application local messages are sent without retry and acknowledge option.
Returns 1 when send was possible to all targets and 0 when some targets were not connected yet.
void MessageArgument::SetForward(bool forward)
Sets auto forwarding of messages to all routings.
MessageArgument will by default forward all recieved messages to all connected objects indicated in the RoutingList property
void MessageArgument::SetHandler(std::function<int( const MessageArgument & arg, void * message ) > handler)
void MessageArgument::SetHandler(std::function<int( const MessageArgument & arg, const MessagePacketHandle & handle ) > handler)
void MessageArgument::SetRoutingList(const std::string &routingList)
Sets new RoutingList value
Also causes a new connection to be initiated to the provided routings.
std::string MessageArgument::TextCommand() const
Gets the configured TextCommand value
Returns TextCommand value
bool MessageArgument::operator==(const MessageArgument &rhs) const
Get started with CDP Studio today
Let us help you take your great ideas and turn them into the products your customer will love.