Created metric class
Metric collects updates from sensor. Report displays metric readings
depending on reportingType.
Tested:
- Added new units tests for Metric class
- All other unit tests are passing
Change-Id: I19f4831fab163a4f9540cef7bb23e903ae90fddf
Signed-off-by: Krzysztof Grobelny <krzysztof.grobelny@intel.com>
diff --git a/src/metric.hpp b/src/metric.hpp
index 76a60fb..6e27446 100644
--- a/src/metric.hpp
+++ b/src/metric.hpp
@@ -1,21 +1,30 @@
#pragma once
#include "interfaces/metric.hpp"
+#include "interfaces/sensor.hpp"
#include "interfaces/sensor_listener.hpp"
-class Metric : public interfaces::Metric, public interfaces::SensorListener
+class Metric :
+ public interfaces::Metric,
+ public interfaces::SensorListener,
+ public std::enable_shared_from_this<Metric>
{
public:
- const std::vector<MetricValue>& getReadings() const override
- {
- return readings;
- }
+ Metric(std::vector<std::shared_ptr<interfaces::Sensor>> sensors,
+ std::string operationType, std::string id, std::string metadata);
- void sensorUpdated(interfaces::Sensor&, uint64_t) override
- {}
- void sensorUpdated(interfaces::Sensor&, uint64_t, double value) override
- {}
+ void initialize() override;
+ const std::vector<MetricValue>& getReadings() const override;
+ void sensorUpdated(interfaces::Sensor&, uint64_t) override;
+ void sensorUpdated(interfaces::Sensor&, uint64_t, double value) override;
+ nlohmann::json to_json() const override;
private:
+ MetricValue& findMetric(interfaces::Sensor&);
+
+ std::vector<std::shared_ptr<interfaces::Sensor>> sensors;
+ std::string operationType;
+ std::string id;
+ std::string metadata;
std::vector<MetricValue> readings;
};