• Skip to main content
  • Skip to header right navigation
  • Skip to site footer
CDP Studio logo

CDP Studio

The no-code and full-code software development tool for distributed control systems and HMI

  • Doc
  • Why CDP
    • Software developers
    • Automation engineers
    • Managers
  • Products
    • Automation Designer
    • HMI Designer
    • Maritime HMIs
  • Services
  • Use cases
  • Pricing
  • Try CDP

CDP Studio Documentation

  • Framework - CDP Core
  • MessageArgument
  • 5.0.0

MessageArgument Class

The MessageArgument is a class used to add configurable Message receive and send capability to Operators and Components. More...

Header: #include <MessageArgument>
Inherits: CDPBaseObject
  • List of all members, including inherited members

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(const std::string &command, const std::string &parameter = "", 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)
void SetSendValidator(std::function<MessagePacketHandle( const MessageArgument & arg, std::unique_ptr<CDPConnector> & connector, const MessagePacketHandle & handle ) > validator)
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 ReportFailedReceive(const MessagePacketHandle &handle, const std::string &source) override
  • 49 public functions inherited from CDPBaseObject
  • 27 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
  • 8 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 received 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 received 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::ReportFailedReceive(const MessagePacketHandle &handle, const std::string &source)

Reimplemented from CDPBaseObject::ReportFailedReceive().

std::string MessageArgument::RoutingList() const

Gets the configured RoutingList value

Returns RoutingList value

unsigned int MessageArgument::SendMessage(const std::string &command, const std::string &parameter = "", 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 there are no targets or some targets have no routing set.

unsigned int MessageArgument::SendMessage(const MessagePacketHandle &handle)

Sends Message contained in MessagePacketHandle handle parameter to all configured targets.

Returns 1 on success or 0 when there are no targets or some targets have no routing set.

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 on success or 0 when there are no targets or some targets have no routing set.

void MessageArgument::SetForward(bool forward)

Sets auto forwarding of messages to all routings.

MessageArgument will by default forward all received 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.

void MessageArgument::SetSendValidator(std::function<MessagePacketHandle( const MessageArgument & arg, std::unique_ptr<CDPConnector> & connector, const MessagePacketHandle & handle ) > validator)

std::string MessageArgument::TextCommand() const

Gets the configured TextCommand value

Returns TextCommand value

bool MessageArgument::operator==(const MessageArgument &rhs) const

The content of this document is confidential information not to be published without the consent of CDP Technologies AS.

CDP Technologies AS, www.cdpstudio.com

Get started with CDP Studio today

Let us help you take your great ideas and turn them into the products your customer will love.

Try CDP Studio for free
Why CDP Studio?

CDP Technologies AS
Hundsværgata 8,
P.O. Box 144
6001 Ålesund, Norway

Tel: +47 990 80 900
E-mail: info@cdptech.com

Company

About CDP

Contact us

Services

Partners

Blog

Developers

Get started

User manuals

Support

Document download

Release notes

My account

Follow CDP

  • LinkedIn
  • YouTube
  • GitHub

© Copyright 2025 CDP Technologies. Privacy and cookie policy.

Return to top