From 776745f59711f2cde030a9b56316247237566678 Mon Sep 17 00:00:00 2001 From: stephb9959 Date: Sat, 29 Oct 2022 21:52:26 -0700 Subject: [PATCH] https://telecominfraproject.atlassian.net/browse/WIFI-11303 Signed-off-by: stephb9959 --- CMakeLists.txt | 3 +- .../UI_WebSocketClientNotifications.cpp | 11 + .../UI_WebSocketClientNotifications.h | 44 ++++ src/framework/UI_WebSocketClientServer.h | 2 +- src/framework/WebSocketClientNotification.cpp | 146 -------------- src/framework/WebSocketClientNotifications.h | 190 ------------------ 6 files changed, 58 insertions(+), 338 deletions(-) create mode 100644 src/framework/UI_WebSocketClientNotifications.cpp create mode 100644 src/framework/UI_WebSocketClientNotifications.h delete mode 100644 src/framework/WebSocketClientNotification.cpp delete mode 100644 src/framework/WebSocketClientNotifications.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 12dc20f..d8608b0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -78,13 +78,14 @@ add_executable(owanalytics src/framework/MicroServiceErrorHandler.h src/framework/UI_WebSocketClientServer.cpp src/framework/UI_WebSocketClientServer.h + src/framework/UI_WebSocketClientNotifications.cpp + src/framework/UI_WebSocketClientNotifications.h src/framework/utils.h src/framework/utils.cpp src/framework/AppServiceRegistry.h src/framework/SubSystemServer.cpp src/framework/SubSystemServer.h src/framework/RESTAPI_utils.h - src/framework/WebSocketClientNotification.cpp src/framework/AuthClient.cpp src/framework/AuthClient.h src/framework/MicroServiceNames.h diff --git a/src/framework/UI_WebSocketClientNotifications.cpp b/src/framework/UI_WebSocketClientNotifications.cpp new file mode 100644 index 0000000..c8fcfda --- /dev/null +++ b/src/framework/UI_WebSocketClientNotifications.cpp @@ -0,0 +1,11 @@ +// +// Created by stephane bourque on 2022-10-25. +// + +#include "framework/UI_WebSocketClientNotifications.h" +#include "framework/UI_WebSocketClientServer.h" + +namespace OpenWifi { + +} + diff --git a/src/framework/UI_WebSocketClientNotifications.h b/src/framework/UI_WebSocketClientNotifications.h new file mode 100644 index 0000000..bc33c5c --- /dev/null +++ b/src/framework/UI_WebSocketClientNotifications.h @@ -0,0 +1,44 @@ +// +// Created by stephane bourque on 2022-05-05. +// + +#pragma once + +#include "framework/RESTAPI_utils.h" +#include "framework/utils.h" + +namespace OpenWifi { + + template + struct WebSocketNotification { + inline static uint64_t xid = 1; + uint64_t notification_id = ++xid; + std::string type; + ContentStruct content; + + void to_json(Poco::JSON::Object &Obj) const; + + bool from_json(const Poco::JSON::Object::Ptr &Obj); + }; + + template + void WebSocketNotification::to_json(Poco::JSON::Object &Obj) const { + RESTAPI_utils::field_to_json(Obj, "notification_id", notification_id); + RESTAPI_utils::field_to_json(Obj, "type", type); + RESTAPI_utils::field_to_json(Obj, "content", content); + } + + template + bool WebSocketNotification::from_json(const Poco::JSON::Object::Ptr &Obj) { + try { + RESTAPI_utils::field_from_json(Obj, "notification_id", notification_id); + RESTAPI_utils::field_from_json(Obj, "content", content); + RESTAPI_utils::field_from_json(Obj, "type", type); + return true; + } catch (...) { + + } + return false; + } +} + diff --git a/src/framework/UI_WebSocketClientServer.h b/src/framework/UI_WebSocketClientServer.h index 4f6adf7..6a4804f 100644 --- a/src/framework/UI_WebSocketClientServer.h +++ b/src/framework/UI_WebSocketClientServer.h @@ -15,7 +15,7 @@ #include "RESTObjects/RESTAPI_SecurityObjects.h" #include "framework/SubSystemServer.h" -#include "framework/WebSocketClientNotifications.h" +#include "framework/UI_WebSocketClientNotifications.h" namespace OpenWifi { diff --git a/src/framework/WebSocketClientNotification.cpp b/src/framework/WebSocketClientNotification.cpp deleted file mode 100644 index 1bfedc9..0000000 --- a/src/framework/WebSocketClientNotification.cpp +++ /dev/null @@ -1,146 +0,0 @@ -// -// Created by stephane bourque on 2022-10-25. -// - -#include "framework/WebSocketClientNotifications.h" -#include "framework/UI_WebSocketClientServer.h" - -namespace OpenWifi { - - - void WebSocketClientNotificationNumberOfConnections(std::uint64_t numberOfDevices, - std::uint64_t averageConnectedTime, - std::uint64_t numberOfConnectingDevices) { - WebSocketNotification N; - N.content.numberOfDevices = numberOfDevices; - N.content.averageConnectedTime = averageConnectedTime; - N.content.numberOfConnectingDevices = numberOfConnectingDevices; - N.type = "device_connections_statistics"; - UI_WebSocketClientServer()->SendNotification(N); - } - - void WebSocketClientNotificationDeviceConfigurationChange(const std::string &SerialNumber, uint64_t oldUUID, uint64_t newUUID) { - WebSocketNotification N; - N.content.serialNumber = SerialNumber; - N.content.oldUUID = oldUUID; - N.content.newUUID = newUUID; - N.type = "device_configuration_upgrade"; - UI_WebSocketClientServer()->SendNotification(N); - } - - void WebSocketClientNotificationDeviceFirmwareUpdated(const std::string &SerialNumber, const std::string &Firmware) { - WebSocketNotification N; - N.content.serialNumber = SerialNumber; - N.content.newFirmware = Firmware; - N.type = "device_firmware_upgrade"; - UI_WebSocketClientServer()->SendNotification(N); - } - - void WebSocketClientNotificationDeviceConnected(const std::string &SerialNumber) { - WebSocketNotification N; - N.content.serialNumber = SerialNumber; - N.type = "device_connection"; - UI_WebSocketClientServer()->SendNotification(N); - } - - void WebSocketClientNotificationDeviceDisconnected(const std::string & SerialNumber) { - WebSocketNotification N; - N.content.serialNumber = SerialNumber; - N.type = "device_disconnection"; - UI_WebSocketClientServer()->SendNotification(N); - } - - void WebSocketNotificationJobContent::to_json(Poco::JSON::Object &Obj) const { - RESTAPI_utils::field_to_json(Obj,"title",title); - RESTAPI_utils::field_to_json(Obj,"jobId",jobId); - RESTAPI_utils::field_to_json(Obj,"success",success); - RESTAPI_utils::field_to_json(Obj,"error",error); - RESTAPI_utils::field_to_json(Obj,"warning",warning); - RESTAPI_utils::field_to_json(Obj,"timeStamp",timeStamp); - RESTAPI_utils::field_to_json(Obj,"details",details); - } - - bool WebSocketNotificationJobContent::from_json(const Poco::JSON::Object::Ptr &Obj) { - try { - RESTAPI_utils::field_from_json(Obj,"title",title); - RESTAPI_utils::field_from_json(Obj,"jobId",jobId); - RESTAPI_utils::field_from_json(Obj,"success",success); - RESTAPI_utils::field_from_json(Obj,"error",error); - RESTAPI_utils::field_from_json(Obj,"warning",warning); - RESTAPI_utils::field_from_json(Obj,"timeStamp",timeStamp); - RESTAPI_utils::field_from_json(Obj,"details",details); - return true; - } catch(...) { - - } - return false; - } - - void WebSocketClientNotificationVenueUpdateJobCompletionToUser( const std::string & User, WebSocketClientNotificationVenueUpdateJob_t &N) { - N.type = "venue_configuration_update"; - UI_WebSocketClientServer()->SendUserNotification(User,N); - } - - void WebSocketNotificationRebootList::to_json(Poco::JSON::Object &Obj) const { - RESTAPI_utils::field_to_json(Obj,"title",title); - RESTAPI_utils::field_to_json(Obj,"jobId",jobId); - RESTAPI_utils::field_to_json(Obj,"success",success); - RESTAPI_utils::field_to_json(Obj,"warning",warning); - RESTAPI_utils::field_to_json(Obj,"timeStamp",timeStamp); - RESTAPI_utils::field_to_json(Obj,"details",details); - } - - bool WebSocketNotificationRebootList::from_json(const Poco::JSON::Object::Ptr &Obj) { - try { - RESTAPI_utils::field_from_json(Obj,"title",title); - RESTAPI_utils::field_from_json(Obj,"jobId",jobId); - RESTAPI_utils::field_from_json(Obj,"success",success); - RESTAPI_utils::field_from_json(Obj,"warning",warning); - RESTAPI_utils::field_from_json(Obj,"timeStamp",timeStamp); - RESTAPI_utils::field_from_json(Obj,"details",details); - return true; - } catch(...) { - - } - return false; - } - - void WebSocketClientNotificationVenueRebootCompletionToUser( const std::string & User, WebSocketClientNotificationVenueRebootList_t &N) { - N.type = "venue_rebooter"; - UI_WebSocketClientServer()->SendUserNotification(User,N); - } - - void WebSocketNotificationUpgradeList::to_json(Poco::JSON::Object &Obj) const { - RESTAPI_utils::field_to_json(Obj,"title",title); - RESTAPI_utils::field_to_json(Obj,"jobId",jobId); - RESTAPI_utils::field_to_json(Obj,"success",success); - RESTAPI_utils::field_to_json(Obj,"notConnected",not_connected); - RESTAPI_utils::field_to_json(Obj,"noFirmware",no_firmware); - RESTAPI_utils::field_to_json(Obj,"skipped",skipped); - RESTAPI_utils::field_to_json(Obj,"timeStamp",timeStamp); - RESTAPI_utils::field_to_json(Obj,"details",details); - } - - bool WebSocketNotificationUpgradeList::from_json(const Poco::JSON::Object::Ptr &Obj) { - try { - RESTAPI_utils::field_from_json(Obj,"title",title); - RESTAPI_utils::field_from_json(Obj,"jobId",jobId); - RESTAPI_utils::field_from_json(Obj,"success",success); - RESTAPI_utils::field_from_json(Obj,"notConnected",not_connected); - RESTAPI_utils::field_from_json(Obj,"noFirmware",no_firmware); - RESTAPI_utils::field_from_json(Obj,"skipped",skipped); - RESTAPI_utils::field_from_json(Obj,"timeStamp",timeStamp); - RESTAPI_utils::field_from_json(Obj,"details",details); - return true; - } catch(...) { - - } - return false; - } - - void WebSocketClientNotificationVenueUpgradeCompletionToUser( const std::string & User, WebSocketClientNotificationVenueUpgradeList_t &N) { - N.type = "venue_upgrader"; - UI_WebSocketClientServer()->SendUserNotification(User,N); - } -} - diff --git a/src/framework/WebSocketClientNotifications.h b/src/framework/WebSocketClientNotifications.h deleted file mode 100644 index 2687f3c..0000000 --- a/src/framework/WebSocketClientNotifications.h +++ /dev/null @@ -1,190 +0,0 @@ -// -// Created by stephane bourque on 2022-05-05. -// - -#pragma once - -#include "framework/RESTAPI_utils.h" -#include "framework/utils.h" - -namespace OpenWifi { - - template struct WebSocketNotification { - inline static uint64_t xid=1; - uint64_t notification_id=++xid; - std::string type; - ContentStruct content; - - void to_json(Poco::JSON::Object &Obj) const; - bool from_json(const Poco::JSON::Object::Ptr &Obj); - }; - - template void WebSocketNotification::to_json(Poco::JSON::Object &Obj) const { - RESTAPI_utils::field_to_json(Obj,"notification_id",notification_id); - RESTAPI_utils::field_to_json(Obj,"type",type); - RESTAPI_utils::field_to_json(Obj,"content",content); - } - - template bool WebSocketNotification::from_json(const Poco::JSON::Object::Ptr &Obj) { - try { - RESTAPI_utils::field_from_json(Obj,"notification_id",notification_id); - RESTAPI_utils::field_from_json(Obj,"content",content); - RESTAPI_utils::field_from_json(Obj,"type",type); - return true; - } catch(...) { - - } - return false; - } - - struct WebNotificationSingleDevice { - std::string serialNumber; - inline void to_json(Poco::JSON::Object &Obj) const { - RESTAPI_utils::field_to_json(Obj,"serialNumber", serialNumber); - } - - inline bool from_json(const Poco::JSON::Object::Ptr &Obj) { - try { - RESTAPI_utils::field_from_json(Obj,"serialNumber", serialNumber); - return true; - } catch (...) { - - } - return false; - } - }; - - struct WebNotificationSingleDeviceConfigurationChange { - std::string serialNumber; - uint64_t oldUUID; - uint64_t newUUID; - - inline void to_json(Poco::JSON::Object &Obj) const { - RESTAPI_utils::field_to_json(Obj,"serialNumber", serialNumber); - RESTAPI_utils::field_to_json(Obj,"oldUUID", oldUUID); - RESTAPI_utils::field_to_json(Obj,"newUUID", newUUID); - } - - inline bool from_json(const Poco::JSON::Object::Ptr &Obj) { - try { - RESTAPI_utils::field_from_json(Obj,"serialNumber", serialNumber); - RESTAPI_utils::field_from_json(Obj,"oldUUID", oldUUID); - RESTAPI_utils::field_from_json(Obj,"newUUID", newUUID); - return true; - } catch (...) { - - } - return false; - } - }; - - struct WebNotificationSingleDeviceFirmwareChange { - std::string serialNumber; - std::string newFirmware; - inline void to_json(Poco::JSON::Object &Obj) const { - RESTAPI_utils::field_to_json(Obj,"serialNumber", serialNumber); - RESTAPI_utils::field_to_json(Obj,"newFirmware", newFirmware); - } - - inline bool from_json(const Poco::JSON::Object::Ptr &Obj) { - try { - RESTAPI_utils::field_from_json(Obj,"serialNumber", serialNumber); - RESTAPI_utils::field_from_json(Obj,"newFirmware", newFirmware); - return true; - } catch (...) { - - } - return false; - } - }; - - struct WebSocketClientNotificationNumberOfConnection { - std::uint64_t numberOfDevices=0; - std::uint64_t averageConnectedTime=0; - std::uint64_t numberOfConnectingDevices=0; - - inline void to_json(Poco::JSON::Object &Obj) const { - RESTAPI_utils::field_to_json(Obj,"numberOfDevices", numberOfDevices); - RESTAPI_utils::field_to_json(Obj,"averageConnectedTime", averageConnectedTime); - RESTAPI_utils::field_to_json(Obj,"numberOfConnectingDevices", numberOfConnectingDevices); - } - - inline bool from_json(const Poco::JSON::Object::Ptr &Obj) { - try { - RESTAPI_utils::field_from_json(Obj,"numberOfDevices", numberOfDevices); - RESTAPI_utils::field_from_json(Obj,"averageConnectedTime", averageConnectedTime); - RESTAPI_utils::field_from_json(Obj,"numberOfConnectingDevices", numberOfConnectingDevices); - return true; - } catch (...) { - - } - return false; - } - }; - - void WebSocketClientNotificationNumberOfConnections(std::uint64_t numberOfDevices, - std::uint64_t averageConnectedTime, - std::uint64_t numberOfConnectingDevices); - void WebSocketClientNotificationDeviceConfigurationChange(const std::string &SerialNumber, uint64_t oldUUID, uint64_t newUUID); - void WebSocketClientNotificationDeviceFirmwareUpdated(const std::string &SerialNumber, const std::string &Firmware); - void WebSocketClientNotificationDeviceConnected(const std::string &SerialNumber); - void WebSocketClientNotificationDeviceDisconnected(const std::string & SerialNumber); - - struct WebSocketNotificationJobContent { - std::string title, - details, - jobId; - std::vector success, - error, - warning; - uint64_t timeStamp=OpenWifi::Utils::Now(); - - void to_json(Poco::JSON::Object &Obj) const; - bool from_json(const Poco::JSON::Object::Ptr &Obj); - }; - - typedef WebSocketNotification WebSocketClientNotificationVenueUpdateJob_t; - - void WebSocketClientNotificationVenueUpdateJobCompletionToUser( const std::string & User, WebSocketClientNotificationVenueUpdateJob_t &N); - - ///// - ///// - ///// - - struct WebSocketNotificationRebootList { - std::string title, - details, - jobId; - std::vector success, - warning; - uint64_t timeStamp=OpenWifi::Utils::Now(); - - void to_json(Poco::JSON::Object &Obj) const; - bool from_json(const Poco::JSON::Object::Ptr &Obj); - }; - - typedef WebSocketNotification WebSocketClientNotificationVenueRebootList_t; - - void WebSocketClientNotificationVenueRebootCompletionToUser( const std::string & User, WebSocketClientNotificationVenueRebootList_t &N); - - struct WebSocketNotificationUpgradeList { - std::string title, - details, - jobId; - std::vector success, - skipped, - no_firmware, - not_connected; - uint64_t timeStamp=OpenWifi::Utils::Now(); - - void to_json(Poco::JSON::Object &Obj) const; - bool from_json(const Poco::JSON::Object::Ptr &Obj); - }; - - typedef WebSocketNotification WebSocketClientNotificationVenueUpgradeList_t; - - - void WebSocketClientNotificationVenueUpgradeCompletionToUser( const std::string & User, WebSocketClientNotificationVenueUpgradeList_t &N); - -} // namespace OpenWifi -