6.5.2021, 9:00 - 11:00: Due to updates GitLab may be unavailable for some minutes between 09:00 and 11:00.

Commit 78cce230 authored by Alessio Netti's avatar Alessio Netti

Removed custom readConfig() method from ProcFSConfigurator

- This allows to use additional features in the plugin, e.g. templates
for single sensors
parent 67ec262d
...@@ -42,60 +42,6 @@ ProcfsConfigurator::ProcfsConfigurator() { ...@@ -42,60 +42,6 @@ ProcfsConfigurator::ProcfsConfigurator() {
*/ */
ProcfsConfigurator::~ProcfsConfigurator() {} ProcfsConfigurator::~ProcfsConfigurator() {}
/**
* Reads a configuration file and instantiates Procfs Sensor Groups accordingly.
*
* Unlike in ConfiguratorTemplate, the assignment of MQTT topics to sensor is done in the
* sensorGroup() method.
*
* @param cfgPath: the path to the configuration file to be used
* @return true if successful, false otherwise
*
*/
bool ProcfsConfigurator::readConfig(std::string cfgPath) {
_cfgPath = cfgPath;
boost::property_tree::iptree cfg;
boost::property_tree::read_info(cfgPath, cfg);
// Read global variables (if present overwrite those from global.conf)
readGlobal(cfg);
// Read groups and templates for groups. Entities and single sensors are ignored as they are not supported in this plugin
BOOST_FOREACH (boost::property_tree::iptree::value_type &val, cfg) {
// Read template group
if (boost::iequals(val.first, "template_" + _groupName)) {
LOG(debug) << "Template " << _groupName << " \"" << val.second.data() << "\"";
if (!val.second.empty()) {
ProcfsSensorGroup *group = new ProcfsSensorGroup(val.second.data());
if (readSensorGroup(*group, val.second)) {
auto ret = _templateSensorGroups.insert(std::pair<std::string, ProcfsSensorGroup *>(val.second.data(), group));
if (!ret.second) {
LOG(warning) << "Template " << _groupName << " " << val.second.data() << " already exists! Omitting...";
}
} else {
LOG(warning) << "Template " << _groupName << " \"" << val.second.data() << "\" has bad values! Ignoring...";
}
}
// Read sensor group
} else if (boost::iequals(val.first, _groupName)) {
LOG(debug) << _groupName << " \"" << val.second.data() << "\"";
if (!val.second.empty()) {
ProcfsSGPtr group = std::make_shared<ProcfsSensorGroup>(val.second.data());
if (readSensorGroup(*group, val.second)) {
storeSensorGroup(group);
} else {
LOG(warning) << _groupName << " \"" << val.second.data() << "\" has bad values! Ignoring...";
}
}
} else if (!boost::iequals(val.first, "global")) {
LOG(error) << "\"" << val.first << "\": unknown construct!";
return false;
}
}
return constructSensorTopics();
}
/** /**
* Configures a ProcfsSensorBase object instantiated by the readSensorBase method. * Configures a ProcfsSensorBase object instantiated by the readSensorBase method.
* *
......
...@@ -51,8 +51,6 @@ class ProcfsConfigurator : public ConfiguratorTemplate<ProcfsSensorBase, ProcfsS ...@@ -51,8 +51,6 @@ class ProcfsConfigurator : public ConfiguratorTemplate<ProcfsSensorBase, ProcfsS
// Therefore, we only deal with the sensorGroup and sensorBase methods from ConfiguratorTemplate // Therefore, we only deal with the sensorGroup and sensorBase methods from ConfiguratorTemplate
void sensorGroup(ProcfsSensorGroup &sGroup, CFG_VAL config) override; void sensorGroup(ProcfsSensorGroup &sGroup, CFG_VAL config) override;
void sensorBase(ProcfsSensorBase &s, CFG_VAL config) override; void sensorBase(ProcfsSensorBase &s, CFG_VAL config) override;
// The readConfig method has to be overridden as the MQTT topic logic is custom
bool readConfig(std::string cfgPath) override;
}; };
// Functions required to correctly generate Configurator objects from linked libraries // Functions required to correctly generate Configurator objects from linked libraries
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment