#pragma once #include "interfaces/sensor.hpp" #include "interfaces/sensor_listener.hpp" #include "types/duration_types.hpp" #include "utils/unique_call.hpp" #include #include #include #include class Sensor final : public interfaces::Sensor, public std::enable_shared_from_this { using ValueVariant = std::variant; public: Sensor(interfaces::Sensor::Id sensorId, const std::string& sensorMetadata, boost::asio::io_context& ioc, const std::shared_ptr& bus); Sensor(const Sensor&) = delete; Sensor& operator=(const Sensor&) = delete; static Id makeId(std::string_view service, std::string_view path); Id id() const override; std::string metadata() const override; std::string getName() const override; void registerForUpdates( const std::weak_ptr& weakListener) override; void unregisterFromUpdates( const std::weak_ptr& weakListener) override; LabeledSensorInfo getLabeledSensorInfo() const override; private: static std::optional readValue(const ValueVariant& v); static void signalProc(const std::weak_ptr& weakSelf, sdbusplus::message_t&); void async_read(); void async_read(std::shared_ptr); void makeSignalMonitor(); void updateValue(double); interfaces::Sensor::Id sensorId; std::string sensorMetadata; boost::asio::io_context& ioc; std::shared_ptr bus; Milliseconds timerInterval = Milliseconds(0); std::optional timer; utils::UniqueCall uniqueCall; std::vector> listeners; Milliseconds timestamp = Milliseconds{0u}; std::optional value; std::unique_ptr signalMonitor; };