iLab Neuromorphic Robotics Toolkit  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
nrt::MessageSubscription< Port, Msg, Ret > Class Template Reference

#include <nrt/Core/Blackboard/details/ModulePortHelpers.H>

template<class Port, class Msg, class Ret>
class nrt::MessageSubscription< Port, Msg, Ret >

A Subscription is a unique binding of a received Message type and a returned Message type to a port class.

Module objects must implement an onMessage() callback function on a given Subscription port if and only if they derive from the corresponding MessageSubscriber of the Subscription. Typically, Msg and Ret should derive from nrt::MessageBase, with a special case allowed for Ret being void. See MessageSubscriber for how to define onMessage(). A convenience macro is provided (in details/ModuleHelpers.H) to easily declare a subscription class:

Where PortName is the name of the class that will embody your Subscription, MsgType is the type of posted message (must derive from nrt::MessageBase), RetType is the type of message returned by your subscriber (callback) that will respond to posts on any matching Posting (must derive from nrt::MessageBase or be void), and Description is a plain C-style string describing your Subscription. For example:

class MessageA : public nrt::MessageBase { }; // define some message type A
class MessageB : public nrt::MessageBase { }; // define some message type B
NRT_DECLARE_MESSAGESUBSCRIBER_PORT(InputA, MessageA, MessageB, "MessageA Input, returns MessageB results");

The reason for declaring a new Subscription type for each port is to allow one to have several subscribers and callbacks with identical message and return types, but different descriptions and different port classes. Although these deal with identical messages, they may subscribe to them in different namespaces and on different topics (see the definition of MessageSubscriber) and thus achieve different functionalities.

Definition at line 303 of file ModulePortHelpers.H.

Inherits shared_ptr< Msg const >.

Public Types

typedef Port PortType
 
typedef Msg MsgType
 The outgoing message type.
 
typedef Ret RetType
 The return message type.
 
typedef std::shared_ptr< Msg
const > 
MsgPtr
 The outgoing message pointer type.
 
typedef std::shared_ptr< Ret
const > 
RetPtr
 The return message pointer type, as received by poster.
 
typedef std::unique_ptr< Ret > RetUptr
 The return message pointer type, as returned by callback.
 

Public Member Functions

 MessageSubscription (std::shared_ptr< Msg const > msg)
 Construct from a shared_ptr to a message.
 
template<typename... Args>
nrt::MessageSubscription< Port,
Msg, Ret >::RetUptr 
make_return_message (Args &&...args)
 

Static Public Member Functions

static RetPtr runBoundOnMessage (std::function< RetUptr()> func)
 
template<typename... Args>
static RetUptr make_return_message (Args &&...args)
 Allocate a return message and return a unique_ptr to it, to be used in a callback as return value. More...
 

Static Public Attributes

static bool const isSplittable = false
 Subscriptions with non-void returns cannot be split.
 

Member Function Documentation

template<class Port, class Msg, class Ret>
template<typename... Args>
static RetUptr nrt::MessageSubscription< Port, Msg, Ret >::make_return_message ( Args &&...  args)
static

Allocate a return message and return a unique_ptr to it, to be used in a callback as return value.

All given args are forwarded to the return message constructor.


The documentation for this class was generated from the following files: