Leosac  0.8.0
Open Source Access Control
Leosac::Module::WebSockAPI::BaseModuleSupportThread< ParameterT > Class Template Referenceabstract

This class provide a base implementation -designed to be extended by subclass- so that non-boost-asio based module can "easily" make use of the WebSockAPI module. More...

#include <WSHelperThread.hpp>

+ Collaboration diagram for Leosac::Module::WebSockAPI::BaseModuleSupportThread< ParameterT >:

Public Member Functions

 BaseModuleSupportThread (const CoreUtilsPtr &core_utils, const ParameterT &param)
 
virtual ~BaseModuleSupportThread ()
 
void start_running ()
 Effectively starts an helper thread and run its io_service. More...
 
void set_parameter (const ParameterT &p)
 
virtual void unregister_ws_handlers (Service &ws_service)=0
 

Protected Attributes

CoreUtilsPtr core_utils_
 
bs2::scoped_connection service_event_listener_
 
std::unique_ptr< std::thread > thread_
 
boost::asio::io_service io_
 
std::unique_ptr< boost::asio::io_service::work > work_
 
ParameterT parameters_
 
std::mutex mutex_
 
std::shared_ptr< WebSockAPI::Serviceservice_ptr_
 

Private Member Functions

void run_io_service ()
 
void on_service_event (const service_event::Event &e)
 
virtual void register_ws_handlers (Service &ws_service)=0
 Called when websocket handler registration is possible. More...
 

Detailed Description

template<typename ParameterT>
class Leosac::Module::WebSockAPI::BaseModuleSupportThread< ParameterT >

This class provide a base implementation -designed to be extended by subclass- so that non-boost-asio based module can "easily" make use of the WebSockAPI module.

When this object is created and its internal io_service runs, (after start_running() is called), it will attempt to locate a WS service object. If available, register_ws_handler() will be called. Otherwise, it will be called when (if) a WS Service object becomes registered.

The class provide extensions points that are called to register and unregister websocket handler. The function register_ws_handlers() is called when a WSService is available. The user is responsible for calling unregister_ws_handler().

Note
This class is templated on a Parameter template that allows the user to pass custom parameters to the support thread.
A new thread is create in this class's constructor.

Definition at line 61 of file WSHelperThread.hpp.

Constructor & Destructor Documentation

◆ BaseModuleSupportThread()

template<typename ParameterT >
Leosac::Module::WebSockAPI::BaseModuleSupportThread< ParameterT >::BaseModuleSupportThread ( const CoreUtilsPtr core_utils,
const ParameterT &  param 
)
inlineexplicit

Definition at line 64 of file WSHelperThread.hpp.

◆ ~BaseModuleSupportThread()

template<typename ParameterT >
virtual Leosac::Module::WebSockAPI::BaseModuleSupportThread< ParameterT >::~BaseModuleSupportThread ( )
inlinevirtual

Definition at line 71 of file WSHelperThread.hpp.

Member Function Documentation

◆ on_service_event()

template<typename ParameterT >
void Leosac::Module::WebSockAPI::BaseModuleSupportThread< ParameterT >::on_service_event ( const service_event::Event e)
inlineprivate

Definition at line 126 of file WSHelperThread.hpp.

◆ register_ws_handlers()

template<typename ParameterT >
virtual void Leosac::Module::WebSockAPI::BaseModuleSupportThread< ParameterT >::register_ws_handlers ( Service ws_service)
privatepure virtual

Called when websocket handler registration is possible.

This function is called with the internal mutex locked, to prevent conflict with a call to set_parameters().

Implemented in Leosac::Module::Piface::WSHelperThread, Leosac::Module::LedBuzzer::WSHelperThread, and Leosac::Module::Wiegand::WSHelperThread.

◆ run_io_service()

template<typename ParameterT >
void Leosac::Module::WebSockAPI::BaseModuleSupportThread< ParameterT >::run_io_service ( )
inlineprivate

Definition at line 106 of file WSHelperThread.hpp.

◆ set_parameter()

template<typename ParameterT >
void Leosac::Module::WebSockAPI::BaseModuleSupportThread< ParameterT >::set_parameter ( const ParameterT &  p)
inline

Definition at line 97 of file WSHelperThread.hpp.

◆ start_running()

template<typename ParameterT >
void Leosac::Module::WebSockAPI::BaseModuleSupportThread< ParameterT >::start_running ( )
inline

Effectively starts an helper thread and run its io_service.

Using this function is required because it wasn't possible to safely start running from the constructor (risk of calling virtual method on a not-yet fully initialised object).

Definition at line 92 of file WSHelperThread.hpp.

◆ unregister_ws_handlers()

template<typename ParameterT >
virtual void Leosac::Module::WebSockAPI::BaseModuleSupportThread< ParameterT >::unregister_ws_handlers ( Service ws_service)
pure virtual

Member Data Documentation

◆ core_utils_

template<typename ParameterT >
CoreUtilsPtr Leosac::Module::WebSockAPI::BaseModuleSupportThread< ParameterT >::core_utils_
protected

Definition at line 160 of file WSHelperThread.hpp.

◆ io_

template<typename ParameterT >
boost::asio::io_service Leosac::Module::WebSockAPI::BaseModuleSupportThread< ParameterT >::io_
protected

Definition at line 163 of file WSHelperThread.hpp.

◆ mutex_

template<typename ParameterT >
std::mutex Leosac::Module::WebSockAPI::BaseModuleSupportThread< ParameterT >::mutex_
protected

Definition at line 166 of file WSHelperThread.hpp.

◆ parameters_

template<typename ParameterT >
ParameterT Leosac::Module::WebSockAPI::BaseModuleSupportThread< ParameterT >::parameters_
protected

Definition at line 165 of file WSHelperThread.hpp.

◆ service_event_listener_

template<typename ParameterT >
bs2::scoped_connection Leosac::Module::WebSockAPI::BaseModuleSupportThread< ParameterT >::service_event_listener_
protected

Definition at line 161 of file WSHelperThread.hpp.

◆ service_ptr_

template<typename ParameterT >
std::shared_ptr<WebSockAPI::Service> Leosac::Module::WebSockAPI::BaseModuleSupportThread< ParameterT >::service_ptr_
protected

Definition at line 172 of file WSHelperThread.hpp.

◆ thread_

template<typename ParameterT >
std::unique_ptr<std::thread> Leosac::Module::WebSockAPI::BaseModuleSupportThread< ParameterT >::thread_
protected

Definition at line 162 of file WSHelperThread.hpp.

◆ work_

template<typename ParameterT >
std::unique_ptr<boost::asio::io_service::work> Leosac::Module::WebSockAPI::BaseModuleSupportThread< ParameterT >::work_
protected

Definition at line 164 of file WSHelperThread.hpp.


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