entity-manager: extract getDBusType
For read+write properties the numbers are represented as doubles.
Extract that quirk into a separate function (separation of concerns).
Tested: on Tyan s8030 board
Inventory is properly exposed and object paths appear as expected.
```
root@s8030-bmc-30303035c0c1:~# busctl tree xyz.openbmc_project.EntityManager
`- /xyz
`- /xyz/openbmc_project
|- /xyz/openbmc_project/EntityManager
`- /xyz/openbmc_project/inventory
`- /xyz/openbmc_project/inventory/system
|- /xyz/openbmc_project/inventory/system/board
| `- /xyz/openbmc_project/inventory/system/board/Tyan_S8030_Baseboard
| |- /xyz/openbmc_project/inventory/system/board/Tyan_S8030_Baseboard/CPU0_Power_Consumption
| |- /xyz/openbmc_project/inventory/system/board/Tyan_S8030_Baseboard/CPU0_Temp
| |- /xyz/openbmc_project/inventory/system/board/Tyan_S8030_Baseboard/GARBO_SENSOR
| |- /xyz/openbmc_project/inventory/system/board/Tyan_S8030_Baseboard/P0_VDD_18_RUN
| |- /xyz/openbmc_project/inventory/system/board/Tyan_S8030_Baseboard/P0_VDD_CORE_RUN
| |- /xyz/openbmc_project/inventory/system/board/Tyan_S8030_Baseboard/P0_VDD_MEM_ABCD
| |- /xyz/openbmc_project/inventory/system/board/Tyan_S8030_Baseboard/P0_VDD_MEM_EFGH
| |- /xyz/openbmc_project/inventory/system/board/Tyan_S8030_Baseboard/P0_VDD_SOC_RUN
| |- /xyz/openbmc_project/inventory/system/board/Tyan_S8030_Baseboard/VBAT_33
| |- /xyz/openbmc_project/inventory/system/board/Tyan_S8030_Baseboard/VDD_12_RUN
| |- /xyz/openbmc_project/inventory/system/board/Tyan_S8030_Baseboard/VDD_33_DUAL
| |- /xyz/openbmc_project/inventory/system/board/Tyan_S8030_Baseboard/VDD_33_RUN
| |- /xyz/openbmc_project/inventory/system/board/Tyan_S8030_Baseboard/VDD_5_DUAL
| |- /xyz/openbmc_project/inventory/system/board/Tyan_S8030_Baseboard/VDD_5_RUN
| `- /xyz/openbmc_project/inventory/system/board/Tyan_S8030_Baseboard/X550
```
DBus interfaces appear as expected
```
root@s8030-bmc-30303035c0c1:~# busctl introspect xyz.openbmc_project.EntityManager /xyz/openbmc_project/inventory/system/board/Tyan_S8030_Baseboard/VBAT_33
NAME TYPE SIGNATURE RESULT/VALUE FLAGS
org.freedesktop.DBus.Introspectable interface - - -
.Introspect method - s -
org.freedesktop.DBus.Peer interface - - -
.GetMachineId method - s -
.Ping method - - -
org.freedesktop.DBus.Properties interface - - -
.Get method ss v -
.GetAll method s a{sv} -
.Set method ssv - -
.PropertiesChanged signal sa{sv}as - -
xyz.openbmc_project.Configuration.ADC interface - - -
.Index property t 10 emits-change
.Name property s "VBAT_33" emits-change
.PowerState property s "Always" emits-change
.ScaleFactor property d 0.3333 emits-change
.Type property s "ADC" emits-change
xyz.openbmc_project.Configuration.ADC.Thresholds0 interface - - -
.Delete method - - -
.Direction property s "greater than" emits-change
.Name property s "upper critical" emits-change
.Severity property d 1 emits-change
.Value property d 3.507 emits-change
xyz.openbmc_project.Configuration.ADC.Thresholds1 interface - - -
.Delete method - - -
.Direction property s "less than" emits-change
.Name property s "lower critical" emits-change
.Severity property d 1 emits-change
.Value property d 2.688 emits-change
```
Change-Id: I9e6855de4ac98a79978422d42b58a355c601d38a
Signed-off-by: Alexander Hansen <alexander.hansen@9elements.com>
Signed-off-by: Ed Tanous <etanous@nvidia.com>
diff --git a/src/entity_manager/dbus_interface.cpp b/src/entity_manager/dbus_interface.cpp
index c4bd311..3ad8874 100644
--- a/src/entity_manager/dbus_interface.cpp
+++ b/src/entity_manager/dbus_interface.cpp
@@ -122,11 +122,8 @@
});
}
-static void populateInterfacePropertyFromJson(
- nlohmann::json& systemConfiguration, const std::string& path,
- const nlohmann::json& key, const nlohmann::json& value,
- nlohmann::json::value_t type,
- std::shared_ptr<sdbusplus::asio::dbus_interface>& iface,
+static nlohmann::json::value_t getDBusType(
+ const nlohmann::json& value, nlohmann::json::value_t type,
sdbusplus::asio::PropertyPermission permission)
{
const bool array = value.type() == nlohmann::json::value_t::array;
@@ -140,20 +137,32 @@
{
if (value[0].is_number())
{
- type = nlohmann::json::value_t::number_float;
+ return nlohmann::json::value_t::number_float;
}
}
else if (value.is_number())
{
- type = nlohmann::json::value_t::number_float;
+ return nlohmann::json::value_t::number_float;
}
}
- switch (type)
+ return type;
+}
+
+static void populateInterfacePropertyFromJson(
+ nlohmann::json& systemConfiguration, const std::string& path,
+ const nlohmann::json& key, const nlohmann::json& value,
+ nlohmann::json::value_t type,
+ std::shared_ptr<sdbusplus::asio::dbus_interface>& iface,
+ sdbusplus::asio::PropertyPermission permission)
+{
+ const auto modifiedType = getDBusType(value, type, permission);
+
+ switch (modifiedType)
{
case (nlohmann::json::value_t::boolean):
{
- if (array)
+ if (value.is_array())
{
// todo: array of bool isn't detected correctly by
// sdbusplus, change it to numbers