entity-manager: simplify addValueToDBus usage
addValueToDBus is used in populateInterfacePropertyFromJson but the
caller still has an instance of the internal implementation to account
for the quirk with how arrays of bools are exposed on DBus.
Since removing that quirk is not easily possible, add a second template
parameter in 'addValueToDBus' to capture the quirk.
Tested: Code is only moved here. Property and Array still exposed as
before.
Change-Id: I500c778841ce5d90571032da4c3b81495ed5a615
Signed-off-by: Alexander Hansen <alexander.hansen@9elements.com>
diff --git a/src/entity_manager/dbus_interface.cpp b/src/entity_manager/dbus_interface.cpp
index 3ad8874..45c90fa 100644
--- a/src/entity_manager/dbus_interface.cpp
+++ b/src/entity_manager/dbus_interface.cpp
@@ -162,19 +162,10 @@
{
case (nlohmann::json::value_t::boolean):
{
- if (value.is_array())
- {
- // todo: array of bool isn't detected correctly by
- // sdbusplus, change it to numbers
- addArrayToDbus<uint64_t>(key, value, iface.get(), permission,
- systemConfiguration, path);
- }
-
- else
- {
- addProperty(key, value.get<bool>(), iface.get(),
- systemConfiguration, path, permission);
- }
+ // todo: array of bool isn't detected correctly by
+ // sdbusplus, change it to numbers
+ addValueToDBus<uint64_t, bool>(key, value, *iface, permission,
+ systemConfiguration, path);
break;
}
case (nlohmann::json::value_t::number_integer):
diff --git a/src/entity_manager/dbus_interface.hpp b/src/entity_manager/dbus_interface.hpp
index 5e6609d..60527e3 100644
--- a/src/entity_manager/dbus_interface.hpp
+++ b/src/entity_manager/dbus_interface.hpp
@@ -99,7 +99,7 @@
});
}
-template <typename PropertyType>
+template <typename PropertyType, typename SinglePropertyType = PropertyType>
void addValueToDBus(const std::string& key, const nlohmann::json& value,
sdbusplus::asio::dbus_interface& iface,
sdbusplus::asio::PropertyPermission permission,
@@ -113,8 +113,9 @@
}
else
{
- addProperty(key, value.get<PropertyType>(), &iface, systemConfiguration,
- path, sdbusplus::asio::PropertyPermission::readOnly);
+ addProperty(key, value.get<SinglePropertyType>(), &iface,
+ systemConfiguration, path,
+ sdbusplus::asio::PropertyPermission::readOnly);
}
}