slot: explicitly transfer pointer
The slot class is intended to be an RAII wrapper around the C-style
`sd_bus_slot*`. As part of the constructor it gets the pointer it is
assuming ownership for.
The previous constructor took the `sd_bus_slot*` by value so it was
possible that the caller still kept the slot rather than fully
transferring ownership. Switch the constructor to an r-value reference
so that the caller's pointer can be erased as part of the ownership
transfer.
Also, add an assignment operator to simplify the syntax when a slot is
first initialized with `nullptr` and then later given ownership of a
newly constructed slot.
While this is an incompatible constructor change, it is not expected to
affect any current users. The only example of referencing a
`slot::slot` I could see in the current OpenBMC org calls the
constructor with a `nullptr`, which will seamlessly call the new r-value
variant.
Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
Change-Id: I577de2e10e4d5ccae6337c763b848ea4cf2121dd
diff --git a/src/server/interface.cpp b/src/server/interface.cpp
index 9832547..653e6d6 100644
--- a/src/server/interface.cpp
+++ b/src/server/interface.cpp
@@ -13,7 +13,7 @@
const char* interf, const sdbusplus::vtable_t* vtable,
void* context) :
_bus(bus.get(), bus.getInterface()),
- _path(path), _interf(interf), _slot(nullptr), _intf(bus.getInterface()),
+ _path(path), _interf(interf), _intf(bus.getInterface()),
_interface_added(false)
{
sd_bus_slot* slot = nullptr;
@@ -24,7 +24,7 @@
throw exception::SdBusError(-r, "sd_bus_add_object_vtable");
}
- _slot = decltype(_slot){slot};
+ _slot = std::move(slot);
}
interface::~interface()