|
| Service (epoll::EventPoll &eventPoll, const std::string &path, const PeerCallback &addPeerCallback=nullptr, const PeerCallback &removePeerCallback=nullptr) |
| Constructs the Service, but doesn't start it. More...
|
|
virtual | ~Service () |
|
| Service (const Service &)=delete |
| Copying Service class is prohibited. More...
|
|
Service & | operator= (const Service &)=delete |
| Copying Service class is prohibited. More...
|
|
void | start () |
| Starts processing. More...
|
|
bool | isStarted () |
|
void | stop (bool wait=true) |
| Stops all working threads. 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 callbacks connected to the method id. More...
|
|
template<typename ReceivedDataType > |
void | setSignalHandler (const MethodID methodID, const typename SignalHandler< ReceivedDataType >::type &handler) |
| Saves the callbacks 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 PeerID &peerID, 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 PeerID &peerID, 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 PeerID &peerID, 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...
|
|
This class wraps communication via UX sockets.
It uses serialization mechanism from Config.
};
};
connectedCallback, disconnectedCallback));
auto returnData = std::make_shared<SendData>(
data->intVal);
methodResult->set(returnData);
};
myService.setMethodHandler<SendData, RecvData>(exampleMethodID, exampleMethodHandler);
myService.start();
- See Also
- libCargo
-
cargo::ipc::Processor
template<typename SentDataType , typename ReceivedDataType >
void cargo::ipc::Service::setMethodHandler |
( |
const MethodID |
methodID, |
|
|
const typename MethodHandler< SentDataType, ReceivedDataType >::type & |
method |
|
) |
| |
Saves the callbacks connected to the method id.
When a message with the given method id is received, the data will be passed to the serialization callback through file descriptor.
Then the process callback will be called with the parsed data.
- Parameters
-
methodID | API dependent id of the method |
method | data processing callback |
- Template Parameters
-
SentDataType | data type to send |
ReceivedDataType | data type to receive |
template<typename ReceivedDataType >
void cargo::ipc::Service::setSignalHandler |
( |
const MethodID |
methodID, |
|
|
const typename SignalHandler< ReceivedDataType >::type & |
handler |
|
) |
| |
Saves the callbacks connected to the method id.
When a message with the given method id is received, the data will be passed to the serialization callback through file descriptor.
Then the process callback will be called with the parsed data. There is no return data to send back.
Adding signal sends a registering message to all peers
- Parameters
-
methodID | API dependent id of the method |
handler | data processing callback |
- Template Parameters
-
ReceivedDataType | data type to receive |