diff --git a/netsim/CMakeLists.txt b/netsim/CMakeLists.txt index e5e650d..cc3d3ca 100644 --- a/netsim/CMakeLists.txt +++ b/netsim/CMakeLists.txt @@ -1,6 +1,7 @@ add_library(libnetsim STATIC "src/Device.cpp" "src/Network.cpp" + "src/Port.cpp" ) target_include_directories(libnetsim PUBLIC diff --git a/netsim/include/Device.hpp b/netsim/include/Device.hpp index 096141e..2e1bab8 100644 --- a/netsim/include/Device.hpp +++ b/netsim/include/Device.hpp @@ -5,6 +5,8 @@ #include #include +class Port; + class Device { public: friend std::ostream& operator<<(std::ostream& os, const Device& device); @@ -24,6 +26,9 @@ public: private: void parseAndSetMac(const std::string& macAddress); +private: + std::shared_ptr port; + public: uint8_t macAddress[6]; }; \ No newline at end of file diff --git a/netsim/include/Port.hpp b/netsim/include/Port.hpp new file mode 100644 index 0000000..3fe099b --- /dev/null +++ b/netsim/include/Port.hpp @@ -0,0 +1,20 @@ +#pragma once + +#include +#include + +class Device; + +class Port { +public: + Port(); + + void Connect(std::shared_ptr port); + + void Send(const std::vector& data); + std::vector Receive(); + +private: + std::vector data; + std::weak_ptr connection; +}; \ No newline at end of file diff --git a/netsim/src/Device.cpp b/netsim/src/Device.cpp index fbfdf36..bc5d56c 100644 --- a/netsim/src/Device.cpp +++ b/netsim/src/Device.cpp @@ -3,7 +3,10 @@ #include #include +#include "Port.hpp" + Device::Device(const std::string& macAddress) { + port = std::make_shared(); parseAndSetMac(macAddress); } diff --git a/netsim/src/Port.cpp b/netsim/src/Port.cpp new file mode 100644 index 0000000..5a3a52c --- /dev/null +++ b/netsim/src/Port.cpp @@ -0,0 +1,23 @@ +#include "Port.hpp" + +Port::Port() +{ + +} + +void Port::Connect(std::shared_ptr port) { + this->connection = std::weak_ptr(port); +} + +void Port::Send(const std::vector& data) { + this->data = data; +} + +std::vector Port::Receive() { + if (this->connection.expired()) { + return {}; + } + + std::shared_ptr other_port = connection.lock(); + return other_port->data; +} \ No newline at end of file