unit-test: Move removeAssociationEndpoints()

Make it easier to unit test and continue reduction of main.cpp

Change-Id: I2c0eac5c301687acab14add627586170020e4fe4
Signed-off-by: Andrew Geissler <geissonator@yahoo.com>
diff --git a/src/associations.cpp b/src/associations.cpp
index 3ae7db4..9bb7a34 100644
--- a/src/associations.cpp
+++ b/src/associations.cpp
@@ -74,3 +74,40 @@
         assocOwners.erase(owners);
     }
 }
+
+void removeAssociationEndpoints(
+    sdbusplus::asio::object_server& objectServer, const std::string& assocPath,
+    const boost::container::flat_set<std::string>& endpointsToRemove,
+    AssociationInterfaces& assocInterfaces)
+{
+    auto assoc = assocInterfaces.find(assocPath);
+    if (assoc == assocInterfaces.end())
+    {
+        return;
+    }
+
+    auto& endpointsInDBus = std::get<endpointsPos>(assoc->second);
+
+    for (const auto& endpointToRemove : endpointsToRemove)
+    {
+        auto e = std::find(endpointsInDBus.begin(), endpointsInDBus.end(),
+                           endpointToRemove);
+
+        if (e != endpointsInDBus.end())
+        {
+            endpointsInDBus.erase(e);
+        }
+    }
+
+    if (endpointsInDBus.empty())
+    {
+        objectServer.remove_interface(std::get<ifacePos>(assoc->second));
+        std::get<ifacePos>(assoc->second) = nullptr;
+        std::get<endpointsPos>(assoc->second).clear();
+    }
+    else
+    {
+        std::get<ifacePos>(assoc->second)
+            ->set_property("endpoints", endpointsInDBus);
+    }
+}