blob: 1c2b3ebaebb1ca784f5f030f193db08aecf7737f [file] [log] [blame]
Benjamin Fairf2f5b7a2022-09-09 19:45:02 +00001#pragma once
2
3#include <nlohmann/json.hpp>
4
5#include <set>
6#include <unordered_map>
7
8using Association = std::tuple<std::string, std::string, std::string>;
9
Alexander Hansen32e74182025-08-20 16:16:00 +020010using BoardPathsView = decltype(std::views::keys(
11 std::declval<std::map<std::string, std::string>&>()));
12
Benjamin Fairf2f5b7a2022-09-09 19:45:02 +000013class Topology
14{
15 public:
16 explicit Topology() = default;
17
18 void addBoard(const std::string& path, const std::string& boardType,
Matt Spinler6eb60972023-08-14 16:36:20 -050019 const std::string& boardName,
Benjamin Fairf2f5b7a2022-09-09 19:45:02 +000020 const nlohmann::json& exposesItem);
Alexander Hansen0519f572025-08-19 18:11:04 +020021 std::unordered_map<std::string, std::set<Association>> getAssocs(
Alexander Hansen32e74182025-08-20 16:16:00 +020022 BoardPathsView boardPaths);
Matt Spinler6eb60972023-08-14 16:36:20 -050023 void remove(const std::string& boardName);
Benjamin Fairf2f5b7a2022-09-09 19:45:02 +000024
25 private:
26 using Path = std::string;
27 using BoardType = std::string;
Matt Spinler6eb60972023-08-14 16:36:20 -050028 using BoardName = std::string;
Benjamin Fairf2f5b7a2022-09-09 19:45:02 +000029 using PortType = std::string;
30
Alexander Hansenec938ad2025-08-19 16:48:44 +020031 void addDownstreamPort(const Path& path, const nlohmann::json& exposesItem);
32
Alexander Hansen7cfc0432025-08-20 14:43:04 +020033 std::unordered_map<PortType, std::set<Path>> upstreamPorts;
34 std::unordered_map<PortType, std::set<Path>> downstreamPorts;
Jeff Linb02752f2023-12-01 11:23:54 +080035 std::set<Path> powerPaths;
Benjamin Fairf2f5b7a2022-09-09 19:45:02 +000036 std::unordered_map<Path, BoardType> boardTypes;
Matt Spinler6eb60972023-08-14 16:36:20 -050037 std::unordered_map<BoardName, Path> boardNames;
Benjamin Fairf2f5b7a2022-09-09 19:45:02 +000038};