Leosac
0.8.0
Open Source Access Control
|
Base class for module implementation. More...
#include <BaseModule.hpp>
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_ |
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:
Definition at line 110 of file BaseModule.hpp.
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.
|
virtualdefault |
|
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.
|
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.
|
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.
out | MUST not be null. |
Reimplemented in Leosac::Module::Auth::AuthFileModule.
Definition at line 127 of file BaseModule.cpp.
|
protected |
Fills a message with the module's configuration information.
This method calls the dump_additional_config()
method.
out_msg | MUST not be null. |
Definition at line 76 of file BaseModule.cpp.
|
protectedvirtual |
Handle called when a message on the module's control socket arrives.
Definition at line 101 of file BaseModule.cpp.
|
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.
|
virtual |
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 in Leosac::Module::AsioModule, Leosac::Module::Piface::PFDigitalModule, Leosac::Module::LedBuzzer::LEDBuzzerModule, Leosac::Module::Libgpiod::LibgpiodModule, Leosac::Module::SysFsGpio::SysFsGpioModule, Leosac::Module::Doorman::DoormanModule, Leosac::Module::Wiegand::WiegandReaderModule, Leosac::Module::WebSockAPI::WebSockAPIModule, Leosac::Module::Monitor::MonitorModule, Leosac::Module::Mqtt::MqttModule, and Leosac::Module::Replication::ReplicationModule.
Definition at line 48 of file BaseModule.cpp.
|
protected |
The configuration tree passed to the start_module
function.
Definition at line 193 of file BaseModule.hpp.
|
protected |
Control REP socket.
Definition at line 208 of file BaseModule.hpp.
|
protected |
A reference to the ZeroMQ context in case you need it to create additional socket.
Definition at line 183 of file BaseModule.hpp.
|
protected |
Boolean indicating whether the main loop should run or not.
Definition at line 203 of file BaseModule.hpp.
|
protected |
Definition at line 216 of file BaseModule.hpp.
|
protected |
A reference to the pair socket that link back to the module manager.
Definition at line 188 of file BaseModule.hpp.
|
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.
|
protected |
Pointer to the core utils, which gives access to scheduler and others.
Definition at line 198 of file BaseModule.hpp.