From 2564bbfb215f346e9fcc0723837daff4ea4f7591 Mon Sep 17 00:00:00 2001 From: Stanislav Angelovic Date: Thu, 15 Mar 2018 17:03:49 +0100 Subject: [PATCH] Add object proxy factory overload that takes unique_ptr to connection --- include/sdbus-c++/IObjectProxy.h | 21 +++++++++++++++++++++ src/ObjectProxy.cpp | 14 ++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/include/sdbus-c++/IObjectProxy.h b/include/sdbus-c++/IObjectProxy.h index 27104ef..50e2164 100755 --- a/include/sdbus-c++/IObjectProxy.h +++ b/include/sdbus-c++/IObjectProxy.h @@ -225,6 +225,27 @@ namespace sdbus { , std::string destination , std::string objectPath ); + /*! + * @brief Creates object proxy instance + * + * @param[in] connection D-Bus connection to be used by the proxy object + * @param[in] destination Bus name that provides a D-Bus object + * @param[in] objectPath Path of the D-Bus object + * @return Pointer to the object proxy instance + * + * The provided connection will be used by the proxy to issue calls against the object, + * and signals, if any, will be subscribed to on this connection. Object proxy becomes + * an exclusive owner of this connection. + * + * Code example: + * @code + * auto proxy = sdbus::createObjectProxy(std::move(connection), "com.kistler.foo", "/com/kistler/foo"); + * @endcode + */ + std::unique_ptr createObjectProxy( std::unique_ptr&& connection + , std::string destination + , std::string objectPath ); + /*! * @brief Creates object proxy instance that uses its own D-Bus connection * diff --git a/src/ObjectProxy.cpp b/src/ObjectProxy.cpp index a88018a..65643f3 100755 --- a/src/ObjectProxy.cpp +++ b/src/ObjectProxy.cpp @@ -166,6 +166,20 @@ std::unique_ptr createObjectProxy( IConnection& connection , std::move(objectPath) ); } +std::unique_ptr createObjectProxy( std::unique_ptr&& connection + , std::string destination + , std::string objectPath ) +{ + auto* sdbusConnection = dynamic_cast(connection.get()); + SDBUS_THROW_ERROR_IF(!sdbusConnection, "Connection is not a real sdbus-c++ connection", EINVAL); + + connection.release(); + + return std::make_unique( std::unique_ptr(sdbusConnection) + , std::move(destination) + , std::move(objectPath) ); +} + std::unique_ptr createObjectProxy( std::string destination , std::string objectPath ) {