Leosac  0.8.0
Open Source Access Control
Leosac::Module::WebSockAPI::Service Class Reference

A service object provided by the Websocket module. More...

#include <Service.hpp>

+ Collaboration diagram for Leosac::Module::WebSockAPI::Service:

Public Types

using WSHandler = std::function< boost::optional< json >(const RequestContext &)>
 

Public Member Functions

 Service (WSServer &server)
 
template<typename HandlerT >
bool register_asio_handler (HandlerT &&handler, const std::string &type, boost::asio::io_service &io)
 Register an handler that will be invoked by the io_service io. More...
 
template<typename HandlerT >
bool register_handler (HandlerT &&handler, const std::string &type)
 Register a handler for a websocket message. More...
 
void register_crud_handler (const std::string &resource_name, CRUDResourceHandler::Factory factory)
 
void unregister_handler (const std::string &name)
 Remove an handler by name. More...
 
template<typename HandlerT >
bool register_asio_handler_permission (HandlerT &&handler, const std::string &type, ActionActionParam permission, boost::asio::io_service &io)
 
template<typename HandlerT >
bool register_asio_handler_permission (HandlerT &&handler, const std::string &type, SecurityContext::Action permission, boost::asio::io_service &io)
 

Private Member Functions

bool register_typed_handler (const WSHandler &handler, const std::string &type)
 Register an handler that is ready to be invoked in the websocket thread. More...
 

Private Attributes

WSServerserver_
 

Detailed Description

A service object provided by the Websocket module.

Note
This service is fully thread-safe.

Definition at line 45 of file Service.hpp.

Member Typedef Documentation

◆ WSHandler

using Leosac::Module::WebSockAPI::Service::WSHandler = std::function<boost::optional<json>(const RequestContext &)>

Definition at line 53 of file Service.hpp.

Constructor & Destructor Documentation

◆ Service()

Leosac::Module::WebSockAPI::Service::Service ( WSServer server)
inline

Definition at line 48 of file Service.hpp.

Member Function Documentation

◆ register_asio_handler()

template<typename HandlerT >
bool Leosac::Module::WebSockAPI::Service::register_asio_handler ( HandlerT &&  handler,
const std::string &  type,
boost::asio::io_service &  io 
)
inline

Register an handler that will be invoked by the io_service io.

Note
This function actually wraps the user-provided handler so that it can be invoked normally from the websocket thread.

Definition at line 62 of file Service.hpp.

◆ register_asio_handler_permission() [1/2]

template<typename HandlerT >
bool Leosac::Module::WebSockAPI::Service::register_asio_handler_permission ( HandlerT &&  handler,
const std::string &  type,
ActionActionParam  permission,
boost::asio::io_service &  io 
)
inline

Definition at line 112 of file Service.hpp.

◆ register_asio_handler_permission() [2/2]

template<typename HandlerT >
bool Leosac::Module::WebSockAPI::Service::register_asio_handler_permission ( HandlerT &&  handler,
const std::string &  type,
SecurityContext::Action  permission,
boost::asio::io_service &  io 
)
inline

Definition at line 126 of file Service.hpp.

◆ register_crud_handler()

void Leosac::Module::WebSockAPI::Service::register_crud_handler ( const std::string &  resource_name,
CRUDResourceHandler::Factory  factory 
)

Definition at line 41 of file Service.cpp.

◆ register_handler()

template<typename HandlerT >
bool Leosac::Module::WebSockAPI::Service::register_handler ( HandlerT &&  handler,
const std::string &  type 
)
inline

Register a handler for a websocket message.

The handler will be invoked as-is in the websocket thread.

Definition at line 88 of file Service.hpp.

◆ register_typed_handler()

bool Leosac::Module::WebSockAPI::Service::register_typed_handler ( const WSHandler handler,
const std::string &  type 
)
private

Register an handler that is ready to be invoked in the websocket thread.

Definition at line 30 of file Service.cpp.

◆ unregister_handler()

void Leosac::Module::WebSockAPI::Service::unregister_handler ( const std::string &  name)

Remove an handler by name.

This should be called by module that register handlers before the module is destroyed in order to avoid a potential crash / race condition.

If you still have a registered asio-handler when the module goes out of scope, the websocket module will attempt to post() to a dangling io_service, causing a crash.

Note
We assume everyone is nice and module won't remove each-other handler.

Definition at line 36 of file Service.cpp.

Member Data Documentation

◆ server_

WSServer& Leosac::Module::WebSockAPI::Service::server_
private

Definition at line 143 of file Service.hpp.


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