refactor: add nodiscard attribute for more functions

This commit is contained in:
Stanislav Angelovič
2024-01-10 15:05:09 +01:00
parent 4b6fa20491
commit cda14c9702
9 changed files with 45 additions and 45 deletions

View File

@ -55,17 +55,17 @@ namespace sdbus {
{ {
} }
const std::string& getName() const [[nodiscard]] const std::string& getName() const
{ {
return name_; return name_;
} }
const std::string& getMessage() const [[nodiscard]] const std::string& getMessage() const
{ {
return message_; return message_;
} }
bool isValid() const [[nodiscard]] bool isValid() const
{ {
return !getName().empty(); return !getName().empty();
} }

View File

@ -74,21 +74,21 @@ namespace sdbus {
flags_.set(flag, value); flags_.set(flag, value);
} }
bool test(GeneralFlags flag) const [[nodiscard]] bool test(GeneralFlags flag) const
{ {
return flags_.test(flag); return flags_.test(flag);
} }
bool test(PropertyUpdateBehaviorFlags flag) const [[nodiscard]] bool test(PropertyUpdateBehaviorFlags flag) const
{ {
return flags_.test(flag); return flags_.test(flag);
} }
uint64_t toSdBusInterfaceFlags() const; [[nodiscard]] uint64_t toSdBusInterfaceFlags() const;
uint64_t toSdBusMethodFlags() const; [[nodiscard]] uint64_t toSdBusMethodFlags() const;
uint64_t toSdBusSignalFlags() const; [[nodiscard]] uint64_t toSdBusSignalFlags() const;
uint64_t toSdBusPropertyFlags() const; [[nodiscard]] uint64_t toSdBusPropertyFlags() const;
uint64_t toSdBusWritablePropertyFlags() const; [[nodiscard]] uint64_t toSdBusWritablePropertyFlags() const;
private: private:
std::bitset<FLAG_COUNT> flags_; std::bitset<FLAG_COUNT> flags_;

View File

@ -381,7 +381,7 @@ namespace sdbus {
* *
* @deprecated This function has been replaced by getEventLoopPollData() * @deprecated This function has been replaced by getEventLoopPollData()
*/ */
[[deprecated("This function has been replaced by getEventLoopPollData()")]] PollData getProcessLoopPollData() const; [[nodiscard]] [[deprecated("This function has been replaced by getEventLoopPollData()")]] PollData getProcessLoopPollData() const;
/*! /*!
* @struct PollData * @struct PollData

View File

@ -488,7 +488,7 @@ namespace sdbus {
* Pending call in this context means a call whose results have not arrived, or * Pending call in this context means a call whose results have not arrived, or
* have arrived and are currently being processed by the callback handler. * have arrived and are currently being processed by the callback handler.
*/ */
bool isPending() const; [[nodiscard]] bool isPending() const;
private: private:
friend internal::Proxy; friend internal::Proxy;

View File

@ -256,7 +256,7 @@ namespace sdbus {
close(); close();
} }
int get() const [[nodiscard]] int get() const
{ {
return fd_; return fd_;
} }
@ -276,7 +276,7 @@ namespace sdbus {
return std::exchange(fd_, -1); return std::exchange(fd_, -1);
} }
bool isValid() const [[nodiscard]] bool isValid() const
{ {
return fd_ >= 0; return fd_ >= 0;
} }

View File

