blob: 91a9fcdfde7cf64e5003f57d5622e96cbb1fa3c7 [file] [log] [blame]
Andrew Geisslera80a3af2019-02-04 14:01:49 -06001#pragma once
2
3#include <boost/container/flat_map.hpp>
4#include <boost/container/flat_set.hpp>
5#include <memory>
6#include <sdbusplus/asio/object_server.hpp>
7#include <string>
Andrew Geissler271b7dd2019-02-05 11:23:30 -06008#include <tuple>
Andrew Geisslera80a3af2019-02-04 14:01:49 -06009#include <vector>
10
Andrew Geissler4511b332019-02-21 15:40:40 -060011constexpr const char* XYZ_ASSOCIATION_INTERFACE =
12 "xyz.openbmc_project.Association";
13
Andrew Geisslera80a3af2019-02-04 14:01:49 -060014// Associations and some metadata are stored in associationInterfaces.
15// The fields are:
16// * ifacePos - holds the D-Bus interface object
17// * endpointsPos - holds the endpoints array that shadows the property
18static constexpr auto ifacePos = 0;
19static constexpr auto endpointsPos = 1;
20using Endpoints = std::vector<std::string>;
21
Andrew Geissler271b7dd2019-02-05 11:23:30 -060022// map[interface path: tuple[dbus_interface,vector[endpoint paths]]]
Andrew Geisslera80a3af2019-02-04 14:01:49 -060023using AssociationInterfaces = boost::container::flat_map<
24 std::string,
25 std::tuple<std::shared_ptr<sdbusplus::asio::dbus_interface>, Endpoints>>;
26
27// The associationOwners map contains information about creators of
28// associations, so that when a org.openbmc.Association interface is
29// removed or its 'associations' property is changed, the mapper owned
30// association objects can be correctly handled. It is a map of the
31// object path of the org.openbmc.Association owner to a map of the
32// service the path is owned by, to a map of the association objects to
33// their endpoint paths:
34// map[ownerPath : map[service : map[assocPath : [endpoint paths]]]
35// For example:
36// [/logging/entry/1 :
37// [xyz.openbmc_project.Logging :
38// [/logging/entry/1/callout : [/system/cpu0],
39// /system/cpu0/fault : [/logging/entry/1]]]]
40
41using AssociationPaths =
42 boost::container::flat_map<std::string,
43 boost::container::flat_set<std::string>>;
44
45using AssociationOwnersType = boost::container::flat_map<
46 std::string, boost::container::flat_map<std::string, AssociationPaths>>;
47
Andrew Geisslerea80c332019-02-22 15:22:21 -060048// Store the contents of the associations property on the interface
49// For example:
50// ["inventory", "activation", "/xyz/openbmc_project/inventory/system/chassis"]
Andrew Geissler4511b332019-02-21 15:40:40 -060051using Association = std::tuple<std::string, std::string, std::string>;
52
Andrew Geisslera80a3af2019-02-04 14:01:49 -060053/** @brief Remove input association
54 *
55 * @param[in] sourcePath - Path of the object that contains the
56 * org.openbmc.Associations
57 * @param[in] owner - The Dbus service having its associations
58 * removed
59 * @param[in,out] server - sdbus system object
60 * @param[in,out] assocOwners - Owners of associations
61 * @param[in,out] assocInterfaces - Associations endpoints
62 *
63 * @return Void, server, assocOwners, and assocInterfaces updated if needed
64 */
65void removeAssociation(const std::string& sourcePath, const std::string& owner,
66 sdbusplus::asio::object_server& server,
67 AssociationOwnersType& assocOwners,
68 AssociationInterfaces& assocInterfaces);
Andrew Geisslerff5ce922019-02-21 12:43:09 -060069
70/** @brief Remove input paths from endpoints of an association
71 *
72 * If the last endpoint was removed, then remove the whole
73 * association object, otherwise just set the property
74 *
75 * @param[in] objectServer - sdbus system object
76 * @param[in] assocPath - Path of the object that contains the
77 * org.openbmc.Associations
78 * @param[in] endpointsToRemove - Endpoints to remove
79 * @param[in,out] assocInterfaces - Associations endpoints
80 *
81 * @return Void, objectServer and assocInterfaces updated if needed
82 */
83void removeAssociationEndpoints(
84 sdbusplus::asio::object_server& objectServer, const std::string& assocPath,
85 const boost::container::flat_set<std::string>& endpointsToRemove,
86 AssociationInterfaces& assocInterfaces);
Andrew Geissler7f1c44d2019-02-21 13:44:16 -060087
88/** @brief Check and remove any changed associations
89 *
90 * Based on the latest values of the org.openbmc.Associations.associations
91 * property, passed in via the newAssociations param, check if any of the
92 * paths in the xyz.openbmc_project.Association.endpoints D-Bus property
93 * for that association need to be removed. If the last path is removed
94 * from the endpoints property, remove that whole association object from
95 * D-Bus.
96 *
97 * @param[in] sourcePath - Path of the object that contains the
98 * org.openbmc.Associations
99 * @param[in] owner - The Dbus service having it's associatons
100 * changed
101 * @param[in] newAssociations - New associations to look at for change
102 * @param[in,out] objectServer - sdbus system object
103 * @param[in,out] assocOwners - Owners of associations
104 * @param[in,out] assocInterfaces - Associations endpoints
105 *
106 * @return Void, objectServer and assocOwners updated if needed
107 */
108void checkAssociationEndpointRemoves(
109 const std::string& sourcePath, const std::string& owner,
110 const AssociationPaths& newAssociations,
111 sdbusplus::asio::object_server& objectServer,
112 AssociationOwnersType& assocOwners, AssociationInterfaces& assocInterfaces);
Andrew Geissler4511b332019-02-21 15:40:40 -0600113
114/** @brief Handle new or changed association interfaces
115 *
116 * Called when either a new org.openbmc.Associations interface was
117 * created, or the associations property on that interface changed
118 *
119 * @param[in,out] objectServer - sdbus system object
120 * @param[in] associations - New associations to look at for change
121 * @param[in] path - Path of the object that contains the
122 * org.openbmc.Associations
123 * @param[in] owner - The Dbus service having it's associatons
124 * changed
125 * @param[in,out] assocOwners - Owners of associations
126 * @param[in,out] assocInterfaces - Associations endpoints
127 *
128 * @return Void, objectServer and assocOwners updated if needed
129 */
130void associationChanged(sdbusplus::asio::object_server& objectServer,
131 const std::vector<Association>& associations,
132 const std::string& path, const std::string& owner,
133 AssociationOwnersType& assocOwners,
134 AssociationInterfaces& assocInterfaces);