xref: /openbmc/telemetry/src/interfaces/sensor.hpp (revision 583ba441654657bb4ba9d051b747144a7258c159)
17f06f613SKrzysztof Grobelny #pragma once
27f06f613SKrzysztof Grobelny 
394f71c51SSzymon Dompke #include "types/sensor_types.hpp"
494f71c51SSzymon Dompke 
5b5645947SKrzysztof Grobelny #include <chrono>
6b5645947SKrzysztof Grobelny #include <memory>
77f06f613SKrzysztof Grobelny #include <ostream>
87f06f613SKrzysztof Grobelny #include <string>
97f06f613SKrzysztof Grobelny #include <string_view>
107f06f613SKrzysztof Grobelny #include <tuple>
11dcc4e193SKrzysztof Grobelny #include <vector>
127f06f613SKrzysztof Grobelny 
137f06f613SKrzysztof Grobelny namespace interfaces
147f06f613SKrzysztof Grobelny {
157f06f613SKrzysztof Grobelny 
16b5645947SKrzysztof Grobelny class SensorListener;
17b5645947SKrzysztof Grobelny 
187f06f613SKrzysztof Grobelny class Sensor
197f06f613SKrzysztof Grobelny {
207f06f613SKrzysztof Grobelny   public:
217f06f613SKrzysztof Grobelny     struct Id
227f06f613SKrzysztof Grobelny     {
Idinterfaces::Sensor::Id237f06f613SKrzysztof Grobelny         Id(std::string_view type, std::string_view service,
24f535cad6SPatrick Williams            std::string_view path) : type(type), service(service), path(path)
257f06f613SKrzysztof Grobelny         {}
267f06f613SKrzysztof Grobelny 
277f06f613SKrzysztof Grobelny         std::string type;
287f06f613SKrzysztof Grobelny         std::string service;
297f06f613SKrzysztof Grobelny         std::string path;
307f06f613SKrzysztof Grobelny 
operator <interfaces::Sensor::Id317f06f613SKrzysztof Grobelny         bool operator<(const Id& other) const
327f06f613SKrzysztof Grobelny         {
337f06f613SKrzysztof Grobelny             return std::tie(type, service, path) <
347f06f613SKrzysztof Grobelny                    std::tie(other.type, other.service, other.path);
357f06f613SKrzysztof Grobelny         }
36b5645947SKrzysztof Grobelny 
strinterfaces::Sensor::Id37b5645947SKrzysztof Grobelny         inline std::string str() const
38b5645947SKrzysztof Grobelny         {
39b5645947SKrzysztof Grobelny             return type + ":" + service + ":" + path;
40b5645947SKrzysztof Grobelny         }
417f06f613SKrzysztof Grobelny     };
427f06f613SKrzysztof Grobelny 
437f06f613SKrzysztof Grobelny     virtual ~Sensor() = default;
447f06f613SKrzysztof Grobelny 
457f06f613SKrzysztof Grobelny     virtual Id id() const = 0;
46b8cc78ddSKrzysztof Grobelny     virtual std::string metadata() const = 0;
4794f71c51SSzymon Dompke     virtual std::string getName() const = 0;
48b5645947SKrzysztof Grobelny     virtual void registerForUpdates(const std::weak_ptr<SensorListener>&) = 0;
49*583ba441SPatrick Williams     virtual void unregisterFromUpdates(
50*583ba441SPatrick Williams         const std::weak_ptr<SensorListener>&) = 0;
5194f71c51SSzymon Dompke 
5294f71c51SSzymon Dompke     virtual LabeledSensorInfo getLabeledSensorInfo() const = 0;
537f06f613SKrzysztof Grobelny };
547f06f613SKrzysztof Grobelny 
557f06f613SKrzysztof Grobelny } // namespace interfaces
56dcc4e193SKrzysztof Grobelny 
57dcc4e193SKrzysztof Grobelny using Sensors = std::vector<std::shared_ptr<interfaces::Sensor>>;
58