Introduce EntityManager class
Reworking Entity-Manager to use OOP, which will help in further
refactoring. It increases maintainability and supports the 'separation
of concern' concept.
Tested:
QEMU/yosemite4 with probe statement set to TRUE.
```
root@yosemite4:~# journalctl | grep entity-manager
Dec 19 13:26:21 yosemite4 entity-manager[502]: Clearing previous configuration
Dec 19 13:26:25 yosemite4 entity-manager[502]: Inventory Added: Yosemite 4 Management Board
root@yosemite4:~# 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/Yosemite_4_Management_Board
|- /xyz/openbmc_project/inventory/system/board/Yosemite_4_Management_Board/All_Fan
|- /xyz/openbmc_project/inventory/system/board/Yosemite_4_Management_Board/MGNT_ADC_P0V6_VOLT_
V
|- /xyz/openbmc_project/inventory/system/board/Yosemite_4_Management_Board/MGNT_ADC_P12V_VOLT_
V
|- /xyz/openbmc_project/inventory/system/board/Yosemite_4_Management_Board/MGNT_ADC_P1V0_VOLT_
V
|- /xyz/openbmc_project/inventory/system/board/Yosemite_4_Management_Board/MGNT_ADC_P1V2_VOLT_
V
|- /xyz/openbmc_project/inventory/system/board/Yosemite_4_Management_Board/MGNT_ADC_P1V8_VOLT_
V
|- /xyz/openbmc_project/inventory/system/board/Yosemite_4_Management_Board/MGNT_ADC_P2V5_VOLT_
V
|- /xyz/openbmc_project/inventory/system/board/Yosemite_4_Management_Board/MGNT_ADC_P3V3_RGM_V
OLT_V
|- /xyz/openbmc_project/inventory/system/board/Yosemite_4_Management_Board/MGNT_ADC_P3V3_VOLT_
V
|- /xyz/openbmc_project/inventory/system/board/Yosemite_4_Management_Board/MGNT_ADC_P3V_BAT_VO
LT_V
|- /xyz/openbmc_project/inventory/system/board/Yosemite_4_Management_Board/MGNT_ADC_P5V_USB_VO
LT_V
|- /xyz/openbmc_project/inventory/system/board/Yosemite_4_Management_Board/MGNT_ADC_P5V_VOLT_V
|- /xyz/openbmc_project/inventory/system/board/Yosemite_4_Management_Board/MGNT_TEMP_C
|- /xyz/openbmc_project/inventory/system/board/Yosemite_4_Management_Board/PID_NIC_TEMP
|- /xyz/openbmc_project/inventory/system/board/Yosemite_4_Management_Board/Stepwise_MGNT_TEMP
|- /xyz/openbmc_project/inventory/system/board/Yosemite_4_Management_Board/Stepwise_NIC_TEMP
|- /xyz/openbmc_project/inventory/system/board/Yosemite_4_Management_Board/Stepwise_SENTINEL_D
OME_SLOT_PRESENT_PERCENTAGE
`- /xyz/openbmc_project/inventory/system/board/Yosemite_4_Management_Board/Zone_1
```
Creates the same result as previous commit on qemu/yosemite4 with
adapted config set to TRUE.
Change-Id: I0829e073bedf24cb127ad247827e169894f4e962
Signed-off-by: Christopher Meis <christopher.meis@9elements.com>
diff --git a/src/entity_manager/perform_scan.cpp b/src/entity_manager/perform_scan.cpp
index a31e7a1..04d3c67 100644
--- a/src/entity_manager/perform_scan.cpp
+++ b/src/entity_manager/perform_scan.cpp
@@ -28,15 +28,6 @@
#include <charconv>
#include <iostream>
-/* Hacks from splitting entity_manager.cpp */
-// NOLINTBEGIN(cppcoreguidelines-avoid-non-const-global-variables)
-extern std::shared_ptr<sdbusplus::asio::connection> systemBus;
-extern nlohmann::json lastJson;
-extern void propertiesChangedCallback(
- nlohmann::json& systemConfiguration,
- sdbusplus::asio::object_server& objServer);
-// NOLINTEND(cppcoreguidelines-avoid-non-const-global-variables)
-
using GetSubTreeType = std::vector<
std::pair<std::string,
std::vector<std::pair<std::string, std::vector<std::string>>>>>;
@@ -62,7 +53,7 @@
return;
}
- systemBus->async_method_call(
+ scan->_em.systemBus->async_method_call(
[instance, scan, probeVector,
retries](boost::system::error_code& errc, const DBusInterface& resp) {
if (errc)
@@ -87,31 +78,6 @@
"GetAll", instance.interface);
}
-static void registerCallback(nlohmann::json& systemConfiguration,
- sdbusplus::asio::object_server& objServer,
- const std::string& path)
-{
- static boost::container::flat_map<std::string, sdbusplus::bus::match_t>
- dbusMatches;
-
- auto find = dbusMatches.find(path);
- if (find != dbusMatches.end())
- {
- return;
- }
-
- std::function<void(sdbusplus::message_t & message)> eventHandler =
- [&](sdbusplus::message_t&) {
- propertiesChangedCallback(systemConfiguration, objServer);
- };
-
- sdbusplus::bus::match_t match(
- static_cast<sdbusplus::bus_t&>(*systemBus),
- "type='signal',member='PropertiesChanged',path='" + path + "'",
- eventHandler);
- dbusMatches.emplace(path, std::move(match));
-}
-
static void processDbusObjects(
std::vector<std::shared_ptr<probe::PerformProbe>>& probeVector,
const std::shared_ptr<scan::PerformScan>& scan,
@@ -120,7 +86,7 @@
for (const auto& [path, object] : interfaceSubtree)
{
// Get a PropertiesChanged callback for all interfaces on this path.
- registerCallback(scan->_systemConfiguration, scan->objServer, path);
+ scan->_em.registerCallback(path);
for (const auto& [busname, ifaces] : object)
{
@@ -160,7 +126,7 @@
}
// find all connections in the mapper that expose a specific type
- systemBus->async_method_call(
+ scan->_em.systemBus->async_method_call(
[interfaces, probeVector{std::move(probeVector)}, scan,
retries](boost::system::error_code& ec,
const GetSubTreeType& interfaceSubtree) mutable {
@@ -225,15 +191,12 @@
return std::to_string(std::hash<std::string>{}(probeName + device.dump()));
}
-scan::PerformScan::PerformScan(nlohmann::json& systemConfiguration,
+scan::PerformScan::PerformScan(EntityManager& em,
nlohmann::json& missingConfigurations,
std::list<nlohmann::json>& configurations,
- sdbusplus::asio::object_server& objServerIn,
std::function<void()>&& callback) :
- _systemConfiguration(systemConfiguration),
- _missingConfigurations(missingConfigurations),
- _configurations(configurations), objServer(objServerIn),
- _callback(std::move(callback))
+ _em(em), _missingConfigurations(missingConfigurations),
+ _configurations(configurations), _callback(std::move(callback))
{}
static void pruneRecordExposes(nlohmann::json& record)
@@ -471,11 +434,11 @@
{
std::string recordName = getRecordName(itr->interface, probeName);
- auto record = _systemConfiguration.find(recordName);
- if (record == _systemConfiguration.end())
+ auto record = _em.systemConfiguration.find(recordName);
+ if (record == _em.systemConfiguration.end())
{
- record = lastJson.find(recordName);
- if (record == lastJson.end())
+ record = _em.lastJson.find(recordName);
+ if (record == _em.lastJson.end())
{
itr++;
continue;
@@ -483,7 +446,7 @@
pruneRecordExposes(*record);
- _systemConfiguration[recordName] = *record;
+ _em.systemConfiguration[recordName] = *record;
}
_missingConfigurations.erase(recordName);
@@ -542,7 +505,7 @@
// insert into configuration temporarily to be able to
// reference ourselves
- _systemConfiguration[recordName] = record;
+ _em.systemConfiguration[recordName] = record;
auto findExpose = record.find("Exposes");
if (findExpose == record.end())
@@ -558,13 +521,13 @@
em_utils::templateCharReplace(keyPair, dbusObject,
foundDeviceIdx, replaceStr);
- applyExposeActions(_systemConfiguration, recordName, expose,
+ applyExposeActions(_em.systemConfiguration, recordName, expose,
keyPair);
}
}
// overwrite ourselves with cleaned up version
- _systemConfiguration[recordName] = record;
+ _em.systemConfiguration[recordName] = record;
_missingConfigurations.erase(recordName);
}
}
@@ -653,8 +616,7 @@
if (_passed)
{
auto nextScan = std::make_shared<PerformScan>(
- _systemConfiguration, _missingConfigurations, _configurations,
- objServer, std::move(_callback));
+ _em, _missingConfigurations, _configurations, std::move(_callback));
nextScan->passedProbes = std::move(passedProbes);
nextScan->dbusProbeObjects = std::move(dbusProbeObjects);
nextScan->run();