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 | |
Benjamin Fair | f2f5b7a | 2022-09-09 19:45:02 +0000 | [diff] [blame] | 13 | class Topology |
| 14 | { |
| 15 | public: |
| 16 | explicit Topology() = default; |
| 17 | |
| 18 | void addBoard(const std::string& path, const std::string& boardType, |
Matt Spinler | 6eb6097 | 2023-08-14 16:36:20 -0500 | [diff] [blame] | 19 | const std::string& boardName, |
Benjamin Fair | f2f5b7a | 2022-09-09 19:45:02 +0000 | [diff] [blame] | 20 | const nlohmann::json& exposesItem); |
Alexander Hansen | 0519f57 | 2025-08-19 18:11:04 +0200 | [diff] [blame] | 21 | std::unordered_map<std::string, std::set<Association>> getAssocs( |
Alexander Hansen | 32e7418 | 2025-08-20 16:16:00 +0200 | [diff] [blame] | 22 | BoardPathsView boardPaths); |
Matt Spinler | 6eb6097 | 2023-08-14 16:36:20 -0500 | [diff] [blame] | 23 | void remove(const std::string& boardName); |
Benjamin Fair | f2f5b7a | 2022-09-09 19:45:02 +0000 | [diff] [blame] | 24 | |
| 25 | private: |
| 26 | using Path = std::string; |
| 27 | using BoardType = std::string; |
Matt Spinler | 6eb6097 | 2023-08-14 16:36:20 -0500 | [diff] [blame] | 28 | using BoardName = std::string; |
Benjamin Fair | f2f5b7a | 2022-09-09 19:45:02 +0000 | [diff] [blame] | 29 | using PortType = std::string; |
| 30 | |
Alexander Hansen | ec938ad | 2025-08-19 16:48:44 +0200 | [diff] [blame] | 31 | void addDownstreamPort(const Path& path, const nlohmann::json& exposesItem); |
| 32 | |
Alexander Hansen | ca121f5 | 2025-08-21 18:25:19 +0200 | [diff] [blame] | 33 | // e.g. contained_by, containing, powered_by, ... |
| 34 | using AssocName = std::string; |
| 35 | |
Alexander Hansen | d7be0ee | 2025-08-20 14:16:15 +0200 | [diff] [blame] | 36 | // @brief: fill associations map with the associations for a port identifier |
| 37 | // such as 'MB Upstream Port' |
| 38 | void fillAssocsForPortId( |
| 39 | std::unordered_map<std::string, std::set<Association>>& result, |
| 40 | BoardPathsView boardPaths, const std::set<Path>& upstreamPaths, |
| 41 | const std::set<Path>& downstreamPaths); |
| 42 | |
Alexander Hansen | 97a1c93 | 2025-08-20 16:28:52 +0200 | [diff] [blame] | 43 | void fillAssocForPortId( |
| 44 | std::unordered_map<std::string, std::set<Association>>& result, |
| 45 | BoardPathsView boardPaths, const Path& upstream, |
| 46 | const Path& downstream); |
| 47 | |
Alexander Hansen | ca121f5 | 2025-08-21 18:25:19 +0200 | [diff] [blame] | 48 | static std::optional<std::string> getOppositeAssoc( |
| 49 | const AssocName& assocName); |
| 50 | |
Alexander Hansen | 7cfc043 | 2025-08-20 14:43:04 +0200 | [diff] [blame] | 51 | std::unordered_map<PortType, std::set<Path>> upstreamPorts; |
| 52 | std::unordered_map<PortType, std::set<Path>> downstreamPorts; |
Jeff Lin | b02752f | 2023-12-01 11:23:54 +0800 | [diff] [blame] | 53 | std::set<Path> powerPaths; |
Benjamin Fair | f2f5b7a | 2022-09-09 19:45:02 +0000 | [diff] [blame] | 54 | std::unordered_map<Path, BoardType> boardTypes; |
Matt Spinler | 6eb6097 | 2023-08-14 16:36:20 -0500 | [diff] [blame] | 55 | std::unordered_map<BoardName, Path> boardNames; |
Benjamin Fair | f2f5b7a | 2022-09-09 19:45:02 +0000 | [diff] [blame] | 56 | }; |