Leosac  0.8.0
Open Source Access Control
Leosac::Module::BaseModule Class Reference

Base class for module implementation. More...

#include <BaseModule.hpp>

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

Public Member Functions

 BaseModule (zmqpp::context &ctx, zmqpp::socket *pipe, const boost::property_tree::ptree &cfg, CoreUtilsPtr utils)
 Constructor of BaseModule. More...
 
virtual ~BaseModule ()=default
 
virtual void run ()
 This is the main loop of the module. More...
 

Protected Member Functions

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

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_
 

Detailed Description

Base class for module implementation.

It provide a base class for writing module code. The base class implements run() as a main loop and use a reactor to handle socket when they become available for reading. When implementing a module using this class you're supposed to use that reactor and register your socket. In case you need to override run(), remember to poll on the reactor, or to watch the pipe_ on way or another.

It use a reactor to poll on the pipe socket that connect the module back to the module manager.

A module shall have a control socket and it must be a REP socket and bound to inproc://module-${MODULE_NAME}

For replication and ease of management, command can be written on the module's control socket and must be implemented in the module (unless it is implemented by the BaseModule class).

Commands: DUMP_CONFIG: serialize the current module config. : Parameter: "0" -> as a ptree "1" -> as a xml tree

It is possible some module require additional configuration file. If that's the case, those this shall be copied in the response. Response may look like this:

  • XML (or ptree encoded by boost serialization)
  • FileName1
  • ContentOfFilename1
  • Filename2
  • Content of Filename2
Note
This class is here to help reduce code duplication. It is NOT mandatory to inherit from this base class to implement a module. However, it may help.

Definition at line 110 of file BaseModule.hpp.

Constructor & Destructor Documentation

◆ BaseModule()

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

Constructor of BaseModule.

It will register the pipe_ to reactor_.

Definition at line 32 of file BaseModule.cpp.

◆ ~BaseModule()

virtual Leosac::Module::BaseModule::~BaseModule ( )
virtualdefault

Member Function Documentation

◆ config_check() [1/2]

void BaseModule::config_check ( const std::string &  obj_name)
protected

An helper that checks configuration the existence of some objects.

Based on whether or not strict mode is enable, it prints a warning or prints an error and assert.

Definition at line 131 of file BaseModule.cpp.

◆ config_check() [2/2]

void BaseModule::config_check ( const std::string &  obj_name,
Leosac::Hardware::DeviceClass  type 
)
protected

An helper that checks configuration the existence of some objects.

Based on whether or not strict mode is enable, it prints a warning or prints an error and assert.

Definition at line 143 of file BaseModule.cpp.

◆ dump_additional_config()

void BaseModule::dump_additional_config ( zmqpp::message *  out) const
protectedvirtual

Dump additional configuration (for example module specific config file).

If your module has this kind of file, you may override this method to provide correct dump of the config.

Note
Unless reimplemented this method does nothing.
See DUMP_CONFIG specs for additional config file.
Parameters
outMUST not be null.

Reimplemented in Leosac::Module::Auth::AuthFileModule.

Definition at line 127 of file BaseModule.cpp.

◆ dump_config()

void BaseModule::dump_config ( ConfigManager::ConfigFormat  fmt,
zmqpp::message *  out_msg 
) const
protected

Fills a message with the module's configuration information.

This method calls the dump_additional_config() method.

Parameters
out_msgMUST not be null.

Definition at line 76 of file BaseModule.cpp.

◆ handle_control()

void BaseModule::handle_control ( )
protectedvirtual

Handle called when a message on the module's control socket arrives.

Definition at line 101 of file BaseModule.cpp.

◆ handle_pipe()

void BaseModule::handle_pipe ( )
protectedvirtual

The base class register the pipe_ socket to its reactor_ so that this function is called when the pipe_ is available from reading.

This implementation switch is_running_ to false.

Definition at line 56 of file BaseModule.cpp.

◆ run()

void BaseModule::run ( )
virtual

Member Data Documentation

◆ config_

boost::property_tree::ptree Leosac::Module::BaseModule::config_
protected

The configuration tree passed to the start_module function.

Definition at line 193 of file BaseModule.hpp.

◆ control_

zmqpp::socket Leosac::Module::BaseModule::control_
protected

Control REP socket.

Definition at line 208 of file BaseModule.hpp.

◆ ctx_

zmqpp::context& Leosac::Module::BaseModule::ctx_
protected

A reference to the ZeroMQ context in case you need it to create additional socket.

Definition at line 183 of file BaseModule.hpp.

◆ is_running_

bool Leosac::Module::BaseModule::is_running_
protected

Boolean indicating whether the main loop should run or not.

Definition at line 203 of file BaseModule.hpp.

◆ name_

std::string Leosac::Module::BaseModule::name_
protected

Definition at line 216 of file BaseModule.hpp.

◆ pipe_

zmqpp::socket& Leosac::Module::BaseModule::pipe_
protected

A reference to the pair socket that link back to the module manager.

Definition at line 188 of file BaseModule.hpp.

◆ reactor_

zmqpp::reactor Leosac::Module::BaseModule::reactor_
protected

The reactor object we poll() on in the main loop.

Register additional socket/fd here if you need to.

Definition at line 214 of file BaseModule.hpp.

◆ utils_

CoreUtilsPtr Leosac::Module::BaseModule::utils_
protected

Pointer to the core utils, which gives access to scheduler and others.

Definition at line 198 of file BaseModule.hpp.


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