Class SuperSocket

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

Summary
Public Properties
Public Methods
SuperSocket(host, port)
SuperSocket()
bool writeLine(text)
int read()
string readCommHub(wait, rcLineOnly)
string readDB(wait, lockoutCallbacks)
string readMsg(wait, queueOk)
string readRpc(wait, lockoutCallbacks, queueOk)
bool servicePendingCallbacks(includingCommHub)
bool readyCommHub()
bool readyDB()
bool readyMsg()
bool readyRpc()
inline unsigned int msgSize() const
inline unsigned int dbSize() const
inline unsigned int rpcSize() const
void setCommHubCB(cb, data)
void setDBCB(cb, data)
void setMsgCB(cb, data)
void setRpcCB(cb, data)
void setRpcRespCB(cb, data)
inline SuperSocketFN getMsgCB()
void setDbPrefix(prefix)
void setMsgPrefix(prefix)
void setRpcPrefix(prefix)
static bool setTap(tap)
static FILE* getTap()
static inline bool tapActive()
void processLine(line, lockoutCallbacks)
inline unsigned long getCmdCount() const
Protected Properties
Protected Methods
string readChars(count)
bool readLine(wait, lockoutCallbacks)
Private Properties
Private Methods
void recordLine(send, text)

#include <SuperSocket.h >

Super class: Socket

Summary

This class handles the communication layer between a MAE daemon/app and CommHub.

The challenge that this class faces is that CommHub communicates asynchronously with its client daemons/app, so an app may have sent a DB request (for example) and while wating for the DB response, it may receive some messages, an RPC request, or control message (perhaps initiated by the user).  So, this class has to remember those messages and then process them after the DB response arrives.

Internally, SuperSocket discerns these logical communication categories:

Public Properties

int outDBs

count of outbound DB messages

int outMsgs

count of outbound msgbroker messages

int outRPCs

count of outbound RPC messages

int outOther

count of outbound other (non-DB/Msg/Rpc) messages

int inDBs

count of inbound DB messages

int inMsgs

count of inbound msgbroker messages

int inRPCs

count of inbound RPC messages

int inOther

count of inbound other (non-DB/Msg/Rpc) messages

static Timer timer

Useful timer for performing time triggered activities without interferring with commhub communication.


Public Methods

SuperSocket(host, port)

string host

The hostname to connect to (if empty, then localhost)

int port

The remote TCP port to connect to


Prepare for a TCP socket connection

Return value: instance of Socket to open().  If FALSE, check errno().

SuperSocket()

Construct anempty SuperSocket.

bool writeLine(text)

string text

text to send


Send text to commhub

Any \n will be converted to text (and later back)

Return value: true upon success, false upon failure

int read()

Read any inbound text.

Use its callback (if defined) to process the inbound text.

Return value: socket status (-1 EOF)

string readCommHub(wait, rcLineOnly)

bool wait

block until we have input from commhub

Default value: false

bool rcLineOnly

wait until we get a response line (starts with + or -) and return that; other lines are queued

Default value: false


Wait for text from commhub.

Read text up to a newline.

Return value: the string read.  If empty, check errno().

string readDB(wait, lockoutCallbacks)

bool wait

Default value: false

bool lockoutCallbacks

Default value: false


Wait for DB response.

Read DB response text up to a newline.

Return value: the string read.  If empty, check errno().

string readMsg(wait, queueOk)

bool wait

Set to true to wait until there's valid input, false if just checking quickly

Default value: false

bool queueOk

Set to true if it's OK to pull queued/pending messages (this is normal/default)

Default value: true


Wait for text message.

Read a Message text up to a newline.

Return value: the string read.  If empty, check errno().

string readRpc(wait, lockoutCallbacks, queueOk)

bool wait

Set to true to wait until there's valid input, false if just checking quickly

Default value: false

bool lockoutCallbacks

Set to prevent other requests from being serviced while waiting

Default value: false

bool queueOk

Set to true if it's OK to pull queued/pending messages (this is normal/default)

Default value: true


Wait for text message.

Read an RPC text up to a newline.

Return value: the string read.  If empty, check errno().

bool servicePendingCallbacks(includingCommHub)

bool includingCommHub

Default value: true


bool readyCommHub()

Return true if commhub command queue has a command ready to be processed

