Commit 9f1bfba9 authored by Michael Ott's avatar Michael Ott
Browse files

Add isTemplate parameter to readSensorBase() and readSensorGroup() to reduce...

Add isTemplate parameter to readSensorBase() and readSensorGroup() to reduce debug output for templates
parent f728daf3
......@@ -137,7 +137,7 @@ public:
LOG(debug) << "Template " << _groupName << " \"" << val.second.data() << "\"";
if (!val.second.empty()) {
SGroup* group = new SGroup(val.second.data());
if (readSensorGroup(*group, val.second)) {
if (readSensorGroup(*group, val.second, true)) {
auto ret = _templateSensorGroups.insert(std::pair<std::string, SGroup*>(val.second.data(), group));
if(!ret.second) {
LOG(warning) << "Template " << _groupName << " " << val.second.data() << " already exists! Omitting...";
......@@ -153,7 +153,7 @@ public:
LOG(debug) << "Template " << _baseName << " \"" << val.second.data() << "\"";
if (!val.second.empty()) {
SBase* base = new SBase(val.second.data());
if (readSensorBase(*base, val.second)) {
if (readSensorBase(*base, val.second, true)) {
auto ret = _templateSensorBases.insert(std::pair<std::string, SBase*>(val.second.data(), base));
if(!ret.second) {
LOG(warning) << "Template " << _baseName << " " << val.second.data() << " already exists! Omitting...";
......@@ -169,10 +169,10 @@ public:
LOG(debug) << "Template single " << _baseName << " \"" << val.second.data() << "\"";
if (!val.second.empty()) {
SGroup* group = new SGroup(val.second.data());
if (readSensorGroup(*group, val.second)) {
if (readSensorGroup(*group, val.second, true)) {
//group which consists of only one sensor
SB_Ptr sensor = std::make_shared<SBase>(val.second.data());
if (readSensorBase(*sensor, val.second)) {
if (readSensorBase(*sensor, val.second, true)) {
group->pushBackSensor(sensor);
auto ret = _templateSensorGroups.insert(std::pair<std::string, SGroup*>(val.second.data(), group));
if(!ret.second) {
......@@ -340,22 +340,25 @@ protected:
*
* @param sBase The sensor base for which to set the values
* @param config A boost property (sub-)tree containing the sensor values
* @param isTemplate Are we parsing a template or a regular sensor?
*
* @return True on success, false otherwise
*/
bool readSensorBase(SBase& sBase, CFG_VAL config) {
bool readSensorBase(SBase& sBase, CFG_VAL config, bool isTemplate=false) {
sBase.setCacheInterval(_cacheInterval);
boost::optional<boost::property_tree::iptree&> def = config.get_child_optional("default");
if(def) {
//we copy all values from default (including copy constructing its sensors)
//if own sensors are specified they are appended
LOG(debug) << " Using \"" << def.get().data() << "\" as default.";
auto it = _templateSensorBases.find(def.get().data());
if(it != _templateSensorBases.end()) {
sBase = *(it->second);
sBase.setName(config.data());
} else {
LOG(warning) << "Template " << _baseName << "\" " << def.get().data() << "\" not found! Using standard values.";
if (!isTemplate) {
boost::optional<boost::property_tree::iptree&> def = config.get_child_optional("default");
if(def) {
//we copy all values from default (including copy constructing its sensors)
//if own sensors are specified they are appended
LOG(debug) << " Using \"" << def.get().data() << "\" as default.";
auto it = _templateSensorBases.find(def.get().data());
if(it != _templateSensorBases.end()) {
sBase = *(it->second);
sBase.setName(config.data());
} else {
LOG(warning) << "Template " << _baseName << "\" " << def.get().data() << "\" not found! Using standard values.";
}
}
}
......@@ -387,22 +390,25 @@ protected:
*
* @param sGroup The sensor group for which to set the values
* @param config A boost property (sub-)tree containing the sensor values
* @param isTemplate Is this a template or a regular group?
*
* @return True on success, false otherwise
*/
bool readSensorGroup(SGroup& sGroup, CFG_VAL config) {
//first check if default group is given
boost::optional<boost::property_tree::iptree&> def = config.get_child_optional("default");
if(def) {
//we copy all values from default (including copy constructing its sensors)
//if own sensors are specified they are appended
LOG(debug) << " Using \"" << def.get().data() << "\" as default.";
auto it = _templateSensorGroups.find(def.get().data());
if(it != _templateSensorGroups.end()) {
sGroup = *(it->second);
sGroup.setGroupName(config.data());
} else {
LOG(warning) << "Template " << _groupName << "\" " << def.get().data() << "\" not found! Using standard values.";
bool readSensorGroup(SGroup& sGroup, CFG_VAL config, bool isTemplate=false) {
//first check if default group is given, unless we are reading a template already
if (!isTemplate) {
boost::optional<boost::property_tree::iptree&> def = config.get_child_optional("default");
if(def) {
//we copy all values from default (including copy constructing its sensors)
//if own sensors are specified they are appended
LOG(debug) << " Using \"" << def.get().data() << "\" as default.";
auto it = _templateSensorGroups.find(def.get().data());
if(it != _templateSensorGroups.end()) {
sGroup = *(it->second);
sGroup.setGroupName(config.data());
} else {
LOG(warning) << "Template " << _groupName << "\" " << def.get().data() << "\" not found! Using standard values.";
}
}
}
......@@ -421,11 +427,13 @@ protected:
sGroup.setSync(true);
}
} else if (boost::iequals(val.first, _baseName)) {
LOG(debug) << " " << _baseName << " " << val.second.data();
if (!isTemplate) {
LOG(debug) << " " << _baseName << " " << val.second.data();
}
SB_Ptr sensor = std::make_shared<SBase>(val.second.data());
if (readSensorBase(*sensor, val.second)) {
if (readSensorBase(*sensor, val.second, isTemplate)) {
sGroup.pushBackSensor(sensor);
} else {
} else if (!isTemplate) {
LOG(warning) << _baseName << " " << sGroup.getGroupName() << "::" << sensor->getName() << " could not be read! Omitting";
}
}
......
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