From ecadf8bdb14999a83dec321678a22e6706a48efa Mon Sep 17 00:00:00 2001 From: Karunakaran A Date: Tue, 1 Oct 2024 14:10:55 -0400 Subject: [PATCH] DELIA-66446 : Implement RDKLogger Support to NetworkManager Plugin Reason for change: Implement RDKLogger Support to NetworkManager Plugin Test Procedure: Verify logs are printed properly Risks: Low Signed-off-by: Karunakaran A --- CMakeLists.txt | 32 +++++++++++++++------- CONTRIBUTING.md | 4 +++ NetworkManagerImplementation.cpp | 4 +-- NetworkManagerLogger.cpp | 4 +-- NetworkManagerRDKProxy.cpp | 47 ++++++++++++++++---------------- README.md | 5 ++-- cmake/Findrdklogger.cmake | 38 ++++++++++++++++++++++++++ 7 files changed, 93 insertions(+), 41 deletions(-) create mode 100644 CONTRIBUTING.md create mode 100644 cmake/Findrdklogger.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index edb86eda..9e55f947 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,9 +14,10 @@ add_compile_definitions(NETWORKMANAGER_PATCH_VERSION=${VERSION_PATCH}) set(PROJECT_VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}) - include(CmakeHelperFunctions) +option(USE_RDK_LOGGER "Enable RDK Logger for logging" OFF ) + string(TOLOWER ${NAMESPACE} STORAGE_DIRECTORY) get_directory_property(SEVICES_DEFINES COMPILE_DEFINITIONS) @@ -60,6 +61,12 @@ message("Setup ${PROJECT_NAME} v${PROJECT_VERSION}") set(PLUGIN_NETWORKMANAGER_LOGLEVEL "5" CACHE STRING "To configure default loglevel NetworkManager plugin") +if (USE_RDK_LOGGER) + find_package(rdklogger REQUIRED) + add_definitions(-DUSE_RDK_LOGGER) + + include_directories(${RDKLOGGER_INCLUDE_DIRS}) +endif (USE_RDK_LOGGER) include_directories(${PROJECT_SOURCE_DIR}) # Build the main plugin that runs inside the WPEFramework daemon @@ -84,14 +91,6 @@ set_target_properties(${MODULE_NAME} PROPERTIES CXX_STANDARD_REQUIRED YES FRAMEWORK FALSE) -include_directories(${PROJECT_SOURCE_DIR}/interface) -include_directories(${PROJECT_SOURCE_DIR}/service) -include_directories(${PROJECT_SOURCE_DIR}/../helpers) - -install(TARGETS ${MODULE_NAME} DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/${STORAGE_DIRECTORY}/plugins) - - -# Build the implementation that runs out-of-process behind a COM-RPC interface if(ENABLE_GNOME_NETWORKMANAGER) target_sources(${MODULE_NAME} PRIVATE NetworkManagerGnomeProxy.cpp @@ -106,10 +105,15 @@ else() target_link_libraries(${MODULE_NAME} PRIVATE ${IARMBUS_LIBRARIES}) endif() - target_link_libraries(${MODULE_NAME} PRIVATE ${CURL_LIBRARIES}) target_include_directories(${MODULE_NAME} PRIVATE ${CURL_INCLUDE_DIRS}) +if (USE_RDK_LOGGER) + target_link_libraries(${MODULE_NAME} PRIVATE ${RDKLOGGER_LIBRARIES}) +endif (USE_RDK_LOGGER) + +install(TARGETS ${MODULE_NAME} DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/${STORAGE_DIRECTORY}/plugins) + add_library(${PLUGIN_LEGACY_DEPRECATED_NETWORK} SHARED LegacyPlugin_NetworkAPIs.cpp NetworkManagerLogger.cpp @@ -121,6 +125,10 @@ target_link_libraries(${PLUGIN_LEGACY_DEPRECATED_NETWORK} PRIVATE ${NAMESPACE}Plugins::${NAMESPACE}Plugins ) +if (USE_RDK_LOGGER) + target_link_libraries(${PLUGIN_LEGACY_DEPRECATED_NETWORK} PRIVATE ${RDKLOGGER_LIBRARIES}) +endif (USE_RDK_LOGGER) + set_target_properties(${PLUGIN_LEGACY_DEPRECATED_NETWORK} PROPERTIES CXX_STANDARD 11 CXX_STANDARD_REQUIRED YES) @@ -138,6 +146,10 @@ target_link_libraries(${PLUGIN_LEGACY_DEPRECATED_WIFI} PRIVATE ${NAMESPACE}Plugins::${NAMESPACE}Plugins ) +if (USE_RDK_LOGGER) + target_link_libraries(${PLUGIN_LEGACY_DEPRECATED_WIFI} PRIVATE ${RDKLOGGER_LIBRARIES}) +endif (USE_RDK_LOGGER) + set_target_properties(${PLUGIN_LEGACY_DEPRECATED_WIFI} PROPERTIES CXX_STANDARD 11 CXX_STANDARD_REQUIRED YES) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 00000000..161c0928 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,4 @@ +Contributing +============ + +If you would like to contribute code to this project you can do so through GitHub by forking the repository and sending a pull request. Before RDK accepts your code into the project you must sign the RDK Contributor License Agreement (CLA). \ No newline at end of file diff --git a/NetworkManagerImplementation.cpp b/NetworkManagerImplementation.cpp index 2ae61301..6c488573 100644 --- a/NetworkManagerImplementation.cpp +++ b/NetworkManagerImplementation.cpp @@ -300,7 +300,7 @@ namespace WPEFramework snprintf(cmd, sizeof(cmd), "ping -c %d -W %d '%s' 2>&1", noOfRequest, timeOutInSeconds, endpoint.c_str()); } - NMLOG_INFO ("The Command is %s", cmd); + NMLOG_TRACE ("The Command is %s", cmd); string commandToExecute(cmd); executeExternally(NETMGR_PING, commandToExecute, response); @@ -321,7 +321,7 @@ namespace WPEFramework snprintf(cmd, 256, "traceroute -w 3 -m 6 -q %d %s 52 2>&1", noOfRequest, endpoint.c_str()); } - NMLOG_INFO ("The Command is %s", cmd); + NMLOG_TRACE ("The Command is %s", cmd); string commandToExecute(cmd); executeExternally(NETMGR_TRACE, commandToExecute, tempResult); diff --git a/NetworkManagerLogger.cpp b/NetworkManagerLogger.cpp index fe67d812..0b118314 100644 --- a/NetworkManagerLogger.cpp +++ b/NetworkManagerLogger.cpp @@ -34,7 +34,7 @@ #endif namespace NetworkManagerLogger { - static LogLevel gDefaultLogLevel = TRACE_LEVEL; + static LogLevel gDefaultLogLevel = INFO_LEVEL; const char* methodName(const std::string& prettyFunction) { @@ -72,7 +72,7 @@ namespace NetworkManagerLogger { } formattedLog[kFormatMessageSize - 1] = '\0'; #ifdef USE_RDK_LOGGER - RDK_LOG((int)level, "LOG.RDK.NETSRVMGER", "%s\n", formattedLog); + RDK_LOG(static_cast(level), "LOG.RDK.NETMGR", "%s\n", formattedLog); #else const char* levelMap[] = {"Fatal", "Error", "Warning", "Info", "Verbose", "Trace"}; struct timeval tv; diff --git a/NetworkManagerRDKProxy.cpp b/NetworkManagerRDKProxy.cpp index 32316f39..9fd5ffdc 100644 --- a/NetworkManagerRDKProxy.cpp +++ b/NetworkManagerRDKProxy.cpp @@ -399,8 +399,8 @@ namespace WPEFramework return Exchange::INetworkManager::WIFI_STATE_INVALID_CREDENTIALS; case WIFI_AUTH_FAILED: return Exchange::INetworkManager::WIFI_STATE_AUTHENTICATION_FAILED; - case WIFI_NO_SSID: - return Exchange::INetworkManager::WIFI_STATE_SSID_NOT_FOUND; + case WIFI_NO_SSID: + return Exchange::INetworkManager::WIFI_STATE_SSID_NOT_FOUND; case WIFI_UNKNOWN: return Exchange::INetworkManager::WIFI_STATE_ERROR; } @@ -818,10 +818,10 @@ namespace WPEFramework strncpy(iarmData.ipversion, ipversion.c_str(), 16); iarmData.isSupported = true; - NMLOG_INFO("NetworkManagerImplementation::GetIPSettings - Before Calling IARM"); + if (IARM_RESULT_SUCCESS == IARM_Bus_Call (IARM_BUS_NM_SRV_MGR_NAME, IARM_BUS_NETSRVMGR_API_getIPSettings, (void *)&iarmData, sizeof(iarmData))) { - NMLOG_INFO("NetworkManagerImplementation::GetIPSettings - IARM Success.. Filling the data"); + NMLOG_TRACE("NetworkManagerImplementation::GetIPSettings - IARM Success.. Filling the data"); result.m_ipAddrType = string(iarmData.ipversion); result.m_autoConfig = iarmData.autoconfig; result.m_dhcpServer = string(iarmData.dhcpserver,MAX_IP_ADDRESS_LEN - 1); @@ -829,12 +829,11 @@ namespace WPEFramework result.m_ipAddress = string(iarmData.ipaddress,MAX_IP_ADDRESS_LEN - 1); if (0 == strcasecmp("ipv4", iarmData.ipversion)) result.m_prefix = NetmaskToPrefix(iarmData.netmask); - else if (0 == strcasecmp("ipv6", iarmData.ipversion)) + else if (0 == strcasecmp("ipv6", iarmData.ipversion)) result.m_prefix = std::atoi(iarmData.netmask); result.m_gateway = string(iarmData.gateway,MAX_IP_ADDRESS_LEN - 1); result.m_primaryDns = string(iarmData.primarydns,MAX_IP_ADDRESS_LEN - 1); result.m_secondaryDns = string(iarmData.secondarydns,MAX_IP_ADDRESS_LEN - 1); - NMLOG_INFO("NetworkManagerImplementation::GetIPSettings - IARM Success.. Filled the data"); rc = Core::ERROR_NONE; } else @@ -1214,36 +1213,36 @@ const string CIDR_PREFIXES[CIDR_NETMASK_IP_LEN] = { signalStrength = ssidInfo.m_signalStrength; if (!signalStrength.empty()) - { + { signalStrengthOut = std::stof(signalStrength.c_str()); - NMLOG_INFO ("WiFiSignalStrength in dB = %s",signalStrengthOut); - } + NMLOG_INFO ("WiFiSignalStrength in dB = %s",signalStrengthOut); + } if (signalStrengthOut == 0) - { + { quality = WIFI_SIGNAL_DISCONNECTED; - signalStrength = "0"; - } + signalStrength = "0"; + } else if (signalStrengthOut >= signalStrengthThresholdExcellent && signalStrengthOut < 0) - { + { quality = WIFI_SIGNAL_EXCELLENT; - signalStrength = "100"; - } + signalStrength = "100"; + } else if (signalStrengthOut >= signalStrengthThresholdGood && signalStrengthOut < signalStrengthThresholdExcellent) - { + { quality = WIFI_SIGNAL_GOOD; - signalStrength = "75"; - } + signalStrength = "75"; + } else if (signalStrengthOut >= signalStrengthThresholdFair && signalStrengthOut < signalStrengthThresholdGood) - { + { quality = WIFI_SIGNAL_FAIR; - signalStrength = "50"; - } + signalStrength = "50"; + } else - { + { quality = WIFI_SIGNAL_WEAK; - signalStrength = "25"; - } + signalStrength = "25"; + } NMLOG_INFO ("GetWiFiSignalStrength success"); rc = Core::ERROR_NONE; diff --git a/README.md b/README.md index e7138355..dbe07701 100644 --- a/README.md +++ b/README.md @@ -13,9 +13,8 @@ The documentation for legacy [Network](https://github.com/rdkcentral/rdkservices ## Release ## There are 2 active branches namely `develop` and `main`. As the name conveys, `develop` branch is for active development and for contributions. -The Plugin workflow verifies every PR and also the team verifies the plugin on the RPi and RDK Device +The Plugin workflow verifies every PR and also the team verifies the plugin on the RPi and RDK Device. The verified changes are taken to `main` branch and releases will be made from there ## Questions? ## -If you have any questions or concerns reach out to [Jacob Gladish](mailto:Jacob_Gladish@cable.comcast.com) - and [Karunakaran Amirthalingam](mailto:karunakaran_amirthalingam@comcast.com). +If you have any questions or concerns reach out to [Jacob Gladish](mailto:Jacob_Gladish@cable.comcast.com) and [Karunakaran Amirthalingam](mailto:karunakaran_amirthalingam@comcast.com). diff --git a/cmake/Findrdklogger.cmake b/cmake/Findrdklogger.cmake new file mode 100644 index 00000000..3e08fb53 --- /dev/null +++ b/cmake/Findrdklogger.cmake @@ -0,0 +1,38 @@ +############################################################################# +# If not stated otherwise in this file or this component's Licenses.txt file +# the following copyright and licenses apply: +# +# Copyright 2016 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. +############################################################################# + +find_package(PkgConfig) + +find_library(RDKLOGGER_LIBRARIES NAMES rdkloggers) +find_path(RDKLOGGER_INCLUDE_DIRS NAMES rdk_debug.h) + +set(RDKLOGGER_LIBRARIES ${RDKLOGGER_LIBRARIES} CACHE PATH "Path to rdkLogger library") +set(RDKLOGGER_INCLUDE_DIRS ${RDKLOGGER_INCLUDE_DIRS} ) +set(RDKLOGGER_INCLUDE_DIRS ${RDKLOGGER_INCLUDE_DIRS} CACHE PATH "Path to rdkLogger include") + +include(FindPackageHandleStandardArgs) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(RDKLOGGER DEFAULT_MSG RDKLOGGER_INCLUDE_DIRS RDKLOGGER_LIBRARIES) + +mark_as_advanced( + RDKLOGGER_FOUND + RDKLOGGER_INCLUDE_DIRS + RDKLOGGER_LIBRARIES + RDKLOGGER_LIBRARY_DIRS + RDKLOGGER_FLAGS)