AndroMeta  2.0.0
Public Member Functions
Meta::MCommunicator Class Reference

A network communication class for sending and receiving MVar's asynchronously. More...

#include <MCommunicator.h>

Inheritance diagram for Meta::MCommunicator:
Meta::MSocket Meta::MNetProc

List of all members.

Public Member Functions

 MCommunicator (MProcTask *task, MMessageBuffer *sendBuffer=0, MMessageBuffer *receiveBuffer=0)
virtual ~MCommunicator ()
MProcTasktask ()
MMessageBuffersendBuffer ()
MMessageBufferreceiveBuffer ()
void close (bool manual=true)
virtual void onClose (bool manual)
virtual void onConnect ()
bool isConnected () const
bool send (MMessage *msg)
bool send (const mvar &header, const mvar &body)
bool send (const mvar &body)
bool receive (mvar &header, mvar &body)
bool receive (mvar &body)
bool receive (mvar &header, mvar &body, const mtime &timeout)
bool receive (mvar &body, const mtime &timeout)

Detailed Description

A network communication class for sending and receiving MVar's asynchronously.

MCommunicator provides and easy-to-use interface for communicating (complex) data over a socket. MVar's may be sent and received asynchronously. Internally, mvar's are sent and received in compressed binary form.


Constructor & Destructor Documentation

Meta::MCommunicator::MCommunicator ( MProcTask task,
MMessageBuffer sendBuffer = 0,
MMessageBuffer receiveBuffer = 0 
)

Constructor.

Parameters:
taskThe task to use for concurrent/communications processing.
sendBufferThe message buffer to be used for sending. Messages placed in the send buffer are queued for sending using the normal message buffer and message handling semantics. If null, then a send buffer is created and managed internally.
receiveBufferThe message buffer to be used for receiving messages. Received messages are placed in the receive buffer and a message handler is used internally for receiving messages however external message handlers may also respond to messages in this buffer in the usual way. If null, then a receive buffer is created and managed internally.
virtual Meta::MCommunicator::~MCommunicator ( ) [virtual]

Destructor.


Member Function Documentation

void Meta::MCommunicator::close ( bool  manual = true) [virtual]

Shutdown and close the communicator.

Parameters:
manualTrue if the communicator is closing manually as opposed to being closed at the socket-level.

Reimplemented from Meta::MSocket.

Returns:
true If the communicator is connected.
virtual void Meta::MCommunicator::onClose ( bool  manual) [virtual]

Called when the communicator is closed.

Parameters:
manualIndicates that the communicator was closed manually as opposed to being closed at the socket-level.
virtual void Meta::MCommunicator::onConnect ( ) [virtual]

Called upon successful connect. When re-implementing, MCommunicator::onConnect() must be called.

Reimplemented from Meta::MSocket.

bool Meta::MCommunicator::receive ( mvar header,
mvar body 
)

Block until the next message is received by the communicator, retrieving header and body.

Returns:
true on success. Fails if communicator becomes disconnected.

Block until the next message is received by the communicator, retrieving body.

Returns:
true on success. Fails if communicator becomes disconnected.
bool Meta::MCommunicator::receive ( mvar header,
mvar body,
const mtime timeout 
)

Block until the next message is received by the communicator or call times out, retrieving header and body.

Returns:
true on success. Fails if communicator becomes disconnected or timeout is reached.
bool Meta::MCommunicator::receive ( mvar body,
const mtime timeout 
)

Block until the next message is received by the communicator or call times out, retrieving body.

Returns:
true on success. Fails if communicator becomes disconnected or timeout is reached.
Returns:
The message buffer using for receiving -- whether created internally or supplied to the constructor.

The fastest way to send a message as the message data is supplied directly as a pointer. Sends asynchronously.

Parameters:
msgThe message to send -- consumed by communicator so it should not be deleted after this call.
Returns:
true on success. Fails if communicator becomes disconnected.
bool Meta::MCommunicator::send ( const mvar header,
const mvar body 
)

Convenience method to asynchronously send a message by passing header and body.

Returns:
true on success. Fails if communicator becomes disconnected.
bool Meta::MCommunicator::send ( const mvar body)

Convenience method to asynchronously send a message without a header. This is the most common usage.

Returns:
true on success. Fails if communicator becomes disconnected.
Returns:
The message buffer using for sending -- whether created internally or supplied to the constructor.
Returns:
The task the communicator was constructed with.

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