Commit fc9a8353 authored by Michael Ott's avatar Michael Ott
Browse files

Fix wildcard matching for SensorCache class

parent 70a9ee39
......@@ -92,22 +92,25 @@ uint64_t SensorCache::getSensor(std::string topic) {
/* Create SensorIds with the lowest and highest values matching the wildcard */
DCDB::SensorId sidLow(std::string(topic).replace(wp, 1, std::string(wl, '0')));
DCDB::SensorId sidHi(std::string(topic).replace(wp, 1, std::string(wl, 'f')));
DCDB::SensorId sidMask(std::string(wp, 'f') + std::string(wl, '0') + std::string(topic.length()-wp-1, 'f'));
sidLow.setRsvd(0);
sidHi.setRsvd(0);
/* See whether there's a SensorId in the cache >= sidLow */
sensorCache_t::iterator it = sensorCache.lower_bound(sidLow);
sensorCache_t::iterator mostRecentSidIt;
sensorCache_t::iterator mostRecentSidIt = sensorCache.end();
bool foundOne = false;
/* Iterate over the cache until the current entry is >= sidHi */
while (it != sensorCache.end() && it->first <= sidHi) {
foundOne = true;
/* We only return one value, even if multiple SensorIds would match.
* At least make sure it's the most recent value
*/
if (checkValid(it->second) && ((mostRecentSidIt == sensorCache.end()) || mostRecentSidIt->second.timestamp < it->second.timestamp)) {
mostRecentSidIt = it;
/* Iterate over the cache until the current entry is > sidHi */
while ((it != sensorCache.end()) && (it->first <= sidHi)) {
if ((it->first & sidMask) == sidLow) {
foundOne = true;
/* We only return one value, even if multiple SensorIds would match.
* At least make sure it's the most recent value
*/
if (checkValid(it->second) && ((mostRecentSidIt == sensorCache.end()) || mostRecentSidIt->second.timestamp < it->second.timestamp)) {
mostRecentSidIt = it;
}
}
it++;
}
......
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