47 #ifndef _MIRA_RPCCLIENT_H_ 48 #define _MIRA_RPCCLIENT_H_ 51 #include <boost/preprocessor/repetition.hpp> 52 #include <boost/thread/mutex.hpp> 135 template <
typename Backend,
typename R>
149 concreteResponsePtr->getReturn(
promise);
156 promise.set_exception(boost::copy_exception(
XRPC(
"Service removed (unpublished or remote disconnected)")));
174 template<
typename Backend,
typename Head,
typename... Tail>
175 void setParameters(
typename Backend::ClientRequest& request, Head&& head, Tail&&... tail)
177 request.setParameter(std::forward<Head>(head));
178 setParameters<Backend>(request, std::forward<Tail>(tail)...);
181 template<
typename Backend>
182 void setParameters(
typename Backend::ClientRequest& request)
218 template<
typename Backend,
typename R,
typename... ARGS>
220 const std::string& method, ARGS&&... args)
222 std::string callId = request.generateCallID();
223 RPCFuture<R> future = addPendingResponse<Backend, R>(callId);
224 request.setHeader(std::move(callId), service, makeRPCSignature<R, ARGS...>(method));
225 setParameters<Backend>(request, std::forward<ARGS>(args)...);
241 template <
typename Backend,
typename R>
245 boost::mutex::scoped_lock lock(mMutex);
248 mPendingResponses[callId] = ptr;
249 return RPCFuture<R>(ptr->promise.get_future(),
this, callId);
260 template <
typename Backend>
264 response.getHeader(callId);
266 boost::mutex::scoped_lock lock(mMutex);
267 auto it = mPendingResponses.find(callId);
271 if(it==mPendingResponses.end())
275 if(typeId<Backend>()!=it->second->getBackendTypeId())
276 MIRA_THROW(XLogical,
"The expected Response Backend type does not match " 277 "the given Response. Probably you sent an RPC call with a " 278 "different Request Backend that does not match to the received " 282 mPendingResponses.erase(it);
285 r->handleResponse(&response);
296 boost::mutex::scoped_lock lock(mMutex);
297 auto it = mPendingResponses.find(callId);
300 if(it==mPendingResponses.end())
304 mPendingResponses.erase(it);
307 r->handleServiceRemoved();
317 boost::mutex::scoped_lock lock(mMutex);
318 mPendingResponses.erase(callId);
323 typedef std::map<std::string, PendingResponsePtr> PendingResponses;
324 PendingResponses mPendingResponses;
TypeId typeId()
Generates unique IDs for different types.
Definition: TypeId.h:94
The RPCClient is responsible for handling the client-side of an rpc call.
Definition: RPCClient.h:104
virtual void handleServiceRemoved()=0
void handleServiceRemoved(const std::string &callId)
Definition: RPCClient.h:294
specialize cv::DataType for our ImgPixel and inherit from cv::DataType<Vec>
Definition: IOService.h:67
PendingResponse template class.
Definition: RPCClient.h:136
virtual int getBackendTypeId() const =0
Implementation of RPCFuture.
An RPCFuture is a proxy for the result of an asynchronous RPC call.
Definition: RPCFuture.h:173
#define MIRA_THROW(ex, msg)
Macro for throwing an exception.
Definition: Exception.h:81
RPCFuture< R > addPendingResponse(const std::string &callId)
Adds a new "PendingResponse" object for a call (with the specified callid) that was either generated ...
Definition: RPCClient.h:242
Contains the base interface of all Reflectors, Serializers, etc.
Abstract interface for RPCClient.
Abstract interface for RPCClient.
Definition: AbstractRPCClient.h:60
An exception that is thrown by the RPCServer if an RPC call fails.
Definition: RPCError.h:76
RPCSignature for storing all information about an RPC method signature.
int backendTypeId
Definition: RPCClient.h:168
virtual ~PendingResponseBase()
Definition: RPCClient.h:113
Interface for PendingResponse.
Definition: RPCClient.h:112
boost::shared_ptr< PendingResponseBase > PendingResponsePtr
Definition: RPCClient.h:171
virtual void onDestructFuture(const std::string &callId)
Is called by the RPCFutures that are created by the call() method upon the destruction of the RPCFutu...
Definition: RPCClient.h:315
Utility macros used in generating RPC method definitions with BOOST_PP.
virtual void handleResponse(void *responsePtr)
Handles the response by calling getReturn() of the RPCResponse backend.
Definition: RPCClient.h:147
virtual void handleServiceRemoved()
Handles the service being removed before a response is received.
Definition: RPCClient.h:155
RPCFuture< R > call(typename Backend::ClientRequest &request, const std::string &service, const std::string &method, ARGS &&... args)
Generates an RPCRequest for an RPC call.
Definition: RPCClient.h:219
PendingResponse()
Definition: RPCClient.h:140
Backend::ClientResponse Response
Definition: RPCClient.h:138
virtual void handleResponse(void *responsePtr)=0
virtual int getBackendTypeId() const
Returns the (non portable) type id of the used backend.
Definition: RPCClient.h:164
boost::promise< R > promise
The boost::promise object that is used for generating and setting the RPCFuture.
Definition: RPCClient.h:167
std::string handleResponse(typename Backend::ClientResponse &response)
Is called after the RPCServer has sent the response of the RPC call to handle the response and to set...
Definition: RPCClient.h:261