Patrick Venture | 863b924 | 2018-03-08 08:29:23 -0800 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame^] | 3 | #include "sensor.hpp" |
Patrick Venture | 863b924 | 2018-03-08 08:29:23 -0800 | [diff] [blame] | 4 | #include "xyz/openbmc_project/Sensor/Value/server.hpp" |
| 5 | |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame^] | 6 | #include <memory> |
| 7 | #include <mutex> |
| 8 | #include <sdbusplus/bus.hpp> |
| 9 | #include <sdbusplus/server.hpp> |
Patrick Venture | 863b924 | 2018-03-08 08:29:23 -0800 | [diff] [blame] | 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 | { |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame^] | 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); |
Patrick Venture | 863b924 | 2018-03-08 08:29:23 -0800 | [diff] [blame] | 28 | |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame^] | 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 | } |
Patrick Venture | 863b924 | 2018-03-08 08:29:23 -0800 | [diff] [blame] | 35 | |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame^] | 36 | /* Note: This must be int64_t because it's from ValueObject */ |
| 37 | int64_t value(int64_t value) override; |
Patrick Venture | 863b924 | 2018-03-08 08:29:23 -0800 | [diff] [blame] | 38 | |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame^] | 39 | ReadReturn read(void) override; |
| 40 | void write(double value) override; |
Patrick Venture | 863b924 | 2018-03-08 08:29:23 -0800 | [diff] [blame] | 41 | |
Patrick Venture | da4a5dd | 2018-08-31 09:42:48 -0700 | [diff] [blame^] | 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; |
Patrick Venture | 863b924 | 2018-03-08 08:29:23 -0800 | [diff] [blame] | 50 | }; |