From 42e27653d0873cc0cbf96d332c9ba695b0456c20 Mon Sep 17 00:00:00 2001 From: Marco Edoardo Santimaria Date: Fri, 20 Feb 2026 11:31:11 +0000 Subject: [PATCH] Added toml configuration to enable monitors --- capiocl/configuration.h | 4 ++++ src/Engine.cpp | 23 +++++++++++++++++++++-- src/configuration.cpp | 15 +++++++++++---- src/defaults.cpp | 8 +++++++- tests/tomls/sample1.toml | 4 ++++ 5 files changed, 47 insertions(+), 7 deletions(-) diff --git a/capiocl/configuration.h b/capiocl/configuration.h index 3a00cc7..58361d2 100644 --- a/capiocl/configuration.h +++ b/capiocl/configuration.h @@ -21,10 +21,14 @@ struct capiocl::configuration::defaults { static ConfigurationEntry DEFAULT_MONITOR_MCAST_PORT; /// @brief Multicast monitor delay before following operation static ConfigurationEntry DEFAULT_MONITOR_MCAST_DELAY; + /// @brief Enable multicast monitor by default + static ConfigurationEntry DEFAULT_MONITOR_MCAST_ENABLED; /// @brief Multicast monitor homenode IP static ConfigurationEntry DEFAULT_MONITOR_HOMENODE_IP; /// @brief Multicast monitor homenode PORT static ConfigurationEntry DEFAULT_MONITOR_HOMENODE_PORT; + /// @brief Enable File system monitor by default + static ConfigurationEntry DEFAULT_MONITOR_FS_ENABLED; }; /// @brief Load configuration and store it from a CAPIO-CL TOML configuration file diff --git a/src/Engine.cpp b/src/Engine.cpp index 0f0e7e2..b55b6a1 100644 --- a/src/Engine.cpp +++ b/src/Engine.cpp @@ -762,8 +762,27 @@ bool capiocl::engine::Engine::operator==(const capiocl::engine::Engine &other) c void capiocl::engine::Engine::loadConfiguration(const std::string &path) { configuration.load(path); - monitor.registerMonitorBackend(new monitor::MulticastMonitor(configuration)); - monitor.registerMonitorBackend(new monitor::FileSystemMonitor()); + std::string multicast_monitor_enabled, fs_monitor_enabled; + + try { + configuration.getParameter("monitor.mcast.enabled", &multicast_monitor_enabled); + } catch (...) { + multicast_monitor_enabled = "false"; + } + + if (multicast_monitor_enabled == "true") { + monitor.registerMonitorBackend(new monitor::MulticastMonitor(configuration)); + } + + try { + configuration.getParameter("monitor.filesystem.enabled", &fs_monitor_enabled); + } catch (...) { + fs_monitor_enabled = "false"; + } + + if (fs_monitor_enabled == "true") { + monitor.registerMonitorBackend(new monitor::FileSystemMonitor()); + } } void capiocl::engine::Engine::useDefaultConfiguration() { diff --git a/src/configuration.cpp b/src/configuration.cpp index 39d96fc..c5bfb59 100644 --- a/src/configuration.cpp +++ b/src/configuration.cpp @@ -5,8 +5,9 @@ #include "capiocl/printer.h" #include "toml++/toml.hpp" -void flatten_table(const toml::table &tbl, std::unordered_map &map, - const std::string &prefix = "") { +void load_config_to_memory(const toml::table &tbl, + std::unordered_map &map, + const std::string &prefix = "") { for (const auto &[key, value] : tbl) { std::string full_key; if (prefix.empty()) { @@ -16,10 +17,12 @@ void flatten_table(const toml::table &tbl, std::unordered_mapget(); + } else if (value.is_boolean()) { + map[full_key] = value.as_boolean()->get() ? "true" : "false"; } else { map[full_key] = std::to_string(value.as_integer()->get()); } @@ -33,6 +36,8 @@ capiocl::configuration::CapioClConfiguration::CapioClConfiguration() { this->set(defaults::DEFAULT_MONITOR_HOMENODE_IP); this->set(defaults::DEFAULT_MONITOR_HOMENODE_PORT); this->set(defaults::DEFAULT_MONITOR_MCAST_DELAY); + this->set(defaults::DEFAULT_MONITOR_FS_ENABLED); + this->set(defaults::DEFAULT_MONITOR_MCAST_ENABLED); } void capiocl::configuration::CapioClConfiguration::set(const std::string &key, std::string value) { @@ -54,7 +59,9 @@ void capiocl::configuration::CapioClConfiguration::load(const std::filesystem::p } catch (const toml::parse_error &err) { throw CapioClConfigurationException(err.what()); } - flatten_table(tbl, config); + + // copy into the local configuration the parameter from the toml config file + load_config_to_memory(tbl, config); } void capiocl::configuration::CapioClConfiguration::getParameter(const std::string &key, diff --git a/src/defaults.cpp b/src/defaults.cpp index 64d357f..b27d922 100644 --- a/src/defaults.cpp +++ b/src/defaults.cpp @@ -1,4 +1,4 @@ -#include "capiocl//configuration.h" +#include "capiocl/configuration.h" ConfigurationEntry capiocl::configuration::defaults::DEFAULT_MONITOR_MCAST_IP{ "monitor.mcast.commit.ip", "224.224.224.1"}; @@ -14,3 +14,9 @@ ConfigurationEntry capiocl::configuration::defaults::DEFAULT_MONITOR_HOMENODE_IP ConfigurationEntry capiocl::configuration::defaults::DEFAULT_MONITOR_HOMENODE_PORT{ "monitor.mcast.homenode.port", "12345"}; + +ConfigurationEntry capiocl::configuration::defaults::DEFAULT_MONITOR_MCAST_ENABLED{ + "monitor.mcast.enabled", "true"}; + +ConfigurationEntry capiocl::configuration::defaults::DEFAULT_MONITOR_FS_ENABLED{ + "monitor.filesystem.enabled", "true"}; \ No newline at end of file diff --git a/tests/tomls/sample1.toml b/tests/tomls/sample1.toml index b8e486f..6098bed 100644 --- a/tests/tomls/sample1.toml +++ b/tests/tomls/sample1.toml @@ -1,5 +1,9 @@ +[monitor.filesystem] +enabled = true + [monitor.mcast] delay_ms = 300 +enabled = true [monitor.mcast.commit] ip = "224.224.224.3"