From 75fb81be727328c5e99f78be1e527f0b4936f9e0 Mon Sep 17 00:00:00 2001 From: rafi Date: Thu, 24 Oct 2024 10:19:22 +0530 Subject: [PATCH] rearrange and update proxy --- CMakeLists.txt | 29 ++- gdbus/NetworkManagerGnomeProxy.cpp | 195 ++++++++++++++++++ .../NetworkManagerGnomeEvents.cpp | 0 .../NetworkManagerGnomeEvents.h | 0 .../NetworkManagerGnomeProxy.cpp | 0 .../NetworkManagerGnomeUtils.cpp | 0 .../NetworkManagerGnomeUtils.h | 0 .../NetworkManagerGnomeWIFI.cpp | 0 .../NetworkManagerGnomeWIFI.h | 0 9 files changed, 215 insertions(+), 9 deletions(-) create mode 100644 gdbus/NetworkManagerGnomeProxy.cpp rename NetworkManagerGnomeEvents.cpp => libnm/NetworkManagerGnomeEvents.cpp (100%) rename NetworkManagerGnomeEvents.h => libnm/NetworkManagerGnomeEvents.h (100%) rename NetworkManagerGnomeProxy.cpp => libnm/NetworkManagerGnomeProxy.cpp (100%) rename NetworkManagerGnomeUtils.cpp => libnm/NetworkManagerGnomeUtils.cpp (100%) rename NetworkManagerGnomeUtils.h => libnm/NetworkManagerGnomeUtils.h (100%) rename NetworkManagerGnomeWIFI.cpp => libnm/NetworkManagerGnomeWIFI.cpp (100%) rename NetworkManagerGnomeWIFI.h => libnm/NetworkManagerGnomeWIFI.h (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index a302f166..a48b7560 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -93,12 +93,23 @@ set_target_properties(${MODULE_NAME} PROPERTIES if(ENABLE_GNOME_NETWORKMANAGER) - target_sources(${MODULE_NAME} PRIVATE NetworkManagerGnomeProxy.cpp - NetworkManagerGnomeWIFI.cpp - NetworkManagerGnomeEvents.cpp - NetworkManagerGnomeUtils.cpp ) - target_include_directories(${MODULE_NAME} PRIVATE ${GLIB_INCLUDE_DIRS} ${LIBNM_INCLUDE_DIRS}) - target_link_libraries(${MODULE_NAME} PRIVATE ${LIBNM_LIBRARIES}) + if(ENABLE_GNOME_LIBNM_PROXY) + target_sources(${MODULE_NAME} PRIVATE + libnm/NetworkManagerGnomeProxy.cpp + libnm/NetworkManagerGnomeWIFI.cpp + libnm/NetworkManagerGnomeEvents.cpp + libnm/NetworkManagerGnomeUtils.cpp ) + target_include_directories(${MODULE_NAME} PRIVATE ${GLIB_INCLUDE_DIRS} ${LIBNM_INCLUDE_DIRS}) + target_link_libraries(${MODULE_NAME} PRIVATE ${LIBNM_LIBRARIES}) + else() + target_sources(${MODULE_NAME} PRIVATE + gdbus/NetworkManagerGnomeProxy.cpp + gdbus/NetworkManagerGdbusClient.cpp + gdbus/NetworkManagerGdbusMgr.cpp + gdbus/NetworkManagerGdbusUtils.cpp ) + target_include_directories(${MODULE_NAME} PRIVATE ${GLIB_INCLUDE_DIRS} ${LIBNM_INCLUDE_DIRS} gdbus) + target_link_libraries(${MODULE_NAME} PRIVATE ${GLIB_LIBRARIES} ${GIO_LIBRARIES} uuid ) + endif() else() target_sources(${MODULE_NAME} PRIVATE NetworkManagerRDKProxy.cpp) target_include_directories(${MODULE_NAME} PRIVATE ${IARMBUS_INCLUDE_DIRS}) @@ -157,7 +168,7 @@ set_target_properties(${PLUGIN_LEGACY_DEPRECATED_WIFI} PROPERTIES install(TARGETS ${PLUGIN_LEGACY_DEPRECATED_WIFI} DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/${STORAGE_DIRECTORY}/plugins) write_config() -write_config(PLUGINS LegacyPlugin_NetworkAPIs CLASSNAME Network LOCATOR lib${PLUGIN_LEGACY_DEPRECATED_NETWORK}.so) -write_config(PLUGINS LegacyPlugin_WiFiManagerAPIs CLASSNAME WiFiManager LOCATOR lib${PLUGIN_LEGACY_DEPRECATED_WIFI}.so) +# write_config(PLUGINS LegacyPlugin_NetworkAPIs CLASSNAME Network LOCATOR lib${PLUGIN_LEGACY_DEPRECATED_NETWORK}.so) +# write_config(PLUGINS LegacyPlugin_WiFiManagerAPIs CLASSNAME WiFiManager LOCATOR lib${PLUGIN_LEGACY_DEPRECATED_WIFI}.so) -include(Tests/raspberrypi/NetworkManagerGdbusTest.cmake) \ No newline at end of file +include(Tests/raspberrypi/NetworkManagerGdbusTest.cmake) diff --git a/gdbus/NetworkManagerGnomeProxy.cpp b/gdbus/NetworkManagerGnomeProxy.cpp new file mode 100644 index 00000000..3b0feda0 --- /dev/null +++ b/gdbus/NetworkManagerGnomeProxy.cpp @@ -0,0 +1,195 @@ +/** +* If not stated otherwise in this file or this component's LICENSE +* file the following copyright and licenses apply: +* +* Copyright 2022 RDK Management +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +**/ + +#include "NetworkManagerImplementation.h" +#include "NetworkManagerGdbusClient.h" + +using namespace WPEFramework; +using namespace WPEFramework::Plugin; +using namespace std; + +namespace WPEFramework +{ + namespace Plugin + { + NetworkManagerImplementation* _instance = nullptr; + NetworkManagerClient* gnomeDbusClient = nullptr; + void NetworkManagerInternalEventHandler(const char *owner, int eventId, void *data, size_t len) + { + return; + } + + void NetworkManagerImplementation::platform_init() + { + ::_instance = this; + gnomeDbusClient = NetworkManagerClient::getInstance(); + } + + uint32_t NetworkManagerImplementation::GetAvailableInterfaces (Exchange::INetworkManager::IInterfaceDetailsIterator*& interfacesItr/* @out */) + { + return Core::ERROR_NONE; + } + + uint32_t NetworkManagerImplementation::GetPrimaryInterface (string& interface /* @out */) + { + return Core::ERROR_NONE; + } + + uint32_t NetworkManagerImplementation::SetPrimaryInterface (const string& interface/* @in */) + { + return Core::ERROR_NONE; + } + + uint32_t NetworkManagerImplementation::SetInterfaceState(const string& interface/* @in */, const bool& enabled /* @in */) + { + return Core::ERROR_NONE; + } + + uint32_t NetworkManagerImplementation::GetInterfaceState(const string& interface/* @in */, bool& isEnabled /* @out */) + { + return Core::ERROR_NONE; + } + + uint32_t NetworkManagerImplementation::GetIPSettings(const string& interface /* @in */, const string& ipversion /* @in */, IPAddressInfo& result /* @out */) + { + return Core::ERROR_NONE; + } + + uint32_t NetworkManagerImplementation::SetIPSettings(const string& interface /* @in */, const string &ipversion /* @in */, const IPAddressInfo& address /* @in */) + { + return Core::ERROR_NONE; + } + + uint32_t NetworkManagerImplementation::StartWiFiScan(const WiFiFrequency frequency /* @in */) + { + uint32_t rc = Core::ERROR_GENERAL; + if(gnomeDbusClient->startWifiScan()) + rc = Core::ERROR_NONE; + else + NMLOG_ERROR("StartWiFiScan failed"); + return rc; + } + + uint32_t NetworkManagerImplementation::StopWiFiScan(void) + { + // TODO FIX + uint32_t rc = Core::ERROR_GENERAL; + if(gnomeDbusClient->stopWiFiScan()) + rc = Core::ERROR_NONE; + else + NMLOG_ERROR("stopWiFiScan failed"); + return rc; + } + + uint32_t NetworkManagerImplementation::GetKnownSSIDs(IStringIterator*& ssids /* @out */) + { + uint32_t rc = Core::ERROR_GENERAL; + std::list ssidList; + if(gnomeDbusClient->getKnownSSIDs(ssidList) && !ssidList.empty()) + { + ssids = Core::Service::Create(ssidList); + rc = Core::ERROR_NONE; + } + else + NMLOG_ERROR("GetKnownSSIDs failed"); + + return rc; + } + + uint32_t NetworkManagerImplementation::AddToKnownSSIDs(const WiFiConnectTo& ssid /* @in */) + { + uint32_t rc = Core::ERROR_GENERAL; + if(gnomeDbusClient->addToKnownSSIDs(ssid)) + rc = Core::ERROR_NONE; + else + NMLOG_ERROR("addToKnownSSIDs failed"); + return rc; + } + + uint32_t NetworkManagerImplementation::RemoveKnownSSID(const string& ssid /* @in */) + { + uint32_t rc = Core::ERROR_GENERAL; + if(gnomeDbusClient->removeKnownSSIDs(ssid)) + rc = Core::ERROR_NONE; + else + NMLOG_ERROR("RemoveKnownSSID failed"); + return rc; + } + + uint32_t NetworkManagerImplementation::WiFiConnect(const WiFiConnectTo& ssid /* @in */) + { + uint32_t rc = Core::ERROR_GENERAL; + if(gnomeDbusClient->wifiConnect(ssid)) + rc = Core::ERROR_NONE; + else + NMLOG_ERROR("WiFiConnect failed"); + return rc; + } + + uint32_t NetworkManagerImplementation::WiFiDisconnect(void) + { + uint32_t rc = Core::ERROR_GENERAL; + if(gnomeDbusClient->wifiDisconnect()) + rc = Core::ERROR_NONE; + else + NMLOG_ERROR("WiFiDisconnect failed"); + return rc; + } + + uint32_t NetworkManagerImplementation::GetConnectedSSID(WiFiSSIDInfo& ssidInfo /* @out */) + { + uint32_t rc = Core::ERROR_GENERAL; + if(gnomeDbusClient->getConnectedSSID(ssidInfo)) + rc = Core::ERROR_NONE; + else + NMLOG_ERROR("getConnectedSSID failed"); + return rc; + } + + uint32_t NetworkManagerImplementation::GetWiFiSignalStrength(string& ssid /* @out */, string& signalStrength /* @out */, WiFiSignalQuality& quality /* @out */) + { + uint32_t rc = Core::ERROR_GENERAL; + if(gnomeDbusClient->getWiFiSignalStrength(ssid, signalStrength, quality)) + rc = Core::ERROR_NONE; + else + NMLOG_ERROR("GetWiFiSignalStrength failed"); + return rc; + } + + uint32_t NetworkManagerImplementation::GetWifiState(WiFiState &state) + { + uint32_t rc = Core::ERROR_GENERAL; + if(gnomeDbusClient->getWifiState(state)) + rc = Core::ERROR_NONE; + else + NMLOG_ERROR("GetWifiState failed"); + return rc; + } + + uint32_t NetworkManagerImplementation::StartWPS(const WiFiWPS& method /* @in */, const string& wps_pin /* @in */) + { + return Core::ERROR_NONE; + } + + uint32_t NetworkManagerImplementation::StopWPS(void) + { + return Core::ERROR_NONE; + } + } +} diff --git a/NetworkManagerGnomeEvents.cpp b/libnm/NetworkManagerGnomeEvents.cpp similarity index 100% rename from NetworkManagerGnomeEvents.cpp rename to libnm/NetworkManagerGnomeEvents.cpp diff --git a/NetworkManagerGnomeEvents.h b/libnm/NetworkManagerGnomeEvents.h similarity index 100% rename from NetworkManagerGnomeEvents.h rename to libnm/NetworkManagerGnomeEvents.h diff --git a/NetworkManagerGnomeProxy.cpp b/libnm/NetworkManagerGnomeProxy.cpp similarity index 100% rename from NetworkManagerGnomeProxy.cpp rename to libnm/NetworkManagerGnomeProxy.cpp diff --git a/NetworkManagerGnomeUtils.cpp b/libnm/NetworkManagerGnomeUtils.cpp similarity index 100% rename from NetworkManagerGnomeUtils.cpp rename to libnm/NetworkManagerGnomeUtils.cpp diff --git a/NetworkManagerGnomeUtils.h b/libnm/NetworkManagerGnomeUtils.h similarity index 100% rename from NetworkManagerGnomeUtils.h rename to libnm/NetworkManagerGnomeUtils.h diff --git a/NetworkManagerGnomeWIFI.cpp b/libnm/NetworkManagerGnomeWIFI.cpp similarity index 100% rename from NetworkManagerGnomeWIFI.cpp rename to libnm/NetworkManagerGnomeWIFI.cpp diff --git a/NetworkManagerGnomeWIFI.h b/libnm/NetworkManagerGnomeWIFI.h similarity index 100% rename from NetworkManagerGnomeWIFI.h rename to libnm/NetworkManagerGnomeWIFI.h