From b65461c4046865bced77d5ba2eefb3cc755b89a2 Mon Sep 17 00:00:00 2001 From: Stanislav Angelovic Date: Sat, 30 Dec 2023 19:57:48 +0100 Subject: [PATCH] refactor: add nodiscard attribute for some functions --- include/sdbus-c++/ConvenienceApiClasses.inl | 4 ++-- include/sdbus-c++/IConnection.h | 6 +++--- include/sdbus-c++/IObject.h | 12 ++++++------ include/sdbus-c++/IProxy.h | 10 +++++----- src/IConnection.h | 2 +- 5 files changed, 17 insertions(+), 17 deletions(-) diff --git a/include/sdbus-c++/ConvenienceApiClasses.inl b/include/sdbus-c++/ConvenienceApiClasses.inl index b1dc8c2..5ee2258 100644 --- a/include/sdbus-c++/ConvenienceApiClasses.inl +++ b/include/sdbus-c++/ConvenienceApiClasses.inl @@ -57,7 +57,7 @@ namespace sdbus { object_.addVTable(std::move(interfaceName), std::move(vtable_)); } - inline Slot VTableAdder::forInterface(std::string interfaceName, return_slot_t) + [[nodiscard]] inline Slot VTableAdder::forInterface(std::string interfaceName, return_slot_t) { return object_.addVTable(std::move(interfaceName), std::move(vtable_), return_slot); } @@ -311,7 +311,7 @@ namespace sdbus { } template - inline Slot SignalSubscriber::call(_Function&& callback, return_slot_t) + [[nodiscard]] inline Slot SignalSubscriber::call(_Function&& callback, return_slot_t) { assert(!interfaceName_.empty()); // onInterface() must be placed/called prior to this function diff --git a/include/sdbus-c++/IConnection.h b/include/sdbus-c++/IConnection.h index c3c8a0c..76e6351 100644 --- a/include/sdbus-c++/IConnection.h +++ b/include/sdbus-c++/IConnection.h @@ -82,7 +82,7 @@ namespace sdbus { * * @throws sdbus::Error in case of failure */ - virtual std::string getUniqueName() const = 0; + [[nodiscard]] virtual std::string getUniqueName() const = 0; /*! * @brief Enters I/O event loop on this bus connection @@ -225,7 +225,7 @@ namespace sdbus { * * @return Currently processed D-Bus message */ - virtual Message getCurrentlyProcessedMessage() const = 0; + [[nodiscard]] virtual Message getCurrentlyProcessedMessage() const = 0; /*! * @brief Sets general method call timeout @@ -256,7 +256,7 @@ namespace sdbus { * * @throws sdbus::Error in case of failure */ - virtual uint64_t getMethodCallTimeout() const = 0; + [[nodiscard]] virtual uint64_t getMethodCallTimeout() const = 0; /*! * @brief Adds an ObjectManager at the specified D-Bus object path diff --git a/include/sdbus-c++/IObject.h b/include/sdbus-c++/IObject.h index 187b35a..53fdda0 100644 --- a/include/sdbus-c++/IObject.h +++ b/include/sdbus-c++/IObject.h @@ -140,7 +140,7 @@ namespace sdbus { * * @throws sdbus::Error in case of failure */ - virtual Slot addVTable(std::string interfaceName, std::vector vtable, return_slot_t) = 0; + [[nodiscard]] virtual Slot addVTable(std::string interfaceName, std::vector vtable, return_slot_t) = 0; /*! * @brief A little more convenient overload of addVTable() above @@ -187,7 +187,7 @@ namespace sdbus { * * @throws sdbus::Error in case of failure */ - virtual Signal createSignal(const std::string& interfaceName, const std::string& signalName) = 0; + [[nodiscard]] virtual Signal createSignal(const std::string& interfaceName, const std::string& signalName) = 0; /*! * @brief Emits signal for this object path @@ -288,14 +288,14 @@ namespace sdbus { * @brief Tests whether ObjectManager interface is added at the path of this D-Bus object * @return True if ObjectManager interface is there, false otherwise */ - virtual bool hasObjectManager() const = 0; + [[nodiscard]] virtual bool hasObjectManager() const = 0; /*! * @brief Provides D-Bus connection used by the object * * @return Reference to the D-Bus connection */ - virtual sdbus::IConnection& getConnection() const = 0; + [[nodiscard]] virtual sdbus::IConnection& getConnection() const = 0; /*! * @brief Emits signal on D-Bus @@ -321,7 +321,7 @@ namespace sdbus { /*! * @brief Returns object path of the underlying DBus object */ - virtual const std::string& getObjectPath() const = 0; + [[nodiscard]] virtual const std::string& getObjectPath() const = 0; /*! * @brief Provides access to the currently processed D-Bus message @@ -336,7 +336,7 @@ namespace sdbus { * * @return Currently processed D-Bus message */ - virtual Message getCurrentlyProcessedMessage() const = 0; + [[nodiscard]] virtual Message getCurrentlyProcessedMessage() const = 0; }; // Out-of-line member definitions diff --git a/include/sdbus-c++/IProxy.h b/include/sdbus-c++/IProxy.h index 90a8ed0..c9312c7 100644 --- a/include/sdbus-c++/IProxy.h +++ b/include/sdbus-c++/IProxy.h @@ -80,7 +80,7 @@ namespace sdbus { * * @throws sdbus::Error in case of failure */ - virtual MethodCall createMethodCall(const std::string& interfaceName, const std::string& methodName) = 0; + [[nodiscard]] virtual MethodCall createMethodCall(const std::string& interfaceName, const std::string& methodName) = 0; /*! * @brief Calls method on the remote D-Bus object @@ -107,7 +107,7 @@ namespace sdbus { * * Note: To avoid messing with messages, use API on a higher level of abstraction defined below. * - * @throws sdbus::Error in case of failure + * @throws sdbus::Error in case of failure (also in case the remote function returned an error) */ virtual MethodReply callMethod(const MethodCall& message, uint64_t timeout = 0) = 0; @@ -426,12 +426,12 @@ namespace sdbus { * * @return Reference to the D-Bus connection */ - virtual sdbus::IConnection& getConnection() const = 0; + [[nodiscard]] virtual sdbus::IConnection& getConnection() const = 0; /*! * @brief Returns object path of the underlying DBus object */ - virtual const std::string& getObjectPath() const = 0; + [[nodiscard]] virtual const std::string& getObjectPath() const = 0; /*! * @brief Provides access to the currently processed D-Bus message @@ -446,7 +446,7 @@ namespace sdbus { * * @return Currently processed D-Bus message */ - virtual Message getCurrentlyProcessedMessage() const = 0; + [[nodiscard]] virtual Message getCurrentlyProcessedMessage() const = 0; }; /********************************************//** diff --git a/src/IConnection.h b/src/IConnection.h index 5145f3c..6c21d86 100644 --- a/src/IConnection.h +++ b/src/IConnection.h @@ -73,7 +73,7 @@ namespace sdbus::internal { virtual MethodReply callMethod(const MethodCall& message, uint64_t timeout) = 0; virtual void callMethod(const MethodCall& message, void* callback, void* userData, uint64_t timeout, floating_slot_t) = 0; - virtual Slot callMethod(const MethodCall& message, void* callback, void* userData, uint64_t timeout) = 0; + [[nodiscard]] virtual Slot callMethod(const MethodCall& message, void* callback, void* userData, uint64_t timeout) = 0; virtual void emitPropertiesChangedSignal( const std::string& objectPath , const std::string& interfaceName