entity-manager: extract function addObjectJson
extract function `addObjectJson` from `addObject` function.
This separates the data conversion from core `AddObject` logic which
operates on json (as usual with EM internals).
Tested: on Tyan S8030:
Adding a dummy record:
```
root@s8030-bmc-30303035c0c1:~# busctl call xyz.openbmc_project.EntityManager /xyz/openbmc_project/inventory/system/board/Tyan_S8030_Baseboard xyz.openbmc_project.AddObject AddObject a{sv} 3 Name s DummyRecord Type s DummyType PollRate u 1000
root@s8030-bmc-30303035c0c1:~# busctl introspect xyz.openbmc_project.EntityManager /xyz/openbmc_project/inventory/system/board/Tyan_S8030_Baseboard/DummyRecord
NAME TYPE SIGNATURE RESULT/VALUE FLAGS
...
xyz.openbmc_project.Configuration.DummyType interface - - -
.Delete method - - -
.Name property s "DummyRecord" emits-change
.PollRate property d 1000 emits-change
.Type property s "DummyType" emits-change
```
New record is added without issues.
Change-Id: I62e2276ff517d0369f5644fa21dae162c44590db
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 c8f55a6..0610812 100644
--- a/src/entity_manager/dbus_interface.cpp
+++ b/src/entity_manager/dbus_interface.cpp
@@ -291,6 +291,17 @@
item.second);
}
+ addObjectJson(newData, systemConfiguration, jsonPointerPath, path, board);
+}
+
+void EMDBusInterface::addObjectJson(
+ nlohmann::json& newData, nlohmann::json& systemConfiguration,
+ const std::string& jsonPointerPath, const std::string& path,
+ const std::string& board)
+{
+ nlohmann::json::json_pointer ptr(jsonPointerPath);
+ nlohmann::json& base = systemConfiguration[ptr];
+ auto findExposes = base.find("Exposes");
auto findName = newData.find("Name");
auto findType = newData.find("Type");
if (findName == newData.end() || findType == newData.end())
diff --git a/src/entity_manager/dbus_interface.hpp b/src/entity_manager/dbus_interface.hpp
index 3e24768..1f978bc 100644
--- a/src/entity_manager/dbus_interface.hpp
+++ b/src/entity_manager/dbus_interface.hpp
@@ -55,6 +55,12 @@
nlohmann::json& systemConfiguration, const std::string& jsonPointerPath,
const std::string& path, const std::string& board);
+ // @brief: same as 'addObject', but operates on json
+ void addObjectJson(nlohmann::json& newData,
+ nlohmann::json& systemConfiguration,
+ const std::string& jsonPointerPath,
+ const std::string& path, const std::string& board);
+
boost::asio::io_context& io;
sdbusplus::asio::object_server& objServer;