Remove an endpoint from the pending assocs

If there is a pending association, but the object that
owns that association goes off the bus, then there is
no need to wait for the endpoint to show up anymore so
remove it from the pending associations list.

Signed-off-by: Matt Spinler <spinler@us.ibm.com>
Change-Id: I96af6ffd62f857015522c041dfbdbcd2132d8374
diff --git a/src/associations.cpp b/src/associations.cpp
index 0f84d1e..30a8e9a 100644
--- a/src/associations.cpp
+++ b/src/associations.cpp
@@ -42,6 +42,10 @@
     {
         assocMaps.owners.erase(owners);
     }
+
+    // If we were still waiting on the other side of this association to
+    // show up, cancel that wait.
+    removeFromPendingAssociations(sourcePath, assocMaps);
 }
 
 void removeAssociationEndpoints(
@@ -272,3 +276,32 @@
         }
     }
 }
+
+void removeFromPendingAssociations(const std::string& endpointPath,
+                                   AssociationMaps& assocMaps)
+{
+    auto assoc = assocMaps.pending.begin();
+    while (assoc != assocMaps.pending.end())
+    {
+        auto endpoint = assoc->second.begin();
+        while (endpoint != assoc->second.end())
+        {
+            auto& e = std::get<assocPos>(*endpoint);
+            if (std::get<reversePathPos>(e) == endpointPath)
+            {
+                endpoint = assoc->second.erase(endpoint);
+                continue;
+            }
+
+            endpoint++;
+        }
+
+        if (assoc->second.empty())
+        {
+            assoc = assocMaps.pending.erase(assoc);
+            continue;
+        }
+
+        assoc++;
+    }
+}