From ddf35406c35bced86b1b583271721d7cd7a301bd Mon Sep 17 00:00:00 2001 From: Robert Date: Sun, 2 Jul 2023 18:24:59 +0200 Subject: [PATCH] add test setup --- gui/src/main.cpp | 10 +++++++++- netsim/include/Device.hpp | 6 ++++-- netsim/src/Device.cpp | 6 ++++++ 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/gui/src/main.cpp b/gui/src/main.cpp index 43c1c12..93f6750 100644 --- a/gui/src/main.cpp +++ b/gui/src/main.cpp @@ -32,6 +32,14 @@ int main(int argc, char** argv) { Network network("Testnet"); NetworkRenderer networkRenderer(network); + auto dev1 = Device::Create(); + auto dev2 = Device::Create(); + + dev1->Connect(dev2); + + networkRenderer.AddDevice(dev1, 300, 400); + networkRenderer.AddDevice(dev2, 500, 400); + bool shouldClose = false; SDL_Event event; @@ -66,7 +74,7 @@ int main(int argc, char** argv) { if (ImGui::BeginMenu("New...")) { if (ImGui::MenuItem("Host")) { - auto device = Device::create(); + auto device = Device::Create(); network.addDevice(device); networkRenderer.AddDevice(device, 400, 400); diff --git a/netsim/include/Device.hpp b/netsim/include/Device.hpp index 2e1bab8..0fcfa56 100644 --- a/netsim/include/Device.hpp +++ b/netsim/include/Device.hpp @@ -15,14 +15,16 @@ public: Device(const std::string& macAddress); Device(uint8_t a, uint8_t b, uint8_t c, uint8_t d, uint8_t e, uint8_t f); - inline static std::shared_ptr create(const std::string& macAddress) { + inline static std::shared_ptr Create(const std::string& macAddress) { return std::make_shared(macAddress); } - inline static std::shared_ptr create() { + inline static std::shared_ptr Create() { return std::make_shared(rand() % 256, rand() % 256, rand() % 256, rand() % 256, rand() % 256, rand() % 256); } + void Connect(std::shared_ptr other); + private: void parseAndSetMac(const std::string& macAddress); diff --git a/netsim/src/Device.cpp b/netsim/src/Device.cpp index bc5d56c..abcf7d3 100644 --- a/netsim/src/Device.cpp +++ b/netsim/src/Device.cpp @@ -13,6 +13,7 @@ Device::Device(const std::string& macAddress) { Device::Device(uint8_t a, uint8_t b, uint8_t c, uint8_t d, uint8_t e, uint8_t f) : macAddress{a, b, c, d, e, f} { + port = std::make_shared(); } void Device::parseAndSetMac(const std::string& mac) { @@ -28,6 +29,11 @@ void Device::parseAndSetMac(const std::string& mac) { ); } +void Device::Connect(std::shared_ptr other) { + port->Connect(other->port); + other->port->Connect(port); +} + std::ostream& operator<<(std::ostream& os, const Device& device) { printf( "%02X:%02X:%02X:%02X:%02X:%02X",