Class Messenger

Index Home MAE > MAE Architecture > MAE Data Types > Class Index > Class Messenger

Summary
Public Methods
Messenger()
bool send(dest, request, data)
bool open(channel, persist, cbfn)
inline string getChannel() const
static Messenger& get(channel)
static StringSet getChannels()
bool sendError(dest, errorMessage)
bool close()
static void closeAll()
bool cease()
inline string getStatus() const
inline void clearStatus()
inline bool fromSysAdmin(source)
Private Properties
Private Methods
static void mastercb(sock, text, data)

#include <Messenger.h >

Summary

Class to handle MAE (one-way) messages between MAE apps.

Messages are routed by MsgBroker.

This class works in conjunction with the MAETask class, which maintains the connection to CommHub, which is required to reach the MsgBroker daemon.

The MAE class class sets up message channels for your app and code generated by genmae uses this class to send messages.

Public Methods

Messenger()

Constructor. Connects to app MAETask class instance.

By default, sent messages will be sent on the task's first registered channel.

bool send(dest, request, data)

const string& dest

the name of the channel to send this message to

const string& request

the message type or name of the request being sent (a keyword)

const XMLData& data

the data/payload of the message. You should make sure it is compatbile with the app that is receiving the request to make sure they key-value pairs in the payload can be processed by the receiving app


Send a message

Return value: true if message sent

bool open(channel, persist, cbfn)

const string& channel

the unique channel name for listening (this is is registered with MsgBroker)

bool persist

true if MsgBroker should queue up messages to this channel even when the channel is off-line

MessengerFN cbfn

specify the message handler that will process the messages, typically handleMessage()


MAE calls this for your app; your app should not call it.

Start listening to a channel.

(Only listen to one channel per instance of Messenger)

inline string getChannel() const

Return name of this channel

Return value: the name of the current channel

static Messenger& get(channel)

const string& channel

the Messenger channel to find.


Get Messenger instance of channel

Return value: the instance Messenger registered to the named channel

static StringSet getChannels()

Get list of all channels open for listening

Return value: a list of all registered channels

bool sendError(dest, errorMessage)

const string& dest

the name of the channel to send this message to

const string& errorMessage

the message to send to the destination channel


Send an error back to the calling app

Return value: true if message sent

bool close()

Close the current channel.

Return value: true

static void closeAll()

Close all open channels.

bool cease()

Close a persistent channel.  MsgBroker will stop queuing messages for this channel.

inline string getStatus() const

Get last status message sent by MsgBroker.

Return value: the current status of the channel

inline void clearStatus()

Clear last status message from MsgBroker.

inline bool fromSysAdmin(source)

const string& source

a channel name to check


Check if a message came from the system administrator

Return value: true if source came from the Supervisor app.

Private Properties

string channel

the message channel for this instance

MessengerFN cbfn

the callback function to handle inbound messages for this channel

string status

the status of this channel

static vector <Messenger* list

all message channels used by this app


Private Methods

static void mastercb(sock, text, data)

SuperSocket& sock

the socket for communication with commhub

const string& text

the message to handle

void* data

callback data


Master callback handler for inbound messages