From ff5ce9247fd2e55793c6afcdf0bd9b86ed9b0e36 Mon Sep 17 00:00:00 2001 From: Andrew Geissler Date: Thu, 21 Feb 2019 12:43:09 -0600 Subject: unit-test: Move removeAssociationEndpoints() Make it easier to unit test and continue reduction of main.cpp Change-Id: I2c0eac5c301687acab14add627586170020e4fe4 Signed-off-by: Andrew Geissler --- src/associations.cpp | 37 +++++++++++++++++++++++++++++++++++++ src/associations.hpp | 18 ++++++++++++++++++ src/main.cpp | 47 ++++------------------------------------------- 3 files changed, 59 insertions(+), 43 deletions(-) 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 @@ void removeAssociation(const std::string& sourcePath, const std::string& owner, assocOwners.erase(owners); } } + +void removeAssociationEndpoints( + sdbusplus::asio::object_server& objectServer, const std::string& assocPath, + const boost::container::flat_set& endpointsToRemove, + AssociationInterfaces& assocInterfaces) +{ + auto assoc = assocInterfaces.find(assocPath); + if (assoc == assocInterfaces.end()) + { + return; + } + + auto& endpointsInDBus = std::get(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(assoc->second)); + std::get(assoc->second) = nullptr; + std::get(assoc->second).clear(); + } + else + { + std::get(assoc->second) + ->set_property("endpoints", endpointsInDBus); + } +} diff --git a/src/associations.hpp b/src/associations.hpp index 8ebef43..d926006 100644 --- a/src/associations.hpp +++ b/src/associations.hpp @@ -58,3 +58,21 @@ void removeAssociation(const std::string& sourcePath, const std::string& owner, sdbusplus::asio::object_server& server, AssociationOwnersType& assocOwners, AssociationInterfaces& assocInterfaces); + +/** @brief Remove input paths from endpoints of an association + * + * If the last endpoint was removed, then remove the whole + * association object, otherwise just set the property + * + * @param[in] objectServer - sdbus system object + * @param[in] assocPath - Path of the object that contains the + * org.openbmc.Associations + * @param[in] endpointsToRemove - Endpoints to remove + * @param[in,out] assocInterfaces - Associations endpoints + * + * @return Void, objectServer and assocInterfaces updated if needed + */ +void removeAssociationEndpoints( + sdbusplus::asio::object_server& objectServer, const std::string& assocPath, + const boost::container::flat_set& endpointsToRemove, + AssociationInterfaces& assocInterfaces); diff --git a/src/main.cpp b/src/main.cpp index e5d566e..44fe063 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -130,46 +130,6 @@ struct InProgressIntrospect #endif }; -// Remove paths from the endpoints property of an association. -// If the last endpoint was removed, then remove the whole -// association object, otherwise just set the property. -void removeAssociationEndpoints( - sdbusplus::asio::object_server& objectServer, const std::string& assocPath, - const std::string& owner, - const boost::container::flat_set& endpointsToRemove) -{ - auto assoc = associationInterfaces.find(assocPath); - if (assoc == associationInterfaces.end()) - { - return; - } - - auto& endpointsInDBus = std::get(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(assoc->second)); - std::get(assoc->second) = nullptr; - std::get(assoc->second).clear(); - } - else - { - std::get(assoc->second) - ->set_property("endpoints", endpointsInDBus); - } -} - // Based on the latest values of the org.openbmc.Associations.associations // property, passed in via the newAssociations param, check if any of the // paths in the xyz.openbmc_project.Association.endpoints D-Bus property @@ -207,8 +167,9 @@ void checkAssociationEndpointRemoves( auto newEndpoints = newAssociations.find(originalAssocPath); if (newEndpoints == newAssociations.end()) { - removeAssociationEndpoints(objectServer, originalAssocPath, owner, - originalEndpoints); + removeAssociationEndpoints(objectServer, originalAssocPath, + originalEndpoints, + associationInterfaces); } else { @@ -228,7 +189,7 @@ void checkAssociationEndpointRemoves( if (!toRemove.empty()) { removeAssociationEndpoints(objectServer, originalAssocPath, - owner, toRemove); + toRemove, associationInterfaces); } } } -- cgit v1.2.1