blob: 7cd38422f416641e843f5ac6c48b92db9ef7ef81 [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 Geissler4511b332019-02-21 15:40:40 -060048using Association = std::tuple<std::string, std::string, std::string>;
49
Andrew Geisslera80a3af2019-02-04 14:01:49 -060050/** @brief Remove input association
51 *
52 * @param[in] sourcePath - Path of the object that contains the
53 * org.openbmc.Associations
54 * @param[in] owner - The Dbus service having its associations
55 * removed
56 * @param[in,out] server - sdbus system object
57 * @param[in,out] assocOwners - Owners of associations
58 * @param[in,out] assocInterfaces - Associations endpoints
59 *
60 * @return Void, server, assocOwners, and assocInterfaces updated if needed
61 */
62void removeAssociation(const std::string& sourcePath, const std::string& owner,
63 sdbusplus::asio::object_server& server,
64 AssociationOwnersType& assocOwners,
65 AssociationInterfaces& assocInterfaces);
Andrew Geisslerff5ce922019-02-21 12:43:09 -060066
67/** @brief Remove input paths from endpoints of an association
68 *
69 * If the last endpoint was removed, then remove the whole
70 * association object, otherwise just set the property
71 *
72 * @param[in] objectServer - sdbus system object
73 * @param[in] assocPath - Path of the object that contains the
74 * org.openbmc.Associations
75 * @param[in] endpointsToRemove - Endpoints to remove
76 * @param[in,out] assocInterfaces - Associations endpoints
77 *
78 * @return Void, objectServer and assocInterfaces updated if needed
79 */
80void removeAssociationEndpoints(
81 sdbusplus::asio::object_server& objectServer, const std::string& assocPath,
82 const boost::container::flat_set<std::string>& endpointsToRemove,
83 AssociationInterfaces& assocInterfaces);
Andrew Geissler7f1c44d2019-02-21 13:44:16 -060084
85/** @brief Check and remove any changed associations
86 *
87 * Based on the latest values of the org.openbmc.Associations.associations
88 * property, passed in via the newAssociations param, check if any of the
89 * paths in the xyz.openbmc_project.Association.endpoints D-Bus property
90 * for that association need to be removed. If the last path is removed
91 * from the endpoints property, remove that whole association object from
92 * D-Bus.
93 *
94 * @param[in] sourcePath - Path of the object that contains the
95 * org.openbmc.Associations
96 * @param[in] owner - The Dbus service having it's associatons
97 * changed
98 * @param[in] newAssociations - New associations to look at for change
99 * @param[in,out] objectServer - sdbus system object
100 * @param[in,out] assocOwners - Owners of associations
101 * @param[in,out] assocInterfaces - Associations endpoints
102 *
103 * @return Void, objectServer and assocOwners updated if needed
104 */
105void checkAssociationEndpointRemoves(
106 const std::string& sourcePath, const std::string& owner,
107 const AssociationPaths& newAssociations,
108 sdbusplus::asio::object_server& objectServer,
109 AssociationOwnersType& assocOwners, AssociationInterfaces& assocInterfaces);
Andrew Geissler4511b332019-02-21 15:40:40 -0600110
111/** @brief Handle new or changed association interfaces
112 *
113 * Called when either a new org.openbmc.Associations interface was
114 * created, or the associations property on that interface changed
115 *
116 * @param[in,out] objectServer - sdbus system object
117 * @param[in] associations - New associations to look at for change
118 * @param[in] path - Path of the object that contains the
119 * org.openbmc.Associations
120 * @param[in] owner - The Dbus service having it's associatons
121 * changed
122 * @param[in,out] assocOwners - Owners of associations
123 * @param[in,out] assocInterfaces - Associations endpoints
124 *
125 * @return Void, objectServer and assocOwners updated if needed
126 */
127void associationChanged(sdbusplus::asio::object_server& objectServer,
128 const std::vector<Association>& associations,
129 const std::string& path, const std::string& owner,
130 AssociationOwnersType& assocOwners,
131 AssociationInterfaces& assocInterfaces);