From cb8d7725812c51d9fef67e5eb3c6a6b46754a61f Mon Sep 17 00:00:00 2001 From: preeja33 Date: Sat, 6 Jun 2026 01:30:27 +0530 Subject: [PATCH 1/2] RDKEMW-16743:Integrate to common headers (#18) * integrate common helpers * Update L2-tests-oop.yml * Update L2-tests.yml * Update L2-tests.yml * Update L2-tests-oop.yml * Update L2-tests.yml * Update testframework to 1.0.12 and fix entservices-helpers build * Update L2-tests.yml * Update L1-tests.yml * Update L2-tests-oop.yml * Update L2-tests.yml * Update L1-tests.yml * Fixed * Fix build * Fixed build issues --------- Co-authored-by: srinibas15 <113517102+srinibas15@users.noreply.github.com> Co-authored-by: rajaLucy --- .github/workflows/L1-tests.yml | 34 ++++- .github/workflows/L2-tests-oop.yml | 35 ++++- .github/workflows/L2-tests.yml | 34 ++++- Tests/L1Tests/CMakeLists.txt | 4 +- Tests/L2Tests/CMakeLists.txt | 1 - build_dependencies.sh | 30 +++- cmake/FindWPEFrameworkHelpers.cmake | 39 +++++ helpers/PluginInterfaceBuilder.h | 225 ---------------------------- helpers/UtilsFile.h | 112 -------------- helpers/UtilsJsonRpc.h | 169 --------------------- helpers/UtilsLogging.h | 36 ----- helpers/UtilsTelemetry.h | 71 --------- helpers/UtilssyncPersistFile.h | 63 -------- plugin/CMakeLists.txt | 10 +- 14 files changed, 169 insertions(+), 694 deletions(-) create mode 100644 cmake/FindWPEFrameworkHelpers.cmake delete mode 100755 helpers/PluginInterfaceBuilder.h delete mode 100644 helpers/UtilsFile.h delete mode 100644 helpers/UtilsJsonRpc.h delete mode 100644 helpers/UtilsLogging.h delete mode 100644 helpers/UtilsTelemetry.h delete mode 100644 helpers/UtilssyncPersistFile.h diff --git a/.github/workflows/L1-tests.yml b/.github/workflows/L1-tests.yml index 440aa87..37f6ddd 100755 --- a/.github/workflows/L1-tests.yml +++ b/.github/workflows/L1-tests.yml @@ -125,7 +125,7 @@ jobs: with: repository: rdkcentral/entservices-testframework path: entservices-testframework - ref: 1.0.1 + ref: 1.0.14 - name: Checkout entservices-usersettings if: ${{ inputs.caller_source == 'local' }} @@ -334,6 +334,34 @@ jobs: && cmake --install build/googletest + - name: Checkout entservices-helpers + uses: actions/checkout@v3 + with: + repository: rdkcentral/entservices-helpers + path: entservices-helpers + ref: develop + + - name: Build entservices-helpers + run: > + cmake -G Ninja + -S "$GITHUB_WORKSPACE/entservices-helpers" + -B build/entservices-helpers + -DCMAKE_INSTALL_PREFIX="$GITHUB_WORKSPACE/install/usr" + -DCMAKE_MODULE_PATH="$GITHUB_WORKSPACE/install/tools/cmake" + -DUSE_THUNDER_R4=ON + -DHIDE_NON_EXTERNAL_SYMBOLS=OFF + -DPLUGIN_HELPERS=ON + "-DCMAKE_CXX_FLAGS= + -I$GITHUB_WORKSPACE/entservices-testframework/Tests/headers + -I$GITHUB_WORKSPACE/entservices-testframework/Tests/headers/rdk/iarmbus + -I$GITHUB_WORKSPACE/entservices-testframework/Tests/mocks + -include $GITHUB_WORKSPACE/entservices-testframework/Tests/mocks/tr181api.h + -include $GITHUB_WORKSPACE/entservices-testframework/Tests/mocks/Iarm.h" + && + cmake --build build/entservices-helpers + && + cmake --install build/entservices-helpers + - name: Build mocks run: > cmake @@ -361,7 +389,7 @@ jobs: -I $GITHUB_WORKSPACE/entservices-testframework/Tests/headers/ccec/drivers -I $GITHUB_WORKSPACE/entservices-testframework/Tests/headers/network -I $GITHUB_WORKSPACE/entservices-testframework/Tests - -I $GITHUB_WORKSPACE/entservices-usersettings/helpers + -I $GITHUB_WORKSPACE/entservices-helpers/helpers -I $GITHUB_WORKSPACE/install/usr/include -I ./usr/include/libdrm -include $GITHUB_WORKSPACE/entservices-testframework/Tests/mocks/devicesettings.h @@ -500,7 +528,7 @@ jobs: -I $GITHUB_WORKSPACE/entservices-testframework/Tests/headers/rdk/iarmmgrs-hal -I $GITHUB_WORKSPACE/entservices-testframework/Tests/headers/ccec/drivers -I $GITHUB_WORKSPACE/entservices-testframework/Tests/headers/network - -I $GITHUB_WORKSPACE/entservices-usersettings/helpers + -I $GITHUB_WORKSPACE/entservices-helpers/helpers -I $GITHUB_WORKSPACE/entservices-testframework/Tests -I $GITHUB_WORKSPACE/install/usr/include -I ./usr/include/libdrm diff --git a/.github/workflows/L2-tests-oop.yml b/.github/workflows/L2-tests-oop.yml index 9986841..db989bf 100755 --- a/.github/workflows/L2-tests-oop.yml +++ b/.github/workflows/L2-tests-oop.yml @@ -105,7 +105,7 @@ jobs: with: repository: rdkcentral/entservices-testframework path: entservices-testframework - ref: 1.0.1 + ref: 1.0.14 - name: Checkout entservices-persistentstore uses: actions/checkout@v3 @@ -133,7 +133,7 @@ jobs: with: repository: rdkcentral/entservices-persistentstore path: entservices-persistentstore - ref: feature/RDKEMW-13477 + ref: develop - name: Apply ThunderTools run: | @@ -349,6 +349,34 @@ jobs: && cmake --install build/mocks + - name: Checkout entservices-helpers + uses: actions/checkout@v3 + with: + repository: rdkcentral/entservices-helpers + path: entservices-helpers + ref: develop + + - name: Build entservices-helpers + run: > + cmake -G Ninja + -S "$GITHUB_WORKSPACE/entservices-helpers" + -B build/entservices-helpers + -DCMAKE_INSTALL_PREFIX="$GITHUB_WORKSPACE/install/usr" + -DCMAKE_MODULE_PATH="$GITHUB_WORKSPACE/install/tools/cmake" + -DUSE_THUNDER_R4=ON + -DHIDE_NON_EXTERNAL_SYMBOLS=OFF + -DPLUGIN_HELPERS=ON + "-DCMAKE_CXX_FLAGS= + -I$GITHUB_WORKSPACE/entservices-testframework/Tests/headers + -I$GITHUB_WORKSPACE/entservices-testframework/Tests/headers/rdk/iarmbus + -I$GITHUB_WORKSPACE/entservices-testframework/Tests/mocks + -include $GITHUB_WORKSPACE/entservices-testframework/Tests/mocks/tr181api.h + -include $GITHUB_WORKSPACE/entservices-testframework/Tests/mocks/Iarm.h" + && + cmake --build build/entservices-helpers + && + cmake --install build/entservices-helpers + - name: Build entservices-persistentstore run: > cmake @@ -463,6 +491,7 @@ jobs: -I $GITHUB_WORKSPACE/entservices-testframework/Tests/headers/systemservices -I $GITHUB_WORKSPACE/entservices-testframework/Tests/headers/systemservices/proc -I $GITHUB_WORKSPACE/entservices-testframework/Tests/headers/libusb + -I $GITHUB_WORKSPACE/entservices-helpers/helpers -I $GITHUB_WORKSPACE/install/usr/include -I ./usr/include/libdrm -include $GITHUB_WORKSPACE/entservices-testframework/Tests/mocks/devicesettings.h @@ -543,7 +572,7 @@ jobs: -I $GITHUB_WORKSPACE/entservices-testframework/Tests/headers/rdk/iarmmgrs-hal -I $GITHUB_WORKSPACE/entservices-testframework/Tests/headers/systemservices -I $GITHUB_WORKSPACE/entservices-testframework/Tests/headers/systemservices/proc - -I $GITHUB_WORKSPACE/entservices-usersettings/helpers + -I $GITHUB_WORKSPACE/entservices-helpers/helpers -I $GITHUB_WORKSPACE/install/usr/include -I ./usr/include/libdrm -include $GITHUB_WORKSPACE/entservices-testframework/Tests/mocks/devicesettings.h diff --git a/.github/workflows/L2-tests.yml b/.github/workflows/L2-tests.yml index 4f3ddb5..51b77c4 100755 --- a/.github/workflows/L2-tests.yml +++ b/.github/workflows/L2-tests.yml @@ -114,7 +114,7 @@ jobs: with: repository: rdkcentral/entservices-testframework path: entservices-testframework - ref: 1.0.1 + ref: 1.0.14 - name: Checkout entservices-persistentstore uses: actions/checkout@v3 @@ -323,6 +323,7 @@ jobs: -DCMAKE_INSTALL_PREFIX="$GITHUB_WORKSPACE/install/usr" -DCMAKE_MODULE_PATH="$GITHUB_WORKSPACE/install/tools/cmake" -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} + -DRDK_SERVICE_L2_TEST=ON -DCMAKE_CXX_FLAGS=" -I $GITHUB_WORKSPACE/entservices-testframework/Tests/headers -I $GITHUB_WORKSPACE/install/usr/include" @@ -331,6 +332,34 @@ jobs: && cmake --install build/mocks + - name: Checkout entservices-helpers + uses: actions/checkout@v3 + with: + repository: rdkcentral/entservices-helpers + path: entservices-helpers + ref: develop + + - name: Build entservices-helpers + run: > + cmake -G Ninja + -S "$GITHUB_WORKSPACE/entservices-helpers" + -B build/entservices-helpers + -DCMAKE_INSTALL_PREFIX="$GITHUB_WORKSPACE/install/usr" + -DCMAKE_MODULE_PATH="$GITHUB_WORKSPACE/install/tools/cmake" + -DUSE_THUNDER_R4=ON + -DHIDE_NON_EXTERNAL_SYMBOLS=OFF + -DPLUGIN_HELPERS=ON + "-DCMAKE_CXX_FLAGS= + -I$GITHUB_WORKSPACE/entservices-testframework/Tests/headers + -I$GITHUB_WORKSPACE/entservices-testframework/Tests/headers/rdk/iarmbus + -I$GITHUB_WORKSPACE/entservices-testframework/Tests/mocks + -include $GITHUB_WORKSPACE/entservices-testframework/Tests/mocks/tr181api.h + -include $GITHUB_WORKSPACE/entservices-testframework/Tests/mocks/Iarm.h" + && + cmake --build build/entservices-helpers + && + cmake --install build/entservices-helpers + - name: Build entservices-persistentstore run: > cmake @@ -446,6 +475,7 @@ jobs: -I $GITHUB_WORKSPACE/entservices-testframework/Tests/headers/systemservices -I $GITHUB_WORKSPACE/entservices-testframework/Tests/headers/systemservices/proc -I $GITHUB_WORKSPACE/entservices-testframework/Tests/headers/libusb + -I $GITHUB_WORKSPACE/entservices-helpers/helpers -I $GITHUB_WORKSPACE/install/usr/include -I $GITHUB_WORKSPACE/build/mocks -I $GITHUB_WORKSPACE/entservices-testframework/Tests/mocks @@ -528,7 +558,7 @@ jobs: -I $GITHUB_WORKSPACE/entservices-testframework/Tests/headers/rdk/iarmmgrs-hal -I $GITHUB_WORKSPACE/entservices-testframework/Tests/headers/systemservices -I $GITHUB_WORKSPACE/entservices-testframework/Tests/headers/systemservices/proc - -I $GITHUB_WORKSPACE/entservices-usersettings/helpers + -I $GITHUB_WORKSPACE/entservices-helpers/helpers -I $GITHUB_WORKSPACE/install/usr/include -I ./usr/include/libdrm -include $GITHUB_WORKSPACE/entservices-testframework/Tests/mocks/devicesettings.h diff --git a/Tests/L1Tests/CMakeLists.txt b/Tests/L1Tests/CMakeLists.txt index 8e62a60..e2315d6 100755 --- a/Tests/L1Tests/CMakeLists.txt +++ b/Tests/L1Tests/CMakeLists.txt @@ -28,7 +28,7 @@ set (TEST_LIB ${NAMESPACE}Plugins::${NAMESPACE}Plugins ) -set (TEST_INC ../../helpers) +set (TEST_INC) ######################################################################################### # add_plugin_test_ex: Macro to add plugin tests, it will append to TEST_SRC, TEST_INC, @@ -98,7 +98,7 @@ macro(add_plugin_test plugin_name test_files) endmacro() # PLUGIN_USERSETTINGS -set (USERSETTINGS_INC ${CMAKE_SOURCE_DIR}/plugin ${CMAKE_SOURCE_DIR}/helpers) +set (USERSETTINGS_INC ${CMAKE_SOURCE_DIR}/plugin ${CMAKE_SOURCE_DIR}/../entservices-helpers/helpers) set (USERSETTINGS_LIBS ${NAMESPACE}UserSettings ${NAMESPACE}UserSettingsImplementation) add_plugin_test_ex(PLUGIN_USERSETTINGS tests/test_UserSettings.cpp "${USERSETTINGS_INC}" "${USERSETTINGS_LIBS}") diff --git a/Tests/L2Tests/CMakeLists.txt b/Tests/L2Tests/CMakeLists.txt index df03e5e..7f64ff0 100755 --- a/Tests/L2Tests/CMakeLists.txt +++ b/Tests/L2Tests/CMakeLists.txt @@ -60,7 +60,6 @@ endif (MOCKACCESSOR_LIBRARIES) target_include_directories( ${MODULE_NAME} PRIVATE ./ - ../../helpers ../../../entservices-testframework/Tests/mocks ../../../entservices-testframework/Tests/mocks/thunder ../../../entservices-testframework/Tests/mocks/devicesettings diff --git a/build_dependencies.sh b/build_dependencies.sh index aedb90e..2bd71ff 100644 --- a/build_dependencies.sh +++ b/build_dependencies.sh @@ -51,7 +51,11 @@ git clone --branch R4.4.1 https://github.com/rdkcentral/Thunder.git git clone --branch main https://github.com/rdkcentral/entservices-apis.git -git clone --branch 1.0.1 https://github.com/rdkcentral/entservices-testframework.git +cd .. +git clone --branch develop https://github.com/rdkcentral/entservices-helpers.git +cd "$GITHUB_WORKSPACE" + +git clone --branch 1.0.12 https://github.com/rdkcentral/entservices-testframework.git ############################ # Build Thunder-Tools @@ -112,7 +116,29 @@ cmake -G Ninja -S entservices-apis -B build/entservices-apis \ cmake --build build/entservices-apis --target install - +############################ +# generating minimal mock headers +cd $GITHUB_WORKSPACE/entservices-testframework/Tests +mkdir -p headers +cd headers +touch secure_wrapper.h +touch wpa_ctrl.h +touch rdk_logger_milestone.h +mkdir -p rdk/iarmbus +touch rdk/iarmbus/libIARM.h +touch rdk/iarmbus/libIBus.h +touch iarm.h +cd $GITHUB_WORKSPACE +############################## +# Build entservices-helpers +echo "======================================================================================" +echo "building entservices-helpers" +cmake -G Ninja -S ../entservices-helpers -B build/entservices-helpers \ + -DEXCEPTIONS_ENABLE=ON \ + -DCMAKE_INSTALL_PREFIX="$GITHUB_WORKSPACE/install/usr" \ + -DCMAKE_MODULE_PATH="$GITHUB_WORKSPACE/install/tools/cmake" \ + "-DCMAKE_CXX_FLAGS=-I$GITHUB_WORKSPACE/entservices-testframework/Tests/mocks -I$GITHUB_WORKSPACE/entservices-testframework/Tests/headers -I$GITHUB_WORKSPACE/entservices-testframework/Tests/headers/rdk/iarmbus -include $GITHUB_WORKSPACE/entservices-testframework/Tests/mocks/tr181api.h -include $GITHUB_WORKSPACE/entservices-testframework/Tests/mocks/Iarm.h " +cmake --build build/entservices-helpers --target install ############################ # generating extrnal headers diff --git a/cmake/FindWPEFrameworkHelpers.cmake b/cmake/FindWPEFrameworkHelpers.cmake new file mode 100644 index 0000000..0548f7f --- /dev/null +++ b/cmake/FindWPEFrameworkHelpers.cmake @@ -0,0 +1,39 @@ +# - Try to find WPEFrameworkHelpers +# Once done this will define +# WPEFrameworkHelpers_FOUND - System has WPEFrameworkHelpers +# WPEFrameworkHelpers_INCLUDE_DIRS - The WPEFrameworkHelpers include directories +# WPEFrameworkHelpers_LIBRARIES - The libraries needed to use WPEFrameworkHelpers +# +# Also creates an imported target: +# WPEFramework::WPEFrameworkHelpers + +find_library(WPEFrameworkHelpers_LIBRARIES + NAMES WPEFrameworkHelpers + PATH_SUFFIXES wpeframework/plugins) + +find_path(WPEFrameworkHelpers_INCLUDE_DIRS + NAMES UtilsLogging.h + PATH_SUFFIXES wpeframework/helpers) + +set(WPEFrameworkHelpers_LIBRARIES + ${WPEFrameworkHelpers_LIBRARIES} + CACHE PATH "Path to WPEFrameworkHelpers library") + +set(WPEFrameworkHelpers_INCLUDE_DIRS ${WPEFrameworkHelpers_INCLUDE_DIRS} CACHE PATH "Path to WPEFrameworkHelpers includes") + +include(FindPackageHandleStandardArgs) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(WPEFrameworkHelpers DEFAULT_MSG + WPEFrameworkHelpers_INCLUDE_DIRS + WPEFrameworkHelpers_LIBRARIES) + +if(WPEFrameworkHelpers_FOUND AND NOT TARGET WPEFramework::WPEFrameworkHelpers) + add_library(WPEFramework::WPEFrameworkHelpers SHARED IMPORTED) + set_target_properties(WPEFramework::WPEFrameworkHelpers PROPERTIES + IMPORTED_LOCATION "${WPEFrameworkHelpers_LIBRARIES}" + INTERFACE_INCLUDE_DIRECTORIES "${WPEFrameworkHelpers_INCLUDE_DIRS}") +endif() + +mark_as_advanced( + WPEFrameworkHelpers_FOUND + WPEFrameworkHelpers_INCLUDE_DIRS + WPEFrameworkHelpers_LIBRARIES) diff --git a/helpers/PluginInterfaceBuilder.h b/helpers/PluginInterfaceBuilder.h deleted file mode 100755 index 65cda09..0000000 --- a/helpers/PluginInterfaceBuilder.h +++ /dev/null @@ -1,225 +0,0 @@ -/** - * If not stated otherwise in this file or this component's LICENSE - * file the following copyright and licenses apply: - * - * Copyright 2024 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. - **/ -#pragma once - -#include -#include -#include - -#include "UtilsLogging.h" - -namespace WPEFramework { -namespace PluginHost { - class IShell; -} - -namespace Plugin { - - template - class PluginInterfaceRef { - INTERFACE* _interface; - PluginHost::IShell* _service; - - public: - PluginInterfaceRef() - : _interface(nullptr), _service(nullptr) - { - } - - PluginInterfaceRef(INTERFACE* interface, PluginHost::IShell* controller) - : _interface(interface), _service(controller) - { - } - - ~PluginInterfaceRef() - { - Reset(); - } - - // avoid copies - PluginInterfaceRef(const PluginInterfaceRef&) = delete; - PluginInterfaceRef& operator=(const PluginInterfaceRef&) = delete; - - // use move - PluginInterfaceRef(PluginInterfaceRef&& other) - : _interface(other._interface), _service(other._service) - { - other._interface = nullptr; - other._service = nullptr; - } - - PluginInterfaceRef& operator=(PluginInterfaceRef&& other) - { - if (this != &other) { - _interface = other._interface; - other._interface = nullptr; - } - return *this; - } - - operator bool() const - { - return _interface != nullptr; - } - - INTERFACE* operator->() const - { - return _interface; - } - - void Reset() - { - if (_interface) { - _interface->Release(); - _interface = nullptr; - } - } - }; - - template - class PluginInterfaceBuilder; - - // default impl - template - INTERFACE* createInterface(PluginInterfaceBuilder& builder) - { - WPEFramework::PluginHost::IShell* controller = builder.controller(); - const std::string& callsign = builder.callSign(); - const int retry_count = builder.retryCount(); - const uint32_t retry_interval = builder.retryInterval(); - int count = 0; - - if (!controller) { - LOGERR("Invalid controller"); - return nullptr; - } - - do { - auto pluginInterface = controller->QueryInterfaceByCallsign(callsign.c_str()); - - if (pluginInterface) { - LOGINFO("plugin interface succeed and retry count: %d",count); - return pluginInterface; - } - else - { - count++; - LOGERR("plugin interface failed and retry: %d",count); - usleep(retry_interval*1000); - } - }while(count < retry_count); - - return nullptr; - } - - template - std::unique_ptr make_unique(Args&&... args) - { - return std::unique_ptr(new T(std::forward(args)...)); - } - - template - class PluginInterfaceBuilder { - - const std::string _callsign; - PluginHost::IShell* _service; - uint32_t _version; - uint32_t _timeout; - int _retry_count; - uint32_t _retry_interval; - - public: - PluginInterfaceBuilder(const char* callsign) - : _callsign(callsign) - , _service(nullptr) - , _version(static_cast(~0)) - , _timeout(3000) - ,_retry_count(0) - ,_retry_interval(0) - { - } - - // won't take ownership of ref members - ~PluginInterfaceBuilder() = default; - - inline PluginInterfaceBuilder& withVersion(uint32_t version) - { - _version = version; - return *this; - } - - inline PluginInterfaceBuilder& withTimeout(uint32_t timeoutMs) - { - _timeout = timeoutMs; - return *this; - } - - inline PluginInterfaceBuilder& withIShell(PluginHost::IShell * service) - { - _service = service; - return *this; - } - - inline PluginInterfaceBuilder& withRetryIntervalMS(int retryInterval) - { - _retry_interval = retryInterval; - return *this; - } - - inline PluginInterfaceBuilder& withRetryCount(int retryCount) - { - _retry_count = retryCount; - return *this; - } - - PluginInterfaceRef createInterface() - { - auto* interface = ::WPEFramework::Plugin::createInterface(*this); - - if (!interface) { - LOGERR("Failed to create plugin interface for %s", _callsign.c_str()); - } - - // pass on the ownership of controller to interfaceRef - return std::move(PluginInterfaceRef(interface, _service)); - } - - uint32_t retryInterval() const - { - return _retry_interval; - } - - int retryCount() const - { - return _retry_count; - } - - const std::string& callSign() const - { - return _callsign; - } - - WPEFramework::PluginHost::IShell* controller() - { - return _service; - } - }; - -} // Plugin -} // WPEFramework diff --git a/helpers/UtilsFile.h b/helpers/UtilsFile.h deleted file mode 100644 index 5d34c2a..0000000 --- a/helpers/UtilsFile.h +++ /dev/null @@ -1,112 +0,0 @@ -/** -* If not stated otherwise in this file or this component's LICENSE -* file the following copyright and licenses apply: -* -* Copyright 2024 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. -**/ - -#pragma once - -#include -#include -#include -#include - -using namespace std; - -namespace Utils -{ -auto MoveFile( - const string &from, - const string &to) -> bool -{ - using namespace WPEFramework::Core; - - File fileFrom(from); - File fileTo(to); - - Directory(fileTo.PathName().c_str()).CreatePath(); - - bool result = - fileFrom.Exists() && - !fileTo.Exists() && - fileFrom.Open(true) && - fileTo.Create(); - - if (result) { - const uint32_t bufLen = 1024; - - uint8_t buffer[bufLen]; - - do { - auto len = fileFrom.Read(buffer, bufLen); - if (len <= 0) { - break; - } - - auto ptr = buffer; - - do { - auto count = fileTo.Write(ptr, len); - if (count <= 0) { - result = false; - break; - } - - len -= count; - ptr += count; - } - while (len > 0); - } - while (result); - - if (result) { - fileFrom.Destroy(); - } - else { - fileTo.Destroy(); - } - } - - return result; -} - -/** -* @brief Get the last non empty line from the input string, equivalent to "tr -s '\r' '\n' | tail -n 1" -* @param[in] input - The input string -* @param[out] res_str - The last non empty line from the input string -* @return whether or not a non empty line was found -*/ -bool getLastLine(const std::string& input, std::string& res_str) -{ - string read_line = ""; - bool ret_value = false; - - if (!input.empty()) - { - stringstream read_str(input); - while (getline(read_str, read_line, '\n')) - { - if (!read_line.empty()) - { - res_str = read_line; - ret_value = true; - } - } - } - return ret_value; -} - -} diff --git a/helpers/UtilsJsonRpc.h b/helpers/UtilsJsonRpc.h deleted file mode 100644 index bff772a..0000000 --- a/helpers/UtilsJsonRpc.h +++ /dev/null @@ -1,169 +0,0 @@ -/** -* If not stated otherwise in this file or this component's LICENSE -* file the following copyright and licenses apply: -* -* Copyright 2024 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. -**/ - -#pragma once - -#include "UtilsLogging.h" - -#define LOGINFOMETHOD() { std::string json; parameters.ToString(json); LOGINFO( "params=%s", json.c_str() ); } -#define LOGTRACEMETHODFIN() { std::string json; response.ToString(json); LOGINFO( "response=%s", json.c_str() ); } - -/** - * DO NOT USE THIS. - * - * "success" parameter was added for legacy reasons. - * Newer APIs should return only error code to match the spec - */ - -#define returnResponse(expression) \ - { \ - bool successBoolean = expression; \ - response["success"] = successBoolean; \ - LOGTRACEMETHODFIN(); \ - return (successBoolean ? WPEFramework::Core::ERROR_NONE : WPEFramework::Core::ERROR_GENERAL); \ - } -#define returnIfParamNotFound(param, name) \ - if (!param.HasLabel(name)) \ - { \ - LOGERR("No argument '%s'", name); \ - returnResponse(false); \ - } -#define returnIfStringParamNotFound(param, name) \ - if (!param.HasLabel(name) || param[name].Content() != WPEFramework::Core::JSON::Variant::type::STRING) \ - {\ - LOGERR("No argument '%s' or it has incorrect type", name); \ - returnResponse(false); \ - } -#define returnIfBooleanParamNotFound(param, name) \ - if (!param.HasLabel(name) || param[name].Content() != WPEFramework::Core::JSON::Variant::type::BOOLEAN) \ - { \ - LOGERR("No argument '%s' or it has incorrect type", name); \ - returnResponse(false); \ - } -#define returnIfNumberParamNotFound(param, name) \ - if (!param.HasLabel(name) || param[name].Content() != WPEFramework::Core::JSON::Variant::type::NUMBER) \ - { \ - LOGERR("No argument '%s' or it has incorrect type", name); \ - returnResponse(false); \ - } - -/** - * DO NOT USE THIS. - * - * You should be capable of just using "Notify". - */ - -#if ((THUNDER_VERSION >= 4) && (THUNDER_VERSION_MINOR == 4)) - -#define sendNotify(event,params) { \ - std::string json; \ - params.ToString(json); \ - LOGINFO("Notify %s %s", event, json.c_str()); \ - Notify(event,params); \ -} - -#define sendNotifyMaskParameters(event,params) { \ - std::string json; \ - params.ToString(json); \ - LOGINFO("Notify %s <***>", event); \ - Notify(event,params); \ -} - -#else - -#define sendNotify(event,params) { \ - std::string json; \ - params.ToString(json); \ - LOGINFO("Notify %s %s", event, json.c_str()); \ - for (uint8_t i = 1; GetHandler(i); i++) GetHandler(i)->Notify(event,params); \ -} -#define sendNotifyMaskParameters(event,params) { \ - std::string json; \ - params.ToString(json); \ - LOGINFO("Notify %s <***>", event); \ - for (uint8_t i = 1; GetHandler(i); i++) GetHandler(i)->Notify(event,params); \ -} - -#endif -/** - * DO NOT USE THIS. - * - * Instead, add YOURPLUGINNAME.json to https://github.com/rdkcentral/ThunderInterfaces - * and use the generated classes from - */ - -#define getNumberParameter(paramName, param) { \ - if (WPEFramework::Core::JSON::Variant::type::NUMBER == parameters[paramName].Content()) \ - param = parameters[paramName].Number(); \ - else \ - try { param = std::stoi( parameters[paramName].String()); } \ - catch (...) { param = 0; } \ -} -#define getNumberParameterObject(parameters, paramName, param) { \ - if (WPEFramework::Core::JSON::Variant::type::NUMBER == parameters[paramName].Content()) \ - param = parameters[paramName].Number(); \ - else \ - try {param = std::stoi( parameters[paramName].String());} \ - catch (...) { param = 0; } \ -} -#define getBoolParameter(paramName, param) { \ - if (WPEFramework::Core::JSON::Variant::type::BOOLEAN == parameters[paramName].Content()) \ - param = parameters[paramName].Boolean(); \ - else \ - param = parameters[paramName].String() == "true" || parameters[paramName].String() == "1"; \ -} -#define getStringParameter(paramName, param) { \ - if (WPEFramework::Core::JSON::Variant::type::STRING == parameters[paramName].Content()) \ - param = parameters[paramName].String(); \ -} -#define getFloatParameter(paramName, param) { \ - if (Core::JSON::Variant::type::FLOAT == parameters[paramName].Content()) \ - param = parameters[paramName].Float(); \ - else \ - try { param = std::stof( parameters[paramName].String()); } \ - catch (...) { param = 0; } \ -} -#define vectorSet(v,s) \ - if (find(begin(v), end(v), s) == end(v)) \ - v.emplace_back(s); -#define getDefaultNumberParameter(paramName, param, default) { \ - if (parameters.HasLabel(paramName)) { \ - if (WPEFramework::Core::JSON::Variant::type::NUMBER == parameters[paramName].Content()) \ - param = parameters[paramName].Number(); \ - else \ - try { param = std::stoi( parameters[paramName].String()); } \ - catch (...) { param = default; } \ - } else param = default; \ -} -#define getDefaultStringParameter(paramName, param, default) { \ - if (parameters.HasLabel(paramName)) { \ - if (WPEFramework::Core::JSON::Variant::type::STRING == parameters[paramName].Content()) \ - param = parameters[paramName].String(); \ - else \ - param = default; \ - } else param = default; \ -} -#define getDefaultBoolParameter(paramName, param, default) { \ - if (parameters.HasLabel(paramName)) { \ - if (WPEFramework::Core::JSON::Variant::type::BOOLEAN == parameters[paramName].Content()) \ - param = parameters[paramName].Boolean(); \ - else \ - param = parameters[paramName].String() == "true" || parameters[paramName].String() == "1"; \ - } else param = default; \ -} diff --git a/helpers/UtilsLogging.h b/helpers/UtilsLogging.h deleted file mode 100644 index fb50b6a..0000000 --- a/helpers/UtilsLogging.h +++ /dev/null @@ -1,36 +0,0 @@ -/** -* If not stated otherwise in this file or this component's LICENSE -* file the following copyright and licenses apply: -* -* Copyright 2024 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. -**/ - -#pragma once - -#include - -#ifdef __DEBUG__ // XXX: maybe use BUILD_TYPE -#define LOGTRACE(fmt, ...) do { fprintf(stderr, "[%d] TRACE [%s:%d] %s: " fmt "\n", (int)syscall(SYS_gettid), WPEFramework::Core::FileNameOnly(__FILE__), __LINE__, __FUNCTION__, ##__VA_ARGS__); fflush(stderr); } while (0) -#else -#define LOGTRACE(fmt, ...) -#endif -#define LOGDBG(fmt, ...) do { fprintf(stderr, "[%d] DEBUG [%s:%d] %s: " fmt "\n", (int)syscall(SYS_gettid), WPEFramework::Core::FileNameOnly(__FILE__), __LINE__, __FUNCTION__, ##__VA_ARGS__); fflush(stderr); } while (0) -#define LOGINFO(fmt, ...) do { fprintf(stderr, "[%d] INFO [%s:%d] %s: " fmt "\n", (int)syscall(SYS_gettid), WPEFramework::Core::FileNameOnly(__FILE__), __LINE__, __FUNCTION__, ##__VA_ARGS__); fflush(stderr); } while (0) -#define LOGWARN(fmt, ...) do { fprintf(stderr, "[%d] WARN [%s:%d] %s: " fmt "\n", (int)syscall(SYS_gettid), WPEFramework::Core::FileNameOnly(__FILE__), __LINE__, __FUNCTION__, ##__VA_ARGS__); fflush(stderr); } while (0) -#define LOGERR(fmt, ...) do { fprintf(stderr, "[%d] ERROR [%s:%d] %s: " fmt "\n", (int)syscall(SYS_gettid), WPEFramework::Core::FileNameOnly(__FILE__), __LINE__, __FUNCTION__, ##__VA_ARGS__); fflush(stderr); } while (0) - -#define LOG_DEVICE_EXCEPTION0() LOGWARN("Exception caught: code=%d message=%s", err.getCode(), err.what()); -#define LOG_DEVICE_EXCEPTION1(param1) LOGWARN("Exception caught" #param1 "=%s code=%d message=%s", param1.c_str(), err.getCode(), err.what()); -#define LOG_DEVICE_EXCEPTION2(param1, param2) LOGWARN("Exception caught " #param1 "=%s " #param2 "=%s code=%d message=%s", param1.c_str(), param2.c_str(), err.getCode(), err.what()); diff --git a/helpers/UtilsTelemetry.h b/helpers/UtilsTelemetry.h deleted file mode 100644 index 0d564c2..0000000 --- a/helpers/UtilsTelemetry.h +++ /dev/null @@ -1,71 +0,0 @@ -/** -* If not stated otherwise in this file or this component's LICENSE -* file the following copyright and licenses apply: -* -* Copyright 2024 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. -**/ - -#pragma once - -// telemetry -#ifdef ENABLE_TELEMETRY_LOGGING -#include -#endif - -namespace Utils -{ - struct Telemetry - { - static void init() - { -#ifdef ENABLE_TELEMETRY_LOGGING - t2_init((char *) "Thunder_Plugins"); -#endif - }; - - static void sendMessage(char* message) - { -#ifdef ENABLE_TELEMETRY_LOGGING - t2_event_s((char *)"THUNDER_MESSAGE", message); -#endif - }; - - static void sendMessage(char *marker, char* message) - { -#ifdef ENABLE_TELEMETRY_LOGGING - t2_event_s(marker, message); -#endif - }; - - static void sendError(const char* format, ...) - { -#ifdef ENABLE_TELEMETRY_LOGGING - va_list parameters; - va_start(parameters, format); - std::string message; - WPEFramework::Trace::Format(message, format, parameters); - va_end(parameters); - - // get rid of const for t2_event_s - char* error = strdup(message.c_str()); - t2_event_s((char *)"THUNDER_ERROR", error); - if (error) - { - free(error); - } -#endif - }; - }; -} diff --git a/helpers/UtilssyncPersistFile.h b/helpers/UtilssyncPersistFile.h deleted file mode 100644 index 0ba6720..0000000 --- a/helpers/UtilssyncPersistFile.h +++ /dev/null @@ -1,63 +0,0 @@ -/** -* If not stated otherwise in this file or this component's LICENSE -* file the following copyright and licenses apply: -* -* Copyright 2024 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. -**/ - -#pragma once - -#include - -#include - -namespace Utils { -inline void syncPersistFile(const string file) -{ - FILE* fp = NULL; - fp = fopen(file.c_str(), "r"); - if (fp == NULL) { - printf("fopen NULL\n"); - return; - } - fflush(fp); - fsync(fileno(fp)); - fclose(fp); -} - -inline void persistJsonSettings(const string strFile, const string strKey, const JsonValue& jsValue) -{ - WPEFramework::Core::File file; - file = strFile.c_str(); - - file.Open(false); - if (!file.IsOpen()) - file.Create(); - - JsonObject cecSetting; - cecSetting.IElement::FromFile(file); - file.Destroy(); - file.Create(); - cecSetting[strKey.c_str()] = jsValue; - cecSetting.IElement::ToFile(file); - - file.Close(); - - //Sync the settings - Utils::syncPersistFile(strFile); - - return; -} -} diff --git a/plugin/CMakeLists.txt b/plugin/CMakeLists.txt index 0f38bb9..3891977 100755 --- a/plugin/CMakeLists.txt +++ b/plugin/CMakeLists.txt @@ -27,6 +27,7 @@ list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") find_package(${NAMESPACE}Plugins REQUIRED) find_package(${NAMESPACE}Definitions REQUIRED) find_package(CompileSettingsDebug CONFIG REQUIRED) +find_package(${NAMESPACE}Helpers REQUIRED) add_library(${MODULE_NAME} SHARED UserSettings.cpp @@ -40,7 +41,8 @@ target_link_libraries(${MODULE_NAME} PRIVATE CompileSettingsDebug::CompileSettingsDebug ${NAMESPACE}Plugins::${NAMESPACE}Plugins - ${NAMESPACE}Definitions::${NAMESPACE}Definitions) + ${NAMESPACE}Definitions::${NAMESPACE}Definitions + ${NAMESPACE}::${NAMESPACE}Helpers) install(TARGETS ${MODULE_NAME} DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/${STORAGE_DIRECTORY}/plugins) @@ -49,9 +51,6 @@ add_library(${PLUGIN_IMPLEMENTATION} SHARED UserSettingsImplementation.cpp Module.cpp) -include_directories( - ../helpers) - set_target_properties(${PLUGIN_IMPLEMENTATION} PROPERTIES CXX_STANDARD 11 CXX_STANDARD_REQUIRED YES) @@ -69,7 +68,8 @@ endif (RDK_SERVICES_L2_TEST) target_link_libraries(${PLUGIN_IMPLEMENTATION} PRIVATE CompileSettingsDebug::CompileSettingsDebug - ${NAMESPACE}Plugins::${NAMESPACE}Plugins) + ${NAMESPACE}Plugins::${NAMESPACE}Plugins + ${NAMESPACE}::${NAMESPACE}Helpers) install(TARGETS ${PLUGIN_IMPLEMENTATION} DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/${STORAGE_DIRECTORY}/plugins) From 8c06c366543c7757dd41ee411742ff0eb23dbaff Mon Sep 17 00:00:00 2001 From: GitHub Actions <187267378+rdkcm-rdke@users.noreply.github.com> Date: Fri, 5 Jun 2026 20:01:10 +0000 Subject: [PATCH 2/2] 1.2.5 release changelog updates --- CHANGELOG.md | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b120740..23a86f2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,9 +4,17 @@ All notable changes to this project will be documented in this file. Dates are d Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog). +#### [1.2.5](https://github.com/rdkcentral/entservices-usersettings/compare/1.2.4...1.2.5) + +- RDKEMW-16743:Integrate to common headers [`#18`](https://github.com/rdkcentral/entservices-usersettings/pull/18) +- Merge tag '1.2.4' into develop [`e2579b5`](https://github.com/rdkcentral/entservices-usersettings/commit/e2579b5f8e3878eb28df5857aef2697273d3c04d) + #### [1.2.4](https://github.com/rdkcentral/entservices-usersettings/compare/1.2.3...1.2.4) +> 8 May 2026 + - RDKEMW-16957: Create agent for L2 tests for entservices-usersettings [`#32`](https://github.com/rdkcentral/entservices-usersettings/pull/32) +- 1.2.4 release changelog updates [`7e26459`](https://github.com/rdkcentral/entservices-usersettings/commit/7e264591dc63af3f62cfea35bd8ff33fd66f0cd3) - Merge tag '1.2.3' into develop [`b5222cd`](https://github.com/rdkcentral/entservices-usersettings/commit/b5222cd6c1af058772f6a1cee84464521e877236) #### [1.2.3](https://github.com/rdkcentral/entservices-usersettings/compare/1.2.2...1.2.3)