-
Notifications
You must be signed in to change notification settings - Fork 22
/
host.hpp
70 lines (56 loc) · 1.83 KB
/
host.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#pragma once
#include "sensor.hpp"
#include <sdbusplus/bus.hpp>
#include <sdbusplus/server.hpp>
#include <xyz/openbmc_project/Sensor/Value/server.hpp>
#include <memory>
#include <mutex>
#include <type_traits>
template <typename... T>
using ServerObject = typename sdbusplus::server::object_t<T...>;
using ValueInterface = sdbusplus::xyz::openbmc_project::Sensor::server::Value;
using ValueObject = ServerObject<ValueInterface>;
namespace pid_control
{
class ValueHelper : public ValueInterface
{
public:
auto operator()() const
{
return value();
}
};
constexpr bool usingDouble =
std::is_same_v<std::result_of_t<ValueHelper()>, double>;
using ValueType = std::conditional_t<usingDouble, double, int64_t>;
/*
* HostSensor object is a Sensor derivative that also implements a ValueObject,
* which comes from the dbus as an object that implements Sensor.Value.
*/
class HostSensor : public Sensor, public ValueObject
{
public:
static std::unique_ptr<Sensor>
createTemp(const std::string& name, int64_t timeout,
sdbusplus::bus_t& bus, const char* objPath, bool defer);
HostSensor(const std::string& name, int64_t timeout, sdbusplus::bus_t& bus,
const char* objPath, bool defer) :
Sensor(name, timeout),
ValueObject(bus, objPath,
defer ? ValueObject::action::defer_emit
: ValueObject::action::emit_object_added)
{}
ValueType value(ValueType value) override;
ReadReturn read(void) override;
void write(double value) override;
bool getFailed(void) override;
private:
/*
* _lock will be used to make sure _updated & _value are updated
* together.
*/
std::mutex _lock;
std::chrono::high_resolution_clock::time_point _updated;
double _value = 0;
};
} // namespace pid_control