47 #ifndef _MIRA_RPCSERVER_H_ 48 #define _MIRA_RPCSERVER_H_ 53 #include <boost/preprocessor/repetition.hpp> 54 #include <boost/thread/mutex.hpp> 122 template<
typename Reflector>
125 r.member(
"Name",
name,
"");
162 mReflectMethodParamsDocumentation =
false;
164 <<
"MIRA_RPC_METHODS_REFLECT_NO_PARAMS_DOCUMENTATION " 165 <<
"- RPC parameter documentation will not be shared with " 166 <<
"remote frameworks (ensuring backward compatibility)";
175 bool mReflectMethodParamsDocumentation;
188 template<
typename Reflector>
194 r.member(
"Comment",
comment,
"");
205 template<
typename Reflector>
211 version = r.version(2,
this);
214 r.member(
"Comment",
comment,
"");
223 template<
typename Stream>
230 template<
typename Stream>
280 template<
typename Backend>
283 invokers.insert(std::make_pair(typeId<Backend>(),
284 boost::shared_ptr<RPCInvoker>(invoker)));
288 std::map<int, boost::shared_ptr<RPCInvoker>>
invokers;
301 template <
typename TMethodSet>
307 template<
typename Reflector>
310 r.member(
"Name",
name,
"");
311 r.member(
"Methods",
methods,
"");
355 mService(iService) {}
361 template <
typename Base>
371 return mAddedMethods;
376 return mAddedInterfaces;
382 if(mService.
interfaces.insert(std::string(name)).second)
383 mAddedInterfaces.insert(std::string(name));
394 #define CREATE_WARN_MISSING_PARAMS_DOCUMENTATION(z,n, _) \ 395 template<BOOST_PP_ENUM_PARAMS_Z(z,n,typename P)> \ 396 MIRA_DEPRECATED("_________________Please provide parameter descriptions (and sample values, if appropriate) for RPC methods!_________________", \ 397 void warnMissingParamsDocumentation##n (int dummy BOOST_PP_REPEAT_ ## z(n,RPCGEN_CALL_PARAM_DECL,nil))) {} 400 #undef CREATE_WARN_MISSING_PARAMS_DOCUMENTATION 402 #define RPCGEN_SERVER_METHODS_PUSH_DEFAULTSAMPLE(z, n, _) \ 403 typedef typename std::remove_const<typename std::remove_reference<P##n>::type>::type SampleType##n; \ 404 m.parameterSamples.push_back(createParameterSample<SampleType##n>()); 406 #define RPCGEN_SERVER_METHODS_PUSH_SAMPLE(z, n, _) \ 407 typedef typename std::remove_const<typename std::remove_reference<P##n>::type>::type SampleType##n; \ 408 m.parameterSamples.push_back(createParameterSample<SampleType##n>(sample##n)); 411 #define RPCGEN_SERVER_METHODS(z,n,_) \ 412 template<typename R BOOST_PP_ENUM_TRAILING_PARAMS_Z(z,n,typename P)> \ 413 void method(const char* name, R (*fn)(BOOST_PP_ENUM_PARAMS_Z(z,n,P)), const char* comment) \ 415 warnMissingParamsDocumentation##n(0 BOOST_PP_REPEAT_ ## z(n,RPCGEN_SERVER_PARAM_DEFAULT,nil)); \ 416 Method m(makeRPCSignature<R BOOST_PP_ENUM_TRAILING_PARAMS_Z(z,n,P)>(name), comment); \ 417 BOOST_PP_REPEAT_ ## z(n, RPCGEN_SERVER_METHODS_PUSH_DEFAULTSAMPLE, nil) \ 418 m.addInvoker(make_RPCInvoker<BinaryRPCBackend,R BOOST_PP_ENUM_TRAILING_PARAMS_Z(z,n,P)>(fn)); \ 419 m.addInvoker(make_RPCInvoker<BinaryRPCBackendLegacy,R BOOST_PP_ENUM_TRAILING_PARAMS_Z(z,n,P)>(fn)); \ 420 m.addInvoker(make_RPCInvoker<JSONRPCBackend,R BOOST_PP_ENUM_TRAILING_PARAMS_Z(z,n,P)>(fn)); \ 424 template<typename R, typename Class BOOST_PP_ENUM_TRAILING_PARAMS_Z(z,n,typename P)> \ 425 void method(const char* name, R (Class::*fn)(BOOST_PP_ENUM_PARAMS_Z(z,n,P)), Class* This, const char* comment)\ 427 warnMissingParamsDocumentation##n(0 BOOST_PP_REPEAT_ ## z(n,RPCGEN_SERVER_PARAM_DEFAULT,nil)); \ 428 Method m(makeRPCSignature<R BOOST_PP_ENUM_TRAILING_PARAMS_Z(z,n,P)>(name), comment); \ 429 BOOST_PP_REPEAT_ ## z(n, RPCGEN_SERVER_METHODS_PUSH_DEFAULTSAMPLE, nil) \ 430 m.addInvoker(make_RPCInvoker<BinaryRPCBackend BOOST_PP_ENUM_TRAILING_PARAMS_Z(z,n,P)>(std::mem_fn(fn),This)); \ 431 m.addInvoker(make_RPCInvoker<BinaryRPCBackendLegacy BOOST_PP_ENUM_TRAILING_PARAMS_Z(z,n,P)>(std::mem_fn(fn),This)); \ 432 m.addInvoker(make_RPCInvoker<JSONRPCBackend BOOST_PP_ENUM_TRAILING_PARAMS_Z(z,n,P)>(std::mem_fn(fn),This)); \ 436 template<typename R, typename Class BOOST_PP_ENUM_TRAILING_PARAMS_Z(z,n,typename P)> \ 437 void method(const char* name, R (Class::*fn)(BOOST_PP_ENUM_PARAMS_Z(z,n,P)) const, Class* This, const char* comment) \ 439 warnMissingParamsDocumentation##n(0 BOOST_PP_REPEAT_ ## z(n,RPCGEN_SERVER_PARAM_DEFAULT,nil)); \ 440 Method m(makeRPCSignature<R BOOST_PP_ENUM_TRAILING_PARAMS_Z(z,n,P)>(name), comment); \ 441 BOOST_PP_REPEAT_ ## z(n, RPCGEN_SERVER_METHODS_PUSH_DEFAULTSAMPLE, nil) \ 442 m.addInvoker(make_RPCInvoker<BinaryRPCBackend BOOST_PP_ENUM_TRAILING_PARAMS_Z(z,n,P)>(std::mem_fn(fn),This)); \ 443 m.addInvoker(make_RPCInvoker<BinaryRPCBackendLegacy BOOST_PP_ENUM_TRAILING_PARAMS_Z(z,n,P)>(std::mem_fn(fn),This)); \ 444 m.addInvoker(make_RPCInvoker<JSONRPCBackend BOOST_PP_ENUM_TRAILING_PARAMS_Z(z,n,P)>(std::mem_fn(fn),This)); \ 448 template<typename R BOOST_PP_ENUM_TRAILING_PARAMS_Z(z,n,typename P)> \ 449 void method(const char* name, boost::function<R (BOOST_PP_ENUM_PARAMS_Z(z,n,P))> fn, const char* comment) \ 451 warnMissingParamsDocumentation##n(0 BOOST_PP_REPEAT_ ## z(n,RPCGEN_SERVER_PARAM_DEFAULT,nil)); \ 452 Method m(makeRPCSignature<R BOOST_PP_ENUM_TRAILING_PARAMS_Z(z,n,P)>(name), comment); \ 453 BOOST_PP_REPEAT_ ## z(n, RPCGEN_SERVER_METHODS_PUSH_DEFAULTSAMPLE, nil) \ 454 m.addInvoker(make_RPCInvoker<BinaryRPCBackend,R BOOST_PP_ENUM_TRAILING_PARAMS_Z(z,n,P)>(fn)); \ 455 m.addInvoker(make_RPCInvoker<BinaryRPCBackendLegacy,R BOOST_PP_ENUM_TRAILING_PARAMS_Z(z,n,P)>(fn)); \ 456 m.addInvoker(make_RPCInvoker<JSONRPCBackend,R BOOST_PP_ENUM_TRAILING_PARAMS_Z(z,n,P)>(fn)); \ 461 #undef RPCGEN_SERVER_METHODS 463 #define RPCGEN_SERVER_PARAMINFO_NAME_DESC(z,n,_) ParameterInfo(name##n, description##n) 466 #define RPCGEN_SERVER_METHODS_PARAMDESC(z,n,_) \ 467 template<typename R BOOST_PP_ENUM_TRAILING_PARAMS_Z(z,n,typename P)> \ 468 void method(const char* name, R (*fn)(BOOST_PP_ENUM_PARAMS_Z(z,n,P)), \ 469 const char* comment, BOOST_PP_ENUM(n,RPCGEN_CALL_NAME_DESC_DECL,nil)) \ 471 Method m(makeRPCSignature<R BOOST_PP_ENUM_TRAILING_PARAMS_Z(z,n,P)>(name), comment, \ 472 ParameterDescriptions{BOOST_PP_ENUM(n,RPCGEN_SERVER_PARAMINFO_NAME_DESC,nil)}); \ 473 BOOST_PP_REPEAT_ ## z(n, RPCGEN_SERVER_METHODS_PUSH_DEFAULTSAMPLE, nil) \ 474 m.addInvoker(make_RPCInvoker<BinaryRPCBackend,R BOOST_PP_ENUM_TRAILING_PARAMS_Z(z,n,P)>(fn)); \ 475 m.addInvoker(make_RPCInvoker<BinaryRPCBackendLegacy,R BOOST_PP_ENUM_TRAILING_PARAMS_Z(z,n,P)>(fn)); \ 476 m.addInvoker(make_RPCInvoker<JSONRPCBackend,R BOOST_PP_ENUM_TRAILING_PARAMS_Z(z,n,P)>(fn)); \ 480 template<typename R, typename Class BOOST_PP_ENUM_TRAILING_PARAMS_Z(z,n,typename P)> \ 481 void method(const char* name, R (Class::*fn)(BOOST_PP_ENUM_PARAMS_Z(z,n,P)), Class* This, \ 482 const char* comment, BOOST_PP_ENUM(n,RPCGEN_CALL_NAME_DESC_DECL,nil)) \ 484 Method m(makeRPCSignature<R BOOST_PP_ENUM_TRAILING_PARAMS_Z(z,n,P)>(name), comment, \ 485 ParameterDescriptions{BOOST_PP_ENUM(n,RPCGEN_SERVER_PARAMINFO_NAME_DESC,nil)}); \ 486 BOOST_PP_REPEAT_ ## z(n, RPCGEN_SERVER_METHODS_PUSH_DEFAULTSAMPLE, nil) \ 487 m.addInvoker(make_RPCInvoker<BinaryRPCBackend BOOST_PP_ENUM_TRAILING_PARAMS_Z(z,n,P)>(std::mem_fn(fn),This)); \ 488 m.addInvoker(make_RPCInvoker<BinaryRPCBackendLegacy BOOST_PP_ENUM_TRAILING_PARAMS_Z(z,n,P)>(std::mem_fn(fn),This)); \ 489 m.addInvoker(make_RPCInvoker<JSONRPCBackend BOOST_PP_ENUM_TRAILING_PARAMS_Z(z,n,P)>(std::mem_fn(fn),This)); \ 493 template<typename R, typename Class BOOST_PP_ENUM_TRAILING_PARAMS_Z(z,n,typename P)> \ 494 void method(const char* name, R (Class::*fn)(BOOST_PP_ENUM_PARAMS_Z(z,n,P)) const, Class* This, \ 495 const char* comment, BOOST_PP_ENUM(n,RPCGEN_CALL_NAME_DESC_DECL,nil)) \ 497 Method m(makeRPCSignature<R BOOST_PP_ENUM_TRAILING_PARAMS_Z(z,n,P)>(name), comment, \ 498 ParameterDescriptions{BOOST_PP_ENUM(n,RPCGEN_SERVER_PARAMINFO_NAME_DESC,nil)}); \ 499 BOOST_PP_REPEAT_ ## z(n, RPCGEN_SERVER_METHODS_PUSH_DEFAULTSAMPLE, nil) \ 500 m.addInvoker(make_RPCInvoker<BinaryRPCBackend BOOST_PP_ENUM_TRAILING_PARAMS_Z(z,n,P)>(std::mem_fn(fn),This)); \ 501 m.addInvoker(make_RPCInvoker<BinaryRPCBackendLegacy BOOST_PP_ENUM_TRAILING_PARAMS_Z(z,n,P)>(std::mem_fn(fn),This)); \ 502 m.addInvoker(make_RPCInvoker<JSONRPCBackend BOOST_PP_ENUM_TRAILING_PARAMS_Z(z,n,P)>(std::mem_fn(fn),This)); \ 506 template<typename R BOOST_PP_ENUM_TRAILING_PARAMS_Z(z,n,typename P)> \ 507 void method(const char* name, boost::function<R (BOOST_PP_ENUM_PARAMS_Z(z,n,P))> fn, \ 508 const char* comment, BOOST_PP_ENUM(n,RPCGEN_CALL_NAME_DESC_DECL,nil)) \ 510 Method m(makeRPCSignature<R BOOST_PP_ENUM_TRAILING_PARAMS_Z(z,n,P)>(name), comment, \ 511 ParameterDescriptions{BOOST_PP_ENUM(n,RPCGEN_SERVER_PARAMINFO_NAME_DESC,nil)}); \ 512 BOOST_PP_REPEAT_ ## z(n, RPCGEN_SERVER_METHODS_PUSH_DEFAULTSAMPLE, nil) \ 513 m.addInvoker(make_RPCInvoker<BinaryRPCBackend,R BOOST_PP_ENUM_TRAILING_PARAMS_Z(z,n,P)>(fn)); \ 514 m.addInvoker(make_RPCInvoker<BinaryRPCBackendLegacy,R BOOST_PP_ENUM_TRAILING_PARAMS_Z(z,n,P)>(fn)); \ 515 m.addInvoker(make_RPCInvoker<JSONRPCBackend,R BOOST_PP_ENUM_TRAILING_PARAMS_Z(z,n,P)>(fn)); \ 521 #undef RPCGEN_SERVER_METHODS_PARAMDESC 524 #define RPCGEN_SERVER_METHODS_PARAMDESCSAMPLE(z,n,_) \ 525 template<typename R, BOOST_PP_ENUM(n,RPCGEN_CALL_TYPENAME_PARAM_DECL,nil)> \ 526 void method(const char* name, R (*fn)(BOOST_PP_ENUM_PARAMS_Z(z,n,P)), \ 527 const char* comment, BOOST_PP_ENUM(n,RPCGEN_CALL_NAME_DESC_SAMPLE_DECL,nil)) \ 529 Method m(makeRPCSignature<R BOOST_PP_ENUM_TRAILING_PARAMS_Z(z,n,P)>(name), comment, \ 530 ParameterDescriptions{BOOST_PP_ENUM(n,RPCGEN_SERVER_PARAMINFO_NAME_DESC,nil)}); \ 531 BOOST_PP_REPEAT_ ## z(n, RPCGEN_SERVER_METHODS_PUSH_SAMPLE, nil) \ 532 m.parameterSamplesDefault = false; \ 533 m.addInvoker(make_RPCInvoker<BinaryRPCBackend,R BOOST_PP_ENUM_TRAILING_PARAMS_Z(z,n,P)>(fn)); \ 534 m.addInvoker(make_RPCInvoker<BinaryRPCBackendLegacy,R BOOST_PP_ENUM_TRAILING_PARAMS_Z(z,n,P)>(fn)); \ 535 m.addInvoker(make_RPCInvoker<JSONRPCBackend,R BOOST_PP_ENUM_TRAILING_PARAMS_Z(z,n,P)>(fn)); \ 539 template<typename R, typename Class, BOOST_PP_ENUM(n,RPCGEN_CALL_TYPENAME_PARAM_DECL,nil)> \ 540 void method(const char* name, R (Class::*fn)(BOOST_PP_ENUM_PARAMS_Z(z,n,P)), Class* This, \ 541 const char* comment, BOOST_PP_ENUM(n,RPCGEN_CALL_NAME_DESC_SAMPLE_DECL,nil)) \ 543 Method m(makeRPCSignature<R BOOST_PP_ENUM_TRAILING_PARAMS_Z(z,n,P)>(name), comment, \ 544 ParameterDescriptions{BOOST_PP_ENUM(n,RPCGEN_SERVER_PARAMINFO_NAME_DESC,nil)}); \ 545 BOOST_PP_REPEAT_ ## z(n, RPCGEN_SERVER_METHODS_PUSH_SAMPLE, nil) \ 546 m.parameterSamplesDefault = false; \ 547 m.addInvoker(make_RPCInvoker<BinaryRPCBackend BOOST_PP_ENUM_TRAILING_PARAMS_Z(z,n,P)>(std::mem_fn(fn),This)); \ 548 m.addInvoker(make_RPCInvoker<BinaryRPCBackendLegacy BOOST_PP_ENUM_TRAILING_PARAMS_Z(z,n,P)>(std::mem_fn(fn),This)); \ 549 m.addInvoker(make_RPCInvoker<JSONRPCBackend BOOST_PP_ENUM_TRAILING_PARAMS_Z(z,n,P)>(std::mem_fn(fn),This)); \ 553 template<typename R, typename Class, BOOST_PP_ENUM(n,RPCGEN_CALL_TYPENAME_PARAM_DECL,nil)> \ 554 void method(const char* name, R (Class::*fn)(BOOST_PP_ENUM_PARAMS_Z(z,n,P)) const, Class* This, \ 555 const char* comment, BOOST_PP_ENUM(n,RPCGEN_CALL_NAME_DESC_SAMPLE_DECL,nil)) \ 557 Method m(makeRPCSignature<R BOOST_PP_ENUM_TRAILING_PARAMS_Z(z,n,P)>(name), comment, \ 558 ParameterDescriptions{BOOST_PP_ENUM(n,RPCGEN_SERVER_PARAMINFO_NAME_DESC,nil)}); \ 559 BOOST_PP_REPEAT_ ## z(n, RPCGEN_SERVER_METHODS_PUSH_SAMPLE, nil) \ 560 m.parameterSamplesDefault = false; \ 561 m.addInvoker(make_RPCInvoker<BinaryRPCBackend BOOST_PP_ENUM_TRAILING_PARAMS_Z(z,n,P)>(std::mem_fn(fn),This)); \ 562 m.addInvoker(make_RPCInvoker<BinaryRPCBackendLegacy BOOST_PP_ENUM_TRAILING_PARAMS_Z(z,n,P)>(std::mem_fn(fn),This)); \ 563 m.addInvoker(make_RPCInvoker<JSONRPCBackend BOOST_PP_ENUM_TRAILING_PARAMS_Z(z,n,P)>(std::mem_fn(fn),This)); \ 567 template<typename R, BOOST_PP_ENUM(n,RPCGEN_CALL_TYPENAME_PARAM_DECL,nil)> \ 568 void method(const char* name, boost::function<R (BOOST_PP_ENUM_PARAMS_Z(z,n,P))> fn, \ 569 const char* comment, BOOST_PP_ENUM(n,RPCGEN_CALL_NAME_DESC_SAMPLE_DECL,nil)) \ 571 Method m(makeRPCSignature<R BOOST_PP_ENUM_TRAILING_PARAMS_Z(z,n,P)>(name), comment, \ 572 ParameterDescriptions{BOOST_PP_ENUM(n,RPCGEN_SERVER_PARAMINFO_NAME_DESC,nil)}); \ 573 BOOST_PP_REPEAT_ ## z(n, RPCGEN_SERVER_METHODS_PUSH_SAMPLE, nil) \ 574 m.parameterSamplesDefault = false; \ 575 m.addInvoker(make_RPCInvoker<BinaryRPCBackend,R BOOST_PP_ENUM_TRAILING_PARAMS_Z(z,n,P)>(fn)); \ 576 m.addInvoker(make_RPCInvoker<BinaryRPCBackendLegacy,R BOOST_PP_ENUM_TRAILING_PARAMS_Z(z,n,P)>(fn)); \ 577 m.addInvoker(make_RPCInvoker<JSONRPCBackend,R BOOST_PP_ENUM_TRAILING_PARAMS_Z(z,n,P)>(fn)); \ 583 #undef RPCGEN_SERVER_METHODS_PARAMDESCSAMPLE 585 #undef RPCGEN_SERVER_PARAMINFO_NAME_DESC 590 #define RPCGEN_SERVER_METHODS_WRONG_ARGUMENT_NUMBER(z,n,_) \ 591 template<typename R BOOST_PP_ENUM_TRAILING_PARAMS_Z(z,n,typename P), typename... Args> \ 592 void method(const char* name, R (*fn)(BOOST_PP_ENUM_PARAMS_Z(z,n,P)), \ 593 const char* comment, Args...) \ 595 invalid_method<R BOOST_PP_ENUM_TRAILING_PARAMS_Z(z,n,P)>(); \ 597 template<typename R, typename Class BOOST_PP_ENUM_TRAILING_PARAMS_Z(z,n,typename P), typename... Args> \ 598 void method(const char* name, R (Class::*fn)(BOOST_PP_ENUM_PARAMS_Z(z,n,P)), Class* This, \ 599 const char* comment, Args...) \ 601 invalid_method<R BOOST_PP_ENUM_TRAILING_PARAMS_Z(z,n,P)>(); \ 604 template<typename R, typename Class BOOST_PP_ENUM_TRAILING_PARAMS_Z(z,n,typename P), typename... Args> \ 605 void method(const char* name, R (Class::*fn)(BOOST_PP_ENUM_PARAMS_Z(z,n,P)) const, Class* This, \ 606 const char* comment, Args...) \ 608 invalid_method<R BOOST_PP_ENUM_TRAILING_PARAMS_Z(z,n,P)>(); \ 611 template<typename R BOOST_PP_ENUM_TRAILING_PARAMS_Z(z,n,typename P), typename... Args> \ 612 void method(const char* name, boost::function<R (BOOST_PP_ENUM_PARAMS_Z(z,n,P))> fn, \ 613 const char* comment, Args...) \ 615 invalid_method<R BOOST_PP_ENUM_TRAILING_PARAMS_Z(z,n,P)>(); \ 619 #undef RPCGEN_SERVER_METHODS_WRONG_ARGUMENT_NUMBER 623 void addMethod(
const Method&
method) {
624 foreach (
const MethodInfo& m, mService.
methods) {
626 if ((m.signature.name ==
method.signature.name) &&
627 (m.signature.parameterTypes.size() ==
method.signature.parameterTypes.size())) {
630 <<
" are ambiguous when called through JSON RPC" 631 <<
" - suggest choosing different method names.";
636 mAddedMethods.insert(
method.signature);
641 json::Value createParameterSample(
const T& v = T()) {
651 std::set<RPCSignature> mAddedMethods;
654 std::set<std::string> mAddedInterfaces;
657 JSONSerializer mJSONSerializer;
669 template <
typename T>
672 std::set<RPCSignature>* addedMethods = NULL,
673 std::set<std::string>* addedInterfaces = NULL)
675 boost::mutex::scoped_lock lock(mMutex);
678 ServiceMap::iterator it = mServices.find(serviceName);
679 if (it==mServices.end())
680 it = mServices.insert(std::make_pair(serviceName,
686 serviceObject.reflect(r);
689 serviceName <<
"'. With the following new methods:";
693 if(addedMethods!=NULL)
696 if(addedInterfaces!=NULL)
708 boost::mutex::scoped_lock lock(mMutex);
709 MIRA_LOG(
NOTICE) <<
"Unregistering service: '" << serviceName <<
"'.";
710 mServices.erase(serviceName);
730 boost::mutex::scoped_lock lock(mMutex);
731 auto i = mServices.find(name);
732 if (i == mServices.end())
733 MIRA_THROW(XInvalidParameter,
"No such service '" << name <<
"'");
743 boost::mutex::scoped_lock lock(mMutex);
744 auto i = mServices.find(name);
745 return i!= mServices.end();
754 boost::mutex::scoped_lock lock(mMutex);
755 std::list<std::string> res;
757 for(
auto it=mServices.begin(); it!=mServices.end(); ++it)
759 if(it->second.interfaces.count(interface)!=0)
760 res.push_back(it->second.name);
769 boost::mutex::scoped_lock lock(mMutex);
770 auto it = mServices.find(name);
771 if (it == mServices.end())
773 return it->second.interfaces.count(interface) > 0;
784 template <
typename Backend>
786 typename Backend::ServerResponse& response)
788 boost::shared_ptr<TRPCInvoker<Backend>> invoker;
793 if(!processCallCommon<Backend>(request, response, callId, invoker, service, method))
797 response.setHeader(callId);
800 invoker->invoke(request, response);
802 catch(std::exception& ex) {
816 template <
typename Backend>
821 typename Backend::ServerResponse& response,
822 const std::string& callId,
823 const std::string& service,
824 const std::string& method,
827 mRequest(request), mResponse(response),
834 mInvoker->invoke(mRequest, mResponse);
836 catch(std::exception& ex) {
844 }
catch(std::exception& ex) {
850 typename Backend::ServerRequest& mRequest;
851 typename Backend::ServerResponse& mResponse;
852 boost::shared_ptr<TRPCInvoker<Backend>> mInvoker;
866 template <
typename Backend>
868 typename Backend::ServerResponse& response)
870 boost::shared_ptr<TRPCInvoker<Backend>> invoker;
876 if(processCallCommon<Backend>(request, response, callId, invoker, service, method)) {
877 assert(service!=NULL);
882 return deferredInvoker;
892 template <
typename Backend>
894 typename Backend::ServerResponse& response,
895 std::string &oCallId,
901 std::string serviceStr;
904 request.getHeader(callId, serviceStr);
905 }
catch(std::exception& ex) {
912 boost::mutex::scoped_lock lock(mMutex);
915 auto serviceIt = mServices.find(serviceStr);
917 if(serviceIt==mServices.end()) {
920 "Cannot process RPC call, a service named '" 921 + serviceStr +
"' does not exist", response);
925 Service& service = serviceIt->second;
933 if(request.checkSignature(m.
signature)) {
935 method =
const_cast<Method*
>(&m);
943 std::string methodName = request.getSignature().name;
944 std::string candidates;
948 if(!candidates.empty())
954 if(!candidates.empty())
955 candidates =
" Candidates are: " + candidates;
957 candidates =
" No candidates found.";
961 <<
", candidates: " << candidates;
962 generateErrorResponse<Backend>(callId,
964 serviceStr +
"' does not have a method '" +
965 toString(request.getSignature()) +
"'." + candidates,
971 auto invokerIt = method->
invokers.find(typeId<Backend>());
972 if(invokerIt == method->
invokers.end())
973 MIRA_THROW(XLogical,
"Cannot process RPC call, no invoker for service method '" <<
974 serviceStr <<
"." << request.getSignature() <<
975 "' was registered for backend type '" <<
976 typeName<Backend>() <<
"'.");
988 template <
typename Backend>
990 RPCError reason,
const std::string& message,
991 typename Backend::ServerResponse& oResponse)
993 oResponse.setHeader(callId);
994 oResponse.returnException(reason, message);
1000 mutable boost::mutex mMutex;
#define CREATE_WARN_MISSING_PARAMS_DOCUMENTATION(z, n, _)
Definition: RPCServer.h:394
DeferredInvoker(typename Backend::ServerRequest &request, typename Backend::ServerResponse &response, const std::string &callId, const std::string &service, const std::string &method, boost::shared_ptr< TRPCInvoker< Backend >> invoker)
Definition: RPCServer.h:820
ServiceInfo< MethodSet > Service
Definition: RPCServer.h:323
MethodInfo(const RPCSignature &iSignature, const std::string &iComment)
Definition: RPCServer.h:180
Definition: BinarySerializer.h:324
Contains all available information about a single RPC service, including the service' name...
Definition: RPCServer.h:302
#define RPC_METHODS_MAX_PARAMS
Definition: ReflectorInterface.h:583
AbstractDeferredInvokerPtr processCallDeferred(typename Backend::ServerRequest &request, typename Backend::ServerResponse &response)
Similar to processCall() this method decodes the RPCRequest which was received from the client-side...
Definition: RPCServer.h:867
void unregisterService(const std::string &serviceName)
Unregisters the specified service with all methods of all service objects that were registered...
Definition: RPCServer.h:706
Method(const RPCSignature &signature, const std::string &comment, const ParameterDescriptions ¶meterDescriptions)
Definition: RPCServer.h:275
Provides binary client and server side requests and responses.
bool implementsInterface(const std::string &name, const std::string &interface) const
Returns if the given service implements a certain interface.
Definition: RPCServer.h:767
std::string comment
User comments and description.
Definition: RPCServer.h:255
Contains information on an RPC method's parameter: name, description.
Definition: RPCServer.h:115
Invalid parameters were specified for the method.
Definition: RPCError.h:68
void reflect(ConcreteBinarySerializer< Stream, 0 > &r)
Definition: RPCServer.h:224
RPCReflector(Service &iService)
Definition: RPCServer.h:354
const std::set< std::string > & getAddedInterfaces() const
Returns all interfaces that were added to the service while visiting the service object.
Definition: RPCServer.h:375
Implementation of the CreationPolicy that is used by the Singleton template.
Definition: Singleton.h:174
#define RPCGEN_SERVER_METHODS(z, n, _)
Definition: RPCServer.h:411
Contains information on an existing RPC method: the signature of the method, comments, etc.
Definition: RPCServer.h:150
MethodInfo()
Definition: RPCServer.h:178
static Type & instance()
Returns a reference to the singleton instance.
Definition: Singleton.h:544
bool existsService(const std::string &name) const
Returns true, if a service with the specified name exists, otherwise false.
Definition: RPCServer.h:741
specialize cv::DataType for our ImgPixel and inherit from cv::DataType<Vec>
Definition: IOService.h:67
Error codes for reasons of errors/exceptions while processing an rpc call.
std::map< int, boost::shared_ptr< RPCInvoker > > invokers
stores corresponding RPCInvoker for each backend type
Definition: RPCServer.h:288
#define RPCGEN_SERVER_METHODS_WRONG_ARGUMENT_NUMBER(z, n, _)
Definition: RPCServer.h:590
ReflectMethodParamsDocumentation()
Definition: RPCServer.h:157
Invoker that is used to invoke an RPC method call for a special backend.
Definition: RPCInvoker.h:94
#define MIRA_LOG(level)
Use this macro to log data.
Definition: LoggingCore.h:528
std::string description
Parameter description.
Definition: RPCServer.h:133
std::list< json::Value > parameterSamples
Definition: RPCServer.h:262
ParameterInfo()
Definition: RPCServer.h:117
Abstract interface for DeferredInvoker which is a class to support different RPC backends.
Definition: AbstractDeferredInvoker.h:80
Contains toString and fromString functions for converting data types to strings and the other way rou...
#define RPCGEN_SERVER_METHODS_PARAMDESCSAMPLE(z, n, _)
Definition: RPCServer.h:524
Definition: BinarySerializer.h:991
std::string extendedSignature() const
void reflect(Reflector &r)
Definition: RPCServer.h:123
Definition: RPCServer.h:152
void serialize(const std::string &name, const T &value, const std::string &comment="")
Serializes the specified object value under the given name.
Definition: Serializer.h:204
bool processCallCommon(typename Backend::ServerRequest &request, typename Backend::ServerResponse &response, std::string &oCallId, boost::shared_ptr< TRPCInvoker< Backend >> &oInvoker, Service *&oService, Method *&oMethod)
contains common functionality that is used by processCall() and processCallDeferred() ...
Definition: RPCServer.h:893
uint8 VersionType
Definition: ReflectorInterface.h:72
#define MIRA_THROW(ex, msg)
Macro for throwing an exception.
Definition: Exception.h:81
This is the public interface of all reflectors that are able to visit a class' reflect() method...
Definition: ReflectorInterface.h:111
Provides JSON client and server side requests and responses.
std::string toString(const T &value, int precision=-1)
Converts any data type to string (the data type must support the stream << operator).
Definition: ToString.h:256
void reflectBinaryV0(Reflector &r)
Definition: RPCServer.h:206
const Service & registerServiceObject(const std::string &serviceName, T &serviceObject, std::set< RPCSignature > *addedMethods=NULL, std::set< std::string > *addedInterfaces=NULL)
Registers the methods of the specified service object under the specified service name...
Definition: RPCServer.h:670
TMethodSet methods
All methods that were registered for this service.
Definition: RPCServer.h:318
void warnMissingParamsDocumentation0(int)
Definition: RPCServer.h:392
Contains the base interface of all Reflectors, Serializers, etc.
Special visitor for the reflect() method that visits all method() and interface() calls within the re...
Definition: RPCServer.h:339
void interface(const char *name)
Definition: RPCServer.h:381
Auxiliary logging macros for special entities like exceptions, etc.
#define RPCGEN_SERVER_METHODS_PARAMDESC(z, n, _)
Definition: RPCServer.h:466
A singleton template class that can be freely configured using policies that control the instantiatio...
Definition: Singleton.h:531
MIRA_BASE_EXPORT std::string resolveEnvironmentVariable(const std::string &envVar)
Resolves an environmental variable.
Core class of the logging library.
std::string name
Parameter name.
Definition: RPCServer.h:130
RPCSignature for storing all information about an RPC method signature.
Contains all information on a registered RPC method, including the signature of the method...
Definition: RPCServer.h:270
Implements the RPCInvoker and TRPCInvoker classes.
bool operator<(const MethodInfo &rhs) const
Definition: RPCServer.h:236
void reflect(Reflector &r)
Definition: RPCServer.h:308
Abstract interface for DeferredInvoker.
ServiceInfo(const std::string &iName="")
Definition: RPCServer.h:304
std::string sampleParametersSet(bool formatted=false) const
std::string name
The method's name.
Definition: RPCSignature.h:134
std::string mCallId
Definition: AbstractDeferredInvoker.h:113
bool operator==(const MethodInfo &rhs) const
Definition: RPCServer.h:240
void generateErrorResponse(const std::string &callId, RPCError reason, const std::string &message, typename Backend::ServerResponse &oResponse)
Definition: RPCServer.h:989
RPCError
enumeration of possible reasons for errors/exceptions while performing an RPC call ...
Definition: RPCError.h:64
const std::set< RPCSignature > & getAddedMethods() const
Returns all methods that were added to the service while visiting the service object.
Definition: RPCServer.h:370
json_spirit::mValue Value
A value is an abstract description of data in JSON (underlying data can either be one of the JSON bas...
Definition: JSON.h:176
virtual void invoke()
Invokes the RPC call that is represented by this DeferredInvoker.
Definition: RPCServer.h:830
void method(const char *name, Method method, const char *comment, const char *paramName, const char *paramDescription, P paramSampleValue,...)
Specifies that the class that is reflected provides a service through the specified static member fun...
void addInvoker(TRPCInvoker< Backend > *invoker)
adds a new invoker that processes the method for a certain backend
Definition: RPCServer.h:281
void processCall(typename Backend::ServerRequest &request, typename Backend::ServerResponse &response)
Decodes the Request which was received from the client-side and invokes the RPC call immediately...
Definition: RPCServer.h:785
void reflectBase(Base &base)
implements ReflectorInterface (for documentation see ReflectorInterface)
Definition: RPCServer.h:362
std::list< std::string > queryServicesForInterface(const std::string &interface) const
Returns a string list with the names of all registered services, that implement the specified interfa...
Definition: RPCServer.h:752
#define MIRA_LOG_EXCEPTION(level, ex)
Log the specified exception, including all information that the exception object carries.
Definition: LoggingAux.h:107
std::set< MethodInfo > MethodInfoSet
Definition: RPCServer.h:293
std::map< std::string, Service > ServiceMap
Definition: RPCServer.h:325
Definition: LoggingCore.h:75
Functions for platform independent resolving of environment variables.
friend std::ostream & operator<<(std::ostream &s, const ParameterInfo &v)
Definition: RPCServer.h:137
RPCSignature signature
The signature of the method (including its name)
Definition: RPCServer.h:252
std::set< Method > MethodSet
Definition: RPCServer.h:291
std::set< std::string > interfaces
All interfaces that this service supports.
Definition: RPCServer.h:320
Requested method was not found.
Definition: RPCError.h:67
std::string name
The name of this service.
Definition: RPCServer.h:316
void reflect(ConcreteBinaryDeserializer< Stream, 0 > &r)
Definition: RPCServer.h:231
static bool enabled()
Definition: RPCServer.h:172
Definition: LoggingCore.h:74
const ServiceMap & getServices() const
Returns the map with all known services.
Definition: RPCServer.h:718
Stores the signature of an RPC method including the methods name and its parameter types...
Definition: RPCSignature.h:68
ParameterDescriptions parameterDesc
User info on method parameters.
Definition: RPCServer.h:258
The request is invalid or can not be parsed.
Definition: RPCError.h:66
virtual void onRPCfinished(AbstractDeferredInvoker *invoker)=0
called upon finish of the RPC call, the ID of the call is passed as parameter.
void reflect(Reflector &r)
Definition: RPCServer.h:189
ParameterInfo(const std::string &iName, const std::string &iDescription)
Definition: RPCServer.h:119
const Service & getService(const std::string &name) const
Returns a reference to the service with the given name.
Definition: RPCServer.h:728
bool parameterSamplesDefault
Sample parameter values.
Definition: RPCServer.h:261
Method(const RPCSignature &signature, const std::string &comment)
Definition: RPCServer.h:272
boost::shared_ptr< AbstractDeferredInvoker > AbstractDeferredInvokerPtr
Definition: AbstractDeferredInvoker.h:119
std::string parameterDescriptions(const std::string &prefix="") const
The RPCServer is responsible for handling the server-side of an rpc call.
Definition: RPCServer.h:107
MethodInfo(const RPCSignature &iSignature, const std::string &iComment, const ParameterDescriptions &iParameterDescriptions)
Definition: RPCServer.h:183
std::vector< ParameterInfo > ParameterDescriptions
Definition: RPCServer.h:144
Definition: LoggingCore.h:76
DeferredInvokerFinishHandler * mFinishHandler
Definition: AbstractDeferredInvoker.h:116
Stores all necessary information to invoke a previously decoded and prepared RPC call.
Definition: RPCServer.h:817