Commit ad6d7139 authored by Alessio Netti's avatar Alessio Netti
Browse files

Minor changes

- Fixed a minor bug in QueryEngine that broke thread safety
- The all and all-recursive clauses for unit input sensors do not
replace all existing sensors anymore, but only add the remaining ones
parent 89cc1f57
......@@ -18,7 +18,7 @@ void AverageAnalyzer::compute(int unitID) {
// Getting the most recent values as specified in _window
_buffer = _queryEngine.querySensor(in->getName(), _window, 0, _buffer);
if(_buffer->empty()) {
LOG(error) << "Analyzer" << _name << " cannot read from sensor " << in->getName() << "!";
LOG(error) << "Analyzer " << _name << " cannot read from sensor " << in->getName() << "!";
return;
}
......
......@@ -323,9 +323,7 @@ protected:
// An "all" or "all-recursive" statement in the input block causes all sensors related to the specific
// unit to be picked
} else if (boost::iequals(val.first, INPUT_BLOCK) && (boost::iequals(valInner.first, ALL_CLAUSE) || boost::iequals(valInner.first, ALL_REC_CLAUSE))) {
protoInputs.clear();
inputMode = boost::iequals(valInner.first, ALL_CLAUSE) ? ALL : ALL_RECURSIVE;
break;
} else {
LOG(error) << "\"" << valInner.first << "\": unknown I/O construct!";
return false;
......
......@@ -122,7 +122,6 @@ public:
return sensors;
}
//TODO: make all and all-recursive add sensors to existing ones
/**
* @brief Computes and instantiates units associated to the input analyzer
*
......@@ -168,45 +167,51 @@ public:
// We iterate over the units, and resolve their inputs and outputs starting from the prototype definitions
vector<shared_ptr<SBase>> unitInputs, unitOutputs;
vector<shared_ptr<UnitTemplate<SBase>>> *unitObjects = new vector<shared_ptr<UnitTemplate<SBase>>>();
set<string>* sensors;
// AddedSensors keeps track of which sensor names were added already to the input set, to prevent duplicates
set<string> addedSensors, *sensors;
for(const auto& u : *units) {
unitInputs.clear();
unitOutputs.clear();
if(inputMode == SELECTIVE)
// Mapping inputs
for(const auto& in : inputs) {
// Depending on the relationship of an input prototype sensor to the output level, it could be
// mapped to one sensor or more: for example, if output has level <unit-1>, and an input sensor
// has level <unit-2>, than the input will be unique, and the sensor associated to the father of the
// unit. If the other way around, the input will consist of multiple sensors, one for each child of
// the unit
sensors = resolveNodeLevelString(in.getName(), u);
if( sensors->empty() ) {
delete units;
delete sensors;
delete unitObjects;
throw invalid_argument("UnitGenerator: String " + in.getName() + " cannot be resolved!");
} else
for(const auto& s : *sensors) {
// Mapping inputs
for(const auto& in : inputs) {
// Depending on the relationship of an input prototype sensor to the output level, it could be
// mapped to one sensor or more: for example, if output has level <unit-1>, and an input sensor
// has level <unit-2>, than the input will be unique, and the sensor associated to the father of the
// unit. If the other way around, the input will consist of multiple sensors, one for each child of
// the unit
sensors = resolveNodeLevelString(in.getName(), u);
if (sensors->empty()) {
delete units;
delete sensors;
delete unitObjects;
throw invalid_argument("UnitGenerator: String " + in.getName() + " cannot be resolved!");
} else
for (const auto &s : *sensors) {
if (!addedSensors.count(s)) {
SBase uIn(in);
uIn.setName(s);
if (!_navi->sensorExists(uIn.getName())) {
delete units;
delete sensors;
delete unitObjects;
throw invalid_argument("UnitGenerator: Sensor " + in.getName() + " does not exist!");
throw invalid_argument("UnitGenerator: Sensor " + uIn.getName() + " does not exist!");
}
addedSensors.insert(s);
unitInputs.push_back(make_shared<SBase>(uIn));
}
delete sensors;
}
// If no input sensors were specified, we pick all sensors related to the specific unit
// This means that when output unit is "root" (or not specified) we get only sensors at the highest level
else {
}
delete sensors;
}
// If the all or all-recursive clauses were specified, we pick all sensors related to the specific unit
// This means that when output unit is "root" (or not specified) we get only sensors at the highest level
if( inputMode != SELECTIVE) {
sensors = _navi->getSensors(u, inputMode == ALL_RECURSIVE);
for(const auto& s : *sensors) {
SBase uIn(s);
unitInputs.push_back(make_shared<SBase>(uIn));
if( !addedSensors.count(s) ) {
SBase uIn(s);
unitInputs.push_back(make_shared<SBase>(uIn));
}
}
delete sensors;
}
......
......@@ -63,7 +63,6 @@ std::vector<reading_t>* sensorQueryCallback(const string& name, const uint64_t s
buffer->clear();
//Initializing the sensor map if necessary. Thread safe!
if(_queryEngine.updated.load()) {
QueryEngine::getInstance().updated = false;
if(!_queryEngine.updating.exchange(true)) {
for (auto &p : _configuration->getPlugins())
for (auto &g : p.configurator->getSensorGroups())
......
Supports Markdown
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