diff --git a/source/gns3/GnsProject.cpp b/source/gns3/GnsProject.cpp index 851390e..7bd7531 100644 --- a/source/gns3/GnsProject.cpp +++ b/source/gns3/GnsProject.cpp @@ -23,8 +23,8 @@ std::string GnsProject::getUuid() const { return this->uuid; } -std::vector GnsProject::getNodes() const { - std::vector nodes; +std::vector> GnsProject::getNodes() const { + std::vector> nodes; // request the API endpoint cpr::Url endpoint = this->getApiBase() + "nodes"; @@ -59,11 +59,11 @@ std::vector GnsProject::getNodes() const { } // save the node - nodes.emplace_back( + nodes.emplace_back(std::make_shared( this, node_data["node_id"], ports - ); + )); } return nodes; diff --git a/source/gns3/GnsProject.hpp b/source/gns3/GnsProject.hpp index 3c1c383..963b08e 100644 --- a/source/gns3/GnsProject.hpp +++ b/source/gns3/GnsProject.hpp @@ -1,4 +1,5 @@ #pragma once +#include #include #include @@ -34,7 +35,7 @@ public: * Get all the nodes of the project * @return all the nodes of the project */ - [[nodiscard]] std::vector getNodes() const; + [[nodiscard]] std::vector> getNodes() const; private: const GnsServer* server; diff --git a/source/gns3/GnsServer.cpp b/source/gns3/GnsServer.cpp index 43ad603..6b1161b 100644 --- a/source/gns3/GnsServer.cpp +++ b/source/gns3/GnsServer.cpp @@ -17,8 +17,8 @@ std::string GnsServer::getApiBase() const { return "http://" + this->host + ":" + std::to_string(this->port) + "/v2/"; } -std::vector GnsServer::getProjects() const { - std::vector projects; +std::vector> GnsServer::getProjects() const { + std::vector> projects; // request the API endpoint cpr::Url endpoint = this->getApiBase() + "projects"; @@ -38,20 +38,20 @@ std::vector GnsServer::getProjects() const { // deserialize the projects projects.reserve(data.size()); for (const auto& project_data : data) - projects.emplace_back( + projects.emplace_back(std::make_shared( this, project_data["project_id"] - ); + )); return projects; } -std::vector GnsServer::getNodes() const { - std::vector nodes; +std::vector> GnsServer::getNodes() const { + std::vector> nodes; // get all the nodes from all the projects - for (const GnsProject& project : this->getProjects()) { - std::vector project_nodes = project.getNodes(); + for (const std::shared_ptr& project : this->getProjects()) { + std::vector> project_nodes = project->getNodes(); nodes.insert(nodes.end(), project_nodes.begin(), project_nodes.end()); } diff --git a/source/gns3/GnsServer.hpp b/source/gns3/GnsServer.hpp index be95bf1..f90894a 100644 --- a/source/gns3/GnsServer.hpp +++ b/source/gns3/GnsServer.hpp @@ -1,6 +1,7 @@ #pragma once #include #include +#include #include #include "GnsProject.hpp" @@ -27,13 +28,13 @@ public: * Get all the projects in the server * @return all the projects in the server */ - [[nodiscard]] std::vector getProjects() const; + [[nodiscard]] std::vector> getProjects() const; /** * Get all the nodes in the server * @return all the nodes in the server */ - [[nodiscard]] std::vector getNodes() const; + [[nodiscard]] std::vector> getNodes() const; private: std::string host; diff --git a/source/main.cpp b/source/main.cpp index cda5028..2a6152e 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -50,11 +50,11 @@ void packet_wol_handler( // TODO(Faraphel): check the 16 repetitions of the source address ? // find the machine with the mac address - for (const gns::GnsNode& node : gnsServer->getNodes()) - for (const gns::GnsPort& port : node.getPorts()) + for (const std::shared_ptr& node : gnsServer->getNodes()) + for (const gns::GnsPort& port : node->getPorts()) if (port.mac_address == mac_address_target) { - std::cout << "Matching node: " + node.getUuid() << std::endl; - node.start(); + std::cout << "Matching node: " + node->getUuid() << std::endl; + node->start(); std::cout << "Node started." << std::endl; return; }