This class wraps communication via UX sockets for client applications. More...
#include <client.hpp>
Public Member Functions | |
Client (epoll::EventPoll &eventPoll, const std::string &serverPath) | |
Constructs the Client, but doesn't start it. More... | |
~Client () | |
Client (const Client &)=delete | |
Copying Client class is prohibited. More... | |
Client & | operator= (const Client &)=delete |
Copying Client class is prohibited. More... | |
void | start () |
Starts processing. More... | |
bool | isStarted () |
Is the communication thread running? More... | |
void | stop (bool wait=true) |
Stops processing. More... | |
void | setNewPeerCallback (const PeerCallback &newPeerCallback) |
Set the callback called for each new connection to a peer. More... | |
void | setRemovedPeerCallback (const PeerCallback &removedPeerCallback) |
Set the callback called when connection to a peer is lost. More... | |
template<typename SentDataType , typename ReceivedDataType > | |
void | setMethodHandler (const MethodID methodID, const typename MethodHandler< SentDataType, ReceivedDataType >::type &method) |
Saves the callback connected to the method id. More... | |
template<typename ReceivedDataType > | |
void | setSignalHandler (const MethodID methodID, const typename SignalHandler< ReceivedDataType >::type &signal) |
Saves the callback connected to the method id. More... | |
void | removeMethod (const MethodID methodID) |
Removes the callback associated with specific method id. More... | |
bool | isHandled (const MethodID methodID) |
template<typename SentDataType , typename ReceivedDataType > | |
std::shared_ptr< ReceivedDataType > | callSync (const MethodID methodID, const std::shared_ptr< SentDataType > &data, unsigned int timeoutMS=5000) |
Synchronous method call. More... | |
template<typename SentDataType , typename ReceivedDataType > | |
void | callAsync (const MethodID methodID, const std::shared_ptr< SentDataType > &data, const typename ResultHandler< ReceivedDataType >::type &resultCallback=nullptr) |
Asynchronous method call. More... | |
template<typename SentDataType , typename ReceivedDataType > | |
void | callAsyncFromCallback (const MethodID methodID, const std::shared_ptr< SentDataType > &data, const typename ResultHandler< ReceivedDataType >::type &resultCallback=nullptr) |
template<typename SentDataType > | |
void | signal (const MethodID methodID, const std::shared_ptr< SentDataType > &data) |
Send a signal to the peer. More... | |
Private Member Functions | |
void | handle (const FileDescriptor fd, const epoll::Events pollEvents) |
Private Attributes | |
epoll::EventPoll & | mEventPoll |
PeerID | mServiceID |
Processor | mProcessor |
std::string | mSocketPath |
This class wraps communication via UX sockets for client applications.
It uses serialization mechanism from Cargo.
Client::Client | ( | epoll::EventPoll & | eventPoll, |
const std::string & | serverPath | ||
) |
Client::~Client | ( | ) |
void Client::callAsync | ( | const MethodID | methodID, |
const std::shared_ptr< SentDataType > & | data, | ||
const typename ResultHandler< ReceivedDataType >::type & | resultCallback = nullptr |
||
) |
Asynchronous method call.
The return callback will be called on return data arrival. It will be run in the PROCESSOR thread.
methodID | API dependent id of the method |
data | data to send |
resultCallback | callback processing the return data |
SentDataType | data type to send |
ReceivedDataType | data type to receive |
void Client::callAsyncFromCallback | ( | const MethodID | methodID, |
const std::shared_ptr< SentDataType > & | data, | ||
const typename ResultHandler< ReceivedDataType >::type & | resultCallback = nullptr |
||
) |
std::shared_ptr< ReceivedDataType > Client::callSync | ( | const MethodID | methodID, |
const std::shared_ptr< SentDataType > & | data, | ||
unsigned int | timeoutMS = 5000 |
||
) |
Synchronous method call.
methodID | API dependent id of the method |
data | data to send |
timeoutMS | optional, how long to wait for the return value before throw (milliseconds, default: 5000) |
SentDataType | data type to send |
ReceivedDataType | data type to receive |
|
private |
bool Client::isHandled | ( | const MethodID | methodID | ) |
methodID | MethodID defined in the user's API |
bool Client::isStarted | ( | ) |
Is the communication thread running?
void Client::removeMethod | ( | const MethodID | methodID | ) |
Removes the callback associated with specific method id.
methodID | API dependent id of the method |
void Client::setMethodHandler | ( | const MethodID | methodID, |
const typename MethodHandler< SentDataType, ReceivedDataType >::type & | method | ||
) |
Saves the callback connected to the method id.
When a message with the given method id is received the data will be parsed and passed to this callback.
methodID | API dependent id of the method |
method | method handling implementation |
SentDataType | data type to send |
ReceivedDataType | data type to receive |
void Client::setNewPeerCallback | ( | const PeerCallback & | newPeerCallback | ) |
Set the callback called for each new connection to a peer.
newPeerCallback | the callback to call on new connection event |
void Client::setRemovedPeerCallback | ( | const PeerCallback & | removedPeerCallback | ) |
Set the callback called when connection to a peer is lost.
removedPeerCallback | the callback to call on peer disconnected event |
void Client::setSignalHandler | ( | const MethodID | methodID, |
const typename SignalHandler< ReceivedDataType >::type & | signal | ||
) |
Saves the callback connected to the method id.
When a message with the given method id is received the data will be parsed and passed to this callback.
methodID | API dependent id of the method |
signal | data processing callback |
ReceivedDataType | data type to receive |
void Client::signal | ( | const MethodID | methodID, |
const std::shared_ptr< SentDataType > & | data | ||
) |
Send a signal to the peer.
There is no return value from the peer Sends any data only if a peer registered this a signal
methodID | API dependent id of the method |
data | data to send |
SentDataType | data type to send |
void Client::start | ( | ) |
Starts processing.
void Client::stop | ( | bool | wait = true | ) |
Stops processing.
wait | should the call block while waiting for all internals to stop? By default true - do block. |
|
private |
|
private |
|
private |
|
private |