Return value: true if there's 1+ backlog commands

bool readyDB()

Return true if DB command queue has a command ready to be processed

Return value: true if there's 1+ backlog commands

bool readyMsg()

Return true if msgbroker message command queue has a command ready to be processed

Return value: true if there's 1+ backlog commands

bool readyRpc()

Return true if RPC command queue has a command ready to be processed

Return value: true if there's 1+ backlog commands

inline unsigned int msgSize() const

Get size of msg backlog queue

Return value: size of the queue

inline unsigned int dbSize() const

Get size of db backlog queue

Return value: size of the queue

inline unsigned int rpcSize() const

Get size of rpc backlog queue

Return value: size of the queue

void setCommHubCB(cb, data)

SuperSocketFN cb

callback function

Default value: NULL

void* data

callback data

Default value: NULL


Setup the commhub callback

void setDBCB(cb, data)

SuperSocketFN cb

callback function

Default value: NULL

void* data

callback data

Default value: NULL


Setup the DB callback

void setMsgCB(cb, data)

SuperSocketFN cb

callback function

Default value: NULL

void* data

callback data

Default value: NULL


Setup the msgbroker message callback

void setRpcCB(cb, data)

SuperSocketFN cb

callback function

Default value: NULL

void* data

callback data

Default value: NULL


Setup the RPC request callback

void setRpcRespCB(cb, data)

SuperSocketFN cb

callback function

Default value: NULL

void* data

callback data

Default value: NULL


Setup the RPC response callback

inline SuperSocketFN getMsgCB()

Get the msgbroker message callback method

Return value: the msgbroker message callback method

void setDbPrefix(prefix)

string prefix

the new prefix


If a different DB prefix hapens, configure new prefix here

void setMsgPrefix(prefix)

string prefix

the new prefix


If a different msgbroker message prefix hapens, configure new prefix here

void setRpcPrefix(prefix)

string prefix

the new prefix


If a different RPC prefix hapens, configure new prefix here

static bool setTap(tap)

FILE* tap

Default value: NULL


Useful for monitoring all socket communication - a socket tap

will record all read/write activity (set to NULL to disable)

static FILE* getTap()

query the tap's pointer

static inline bool tapActive()

Determine if tap is active

void processLine(line, lockoutCallbacks)

const string& line

the line from commhub to process

bool lockoutCallbacks

true if no callbacks should be called to immediately handle a message

Default value: false


Put line into right queue or send to callback (if not locked out/blocked)

inline unsigned long getCmdCount() const

Get # of lines received

Protected Properties

static queue <string > commhub

Queue of backlog commands from commhub

static queue <string > db

Queue of backlog commands from dbbroker

static vector <string > msg

Queue of backlog commands from msgbroker

static vector <string > rpc

Queue of backlog commands from rpcbroker

SuperSocketFN cbfnCommHub

Callback method to handle commhub messages

SuperSocketFN cbfnDB

Callback method to handle DB responses

SuperSocketFN cbfnMsg

Callback method to handle inbound messages from msgbroker

SuperSocketFN cbfnRpc

Callback method to handle rpcbroker requests

SuperSocketFN cbfnRpcResp

Callback method to handle rpcbroker responese

void* cbdataCommHub

Callback data for commhub message callback

void* cbdataDB

Callback data for database message callback

void* cbdataMsg

Callback data for msgbroker message callback

void* cbdataRpc

Callback data for RPC request callback

void* cbdataRpcResp

Callback data for RPC response callback

static string dbPrefix

Prefix characters of DbBroker commands

static string msgPrefix

Prefix characters of MsgBroker commands

static string rpcPrefix

Prefix characters of RpcBroker commands


Protected Methods

string readChars(count)

int count

The number of characters to read


Read the specified number of characters from the socket

Return value: the string read.  If empty, check errno().

bool readLine(wait, lockoutCallbacks)

bool wait

Default value: false

bool lockoutCallbacks

Default value: false


Read text up to a newline.

Return value: true if something read

Private Properties

static Stopwatch time0

Time when socket opened

static FILE* tapf

if a socket tap is active, this points to the file where text is recorded


Private Methods

void recordLine(send, text)

bool send

true is message is outbound, false if message is inbound

const string& text

the message


Save a message out to tap file