FreeNOS
Data Structures | Public Types | Public Member Functions | Private Types | Private Member Functions | Private Attributes | Static Private Attributes
ChannelClient Class Reference

Client for using Channels on the local processor. More...

#include <ChannelClient.h>

Inheritance diagram for ChannelClient:
StrictSingleton< ChannelClient >

Data Structures

struct  Request
 Holds an outgoing request. More...
 

Public Types

enum  Result {
  Success, InvalidArgument, InvalidSize, IOError,
  OutOfMemory, NotFound
}
 Result codes. More...
 

Public Member Functions

 ChannelClient ()
 Constructor. More...
 
virtual ~ChannelClient ()
 Destructor. More...
 
ChannelRegistrygetRegistry ()
 Get channel registry. More...
 
virtual Result initialize ()
 Initialize the ChannelClient. More...
 
virtual Result connect (const ProcessID pid, const Size msgSize)
 Connect to a process. More...
 
virtual Result receiveAny (void *buffer, const Size msgSize, ProcessID *pid)
 Try to receive message from any channel. More...
 
virtual Result sendRequest (const ProcessID pid, void *buffer, const Size msgSize, CallbackFunction *callback)
 Send asynchronous request message. More...
 
virtual Result processResponse (const ProcessID pid, ChannelMessage *msg)
 Process a response message. More...
 
virtual Result syncReceiveFrom (void *buffer, const Size msgSize, const ProcessID pid)
 Synchronous receive from one process. More...
 
virtual Result syncSendTo (const void *buffer, const Size msgSize, const ProcessID pid)
 Synchronous send to one process. More...
 
virtual Result syncSendReceive (void *buffer, const Size msgSize, const ProcessID pid)
 Synchronous send and receive to/from one process. More...
 

Private Types

typedef struct ChannelClient::Request Request
 Holds an outgoing request. More...
 

Private Member Functions

ChannelfindConsumer (const ProcessID pid, const Size msgSize)
 Get consumer for a process. More...
 
ChannelfindProducer (const ProcessID pid, const Size msgSize)
 Get producer for a process. More...
 

Private Attributes

ChannelRegistry m_registry
 Contains registered channels. More...
 
Index< Request, MaximumRequestsm_requests
 Contains ongoing requests. More...
 
const ProcessID m_pid
 Current Process ID. More...
 

Static Private Attributes

static const Size MaximumRequests = 32u
 Maximum number of concurrent outgoing requests. More...
 
static const Size MaxConnectRetries = 16u
 Maximum number of retries for establishing new connection. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from StrictSingleton< ChannelClient >
static ChannelClientinstance ()
 Retrieve the instance. More...
 

Detailed Description

Client for using Channels on the local processor.

Todo:
Intra-core communication is not yet supported by this client. For intra-core channels, the local CoreServer should be contacted which communicates with the remote CoreServer to properly setup the channel between cores.

Definition at line 44 of file ChannelClient.h.

Member Typedef Documentation

◆ Request

Holds an outgoing request.

Member Enumeration Documentation

◆ Result

Result codes.

Enumerator
Success 
InvalidArgument 
InvalidSize 
IOError 
OutOfMemory 
NotFound 

Definition at line 81 of file ChannelClient.h.

Constructor & Destructor Documentation

◆ ChannelClient()

ChannelClient::ChannelClient ( )

Constructor.

Definition at line 24 of file ChannelClient.cpp.

◆ ~ChannelClient()

ChannelClient::~ChannelClient ( )
virtual

Destructor.

Definition at line 30 of file ChannelClient.cpp.

Member Function Documentation

◆ connect()

ChannelClient::Result ChannelClient::connect ( const ProcessID  pid,
const Size  msgSize 
)
virtual

◆ findConsumer()

Channel * ChannelClient::findConsumer ( const ProcessID  pid,
const Size  msgSize 
)
private

Get consumer for a process.

Parameters
pidProcessID of the process
msgSizeMessage size to use.
Returns
Channel object if found or ZERO otherwise.

Definition at line 243 of file ChannelClient.cpp.

References connect(), ERROR, ChannelRegistry::getConsumer(), m_registry, Success, and ZERO.

Referenced by syncReceiveFrom().

◆ findProducer()

Channel * ChannelClient::findProducer ( const ProcessID  pid,
const Size  msgSize 
)
private

Get producer for a process.

Parameters
pidProcessID of the process
msgSizeMessage size to use.
Returns
Channel object if found or ZERO otherwise.

Definition at line 260 of file ChannelClient.cpp.

References connect(), ERROR, ChannelRegistry::getProducer(), m_registry, Success, and ZERO.

Referenced by sendRequest(), and syncSendTo().

◆ getRegistry()

ChannelRegistry & ChannelClient::getRegistry ( )

Get channel registry.

Returns
ChannelRegistry object reference

Definition at line 34 of file ChannelClient.cpp.

References m_registry.

◆ initialize()

ChannelClient::Result ChannelClient::initialize ( )
virtual

Initialize the ChannelClient.

