EntityManager: Extract pruneConfiguration()

Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
Change-Id: If2ce19c6353cdf49212fc586ab6354f8b8e608ad
diff --git a/src/EntityManager.cpp b/src/EntityManager.cpp
index 173f4dc..e8113c2 100644
--- a/src/EntityManager.cpp
+++ b/src/EntityManager.cpp
@@ -918,6 +918,32 @@
     return inventory[device["Name"].get<std::string>()];
 }
 
+static void pruneConfiguration(nlohmann::json& systemConfiguration,
+                               sdbusplus::asio::object_server& objServer,
+                               bool powerOff, const std::string& name,
+                               const nlohmann::json& device)
+{
+    if (powerOff && deviceRequiresPowerOn(device))
+    {
+        // power not on yet, don't know if it's there or not
+        return;
+    }
+
+    auto& ifaces = getDeviceInterfaces(device);
+    for (auto& iface : ifaces)
+    {
+        auto sharedPtr = iface.lock();
+        if (!!sharedPtr)
+        {
+            objServer.remove_interface(sharedPtr);
+        }
+    }
+
+    ifaces.clear();
+    systemConfiguration.erase(name);
+    logDeviceRemoved(device);
+}
+
 // main properties changed entry
 void propertiesChangedCallback(nlohmann::json& systemConfiguration,
                                sdbusplus::asio::object_server& objServer)
@@ -974,23 +1000,8 @@
                 for (const auto& [name, device] :
                      missingConfigurations->items())
                 {
-                    if (powerOff && deviceRequiresPowerOn(device))
-                    {
-                        // power not on yet, don't know if it's there or not
-                        continue;
-                    }
-                    auto& ifaces = getDeviceInterfaces(device);
-                    for (auto& iface : ifaces)
-                    {
-                        auto sharedPtr = iface.lock();
-                        if (!!sharedPtr)
-                        {
-                            objServer.remove_interface(sharedPtr);
-                        }
-                    }
-                    ifaces.clear();
-                    systemConfiguration.erase(name);
-                    logDeviceRemoved(device);
+                    pruneConfiguration(systemConfiguration, objServer, powerOff,
+                                       name, device);
                 }
 
                 nlohmann::json newConfiguration = systemConfiguration;