Add new_signal and extend set_property methods to dbus_interface
new_signal exports the same member function of sdbusplus::server::interface
extend set_property to be able to return true only when the property value
is changed. default behavior remains unchanged - returns true when property
is updated successfully, value may be same or changed.
With these two functions, dbus_interface can broadcast new signal when
a property is changed. This allows a customized message to be sent
when a property changes.
Tested:
Build test code to use the two new method to create and send new_signal when
a property is changed.
Signed-off-by: Zhikui Ren <zhikui.ren@intel.com>
Change-Id: I1815885bc77aad2c526b402f1386d4914479e738
diff --git a/include/sdbusplus/asio/object_server.hpp b/include/sdbusplus/asio/object_server.hpp
index 2c65ace..1e344b1 100644
--- a/include/sdbusplus/asio/object_server.hpp
+++ b/include/sdbusplus/asio/object_server.hpp
@@ -494,7 +494,7 @@
return true;
}
- template <typename PropertyType>
+ template <typename PropertyType, bool changesOnly = false>
bool set_property(const std::string& name, const PropertyType& value)
{
if (!initialized_)
@@ -511,8 +511,12 @@
if (status != SetPropertyReturnValue::sameValueUpdated)
{
signal_property(name);
+ return true;
}
- return true;
+ if constexpr (!changesOnly)
+ {
+ return true;
+ }
}
}
return false;
@@ -720,6 +724,19 @@
return sd_bus_error_set_const(error, SD_BUS_ERROR_INVALID_ARGS, NULL);
}
+ /** @brief Create a new signal message.
+ *
+ * @param[in] member - The signal name to create.
+ */
+ auto new_signal(const char* member)
+ {
+ if (!initialized_)
+ {
+ return message::message(nullptr);
+ }
+ return interface_->new_signal(member);
+ }
+
bool initialize(const bool skipPropertyChangedSignal = false)
{
// can only register once