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++;
+ }
+}
diff --git a/src/associations.hpp b/src/associations.hpp
index 64688bf..3f4b81e 100644
--- a/src/associations.hpp
+++ b/src/associations.hpp
@@ -110,3 +110,13 @@
const std::string& endpointType,
const std::string& owner,
AssociationMaps& assocMaps);
+
+/** @brief Removes an endpoint from the pending associations map
+ *
+ * If the last endpoint is removed, removes the whole entry
+ *
+ * @param[in] endpointPath - the endpoint path to remove
+ * @param[in,out] assocMaps - The association maps
+ */
+void removeFromPendingAssociations(const std::string& endpointPath,
+ AssociationMaps& assocMaps);
diff --git a/src/test/associations.cpp b/src/test/associations.cpp
index cebd614..5f87020 100644
--- a/src/test/associations.cpp
+++ b/src/test/associations.cpp
@@ -415,3 +415,32 @@
// 1 pending association
EXPECT_EQ(assocMaps.pending.size(), 1);
}
+
+// Test removing pending associations
+TEST_F(TestAssociations, testRemoveFromPendingAssociations)
+{
+ AssociationMaps assocMaps;
+
+ addPendingAssociation(DEFAULT_SOURCE_PATH, "inventory", DEFAULT_ENDPOINT,
+ "error", DEFAULT_DBUS_SVC, assocMaps);
+
+ addPendingAssociation(DEFAULT_SOURCE_PATH, "inventory",
+ "some/other/endpoint", "error", DEFAULT_DBUS_SVC,
+ assocMaps);
+
+ EXPECT_EQ(assocMaps.pending.size(), 1);
+
+ removeFromPendingAssociations("some/other/endpoint", assocMaps);
+
+ // Still 1 pending entry, but down to 1 endpoint
+ EXPECT_EQ(assocMaps.pending.size(), 1);
+
+ auto assoc = assocMaps.pending.find(DEFAULT_SOURCE_PATH);
+ EXPECT_NE(assoc, assocMaps.pending.end());
+ auto& endpoints = assoc->second;
+ EXPECT_EQ(endpoints.size(), 1);
+
+ // Now nothing pending
+ removeFromPendingAssociations(DEFAULT_ENDPOINT, assocMaps);
+ EXPECT_EQ(assocMaps.pending.size(), 0);
+}
diff --git a/src/types.hpp b/src/types.hpp
index df7b7fa..87c3b4d 100644
--- a/src/types.hpp
+++ b/src/types.hpp
@@ -61,6 +61,9 @@
* For example:
* ["inventory", "activation", "/xyz/openbmc_project/inventory/system/chassis"]
*/
+constexpr auto forwardTypePos = 0;
+constexpr auto reverseTypePos = 1;
+constexpr auto reversePathPos = 2;
using Association = std::tuple<std::string, std::string, std::string>;
/**