xref: /openbmc/sdbusplus/src/server/interface.cpp (revision 9d8ba947)
1 #include <sdbusplus/server/interface.hpp>
2 
3 namespace sdbusplus
4 {
5 
6 namespace server
7 {
8 
9 namespace interface
10 {
11 
makeObjVtable(SdBusInterface * intf,sd_bus * bus,const char * path,const char * interf,const sdbusplus::vtable_t * vtable,void * context)12 static slot_t makeObjVtable(SdBusInterface* intf, sd_bus* bus, const char* path,
13                             const char* interf,
14                             const sdbusplus::vtable_t* vtable, void* context)
15 {
16     sd_bus_slot* slot;
17     int r = intf->sd_bus_add_object_vtable(bus, &slot, path, interf, vtable,
18                                            context);
19     if (r < 0)
20     {
21         throw exception::SdBusError(-r, "sd_bus_add_object_vtable");
22     }
23     return slot_t{slot, intf};
24 }
25 
interface(sdbusplus::bus_t & bus,const char * path,const char * interf,const sdbusplus::vtable_t * vtable,void * context)26 interface::interface(sdbusplus::bus_t& bus, const char* path,
27                      const char* interf, const sdbusplus::vtable_t* vtable,
28                      void* context) :
29     _bus(get_busp(bus), bus.getInterface()),
30     _path(path), _interf(interf), _interface_added(false),
31     _slot(makeObjVtable(_bus.getInterface(), get_busp(_bus), _path.c_str(),
32                         _interf.c_str(), vtable, context))
33 {}
34 
~interface()35 interface::~interface()
36 {
37     emit_removed();
38 }
39 
property_changed(const char * property)40 void interface::property_changed(const char* property)
41 {
42     std::array<const char*, 2> values = {property, nullptr};
43 
44     // Note: Converting to use _strv version, could also mock two pointer
45     // use-case explicitly.
46     _bus.getInterface()->sd_bus_emit_properties_changed_strv(
47         get_busp(_bus), _path.c_str(), _interf.c_str(), values.data());
48 }
49 
50 } // namespace interface
51 } // namespace server
52 } // namespace sdbusplus
53