blob: a72c6560230980b8571de43c920d59378b8f102d [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
12interface::interface(sdbusplus::bus::bus& bus, const char* path,
13 const char* interf,
14 const sdbusplus::vtable::vtable_t* vtable, void* context) :
15 _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