Topology::addBoard: extract addDownstreamPort
Extract separate function for adding a downstream port since there are
different steps done there based on the schema syntax.
Tested: Topology Unit Tests pass. Straightforward function extraction,
everything passed by reference.
Change-Id: I2b9096842f27b0b4d81975633c0954acb4346c4d
Signed-off-by: Alexander Hansen <alexander.hansen@9elements.com>
diff --git a/src/entity_manager/topology.cpp b/src/entity_manager/topology.cpp
index 2142cdf..1238447 100644
--- a/src/entity_manager/topology.cpp
+++ b/src/entity_manager/topology.cpp
@@ -18,27 +18,36 @@
if (exposesType == "DownstreamPort")
{
- auto findConnectsTo = exposesItem.find("ConnectsToType");
- if (findConnectsTo == exposesItem.end())
- {
- std::cerr << "Board at path " << path
- << " is missing ConnectsToType" << std::endl;
- return;
- }
- PortType connectsTo = findConnectsTo->get<std::string>();
-
- downstreamPorts[connectsTo].emplace_back(path);
- boardTypes[path] = boardType;
- auto findPoweredBy = exposesItem.find("PowerPort");
- if (findPoweredBy != exposesItem.end())
- {
- powerPaths.insert(path);
- }
+ addDownstreamPort(path, exposesItem);
}
else if (exposesType.ends_with("Port"))
{
upstreamPorts[exposesType].emplace_back(path);
- boardTypes[path] = boardType;
+ }
+ else
+ {
+ return;
+ }
+ boardTypes[path] = boardType;
+}
+
+void Topology::addDownstreamPort(const Path& path,
+ const nlohmann::json& exposesItem)
+{
+ auto findConnectsTo = exposesItem.find("ConnectsToType");
+ if (findConnectsTo == exposesItem.end())
+ {
+ std::cerr << "Board at path " << path << " is missing ConnectsToType"
+ << std::endl;
+ return;
+ }
+ PortType connectsTo = findConnectsTo->get<std::string>();
+
+ downstreamPorts[connectsTo].emplace_back(path);
+ auto findPoweredBy = exposesItem.find("PowerPort");
+ if (findPoweredBy != exposesItem.end())
+ {
+ powerPaths.insert(path);
}
}
diff --git a/src/entity_manager/topology.hpp b/src/entity_manager/topology.hpp
index 816704a..7317b3a 100644
--- a/src/entity_manager/topology.hpp
+++ b/src/entity_manager/topology.hpp
@@ -25,6 +25,8 @@
using BoardName = std::string;
using PortType = std::string;
+ void addDownstreamPort(const Path& path, const nlohmann::json& exposesItem);
+
std::unordered_map<PortType, std::vector<Path>> upstreamPorts;
std::unordered_map<PortType, std::vector<Path>> downstreamPorts;
std::set<Path> powerPaths;