@ -83,11 +83,11 @@ namespace sdbus::internal {
void requestName(const std::string& name) override; void requestName(const std::string& name) override;
void releaseName(const std::string& name) override; void releaseName(const std::string& name) override;
std::string getUniqueName() const override; [[nodiscard]] std::string getUniqueName() const override;
void enterEventLoop() override; void enterEventLoop() override;
void enterEventLoopAsync() override; void enterEventLoopAsync() override;
void leaveEventLoop() override; void leaveEventLoop() override;
PollData getEventLoopPollData() const override; [[nodiscard]] PollData getEventLoopPollData() const override;
bool processPendingEvent() override; bool processPendingEvent() override;
Message getCurrentlyProcessedMessage() const override; Message getCurrentlyProcessedMessage() const override;
@ -96,7 +96,7 @@ namespace sdbus::internal {
Slot addObjectManager(const std::string& objectPath, return_slot_t) override; Slot addObjectManager(const std::string& objectPath, return_slot_t) override;
void setMethodCallTimeout(uint64_t timeout) override; void setMethodCallTimeout(uint64_t timeout) override;
uint64_t getMethodCallTimeout() const override; [[nodiscard]] uint64_t getMethodCallTimeout() const override;
[[nodiscard]] Slot addMatch(const std::string& match, message_handler callback) override; [[nodiscard]] Slot addMatch(const std::string& match, message_handler callback) override;
void addMatch(const std::string& match, message_handler callback, floating_slot_t) override; void addMatch(const std::string& match, message_handler callback, floating_slot_t) override;
@ -107,22 +107,22 @@ namespace sdbus::internal {
void detachSdEventLoop() override; void detachSdEventLoop() override;
sd_event *getSdEventLoop() override; sd_event *getSdEventLoop() override;
const ISdBus& getSdBusInterface() const override; [[nodiscard]] const ISdBus& getSdBusInterface() const override;
ISdBus& getSdBusInterface() override; [[nodiscard]] ISdBus& getSdBusInterface() override;
Slot addObjectVTable( const std::string& objectPath Slot addObjectVTable( const std::string& objectPath
, const std::string& interfaceName , const std::string& interfaceName
, const sd_bus_vtable* vtable , const sd_bus_vtable* vtable
, void* userData ) override; , void* userData ) override;
PlainMessage createPlainMessage() const override; [[nodiscard]] PlainMessage createPlainMessage() const override;
MethodCall createMethodCall( const std::string& destination [[nodiscard]] MethodCall createMethodCall( const std::string& destination
, const std::string& objectPath , const std::string& objectPath
, const std::string& interfaceName , const std::string& interfaceName
, const std::string& methodName ) const override; , const std::string& methodName ) const override;
Signal createSignal( const std::string& objectPath [[nodiscard]] Signal createSignal( const std::string& objectPath
, const std::string& interfaceName , const std::string& interfaceName
, const std::string& signalName ) const override; , const std::string& signalName ) const override;
MethodReply callMethod(const MethodCall& message, uint64_t timeout) override; MethodReply callMethod(const MethodCall& message, uint64_t timeout) override;
void callMethod(const MethodCall& message, void* callback, void* userData, uint64_t timeout, floating_slot_t) override; void callMethod(const MethodCall& message, void* callback, void* userData, uint64_t timeout, floating_slot_t) override;
@ -155,7 +155,7 @@ namespace sdbus::internal {
void finishHandshake(sd_bus* bus); void finishHandshake(sd_bus* bus);
bool waitForNextEvent(); bool waitForNextEvent();
bool arePendingMessagesInReadQueue() const; [[nodiscard]] bool arePendingMessagesInReadQueue() const;
void notifyEventLoopToExit(); void notifyEventLoopToExit();
void notifyEventLoopToWakeUpFromPoll(); void notifyEventLoopToWakeUpFromPoll();

View File

@ -56,22 +56,22 @@ namespace sdbus::internal {
public: public:
~IConnection() override = default; ~IConnection() override = default;
virtual const ISdBus& getSdBusInterface() const = 0; [[nodiscard]] virtual const ISdBus& getSdBusInterface() const = 0;
virtual ISdBus& getSdBusInterface() = 0; [[nodiscard]] virtual ISdBus& getSdBusInterface() = 0;
[[nodiscard]] virtual Slot addObjectVTable( const std::string& objectPath [[nodiscard]] virtual Slot addObjectVTable( const std::string& objectPath
, const std::string& interfaceName , const std::string& interfaceName
, const sd_bus_vtable* vtable , const sd_bus_vtable* vtable
, void* userData ) = 0; , void* userData ) = 0;
virtual PlainMessage createPlainMessage() const = 0; [[nodiscard]] virtual PlainMessage createPlainMessage() const = 0;
virtual MethodCall createMethodCall( const std::string& destination [[nodiscard]] virtual MethodCall createMethodCall( const std::string& destination
, const std::string& objectPath , const std::string& objectPath
, const std::string& interfaceName , const std::string& interfaceName
, const std::string& methodName ) const = 0; , const std::string& methodName ) const = 0;
virtual Signal createSignal( const std::string& objectPath [[nodiscard]] virtual Signal createSignal( const std::string& objectPath
, const std::string& interfaceName , const std::string& interfaceName
, const std::string& signalName ) const = 0; , const std::string& signalName ) const = 0;
virtual MethodReply callMethod(const MethodCall& message, uint64_t timeout) = 0; 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 void callMethod(const MethodCall& message, void* callback, void* userData, uint64_t timeout, floating_slot_t) = 0;

View File

@ -62,11 +62,11 @@ namespace sdbus::internal {
void addObjectManager() override; void addObjectManager() override;
void removeObjectManager() override; void removeObjectManager() override;
bool hasObjectManager() const override; [[nodiscard]] bool hasObjectManager() const override;
sdbus::IConnection& getConnection() const override; [[nodiscard]] sdbus::IConnection& getConnection() const override;
const std::string& getObjectPath() const override; [[nodiscard]] const std::string& getObjectPath() const override;
Message getCurrentlyProcessedMessage() const override; [[nodiscard]] Message getCurrentlyProcessedMessage() const override;
private: private:
// A vtable record comprising methods, signals, properties, flags. // A vtable record comprising methods, signals, properties, flags.

View File

@ -70,9 +70,9 @@ namespace sdbus::internal {
, return_slot_t ) override; , return_slot_t ) override;
void unregister() override; void unregister() override;
sdbus::IConnection& getConnection() const override; [[nodiscard]] sdbus::IConnection& getConnection() const override;
const std::string& getObjectPath() const override; [[nodiscard]] const std::string& getObjectPath() const override;
Message getCurrentlyProcessedMessage() const override; [[nodiscard]] Message getCurrentlyProcessedMessage() const override;
private: private:
static int sdbus_signal_handler(sd_bus_message *sdbusMessage, void *userData, sd_bus_error *retError); static int sdbus_signal_handler(sd_bus_message *sdbusMessage, void *userData, sd_bus_error *retError);