Add Configuration class
Adding this class improves maintainability by increasing separation
of concern. One major improvement is the removal of reoccuring calls to
loadConfigurations. These calls took a long time. Now it's only called
once.
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_VOLT_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_VOLT_V
|- /xyz/openbmc_project/inventory/system/board/Yosemite_4_Management_Board/MGNT_ADC_P5V_USB_VOLT_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_DOME_SLOT_PRESENT_PERCENTAGE
`- /xyz/openbmc_project/inventory/system/board/Yosemite_4_Management_Board/Zone_1
```
Change-Id: I5684a03232012e14d97edcf4ea5ed1aed4d50c8d
Signed-off-by: Christopher Meis <christopher.meis@9elements.com>
diff --git a/src/entity_manager/configuration.cpp b/src/entity_manager/configuration.cpp
index 137f4e3..9463133 100644
--- a/src/entity_manager/configuration.cpp
+++ b/src/entity_manager/configuration.cpp
@@ -13,28 +13,16 @@
#include <filesystem>
#include <fstream>
#include <iostream>
-#include <list>
#include <string>
#include <vector>
-namespace configuration
+Configuration::Configuration()
{
-// writes output files to persist data
-bool writeJsonFiles(const nlohmann::json& systemConfiguration)
-{
- std::filesystem::create_directory(configurationOutDir);
- std::ofstream output(currentConfiguration);
- if (!output.good())
- {
- return false;
- }
- output << systemConfiguration.dump(4);
- output.close();
- return true;
+ loadConfigurations();
+ filterProbeInterfaces();
}
-// reads json files out of the filesystem
-bool loadConfigurations(std::list<nlohmann::json>& configurations)
+void Configuration::loadConfigurations()
{
const auto start = std::chrono::steady_clock::now();
@@ -47,7 +35,7 @@
{
std::cerr << "Unable to find any configuration files in "
<< configurationDirectory << "\n";
- return false;
+ return;
}
std::ifstream schemaStream(
@@ -57,7 +45,7 @@
std::cerr
<< "Cannot open schema file, cannot validate JSON, exiting\n\n";
std::exit(EXIT_FAILURE);
- return false;
+ return;
}
nlohmann::json schema =
nlohmann::json::parse(schemaStream, nullptr, false, true);
@@ -66,7 +54,7 @@
std::cerr
<< "Illegal schema file detected, cannot validate JSON, exiting\n";
std::exit(EXIT_FAILURE);
- return false;
+ return;
}
for (auto& jsonPath : jsonPaths)
@@ -109,8 +97,6 @@
lg2::debug("Finished loading json configuration in {MILLIS}ms", "MILLIS",
duration);
-
- return true;
}
// Iterate over new configuration and erase items from old configuration.
@@ -144,15 +130,8 @@
}
// Extract the D-Bus interfaces to probe from the JSON config files.
-std::set<std::string> getProbeInterfaces()
+void Configuration::filterProbeInterfaces()
{
- std::set<std::string> interfaces;
- std::list<nlohmann::json> configurations;
- if (!configuration::loadConfigurations(configurations))
- {
- return interfaces;
- }
-
for (auto it = configurations.begin(); it != configurations.end();)
{
auto findProbe = it->find("Probe");
@@ -193,13 +172,22 @@
if (findStart != std::string::npos)
{
std::string interface = probe->substr(0, findStart);
- interfaces.emplace(interface);
+ probeInterfaces.emplace(interface);
}
}
it++;
}
-
- return interfaces;
}
-} // namespace configuration
+bool writeJsonFiles(const nlohmann::json& systemConfiguration)
+{
+ std::filesystem::create_directory(configurationOutDir);
+ std::ofstream output(currentConfiguration);
+ if (!output.good())
+ {
+ return false;
+ }
+ output << systemConfiguration.dump(4);
+ output.close();
+ return true;
+}