Leosac
0.8.0
Open Source Access Control
|
#include <kernel.hpp>
Public Member Functions | |
Kernel (const boost::property_tree::ptree &config, bool strict_mode=false) | |
Construct a Kernel object. More... | |
Kernel (const Kernel &)=delete | |
Disable copy constructor as it makes no sense to copy this. More... | |
Kernel & | operator= (const Kernel &)=delete |
Disable assignment operator. More... | |
Kernel & | operator= (Kernel &&)=delete |
Disable move-assignment. More... | |
Kernel (Kernel &&)=delete | |
Disable move-construction. More... | |
~Kernel () | |
Implemented in .cpp for unique_ptr to work. More... | |
bool | run () |
Main loop of the main thread. More... | |
std::string | script_directory () const |
Return the path to the scripts directory. More... | |
std::string | factory_config_directory () const |
Return the path to factory config directory Uses environment variable if available, otherwise defaults to hardcoded path relative to cwd. More... | |
const ModuleManager & | module_manager () const |
Returns a reference to the module manager object (const version). More... | |
ModuleManager & | module_manager () |
Returns a reference to the module manager object. More... | |
zmqpp::context & | zmqpp_context () |
Returns a reference to the zmqpp context created for the application. More... | |
CoreUtilsPtr | core_utils () |
Returns a (smart) pointer to the core utils: some thread-safe utilities. More... | |
ConfigManager & | config_manager () |
Retrieve a reference to the configuration manager object. More... | |
bool | save_config () |
Save the current configuration to its original file if autosave is enabled. More... | |
void | restart_later () |
Set the running_ and want_restart flag so that leosac will restart in the next main loop iteration. More... | |
const std::chrono::steady_clock::time_point | start_time () const |
Return the time point at which Leosac started. More... | |
DBPtr | database () |
Retrieve a pointer to the database, if any. More... | |
ServiceRegistry & | service_registry () |
Retrieve a reference to the service registry. More... | |
Static Public Member Functions | |
static boost::property_tree::ptree | make_config (const Leosac::Tools::RuntimeOptions &opt) |
Build a property tree from a runtime object object. More... | |
Private Types | |
enum | EnvironVar { EnvironVar::FACTORY_CONFIG_DIR, EnvironVar::SCRIPTS_DIR } |
Private Member Functions | |
void | module_manager_init () |
Init the module manager by feeding it paths to library file, loading module, etc. More... | |
void | handle_control_request () |
A request has arrived on the control_ socket. More... | |
void | factory_reset () |
Reset Leosac configuration. More... | |
void | get_netconfig () |
Handle GET_NETCONFIG command. More... | |
void | set_netconfig (zmqpp::message *msg) |
Handle SET_NETCONFIG command and update the configuration file directly. More... | |
void | extract_environ () |
void | configure_database () |
void | populate_default_db () |
void | create_update_schema () |
Create and/or update the database schema. More... | |
void | connect_to_db (const boost::property_tree::ptree &db_cfg_node) |
void | configure_logger () |
void | configure_signal_handler () |
Setup signal handling for the process. More... | |
void | register_core_services () |
Register some important services to the service registry. More... | |
void | unregister_core_services () |
Unregister the service that were registered into register_core_services() . More... | |
void | shutdown () |
std::string | config_file_path () const |
Return the path to the kernel configuration file. More... | |
Private Attributes | |
CoreUtilsPtr | utils_ |
ConfigManager | config_manager_ |
zmqpp::context | ctx_ |
The application ZMQ context. More... | |
MessageBus | bus_ |
Application wide (inproc) message bus. More... | |
zmqpp::socket | control_ |
A REP socket to send request to the kernel. More... | |
zmqpp::socket | bus_push_ |
A PUSH socket to write on the bus. More... | |
zmqpp::reactor | reactor_ |
Watch for message on the control_ socket. More... | |
bool | is_running_ |
Controls core main loop. More... | |
bool | want_restart_ |
Should leosac restart ? More... | |
ModuleManager | module_manager_ |
Manages the different libraries (.so) we load, path to those libraries, modules instantiation. More... | |
std::unique_ptr< NetworkConfig > | network_config_ |
Object that handle networking configuration. More... | |
std::unique_ptr< RemoteControl > | remote_controller_ |
Object that expose leosac to the world. More... | |
std::map< EnvironVar, std::string > | environ_ |
bool | send_sighup_ |
Should we broadcast "SIGHUP" in the next main loop iteration ? More... | |
bool | autosave_ |
Autosave configuration on shutdown. More... | |
const std::chrono::steady_clock::time_point | start_time_ |
Time-point when Leosac started to run. More... | |
DBPtr | database_ |
A pointer to the database used by Leosac, if any. More... | |
Tools::XmlNodeNameEnforcer | xmlnne_ |
ServiceRegistryUPtr | service_registry_ |
Static Private Attributes | |
static Kernel * | instance_ = nullptr |
A global pointer to the Kernel instance. More... | |
Friends | |
ServiceRegistry & | get_service_registry () |
A function to retrieve the ServiceRegistry from pretty much anywhere. More... | |
Core of Leosac.
Handles module management and loading. The kernel binds a REP socket at "inproc://leosac-kernel".
Leosac kernel support a few commands. Those commands can be sent by modules.
Command (Frame 1) | Frame 2 | Frame 3 | Description |
---|---|---|---|
RESTART | Restart Leosac. |
This will destroy the kernel object, unload all module, and restart. RESET | | | Reset Leosac configuration to factory default. This will also restart. GET_NETCONFIG | | | Send the network config. SET_NETCONFIG | Serialized ptree | | Write the new network config to file SCRIPTS_DIR | | | Ask the path to scripts directory FACTORY_CONFIG_DIR | | | Ask the path to factory config directory
Leosac core occasionally broadcast notification for other subsystem. The message's topic is "KERNEL" for all notification coming from Leosac's core.
SYSTEM_READY
message when all modules are initialized.SIGHUP
to tell module to reload their configuration (if they support hot-reload). SIGHUP
is sent upon receiving the operating system level SIGHUP signal. Definition at line 73 of file kernel.hpp.
|
strongprivate |
Enumerator | |
---|---|
FACTORY_CONFIG_DIR | |
SCRIPTS_DIR |
Definition at line 323 of file kernel.hpp.
|
explicit |
Construct a Kernel object.
Only one Kernel object may be alive at any given time. This is because a global reference to the instance is kept.
config | initial configuration tree |
strict_mode | are we running in strict mode ? (This is wrt configuration validation) |
Definition at line 66 of file kernel.cpp.
|
delete |
Disable copy constructor as it makes no sense to copy this.
|
delete |
Disable move-construction.
Kernel::~Kernel | ( | ) |
Implemented in .cpp for unique_ptr to work.
Definition at line 117 of file kernel.cpp.
|
private |
Return the path to the kernel configuration file.
This is a simple helper function to throw ConfigException more easily.
Definition at line 523 of file kernel.cpp.
ConfigManager & Kernel::config_manager | ( | ) |
Retrieve a reference to the configuration manager object.
Definition at line 436 of file kernel.cpp.
|
private |
Definition at line 476 of file kernel.cpp.
|
private |
Definition at line 368 of file kernel.cpp.
|
private |
Setup signal handling for the process.
Definition at line 734 of file kernel.cpp.
|
private |
Definition at line 703 of file kernel.cpp.
CoreUtilsPtr Kernel::core_utils | ( | ) |
Returns a (smart) pointer to the core utils: some thread-safe utilities.
Definition at line 447 of file kernel.cpp.
|
private |
Create and/or update the database schema.
Definition at line 756 of file kernel.cpp.
DBPtr Kernel::database | ( | ) |
Retrieve a pointer to the database, if any.
Definition at line 518 of file kernel.cpp.
|
private |
Definition at line 340 of file kernel.cpp.
std::string Kernel::factory_config_directory | ( | ) | const |
Return the path to factory config directory Uses environment variable if available, otherwise defaults to hardcoded path relative to cwd.
Definition at line 361 of file kernel.cpp.
|
private |
Reset Leosac configuration.
Definition at line 278 of file kernel.cpp.
|
private |
Handle GET_NETCONFIG command.
Definition at line 295 of file kernel.cpp.
|
private |
A request has arrived on the control_
socket.
Definition at line 235 of file kernel.cpp.
|
static |
Build a property tree from a runtime object object.
It assume the kernel-config (-k) switch points to an XML config file. If we support more config source type (json) we should move this code.
Definition at line 128 of file kernel.cpp.
ModuleManager& Leosac::Kernel::module_manager | ( | ) |
Returns a reference to the module manager object.
ModuleManager & Kernel::module_manager | ( | ) | const |
Returns a reference to the module manager object (const version).
Definition at line 405 of file kernel.cpp.
|
private |
Init the module manager by feeding it paths to library file, loading module, etc.
Definition at line 186 of file kernel.cpp.
|
private |
Definition at line 623 of file kernel.cpp.
|
private |
Register some important services to the service registry.
Definition at line 528 of file kernel.cpp.
void Kernel::restart_later | ( | ) |
Set the running_ and want_restart flag so that leosac will restart in the next main loop iteration.
Definition at line 441 of file kernel.cpp.
bool Kernel::run | ( | ) |
Main loop of the main thread.
What it does:
Definition at line 151 of file kernel.cpp.
bool Kernel::save_config | ( | ) |
Save the current configuration to its original file if autosave
is enabled.
This means that configuration change made when Leosac was running will be persisted.
Definition at line 415 of file kernel.cpp.
std::string Kernel::script_directory | ( | ) | const |
Return the path to the scripts directory.
Uses environment variable if available, otherwise defaults to hardcoded path relative to cwd.
Definition at line 354 of file kernel.cpp.
ServiceRegistry & Kernel::service_registry | ( | ) |
Retrieve a reference to the service registry.
Definition at line 617 of file kernel.cpp.
|
private |
Handle SET_NETCONFIG command and update the configuration file directly.
The configuration update will take effect on the next restart.
msg | ZMQ message that holds config |
Definition at line 307 of file kernel.cpp.
|
private |
Definition at line 457 of file kernel.cpp.
const std::chrono::steady_clock::time_point Kernel::start_time | ( | ) | const |
Return the time point at which Leosac started.
Definition at line 452 of file kernel.cpp.
|
private |
Unregister the service that were registered into register_core_services()
.
Definition at line 576 of file kernel.cpp.
zmqpp::context & Kernel::zmqpp_context | ( | ) |
Returns a reference to the zmqpp context created for the application.
Definition at line 431 of file kernel.cpp.
|
friend |
A function to retrieve the ServiceRegistry from pretty much anywhere.
The only requirement is that a Kernel object is currently alive.
Definition at line 25 of file GetServiceRegistry.cpp.
|
private |
Autosave configuration on shutdown.
Definition at line 339 of file kernel.hpp.
|
private |
Application wide (inproc) message bus.
Definition at line 280 of file kernel.hpp.
|
private |
A PUSH socket to write on the bus.
Definition at line 290 of file kernel.hpp.
|
private |
Definition at line 270 of file kernel.hpp.
|
private |
A REP socket to send request to the kernel.
Definition at line 285 of file kernel.hpp.
|
private |
The application ZMQ context.
Definition at line 275 of file kernel.hpp.
|
private |
A pointer to the database used by Leosac, if any.
Definition at line 349 of file kernel.hpp.
|
private |
Definition at line 329 of file kernel.hpp.
|
staticprivate |
A global pointer to the Kernel instance.
Definition at line 358 of file kernel.hpp.
|
private |
Controls core main loop.
Definition at line 300 of file kernel.hpp.
|
private |
Manages the different libraries (.so) we load, path to those libraries, modules instantiation.
Definition at line 311 of file kernel.hpp.
|
private |
Object that handle networking configuration.
Definition at line 316 of file kernel.hpp.
|
private |
Watch for message on the control_
socket.
Definition at line 295 of file kernel.hpp.
|
private |
Object that expose leosac to the world.
Definition at line 321 of file kernel.hpp.
|
private |
Should we broadcast "SIGHUP" in the next main loop iteration ?
Definition at line 334 of file kernel.hpp.
|
private |
Definition at line 353 of file kernel.hpp.
|
private |
Time-point when Leosac started to run.
Definition at line 344 of file kernel.hpp.
|
private |
Definition at line 268 of file kernel.hpp.
|
private |
Should leosac restart ?
Definition at line 305 of file kernel.hpp.
|
private |
Definition at line 351 of file kernel.hpp.