entity-manager: handleCurrentConfigurationJson

Extract handleCurrentConfigurationJson from main function.

This helps to avoid mixing abstraction layers. The main function handles
the overall control flow and the helper function handles loading the
stored configuration.

Tested: Code was not changed, only extracted the function.

Change-Id: I6b82048e98acc29ac7971c6b7226aa2ebee5ffe4
Signed-off-by: Alexander Hansen <alexander.hansen@9elements.com>
diff --git a/src/entity_manager/entity_manager.cpp b/src/entity_manager/entity_manager.cpp
index 9a69a25..6a003f5 100644
--- a/src/entity_manager/entity_manager.cpp
+++ b/src/entity_manager/entity_manager.cpp
@@ -584,6 +584,48 @@
     return !intersect.empty();
 }
 
+void EntityManager::handleCurrentConfigurationJson()
+{
+    if (em_utils::fwVersionIsSame())
+    {
+        if (std::filesystem::is_regular_file(
+                configuration::currentConfiguration))
+        {
+            // this file could just be deleted, but it's nice for debug
+            std::filesystem::create_directory(tempConfigDir);
+            std::filesystem::remove(lastConfiguration);
+            std::filesystem::copy(configuration::currentConfiguration,
+                                  lastConfiguration);
+            std::filesystem::remove(configuration::currentConfiguration);
+
+            std::ifstream jsonStream(lastConfiguration);
+            if (jsonStream.good())
+            {
+                auto data = nlohmann::json::parse(jsonStream, nullptr, false);
+                if (data.is_discarded())
+                {
+                    std::cerr
+                        << "syntax error in " << lastConfiguration << "\n";
+                }
+                else
+                {
+                    lastJson = std::move(data);
+                }
+            }
+            else
+            {
+                std::cerr << "unable to open " << lastConfiguration << "\n";
+            }
+        }
+    }
+    else
+    {
+        // not an error, just logging at this level to make it in the journal
+        std::cerr << "Clearing previous configuration\n";
+        std::filesystem::remove(configuration::currentConfiguration);
+    }
+}
+
 void EntityManager::registerCallback(const std::string& path)
 {
     static boost::container::flat_map<std::string, sdbusplus::bus::match_t>
@@ -664,44 +706,7 @@
 
     boost::asio::post(io, [&]() { em.propertiesChangedCallback(); });
 
-    if (em_utils::fwVersionIsSame())
-    {
-        if (std::filesystem::is_regular_file(
-                configuration::currentConfiguration))
-        {
-            // this file could just be deleted, but it's nice for debug
-            std::filesystem::create_directory(tempConfigDir);
-            std::filesystem::remove(lastConfiguration);
-            std::filesystem::copy(configuration::currentConfiguration,
-                                  lastConfiguration);
-            std::filesystem::remove(configuration::currentConfiguration);
-
-            std::ifstream jsonStream(lastConfiguration);
-            if (jsonStream.good())
-            {
-                auto data = nlohmann::json::parse(jsonStream, nullptr, false);
-                if (data.is_discarded())
-                {
-                    std::cerr
-                        << "syntax error in " << lastConfiguration << "\n";
-                }
-                else
-                {
-                    em.lastJson = std::move(data);
-                }
-            }
-            else
-            {
-                std::cerr << "unable to open " << lastConfiguration << "\n";
-            }
-        }
-    }
-    else
-    {
-        // not an error, just logging at this level to make it in the journal
-        std::cerr << "Clearing previous configuration\n";
-        std::filesystem::remove(configuration::currentConfiguration);
-    }
+    em.handleCurrentConfigurationJson();
 
     // some boards only show up after power is on, we want to not say they are
     // removed until the same state happens
diff --git a/src/entity_manager/entity_manager.hpp b/src/entity_manager/entity_manager.hpp
index 97ef441..8490d1c 100644
--- a/src/entity_manager/entity_manager.hpp
+++ b/src/entity_manager/entity_manager.hpp
@@ -52,6 +52,8 @@
                             const nlohmann::json& device);
 
     void initFilters(const std::set<std::string>& probeInterfaces);
+
+    void handleCurrentConfigurationJson();
 };
 
 inline void logDeviceAdded(const nlohmann::json& record)