asio: Added method add_unique_interface to object_server
Add_unique_interface returns unique_ptr instead of shared_ptr.
When shared_ptr is used call to object_server::remove_interface
is needed, when unique_ptr is used interface is removed when
goes out of scope.
Tested:
- Changed two of the examples to use this method
- All other tests are still passing after this change
Signed-off-by: Krzysztof Grobelny <krzysztof.grobelny@intel.com>
Change-Id: I490acafdaf0cd62419a0540adbb846c393c3939f
diff --git a/example/get-all-properties.cpp b/example/get-all-properties.cpp
index 7a2d037..fec7f6d 100644
--- a/example/get-all-properties.cpp
+++ b/example/get-all-properties.cpp
@@ -36,7 +36,8 @@
ioc_(ioc),
bus_(bus), objServer_(objServer)
{
- demo_ = objServer_.add_interface(xyz::demo::path, xyz::demo::interface);
+ demo_ = objServer_.add_unique_interface(xyz::demo::path,
+ xyz::demo::interface);
demo_->register_property_r(name::greetings, std::string(),
sdbusplus::vtable::property_::const_,
@@ -58,11 +59,6 @@
demo_->initialize();
}
- ~Application()
- {
- objServer_.remove_interface(demo_);
- }
-
uint32_t fatalErrors() const
{
return fatalErrors_;
@@ -194,7 +190,7 @@
sdbusplus::asio::connection& bus_;
sdbusplus::asio::object_server& objServer_;
- std::shared_ptr<sdbusplus::asio::dbus_interface> demo_;
+ std::unique_ptr<sdbusplus::asio::dbus_interface> demo_;
std::string greetings_ = "Hello";
std::string goodbyes_ = "Bye";