blob: ad3f834237ec6489d3c79b2f50868457c8bf3abd [file] [log] [blame]
Patrick Venture863b9242018-03-08 08:29:23 -08001#pragma once
2
Patrick Ventureda4a5dd2018-08-31 09:42:48 -07003#include "sensor.hpp"
Patrick Venture863b9242018-03-08 08:29:23 -08004#include "xyz/openbmc_project/Sensor/Value/server.hpp"
5
Patrick Ventureda4a5dd2018-08-31 09:42:48 -07006#include <memory>
7#include <mutex>
8#include <sdbusplus/bus.hpp>
9#include <sdbusplus/server.hpp>
Patrick Venture863b9242018-03-08 08:29:23 -080010
11template <typename... T>
12using ServerObject = typename sdbusplus::server::object::object<T...>;
13
14using ValueInterface = sdbusplus::xyz::openbmc_project::Sensor::server::Value;
15using 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 */
21class HostSensor : public Sensor, public ValueObject
22{
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070023 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 Venture863b9242018-03-08 08:29:23 -080028
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070029 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 Venture863b9242018-03-08 08:29:23 -080035
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070036 /* Note: This must be int64_t because it's from ValueObject */
37 int64_t value(int64_t value) override;
Patrick Venture863b9242018-03-08 08:29:23 -080038
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070039 ReadReturn read(void) override;
40 void write(double value) override;
Patrick Venture863b9242018-03-08 08:29:23 -080041
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070042 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 Venture863b9242018-03-08 08:29:23 -080050};