MIRA
Classes | Public Types | Public Member Functions | Protected Member Functions | List of all members
RPCServer Class Reference

The RPCServer is responsible for handling the server-side of an rpc call. More...

#include <rpc/RPCServer.h>

Classes

class  DeferredInvoker
 Stores all necessary information to invoke a previously decoded and prepared RPC call. More...
 
struct  Method
 Contains all information on a registered RPC method, including the signature of the method. More...
 
struct  MethodInfo
 Contains information on an existing RPC method: the signature of the method, comments, etc. More...
 
struct  ParameterInfo
 Contains information on an RPC method's parameter: name, description. More...
 
class  RPCReflector
 Special visitor for the reflect() method that visits all method() and interface() calls within the reflect() method to collect the methods and interfaces within the above Service object. More...
 
struct  ServiceInfo
 Contains all available information about a single RPC service, including the service' name, its registered methods and all implemented RPC interfaces. More...
 

Public Types

typedef std::vector< ParameterInfoParameterDescriptions
 
typedef std::set< MethodMethodSet
 
typedef std::set< MethodInfoMethodInfoSet
 
typedef ServiceInfo< MethodSetService
 
typedef std::map< std::string, ServiceServiceMap
 

Public Member Functions

template<typename T >
const ServiceregisterServiceObject (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. More...
 
void unregisterService (const std::string &serviceName)
 Unregisters the specified service with all methods of all service objects that were registered. More...
 
const ServiceMapgetServices () const
 Returns the map with all known services. More...
 
const ServicegetService (const std::string &name) const
 Returns a reference to the service with the given name. More...
 
bool existsService (const std::string &name) const
 Returns true, if a service with the specified name exists, otherwise false. More...
 
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 interface. More...
 
bool implementsInterface (const std::string &name, const std::string &interface) const
 Returns if the given service implements a certain interface. More...
 
template<typename Backend >
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. More...
 
template<typename Backend >
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. More...
 

Protected Member Functions

template<typename Backend >
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() More...
 
template<typename Backend >
void generateErrorResponse (const std::string &callId, RPCError reason, const std::string &message, typename Backend::ServerResponse &oResponse)
 

Detailed Description

The RPCServer is responsible for handling the server-side of an rpc call.

The server stores all available services with its methods and invokes the requested calls. Each service is identified by its name. The service is formed of one or more service objects that provide the methods of the service. A service object is assigned using registerServiceObject().

The server side view of an rpc call is as follows:

  1. the RPC request is received as RPCServerRequest from the client
  2. processCall() or processCallDeferred() is called using the received request
    • these methods will examine the request and prepare the invokation of the requested method.
    • processCall() will call the method immediately, while processCallDeferred() returns a DeferredInvoker which can be stored and used to invoke the method call later
    • both methods take an RPCServerResponse object as second parameter. The result or error response of the call will be stored in this response right after invokation of the called method
    • similar to RPCClient::call() arbitrary types of RPCServerRequests and RPCServerResponse are supported (e.g. BinaryRPCServerRequest, BinaryRPCServerResponse, etc) which are provided by an RPC backend
  3. the response is submitted to the client where it is processed to finish the call.
See also
Services and Remote Procedure Calls, RPCClient

Member Typedef Documentation

◆ ParameterDescriptions

typedef std::vector<ParameterInfo> ParameterDescriptions

◆ MethodSet

typedef std::set<Method> MethodSet

◆ MethodInfoSet

typedef std::set<MethodInfo> MethodInfoSet

◆ Service

◆ ServiceMap

typedef std::map<std::string, Service> ServiceMap

Member Function Documentation

◆ registerServiceObject()

const Service& registerServiceObject ( const std::string &  serviceName,
T &  serviceObject,
std::set< RPCSignature > *  addedMethods = NULL,
std::set< std::string > *  addedInterfaces = NULL 
)
inline

Registers the methods of the specified service object under the specified service name.

You can register more than one service object under the same service name. The service object is reflected to collect its methods and interfaces that are specified in the classes reflect() methods. Returns the service which was created or extended by the service object.

◆ unregisterService()

void unregisterService ( const std::string &  serviceName)
inline

Unregisters the specified service with all methods of all service objects that were registered.

◆ getServices()

const ServiceMap& getServices ( ) const
inline

Returns the map with all known services.

◆ getService()

const Service& getService ( const std::string &  name) const
inline

Returns a reference to the service with the given name.

Exceptions
XInvalidParameterIf no such service exists.

◆ existsService()

bool existsService ( const std::string &  name) const
inline

Returns true, if a service with the specified name exists, otherwise false.

◆ queryServicesForInterface()

std::list<std::string> queryServicesForInterface ( const std::string &  interface) const
inline

Returns a string list with the names of all registered services, that implement the specified interface.

◆ implementsInterface()

bool implementsInterface ( const std::string &  name,
const std::string &  interface 
) const
inline

Returns if the given service implements a certain interface.

◆ processCall()

void processCall ( typename Backend::ServerRequest &  request,
typename Backend::ServerResponse &  response 
)
inline

Decodes the Request which was received from the client-side and invokes the RPC call immediately.

The result of the RPC call will be stored in the Response which can be sent to the client side afterwards.

◆ processCallDeferred()

AbstractDeferredInvokerPtr processCallDeferred ( typename Backend::ServerRequest &  request,
typename Backend::ServerResponse &  response 
)
inline

Similar to processCall() this method decodes the RPCRequest which was received from the client-side.

In contrast to processCall() the method is not called immediately. Instead the call is prepared only and all necessary information for its invokation is stored in the DeferredInvoker object that is returned. The DeferredInvoker may be stored by the caller to allow invokation at a later time or from a different thread. Returns nullptr, if an error has occured while parsing the request or preparing the call. In this case response is filled with a description of the error that can be shipped to the caller.

◆ processCallCommon()

bool processCallCommon ( typename Backend::ServerRequest &  request,
typename Backend::ServerResponse &  response,
std::string &  oCallId,
boost::shared_ptr< TRPCInvoker< Backend >> &  oInvoker,
Service *&  oService,
Method *&  oMethod 
)
inlineprotected

contains common functionality that is used by processCall() and processCallDeferred()

◆ generateErrorResponse()

void generateErrorResponse ( const std::string &  callId,
RPCError  reason,
const std::string &  message,
typename Backend::ServerResponse &  oResponse 
)
inlineprotected

The documentation for this class was generated from the following file: