Fix behavior of const_ properties
In c9eb7e3bdc5e4ff59f38c0184d17ce3a02e680d2, a regression was introduced
that would prevent the registration of properties using the
sdbusplus::vtable::property_::const_ flag, which defines a parameter as
not being modifiable. Unfortunately, sd_bus has a check to determine
that if the non-modifiable flag was set, it would ensure that the
SD_BUS_PROPERTY method was being used without a setter. Even if the
setter is passed in as nullptr, sd-bus still throws an error unless the
correct overload is used.
This commit makes two adjustments. First, rather than directing
sdbsplus::asio::object_server::property_r() to a nop method, it sets the
method to nullptr. Then at vtable registration time, that function
objects filledness is used to determine which overload of property_o
should be called.
There is one usage of const_ within the codebase, and it is within the
telemetry daemon.
Tested: Telemetry daemon now launches its DBus objects without issue in
qemu, the environment where this issue was found.
Change-Id: I13944695ccd50371fe266048538bc5cceeaf18fd
Signed-off-by: Ed Tanous <edtanous@google.com>
diff --git a/include/sdbusplus/asio/object_server.hpp b/include/sdbusplus/asio/object_server.hpp
index 70237ce..d02a4fd 100644
--- a/include/sdbusplus/asio/object_server.hpp
+++ b/include/sdbusplus/asio/object_server.hpp
@@ -409,8 +409,7 @@
name,
callback_get_instance<PropertyType, CallbackTypeGet>(
propertyPtr, std::move(getFunction)),
- callback_set_message_instance<PropertyType>(
- propertyPtr, details::nop_set_value<PropertyType>),
+ nullptr,
callback_set_value_instance<PropertyType>(
propertyPtr, details::nop_set_value<PropertyType>),
type.data(), flags);
@@ -735,9 +734,18 @@
{
pointers.push_back(&element);
size_t pointer_off = (pointers.size() - 1) * sizeof(void*);
- vtable_.emplace_back(vtable::property_o(
- element.name_.c_str(), element.signature_, get_handler,
- set_handler, pointer_off, element.flags_));
+ if (element.on_set_message_)
+ {
+ vtable_.emplace_back(vtable::property_o(
+ element.name_.c_str(), element.signature_, get_handler,
+ set_handler, pointer_off, element.flags_));
+ }
+ else
+ {
+ vtable_.emplace_back(vtable::property_o(
+ element.name_.c_str(), element.signature_, get_handler,
+ pointer_off, element.flags_));
+ }
}
method_callbacks_.shrink_to_fit();