#pragma once #include "Thresholds.hpp" #include "sensor.hpp" #include #include #include #include class ExternalSensor : public Sensor, public std::enable_shared_from_this { public: ExternalSensor(const std::string& objectType, sdbusplus::asio::object_server& objectServer, std::shared_ptr& conn, const std::string& sensorName, const std::string& sensorUnits, std::vector&& thresholdsIn, const std::string& sensorConfiguration, double maxReading, double minReading, double timeoutSecs, const PowerState& powerState); ~ExternalSensor() override; // Call this immediately after calling the constructor void initWriteHook( std::function&& writeHookIn); // Returns true if sensor has external Value that is subject to timeout bool isAliveAndPerishable() const; // Returns true if AliveAndPerishable and timeout has not yet happened bool isAliveAndFresh(const std::chrono::steady_clock::time_point& now) const; // Marks the time when Value successfully received from external source void writeBegin(const std::chrono::steady_clock::time_point& now); // Marks sensor as timed out, replacing Value with floating-point "NaN" void writeInvalidate(); // Returns amount of time elapsed since last writeBegin() happened std::chrono::steady_clock::duration ageElapsed(const std::chrono::steady_clock::time_point& now) const; // Returns amount of time remaining until sensor timeout will happen std::chrono::steady_clock::duration ageRemaining(const std::chrono::steady_clock::time_point& now) const; private: sdbusplus::asio::object_server& objServer; std::chrono::steady_clock::time_point writeLast; std::chrono::steady_clock::duration writeTimeout; bool writeAlive{false}; bool writePerishable; std::function writeHook; void checkThresholds() override; void externalSetTrigger(); };