Leosac  0.8.0
Open Source Access Control
Leosac::Module::AsioModule Class Referenceabstract

This is a base class for boost::asio 'aware' module. More...

#include <AsioModule.hpp>

+ Inheritance diagram for Leosac::Module::AsioModule:
+ Collaboration diagram for Leosac::Module::AsioModule:

Classes

struct  AsyncReactorPoller
 Poll the zmq reactor from BaseModule. More...
 
struct  StopWatcher
 

Public Member Functions

 AsioModule (zmqpp::context &ctx, zmqpp::socket *pipe, const boost::property_tree::ptree &cfg, CoreUtilsPtr utils)
 
 ~AsioModule ()
 
virtual void run () override final
 This is the main loop of the module. More...
 
template<typename Callable >
void post (Callable &&callable)
 Post some work onto the work queue of the module. More...
 
- Public Member Functions inherited from Leosac::Module::BaseModule
 BaseModule (zmqpp::context &ctx, zmqpp::socket *pipe, const boost::property_tree::ptree &cfg, CoreUtilsPtr utils)
 Constructor of BaseModule. More...
 
virtual ~BaseModule ()=default
 

Protected Member Functions

virtual void on_service_event (const service_event::Event &)=0
 Function invoked when a service event is triggered. More...
 
- Protected Member Functions inherited from Leosac::Module::BaseModule
virtual void handle_pipe ()
 The base class register the pipe_ socket to its reactor_ so that this function is called when the pipe_ is available from reading. More...
 
virtual void handle_control ()
 Handle called when a message on the module's control socket arrives. More...
 
virtual void dump_additional_config (zmqpp::message *out) const
 Dump additional configuration (for example module specific config file). More...
 
void dump_config (ConfigManager::ConfigFormat fmt, zmqpp::message *out_msg) const
 Fills a message with the module's configuration information. More...
 
void config_check (const std::string &obj_name, Leosac::Hardware::DeviceClass type)
 An helper that checks configuration the existence of some objects. More...
 
void config_check (const std::string &obj_name)
 An helper that checks configuration the existence of some objects. More...
 

Protected Attributes

boost::asio::io_service io_service_
 
- Protected Attributes inherited from Leosac::Module::BaseModule
zmqpp::context & ctx_
 A reference to the ZeroMQ context in case you need it to create additional socket. More...
 
zmqpp::socket & pipe_
 A reference to the pair socket that link back to the module manager. More...
 
boost::property_tree::ptree config_
 The configuration tree passed to the start_module function. More...
 
CoreUtilsPtr utils_
 Pointer to the core utils, which gives access to scheduler and others. More...
 
bool is_running_
 Boolean indicating whether the main loop should run or not. More...
 
zmqpp::socket control_
 Control REP socket. More...
 
zmqpp::reactor reactor_
 The reactor object we poll() on in the main loop. More...
 
std::string name_
 

Private Member Functions

void install_async_handlers ()
 Install handlers that periodically poll for activity on the ZMQ reactor from BaseModule. More...
 

Private Attributes

std::unique_ptr< boost::asio::io_service::work > work_
 
bs2::connection service_event_listener_
 

Detailed Description

This is a base class for boost::asio 'aware' module.

It builds on top of the BaseModule but the main loop in provide by boost::asio::io_service.

It periodically polls for signals / messages from the normal messaging infrastructure.

Definition at line 40 of file AsioModule.hpp.

Constructor & Destructor Documentation

◆ AsioModule()

Leosac::Module::AsioModule::AsioModule ( zmqpp::context &  ctx,
zmqpp::socket *  pipe,
const boost::property_tree::ptree &  cfg,
CoreUtilsPtr  utils 
)

Definition at line 28 of file AsioModule.cpp.

◆ ~AsioModule()

Leosac::Module::AsioModule::~AsioModule ( )

Definition at line 34 of file AsioModule.cpp.

Member Function Documentation

◆ install_async_handlers()

void Leosac::Module::AsioModule::install_async_handlers ( )
private

Install handlers that periodically poll for activity on the ZMQ reactor from BaseModule.

While this impedes reactivity, it is the less complicated solution for now.

Definition at line 50 of file AsioModule.cpp.

◆ on_service_event()

virtual void Leosac::Module::AsioModule::on_service_event ( const service_event::Event )
protectedpure virtual

Function invoked when a service event is triggered.

Note
This function MUST be thread safe because it will be invoked from whichever thread triggered the event.

Implemented in Leosac::Module::Auth::AuthDBModule, Leosac::Module::Notifd::NotifdModule, and Leosac::Module::SMTP::SMTPModule.

◆ post()

template<typename Callable >
void Leosac::Module::AsioModule::post ( Callable &&  callable)
inline

Post some work onto the work queue of the module.

Note
This function is thread-safe.
Callable post()ed through this function are guaranteed to be executed in the module's thread.

Definition at line 58 of file AsioModule.hpp.

◆ run()

void Leosac::Module::AsioModule::run ( )
finaloverridevirtual

This is the main loop of the module.

It should only exit when receiving signal::stop on its pipe_ socket. This is completely handled by this base class. In case you override this, make sure you watch the pipe_ socket.

Reimplemented from Leosac::Module::BaseModule.

Definition at line 38 of file AsioModule.cpp.

Member Data Documentation

◆ io_service_

boost::asio::io_service Leosac::Module::AsioModule::io_service_
protected

Definition at line 64 of file AsioModule.hpp.

◆ service_event_listener_

bs2::connection Leosac::Module::AsioModule::service_event_listener_
private

Definition at line 76 of file AsioModule.hpp.

◆ work_

std::unique_ptr<boost::asio::io_service::work> Leosac::Module::AsioModule::work_
private

Definition at line 75 of file AsioModule.hpp.


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