Created sensor cache class
Created sensor cache and sensor interface that needs to be
implemented by sensors.
Tested:
- Sensors created by sensor cache are stored and reused if
there is try to access same sensor multiple times.
- All other units tests are passing
Change-Id: I552b2016bca4688e1b2a223297587826af256b54
Signed-off-by: Krzysztof Grobelny <krzysztof.grobelny@intel.com>
diff --git a/src/sensor_cache.cpp b/src/sensor_cache.cpp
new file mode 100644
index 0000000..3b9c83d
--- /dev/null
+++ b/src/sensor_cache.cpp
@@ -0,0 +1,19 @@
+#include "sensor_cache.hpp"
+
+SensorCache::SensorsContainer::iterator SensorCache::findExpiredSensor(
+ SensorCache::SensorsContainer::iterator begin)
+{
+ return std::find_if(begin, sensors.end(),
+ [](const auto& item) { return item.second.expired(); });
+}
+
+void SensorCache::cleanupExpiredSensors()
+{
+ auto begin = sensors.begin();
+
+ for (auto it = findExpiredSensor(begin); it != sensors.end();
+ it = findExpiredSensor(begin))
+ {
+ begin = sensors.erase(it);
+ }
+}