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