Returns
Result code

Definition at line 39 of file ChannelClient.cpp.

References Success.

◆ processResponse()

ChannelClient::Result ChannelClient::processResponse ( const ProcessID  pid,
ChannelMessage msg 
)
virtual

Process a response message.

Parameters
pidProcessID from which we receive the message
msgMessage which is received
Returns
Result code

Definition at line 220 of file ChannelClient.cpp.

References ChannelClient::Request::active, ChannelClient::Request::callback, CallbackFunction::execute(), ChannelMessage::identifier, m_requests, ChannelClient::Request::message, NotFound, ChannelClient::Request::pid, and Success.

Referenced by ChannelServer< DatastoreServer, DatastoreMessage >::readChannels().

◆ receiveAny()

ChannelClient::Result ChannelClient::receiveAny ( void *  buffer,
const Size  msgSize,
ProcessID pid 
)
virtual

Try to receive message from any channel.

Parameters
bufferMessage buffer for output
msgSizeMessage size to use.
pidProcessID for output
Returns
Result code

Definition at line 140 of file ChannelClient.cpp.

References assert, ChannelRegistry::getConsumers(), HashIterator< K, V >::hasCurrent(), m_registry, NotFound, Channel::Success, and Success.

◆ sendRequest()

ChannelClient::Result ChannelClient::sendRequest ( const ProcessID  pid,
void *  buffer,
const Size  msgSize,
CallbackFunction callback 
)
virtual

Send asynchronous request message.

The client assigns an internal request identifier for the message and ensures that the callback will be called when a response messages is received.

Parameters
pidProcessID to send the message to
bufferPoints to message to send
msgSizeMessage size to use.
callbackCalled when response message is received
Returns
Result code

Definition at line 156 of file ChannelClient.cpp.

References ChannelClient::Request::active, assert, ChannelClient::Request::callback, MemoryBlock::copy(), DEBUG, ERROR, findProducer(), Channel::getMessageSize(), ChannelMessage::identifier, IOError, m_requests, ChannelClient::Request::message, NotFound, NULL, OutOfMemory, ChannelClient::Request::pid, ProcessCtl(), ChannelMessage::Request, Channel::Success, Success, ChannelMessage::type, Wakeup, and Channel::write().

◆ syncReceiveFrom()

ChannelClient::Result ChannelClient::syncReceiveFrom ( void *  buffer,
const Size  msgSize,
const ProcessID  pid 
)
virtual

Synchronous receive from one process.

Parameters
bufferMessage buffer for output
msgSizeMessage size to use.
pidProcessID for the channel
Returns
Result code

Definition at line 277 of file ChannelClient.cpp.

References EnterSleep, ERROR, findConsumer(), NotFound, ProcessCtl(), Channel::read(), SELF, Channel::Success, and Success.

Referenced by syncSendReceive().

◆ syncSendReceive()

ChannelClient::Result ChannelClient::syncSendReceive ( void *  buffer,
const Size  msgSize,
const ProcessID  pid 
)
virtual

Synchronous send and receive to/from one process.

Parameters
bufferMessage buffer to send/receive
msgSizeMessage size to use.
pidProcessID for the channel
Returns
Result code

Definition at line 322 of file ChannelClient.cpp.

References ERROR, Success, syncReceiveFrom(), and syncSendTo().

Referenced by FileSystemClient::request().

◆ syncSendTo()

ChannelClient::Result ChannelClient::syncSendTo ( const void *  buffer,
const Size  msgSize,
const ProcessID  pid 
)
virtual

Synchronous send to one process.

Parameters
bufferMessage buffer to send
msgSizeMessage size to use.
pidProcessID for the channel
Returns
Result code

Definition at line 292 of file ChannelClient.cpp.

References Channel::ChannelFull, ERROR, findProducer(), IOError, NotFound, ProcessCtl(), Schedule, SELF, Channel::Success, Success, Wakeup, and Channel::write().

Referenced by CoreServer::createProcess(), and syncSendReceive().

Field Documentation

◆ m_pid

const ProcessID ChannelClient::m_pid
private

Current Process ID.

Definition at line 235 of file ChannelClient.h.

Referenced by connect().

◆ m_registry

ChannelRegistry ChannelClient::m_registry
private

Contains registered channels.

Definition at line 229 of file ChannelClient.h.

Referenced by connect(), findConsumer(), findProducer(), getRegistry(), and receiveAny().

◆ m_requests

Index<Request, MaximumRequests> ChannelClient::m_requests
private

Contains ongoing requests.

Definition at line 232 of file ChannelClient.h.

Referenced by processResponse(), and sendRequest().

◆ MaxConnectRetries

const Size ChannelClient::MaxConnectRetries = 16u
staticprivate

Maximum number of retries for establishing new connection.

Definition at line 52 of file ChannelClient.h.

Referenced by connect().

◆ MaximumRequests

const Size ChannelClient::MaximumRequests = 32u
staticprivate

Maximum number of concurrent outgoing requests.

Definition at line 49 of file ChannelClient.h.


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