blob: fa462cb6395d36455fedf1bf9bbdaa85fda251cf [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 Grobelnycff70c12022-10-27 07:16:08 +000017 Metric(Sensors sensors, OperationType operationType, CollectionTimeScope,
18 CollectionDuration, std::unique_ptr<interfaces::Clock>);
Krzysztof Grobelnyc8e3a642020-10-23 12:29:16 +020019
Krzysztof Grobelny6ccfcbf2020-11-04 09:31:36 +010020 void initialize() override;
Lukasz Kazmierczak7e098e92021-09-16 15:59:56 +020021 void deinitialize() override;
Krzysztof Grobelny9e8da542022-02-17 10:40:16 +010022 const std::vector<MetricValue>& getUpdatedReadings() override;
Krzysztof Grobelny51f0fd52021-12-28 16:32:08 +010023 void sensorUpdated(interfaces::Sensor&, Milliseconds,
24 double value) override;
Krzysztof Grobelnyd2238192020-12-02 09:27:28 +000025 LabeledMetricParameters dumpConfiguration() const override;
Krzysztof Grobelny18e71012022-11-02 13:17:01 +000026 uint64_t metricCount() const override;
Krzysztof Grobelnyf7ea2992022-01-27 11:04:58 +010027 void registerForUpdates(interfaces::MetricListener& listener) override;
28 void unregisterFromUpdates(interfaces::MetricListener& listener) override;
29 void updateReadings(Milliseconds) override;
30 bool isTimerRequired() const override;
Krzysztof Grobelnyc8e3a642020-10-23 12:29:16 +020031
32 private:
Krzysztof Grobelnyf7ea2992022-01-27 11:04:58 +010033 metrics::CollectionData&
34 findAssociatedData(const interfaces::Sensor& notifier);
Krzysztof Grobelny6ccfcbf2020-11-04 09:31:36 +010035
Krzysztof Grobelnydcc4e192021-03-08 09:09:34 +000036 std::vector<MetricValue> readings;
37 Sensors sensors;
Krzysztof Grobelnye8fc5752021-02-05 14:30:45 +000038 OperationType operationType;
Krzysztof Grobelny80697712021-03-04 09:49:27 +000039 CollectionTimeScope collectionTimeScope;
Krzysztof Grobelnydcc4e192021-03-08 09:09:34 +000040 CollectionDuration collectionDuration;
Krzysztof Grobelnyf7ea2992022-01-27 11:04:58 +010041 std::vector<std::unique_ptr<metrics::CollectionData>> collectionAlgorithms;
Krzysztof Grobelny80697712021-03-04 09:49:27 +000042 std::unique_ptr<interfaces::Clock> clock;
Krzysztof Grobelnyf7ea2992022-01-27 11:04:58 +010043 std::vector<std::reference_wrapper<interfaces::MetricListener>> listeners;
Krzysztof Grobelnyc8e3a642020-10-23 12:29:16 +020044};