blob: e47f6ef04a2aed07d9da9357e04be6f60a708a81 [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 Williams66492212021-11-19 16:49:28 -060015 _bus(get_busp(bus), bus.getInterface()),
Patrick Williamsa7ac3132021-11-19 14:48:22 -060016 _path(path), _interf(interf), _intf(bus.getInterface()),
Patrick Williams32ffb032020-10-12 12:17:48 -050017 _interface_added(false)
18{
19 sd_bus_slot* slot = nullptr;
Patrick Williams66492212021-11-19 16:49:28 -060020 int r = _intf->sd_bus_add_object_vtable(
21 get_busp(_bus), &slot, _path.c_str(), _interf.c_str(), vtable, context);
Patrick Williams32ffb032020-10-12 12:17:48 -050022 if (r < 0)
23 {
24 throw exception::SdBusError(-r, "sd_bus_add_object_vtable");
25 }
26
Patrick Williamsa7ac3132021-11-19 14:48:22 -060027 _slot = std::move(slot);
Patrick Williams32ffb032020-10-12 12:17:48 -050028}
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.
Patrick Williams66492212021-11-19 16:49:28 -060041 _intf->sd_bus_emit_properties_changed_strv(get_busp(_bus), _path.c_str(),
Patrick Williams32ffb032020-10-12 12:17:48 -050042 _interf.c_str(), values.data());
43}
44
45} // namespace interface
46} // namespace server
47} // namespace sdbusplus