1 #pragma once 2 3 #include "interfaces/clock.hpp" 4 #include "interfaces/metric.hpp" 5 #include "interfaces/sensor.hpp" 6 #include "interfaces/sensor_listener.hpp" 7 8 class Metric : 9 public interfaces::Metric, 10 public interfaces::SensorListener, 11 public std::enable_shared_from_this<Metric> 12 { 13 public: 14 Metric(Sensors sensors, OperationType operationType, std::string id, 15 CollectionTimeScope, CollectionDuration, 16 std::unique_ptr<interfaces::Clock>); 17 ~Metric(); 18 19 void initialize() override; 20 void deinitialize() override; 21 std::vector<MetricValue> getReadings() const override; 22 void sensorUpdated(interfaces::Sensor&, Milliseconds) override; 23 void sensorUpdated(interfaces::Sensor&, Milliseconds, 24 double value) override; 25 LabeledMetricParameters dumpConfiguration() const override; 26 uint64_t sensorCount() const override; 27 28 private: 29 class CollectionData; 30 class DataPoint; 31 class DataInterval; 32 class DataStartup; 33 34 static std::vector<std::unique_ptr<CollectionData>> 35 makeCollectionData(size_t size, OperationType, CollectionTimeScope, 36 CollectionDuration); 37 38 CollectionData& findAssociatedData(const interfaces::Sensor& notifier); 39 40 std::string id; 41 std::vector<MetricValue> readings; 42 Sensors sensors; 43 OperationType operationType; 44 CollectionTimeScope collectionTimeScope; 45 CollectionDuration collectionDuration; 46 std::vector<std::unique_ptr<CollectionData>> collectionAlgorithms; 47 std::unique_ptr<interfaces::Clock> clock; 48 }; 49