commit cb526d9979f3a9e40ad9f122a3f86706401d27db
parent 9e5faa950b38fa8a148e375839b351a241da73ed
Author: Bharatvaj H <bharatvaj@yahoo.com>
Date: Tue, 26 Mar 2019 23:42:11 +0530
parent 9e5faa950b38fa8a148e375839b351a241da73ed
Author: Bharatvaj H <bharatvaj@yahoo.com>
Date: Tue, 26 Mar 2019 23:42:11 +0530
Added connect functionality to Forwarder
8 files changed, 24 insertions(+), 14 deletions(-)
diff --git a/forwarder.cpp b/forwarder.cpp @@ -89,6 +89,7 @@ void start(shell4c::Operation op, vector<string> msg) { network.second->setOnDeviceConnected([](Device &d) { Forwarder::addDevice(&d); fmt::print("added device: {}\n", d.address); + Device *de = nc->activeNetworks["Bluetooth"]->connect("B8:"); }); network.second->listen(); }
diff --git a/include/Forwarder.hpp b/include/Forwarder.hpp @@ -6,7 +6,7 @@ #include <device/Device.hpp> -#define BUF_SIZE 20 +#define BUF_SIZE 256 namespace wa { class BindPair { @@ -56,7 +56,7 @@ public: forwarders.push_back(forwarder); forwarder->start(); } - } + } void start() { t1 = new std::thread([&]() {
diff --git a/include/network/Bluetooth.hpp b/include/network/Bluetooth.hpp @@ -54,6 +54,7 @@ public: // accept one connection comm_socket c = accept(s, (struct sockaddr *)&rem_addr, &opt); Device *d = (Device *)new BluetoothDevice(c); + d->address = "B8:27:EB:A5:A1:70"; devices.push_back(d); close(s); if (c == SOCKET_ERROR) { @@ -63,7 +64,7 @@ public: return 0; } - int connect(std::string conParams) { + Device *connect(std::string conParams) { struct sockaddr_rc addr = {0}; comm_socket s; const char *dest = conParams.c_str(); @@ -78,8 +79,11 @@ public: // connect to server int status = ::connect(s, (struct sockaddr *)&addr, sizeof(addr)); - devices.push_back((Device *)new BluetoothDevice(s)); - return status; + Device *d = (Device *)new BluetoothDevice(s); + if(status < 0){ + return nullptr; + } + return d; } // TODO
diff --git a/include/network/Console.hpp b/include/network/Console.hpp @@ -25,9 +25,9 @@ public: } // TODO - int connect(std::string conParam) override { + Device *connect(std::string conParam) override { devices.push_back((Device *)new ConsoleDevice()); - return 0; + return (Device *)new ConsoleDevice(); } std::vector<NetworkInfo> discover() override {
diff --git a/include/network/IP.hpp b/include/network/IP.hpp @@ -16,7 +16,7 @@ #include <network/Network.hpp> // TODO update value based on the hardware using cmake -#define W_DEFAULT_PORT 2500 +#define W_DEFAULT_PORT 21 using namespace std; @@ -44,9 +44,14 @@ public: std::string getUserFriendlyName() override { return _IP_H; } int listen() override { + cout << "IP listening" << endl; struct sockaddr_in peer; socklen_t peerLen = sizeof(peer); comm_socket fd = comm_start_server(W_DEFAULT_PORT); + if(fd < 0){ + cout << "Socket error" << endl; + } + cout << fd << endl; getsockname(fd, (struct sockaddr *)&peer, &peerLen); Device *d = (Device *)new IPDevice(fd); // FIXME NAMING ERROR @@ -63,13 +68,13 @@ public: int addDevice(std::string ipaddress) { return -1; } - int connect(std::string conParams) override { + Device *connect(std::string conParams) override { comm_socket fd = ::comm_connect_server(conParams.c_str(), W_DEFAULT_PORT); if (fd == SOCKET_ERROR) { - return -1; + return nullptr; } devices.push_back((Device *)new IPDevice(fd)); - return 0; + return (Device *)new IPDevice(0); } std::vector<NetworkInfo> discover() override {
diff --git a/include/network/Network.hpp b/include/network/Network.hpp @@ -38,7 +38,7 @@ public: // listen virtual int listen() = 0; // connects to the given address - virtual int connect(std::string) = 0; + virtual Device *connect(std::string) = 0; // discovers different networks virtual std::vector<NetworkInfo> discover() = 0; // should be deprecated
diff --git a/include/network/ZWave.hpp b/include/network/ZWave.hpp @@ -40,7 +40,7 @@ public: return -1; } - int connect(std::string conParams) { return -1; } + Device *connect(std::string conParams) { return nullptr; } // TODO std::vector<NetworkInfo> discover() override {
diff --git a/include/network/ZigBee.hpp b/include/network/ZigBee.hpp @@ -39,7 +39,7 @@ public: return -1; } - int connect(std::string conParams) { return -1; } + Device *connect(std::string conParams) { return nullptr; } // TODO std::vector<NetworkInfo> discover() override {
: bharatvaj/forwarder