blob: dbe95ca3dcde94dcd0416036421be0847fe529c4 [file] [log] [blame]
Krzysztof Grobelnyb5645942020-09-29 11:52:45 +02001#include "dbus_sensor_object.hpp"
2
Szymon Dompke1cdd7e42022-06-08 14:43:13 +02003#include "helpers.hpp"
4
Krzysztof Grobelnyb5645942020-09-29 11:52:45 +02005#include <boost/asio.hpp>
6#include <sdbusplus/asio/connection.hpp>
7#include <sdbusplus/asio/object_server.hpp>
8#include <sdbusplus/bus.hpp>
9
10namespace stubs
11{
12
13DbusSensorObject::DbusSensorObject(
14 boost::asio::io_context& ioc,
15 const std::shared_ptr<sdbusplus::asio::connection>& bus,
16 const std::shared_ptr<sdbusplus::asio::object_server>& objServer) :
17 ioc(ioc),
18 bus(bus), objServer(objServer)
19{
Patrick Williams3a1c2972023-05-10 07:51:04 -050020 sensorIface = objServer->add_unique_interface(path(), interface(),
21 [this](auto& iface) {
22 iface.register_property_r(property.value(), value,
23 sdbusplus::vtable::property_::emits_change,
24 [this](const auto&) { return value; });
25 });
Krzysztof Grobelnyb5645942020-09-29 11:52:45 +020026}
27
28void DbusSensorObject::setValue(double v)
29{
30 value = v;
31
32 sensorIface->signal_property(property.value());
33}
34
35double DbusSensorObject::getValue() const
36{
37 return value;
38}
39
40const char* DbusSensorObject::path()
41{
42 return "/telemetry/ut/DbusSensorObject";
43}
44
45const char* DbusSensorObject::interface()
46{
47 return "xyz.openbmc_project.Sensor.Value";
48}
49
50const char* DbusSensorObject::Properties::value()
51{
52 return "Value";
53}
54
55} // namespace stubs