1a80a3af0SAndrew Geissler #pragma once
2a80a3af0SAndrew Geissler 
335396c10SMatt Spinler #include "types.hpp"
4a80a3af0SAndrew Geissler 
54511b33fSAndrew Geissler constexpr const char* XYZ_ASSOCIATION_INTERFACE =
64511b33fSAndrew Geissler     "xyz.openbmc_project.Association";
74511b33fSAndrew Geissler 
8a80a3af0SAndrew Geissler /** @brief Remove input association
9a80a3af0SAndrew Geissler  *
10a80a3af0SAndrew Geissler  * @param[in] sourcePath          - Path of the object that contains the
11a80a3af0SAndrew Geissler  *                                  org.openbmc.Associations
12a80a3af0SAndrew Geissler  * @param[in] owner               - The Dbus service having its associations
13a80a3af0SAndrew Geissler  *                                  removed
14a80a3af0SAndrew Geissler  * @param[in,out] server          - sdbus system object
15e2359fb7SMatt Spinler  * @param[in,out] assocMaps       - The association maps
16a80a3af0SAndrew Geissler  *
17e2359fb7SMatt Spinler  * @return Void, server, assocMaps updated if needed
18a80a3af0SAndrew Geissler  */
19a80a3af0SAndrew Geissler void removeAssociation(const std::string& sourcePath, const std::string& owner,
20a80a3af0SAndrew Geissler                        sdbusplus::asio::object_server& server,
21e2359fb7SMatt Spinler                        AssociationMaps& assocMaps);
22ff5ce924SAndrew Geissler 
23ff5ce924SAndrew Geissler /** @brief Remove input paths from endpoints of an association
24ff5ce924SAndrew Geissler  *
25ff5ce924SAndrew Geissler  * If the last endpoint was removed, then remove the whole
26ff5ce924SAndrew Geissler  * association object, otherwise just set the property
27ff5ce924SAndrew Geissler  *
28ff5ce924SAndrew Geissler  * @param[in] objectServer        - sdbus system object
29ff5ce924SAndrew Geissler  * @param[in] assocPath           - Path of the object that contains the
30ff5ce924SAndrew Geissler  *                                  org.openbmc.Associations
31ff5ce924SAndrew Geissler  * @param[in] endpointsToRemove   - Endpoints to remove
32e2359fb7SMatt Spinler  * @param[in,out] assocMaps       - The association maps
33ff5ce924SAndrew Geissler  *
34e2359fb7SMatt Spinler  * @return Void, objectServer and assocMaps updated if needed
35ff5ce924SAndrew Geissler  */
36ff5ce924SAndrew Geissler void removeAssociationEndpoints(
37ff5ce924SAndrew Geissler     sdbusplus::asio::object_server& objectServer, const std::string& assocPath,
38ff5ce924SAndrew Geissler     const boost::container::flat_set<std::string>& endpointsToRemove,
39e2359fb7SMatt Spinler     AssociationMaps& assocMaps);
407f1c44dcSAndrew Geissler 
417f1c44dcSAndrew Geissler /** @brief Check and remove any changed associations
427f1c44dcSAndrew Geissler  *
437f1c44dcSAndrew Geissler  * Based on the latest values of the org.openbmc.Associations.associations
447f1c44dcSAndrew Geissler  * property, passed in via the newAssociations param, check if any of the
457f1c44dcSAndrew Geissler  * paths in the xyz.openbmc_project.Association.endpoints D-Bus property
467f1c44dcSAndrew Geissler  * for that association need to be removed.  If the last path is removed
477f1c44dcSAndrew Geissler  * from the endpoints property, remove that whole association object from
487f1c44dcSAndrew Geissler  * D-Bus.
497f1c44dcSAndrew Geissler  *
507f1c44dcSAndrew Geissler  * @param[in] sourcePath         - Path of the object that contains the
517f1c44dcSAndrew Geissler  *                                 org.openbmc.Associations
527f1c44dcSAndrew Geissler  * @param[in] owner              - The Dbus service having it's associatons
537f1c44dcSAndrew Geissler  *                                 changed
547f1c44dcSAndrew Geissler  * @param[in] newAssociations    - New associations to look at for change
557f1c44dcSAndrew Geissler  * @param[in,out] objectServer   - sdbus system object
56e2359fb7SMatt Spinler  * @param[in,out] assocMaps      - The association maps
577f1c44dcSAndrew Geissler  *
58e2359fb7SMatt Spinler  * @return Void, objectServer and assocMaps updated if needed
597f1c44dcSAndrew Geissler  */
607f1c44dcSAndrew Geissler void checkAssociationEndpointRemoves(
617f1c44dcSAndrew Geissler     const std::string& sourcePath, const std::string& owner,
627f1c44dcSAndrew Geissler     const AssociationPaths& newAssociations,
63e2359fb7SMatt Spinler     sdbusplus::asio::object_server& objectServer, AssociationMaps& assocMaps);
644511b33fSAndrew Geissler 
654511b33fSAndrew Geissler /** @brief Handle new or changed association interfaces
664511b33fSAndrew Geissler  *
674511b33fSAndrew Geissler  * Called when either a new org.openbmc.Associations interface was
684511b33fSAndrew Geissler  * created, or the associations property on that interface changed
694511b33fSAndrew Geissler  *
704511b33fSAndrew Geissler  * @param[in,out] objectServer    - sdbus system object
714511b33fSAndrew Geissler  * @param[in] associations        - New associations to look at for change
724511b33fSAndrew Geissler  * @param[in] path                - Path of the object that contains the
734511b33fSAndrew Geissler  *                                  org.openbmc.Associations
744511b33fSAndrew Geissler  * @param[in] owner               - The Dbus service having it's associatons
754511b33fSAndrew Geissler  *                                  changed
76*e0b0e3a2SMatt Spinler  * @param[in] interfaceMap        - The full interface map
77e2359fb7SMatt Spinler  * @param[in,out] assocMaps       - The association maps
784511b33fSAndrew Geissler  *
79e2359fb7SMatt Spinler  * @return Void, objectServer and assocMaps updated if needed
804511b33fSAndrew Geissler  */
814511b33fSAndrew Geissler void associationChanged(sdbusplus::asio::object_server& objectServer,
824511b33fSAndrew Geissler                         const std::vector<Association>& associations,
834511b33fSAndrew Geissler                         const std::string& path, const std::string& owner,
84*e0b0e3a2SMatt Spinler                         const interface_map_type& interfaceMap,
85*e0b0e3a2SMatt Spinler                         AssociationMaps& assocMaps);
86*e0b0e3a2SMatt Spinler 
87*e0b0e3a2SMatt Spinler /** @brief Add a pending associations entry
88*e0b0e3a2SMatt Spinler  *
89*e0b0e3a2SMatt Spinler  *  Used when a client wants to create an association between
90*e0b0e3a2SMatt Spinler  *  2 D-Bus endpoint paths, but one of the paths doesn't exist.
91*e0b0e3a2SMatt Spinler  *  When the path does show up in D-Bus, if there is a pending
92*e0b0e3a2SMatt Spinler  *  association then the real association objects can be created.
93*e0b0e3a2SMatt Spinler  *
94*e0b0e3a2SMatt Spinler  * @param[in] objectPath    - The D-Bus object path that should be an
95*e0b0e3a2SMatt Spinler  *                            association endpoint but doesn't exist
96*e0b0e3a2SMatt Spinler  *                            on D-Bus.
97*e0b0e3a2SMatt Spinler  * @param[in] type          - The association type.  Gets used in the final
98*e0b0e3a2SMatt Spinler  *                            association path of <objectPath>/<type>.
99*e0b0e3a2SMatt Spinler  * @param[in] endpointPath  - The D-Bus path on the other side
100*e0b0e3a2SMatt Spinler  *                            of the association. This path exists.
101*e0b0e3a2SMatt Spinler  * @param[in] endpointType  - The endpoint association type. Gets used
102*e0b0e3a2SMatt Spinler  *                            in the final association path of
103*e0b0e3a2SMatt Spinler  *                            <endpointPath>/<endpointType>.
104*e0b0e3a2SMatt Spinler  * @param[in] owner         - The service name that owns the association.
105*e0b0e3a2SMatt Spinler  * @param[in,out] assocMaps - The association maps
106*e0b0e3a2SMatt Spinler  */
107*e0b0e3a2SMatt Spinler void addPendingAssociation(const std::string& objectPath,
108*e0b0e3a2SMatt Spinler                            const std::string& type,
109*e0b0e3a2SMatt Spinler                            const std::string& endpointPath,
110*e0b0e3a2SMatt Spinler                            const std::string& endpointType,
111*e0b0e3a2SMatt Spinler                            const std::string& owner,
112e2359fb7SMatt Spinler                            AssociationMaps& assocMaps);
113