Gather association maps into a single structure
The AssociationOwners and AssociationIntefaces maps are passed around
separately in the mapper, but usually they are always used together.
Gather them into a structure to make it easier to write code to use
them, especially because soon there will be another entry in it.
Signed-off-by: Matt Spinler <spinler@us.ibm.com>
Change-Id: Ibd5b622c7c1240ff8e23846368cbfd56e5bba24d
diff --git a/src/associations.cpp b/src/associations.cpp
index b4c0fae..317836c 100644
--- a/src/associations.cpp
+++ b/src/associations.cpp
@@ -4,8 +4,7 @@
void removeAssociation(const std::string& sourcePath, const std::string& owner,
sdbusplus::asio::object_server& server,
- AssociationOwnersType& assocOwners,
- AssociationInterfaces& assocInterfaces)
+ AssociationMaps& assocMaps)
{
// Use associationOwners to find the association paths and endpoints
// that the passed in object path and service own. Remove all of
@@ -17,8 +16,8 @@
// association path itself.
// Find the services that have associations for this object path
- auto owners = assocOwners.find(sourcePath);
- if (owners == assocOwners.end())
+ auto owners = assocMaps.owners.find(sourcePath);
+ if (owners == assocMaps.owners.end())
{
return;
}
@@ -34,24 +33,24 @@
for (const auto& [assocPath, endpointsToRemove] : assocs->second)
{
removeAssociationEndpoints(server, assocPath, endpointsToRemove,
- assocInterfaces);
+ assocMaps);
}
// Remove the associationOwners entries for this owning path/service.
owners->second.erase(assocs);
if (owners->second.empty())
{
- assocOwners.erase(owners);
+ assocMaps.owners.erase(owners);
}
}
void removeAssociationEndpoints(
sdbusplus::asio::object_server& objectServer, const std::string& assocPath,
const boost::container::flat_set<std::string>& endpointsToRemove,
- AssociationInterfaces& assocInterfaces)
+ AssociationMaps& assocMaps)
{
- auto assoc = assocInterfaces.find(assocPath);
- if (assoc == assocInterfaces.end())
+ auto assoc = assocMaps.ifaces.find(assocPath);
+ if (assoc == assocMaps.ifaces.end())
{
return;
}
@@ -85,12 +84,11 @@
void checkAssociationEndpointRemoves(
const std::string& sourcePath, const std::string& owner,
const AssociationPaths& newAssociations,
- sdbusplus::asio::object_server& objectServer,
- AssociationOwnersType& assocOwners, AssociationInterfaces& assocInterfaces)
+ sdbusplus::asio::object_server& objectServer, AssociationMaps& assocMaps)
{
// Find the services that have associations on this path.
- auto originalOwners = assocOwners.find(sourcePath);
- if (originalOwners == assocOwners.end())
+ auto originalOwners = assocMaps.owners.find(sourcePath);
+ if (originalOwners == assocMaps.owners.end())
{
return;
}
@@ -115,7 +113,7 @@
if (newEndpoints == newAssociations.end())
{
removeAssociationEndpoints(objectServer, originalAssocPath,
- originalEndpoints, assocInterfaces);
+ originalEndpoints, assocMaps);
}
else
{
@@ -135,7 +133,7 @@
if (!toRemove.empty())
{
removeAssociationEndpoints(objectServer, originalAssocPath,
- toRemove, assocInterfaces);
+ toRemove, assocMaps);
}
}
}
@@ -144,8 +142,7 @@
void associationChanged(sdbusplus::asio::object_server& objectServer,
const std::vector<Association>& associations,
const std::string& path, const std::string& owner,
- AssociationOwnersType& assocOwners,
- AssociationInterfaces& assocInterfaces)
+ AssociationMaps& assocMaps)
{
AssociationPaths objects;
@@ -175,7 +172,7 @@
// the mapper exposes the new association interface but intakes
// the old
- auto& iface = assocInterfaces[object.first];
+ auto& iface = assocMaps.ifaces[object.first];
auto& i = std::get<ifacePos>(iface);
auto& endpoints = std::get<endpointsPos>(iface);
@@ -206,11 +203,11 @@
// Check for endpoints being removed instead of added
checkAssociationEndpointRemoves(path, owner, objects, objectServer,
- assocOwners, assocInterfaces);
+ assocMaps);
// Update associationOwners with the latest info
- auto a = assocOwners.find(path);
- if (a != assocOwners.end())
+ auto a = assocMaps.owners.find(path);
+ if (a != assocMaps.owners.end())
{
auto o = a->second.find(owner);
if (o != a->second.end())
@@ -226,6 +223,6 @@
{
boost::container::flat_map<std::string, AssociationPaths> owners;
owners.emplace(owner, std::move(objects));
- assocOwners.emplace(path, owners);
+ assocMaps.owners.emplace(path, owners);
}
}
diff --git a/src/associations.hpp b/src/associations.hpp
index 73fc2e5..31e8b6a 100644
--- a/src/associations.hpp
+++ b/src/associations.hpp
@@ -12,15 +12,13 @@
* @param[in] owner - The Dbus service having its associations
* removed
* @param[in,out] server - sdbus system object
- * @param[in,out] assocOwners - Owners of associations
- * @param[in,out] assocInterfaces - Associations endpoints
+ * @param[in,out] assocMaps - The association maps
*
- * @return Void, server, assocOwners, and assocInterfaces updated if needed
+ * @return Void, server, assocMaps updated if needed
*/
void removeAssociation(const std::string& sourcePath, const std::string& owner,
sdbusplus::asio::object_server& server,
- AssociationOwnersType& assocOwners,
- AssociationInterfaces& assocInterfaces);
+ AssociationMaps& assocMaps);
/** @brief Remove input paths from endpoints of an association
*
@@ -31,14 +29,14 @@
* @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
+ * @param[in,out] assocMaps - The association maps
*
- * @return Void, objectServer and assocInterfaces updated if needed
+ * @return Void, objectServer and assocMaps updated if needed
*/
void removeAssociationEndpoints(
sdbusplus::asio::object_server& objectServer, const std::string& assocPath,
const boost::container::flat_set<std::string>& endpointsToRemove,
- AssociationInterfaces& assocInterfaces);
+ AssociationMaps& assocMaps);
/** @brief Check and remove any changed associations
*
@@ -55,16 +53,14 @@
* changed
* @param[in] newAssociations - New associations to look at for change
* @param[in,out] objectServer - sdbus system object
- * @param[in,out] assocOwners - Owners of associations
- * @param[in,out] assocInterfaces - Associations endpoints
+ * @param[in,out] assocMaps - The association maps
*
- * @return Void, objectServer and assocOwners updated if needed
+ * @return Void, objectServer and assocMaps updated if needed
*/
void checkAssociationEndpointRemoves(
const std::string& sourcePath, const std::string& owner,
const AssociationPaths& newAssociations,
- sdbusplus::asio::object_server& objectServer,
- AssociationOwnersType& assocOwners, AssociationInterfaces& assocInterfaces);
+ sdbusplus::asio::object_server& objectServer, AssociationMaps& assocMaps);
/** @brief Handle new or changed association interfaces
*
@@ -77,13 +73,11 @@
* org.openbmc.Associations
* @param[in] owner - The Dbus service having it's associatons
* changed
- * @param[in,out] assocOwners - Owners of associations
- * @param[in,out] assocInterfaces - Associations endpoints
+ * @param[in,out] assocMaps - The association maps
*
- * @return Void, objectServer and assocOwners updated if needed
+ * @return Void, objectServer and assocMaps updated if needed
*/
void associationChanged(sdbusplus::asio::object_server& objectServer,
const std::vector<Association>& associations,
const std::string& path, const std::string& owner,
- AssociationOwnersType& assocOwners,
- AssociationInterfaces& assocInterfaces);
+ AssociationMaps& assocMaps);
diff --git a/src/main.cpp b/src/main.cpp
index 1ed5435..fe1ea4c 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -18,8 +18,7 @@
constexpr const char* OBJECT_MAPPER_DBUS_NAME =
"xyz.openbmc_project.ObjectMapper";
-AssociationInterfaces associationInterfaces;
-AssociationOwnersType associationOwners;
+AssociationMaps associationMaps;
static WhiteBlackList service_whitelist;
static WhiteBlackList service_blacklist;
@@ -146,7 +145,7 @@
sdbusplus::message::variant_ns::get<std::vector<Association>>(
variantAssociations);
associationChanged(objectServer, associations, path, processName,
- associationOwners, associationInterfaces);
+ associationMaps);
},
processName, path, "org.freedesktop.DBus.Properties", "Get",
assocDefIface, getAssocDefPropName(assocDefIface));
@@ -465,8 +464,7 @@
if (!old_owner.empty())
{
processNameChangeDelete(name_owners, name, old_owner,
- interface_map, associationOwners,
- associationInterfaces, server);
+ interface_map, associationMaps, server);
}
if (!new_owner.empty())
@@ -510,8 +508,7 @@
service_blacklist))
{
processInterfaceAdded(interface_map, obj_path, interfaces_added,
- well_known, associationOwners,
- associationInterfaces, server);
+ well_known, associationMaps, server);
}
};
@@ -548,7 +545,7 @@
if (isAssocDefIface(interface))
{
removeAssociation(obj_path.str, sender, server,
- associationOwners, associationInterfaces);
+ associationMaps);
}
interface_set->second.erase(interface);
@@ -603,8 +600,7 @@
return;
}
associationChanged(server, associations, message.get_path(),
- well_known, associationOwners,
- associationInterfaces);
+ well_known, associationMaps);
}
};
sdbusplus::bus::match::match assocChangedMatch(
diff --git a/src/processing.cpp b/src/processing.cpp
index 3c7e7fb..4d2d3c1 100644
--- a/src/processing.cpp
+++ b/src/processing.cpp
@@ -42,8 +42,7 @@
void processNameChangeDelete(
boost::container::flat_map<std::string, std::string>& nameOwners,
const std::string& wellKnown, const std::string& oldOwner,
- interface_map_type& interfaceMap, AssociationOwnersType& assocOwners,
- AssociationInterfaces& assocInterfaces,
+ interface_map_type& interfaceMap, AssociationMaps& assocMaps,
sdbusplus::asio::object_server& server)
{
if (boost::starts_with(oldOwner, ":"))
@@ -69,8 +68,7 @@
[](const auto& iface) { return isAssocDefIface(iface); });
if (assoc != ifaces->second.end())
{
- removeAssociation(pathIt->first, wellKnown, server, assocOwners,
- assocInterfaces);
+ removeAssociation(pathIt->first, wellKnown, server, assocMaps);
}
}
pathIt->second.erase(wellKnown);
@@ -89,8 +87,7 @@
const sdbusplus::message::object_path& objPath,
const InterfacesAdded& intfAdded,
const std::string& wellKnown,
- AssociationOwnersType& assocOwners,
- AssociationInterfaces& assocInterfaces,
+ AssociationMaps& assocMaps,
sdbusplus::asio::object_server& server)
{
auto& ifaceList = interfaceMap[objPath.str];
@@ -120,7 +117,7 @@
sdbusplus::message::variant_ns::get<std::vector<Association>>(
*variantAssociations);
associationChanged(server, associations, objPath.str, wellKnown,
- assocOwners, assocInterfaces);
+ assocMaps);
}
}
diff --git a/src/processing.hpp b/src/processing.hpp
index e37f279..53669a5 100644
--- a/src/processing.hpp
+++ b/src/processing.hpp
@@ -91,16 +91,14 @@
* @param[in] wellKnown - Well known name that has new owner
* @param[in] oldOwner - Old unique name
* @param[in,out] interfaceMap - Map of interfaces
- * @param[in,out] assocOwners - Owners of associations
- * @param[in,out] assocInterfaces - Associations endpoints
+ * @param[in,out] assocMaps - The association maps
* @param[in,out] server - sdbus system object
*
*/
void processNameChangeDelete(
boost::container::flat_map<std::string, std::string>& nameOwners,
const std::string& wellKnown, const std::string& oldOwner,
- interface_map_type& interfaceMap, AssociationOwnersType& assocOwners,
- AssociationInterfaces& assocInterfaces,
+ interface_map_type& interfaceMap, AssociationMaps& assocMaps,
sdbusplus::asio::object_server& server);
/** @brief Handle an interfaces added signal
@@ -109,8 +107,7 @@
* @param[in] objPath - New path to process
* @param[in] interfacesAdded - New interfaces to process
* @param[in] wellKnown - Well known name that has new owner
- * @param[in,out] assocOwners - Owners of associations
- * @param[in,out] assocInterfaces - Associations endpoints
+ * @param[in,out] assocMaps - The association maps
* @param[in,out] server - sdbus system object
*
*/
@@ -118,6 +115,5 @@
const sdbusplus::message::object_path& objPath,
const InterfacesAdded& intfAdded,
const std::string& wellKnown,
- AssociationOwnersType& assocOwners,
- AssociationInterfaces& assocInterfaces,
+ AssociationMaps& assocMaps,
sdbusplus::asio::object_server& server);
diff --git a/src/test/associations.cpp b/src/test/associations.cpp
index 1b6a348..ce3c9eb 100644
--- a/src/test/associations.cpp
+++ b/src/test/associations.cpp
@@ -20,35 +20,32 @@
{
EXPECT_NE(nullptr, server);
std::string sourcePath = "/xyz/openbmc_project/no/association";
- AssociationOwnersType assocOwners;
- AssociationInterfaces assocInterfaces;
+ AssociationMaps assocMaps;
- removeAssociation(sourcePath, DEFAULT_DBUS_SVC, *server, assocOwners,
- assocInterfaces);
+ removeAssociation(sourcePath, DEFAULT_DBUS_SVC, *server, assocMaps);
}
// Verify call when owner is not in associated owners
TEST_F(TestAssociations, OwnerNotInAssociations)
{
- AssociationInterfaces assocInterfaces;
-
- auto assocOwners = createDefaultOwnerAssociation();
+ AssociationMaps assocMaps;
+ assocMaps.owners = createDefaultOwnerAssociation();
removeAssociation(DEFAULT_SOURCE_PATH, DEFAULT_DBUS_SVC, *server,
- assocOwners, assocInterfaces);
+ assocMaps);
}
// Verify call when path is not in associated interfaces
TEST_F(TestAssociations, PathNotInAssocInterfaces)
{
- AssociationInterfaces assocInterfaces;
+ AssociationMaps assocMaps;
- auto assocOwners = createDefaultOwnerAssociation();
+ assocMaps.owners = createDefaultOwnerAssociation();
removeAssociation(DEFAULT_SOURCE_PATH, DEFAULT_DBUS_SVC, *server,
- assocOwners, assocInterfaces);
+ assocMaps);
- EXPECT_TRUE(assocOwners.empty());
+ EXPECT_TRUE(assocMaps.owners.empty());
}
// Verify call when path is in associated interfaces
@@ -56,20 +53,21 @@
{
// Build up these objects so that an associated interface will match
// with the associated owner being removed
- auto assocOwners = createDefaultOwnerAssociation();
- auto assocInterfaces = createDefaultInterfaceAssociation(server);
+ AssociationMaps assocMaps;
+ assocMaps.owners = createDefaultOwnerAssociation();
+ assocMaps.ifaces = createDefaultInterfaceAssociation(server);
removeAssociation(DEFAULT_SOURCE_PATH, DEFAULT_DBUS_SVC, *server,
- assocOwners, assocInterfaces);
+ assocMaps);
// Verify owner association was deleted
- EXPECT_TRUE(assocOwners.empty());
+ EXPECT_TRUE(assocMaps.owners.empty());
// Verify endpoint was deleted from interface association
auto intfEndpoints =
- std::get<endpointsPos>(assocInterfaces[DEFAULT_FWD_PATH]);
+ std::get<endpointsPos>(assocMaps.ifaces[DEFAULT_FWD_PATH]);
EXPECT_EQ(intfEndpoints.size(), 0);
- intfEndpoints = std::get<endpointsPos>(assocInterfaces[DEFAULT_REV_PATH]);
+ intfEndpoints = std::get<endpointsPos>(assocMaps.ifaces[DEFAULT_REV_PATH]);
EXPECT_EQ(intfEndpoints.size(), 0);
}
@@ -78,23 +76,24 @@
{
// Build up these objects so that an associated interface will match
// with the associated owner being removed
- auto assocOwners = createDefaultOwnerAssociation();
- auto assocInterfaces = createDefaultInterfaceAssociation(server);
+ AssociationMaps assocMaps;
+ assocMaps.owners = createDefaultOwnerAssociation();
+ assocMaps.ifaces = createDefaultInterfaceAssociation(server);
// Add another endpoint to the assoc interfaces
- addEndpointToInterfaceAssociation(assocInterfaces);
+ addEndpointToInterfaceAssociation(assocMaps.ifaces);
removeAssociation(DEFAULT_SOURCE_PATH, DEFAULT_DBUS_SVC, *server,
- assocOwners, assocInterfaces);
+ assocMaps);
// Verify owner association was deleted
- EXPECT_TRUE(assocOwners.empty());
+ EXPECT_TRUE(assocMaps.owners.empty());
// Verify all endpoints are deleted since source path was deleted
auto intfEndpoints =
- std::get<endpointsPos>(assocInterfaces[DEFAULT_FWD_PATH]);
+ std::get<endpointsPos>(assocMaps.ifaces[DEFAULT_FWD_PATH]);
EXPECT_EQ(intfEndpoints.size(), 0);
- intfEndpoints = std::get<endpointsPos>(assocInterfaces[DEFAULT_REV_PATH]);
+ intfEndpoints = std::get<endpointsPos>(assocMaps.ifaces[DEFAULT_REV_PATH]);
EXPECT_EQ(intfEndpoints.size(), 0);
}
@@ -106,19 +105,19 @@
{DEFAULT_FWD_PATH, {DEFAULT_ENDPOINT}},
{DEFAULT_REV_PATH, {DEFAULT_SOURCE_PATH}}};
- auto assocOwners = createDefaultOwnerAssociation();
- auto assocInterfaces = createDefaultInterfaceAssociation(server);
+ AssociationMaps assocMaps;
+ assocMaps.owners = createDefaultOwnerAssociation();
+ assocMaps.ifaces = createDefaultInterfaceAssociation(server);
checkAssociationEndpointRemoves(DEFAULT_SOURCE_PATH, DEFAULT_DBUS_SVC,
- newAssocPaths, *server, assocOwners,
- assocInterfaces);
+ newAssocPaths, *server, assocMaps);
// Verify endpoints were not deleted because they matche with what was
// in the original
auto intfEndpoints =
- std::get<endpointsPos>(assocInterfaces[DEFAULT_FWD_PATH]);
+ std::get<endpointsPos>(assocMaps.ifaces[DEFAULT_FWD_PATH]);
EXPECT_EQ(intfEndpoints.size(), 1);
- intfEndpoints = std::get<endpointsPos>(assocInterfaces[DEFAULT_REV_PATH]);
+ intfEndpoints = std::get<endpointsPos>(assocMaps.ifaces[DEFAULT_REV_PATH]);
EXPECT_EQ(intfEndpoints.size(), 1);
}
@@ -127,18 +126,18 @@
{
AssociationPaths newAssocPaths = {{"/different/path", {DEFAULT_ENDPOINT}}};
- auto assocOwners = createDefaultOwnerAssociation();
- auto assocInterfaces = createDefaultInterfaceAssociation(server);
+ AssociationMaps assocMaps;
+ assocMaps.owners = createDefaultOwnerAssociation();
+ assocMaps.ifaces = createDefaultInterfaceAssociation(server);
checkAssociationEndpointRemoves(DEFAULT_SOURCE_PATH, DEFAULT_DBUS_SVC,
- newAssocPaths, *server, assocOwners,
- assocInterfaces);
+ newAssocPaths, *server, assocMaps);
// Verify initial endpoints were deleted because the new path
auto intfEndpoints =
- std::get<endpointsPos>(assocInterfaces[DEFAULT_FWD_PATH]);
+ std::get<endpointsPos>(assocMaps.ifaces[DEFAULT_FWD_PATH]);
EXPECT_EQ(intfEndpoints.size(), 0);
- intfEndpoints = std::get<endpointsPos>(assocInterfaces[DEFAULT_REV_PATH]);
+ intfEndpoints = std::get<endpointsPos>(assocMaps.ifaces[DEFAULT_REV_PATH]);
EXPECT_EQ(intfEndpoints.size(), 0);
}
@@ -149,18 +148,18 @@
{DEFAULT_FWD_PATH, {DEFAULT_ENDPOINT + "/different"}},
{DEFAULT_REV_PATH, {DEFAULT_SOURCE_PATH + "/different"}}};
- auto assocOwners = createDefaultOwnerAssociation();
- auto assocInterfaces = createDefaultInterfaceAssociation(server);
+ AssociationMaps assocMaps;
+ assocMaps.owners = createDefaultOwnerAssociation();
+ assocMaps.ifaces = createDefaultInterfaceAssociation(server);
checkAssociationEndpointRemoves(DEFAULT_SOURCE_PATH, DEFAULT_DBUS_SVC,
- newAssocPaths, *server, assocOwners,
- assocInterfaces);
+ newAssocPaths, *server, assocMaps);
// Verify initial endpoints were deleted because of different endpoints
auto intfEndpoints =
- std::get<endpointsPos>(assocInterfaces[DEFAULT_FWD_PATH]);
+ std::get<endpointsPos>(assocMaps.ifaces[DEFAULT_FWD_PATH]);
EXPECT_EQ(intfEndpoints.size(), 0);
- intfEndpoints = std::get<endpointsPos>(assocInterfaces[DEFAULT_REV_PATH]);
+ intfEndpoints = std::get<endpointsPos>(assocMaps.ifaces[DEFAULT_REV_PATH]);
EXPECT_EQ(intfEndpoints.size(), 0);
}
@@ -169,18 +168,19 @@
{
std::vector<Association> associations = {{"inventory", "error", ""}};
- auto assocOwners = createDefaultOwnerAssociation();
- auto assocInterfaces = createDefaultInterfaceAssociation(server);
+ AssociationMaps assocMaps;
+ assocMaps.owners = createDefaultOwnerAssociation();
+ assocMaps.ifaces = createDefaultInterfaceAssociation(server);
// Empty endpoint will result in deletion of corresponding assocInterface
associationChanged(*server, associations, DEFAULT_SOURCE_PATH,
- DEFAULT_DBUS_SVC, assocOwners, assocInterfaces);
+ DEFAULT_DBUS_SVC, assocMaps);
// Both of these should be 0 since we have an invalid endpoint
auto intfEndpoints =
- std::get<endpointsPos>(assocInterfaces[DEFAULT_FWD_PATH]);
+ std::get<endpointsPos>(assocMaps.ifaces[DEFAULT_FWD_PATH]);
EXPECT_EQ(intfEndpoints.size(), 0);
- intfEndpoints = std::get<endpointsPos>(assocInterfaces[DEFAULT_REV_PATH]);
+ intfEndpoints = std::get<endpointsPos>(assocMaps.ifaces[DEFAULT_REV_PATH]);
EXPECT_EQ(intfEndpoints.size(), 0);
}
@@ -190,21 +190,22 @@
std::vector<Association> associations = {
{"abc", "def", "/xyz/openbmc_project/new/endpoint"}};
- auto assocOwners = createDefaultOwnerAssociation();
- auto assocInterfaces = createDefaultInterfaceAssociation(server);
+ AssociationMaps assocMaps;
+ assocMaps.owners = createDefaultOwnerAssociation();
+ assocMaps.ifaces = createDefaultInterfaceAssociation(server);
associationChanged(*server, associations, "/new/source/path",
- DEFAULT_DBUS_SVC, assocOwners, assocInterfaces);
+ DEFAULT_DBUS_SVC, assocMaps);
// Two source paths
- EXPECT_EQ(assocOwners.size(), 2);
+ EXPECT_EQ(assocMaps.owners.size(), 2);
// Four interfaces
- EXPECT_EQ(assocInterfaces.size(), 4);
+ EXPECT_EQ(assocMaps.ifaces.size(), 4);
- // New endpoint so assocInterfaces should be same size
+ // New endpoint so assocMaps.ifaces should be same size
auto intfEndpoints =
- std::get<endpointsPos>(assocInterfaces[DEFAULT_FWD_PATH]);
+ std::get<endpointsPos>(assocMaps.ifaces[DEFAULT_FWD_PATH]);
EXPECT_EQ(intfEndpoints.size(), 1);
}
@@ -219,22 +220,21 @@
// Empty objects because this test will ensure assocOwners adds the
// changed association and interface
- AssociationInterfaces assocInterfaces;
- AssociationOwnersType assocOwners;
+ AssociationMaps assocMaps;
associationChanged(*server, associations, DEFAULT_SOURCE_PATH,
- DEFAULT_DBUS_SVC, assocOwners, assocInterfaces);
+ DEFAULT_DBUS_SVC, assocMaps);
// New associations so ensure it now contains a single entry
- EXPECT_EQ(assocOwners.size(), 1);
+ EXPECT_EQ(assocMaps.owners.size(), 1);
// Verify corresponding assoc paths each have one endpoint in assoc
// interfaces and that those endpoints match
- auto singleOwner = assocOwners[DEFAULT_SOURCE_PATH];
+ auto singleOwner = assocMaps.owners[DEFAULT_SOURCE_PATH];
auto singleIntf = singleOwner[DEFAULT_DBUS_SVC];
for (auto i : singleIntf)
{
- auto intfEndpoints = std::get<endpointsPos>(assocInterfaces[i.first]);
+ auto intfEndpoints = std::get<endpointsPos>(assocMaps.ifaces[i.first]);
EXPECT_EQ(intfEndpoints.size(), 1);
EXPECT_EQ(intfEndpoints[0], *i.second.begin());
}
@@ -248,22 +248,23 @@
{"inventory", "error",
"/xyz/openbmc_project/inventory/system/chassis"}};
- auto assocOwners = createDefaultOwnerAssociation();
- auto assocInterfaces = createDefaultInterfaceAssociation(server);
+ AssociationMaps assocMaps;
+ assocMaps.owners = createDefaultOwnerAssociation();
+ assocMaps.ifaces = createDefaultInterfaceAssociation(server);
associationChanged(*server, associations, DEFAULT_SOURCE_PATH, newOwner,
- assocOwners, assocInterfaces);
+ assocMaps);
// New endpoint so assocOwners should be same size
- EXPECT_EQ(assocOwners.size(), 1);
+ EXPECT_EQ(assocMaps.owners.size(), 1);
// Ensure only one endpoint under first path
auto intfEndpoints =
- std::get<endpointsPos>(assocInterfaces[DEFAULT_FWD_PATH]);
+ std::get<endpointsPos>(assocMaps.ifaces[DEFAULT_FWD_PATH]);
EXPECT_EQ(intfEndpoints.size(), 1);
// Ensure the 2 new association endpoints are under the new owner
- auto a = assocOwners.find(DEFAULT_SOURCE_PATH);
+ auto a = assocMaps.owners.find(DEFAULT_SOURCE_PATH);
auto o = a->second.find(newOwner);
EXPECT_EQ(o->second.size(), 2);
}
@@ -274,26 +275,27 @@
std::vector<Association> associations = {
{"abc", "error", "/xyz/openbmc_project/inventory/system/chassis"}};
- auto assocOwners = createDefaultOwnerAssociation();
- auto assocInterfaces = createDefaultInterfaceAssociation(server);
+ AssociationMaps assocMaps;
+ assocMaps.owners = createDefaultOwnerAssociation();
+ assocMaps.ifaces = createDefaultInterfaceAssociation(server);
associationChanged(*server, associations, DEFAULT_SOURCE_PATH,
- DEFAULT_DBUS_SVC, assocOwners, assocInterfaces);
+ DEFAULT_DBUS_SVC, assocMaps);
// Should have 3 entries in AssociationInterfaces, one is just missing an
// endpoint
- EXPECT_EQ(assocInterfaces.size(), 3);
+ EXPECT_EQ(assocMaps.ifaces.size(), 3);
// Change to existing interface so it will be removed here
auto intfEndpoints =
- std::get<endpointsPos>(assocInterfaces[DEFAULT_FWD_PATH]);
+ std::get<endpointsPos>(assocMaps.ifaces[DEFAULT_FWD_PATH]);
EXPECT_EQ(intfEndpoints.size(), 0);
// The new endpoint should exist though in it's place
intfEndpoints = std::get<endpointsPos>(
- assocInterfaces[DEFAULT_SOURCE_PATH + "/" + "abc"]);
+ assocMaps.ifaces[DEFAULT_SOURCE_PATH + "/" + "abc"]);
EXPECT_EQ(intfEndpoints.size(), 1);
// Added to an existing owner path so still 1
- EXPECT_EQ(assocOwners.size(), 1);
+ EXPECT_EQ(assocMaps.owners.size(), 1);
}
diff --git a/src/test/interfaces_added.cpp b/src/test/interfaces_added.cpp
index a48c254..4f0d2c4 100644
--- a/src/test/interfaces_added.cpp
+++ b/src/test/interfaces_added.cpp
@@ -35,14 +35,13 @@
TEST_F(TestInterfacesAdded, InterfacesAddedGoodPath)
{
interface_map_type interfaceMap;
- AssociationOwnersType assocOwners;
- AssociationInterfaces assocInterfaces;
+ AssociationMaps assocMaps;
+
auto intfAdded = createInterfacesAdded(
assocDefsInterface, getAssocDefPropName(assocDefsInterface));
processInterfaceAdded(interfaceMap, DEFAULT_SOURCE_PATH, intfAdded,
- DEFAULT_DBUS_SVC, assocOwners, assocInterfaces,
- *server);
+ DEFAULT_DBUS_SVC, assocMaps, *server);
// Interface map will get the following:
// /logging/entry/1 /logging/entry /logging/ /
@@ -51,25 +50,24 @@
// New association ower created so ensure it now contains a single entry
// dump_AssociationOwnersType(assocOwners);
- EXPECT_EQ(assocOwners.size(), 1);
+ EXPECT_EQ(assocMaps.owners.size(), 1);
// Ensure the 2 association interfaces were created
// dump_AssociationInterfaces(assocInterfaces);
- EXPECT_EQ(assocInterfaces.size(), 2);
+ EXPECT_EQ(assocMaps.ifaces.size(), 2);
}
TEST_F(TestInterfacesAdded, OrgOpenBmcInterfacesAddedGoodPath)
{
interface_map_type interfaceMap;
- AssociationOwnersType assocOwners;
- AssociationInterfaces assocInterfaces;
+ AssociationMaps assocMaps;
+
auto intfAdded = createInterfacesAdded(
orgOpenBMCAssocDefsInterface,
getAssocDefPropName(orgOpenBMCAssocDefsInterface));
processInterfaceAdded(interfaceMap, DEFAULT_SOURCE_PATH, intfAdded,
- DEFAULT_DBUS_SVC, assocOwners, assocInterfaces,
- *server);
+ DEFAULT_DBUS_SVC, assocMaps, *server);
// Interface map will get the following:
// /logging/entry/1 /logging/entry /logging/ /
@@ -78,9 +76,9 @@
// New association ower created so ensure it now contains a single entry
// dump_AssociationOwnersType(assocOwners);
- EXPECT_EQ(assocOwners.size(), 1);
+ EXPECT_EQ(assocMaps.owners.size(), 1);
// Ensure the 2 association interfaces were created
// dump_AssociationInterfaces(assocInterfaces);
- EXPECT_EQ(assocInterfaces.size(), 2);
+ EXPECT_EQ(assocMaps.ifaces.size(), 2);
}
diff --git a/src/test/name_change.cpp b/src/test/name_change.cpp
index a6d18e4..95d02af 100644
--- a/src/test/name_change.cpp
+++ b/src/test/name_change.cpp
@@ -18,11 +18,10 @@
std::string wellKnown = {"test-name"};
std::string oldOwner = {":1.99"};
interface_map_type interfaceMap;
- AssociationOwnersType assocOwners;
- AssociationInterfaces assocInterfaces;
+ AssociationMaps assocMaps;
processNameChangeDelete(nameOwners, wellKnown, oldOwner, interfaceMap,
- assocOwners, assocInterfaces, *server);
+ assocMaps, *server);
EXPECT_EQ(nameOwners.size(), 0);
}
@@ -37,24 +36,24 @@
// Build up these objects so that an associated interface will match
// with the associated owner being removed
- auto assocOwners = createDefaultOwnerAssociation();
- auto assocInterfaces = createDefaultInterfaceAssociation(server);
+ AssociationMaps assocMaps;
+ assocMaps.owners = createDefaultOwnerAssociation();
+ assocMaps.ifaces = createDefaultInterfaceAssociation(server);
auto interfaceMap = createInterfaceMap(
DEFAULT_SOURCE_PATH, DEFAULT_DBUS_SVC, assocInterfacesSet);
processNameChangeDelete(nameOwners, DEFAULT_DBUS_SVC, oldOwner,
- interfaceMap, assocOwners, assocInterfaces,
- *server);
+ interfaceMap, assocMaps, *server);
EXPECT_EQ(nameOwners.size(), 0);
// Verify owner association was deleted
- EXPECT_TRUE(assocOwners.empty());
+ EXPECT_TRUE(assocMaps.owners.empty());
// Verify endpoint was deleted from interface association
auto intfEndpoints =
- std::get<endpointsPos>(assocInterfaces[DEFAULT_FWD_PATH]);
+ std::get<endpointsPos>(assocMaps.ifaces[DEFAULT_FWD_PATH]);
EXPECT_EQ(intfEndpoints.size(), 0);
- intfEndpoints = std::get<endpointsPos>(assocInterfaces[DEFAULT_REV_PATH]);
+ intfEndpoints = std::get<endpointsPos>(assocMaps.ifaces[DEFAULT_REV_PATH]);
EXPECT_EQ(intfEndpoints.size(), 0);
// Verify interface map was deleted
diff --git a/src/types.hpp b/src/types.hpp
index 8415cf3..0696f47 100644
--- a/src/types.hpp
+++ b/src/types.hpp
@@ -62,3 +62,12 @@
* ["inventory", "activation", "/xyz/openbmc_project/inventory/system/chassis"]
*/
using Association = std::tuple<std::string, std::string, std::string>;
+
+/**
+ * Keeps all association related maps together.
+ */
+struct AssociationMaps
+{
+ AssociationInterfaces ifaces;
+ AssociationOwnersType owners;
+};