From d2019c24df819dfec7e898859150ccbd8e25df2e Mon Sep 17 00:00:00 2001 From: Jeffrey Quesnelle Date: Mon, 11 May 2020 16:17:56 -0400 Subject: [PATCH] reuse discovered pcap interfaces in DeviceFinder::FindAll() --- device/devicefinder.cpp | 10 +++++++--- include/icsneo/device/extensions/deviceextension.h | 2 +- include/icsneo/device/tree/neovifire2/neovifire2eth.h | 9 +++++---- include/icsneo/device/tree/radgalaxy/radgalaxy.h | 9 +++++---- include/icsneo/device/tree/radpluto/radpluto.h | 1 - include/icsneo/device/tree/radstar2/radstar2eth.h | 7 ++++--- include/icsneo/platform/pcap.h | 2 ++ 7 files changed, 24 insertions(+), 16 deletions(-) diff --git a/device/devicefinder.cpp b/device/devicefinder.cpp index 46c39d6..bdec096 100644 --- a/device/devicefinder.cpp +++ b/device/devicefinder.cpp @@ -88,6 +88,10 @@ std::vector> DeviceFinder::FindAll() { std::vector> foundDevices; std::vector>> findResults; +#if defined(LIBICSNEO_HAVE_PCAP) && LIBICSNEO_HAVE_PCAP == 1 + auto pcapDevices = PCAP::FindAll(); +#endif + #ifdef __ETHERBADGE_H_ findResults.push_back(EtherBADGE::Find()); #endif @@ -105,7 +109,7 @@ std::vector> DeviceFinder::FindAll() { #endif #ifdef __NEOVIFIRE2ETH_H_ - findResults.push_back(NeoVIFIRE2ETH::Find()); + findResults.push_back(NeoVIFIRE2ETH::Find(pcapDevices)); #endif #ifdef __NEOVIFIRE2USB_H_ @@ -121,7 +125,7 @@ std::vector> DeviceFinder::FindAll() { #endif #ifdef __RADGALAXY_H_ - findResults.push_back(RADGalaxy::Find()); + findResults.push_back(RADGalaxy::Find(pcapDevices)); #endif #ifdef __RADPLUTOUSB_H_ @@ -129,7 +133,7 @@ std::vector> DeviceFinder::FindAll() { #endif #ifdef __RADSTAR2ETH_H_ - findResults.push_back(RADStar2ETH::Find()); + findResults.push_back(RADStar2ETH::Find(pcapDevices)); #endif #ifdef __RADSTAR2USB_H_ diff --git a/include/icsneo/device/extensions/deviceextension.h b/include/icsneo/device/extensions/deviceextension.h index 4770392..ab6dbb8 100644 --- a/include/icsneo/device/extensions/deviceextension.h +++ b/include/icsneo/device/extensions/deviceextension.h @@ -23,7 +23,7 @@ public: virtual void handleMessage(const std::shared_ptr&) {} // Return true to continue transmitting, success should be written to if false is returned - virtual bool transmitHook(const std::shared_ptr& message, bool& success) { return true; } + virtual bool transmitHook(const std::shared_ptr& message, bool& success) { (void)message; (void)success; return true; } protected: Device& device; diff --git a/include/icsneo/device/tree/neovifire2/neovifire2eth.h b/include/icsneo/device/tree/neovifire2/neovifire2eth.h index b0d2e86..6162c8b 100644 --- a/include/icsneo/device/tree/neovifire2/neovifire2eth.h +++ b/include/icsneo/device/tree/neovifire2/neovifire2eth.h @@ -11,10 +11,10 @@ namespace icsneo { class NeoVIFIRE2ETH : public NeoVIFIRE2 { public: static constexpr const uint16_t PRODUCT_ID = 0x0004; - static std::vector> Find() { + static std::vector> Find(const std::vector& pcapDevices) { std::vector> found; - for(auto& foundDev : PCAP::FindAll()) { + for(auto& foundDev : pcapDevices) { auto fakedev = std::shared_ptr(new NeoVIFIRE2ETH({})); for (auto& payload : foundDev.discoveryPackets) fakedev->com->packetizer->input(payload); @@ -34,8 +34,9 @@ public: if(sn->deviceSerial.substr(0, 2) != SERIAL_START) continue; // Not a FIRE 2 - foundDev.device.serial[sn->deviceSerial.copy(foundDev.device.serial, sizeof(foundDev.device.serial))] = '\0'; - found.push_back(std::make_shared(foundDev.device)); + auto device = foundDev.device; + device.serial[sn->deviceSerial.copy(device.serial, sizeof(device.serial))] = '\0'; + found.push_back(std::make_shared(std::move(device))); break; } } diff --git a/include/icsneo/device/tree/radgalaxy/radgalaxy.h b/include/icsneo/device/tree/radgalaxy/radgalaxy.h index 9b8319b..2bdbd95 100644 --- a/include/icsneo/device/tree/radgalaxy/radgalaxy.h +++ b/include/icsneo/device/tree/radgalaxy/radgalaxy.h @@ -15,10 +15,10 @@ public: static constexpr DeviceType::Enum DEVICE_TYPE = DeviceType::RADGalaxy; static constexpr const uint16_t PRODUCT_ID = 0x0003; static constexpr const char* SERIAL_START = "RG"; - static std::vector> Find() { + static std::vector> Find(const std::vector& pcapDevices) { std::vector> found; - for(auto& foundDev : PCAP::FindAll()) { + for(auto& foundDev : pcapDevices) { auto fakedev = std::shared_ptr(new RADGalaxy({})); for(auto& payload : foundDev.discoveryPackets) fakedev->com->packetizer->input(payload); @@ -38,8 +38,9 @@ public: if(sn->deviceSerial.substr(0, 2) != SERIAL_START) continue; // Not a RADGalaxy - foundDev.device.serial[sn->deviceSerial.copy(foundDev.device.serial, sizeof(foundDev.device.serial))] = '\0'; - found.emplace_back(new RADGalaxy(foundDev.device)); + auto device = foundDev.device; + device.serial[sn->deviceSerial.copy(device.serial, sizeof(device.serial))] = '\0'; + found.emplace_back(new RADGalaxy(std::move(device))); break; } } diff --git a/include/icsneo/device/tree/radpluto/radpluto.h b/include/icsneo/device/tree/radpluto/radpluto.h index 7c8bc97..f0fc330 100644 --- a/include/icsneo/device/tree/radpluto/radpluto.h +++ b/include/icsneo/device/tree/radpluto/radpluto.h @@ -3,7 +3,6 @@ #include "icsneo/device/device.h" #include "icsneo/device/devicetype.h" -#include "icsneo/platform/pcap.h" #include "icsneo/communication/packetizer.h" #include "icsneo/communication/decoder.h" diff --git a/include/icsneo/device/tree/radstar2/radstar2eth.h b/include/icsneo/device/tree/radstar2/radstar2eth.h index eed563d..9e576ea 100644 --- a/include/icsneo/device/tree/radstar2/radstar2eth.h +++ b/include/icsneo/device/tree/radstar2/radstar2eth.h @@ -11,10 +11,10 @@ namespace icsneo { class RADStar2ETH : public RADStar2 { public: // Serial numbers start with RS - static std::vector> Find() { + static std::vector> Find(const std::vector& pcapDevices) { std::vector> found; - for(auto& foundDev : PCAP::FindAll()) { + for(auto& foundDev : pcapDevices) { auto fakedev = std::shared_ptr(new RADStar2ETH({})); for(auto& payload : foundDev.discoveryPackets) fakedev->com->packetizer->input(payload); @@ -34,7 +34,8 @@ public: if(sn->deviceSerial.substr(0, 2) != SERIAL_START) continue; // Not a RADStar2 - foundDev.device.serial[sn->deviceSerial.copy(foundDev.device.serial, sizeof(foundDev.device.serial))] = '\0'; + auto device = foundDev.device; + device.serial[sn->deviceSerial.copy(device.serial, sizeof(device.serial))] = '\0'; found.push_back(std::make_shared(foundDev.device)); break; } diff --git a/include/icsneo/platform/pcap.h b/include/icsneo/platform/pcap.h index e97b5f4..d73138d 100644 --- a/include/icsneo/platform/pcap.h +++ b/include/icsneo/platform/pcap.h @@ -9,4 +9,6 @@ #warning "This platform is not supported by the PCAP driver" #endif +#define LIBICSNEO_HAVE_PCAP 1 + #endif \ No newline at end of file