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