1*a80a3af0SAndrew Geissler #pragma once
2*a80a3af0SAndrew Geissler 
3*a80a3af0SAndrew Geissler #include <boost/container/flat_map.hpp>
4*a80a3af0SAndrew Geissler #include <boost/container/flat_set.hpp>
5*a80a3af0SAndrew Geissler #include <memory>
6*a80a3af0SAndrew Geissler #include <sdbusplus/asio/object_server.hpp>
7*a80a3af0SAndrew Geissler #include <string>
8*a80a3af0SAndrew Geissler #include <vector>
9*a80a3af0SAndrew Geissler 
10*a80a3af0SAndrew Geissler //  Associations and some metadata are stored in associationInterfaces.
11*a80a3af0SAndrew Geissler //  The fields are:
12*a80a3af0SAndrew Geissler //   * ifacePos - holds the D-Bus interface object
13*a80a3af0SAndrew Geissler //   * endpointsPos - holds the endpoints array that shadows the property
14*a80a3af0SAndrew Geissler static constexpr auto ifacePos = 0;
15*a80a3af0SAndrew Geissler static constexpr auto endpointsPos = 1;
16*a80a3af0SAndrew Geissler using Endpoints = std::vector<std::string>;
17*a80a3af0SAndrew Geissler 
18*a80a3af0SAndrew Geissler using AssociationInterfaces = boost::container::flat_map<
19*a80a3af0SAndrew Geissler     std::string,
20*a80a3af0SAndrew Geissler     std::tuple<std::shared_ptr<sdbusplus::asio::dbus_interface>, Endpoints>>;
21*a80a3af0SAndrew Geissler 
22*a80a3af0SAndrew Geissler // The associationOwners map contains information about creators of
23*a80a3af0SAndrew Geissler // associations, so that when a org.openbmc.Association interface is
24*a80a3af0SAndrew Geissler // removed or its 'associations' property is changed, the mapper owned
25*a80a3af0SAndrew Geissler // association objects can be correctly handled.  It is a map of the
26*a80a3af0SAndrew Geissler // object path of the org.openbmc.Association owner to a map of the
27*a80a3af0SAndrew Geissler // service the path is owned by, to a map of the association objects to
28*a80a3af0SAndrew Geissler // their endpoint paths:
29*a80a3af0SAndrew Geissler // map[ownerPath : map[service : map[assocPath : [endpoint paths]]]
30*a80a3af0SAndrew Geissler // For example:
31*a80a3af0SAndrew Geissler // [/logging/entry/1 :
32*a80a3af0SAndrew Geissler //   [xyz.openbmc_project.Logging :
33*a80a3af0SAndrew Geissler //     [/logging/entry/1/callout : [/system/cpu0],
34*a80a3af0SAndrew Geissler //      /system/cpu0/fault : [/logging/entry/1]]]]
35*a80a3af0SAndrew Geissler 
36*a80a3af0SAndrew Geissler using AssociationPaths =
37*a80a3af0SAndrew Geissler     boost::container::flat_map<std::string,
38*a80a3af0SAndrew Geissler                                boost::container::flat_set<std::string>>;
39*a80a3af0SAndrew Geissler 
40*a80a3af0SAndrew Geissler using AssociationOwnersType = boost::container::flat_map<
41*a80a3af0SAndrew Geissler     std::string, boost::container::flat_map<std::string, AssociationPaths>>;
42*a80a3af0SAndrew Geissler 
43*a80a3af0SAndrew Geissler /** @brief Remove input association
44*a80a3af0SAndrew Geissler  *
45*a80a3af0SAndrew Geissler  * @param[in] sourcePath          - Path of the object that contains the
46*a80a3af0SAndrew Geissler  *                                  org.openbmc.Associations
47*a80a3af0SAndrew Geissler  * @param[in] owner               - The Dbus service having its associations
48*a80a3af0SAndrew Geissler  *                                  removed
49*a80a3af0SAndrew Geissler  * @param[in,out] server          - sdbus system object
50*a80a3af0SAndrew Geissler  * @param[in,out] assocOwners     - Owners of associations
51*a80a3af0SAndrew Geissler  * @param[in,out] assocInterfaces - Associations endpoints
52*a80a3af0SAndrew Geissler  *
53*a80a3af0SAndrew Geissler  * @return Void, server, assocOwners, and assocInterfaces updated if needed
54*a80a3af0SAndrew Geissler  */
55*a80a3af0SAndrew Geissler void removeAssociation(const std::string& sourcePath, const std::string& owner,
56*a80a3af0SAndrew Geissler                        sdbusplus::asio::object_server& server,
57*a80a3af0SAndrew Geissler                        AssociationOwnersType& assocOwners,
58*a80a3af0SAndrew Geissler                        AssociationInterfaces& assocInterfaces);
59