Krzysztof Grobelny | b564594 | 2020-09-29 11:52:45 +0200 | [diff] [blame] | 1 | #include "dbus_sensor_object.hpp" |
| 2 | |
Szymon Dompke | 1cdd7e4 | 2022-06-08 14:43:13 +0200 | [diff] [blame] | 3 | #include "helpers.hpp" |
| 4 | |
Krzysztof Grobelny | b564594 | 2020-09-29 11:52:45 +0200 | [diff] [blame] | 5 | #include <boost/asio.hpp> |
| 6 | #include <sdbusplus/asio/connection.hpp> |
| 7 | #include <sdbusplus/asio/object_server.hpp> |
| 8 | #include <sdbusplus/bus.hpp> |
| 9 | |
| 10 | namespace stubs |
| 11 | { |
| 12 | |
| 13 | DbusSensorObject::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 Williams | 3a1c297 | 2023-05-10 07:51:04 -0500 | [diff] [blame] | 20 | 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 Grobelny | b564594 | 2020-09-29 11:52:45 +0200 | [diff] [blame] | 26 | } |
| 27 | |
| 28 | void DbusSensorObject::setValue(double v) |
| 29 | { |
| 30 | value = v; |
| 31 | |
| 32 | sensorIface->signal_property(property.value()); |
| 33 | } |
| 34 | |
| 35 | double DbusSensorObject::getValue() const |
| 36 | { |
| 37 | return value; |
| 38 | } |
| 39 | |
| 40 | const char* DbusSensorObject::path() |
| 41 | { |
| 42 | return "/telemetry/ut/DbusSensorObject"; |
| 43 | } |
| 44 | |
| 45 | const char* DbusSensorObject::interface() |
| 46 | { |
| 47 | return "xyz.openbmc_project.Sensor.Value"; |
| 48 | } |
| 49 | |
| 50 | const char* DbusSensorObject::Properties::value() |
| 51 | { |
| 52 | return "Value"; |
| 53 | } |
| 54 | |
| 55 | } // namespace stubs |