From 70461896775208bbe400cc23786ce4d17a0c07f7 Mon Sep 17 00:00:00 2001 From: Andrew Geissler Date: Wed, 27 Feb 2019 09:57:37 -0600 Subject: unit-test: Move processing of interfaces added Make it easier to unit test and continue reduction of main.cpp Change-Id: Id360255e1546eda026e5e6ef9f15d29dcc82caaa Signed-off-by: Andrew Geissler --- src/processing.cpp | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) (limited to 'src/processing.cpp') diff --git a/src/processing.cpp b/src/processing.cpp index 3cd348b..6dd6493 100644 --- a/src/processing.cpp +++ b/src/processing.cpp @@ -1,6 +1,7 @@ #include "processing.hpp" #include +#include bool getWellKnown( const boost::container::flat_map& owners, @@ -82,3 +83,88 @@ void processNameChangeDelete( pathIt++; } } + +void processInterfaceAdded(interface_map_type& interfaceMap, + const sdbusplus::message::object_path& objPath, + const InterfacesAdded& intfAdded, + const std::string& wellKnown, + AssociationOwnersType& assocOwners, + AssociationInterfaces& assocInterfaces, + sdbusplus::asio::object_server& server) +{ + auto& ifaceList = interfaceMap[objPath.str]; + + for (const auto& interfacePair : intfAdded) + { + ifaceList[wellKnown].emplace(interfacePair.first); + + if (interfacePair.first == ASSOCIATIONS_INTERFACE) + { + const sdbusplus::message::variant>* + variantAssociations = nullptr; + for (const auto& interface : interfacePair.second) + { + if (interface.first == "associations") + { + variantAssociations = &(interface.second); + } + } + if (variantAssociations == nullptr) + { + std::cerr << "Illegal association found on " << wellKnown + << "\n"; + continue; + } + std::vector associations = + sdbusplus::message::variant_ns::get>( + *variantAssociations); + associationChanged(server, associations, objPath.str, wellKnown, + assocOwners, assocInterfaces); + } + } + + // To handle the case where an object path is being created + // with 2 or more new path segments, check if the parent paths + // of this path are already in the interface map, and add them + // if they aren't with just the default freedesktop interfaces. + // This would be done via introspection if they would have + // already existed at startup. While we could also introspect + // them now to do the work, we know there aren't any other + // interfaces or we would have gotten signals for them as well, + // so take a shortcut to speed things up. + // + // This is all needed so that mapper operations can be done + // on the new parent paths. + using iface_map_iterator = interface_map_type::iterator; + using iface_map_value_type = + boost::container::flat_map>; + using name_map_iterator = iface_map_value_type::iterator; + + static const boost::container::flat_set defaultIfaces{ + "org.freedesktop.DBus.Introspectable", "org.freedesktop.DBus.Peer", + "org.freedesktop.DBus.Properties"}; + + std::string parent = objPath.str; + auto pos = parent.find_last_of('/'); + + while (pos != std::string::npos) + { + parent = parent.substr(0, pos); + + std::pair parentEntry = + interfaceMap.insert(std::make_pair(parent, iface_map_value_type{})); + + std::pair ifaceEntry = + parentEntry.first->second.insert( + std::make_pair(wellKnown, defaultIfaces)); + + if (!ifaceEntry.second) + { + // Entry was already there for this name so done. + break; + } + + pos = parent.find_last_of('/'); + } +} -- cgit v1.2.1