13b025e69SAndrew Geissler #pragma once
23b025e69SAndrew Geissler 
32067926aSAndrew Geissler #include "associations.hpp"
42067926aSAndrew Geissler 
53b025e69SAndrew Geissler #include <boost/container/flat_map.hpp>
682815dacSAndrew Geissler #include <boost/container/flat_set.hpp>
73b025e69SAndrew Geissler #include <string>
83b025e69SAndrew Geissler 
982815dacSAndrew Geissler /** @brief Define white list and black list data structure */
1082815dacSAndrew Geissler using WhiteBlackList = boost::container::flat_set<std::string>;
1182815dacSAndrew Geissler 
122067926aSAndrew Geissler /** @brief Dbus interface which contains org.openbmc Associations */
132067926aSAndrew Geissler constexpr const char* ASSOCIATIONS_INTERFACE = "org.openbmc.Associations";
142067926aSAndrew Geissler 
152067926aSAndrew Geissler /** @brief interface_map_type is the underlying datastructure the mapper uses.
162067926aSAndrew Geissler  *
172067926aSAndrew Geissler  * The 3 levels of map are
182067926aSAndrew Geissler  * object paths
192067926aSAndrew Geissler  *   connection names
202067926aSAndrew Geissler  *      interface names
212067926aSAndrew Geissler  */
222067926aSAndrew Geissler using interface_map_type = boost::container::flat_map<
232067926aSAndrew Geissler     std::string, boost::container::flat_map<
242067926aSAndrew Geissler                      std::string, boost::container::flat_set<std::string>>>;
252067926aSAndrew Geissler 
26*70461896SAndrew Geissler /** @brief InterfacesAdded represents the dbus data from the signal
27*70461896SAndrew Geissler  *
28*70461896SAndrew Geissler  * There are 2 pairs
29*70461896SAndrew Geissler  * pair1: D-bus Interface,vector[pair2]
30*70461896SAndrew Geissler  * pair2: D-bus Method,vector[Associations]
31*70461896SAndrew Geissler  */
32*70461896SAndrew Geissler using InterfacesAdded = std::vector<std::pair<
33*70461896SAndrew Geissler     std::string,
34*70461896SAndrew Geissler     std::vector<std::pair<
35*70461896SAndrew Geissler         std::string, sdbusplus::message::variant<std::vector<Association>>>>>>;
36*70461896SAndrew Geissler 
373b025e69SAndrew Geissler /** @brief Get well known name of input unique name
383b025e69SAndrew Geissler  *
393b025e69SAndrew Geissler  * If user passes in well known name then that will be returned.
403b025e69SAndrew Geissler  *
413b025e69SAndrew Geissler  * @param[in] owners       - Current list of owners
423b025e69SAndrew Geissler  * @param[in] request      - The name to look up
433b025e69SAndrew Geissler  * @param[out] wellKnown   - The well known name if found
443b025e69SAndrew Geissler  *
453b025e69SAndrew Geissler  * @return True if well known name is found, false otherwise
463b025e69SAndrew Geissler  */
473b025e69SAndrew Geissler bool getWellKnown(
483b025e69SAndrew Geissler     const boost::container::flat_map<std::string, std::string>& owners,
4982815dacSAndrew Geissler     const std::string& request, std::string& well_known);
5082815dacSAndrew Geissler 
5182815dacSAndrew Geissler /** @brief Determine if dbus service is something to monitor
5282815dacSAndrew Geissler  *
5382815dacSAndrew Geissler  * mapper supports a whitelist and blacklist concept. If a whitelist is provided
5482815dacSAndrew Geissler  * as input then only dbus objects matching that list is monitored. If a
5582815dacSAndrew Geissler  * blacklist is provided then objects matching it will not be monitored.
5682815dacSAndrew Geissler  *
5782815dacSAndrew Geissler  * @param[in] processName   - Dbus service name
5882815dacSAndrew Geissler  * @param[in] whiteList     - The white list
5982815dacSAndrew Geissler  * @param[in] blackList     - The black list
6082815dacSAndrew Geissler  *
6182815dacSAndrew Geissler  * @return True if input process_name should be monitored, false otherwise
6282815dacSAndrew Geissler  */
6382815dacSAndrew Geissler bool needToIntrospect(const std::string& processName,
6482815dacSAndrew Geissler                       const WhiteBlackList& whiteList,
6582815dacSAndrew Geissler                       const WhiteBlackList& blackList);
662067926aSAndrew Geissler 
672067926aSAndrew Geissler /** @brief Handle the removal of an existing name in objmgr data structures
682067926aSAndrew Geissler  *
692067926aSAndrew Geissler  * @param[in,out] nameOwners      - Map of unique name to well known name
702067926aSAndrew Geissler  * @param[in]     wellKnown       - Well known name that has new owner
712067926aSAndrew Geissler  * @param[in]     oldOwner        - Old unique name
722067926aSAndrew Geissler  * @param[in,out] interfaceMap    - Map of interfaces
732067926aSAndrew Geissler  * @param[in,out] assocOwners     - Owners of associations
742067926aSAndrew Geissler  * @param[in,out] assocInterfaces - Associations endpoints
752067926aSAndrew Geissler  * @param[in,out] server          - sdbus system object
762067926aSAndrew Geissler  *
772067926aSAndrew Geissler  */
782067926aSAndrew Geissler void processNameChangeDelete(
792067926aSAndrew Geissler     boost::container::flat_map<std::string, std::string>& nameOwners,
802067926aSAndrew Geissler     const std::string& wellKnown, const std::string& oldOwner,
812067926aSAndrew Geissler     interface_map_type& interfaceMap, AssociationOwnersType& assocOwners,
822067926aSAndrew Geissler     AssociationInterfaces& assocInterfaces,
832067926aSAndrew Geissler     sdbusplus::asio::object_server& server);
84*70461896SAndrew Geissler 
85*70461896SAndrew Geissler /** @brief Handle an interfaces added signal
86*70461896SAndrew Geissler  *
87*70461896SAndrew Geissler  * @param[in,out] interfaceMap    - Global map of interfaces
88*70461896SAndrew Geissler  * @param[in]     objPath         - New path to process
89*70461896SAndrew Geissler  * @param[in]     interfacesAdded - New interfaces to process
90*70461896SAndrew Geissler  * @param[in]     wellKnown       - Well known name that has new owner
91*70461896SAndrew Geissler  * @param[in,out] assocOwners     - Owners of associations
92*70461896SAndrew Geissler  * @param[in,out] assocInterfaces - Associations endpoints
93*70461896SAndrew Geissler  * @param[in,out] server          - sdbus system object
94*70461896SAndrew Geissler  *
95*70461896SAndrew Geissler  */
96*70461896SAndrew Geissler void processInterfaceAdded(interface_map_type& interfaceMap,
97*70461896SAndrew Geissler                            const sdbusplus::message::object_path& objPath,
98*70461896SAndrew Geissler                            const InterfacesAdded& intfAdded,
99*70461896SAndrew Geissler                            const std::string& wellKnown,
100*70461896SAndrew Geissler                            AssociationOwnersType& assocOwners,
101*70461896SAndrew Geissler                            AssociationInterfaces& assocInterfaces,
102*70461896SAndrew Geissler                            sdbusplus::asio::object_server& server);
103