26 #ifndef CARGO_IPC_CLIENT_HPP
27 #define CARGO_IPC_CLIENT_HPP
112 void stop(
bool wait =
true);
140 template<
typename SentDataType,
typename ReceivedDataType>
153 template<
typename ReceivedDataType>
182 template<
typename SentDataType,
typename ReceivedDataType>
184 const std::shared_ptr<SentDataType>&
data,
185 unsigned int timeoutMS = 5000);
197 template<
typename SentDataType,
typename ReceivedDataType>
199 const std::shared_ptr<SentDataType>& data,
203 template<
typename SentDataType,
typename ReceivedDataType>
205 const std::shared_ptr<SentDataType>& data,
217 template<
typename SentDataType>
219 const std::shared_ptr<SentDataType>& data);
231 template<
typename SentDataType,
typename ReceivedDataType>
235 LOGS(
"Client setMethodHandler, methodID: " << methodID);
239 template<
typename ReceivedDataType>
243 LOGS(
"Client setSignalHandler, methodID: " << methodID);
247 template<
typename SentDataType,
typename ReceivedDataType>
249 const std::shared_ptr<SentDataType>&
data,
250 unsigned int timeoutMS)
252 LOGS(
"Client callSync, methodID: " << methodID <<
", timeoutMS: " << timeoutMS);
256 template<
typename SentDataType,
typename ReceivedDataType>
258 const std::shared_ptr<SentDataType>&
data,
261 LOGS(
"Client callAsync, methodID: " << methodID);
263 ReceivedDataType>(methodID,
269 template<
typename SentDataType,
typename ReceivedDataType>
271 const std::shared_ptr<SentDataType>&
data,
274 LOGS(
"Client callAsyncFromCallback, methodID: " << methodID);
276 ReceivedDataType>(methodID,
282 template<
typename SentDataType>
284 const std::shared_ptr<SentDataType>&
data)
286 LOGS(
"Client signal, methodID: " << methodID);
293 #endif // CARGO_IPC_CLIENT_HPP
std::function< void(Result< Data > &&) > type
Definition: result.hpp:73
void stop(bool wait=true)
Stops processing.
Definition: client.cpp:74
void callAsync(const MethodID methodID, const std::shared_ptr< SentDataType > &data, const typename ResultHandler< ReceivedDataType >::type &resultCallback=nullptr)
Asynchronous method call.
Definition: client.hpp:257
#define LOGS(MSG)
Automatically create LoggerScope object which logs at the construction and destruction.
Definition: logger-scope.hpp:78
std::string PeerID
Definition: types.hpp:45
void signal(const MethodID methodID, const std::shared_ptr< SentDataType > &data)
Send a signal to the peer.
Definition: client.hpp:283
Data and event processing thread.
void setSignalHandler(const MethodID methodID, const typename SignalHandler< ReceivedDataType >::type &process)
Saves the callbacks connected to the method id.
Definition: processor.hpp:602
Client(epoll::EventPoll &eventPoll, const std::string &serverPath)
Constructs the Client, but doesn't start it.
Definition: client.cpp:34
void setNewPeerCallback(const PeerCallback &newPeerCallback)
Set the callback called for each new connection to a peer.
Definition: client.cpp:103
Class for storing result of a method - data or exception.
void setRemovedPeerCallback(const PeerCallback &removedPeerCallback)
Set the callback called when connection to a peer is lost.
Definition: client.cpp:118
std::function< void(const cargo::ipc::PeerID peerID, const cargo::ipc::FileDescriptor fd)> PeerCallback
Generic function type used as callback for peer events.
Definition: types.hpp:54
void removeMethod(const MethodID methodID)
Removes the callback associated with specific method id.
Definition: client.cpp:130
MessageID callAsync(const MethodID methodID, const PeerID &peerID, const std::shared_ptr< SentDataType > &data, const typename ResultHandler< ReceivedDataType >::type &process)
Asynchronous method call.
Definition: processor.hpp:637
std::shared_ptr< ReceivedDataType > callSync(const MethodID methodID, const std::shared_ptr< SentDataType > &data, unsigned int timeoutMS=5000)
Synchronous method call.
Definition: client.hpp:248
std::function< bool(PeerID peerID, std::shared_ptr< ReceivedDataType > &data)> type
Definition: types.hpp:99
char data[368]
Definition: initctl.cpp:41
PeerID mServiceID
Definition: client.hpp:223
void start()
Starts processing.
Definition: client.cpp:55
void setMethodHandler(const MethodID methodID, const typename MethodHandler< SentDataType, ReceivedDataType >::type &method)
Saves the callback connected to the method id.
Definition: client.hpp:232
bool isHandled(const MethodID methodID)
Definition: client.cpp:136
void setMethodHandler(const MethodID methodID, const typename MethodHandler< SentDataType, ReceivedDataType >::type &process)
Saves the callbacks connected to the method id.
Definition: processor.hpp:560
Client & operator=(const Client &)=delete
Copying Client class is prohibited.
epoll::EventPoll & mEventPoll
Definition: client.hpp:222
void handle(const FileDescriptor fd, const epoll::Events pollEvents)
Definition: client.cpp:83
Processor mProcessor
Definition: client.hpp:224
bool isStarted()
Is the communication thread running?
Definition: client.cpp:69
unsigned int MethodID
Definition: types.hpp:43
unsigned int Events
bitmask of EPOLL* constants
Definition: events.hpp:39
This class wraps communication via UX sockets for client applications.
Definition: client.hpp:73
This class waits on registered file descriptor for events.
Definition: event-poll.hpp:47
void callAsyncFromCallback(const MethodID methodID, const std::shared_ptr< SentDataType > &data, const typename ResultHandler< ReceivedDataType >::type &resultCallback=nullptr)
Definition: client.hpp:270
std::function< bool(PeerID peerID, std::shared_ptr< ReceivedDataType > &data, MethodResult::Pointer methodResult) > type
Definition: method-result.hpp:78
std::string mSocketPath
Definition: client.hpp:225
std::shared_ptr< ReceivedDataType > callSync(const MethodID methodID, const PeerID &peerID, const std::shared_ptr< SentDataType > &data, unsigned int timeoutMS=5000)
Synchronous method call.
Definition: processor.hpp:659
This class wraps communication via UX sockets.
Definition: processor.hpp:88
int FileDescriptor
Definition: types.hpp:42
void setSignalHandler(const MethodID methodID, const typename SignalHandler< ReceivedDataType >::type &signal)
Saves the callback connected to the method id.
Definition: client.hpp:240
MessageID callAsyncNonBlock(const MethodID methodID, const PeerID &peerID, const std::shared_ptr< SentDataType > &data, const typename ResultHandler< ReceivedDataType >::type &process)
The same as callAsync, but not blocking on the state mutex.
Definition: processor.hpp:647
~Client()
Definition: client.cpp:45
void signal(const MethodID methodID, const std::shared_ptr< SentDataType > &data)
Send a signal to the peer.
Definition: processor.hpp:722