blob: e6c0ea1c6e4c2a47307f3079a5008059bb111e4e [file] [log] [blame]
Krzysztof Grobelnyc8e3a642020-10-23 12:29:16 +02001#pragma once
2
Krzysztof Grobelny80697712021-03-04 09:49:27 +00003#include "interfaces/clock.hpp"
Krzysztof Grobelnyc8e3a642020-10-23 12:29:16 +02004#include "interfaces/metric.hpp"
Krzysztof Grobelnyf7ea2992022-01-27 11:04:58 +01005#include "interfaces/metric_listener.hpp"
Krzysztof Grobelny6ccfcbf2020-11-04 09:31:36 +01006#include "interfaces/sensor.hpp"
Krzysztof Grobelnyc8e3a642020-10-23 12:29:16 +02007#include "interfaces/sensor_listener.hpp"
Krzysztof Grobelnyf7ea2992022-01-27 11:04:58 +01008#include "metrics/collection_data.hpp"
9#include "types/collection_duration.hpp"
Krzysztof Grobelnyc8e3a642020-10-23 12:29:16 +020010
Krzysztof Grobelny6ccfcbf2020-11-04 09:31:36 +010011class Metric :
12 public interfaces::Metric,
13 public interfaces::SensorListener,
14 public std::enable_shared_from_this<Metric>
Krzysztof Grobelnyc8e3a642020-10-23 12:29:16 +020015{
16 public:
Krzysztof Grobelnydcc4e192021-03-08 09:09:34 +000017 Metric(Sensors sensors, OperationType operationType, std::string id,
Krzysztof Grobelnyb8cc78d2021-11-29 15:54:53 +010018 CollectionTimeScope, CollectionDuration,
Krzysztof Grobelny80697712021-03-04 09:49:27 +000019 std::unique_ptr<interfaces::Clock>);
Krzysztof Grobelnyc8e3a642020-10-23 12:29:16 +020020
Krzysztof Grobelny6ccfcbf2020-11-04 09:31:36 +010021 void initialize() override;
Lukasz Kazmierczak7e098e92021-09-16 15:59:56 +020022 void deinitialize() override;
Krzysztof Grobelny9e8da542022-02-17 10:40:16 +010023 const std::vector<MetricValue>& getUpdatedReadings() override;
Krzysztof Grobelny51f0fd52021-12-28 16:32:08 +010024 void sensorUpdated(interfaces::Sensor&, Milliseconds,
25 double value) override;
Krzysztof Grobelnyd2238192020-12-02 09:27:28 +000026 LabeledMetricParameters dumpConfiguration() const override;
Krzysztof Grobelny18e71012022-11-02 13:17:01 +000027 uint64_t metricCount() const override;
Krzysztof Grobelnyf7ea2992022-01-27 11:04:58 +010028 void registerForUpdates(interfaces::MetricListener& listener) override;
29 void unregisterFromUpdates(interfaces::MetricListener& listener) override;
30 void updateReadings(Milliseconds) override;
31 bool isTimerRequired() const override;
Krzysztof Grobelnyc8e3a642020-10-23 12:29:16 +020032
33 private:
Krzysztof Grobelnyf7ea2992022-01-27 11:04:58 +010034 metrics::CollectionData&
35 findAssociatedData(const interfaces::Sensor& notifier);
Krzysztof Grobelny6ccfcbf2020-11-04 09:31:36 +010036
Krzysztof Grobelnydcc4e192021-03-08 09:09:34 +000037 std::string id;
Krzysztof Grobelnydcc4e192021-03-08 09:09:34 +000038 std::vector<MetricValue> readings;
39 Sensors sensors;
Krzysztof Grobelnye8fc5752021-02-05 14:30:45 +000040 OperationType operationType;
Krzysztof Grobelny80697712021-03-04 09:49:27 +000041 CollectionTimeScope collectionTimeScope;
Krzysztof Grobelnydcc4e192021-03-08 09:09:34 +000042 CollectionDuration collectionDuration;
Krzysztof Grobelnyf7ea2992022-01-27 11:04:58 +010043 std::vector<std::unique_ptr<metrics::CollectionData>> collectionAlgorithms;
Krzysztof Grobelny80697712021-03-04 09:49:27 +000044 std::unique_ptr<interfaces::Clock> clock;
Krzysztof Grobelnyf7ea2992022-01-27 11:04:58 +010045 std::vector<std::reference_wrapper<interfaces::MetricListener>> listeners;
Krzysztof Grobelnyc8e3a642020-10-23 12:29:16 +020046};