Krzysztof Grobelny | b564594 | 2020-09-29 11:52:45 +0200 | [diff] [blame] | 1 | #include "dbus_sensor_object.hpp" |
| 2 | |
| 3 | #include <boost/asio.hpp> |
| 4 | #include <sdbusplus/asio/connection.hpp> |
| 5 | #include <sdbusplus/asio/object_server.hpp> |
| 6 | #include <sdbusplus/bus.hpp> |
| 7 | |
| 8 | namespace stubs |
| 9 | { |
| 10 | |
| 11 | DbusSensorObject::DbusSensorObject( |
| 12 | boost::asio::io_context& ioc, |
| 13 | const std::shared_ptr<sdbusplus::asio::connection>& bus, |
| 14 | const std::shared_ptr<sdbusplus::asio::object_server>& objServer) : |
| 15 | ioc(ioc), |
| 16 | bus(bus), objServer(objServer) |
| 17 | { |
| 18 | sensorIface = objServer->add_interface(path(), interface()); |
| 19 | |
| 20 | sensorIface->register_property_r(property.value(), double{}, |
| 21 | sdbusplus::vtable::property_::emits_change, |
| 22 | [this](const auto&) { return value; }); |
| 23 | |
| 24 | sensorIface->initialize(); |
| 25 | } |
| 26 | |
| 27 | DbusSensorObject::~DbusSensorObject() |
| 28 | { |
| 29 | objServer->remove_interface(sensorIface); |
| 30 | } |
| 31 | |
| 32 | void DbusSensorObject::setValue(double v) |
| 33 | { |
| 34 | value = v; |
| 35 | |
| 36 | sensorIface->signal_property(property.value()); |
| 37 | } |
| 38 | |
| 39 | double DbusSensorObject::getValue() const |
| 40 | { |
| 41 | return value; |
| 42 | } |
| 43 | |
| 44 | const char* DbusSensorObject::path() |
| 45 | { |
| 46 | return "/telemetry/ut/DbusSensorObject"; |
| 47 | } |
| 48 | |
| 49 | const char* DbusSensorObject::interface() |
| 50 | { |
| 51 | return "xyz.openbmc_project.Sensor.Value"; |
| 52 | } |
| 53 | |
| 54 | const char* DbusSensorObject::Properties::value() |
| 55 | { |
| 56 | return "Value"; |
| 57 | } |
| 58 | |
| 59 | } // namespace stubs |