1 #pragma once 2 3 #include "sensor.hpp" 4 5 #include <memory> 6 #include <mutex> 7 #include <sdbusplus/bus.hpp> 8 #include <sdbusplus/server.hpp> 9 #include <type_traits> 10 #include <xyz/openbmc_project/Sensor/Value/server.hpp> 11 12 template <typename... T> 13 using ServerObject = typename sdbusplus::server::object::object<T...>; 14 15 using ValueInterface = sdbusplus::xyz::openbmc_project::Sensor::server::Value; 16 using ValueObject = ServerObject<ValueInterface>; 17 18 class ValueHelper : public ValueInterface 19 { 20 21 public: 22 auto operator()() const 23 { 24 return value(); 25 } 26 }; 27 28 constexpr bool usingDouble = 29 std::is_same_v<std::result_of_t<ValueHelper()>, double>; 30 using ValueType = std::conditional_t<usingDouble, double, int64_t>; 31 32 /* 33 * HostSensor object is a Sensor derivative that also implements a ValueObject, 34 * which comes from the dbus as an object that implements Sensor.Value. 35 */ 36 class HostSensor : public Sensor, public ValueObject 37 { 38 public: 39 static std::unique_ptr<Sensor> createTemp(const std::string& name, 40 int64_t timeout, 41 sdbusplus::bus::bus& bus, 42 const char* objPath, bool defer); 43 44 HostSensor(const std::string& name, int64_t timeout, 45 sdbusplus::bus::bus& bus, const char* objPath, bool defer) : 46 Sensor(name, timeout), 47 ValueObject(bus, objPath, defer) 48 { 49 } 50 51 ValueType value(ValueType value) override; 52 53 ReadReturn read(void) override; 54 void write(double value) override; 55 56 private: 57 /* 58 * _lock will be used to make sure _updated & _value are updated 59 * together. 60 */ 61 std::mutex _lock; 62 std::chrono::high_resolution_clock::time_point _updated; 63 double _value = 0; 64 }; 65