blob: 98325477eed6e7540fb908d48bd2d4571eb2f9ae [file] [log] [blame]
Patrick Williams32ffb032020-10-12 12:17:48 -05001#include <sdbusplus/server/interface.hpp>
2
3namespace sdbusplus
4{
5
6namespace server
7{
8
9namespace interface
10{
11
Patrick Williams0f282c42021-11-19 11:36:18 -060012interface::interface(sdbusplus::bus_t& bus, const char* path,
Patrick Williamsa735ca52021-11-19 11:36:18 -060013 const char* interf, const sdbusplus::vtable_t* vtable,
14 void* context) :
Patrick Williams32ffb032020-10-12 12:17:48 -050015 _bus(bus.get(), bus.getInterface()),
16 _path(path), _interf(interf), _slot(nullptr), _intf(bus.getInterface()),
17 _interface_added(false)
18{
19 sd_bus_slot* slot = nullptr;
20 int r = _intf->sd_bus_add_object_vtable(_bus.get(), &slot, _path.c_str(),
21 _interf.c_str(), vtable, context);
22 if (r < 0)
23 {
24 throw exception::SdBusError(-r, "sd_bus_add_object_vtable");
25 }
26
27 _slot = decltype(_slot){slot};
28}
29
30interface::~interface()
31{
32 emit_removed();
33}
34
35void 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.
41 _intf->sd_bus_emit_properties_changed_strv(_bus.get(), _path.c_str(),
42 _interf.c_str(), values.data());
43}
44
45} // namespace interface
46} // namespace server
47} // namespace sdbusplus