Patrick Williams | 32ffb03 | 2020-10-12 12:17:48 -0500 | [diff] [blame] | 1 | #include <sdbusplus/server/interface.hpp> |
| 2 | |
| 3 | namespace sdbusplus |
| 4 | { |
| 5 | |
| 6 | namespace server |
| 7 | { |
| 8 | |
| 9 | namespace interface |
| 10 | { |
| 11 | |
Patrick Williams | 0f282c4 | 2021-11-19 11:36:18 -0600 | [diff] [blame] | 12 | interface::interface(sdbusplus::bus_t& bus, const char* path, |
Patrick Williams | a735ca5 | 2021-11-19 11:36:18 -0600 | [diff] [blame] | 13 | const char* interf, const sdbusplus::vtable_t* vtable, |
| 14 | void* context) : |
Patrick Williams | 6649221 | 2021-11-19 16:49:28 -0600 | [diff] [blame] | 15 | _bus(get_busp(bus), bus.getInterface()), |
Patrick Williams | a7ac313 | 2021-11-19 14:48:22 -0600 | [diff] [blame] | 16 | _path(path), _interf(interf), _intf(bus.getInterface()), |
Patrick Williams | 32ffb03 | 2020-10-12 12:17:48 -0500 | [diff] [blame] | 17 | _interface_added(false) |
| 18 | { |
| 19 | sd_bus_slot* slot = nullptr; |
Patrick Williams | 6649221 | 2021-11-19 16:49:28 -0600 | [diff] [blame] | 20 | int r = _intf->sd_bus_add_object_vtable( |
| 21 | get_busp(_bus), &slot, _path.c_str(), _interf.c_str(), vtable, context); |
Patrick Williams | 32ffb03 | 2020-10-12 12:17:48 -0500 | [diff] [blame] | 22 | if (r < 0) |
| 23 | { |
| 24 | throw exception::SdBusError(-r, "sd_bus_add_object_vtable"); |
| 25 | } |
| 26 | |
Patrick Williams | a7ac313 | 2021-11-19 14:48:22 -0600 | [diff] [blame] | 27 | _slot = std::move(slot); |
Patrick Williams | 32ffb03 | 2020-10-12 12:17:48 -0500 | [diff] [blame] | 28 | } |
| 29 | |
| 30 | interface::~interface() |
| 31 | { |
| 32 | emit_removed(); |
| 33 | } |
| 34 | |
| 35 | void interface::property_changed(const char* property) |
| 36 | { |
| 37 | std::array<const char*, 2> values = {property, nullptr}; |
| 38 | |
| 39 | // Note: Converting to use _strv version, could also mock two pointer |
| 40 | // use-case explicitly. |
Patrick Williams | 6649221 | 2021-11-19 16:49:28 -0600 | [diff] [blame] | 41 | _intf->sd_bus_emit_properties_changed_strv(get_busp(_bus), _path.c_str(), |
Patrick Williams | 32ffb03 | 2020-10-12 12:17:48 -0500 | [diff] [blame] | 42 | _interf.c_str(), values.data()); |
| 43 | } |
| 44 | |
| 45 | } // namespace interface |
| 46 | } // namespace server |
| 47 | } // namespace sdbusplus |