Benjamin Fair | f2f5b7a | 2022-09-09 19:45:02 +0000 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include <nlohmann/json.hpp> |
| 4 | |
| 5 | #include <set> |
| 6 | #include <unordered_map> |
| 7 | |
| 8 | using Association = std::tuple<std::string, std::string, std::string>; |
| 9 | |
Alexander Hansen | 32e7418 | 2025-08-20 16:16:00 +0200 | [diff] [blame] | 10 | using BoardPathsView = decltype(std::views::keys( |
| 11 | std::declval<std::map<std::string, std::string>&>())); |
| 12 | |
Alexander Hansen | 7b2a77f | 2025-08-27 12:27:57 +0200 | [diff] [blame^] | 13 | class AssocName |
| 14 | { |
| 15 | public: |
| 16 | std::string name; |
| 17 | std::string reverse; |
| 18 | |
| 19 | AssocName(const std::string& name, const std::string& reverse); |
| 20 | AssocName() = delete; |
| 21 | |
| 22 | AssocName getReverse() const; |
| 23 | |
| 24 | bool operator==(const AssocName& other) const = default; |
| 25 | bool operator<(const AssocName& other) const; |
| 26 | }; |
| 27 | |
Benjamin Fair | f2f5b7a | 2022-09-09 19:45:02 +0000 | [diff] [blame] | 28 | class Topology |
| 29 | { |
| 30 | public: |
| 31 | explicit Topology() = default; |
| 32 | |
| 33 | void addBoard(const std::string& path, const std::string& boardType, |
Matt Spinler | 6eb6097 | 2023-08-14 16:36:20 -0500 | [diff] [blame] | 34 | const std::string& boardName, |
Benjamin Fair | f2f5b7a | 2022-09-09 19:45:02 +0000 | [diff] [blame] | 35 | const nlohmann::json& exposesItem); |
Alexander Hansen | 0519f57 | 2025-08-19 18:11:04 +0200 | [diff] [blame] | 36 | std::unordered_map<std::string, std::set<Association>> getAssocs( |
Alexander Hansen | 32e7418 | 2025-08-20 16:16:00 +0200 | [diff] [blame] | 37 | BoardPathsView boardPaths); |
Matt Spinler | 6eb6097 | 2023-08-14 16:36:20 -0500 | [diff] [blame] | 38 | void remove(const std::string& boardName); |
Benjamin Fair | f2f5b7a | 2022-09-09 19:45:02 +0000 | [diff] [blame] | 39 | |
| 40 | private: |
| 41 | using Path = std::string; |
| 42 | using BoardType = std::string; |
Matt Spinler | 6eb6097 | 2023-08-14 16:36:20 -0500 | [diff] [blame] | 43 | using BoardName = std::string; |
Benjamin Fair | f2f5b7a | 2022-09-09 19:45:02 +0000 | [diff] [blame] | 44 | using PortType = std::string; |
| 45 | |
Alexander Hansen | ec938ad | 2025-08-19 16:48:44 +0200 | [diff] [blame] | 46 | void addDownstreamPort(const Path& path, const nlohmann::json& exposesItem); |
| 47 | |
Alexander Hansen | d7be0ee | 2025-08-20 14:16:15 +0200 | [diff] [blame] | 48 | // @brief: fill associations map with the associations for a port identifier |
| 49 | // such as 'MB Upstream Port' |
| 50 | void fillAssocsForPortId( |
| 51 | std::unordered_map<std::string, std::set<Association>>& result, |
Alexander Hansen | 68e2b0f | 2025-08-21 17:44:18 +0200 | [diff] [blame] | 52 | BoardPathsView boardPaths, |
| 53 | const std::map<Path, std::set<AssocName>>& pathAssocs); |
Alexander Hansen | d7be0ee | 2025-08-20 14:16:15 +0200 | [diff] [blame] | 54 | |
Alexander Hansen | 97a1c93 | 2025-08-20 16:28:52 +0200 | [diff] [blame] | 55 | void fillAssocForPortId( |
| 56 | std::unordered_map<std::string, std::set<Association>>& result, |
Alexander Hansen | 68e2b0f | 2025-08-21 17:44:18 +0200 | [diff] [blame] | 57 | BoardPathsView boardPaths, const Path& upstream, const Path& downstream, |
| 58 | const AssocName& assocName); |
| 59 | |
| 60 | void addPort(const PortType& port, const Path& path, |
| 61 | const AssocName& assocName); |
Alexander Hansen | 97a1c93 | 2025-08-20 16:28:52 +0200 | [diff] [blame] | 62 | |
Alexander Hansen | 68e2b0f | 2025-08-21 17:44:18 +0200 | [diff] [blame] | 63 | // Maps the port name to the participating paths. |
| 64 | // each path also has their role(s) in the association. |
| 65 | // For example a PSU path which is part of "MB Upstream Port" |
| 66 | // will have "powering" role. |
| 67 | std::unordered_map<PortType, std::map<Path, std::set<AssocName>>> ports; |
| 68 | |
Benjamin Fair | f2f5b7a | 2022-09-09 19:45:02 +0000 | [diff] [blame] | 69 | std::unordered_map<Path, BoardType> boardTypes; |
Matt Spinler | 6eb6097 | 2023-08-14 16:36:20 -0500 | [diff] [blame] | 70 | std::unordered_map<BoardName, Path> boardNames; |
Benjamin Fair | f2f5b7a | 2022-09-09 19:45:02 +0000 | [diff] [blame] | 71 | }; |