add ports
This commit is contained in:
parent
dc966782b5
commit
89fcef5619
5 changed files with 52 additions and 0 deletions
|
@ -3,7 +3,10 @@
|
|||
#include <sstream>
|
||||
#include <iostream>
|
||||
|
||||
#include "Port.hpp"
|
||||
|
||||
Device::Device(const std::string& macAddress) {
|
||||
port = std::make_shared<Port>();
|
||||
parseAndSetMac(macAddress);
|
||||
}
|
||||
|
||||
|
|
23
netsim/src/Port.cpp
Normal file
23
netsim/src/Port.cpp
Normal file
|
@ -0,0 +1,23 @@
|
|||
#include "Port.hpp"
|
||||
|
||||
Port::Port()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void Port::Connect(std::shared_ptr<Port> port) {
|
||||
this->connection = std::weak_ptr<Port>(port);
|
||||
}
|
||||
|
||||
void Port::Send(const std::vector<uint8_t>& data) {
|
||||
this->data = data;
|
||||
}
|
||||
|
||||
std::vector<uint8_t> Port::Receive() {
|
||||
if (this->connection.expired()) {
|
||||
return {};
|
||||
}
|
||||
|
||||
std::shared_ptr<Port> other_port = connection.lock();
|
||||
return other_port->data;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue