blob: 3a8387d4c145468876a6e9e8ec13872d233b69e7 [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
Patrick Ventureda4a5dd2018-08-31 09:42:48 -07005#include <memory>
6#include <mutex>
7#include <sdbusplus/bus.hpp>
8#include <sdbusplus/server.hpp>
Patrick Venture1248b152018-10-30 19:09:54 -07009#include <xyz/openbmc_project/Sensor/Value/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:
Patrick Venture563a3562018-10-30 09:31:26 -070024 static std::unique_ptr<Sensor> createTemp(const std::string& name,
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070025 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};