From 1d077b945d4b7c48d829fe33322ffcaabbe8b754 Mon Sep 17 00:00:00 2001 From: stephb9959 Date: Sat, 23 Sep 2023 15:23:13 -0700 Subject: [PATCH] https://telecominfraproject.atlassian.net/browse/WIFI-12954 Signed-off-by: stephb9959 --- build | 2 +- src/AutoDiscovery.cpp | 20 +++++++++++++++++--- src/AutoDiscovery.h | 2 ++ 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/build b/build index 8580e7b6..b74e882a 100644 --- a/build +++ b/build @@ -1 +1 @@ -30 \ No newline at end of file +31 \ No newline at end of file diff --git a/src/AutoDiscovery.cpp b/src/AutoDiscovery.cpp index ef336fb3..be9e6bcc 100644 --- a/src/AutoDiscovery.cpp +++ b/src/AutoDiscovery.cpp @@ -64,7 +64,16 @@ namespace OpenWifi { } } - void AutoDiscovery::run() { + void AutoDiscovery::ProcessDisconnect(const Poco::JSON::Object::Ptr &P, [[maybe_unused]] std::string &FW, + std::string &SN, + [[maybe_unused]] std::string &Compat, + [[maybe_unused]] std::string &Conn, + [[maybe_unused]] std::string &locale) { + if (P->has(uCentralProtocol::SERIALNUMBER)) + SN = P->get(uCentralProtocol::SERIALNUMBER).toString(); + } + + void AutoDiscovery::run() { Poco::AutoPtr Note(Queue_.waitDequeueNotification()); Utils::SetThreadName("auto-discovery"); while (Note && Running_) { @@ -73,6 +82,7 @@ namespace OpenWifi { try { Poco::JSON::Parser Parser; auto Object = Parser.parse(Msg->Payload()).extract(); + bool Connected=true; if (Object->has(uCentralProtocol::PAYLOAD)) { auto PayloadObj = Object->getObject(uCentralProtocol::PAYLOAD); @@ -82,11 +92,15 @@ namespace OpenWifi { ProcessPing(PingObj, Firmware, SerialNumber, Compatible, ConnectedIP, Locale); } else if(PayloadObj->has("capabilities")) { ProcessConnect(PayloadObj, Firmware, SerialNumber, Compatible, ConnectedIP, Locale); + } else if(PayloadObj->has("disconnection")) { + // we ignore disconnection in provisioning + Connected=false; + ProcessConnect(PayloadObj, Firmware, SerialNumber, Compatible, ConnectedIP, Locale); } else { - std::cout << Msg->Payload() << std::endl; + poco_debug(Logger(),fmt::format("Unknown message on 'connection' topic: {}",Msg->Payload())); } - if (!SerialNumber.empty()) { + if (!SerialNumber.empty() && Connected) { StorageService()->InventoryDB().CreateFromConnection( SerialNumber, ConnectedIP, Compatible, Locale); } diff --git a/src/AutoDiscovery.h b/src/AutoDiscovery.h index 87a3af10..05847f6a 100644 --- a/src/AutoDiscovery.h +++ b/src/AutoDiscovery.h @@ -51,6 +51,8 @@ namespace OpenWifi { std::string &Compat, std::string &Conn, std::string &locale) ; void ProcessConnect(const Poco::JSON::Object::Ptr & P, std::string &FW, std::string &SN, std::string &Compat, std::string &Conn, std::string &locale) ; + void ProcessDisconnect(const Poco::JSON::Object::Ptr & P, std::string &FW, std::string &SN, + std::string &Compat, std::string &Conn, std::string &locale) ; AutoDiscovery() noexcept : SubSystemServer("AutoDiscovery", "AUTO-DISCOVERY", "discovery") {}