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