30 #include <jsonrpccpp/common/procedure.h> 31 #include <jsonrpccpp/server/iprocedureinvokationhandler.h> 32 #include <jsonrpccpp/server/abstractserverconnector.h> 33 #include <jsonrpccpp/server/requesthandlerfactory.h> 45 using MethodBinding = std::tuple<jsonrpc::Procedure, AbstractMethodPointer<I>>;
47 using Methods = std::vector<MethodBinding>;
67 template <
class... Is>
72 : m_handler(
jsonrpc::RequestHandlerFactory::createProtocolHandler(
jsonrpc::JSONRPC_SERVER_V2, *this))
74 m_handler->AddProcedure(jsonrpc::Procedure(
"rpc_modules", jsonrpc::PARAMS_BY_POSITION, jsonrpc::JSON_OBJECT, NULL));
75 m_implementedModules = Json::objectValue;
80 response = m_implementedModules;
87 for (
auto const& connector: m_connectors)
88 connector->StartListening();
93 for (
auto const& connector: m_connectors)
94 connector->StopListening();
99 if (_proc.GetProcedureName() ==
"rpc_modules")
100 modules(_input, _output);
112 m_connectors.emplace_back(_connector);
113 _connector->SetHandler(m_handler.get());
114 return m_connectors.size() - 1;
117 jsonrpc::AbstractServerConnector*
connector(
unsigned _i)
const 119 return m_connectors.at(_i).get();
123 std::vector<std::unique_ptr<jsonrpc::AbstractServerConnector>>
m_connectors;
129 template <
class I,
class... Is>
140 for (
auto const& method: m_interface->methods())
142 m_methods[std::get<0>(method).GetProcedureName()] = std::get<1>(method);
143 this->m_handler->AddProcedure(std::get<0>(method));
146 for (
auto const& notification: m_interface->notifications())
148 m_notifications[std::get<0>(notification).GetProcedureName()] = std::get<1>(notification);
149 this->m_handler->AddProcedure(std::get<0>(notification));
152 for (
auto const& module: m_interface->implementedModules())
153 this->m_implementedModules[module.name] = module.version;
158 auto pointer =
m_methods.find(_proc.GetProcedureName());
160 (m_interface.get()->*(pointer->second))(_input, _output);
169 (m_interface.get()->*(pointer->second))(_input);
std::tuple< jsonrpc::Procedure, AbstractNotificationPointer< PersonalFace >> NotificationBinding
std::vector< RPCModule > RPCModules
jsonrpc::AbstractServerConnector * connector(unsigned _i) const
virtual void HandleMethodCall(jsonrpc::Procedure &_proc, Json::Value const &_input, Json::Value &_output) override
AbstractNotificationPointer< PersonalFace > NotificationPointer
AbstractNotificationPointer< I > NotificationPointer
virtual void StopListening()
std::vector< NotificationBinding > Notifications
std::unique_ptr< jsonrpc::IProtocolHandler > m_handler
virtual void HandleNotificationCall(jsonrpc::Procedure &_proc, Json::Value const &_input) override
AbstractMethodPointer< PersonalFace > MethodPointer
void bindAndAddMethod(jsonrpc::Procedure const &_proc, MethodPointer _pointer)
void bindAndAddNotification(jsonrpc::Procedure const &_proc, NotificationPointer _pointer)
Methods const & methods() const
Json::Value m_implementedModules
Mapping for implemented modules, to be filled by subclasses during construction.
Notifications m_notifications
virtual void StartListening()
virtual void modules(const Json::Value &request, Json::Value &response)
void(I::*)(Json::Value const &_parameter) AbstractNotificationPointer
std::tuple< jsonrpc::Procedure, AbstractMethodPointer< PersonalFace >> MethodBinding
virtual void HandleMethodCall(jsonrpc::Procedure &_proc, Json::Value const &_input, Json::Value &_output) override
std::vector< MethodBinding > Methods
void(I::*)(Json::Value const &_parameter, Json::Value &_result) AbstractMethodPointer
virtual ~ServerInterface()
Notifications const & notifications() const
std::vector< std::unique_ptr< jsonrpc::AbstractServerConnector > > m_connectors
std::map< std::string, NotificationPointer > m_notifications
unsigned addConnector(jsonrpc::AbstractServerConnector *_connector)
server takes ownership of the connector
std::map< std::string, MethodPointer > m_methods
virtual RPCModules implementedModules() const =0
virtual void HandleNotificationCall(jsonrpc::Procedure &_proc, Json::Value const &_input) override
std::unique_ptr< I > m_interface
AbstractMethodPointer< I > MethodPointer