From 9b65f6a41e4823b379b225205cfc599536f36834 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20St=C3=BCrz?= Date: Sat, 5 Jun 2021 23:13:02 +0200 Subject: [PATCH] Allow plugins to loock up mac address manufactureres --- libnymea/network/networkdevicediscovery.cpp | 13 ++++++++++--- libnymea/network/networkdevicediscovery.h | 2 ++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/libnymea/network/networkdevicediscovery.cpp b/libnymea/network/networkdevicediscovery.cpp index 85bf354f..31f9c8f9 100644 --- a/libnymea/network/networkdevicediscovery.cpp +++ b/libnymea/network/networkdevicediscovery.cpp @@ -40,24 +40,27 @@ NYMEA_LOGGING_CATEGORY(dcNetworkDeviceDiscovery, "NetworkDeviceDiscovery") NetworkDeviceDiscovery::NetworkDeviceDiscovery(QObject *parent) : QObject(parent) { + // Create ARP socket m_arpSocket = new ArpSocket(this); connect(m_arpSocket, &ArpSocket::arpResponse, this, &NetworkDeviceDiscovery::onArpResponseRceived); - if (!m_arpSocket->openSocket()) { qCWarning(dcNetworkDeviceDiscovery()) << "Network discovery will not make use of ARP packages."; m_arpSocket->closeSocket(); } + // Create ping socket m_ping = new Ping(this); if (!m_ping->available()) qCWarning(dcNetworkDeviceDiscovery()) << "Failed to create ping tool" << m_ping->error(); + // Init MAC database if available m_macAddressDatabase = new MacAddressDatabase(this); if (!m_macAddressDatabase->available()) qCWarning(dcNetworkDeviceDiscovery()) << "The mac address database is not available. Network discovery will not lookup mac address manufacturer"; + // Timer for max duration af a discovery m_discoveryTimer = new QTimer(this); - m_discoveryTimer->setInterval(5000); + m_discoveryTimer->setInterval(20000); m_discoveryTimer->setSingleShot(true); connect(m_discoveryTimer, &QTimer::timeout, this, [=](){ if (m_runningPingRepies.isEmpty() && m_currentReply) { @@ -110,6 +113,11 @@ PingReply *NetworkDeviceDiscovery::ping(const QHostAddress &address) return m_ping->ping(address); } +MacAddressDatabaseReply *NetworkDeviceDiscovery::lookupMacAddress(const QString &macAddress) +{ + return m_macAddressDatabase->lookupMacAddress(macAddress); +} + void NetworkDeviceDiscovery::pingAllNetworkDevices() { qCDebug(dcNetworkDeviceDiscovery()) << "Starting ping for all network devices..."; @@ -189,7 +197,6 @@ void NetworkDeviceDiscovery::finishDiscovery() qint64 durationMilliSeconds = QDateTime::currentMSecsSinceEpoch() - m_currentReply->m_startTimestamp; qCDebug(dcNetworkDeviceDiscovery()) << "Discovery finished. Found" << m_currentReply->networkDevices().count() << "network devices in" << QTime::fromMSecsSinceStartOfDay(durationMilliSeconds).toString("mm:ss.zzz"); - m_arpSocket->closeSocket(); emit m_currentReply->finished(); m_currentReply->deleteLater(); m_currentReply = nullptr; diff --git a/libnymea/network/networkdevicediscovery.h b/libnymea/network/networkdevicediscovery.h index acd9d8f1..f1a9ca71 100644 --- a/libnymea/network/networkdevicediscovery.h +++ b/libnymea/network/networkdevicediscovery.h @@ -41,6 +41,7 @@ #include "networkdevicediscoveryreply.h" class MacAddressDatabase; +class MacAddressDatabaseReply; Q_DECLARE_LOGGING_CATEGORY(dcNetworkDeviceDiscovery) @@ -56,6 +57,7 @@ public: bool running() const; PingReply *ping(const QHostAddress &address); + MacAddressDatabaseReply *lookupMacAddress(const QString &macAddress); signals: void runningChanged(bool running);