summaryrefslogtreecommitdiffstats
path: root/src/processing.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/processing.cpp')
-rw-r--r--src/processing.cpp86
1 files changed, 86 insertions, 0 deletions
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 <boost/algorithm/string/predicate.hpp>
+#include <iostream>
bool getWellKnown(
const boost::container::flat_map<std::string, std::string>& 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<std::vector<Association>>*
+ 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<Association> associations =
+ sdbusplus::message::variant_ns::get<std::vector<Association>>(
+ *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<std::string,
+ boost::container::flat_set<std::string>>;
+ using name_map_iterator = iface_map_value_type::iterator;
+
+ static const boost::container::flat_set<std::string> 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<iface_map_iterator, bool> parentEntry =
+ interfaceMap.insert(std::make_pair(parent, iface_map_value_type{}));
+
+ std::pair<name_map_iterator, bool> 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('/');
+ }
+}
OpenPOWER on IntegriCloud