From d864e1dfa4d2e94460d16eeb63f774b78631155e Mon Sep 17 00:00:00 2001 From: Stanislav Angelovic Date: Mon, 27 Jun 2022 12:05:06 +0200 Subject: [PATCH] refactor: rename dont_request_slot tag to floating_slot --- include/sdbus-c++/IConnection.h | 20 +++++++++++++++++++- include/sdbus-c++/Message.h | 3 ++- include/sdbus-c++/TypeTraits.h | 5 ++++- src/Connection.cpp | 5 +++++ src/Connection.h | 1 + src/Message.cpp | 5 +++++ src/Proxy.cpp | 2 +- 7 files changed, 37 insertions(+), 4 deletions(-) diff --git a/include/sdbus-c++/IConnection.h b/include/sdbus-c++/IConnection.h index c26be12..0ae5fb9 100644 --- a/include/sdbus-c++/IConnection.h +++ b/include/sdbus-c++/IConnection.h @@ -27,6 +27,7 @@ #ifndef SDBUS_CXX_ICONNECTION_H_ #define SDBUS_CXX_ICONNECTION_H_ +#include #include #include #include @@ -174,7 +175,7 @@ namespace sdbus { * * @throws sdbus::Error in case of failure */ - virtual void addObjectManager(const std::string& objectPath) = 0; + [[deprecated("Use one of other addObjectManager overloads")]] virtual void addObjectManager(const std::string& objectPath) = 0; /*! * @brief Returns fd, I/O events and timeout data you can pass to poll @@ -247,6 +248,23 @@ namespace sdbus { */ virtual uint64_t getMethodCallTimeout() const = 0; + /*! + * @brief Adds an ObjectManager at the specified D-Bus object path + * + * Creates an ObjectManager interface at the specified object path on + * the connection. This is a convenient way to interrogate a connection + * to see what objects it has. + * + * This call creates a floating registration. The ObjectManager will + * be there for the object path until the connection is destroyed. + * + * Another, recommended way to add object managers is directly through + * IObject API. + * + * @throws sdbus::Error in case of failure + */ + virtual void addObjectManager(const std::string& objectPath, floating_slot_t) = 0; + /*! * @copydoc IConnection::enterEventLoop() * diff --git a/include/sdbus-c++/Message.h b/include/sdbus-c++/Message.h index f8e58bb..d135735 100644 --- a/include/sdbus-c++/Message.h +++ b/include/sdbus-c++/Message.h @@ -176,7 +176,8 @@ namespace sdbus { MethodCall() = default; MethodReply send(uint64_t timeout) const; - void send(void* callback, void* userData, uint64_t timeout, dont_request_slot_t) const; + [[deprecated("Use send overload with floating_slot instead")]] void send(void* callback, void* userData, uint64_t timeout, dont_request_slot_t) const; + void send(void* callback, void* userData, uint64_t timeout, floating_slot_t) const; [[nodiscard]] Slot send(void* callback, void* userData, uint64_t timeout) const; MethodReply createReply() const; diff --git a/include/sdbus-c++/TypeTraits.h b/include/sdbus-c++/TypeTraits.h index 0812ab5..fe8f343 100644 --- a/include/sdbus-c++/TypeTraits.h +++ b/include/sdbus-c++/TypeTraits.h @@ -68,8 +68,11 @@ namespace sdbus { struct request_slot_t { explicit request_slot_t() = default; }; inline constexpr request_slot_t request_slot{}; // Tag specifying that the library shall own the slot resulting from the call of the function (so-called floating slot) + struct floating_slot_t { explicit floating_slot_t() = default; }; + inline constexpr floating_slot_t floating_slot{}; + // Deprecated name for the above -- a floating slot struct dont_request_slot_t { explicit dont_request_slot_t() = default; }; - inline constexpr dont_request_slot_t dont_request_slot{}; + [[deprecated("Replaced by floating_slot")]] inline constexpr dont_request_slot_t dont_request_slot{}; // Tag denoting the assumption that the caller has already obtained message ownership struct adopt_message_t { explicit adopt_message_t() = default; }; inline constexpr adopt_message_t adopt_message{}; diff --git a/src/Connection.cpp b/src/Connection.cpp index 991a427..f6f64c7 100644 --- a/src/Connection.cpp +++ b/src/Connection.cpp @@ -143,6 +143,11 @@ ISdBus& Connection::getSdBusInterface() } void Connection::addObjectManager(const std::string& objectPath) +{ + Connection::addObjectManager(objectPath, floating_slot); +} + +void Connection::addObjectManager(const std::string& objectPath, floating_slot_t) { auto r = iface_->sd_bus_add_object_manager(bus_.get(), nullptr, objectPath.c_str()); diff --git a/src/Connection.h b/src/Connection.h index 549aea4..5d71def 100644 --- a/src/Connection.h +++ b/src/Connection.h @@ -68,6 +68,7 @@ namespace sdbus::internal { bool processPendingRequest() override; void addObjectManager(const std::string& objectPath) override; + void addObjectManager(const std::string& objectPath, floating_slot_t) override; Slot addObjectManager(const std::string& objectPath, request_slot_t) override; void setMethodCallTimeout(uint64_t timeout) override; diff --git a/src/Message.cpp b/src/Message.cpp index c5bd2e3..cccae11 100644 --- a/src/Message.cpp +++ b/src/Message.cpp @@ -794,6 +794,11 @@ MethodReply MethodCall::sendWithNoReply() const } void MethodCall::send(void* callback, void* userData, uint64_t timeout, dont_request_slot_t) const +{ + MethodCall::send(callback, userData, timeout, floating_slot); +} + +void MethodCall::send(void* callback, void* userData, uint64_t timeout, floating_slot_t) const { auto r = sdbus_->sd_bus_call_async(nullptr, nullptr, (sd_bus_message*)msg_, (sd_bus_message_handler_t)callback, userData, timeout); SDBUS_THROW_ERROR_IF(r < 0, "Failed to call method", -r); diff --git a/src/Proxy.cpp b/src/Proxy.cpp index e547d99..7fc5a80 100644 --- a/src/Proxy.cpp +++ b/src/Proxy.cpp @@ -127,7 +127,7 @@ MethodReply Proxy::sendMethodCallMessageAndWaitForReply(const MethodCall& messag auto callback = (void*)&Proxy::sdbus_async_reply_handler; AsyncCalls::CallData callData{*this, std::move(asyncReplyCallback), {}}; - message.send(callback, &callData, timeout, dont_request_slot); + message.send(callback, &callData, timeout, floating_slot); return syncCallReplyData.waitForMethodReply(); }