NAP
Public Member Functions | Public Attributes | List of all members
APIMessage Class Reference

#include <apimessage.h>

Public Member Functions

 APIMessage ()=default
 
virtual ~APIMessage ()
 
 APIMessage (const APIEvent &apiEvent)
 
 APIMessage (const std::string &name)
 
template<typename T , typename... Args>
std::unique_ptr< T > toEvent (Args &&... args)
 
bool toJSON (std::string &outString, utility::ErrorState &error)
 
- Public Member Functions inherited from Resource
 Resource ()
 
- Public Member Functions inherited from Object
 Object ()
 
virtual ~Object ()
 
virtual bool init (utility::ErrorState &errorState)
 
virtual void onDestroy ()
 
 Object (Object &)=delete
 
Objectoperator= (const Object &)=delete
 
 Object (Object &&)=delete
 
Objectoperator= (Object &&)=delete
 

Public Attributes

std::vector< APIBaseValue * > mArguments
 Property: 'Arguments': All input arguments associated with this message. More...
 
std::string mName
 Property: 'Name': action associated with the message. More...
 
- Public Attributes inherited from Object
std::string mID
 Property: 'mID' unique name of the object. Used as an identifier by the system. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from Object
static bool isIDProperty (rtti::Instance &object, const rtti::Property &property)
 

Description

Represents a message that can be given to a running NAP application by calling APIService::sendMessage(). When doing so the message is converted into an api event, which is the runtime version of an api message. For convenience, an api event can also be converted into a message and therefore serialized to JSON. This allows for an easy exchange of messages from and to a NAP application.

Note that the 'mID' of the message needs to be unique when sending multiple messages as a bundle from an external environment. The 'Name' of the message is used to find a matching callback with the same name inside the running application. When the name of the message matches the signature of the callback that callback is invoked.

Inheritance diagram for APIMessage:
[legend]
Collaboration diagram for APIMessage:
[legend]

Constructor & Destructor Documentation

◆ APIMessage() [1/3]

APIMessage ( )
default

◆ ~APIMessage()

virtual ~APIMessage ( )
virtual

◆ APIMessage() [2/3]

APIMessage ( const APIEvent apiEvent)

Constructs this message based on the given api event. All arguments in the api events are copied into this object.

Parameters
apiEventthe event to convert into a message.

◆ APIMessage() [3/3]

APIMessage ( const std::string &  name)

Constructs this message based on the given name

Parameters
namethe name (action) associated with this message

Member Function Documentation

◆ toEvent()

std::unique_ptr< T > toEvent ( Args &&...  args)

Converts this message, including all of it's arguments into an api event of type T. This event is the runtime version of an api message.

Parameters
argsextra input arguments given on construction to api-event of type T.
Returns
the newly created api event of type T.

◆ toJSON()

bool toJSON ( std::string &  outString,
utility::ErrorState error 
)

Converts this message into a JSON readable string

Parameters
outStringthe output of the conversion
errorcontains the error if the message couldn't be converted into a string
Returns
if the message converted to JSON successfully.

Member Data Documentation

◆ mArguments

std::vector<APIBaseValue*> mArguments

Property: 'Arguments': All input arguments associated with this message.

◆ mName

std::string mName

Property: 'Name': action associated with the message.