Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions capiocl/configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 21 additions & 2 deletions src/Engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() {

Expand Down
15 changes: 11 additions & 4 deletions src/configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
#include "capiocl/printer.h"
#include "toml++/toml.hpp"

void flatten_table(const toml::table &tbl, std::unordered_map<std::string, std::string> &map,
const std::string &prefix = "") {
void load_config_to_memory(const toml::table &tbl,
std::unordered_map<std::string, std::string> &map,
const std::string &prefix = "") {
for (const auto &[key, value] : tbl) {
std::string full_key;
if (prefix.empty()) {
Expand All @@ -16,10 +17,12 @@ void flatten_table(const toml::table &tbl, std::unordered_map<std::string, std::
}

if (value.is_table()) {
flatten_table(*value.as_table(), map, full_key);
load_config_to_memory(*value.as_table(), map, full_key);
} else {
if (value.is_string()) {
map[full_key] = value.as_string()->get();
} 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());
}
Expand All @@ -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) {
Expand All @@ -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,
Expand Down
8 changes: 7 additions & 1 deletion src/defaults.cpp
Original file line number Diff line number Diff line change
@@ -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"};
Expand All @@ -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"};
4 changes: 4 additions & 0 deletions tests/tomls/sample1.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
[monitor.filesystem]
enabled = true

[monitor.mcast]
delay_ms = 300
enabled = true

[monitor.mcast.commit]
ip = "224.224.224.3"
Expand Down
Loading