From 8f07c2df88d4f05429fddfb18b123f9c32398b81 Mon Sep 17 00:00:00 2001 From: ramkumarpraba Date: Mon, 16 Sep 2024 04:23:32 +0000 Subject: [PATCH 01/21] RDK-51362 : System Mode Thunder Plugin to support ALLM Reason for change: New plugin SystemMode added Test Procedure: verify build success and basic test Risks: Low Priority: P1 Signed-off-by: ramkumar_prabaharan@comcast.com --- .github/workflows/L2-tests-R4-4-1.yml | 1 + CMakeLists.txt | 4 + SystemMode/CHANGELOG.md | 24 + SystemMode/CMakeLists.txt | 79 ++++ SystemMode/Module.cpp | 22 + SystemMode/Module.h | 29 ++ SystemMode/SystemMode.conf.in | 12 + SystemMode/SystemMode.config | 15 + SystemMode/SystemMode.cpp | 143 ++++++ SystemMode/SystemMode.h | 68 +++ SystemMode/SystemModeImplementation.cpp | 437 ++++++++++++++++++ SystemMode/SystemModeImplementation.h | 81 ++++ Tests/L2Tests/L2TestsPlugin/CMakeLists.txt | 3 + .../L2TestsPlugin/tests/SystemMode_L2Test.cpp | 119 +++++ ...RDK-51362-System-Mode-Thunder-Plugin.patch | 139 ++++++ l2tests.cmake | 1 + 16 files changed, 1177 insertions(+) create mode 100755 SystemMode/CHANGELOG.md create mode 100755 SystemMode/CMakeLists.txt create mode 100755 SystemMode/Module.cpp create mode 100755 SystemMode/Module.h create mode 100755 SystemMode/SystemMode.conf.in create mode 100755 SystemMode/SystemMode.config create mode 100755 SystemMode/SystemMode.cpp create mode 100755 SystemMode/SystemMode.h create mode 100755 SystemMode/SystemModeImplementation.cpp create mode 100755 SystemMode/SystemModeImplementation.h create mode 100755 Tests/L2Tests/L2TestsPlugin/tests/SystemMode_L2Test.cpp create mode 100644 Tests/L2Tests/patches/RDK-51362-System-Mode-Thunder-Plugin.patch diff --git a/.github/workflows/L2-tests-R4-4-1.yml b/.github/workflows/L2-tests-R4-4-1.yml index 917e20f705..3650f86799 100755 --- a/.github/workflows/L2-tests-R4-4-1.yml +++ b/.github/workflows/L2-tests-R4-4-1.yml @@ -145,6 +145,7 @@ jobs: patch -p1 < ${{github.workspace}}/rdkservices/Tests/L2Tests/patches/0001-RDK-45037-Secure-Storage-Thunder-Plugin.patch patch -p1 < ${{github.workspace}}/rdkservices/Tests/L2Tests/patches/RDKV-48604-User-Settings-Thunder-Plugin.patch patch -p1 < ${{github.workspace}}/rdkservices/Tests/L2Tests/patches/Use_Legact_Alt_In_ThunderInterfaces_Based_On_ThunderTools_R4.4.3.patch + patch -p1 < ${{github.workspace}}/rdkservices/Tests/L2Tests/patches/RDK-51362-System-Mode-Thunder-Plugin.patch cd .. - name: Build ThunderInterfaces diff --git a/CMakeLists.txt b/CMakeLists.txt index 31a5f514fe..4ed08eec60 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -71,6 +71,10 @@ if(PLUGIN_CONTROLSERVICE) add_subdirectory(ControlService) endif() +if(PLUGIN_SYSTEMMODE) + add_subdirectory(SystemMode) +endif() + if(PLUGIN_USERSETTINGS) add_subdirectory(UserSettings) endif() diff --git a/SystemMode/CHANGELOG.md b/SystemMode/CHANGELOG.md new file mode 100755 index 0000000000..13f6202761 --- /dev/null +++ b/SystemMode/CHANGELOG.md @@ -0,0 +1,24 @@ +# Changelog + +All notable changes to this RDK Service will be documented in this file. + +* Each RDK Service has a CHANGELOG file that contains all changes done so far. When version is updated, add a entry in the CHANGELOG.md at the top with user friendly information on what was changed with the new version. Please don't mention JIRA tickets in CHANGELOG. + +* Please Add entry in the CHANGELOG for each version change and indicate the type of change with these labels: + * **Added** for new features. + * **Changed** for changes in existing functionality. + * **Deprecated** for soon-to-be removed features. + * **Removed** for now removed features. + * **Fixed** for any bug fixes. + * **Security** in case of vulnerabilities. + +* Changes in CHANGELOG should be updated when commits are added to the main or release branches. There should be one CHANGELOG entry per JIRA Ticket. This is not enforced on sprint branches since there could be multiple changes for the same JIRA ticket during development. + +* For more details, refer to [versioning](https://github.com/rdkcentral/rdkservices#versioning) section under Main README. +## [1.0.0] - 16-08-2024 +### Added +- Add CHANGELOG + +### Change +- Reset API version to 1.0.0 +- Change README to inform how to update changelog and API version diff --git a/SystemMode/CMakeLists.txt b/SystemMode/CMakeLists.txt new file mode 100755 index 0000000000..5ba23e4765 --- /dev/null +++ b/SystemMode/CMakeLists.txt @@ -0,0 +1,79 @@ +# 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. + +set(PLUGIN_NAME SystemMode) +set(MODULE_NAME ${NAMESPACE}${PLUGIN_NAME}) +set(PLUGIN_IMPLEMENTATION ${MODULE_NAME}Implementation) + +set(PLUGIN_SYSTEMMODE_AUTOSTART "true" CACHE STRING "Automatically start SystemMode plugin") +set(PLUGIN_SYSTEMMODE_STARTUPORDER "41" CACHE STRING "To configure startup order of SystemMode plugin") + +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) + +add_library(${MODULE_NAME} SHARED + SystemMode.cpp + Module.cpp) + +set_target_properties(${MODULE_NAME} PROPERTIES + CXX_STANDARD 11 + CXX_STANDARD_REQUIRED YES) + +target_link_libraries(${MODULE_NAME} + PRIVATE + CompileSettingsDebug::CompileSettingsDebug + ${NAMESPACE}Plugins::${NAMESPACE}Plugins + ${NAMESPACE}Definitions::${NAMESPACE}Definitions) + +install(TARGETS ${MODULE_NAME} + DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/${STORAGE_DIRECTORY}/plugins) + +add_library(${PLUGIN_IMPLEMENTATION} SHARED + SystemModeImplementation.cpp + Module.cpp) + +include_directories( + ../helpers) + +set_target_properties(${PLUGIN_IMPLEMENTATION} PROPERTIES + CXX_STANDARD 11 + CXX_STANDARD_REQUIRED YES) + +if (RDK_SERVICE_L2_TEST) + find_library(TESTMOCKLIB_LIBRARIES NAMES TestMocklib) + if (TESTMOCKLIB_LIBRARIES) + message ("linking mock libraries ${TESTMOCKLIB_LIBRARIES} library") + target_link_libraries(${PLUGIN_IMPLEMENTATION} PRIVATE ${TESTMOCKLIB_LIBRARIES}) + else (TESTMOCKLIB_LIBRARIES) + message ("Require ${TESTMOCKLIB_LIBRARIES} library") + endif (TESTMOCKLIB_LIBRARIES) +endif (RDK_SERVICES_L2_TEST) + +target_link_libraries(${PLUGIN_IMPLEMENTATION} + PRIVATE + CompileSettingsDebug::CompileSettingsDebug + ${NAMESPACE}Plugins::${NAMESPACE}Plugins + ) + +install(TARGETS ${PLUGIN_IMPLEMENTATION} + DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/${STORAGE_DIRECTORY}/plugins) + +write_config(${PLUGIN_NAME}) + diff --git a/SystemMode/Module.cpp b/SystemMode/Module.cpp new file mode 100755 index 0000000000..713d4b17fb --- /dev/null +++ b/SystemMode/Module.cpp @@ -0,0 +1,22 @@ +/* +* 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. +*/ + +#include "Module.h" + +MODULE_NAME_DECLARATION(BUILD_REFERENCE) diff --git a/SystemMode/Module.h b/SystemMode/Module.h new file mode 100755 index 0000000000..0db625fb7c --- /dev/null +++ b/SystemMode/Module.h @@ -0,0 +1,29 @@ +/* +* 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 +#ifndef MODULE_NAME +#define MODULE_NAME Plugin_SystemMode +#endif + +#include +#include + +#undef EXTERNAL +#define EXTERNAL diff --git a/SystemMode/SystemMode.conf.in b/SystemMode/SystemMode.conf.in new file mode 100755 index 0000000000..13940e5550 --- /dev/null +++ b/SystemMode/SystemMode.conf.in @@ -0,0 +1,12 @@ +autostart = "@PLUGIN_SYSTEMMODE_AUTOSTART@" +precondition = ["Platform"] +callsign = "org.rdk.SystemMode" +startuporder = "@PLUGIN_SYSTEMMODE_STARTUPORDER@" + +configuration = JSON() +rootobject = JSON() + +rootobject.add("mode", "@PLUGIN_SYSTEMMODE_MODE@") +rootobject.add("locator", "lib@PLUGIN_IMPLEMENTATION@.so") +configuration.add("root", rootobject) + diff --git a/SystemMode/SystemMode.config b/SystemMode/SystemMode.config new file mode 100755 index 0000000000..e4fa1b96f3 --- /dev/null +++ b/SystemMode/SystemMode.config @@ -0,0 +1,15 @@ +set(autostart ${PLUGIN_SYSTEMMODE_AUTOSTART}) + +if(PLUGIN_SYSTEMMODE_STARTUPORDER) +set (startuporder ${PLUGIN_SYSTEMMODE_STARTUPORDER}) +endif() + +map() + key(root) + map() + kv(mode ${PLUGIN_SYSTEMMODE_MODE}) + kv(locator lib${PLUGIN_IMPLEMENTATION}.so) + end() +end() +ans(configuration) + diff --git a/SystemMode/SystemMode.cpp b/SystemMode/SystemMode.cpp new file mode 100755 index 0000000000..d3abf00b7b --- /dev/null +++ b/SystemMode/SystemMode.cpp @@ -0,0 +1,143 @@ +/* +* 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. +*/ + +#include "SystemMode.h" + +#define API_VERSION_NUMBER_MAJOR 1 +#define API_VERSION_NUMBER_MINOR 0 +#define API_VERSION_NUMBER_PATCH 0 + +namespace WPEFramework +{ + + namespace { + + static Plugin::Metadata metadata( + // Version (Major, Minor, Patch) + API_VERSION_NUMBER_MAJOR, API_VERSION_NUMBER_MINOR, API_VERSION_NUMBER_PATCH, + // Preconditions + {}, + // Terminations + {}, + // Controls + {} + ); + } + + namespace Plugin + { + + /* + *Register SystemMode module as wpeframework plugin + **/ + SERVICE_REGISTRATION(SystemMode, API_VERSION_NUMBER_MAJOR, API_VERSION_NUMBER_MINOR, API_VERSION_NUMBER_PATCH); + + SystemMode::SystemMode() : _service(nullptr), _connectionId(0), _systemMode(nullptr) + { + SYSLOG(Logging::Startup, (_T("SystemMode Constructor"))); + } + + SystemMode::~SystemMode() + { + SYSLOG(Logging::Shutdown, (string(_T("SystemMode Destructor")))); + } + + const string SystemMode::Initialize(PluginHost::IShell* service) + { + string message=""; + + ASSERT(nullptr != service); + ASSERT(nullptr == _service); + ASSERT(nullptr == _systemMode); + ASSERT(0 == _connectionId); + + SYSLOG(Logging::Startup, (_T("SystemMode::Initialize: PID=%u"), getpid())); + + _service = service; + _service->AddRef(); + _systemMode = _service->Root(_connectionId, 5000, _T("SystemModeImplementation")); + + if(nullptr != _systemMode) + { + Exchange::JSystemMode::Register(*this, _systemMode); + } + else + { + SYSLOG(Logging::Startup, (_T("SystemMode::Initialize: Failed to initialise SystemMode plugin"))); + message = _T("SystemMode plugin could not be initialised"); + } + + if (0 != message.length()) + { + Deinitialize(service); + } + + return message; + } + + void SystemMode::Deinitialize(PluginHost::IShell* service) + { + ASSERT(_service == service); + + SYSLOG(Logging::Shutdown, (string(_T("SystemMode::Deinitialize")))); + + if (nullptr != _systemMode) + { + Exchange::JSystemMode::Unregister(*this); + + // Stop processing: + RPC::IRemoteConnection* connection = service->RemoteConnection(_connectionId); + VARIABLE_IS_NOT_USED uint32_t result = _systemMode->Release(); + + _systemMode = nullptr; + + // If this was running in a (container) process... + if (nullptr != connection) + { + // Lets trigger the cleanup sequence for + // out-of-process code. Which will guard + // that unwilling processes, get shot if + // not stopped friendly :-) + connection->Terminate(); + connection->Release(); + } + } + + _connectionId = 0; + _service->Release(); + _service = nullptr; + SYSLOG(Logging::Shutdown, (string(_T("SystemMode de-initialised")))); + } + + string SystemMode::Information() const + { + // No additional info to report + return (string()); + } + + void SystemMode::Deactivated(RPC::IRemoteConnection* connection) + { + if (connection->Id() == _connectionId) { + ASSERT(nullptr != _service); + Core::IWorkerPool::Instance().Submit(PluginHost::IShell::Job::Create(_service, PluginHost::IShell::DEACTIVATED, PluginHost::IShell::FAILURE)); + } + } + +} // namespace Plugin +} // namespace WPEFramework diff --git a/SystemMode/SystemMode.h b/SystemMode/SystemMode.h new file mode 100755 index 0000000000..fd6ff95c65 --- /dev/null +++ b/SystemMode/SystemMode.h @@ -0,0 +1,68 @@ +/* +* 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 "Module.h" +#include +#include +#include +#include +#include "UtilsLogging.h" +#include "tracing/Logging.h" +#include + +namespace WPEFramework { +namespace Plugin { + + class SystemMode: public PluginHost::IPlugin, public PluginHost::JSONRPC + { + + public: + // We do not allow this plugin to be copied !! + SystemMode(const SystemMode&) = delete; + SystemMode& operator=(const SystemMode&) = delete; + + SystemMode(); + virtual ~SystemMode(); + + BEGIN_INTERFACE_MAP(SystemMode) + INTERFACE_ENTRY(PluginHost::IPlugin) + INTERFACE_ENTRY(PluginHost::IDispatcher) + INTERFACE_AGGREGATE(Exchange::ISystemMode, _systemMode) + END_INTERFACE_MAP + + // IPlugin methods + // ------------------------------------------------------------------------------------------------------- + const string Initialize(PluginHost::IShell* service) override; + void Deinitialize(PluginHost::IShell* service) override; + string Information() const override; + + + private: + void Deactivated(RPC::IRemoteConnection* connection); + + private: + PluginHost::IShell* _service{}; + uint32_t _connectionId{}; + Exchange::ISystemMode* _systemMode{}; + }; + +} // namespace Plugin +} // namespace WPEFramework diff --git a/SystemMode/SystemModeImplementation.cpp b/SystemMode/SystemModeImplementation.cpp new file mode 100755 index 0000000000..3956ad4afe --- /dev/null +++ b/SystemMode/SystemModeImplementation.cpp @@ -0,0 +1,437 @@ +/* +* 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. +*/ + +#include "SystemModeImplementation.h" +#include +#include "UtilsJsonRpc.h" +#include +#include "tracing/Logging.h" +#include +#include + + +#define SYSTEMMODE_NAMESPACE "SystemMode" + +namespace WPEFramework { +namespace Plugin { + +SERVICE_REGISTRATION(SystemModeImplementation, 1, 0); + +SystemModeImplementation::SystemModeImplementation() +: _adminLock() +, _engine(Core::ProxyType>::Create()) +, _communicatorClient(Core::ProxyType::Create(Core::NodeId("/tmp/communicator"), Core::ProxyType(_engine))) +, _controller(nullptr) +,stateRequested(false) +{ + LOGINFO("Create SystemModeImplementation Instance"); + + SystemModeImplementation::instance(this); + + if (!_communicatorClient.IsValid()) + { + LOGWARN("Invalid _communicatorClient\n"); + } + else + { + +#if ((THUNDER_VERSION == 2) || ((THUNDER_VERSION == 4) && (THUNDER_VERSION_MINOR == 2))) + _engine->Announcements(_communicatorClient->Announcement()); +#endif + + } + + //set default value for each SystemMode + + SystemModeMap[DEVICE_OPTIMIZE] = "DEVICE_OPTIMIZE"; + + deviceOptimizeStateMap[VIDEO] ="VIDEO"; + deviceOptimizeStateMap[GAME] ="GAME"; + + + // Check if the file exists + std::ifstream infile(SYSTEM_MODE_FILE); + if (!infile.good()) { + // File doesn't exist, so create it + std::ofstream outfile(SYSTEM_MODE_FILE); + if (outfile) { + LOGINFO("File created successfully: %s\n", SYSTEM_MODE_FILE); + + //set default value for each SystemMode + updateSystemModeFile("DEVICE_OPTIMIZE" ,"currentstate" , "VIDEO" , "add"); + } else { + LOGERR("Error creating file: %s\n", SYSTEM_MODE_FILE); + } + } else { + LOGINFO("File already exists: %s\n", SYSTEM_MODE_FILE); + for (int i =1 ;i <=SYSTEM_MODE_COUNT ; i++ ) + { + std::string value = ""; + std::string systemMode = SystemModeMap[static_cast(i)] ; + getSystemModePropertyValue(systemMode, "callsign", value); + if (value != "") + { + updateSystemModeFile( systemMode, "callsign", "","deleteall") ; + std::vector callSignList; + Utils::String::split(callSignList, value , "|") ; + for (const auto& token : callSignList) { + + ClientActivated(token , systemMode); + } + + } + } + } + +} + +SystemModeImplementation* SystemModeImplementation::instance(SystemModeImplementation *SystemModeImpl) +{ + static SystemModeImplementation *SystemModeImpl_instance = nullptr; + + ASSERT (nullptr != SystemModeImpl); + + if (SystemModeImpl != nullptr) + { + SystemModeImpl_instance = SystemModeImpl; + } + + return(SystemModeImpl_instance); +} + +SystemModeImplementation::~SystemModeImplementation() +{ + if (_controller) + { + _controller->Release(); + _controller = nullptr; + } + + LOGINFO("Disconnect from the COM-RPC socket\n"); + // Disconnect from the COM-RPC socket + _communicatorClient->Close(RPC::CommunicationTimeOut); + if (_communicatorClient.IsValid()) + { + _communicatorClient.Release(); + } + + if(_engine.IsValid()) + { + _engine.Release(); + } + + for (auto& entry : _clients) { + if (entry.second) { // Check if the pointer is not null + entry.second->Release(); + } + } + +} + + +Core::hresult SystemModeImplementation::RequestState(const SystemMode pSystemMode, const State pState) +{ + auto SystemModeMapIterator = SystemModeMap.find(pSystemMode); + Core::hresult result = Core::ERROR_NONE; + + if(SystemModeMapIterator != SystemModeMap.end()) + { + std::string systemMode_str = SystemModeMapIterator->second; + switch (pSystemMode) { + case DEVICE_OPTIMIZE:{ + + auto deviceOptimizeStateMapIterator = deviceOptimizeStateMap.find(pState); + if (deviceOptimizeStateMapIterator != deviceOptimizeStateMap.end()) + { + std::string new_state = deviceOptimizeStateMapIterator->second; + std::string old_state = ""; + getSystemModePropertyValue(systemMode_str ,"currentstate" , old_state); + for (auto it = _clients.begin(); it != _clients.end(); ++it) { + if (it->second) { // Check if the pointer is not null + it->second->Request(new_state); // Call Request() on the object + SystemModesCurrentStateMap[pSystemMode] = pState; + updateSystemModeFile(systemMode_str,"currentstate",new_state,"add"); + LOGINFO("SystemMode state change from %s to new %s" ,old_state.c_str(),new_state.c_str()); + } + } + + stateRequested =true; + result = Core::ERROR_NONE; + } + else + { + LOGERR("Invalid state %d for systemMode %s" ,pState,systemMode_str.c_str()); + result = Core::ERROR_GENERAL; + } + break; + } + default: + { + LOGERR("Invalid systemMode %s",systemMode_str.c_str()); + result = Core::ERROR_GENERAL; + break; + } + + } + } + else + { + LOGERR("Invalid systemMode %d",pSystemMode); + result = Core::ERROR_GENERAL; + } + return result; +} + +Core::hresult SystemModeImplementation::GetState(const SystemMode pSystemMode, State &pState )const +{ + + Core::hresult result = Core::ERROR_NONE; + auto SystemModeMapIterator = SystemModeMap.find(pSystemMode); + if(SystemModeMapIterator != SystemModeMap.end()) + { + std::string value = ""; + std::string systemMode_str = SystemModeMapIterator->second; + getSystemModePropertyValue(systemMode_str ,"currentstate" , value); + switch (pSystemMode) { + case DEVICE_OPTIMIZE:{ + + // Iterate over the map to find the corresponding enum value + for (const auto& pair : deviceOptimizeStateMap) { + if (pair.second == value) { + pState = pair.first; + break; + } + } + result = Core::ERROR_NONE; + break; + } + default: + { + LOGERR("Invalid systemMode %d",static_cast(pSystemMode)); + result = Core::ERROR_GENERAL; + break; + } + } + } + else + { + LOGERR("Invalid systemMode %d",static_cast(pSystemMode)); + return Core::ERROR_GENERAL; + } + return result; + +} + +uint32_t SystemModeImplementation::ClientActivated(const string& callsign , const string& __SystemMode) +{ + SystemMode pSystemMode = DEVICE_OPTIMIZE; + + if (callsign != "") + { + _controller = nullptr; + _controller = _communicatorClient->Open(_T(callsign), ~0, 3000); + + if (_controller) + { + switch (pSystemMode) { + case DEVICE_OPTIMIZE:{ + + Exchange::IDeviceOptimizeStateActivator *deviceOptimizeStateActivator (_controller->QueryInterface()); + + if (deviceOptimizeStateActivator != nullptr) { + _adminLock.Lock(); + + std::map::iterator index(_clients.find(callsign)); + + if (index == _clients.end()) { + _clients.insert({callsign,deviceOptimizeStateActivator}); + updateSystemModeFile( SystemModeMap[pSystemMode], "callsign", callsign,"add") ; + TRACE(Trace::Information, (_T("%s plugin is add to deviceOptimizeStateActivator map"), callsign.c_str())); + + //If For Ex The plugins P1,P2,P3 who implement IDeviceOptimizeStateActivator . P1 ,P2 only activated . P3 is not in activated state .If org.rdk.SystemMode.RequestState (DeviceOptimize,GAME) is called then SystemMode trigger P1.Request() and P2.Request() . After 5 min if P3 come to activate state , then SystemMode need to trigger P3. Request()i + if(stateRequested) + { + State state ; + if(GetState(pSystemMode, state ) == Core::ERROR_NONE) + { + std::string state_str = deviceOptimizeStateMap[state]; + deviceOptimizeStateActivator->Request(state_str) ; + } + } + } + + deviceOptimizeStateActivator->AddRef(); + + _adminLock.Unlock(); + + } + break; + } + default: + { + LOGERR("Invalid systemMode %d",pSystemMode); + break; + } + } + + } + } + return 0; +} +uint32_t SystemModeImplementation::ClientDeactivated(const string& callsign ,const string& systemMode) +{ + SystemMode pSystemMode = DEVICE_OPTIMIZE; + _adminLock.Lock(); + switch (pSystemMode) { + case DEVICE_OPTIMIZE: + { + std::map::iterator index(_clients.find(callsign)); + + if (index != _clients.end()) { // Remove from the list, if it is already there + Exchange::IDeviceOptimizeStateActivator *temp = index->second; + temp->Release(); + _clients.erase(index); + updateSystemModeFile( SystemModeMap[pSystemMode], "callsign", callsign,"delete") ; + TRACE(Trace::Information, (_T("%s plugin is removed from power control list"), callsign.c_str())); + } + break; + } + default:{ + LOGERR("Invalid systemMode %d",pSystemMode); + break; + } + } + _adminLock.Unlock(); + return 0; +} + +void SystemModeImplementation::updateSystemModeFile(const std::string& systemMode, const std::string& property, const std::string& value, const std::string& action) { + + if (systemMode.empty() || property.empty()) { + LOGINFO("Error: systemMode or property is empty. systemMode: %s property: %s", systemMode.c_str(), property.c_str()); + return; + } + + if (action != "add" && action != "delete" && action != "deleteall") { + LOGINFO("Error: Invalid action. Action must be 'add', 'delete', or 'deleteall'."); + return; + } + + std::ifstream infile(SYSTEM_MODE_FILE); + std::string line; + std::stringstream buffer; + bool propertyFound = false; + std::string searchKey = systemMode + "_" + property; + + // Read the file content and process it line by line + if (infile.is_open()) { + while (std::getline(infile, line)) { + // If the line starts with the searchKey + if (line.find(searchKey) == 0) { + propertyFound = true; + if (action == "deleteall" && value.empty()) { + // Skip adding this line to the buffer, effectively removing it + continue; + } else if (property == "currentstate") { + if (action == "add") { + // Replace the value for currentstate + line = searchKey + "=" + value; + } else if (action == "delete") { + // To delete a currentstate, we might want to clear or remove the line + line.clear(); // This effectively removes the line + } + } else if (property == "callsign") { + if (action == "add") { + // Append the value to the callsign, ensuring no duplicate entries + if (line.find(value) == std::string::npos) { + line += value + "|"; + } + } else if (action == "delete") { + // Remove the value from the callsign + size_t pos = line.find(value); + if (pos != std::string::npos) { + line.erase(pos, value.length() + 1); // +1 to remove the trailing '|' + } + } + } + } + if (!line.empty()) { + buffer << line << std::endl; + } + } + infile.close(); + } + + // If the property wasn't found and the action is "add", add it to the file + if (!propertyFound && action == "add") { + if (property == "currentstate") { + buffer << searchKey + "=" + value << std::endl; + } else if (property == "callsign") { + buffer << searchKey + "=" + value + "|" << std::endl; + } + } + + // Write the modified content back to the file + std::ofstream outfile(SYSTEM_MODE_FILE); + if (outfile.is_open()) { + outfile << buffer.str(); + outfile.close(); + LOGINFO("Updated file %s successfully.", SYSTEM_MODE_FILE); + } else { + LOGINFO("Failed to open file %s for writing.", SYSTEM_MODE_FILE); + } +} + + + +bool SystemModeImplementation::getSystemModePropertyValue(const std::string& systemMode, const std::string& property, std::string& value) const +{ + if (systemMode.empty() || property.empty() ) { + LOGINFO("Error: systemMode or property is empty. systemMode: %s property: %s ",systemMode.c_str(),property.c_str()); + return false; + } + + std::ifstream infile(SYSTEM_MODE_FILE); + std::string line; + std::string searchKey = systemMode + "_" + property; + + if (!infile.is_open()) { + std::cerr << "Failed to open file: " << SYSTEM_MODE_FILE << std::endl; + return false; + } + + while (std::getline(infile, line)) { + // Check if the line starts with the search key + if (line.find(searchKey) == 0) { + // Extract the value after the '=' character + size_t pos = line.find('='); + if (pos != std::string::npos) { + value = line.substr(pos + 1); + infile.close(); + return true; + } + } + } + + infile.close(); + return false; +} + +} // namespace Plugin +} // namespace WPEFramework diff --git a/SystemMode/SystemModeImplementation.h b/SystemMode/SystemModeImplementation.h new file mode 100755 index 0000000000..181ab53ad1 --- /dev/null +++ b/SystemMode/SystemModeImplementation.h @@ -0,0 +1,81 @@ +/* +* 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 "Module.h" +#include +#include +#include +#include "tracing/Logging.h" +#include +#include "UtilsString.h" + +#include +#include +#include + +#define SYSTEM_MODE_COUNT 1 //Number of system mode define in Exchange::ISystemMode::SystemMode enum +#define SYSTEM_MODE_FILE "/tmp/SystemMode.txt" + +namespace WPEFramework { +namespace Plugin { + class SystemModeImplementation : public Exchange::ISystemMode{ + + public: + // We do not allow this plugin to be copied !! + SystemModeImplementation(); + ~SystemModeImplementation() override; + + static SystemModeImplementation* instance(SystemModeImplementation *SystemModeImpl = nullptr); + + // We do not allow this plugin to be copied !! + SystemModeImplementation(const SystemModeImplementation&) = delete; + SystemModeImplementation& operator=(const SystemModeImplementation&) = delete; + + BEGIN_INTERFACE_MAP(SystemModeImplementation) + INTERFACE_ENTRY(Exchange::ISystemMode) + END_INTERFACE_MAP + + public: + Core::hresult RequestState(const SystemMode systemMode, const State state) override; + Core::hresult GetState(const SystemMode systemMode, State &state )const override; + + virtual uint32_t ClientActivated(const string& callsign ,const string& systemMode) override ; + virtual uint32_t ClientDeactivated(const string& callsign, const string& systemMode) override ; + +//helper functions + void updateSystemModeFile(const std::string& systemMode, const std::string& property, const std::string& value, const std::string& action) ; + bool getSystemModePropertyValue(const std::string& systemMode, const std::string& property, std::string& value) const; + + private: + mutable Core::CriticalSection _adminLock; + std::map _clients; + Core::ProxyType> _engine; + Core::ProxyType _communicatorClient; + PluginHost::IShell *_controller; + std::map SystemModeMap; + std::map deviceOptimizeStateMap; + std::map SystemModesCurrentStateMap; + std::map SystemModeInterfaceMap; + bool stateRequested ; + + }; +} // namespace Plugin +} // namespace WPEFramework diff --git a/Tests/L2Tests/L2TestsPlugin/CMakeLists.txt b/Tests/L2Tests/L2TestsPlugin/CMakeLists.txt index 9bdc5dfb94..c73df2362c 100755 --- a/Tests/L2Tests/L2TestsPlugin/CMakeLists.txt +++ b/Tests/L2Tests/L2TestsPlugin/CMakeLists.txt @@ -47,6 +47,9 @@ if(PLUGIN_USERSETTINGS) set(SRC_FILES ${SRC_FILES} tests/UserSettings_L2Test.cpp) endif() +if(PLUGIN_SYSTEMMODE) + set(SRC_FILES ${SRC_FILES} tests/SystemMode_L2Test.cpp) +endif() add_library(${MODULE_NAME} SHARED ${SRC_FILES}) set_target_properties(${MODULE_NAME} PROPERTIES diff --git a/Tests/L2Tests/L2TestsPlugin/tests/SystemMode_L2Test.cpp b/Tests/L2Tests/L2TestsPlugin/tests/SystemMode_L2Test.cpp new file mode 100755 index 0000000000..76e704bca4 --- /dev/null +++ b/Tests/L2Tests/L2TestsPlugin/tests/SystemMode_L2Test.cpp @@ -0,0 +1,119 @@ +#include +#include +#include "L2Tests.h" +#include "L2TestsMock.h" +#include +#include +#include +#include + +#define TEST_LOG(x, ...) fprintf(stderr, "\033[1;32m[%s:%d](%s)" x "\n\033[0m", __FILE__, __LINE__, __FUNCTION__, getpid(), gettid(), ##__VA_ARGS__); fflush(stderr); + +#define JSON_TIMEOUT (1000) +#define SYSTEMMODE_CALLSIGN _T("org.rdk.SystemMode") +#define SYSTEMMODEL2TEST_CALLSIGN _T("L2tests.1") + +using ::testing::NiceMock; +using namespace WPEFramework; +using testing::StrictMock; +using ::WPEFramework::Exchange::ISystemMode; + + +class AsyncHandlerMock +{ + public: + AsyncHandlerMock() + { + } +}; + +class SystemModeTest : public L2TestMocks { +protected: + virtual ~SystemModeTest() override; + + public: + SystemModeTest(); + + protected: + /** @brief Pointer to the IShell interface */ + PluginHost::IShell *m_controller_usersettings; + + /** @brief Pointer to the IUserSettings interface */ + //Exchange::IUserSettings *m_usersettingsplugin; +}; + +SystemModeTest:: SystemModeTest():L2TestMocks() +{ + Core::JSONRPC::Message message; + string response; + uint32_t status = Core::ERROR_GENERAL; + + /* Activate plugin in constructor */ + status = ActivateService("org.rdk.SystemMode"); + EXPECT_EQ(Core::ERROR_NONE, status); +} + +/** + * @brief Destructor for SystemServices L2 test class + */ +SystemModeTest::~SystemModeTest() +{ + uint32_t status = Core::ERROR_GENERAL; + + status = DeactivateService("org.rdk.SystemMode"); + EXPECT_EQ(Core::ERROR_NONE, status); +} + +TEST_F(SystemModeTest,GetStatedefault) +{ + JSONRPC::LinkType jsonrpc(SYSTEMMODE_CALLSIGN,SYSTEMMODEL2TEST_CALLSIGN); + uint32_t status = Core::ERROR_GENERAL; + JsonObject params; + JsonObject result; + std::string message; + std::string reply; + + params["systemMode"] = "DeviceOptimize"; + status = InvokeServiceMethod("org.rdk.SystemMode", "GetState", params, result); + EXPECT_EQ(Core::ERROR_NONE, status); + +} + +TEST_F(SystemModeTest,RequestStateGame) +{ + JSONRPC::LinkType jsonrpc(SYSTEMMODE_CALLSIGN,SYSTEMMODEL2TEST_CALLSIGN); + uint32_t status = Core::ERROR_GENERAL; + JsonObject params; + JsonObject result; + std::string message; + std::string reply; + + params["systemMode"] = "DeviceOptimize"; + params["state"] = "Game"; + status = InvokeServiceMethod("org.rdk.SystemMode", "RequestState", params, result); + EXPECT_EQ(Core::ERROR_NONE, status); + + status = InvokeServiceMethod("org.rdk.SystemMode", "GetState", params, result); + EXPECT_EQ(Core::ERROR_NONE, status); + +} + +TEST_F(SystemModeTest,RequestStateVideo) +{ + JSONRPC::LinkType jsonrpc(SYSTEMMODE_CALLSIGN,SYSTEMMODEL2TEST_CALLSIGN); + uint32_t status = Core::ERROR_GENERAL; + JsonObject params; + JsonObject result; + std::string message; + std::string reply; + + params["systemMode"] = "DeviceOptimize"; + params["state"] = "Video"; + status = InvokeServiceMethod("org.rdk.SystemMode", "RequestState", params, result); + EXPECT_EQ(Core::ERROR_NONE, status); + + status = InvokeServiceMethod("org.rdk.SystemMode", "GetState", params, result); + EXPECT_EQ(Core::ERROR_NONE, status); + +} + diff --git a/Tests/L2Tests/patches/RDK-51362-System-Mode-Thunder-Plugin.patch b/Tests/L2Tests/patches/RDK-51362-System-Mode-Thunder-Plugin.patch new file mode 100644 index 0000000000..5ee09042da --- /dev/null +++ b/Tests/L2Tests/patches/RDK-51362-System-Mode-Thunder-Plugin.patch @@ -0,0 +1,139 @@ +diff --git a/interfaces/IDeviceOptimizeStateActivator.h b/interfaces/IDeviceOptimizeStateActivator.h +new file mode 100644 +index 0000000..168c0e0 +--- /dev/null ++++ b/interfaces/IDeviceOptimizeStateActivator.h +@@ -0,0 +1,36 @@ ++/* ++ * 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 "Module.h" ++ ++namespace WPEFramework { ++namespace Exchange { ++ ++ /// Interface implemented by each Thunder component that needs to react to DEVICE_OPTIMIZE system mode state activation requests. ++ struct EXTERNAL IDeviceOptimizeStateActivator : virtual public Core::IUnknown { ++ enum { ID = ID_DEVICE_OPTIMIZE_STATE_ACTIVATOR }; ++ ++ /// Requests the component to asynchronously transition to the new state. ++ /// @param[in] newState The new target state to transition to. ++ virtual void Request(const string& newState /* @in @text newState*/) = 0; ++ }; ++} ++} +diff --git a/interfaces/ISystemMode.h b/interfaces/ISystemMode.h +new file mode 100644 +index 0000000..dea68e6 +--- /dev/null ++++ b/interfaces/ISystemMode.h +@@ -0,0 +1,72 @@ ++/* ++ * 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 "Module.h" ++ ++namespace WPEFramework { ++namespace Exchange { ++ // @json ++struct EXTERNAL ISystemMode : virtual public Core::IUnknown { ++ enum { ID = ID_SYSTEM_MODE }; ++ ++ /// Enumeration of system modes. ++ enum SystemMode : uint8_t { ++ DEVICE_OPTIMIZE = 1 ++ }; ++ ++ /// Enumeration of states for all system modes. ++ enum State : uint32_t { ++ // DEVICE_OPTIMIZE states ++ VIDEO = (DEVICE_OPTIMIZE << 24) | 1 , ++ GAME = (DEVICE_OPTIMIZE << 24) | 2 , ++ ++ // next system mode states... ++ }; ++ ++ // @alt RequestState ++ // @brief Requests a new system mode state in the device. Thunder components asynchronously reconfigure themselves so the caller cannot be guaranteed a full state transition upon return. ++ // @param[in] systemMode The system mode. ++ // @param[in] state The requested state. ++ // @returns Core::hresult ++ virtual Core::hresult RequestState(const SystemMode systemMode /* @in @text systemMode */ , const State state /* @in @text state */) = 0; ++ ++ // @alt GetState ++ // @brief Gets the current state for a given system property ++ // @param[in] systemMode The system mode to get the state of. ++ // @param[out] state Receives the state of the system mode. ++ // @returns Core::hresult ++ virtual Core::hresult GetState(const SystemMode systemMode /* @in @text systemMode */ , State &state /* @out @text state */) const = 0; ++ ++ // @alt ClientActivated ++ // @brief To put client plugin entry in map. ++ // @param[in] callsign callsign of client. ++ // @param[in] systemMode The system mode. ++ // @returns uint32_t ++ virtual uint32_t ClientActivated(const string& callsign /* @in @text callsign*/ ,const string& systemMode) = 0; ++ ++ // @alt ClientDeactivated ++ // @brief To put client plugin entry in map. ++ // @param[in] callsign callsign of client. ++ // @param[in] systemMode The system mode. ++ // @returns uint32_t ++ virtual uint32_t ClientDeactivated(const string& callsign /* @in @text callsign*/, const string& systemMode) = 0; ++}; ++} // namespace Exchange ++} // namespace WPEFramework + +diff --git a/interfaces/Ids.h b/interfaces/Ids.h +index e66cb22..7d53320 100644 +--- a/interfaces/Ids.h ++++ b/interfaces/Ids.h +@@ -363,7 +363,12 @@ namespace Exchange { + ID_TEXT_TO_SPEECH_NOTIFICATION = ID_TEXT_TO_SPEECH + 1, + + ID_USER_SETTINGS = RPC::IDS::ID_EXTERNAL_INTERFACE_OFFSET + 0x4D0, +- ID_USER_SETTINGS_NOTIFICATION = ID_USER_SETTINGS + 1 ++ ID_USER_SETTINGS_NOTIFICATION = ID_USER_SETTINGS + 1, ++ ++ ID_DEVICE_OPTIMIZE_STATE_ACTIVATOR = RPC::IDS::ID_EXTERNAL_INTERFACE_OFFSET + 0x510, ++ ++ ID_SYSTEM_MODE = RPC::IDS::ID_EXTERNAL_INTERFACE_OFFSET + 0x520, ++ ID_SYSTEM_MODE_NOTIFICATION = ID_SYSTEM_MODE + 1 + }; + } + } diff --git a/l2tests.cmake b/l2tests.cmake index 19ff775582..210d8e474a 100755 --- a/l2tests.cmake +++ b/l2tests.cmake @@ -117,6 +117,7 @@ set(PLUGIN_USBACCESS ON) if (USE_THUNDER_R4) set(PLUGIN_PERSISTENTSTORE ON) set(PLUGIN_USERSETTINGS ON) + set(PLUGIN_SYSTEMMODE ON) endif (USE_THUNDER_R4) set(PLUGIN_L2Tests ON) set(BUILD_SHARED_LIBS ON) From 6e7ce97a5bb606780d8c38394cba2d4b5990da78 Mon Sep 17 00:00:00 2001 From: ramkumarpraba Date: Mon, 16 Sep 2024 04:23:32 +0000 Subject: [PATCH 02/21] RDK-51362 : System Mode Thunder Plugin to support ALLM Reason for change: New plugin SystemMode added Test Procedure: verify build success and basic test Risks: Low Priority: P1 Signed-off-by: ramkumar_prabaharan@comcast.com --- .github/workflows/L2-tests-R4-4-1.yml | 1 + CMakeLists.txt | 4 + SystemMode/CHANGELOG.md | 24 + SystemMode/CMakeLists.txt | 79 ++++ SystemMode/Module.cpp | 22 + SystemMode/Module.h | 29 ++ SystemMode/SystemMode.conf.in | 12 + SystemMode/SystemMode.config | 15 + SystemMode/SystemMode.cpp | 143 ++++++ SystemMode/SystemMode.h | 68 +++ SystemMode/SystemMode.json | 77 +++ SystemMode/SystemModeImplementation.cpp | 437 ++++++++++++++++++ SystemMode/SystemModeImplementation.h | 81 ++++ SystemMode/SystemModePlugin.json | 13 + Tests/L2Tests/L2TestsPlugin/CMakeLists.txt | 3 + .../L2TestsPlugin/tests/SystemMode_L2Test.cpp | 119 +++++ ...RDK-51362-System-Mode-Thunder-Plugin.patch | 139 ++++++ l2tests.cmake | 1 + 18 files changed, 1267 insertions(+) create mode 100755 SystemMode/CHANGELOG.md create mode 100755 SystemMode/CMakeLists.txt create mode 100755 SystemMode/Module.cpp create mode 100755 SystemMode/Module.h create mode 100755 SystemMode/SystemMode.conf.in create mode 100755 SystemMode/SystemMode.config create mode 100755 SystemMode/SystemMode.cpp create mode 100755 SystemMode/SystemMode.h create mode 100644 SystemMode/SystemMode.json create mode 100755 SystemMode/SystemModeImplementation.cpp create mode 100755 SystemMode/SystemModeImplementation.h create mode 100644 SystemMode/SystemModePlugin.json create mode 100755 Tests/L2Tests/L2TestsPlugin/tests/SystemMode_L2Test.cpp create mode 100644 Tests/L2Tests/patches/RDK-51362-System-Mode-Thunder-Plugin.patch diff --git a/.github/workflows/L2-tests-R4-4-1.yml b/.github/workflows/L2-tests-R4-4-1.yml index 917e20f705..3650f86799 100755 --- a/.github/workflows/L2-tests-R4-4-1.yml +++ b/.github/workflows/L2-tests-R4-4-1.yml @@ -145,6 +145,7 @@ jobs: patch -p1 < ${{github.workspace}}/rdkservices/Tests/L2Tests/patches/0001-RDK-45037-Secure-Storage-Thunder-Plugin.patch patch -p1 < ${{github.workspace}}/rdkservices/Tests/L2Tests/patches/RDKV-48604-User-Settings-Thunder-Plugin.patch patch -p1 < ${{github.workspace}}/rdkservices/Tests/L2Tests/patches/Use_Legact_Alt_In_ThunderInterfaces_Based_On_ThunderTools_R4.4.3.patch + patch -p1 < ${{github.workspace}}/rdkservices/Tests/L2Tests/patches/RDK-51362-System-Mode-Thunder-Plugin.patch cd .. - name: Build ThunderInterfaces diff --git a/CMakeLists.txt b/CMakeLists.txt index 31a5f514fe..4ed08eec60 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -71,6 +71,10 @@ if(PLUGIN_CONTROLSERVICE) add_subdirectory(ControlService) endif() +if(PLUGIN_SYSTEMMODE) + add_subdirectory(SystemMode) +endif() + if(PLUGIN_USERSETTINGS) add_subdirectory(UserSettings) endif() diff --git a/SystemMode/CHANGELOG.md b/SystemMode/CHANGELOG.md new file mode 100755 index 0000000000..13f6202761 --- /dev/null +++ b/SystemMode/CHANGELOG.md @@ -0,0 +1,24 @@ +# Changelog + +All notable changes to this RDK Service will be documented in this file. + +* Each RDK Service has a CHANGELOG file that contains all changes done so far. When version is updated, add a entry in the CHANGELOG.md at the top with user friendly information on what was changed with the new version. Please don't mention JIRA tickets in CHANGELOG. + +* Please Add entry in the CHANGELOG for each version change and indicate the type of change with these labels: + * **Added** for new features. + * **Changed** for changes in existing functionality. + * **Deprecated** for soon-to-be removed features. + * **Removed** for now removed features. + * **Fixed** for any bug fixes. + * **Security** in case of vulnerabilities. + +* Changes in CHANGELOG should be updated when commits are added to the main or release branches. There should be one CHANGELOG entry per JIRA Ticket. This is not enforced on sprint branches since there could be multiple changes for the same JIRA ticket during development. + +* For more details, refer to [versioning](https://github.com/rdkcentral/rdkservices#versioning) section under Main README. +## [1.0.0] - 16-08-2024 +### Added +- Add CHANGELOG + +### Change +- Reset API version to 1.0.0 +- Change README to inform how to update changelog and API version diff --git a/SystemMode/CMakeLists.txt b/SystemMode/CMakeLists.txt new file mode 100755 index 0000000000..5ba23e4765 --- /dev/null +++ b/SystemMode/CMakeLists.txt @@ -0,0 +1,79 @@ +# 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. + +set(PLUGIN_NAME SystemMode) +set(MODULE_NAME ${NAMESPACE}${PLUGIN_NAME}) +set(PLUGIN_IMPLEMENTATION ${MODULE_NAME}Implementation) + +set(PLUGIN_SYSTEMMODE_AUTOSTART "true" CACHE STRING "Automatically start SystemMode plugin") +set(PLUGIN_SYSTEMMODE_STARTUPORDER "41" CACHE STRING "To configure startup order of SystemMode plugin") + +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) + +add_library(${MODULE_NAME} SHARED + SystemMode.cpp + Module.cpp) + +set_target_properties(${MODULE_NAME} PROPERTIES + CXX_STANDARD 11 + CXX_STANDARD_REQUIRED YES) + +target_link_libraries(${MODULE_NAME} + PRIVATE + CompileSettingsDebug::CompileSettingsDebug + ${NAMESPACE}Plugins::${NAMESPACE}Plugins + ${NAMESPACE}Definitions::${NAMESPACE}Definitions) + +install(TARGETS ${MODULE_NAME} + DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/${STORAGE_DIRECTORY}/plugins) + +add_library(${PLUGIN_IMPLEMENTATION} SHARED + SystemModeImplementation.cpp + Module.cpp) + +include_directories( + ../helpers) + +set_target_properties(${PLUGIN_IMPLEMENTATION} PROPERTIES + CXX_STANDARD 11 + CXX_STANDARD_REQUIRED YES) + +if (RDK_SERVICE_L2_TEST) + find_library(TESTMOCKLIB_LIBRARIES NAMES TestMocklib) + if (TESTMOCKLIB_LIBRARIES) + message ("linking mock libraries ${TESTMOCKLIB_LIBRARIES} library") + target_link_libraries(${PLUGIN_IMPLEMENTATION} PRIVATE ${TESTMOCKLIB_LIBRARIES}) + else (TESTMOCKLIB_LIBRARIES) + message ("Require ${TESTMOCKLIB_LIBRARIES} library") + endif (TESTMOCKLIB_LIBRARIES) +endif (RDK_SERVICES_L2_TEST) + +target_link_libraries(${PLUGIN_IMPLEMENTATION} + PRIVATE + CompileSettingsDebug::CompileSettingsDebug + ${NAMESPACE}Plugins::${NAMESPACE}Plugins + ) + +install(TARGETS ${PLUGIN_IMPLEMENTATION} + DESTINATION ${CMAKE_INSTALL_PREFIX}/lib/${STORAGE_DIRECTORY}/plugins) + +write_config(${PLUGIN_NAME}) + diff --git a/SystemMode/Module.cpp b/SystemMode/Module.cpp new file mode 100755 index 0000000000..713d4b17fb --- /dev/null +++ b/SystemMode/Module.cpp @@ -0,0 +1,22 @@ +/* +* 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. +*/ + +#include "Module.h" + +MODULE_NAME_DECLARATION(BUILD_REFERENCE) diff --git a/SystemMode/Module.h b/SystemMode/Module.h new file mode 100755 index 0000000000..0db625fb7c --- /dev/null +++ b/SystemMode/Module.h @@ -0,0 +1,29 @@ +/* +* 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 +#ifndef MODULE_NAME +#define MODULE_NAME Plugin_SystemMode +#endif + +#include +#include + +#undef EXTERNAL +#define EXTERNAL diff --git a/SystemMode/SystemMode.conf.in b/SystemMode/SystemMode.conf.in new file mode 100755 index 0000000000..13940e5550 --- /dev/null +++ b/SystemMode/SystemMode.conf.in @@ -0,0 +1,12 @@ +autostart = "@PLUGIN_SYSTEMMODE_AUTOSTART@" +precondition = ["Platform"] +callsign = "org.rdk.SystemMode" +startuporder = "@PLUGIN_SYSTEMMODE_STARTUPORDER@" + +configuration = JSON() +rootobject = JSON() + +rootobject.add("mode", "@PLUGIN_SYSTEMMODE_MODE@") +rootobject.add("locator", "lib@PLUGIN_IMPLEMENTATION@.so") +configuration.add("root", rootobject) + diff --git a/SystemMode/SystemMode.config b/SystemMode/SystemMode.config new file mode 100755 index 0000000000..e4fa1b96f3 --- /dev/null +++ b/SystemMode/SystemMode.config @@ -0,0 +1,15 @@ +set(autostart ${PLUGIN_SYSTEMMODE_AUTOSTART}) + +if(PLUGIN_SYSTEMMODE_STARTUPORDER) +set (startuporder ${PLUGIN_SYSTEMMODE_STARTUPORDER}) +endif() + +map() + key(root) + map() + kv(mode ${PLUGIN_SYSTEMMODE_MODE}) + kv(locator lib${PLUGIN_IMPLEMENTATION}.so) + end() +end() +ans(configuration) + diff --git a/SystemMode/SystemMode.cpp b/SystemMode/SystemMode.cpp new file mode 100755 index 0000000000..d3abf00b7b --- /dev/null +++ b/SystemMode/SystemMode.cpp @@ -0,0 +1,143 @@ +/* +* 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. +*/ + +#include "SystemMode.h" + +#define API_VERSION_NUMBER_MAJOR 1 +#define API_VERSION_NUMBER_MINOR 0 +#define API_VERSION_NUMBER_PATCH 0 + +namespace WPEFramework +{ + + namespace { + + static Plugin::Metadata metadata( + // Version (Major, Minor, Patch) + API_VERSION_NUMBER_MAJOR, API_VERSION_NUMBER_MINOR, API_VERSION_NUMBER_PATCH, + // Preconditions + {}, + // Terminations + {}, + // Controls + {} + ); + } + + namespace Plugin + { + + /* + *Register SystemMode module as wpeframework plugin + **/ + SERVICE_REGISTRATION(SystemMode, API_VERSION_NUMBER_MAJOR, API_VERSION_NUMBER_MINOR, API_VERSION_NUMBER_PATCH); + + SystemMode::SystemMode() : _service(nullptr), _connectionId(0), _systemMode(nullptr) + { + SYSLOG(Logging::Startup, (_T("SystemMode Constructor"))); + } + + SystemMode::~SystemMode() + { + SYSLOG(Logging::Shutdown, (string(_T("SystemMode Destructor")))); + } + + const string SystemMode::Initialize(PluginHost::IShell* service) + { + string message=""; + + ASSERT(nullptr != service); + ASSERT(nullptr == _service); + ASSERT(nullptr == _systemMode); + ASSERT(0 == _connectionId); + + SYSLOG(Logging::Startup, (_T("SystemMode::Initialize: PID=%u"), getpid())); + + _service = service; + _service->AddRef(); + _systemMode = _service->Root(_connectionId, 5000, _T("SystemModeImplementation")); + + if(nullptr != _systemMode) + { + Exchange::JSystemMode::Register(*this, _systemMode); + } + else + { + SYSLOG(Logging::Startup, (_T("SystemMode::Initialize: Failed to initialise SystemMode plugin"))); + message = _T("SystemMode plugin could not be initialised"); + } + + if (0 != message.length()) + { + Deinitialize(service); + } + + return message; + } + + void SystemMode::Deinitialize(PluginHost::IShell* service) + { + ASSERT(_service == service); + + SYSLOG(Logging::Shutdown, (string(_T("SystemMode::Deinitialize")))); + + if (nullptr != _systemMode) + { + Exchange::JSystemMode::Unregister(*this); + + // Stop processing: + RPC::IRemoteConnection* connection = service->RemoteConnection(_connectionId); + VARIABLE_IS_NOT_USED uint32_t result = _systemMode->Release(); + + _systemMode = nullptr; + + // If this was running in a (container) process... + if (nullptr != connection) + { + // Lets trigger the cleanup sequence for + // out-of-process code. Which will guard + // that unwilling processes, get shot if + // not stopped friendly :-) + connection->Terminate(); + connection->Release(); + } + } + + _connectionId = 0; + _service->Release(); + _service = nullptr; + SYSLOG(Logging::Shutdown, (string(_T("SystemMode de-initialised")))); + } + + string SystemMode::Information() const + { + // No additional info to report + return (string()); + } + + void SystemMode::Deactivated(RPC::IRemoteConnection* connection) + { + if (connection->Id() == _connectionId) { + ASSERT(nullptr != _service); + Core::IWorkerPool::Instance().Submit(PluginHost::IShell::Job::Create(_service, PluginHost::IShell::DEACTIVATED, PluginHost::IShell::FAILURE)); + } + } + +} // namespace Plugin +} // namespace WPEFramework diff --git a/SystemMode/SystemMode.h b/SystemMode/SystemMode.h new file mode 100755 index 0000000000..fd6ff95c65 --- /dev/null +++ b/SystemMode/SystemMode.h @@ -0,0 +1,68 @@ +/* +* 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 "Module.h" +#include +#include +#include +#include +#include "UtilsLogging.h" +#include "tracing/Logging.h" +#include + +namespace WPEFramework { +namespace Plugin { + + class SystemMode: public PluginHost::IPlugin, public PluginHost::JSONRPC + { + + public: + // We do not allow this plugin to be copied !! + SystemMode(const SystemMode&) = delete; + SystemMode& operator=(const SystemMode&) = delete; + + SystemMode(); + virtual ~SystemMode(); + + BEGIN_INTERFACE_MAP(SystemMode) + INTERFACE_ENTRY(PluginHost::IPlugin) + INTERFACE_ENTRY(PluginHost::IDispatcher) + INTERFACE_AGGREGATE(Exchange::ISystemMode, _systemMode) + END_INTERFACE_MAP + + // IPlugin methods + // ------------------------------------------------------------------------------------------------------- + const string Initialize(PluginHost::IShell* service) override; + void Deinitialize(PluginHost::IShell* service) override; + string Information() const override; + + + private: + void Deactivated(RPC::IRemoteConnection* connection); + + private: + PluginHost::IShell* _service{}; + uint32_t _connectionId{}; + Exchange::ISystemMode* _systemMode{}; + }; + +} // namespace Plugin +} // namespace WPEFramework diff --git a/SystemMode/SystemMode.json b/SystemMode/SystemMode.json new file mode 100644 index 0000000000..a2ea51c8ce --- /dev/null +++ b/SystemMode/SystemMode.json @@ -0,0 +1,77 @@ +{ + "$schema": "https://raw.githubusercontent.com/rdkcentral/rdkservices/main/Tools/json_generator/schemas/interface.schema.json", + "jsonrpc": "2.0", + "info": { + "title": "SystemMode API", + "class": "org.rdk.SystemMode", + "description": "The `SystemMode` plugin coordinates state changes that take effect across multiple components in the system." + }, + "common": { + "$ref": "../common/common.json" + }, + "definitions": { + "systemMode": { + "summary": "System mode (must be one of the following: device_optimize)", + "type": "string", + "example": "device_optimize" + }, + "state": { + "summary": "The target state (must be one of the following: video, game)", + "type": "string", + "example": "game" + } + }, + "methods": { + "requestState": { + "summary": "Requests a new system mode state in the device. Thunder components asynchronously reconfigure themselves so the caller cannot be guaranteed a full state transition upon return.", + "params": { + "type":"object", + "properties": { + "systemMode": { + "$ref": "#/definitions/systemMode" + }, + "state": { + "$ref": "#/definitions/state" + } + }, + "required": [ + "systemMode", + "state" + ] + }, + "result": { + "$ref": "#/common/result" + } + }, + "getState": { + "summary": "Gets the current state for a given system property", + "params": { + "type":"object", + "properties": { + "systemMode": { + "$ref": "#/definitions/systemMode" + } + }, + "required": [ + "systemMode" + ] + }, + "result": { + "type": "object", + "properties": { + "state": { + "$ref": "#/definitions/state" + }, + "success":{ + "$ref": "#/common/success" + } + }, + "required": [ + "state", + "success" + ] + } + } + } +} + diff --git a/SystemMode/SystemModeImplementation.cpp b/SystemMode/SystemModeImplementation.cpp new file mode 100755 index 0000000000..3956ad4afe --- /dev/null +++ b/SystemMode/SystemModeImplementation.cpp @@ -0,0 +1,437 @@ +/* +* 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. +*/ + +#include "SystemModeImplementation.h" +#include +#include "UtilsJsonRpc.h" +#include +#include "tracing/Logging.h" +#include +#include + + +#define SYSTEMMODE_NAMESPACE "SystemMode" + +namespace WPEFramework { +namespace Plugin { + +SERVICE_REGISTRATION(SystemModeImplementation, 1, 0); + +SystemModeImplementation::SystemModeImplementation() +: _adminLock() +, _engine(Core::ProxyType>::Create()) +, _communicatorClient(Core::ProxyType::Create(Core::NodeId("/tmp/communicator"), Core::ProxyType(_engine))) +, _controller(nullptr) +,stateRequested(false) +{ + LOGINFO("Create SystemModeImplementation Instance"); + + SystemModeImplementation::instance(this); + + if (!_communicatorClient.IsValid()) + { + LOGWARN("Invalid _communicatorClient\n"); + } + else + { + +#if ((THUNDER_VERSION == 2) || ((THUNDER_VERSION == 4) && (THUNDER_VERSION_MINOR == 2))) + _engine->Announcements(_communicatorClient->Announcement()); +#endif + + } + + //set default value for each SystemMode + + SystemModeMap[DEVICE_OPTIMIZE] = "DEVICE_OPTIMIZE"; + + deviceOptimizeStateMap[VIDEO] ="VIDEO"; + deviceOptimizeStateMap[GAME] ="GAME"; + + + // Check if the file exists + std::ifstream infile(SYSTEM_MODE_FILE); + if (!infile.good()) { + // File doesn't exist, so create it + std::ofstream outfile(SYSTEM_MODE_FILE); + if (outfile) { + LOGINFO("File created successfully: %s\n", SYSTEM_MODE_FILE); + + //set default value for each SystemMode + updateSystemModeFile("DEVICE_OPTIMIZE" ,"currentstate" , "VIDEO" , "add"); + } else { + LOGERR("Error creating file: %s\n", SYSTEM_MODE_FILE); + } + } else { + LOGINFO("File already exists: %s\n", SYSTEM_MODE_FILE); + for (int i =1 ;i <=SYSTEM_MODE_COUNT ; i++ ) + { + std::string value = ""; + std::string systemMode = SystemModeMap[static_cast(i)] ; + getSystemModePropertyValue(systemMode, "callsign", value); + if (value != "") + { + updateSystemModeFile( systemMode, "callsign", "","deleteall") ; + std::vector callSignList; + Utils::String::split(callSignList, value , "|") ; + for (const auto& token : callSignList) { + + ClientActivated(token , systemMode); + } + + } + } + } + +} + +SystemModeImplementation* SystemModeImplementation::instance(SystemModeImplementation *SystemModeImpl) +{ + static SystemModeImplementation *SystemModeImpl_instance = nullptr; + + ASSERT (nullptr != SystemModeImpl); + + if (SystemModeImpl != nullptr) + { + SystemModeImpl_instance = SystemModeImpl; + } + + return(SystemModeImpl_instance); +} + +SystemModeImplementation::~SystemModeImplementation() +{ + if (_controller) + { + _controller->Release(); + _controller = nullptr; + } + + LOGINFO("Disconnect from the COM-RPC socket\n"); + // Disconnect from the COM-RPC socket + _communicatorClient->Close(RPC::CommunicationTimeOut); + if (_communicatorClient.IsValid()) + { + _communicatorClient.Release(); + } + + if(_engine.IsValid()) + { + _engine.Release(); + } + + for (auto& entry : _clients) { + if (entry.second) { // Check if the pointer is not null + entry.second->Release(); + } + } + +} + + +Core::hresult SystemModeImplementation::RequestState(const SystemMode pSystemMode, const State pState) +{ + auto SystemModeMapIterator = SystemModeMap.find(pSystemMode); + Core::hresult result = Core::ERROR_NONE; + + if(SystemModeMapIterator != SystemModeMap.end()) + { + std::string systemMode_str = SystemModeMapIterator->second; + switch (pSystemMode) { + case DEVICE_OPTIMIZE:{ + + auto deviceOptimizeStateMapIterator = deviceOptimizeStateMap.find(pState); + if (deviceOptimizeStateMapIterator != deviceOptimizeStateMap.end()) + { + std::string new_state = deviceOptimizeStateMapIterator->second; + std::string old_state = ""; + getSystemModePropertyValue(systemMode_str ,"currentstate" , old_state); + for (auto it = _clients.begin(); it != _clients.end(); ++it) { + if (it->second) { // Check if the pointer is not null + it->second->Request(new_state); // Call Request() on the object + SystemModesCurrentStateMap[pSystemMode] = pState; + updateSystemModeFile(systemMode_str,"currentstate",new_state,"add"); + LOGINFO("SystemMode state change from %s to new %s" ,old_state.c_str(),new_state.c_str()); + } + } + + stateRequested =true; + result = Core::ERROR_NONE; + } + else + { + LOGERR("Invalid state %d for systemMode %s" ,pState,systemMode_str.c_str()); + result = Core::ERROR_GENERAL; + } + break; + } + default: + { + LOGERR("Invalid systemMode %s",systemMode_str.c_str()); + result = Core::ERROR_GENERAL; + break; + } + + } + } + else + { + LOGERR("Invalid systemMode %d",pSystemMode); + result = Core::ERROR_GENERAL; + } + return result; +} + +Core::hresult SystemModeImplementation::GetState(const SystemMode pSystemMode, State &pState )const +{ + + Core::hresult result = Core::ERROR_NONE; + auto SystemModeMapIterator = SystemModeMap.find(pSystemMode); + if(SystemModeMapIterator != SystemModeMap.end()) + { + std::string value = ""; + std::string systemMode_str = SystemModeMapIterator->second; + getSystemModePropertyValue(systemMode_str ,"currentstate" , value); + switch (pSystemMode) { + case DEVICE_OPTIMIZE:{ + + // Iterate over the map to find the corresponding enum value + for (const auto& pair : deviceOptimizeStateMap) { + if (pair.second == value) { + pState = pair.first; + break; + } + } + result = Core::ERROR_NONE; + break; + } + default: + { + LOGERR("Invalid systemMode %d",static_cast(pSystemMode)); + result = Core::ERROR_GENERAL; + break; + } + } + } + else + { + LOGERR("Invalid systemMode %d",static_cast(pSystemMode)); + return Core::ERROR_GENERAL; + } + return result; + +} + +uint32_t SystemModeImplementation::ClientActivated(const string& callsign , const string& __SystemMode) +{ + SystemMode pSystemMode = DEVICE_OPTIMIZE; + + if (callsign != "") + { + _controller = nullptr; + _controller = _communicatorClient->Open(_T(callsign), ~0, 3000); + + if (_controller) + { + switch (pSystemMode) { + case DEVICE_OPTIMIZE:{ + + Exchange::IDeviceOptimizeStateActivator *deviceOptimizeStateActivator (_controller->QueryInterface()); + + if (deviceOptimizeStateActivator != nullptr) { + _adminLock.Lock(); + + std::map::iterator index(_clients.find(callsign)); + + if (index == _clients.end()) { + _clients.insert({callsign,deviceOptimizeStateActivator}); + updateSystemModeFile( SystemModeMap[pSystemMode], "callsign", callsign,"add") ; + TRACE(Trace::Information, (_T("%s plugin is add to deviceOptimizeStateActivator map"), callsign.c_str())); + + //If For Ex The plugins P1,P2,P3 who implement IDeviceOptimizeStateActivator . P1 ,P2 only activated . P3 is not in activated state .If org.rdk.SystemMode.RequestState (DeviceOptimize,GAME) is called then SystemMode trigger P1.Request() and P2.Request() . After 5 min if P3 come to activate state , then SystemMode need to trigger P3. Request()i + if(stateRequested) + { + State state ; + if(GetState(pSystemMode, state ) == Core::ERROR_NONE) + { + std::string state_str = deviceOptimizeStateMap[state]; + deviceOptimizeStateActivator->Request(state_str) ; + } + } + } + + deviceOptimizeStateActivator->AddRef(); + + _adminLock.Unlock(); + + } + break; + } + default: + { + LOGERR("Invalid systemMode %d",pSystemMode); + break; + } + } + + } + } + return 0; +} +uint32_t SystemModeImplementation::ClientDeactivated(const string& callsign ,const string& systemMode) +{ + SystemMode pSystemMode = DEVICE_OPTIMIZE; + _adminLock.Lock(); + switch (pSystemMode) { + case DEVICE_OPTIMIZE: + { + std::map::iterator index(_clients.find(callsign)); + + if (index != _clients.end()) { // Remove from the list, if it is already there + Exchange::IDeviceOptimizeStateActivator *temp = index->second; + temp->Release(); + _clients.erase(index); + updateSystemModeFile( SystemModeMap[pSystemMode], "callsign", callsign,"delete") ; + TRACE(Trace::Information, (_T("%s plugin is removed from power control list"), callsign.c_str())); + } + break; + } + default:{ + LOGERR("Invalid systemMode %d",pSystemMode); + break; + } + } + _adminLock.Unlock(); + return 0; +} + +void SystemModeImplementation::updateSystemModeFile(const std::string& systemMode, const std::string& property, const std::string& value, const std::string& action) { + + if (systemMode.empty() || property.empty()) { + LOGINFO("Error: systemMode or property is empty. systemMode: %s property: %s", systemMode.c_str(), property.c_str()); + return; + } + + if (action != "add" && action != "delete" && action != "deleteall") { + LOGINFO("Error: Invalid action. Action must be 'add', 'delete', or 'deleteall'."); + return; + } + + std::ifstream infile(SYSTEM_MODE_FILE); + std::string line; + std::stringstream buffer; + bool propertyFound = false; + std::string searchKey = systemMode + "_" + property; + + // Read the file content and process it line by line + if (infile.is_open()) { + while (std::getline(infile, line)) { + // If the line starts with the searchKey + if (line.find(searchKey) == 0) { + propertyFound = true; + if (action == "deleteall" && value.empty()) { + // Skip adding this line to the buffer, effectively removing it + continue; + } else if (property == "currentstate") { + if (action == "add") { + // Replace the value for currentstate + line = searchKey + "=" + value; + } else if (action == "delete") { + // To delete a currentstate, we might want to clear or remove the line + line.clear(); // This effectively removes the line + } + } else if (property == "callsign") { + if (action == "add") { + // Append the value to the callsign, ensuring no duplicate entries + if (line.find(value) == std::string::npos) { + line += value + "|"; + } + } else if (action == "delete") { + // Remove the value from the callsign + size_t pos = line.find(value); + if (pos != std::string::npos) { + line.erase(pos, value.length() + 1); // +1 to remove the trailing '|' + } + } + } + } + if (!line.empty()) { + buffer << line << std::endl; + } + } + infile.close(); + } + + // If the property wasn't found and the action is "add", add it to the file + if (!propertyFound && action == "add") { + if (property == "currentstate") { + buffer << searchKey + "=" + value << std::endl; + } else if (property == "callsign") { + buffer << searchKey + "=" + value + "|" << std::endl; + } + } + + // Write the modified content back to the file + std::ofstream outfile(SYSTEM_MODE_FILE); + if (outfile.is_open()) { + outfile << buffer.str(); + outfile.close(); + LOGINFO("Updated file %s successfully.", SYSTEM_MODE_FILE); + } else { + LOGINFO("Failed to open file %s for writing.", SYSTEM_MODE_FILE); + } +} + + + +bool SystemModeImplementation::getSystemModePropertyValue(const std::string& systemMode, const std::string& property, std::string& value) const +{ + if (systemMode.empty() || property.empty() ) { + LOGINFO("Error: systemMode or property is empty. systemMode: %s property: %s ",systemMode.c_str(),property.c_str()); + return false; + } + + std::ifstream infile(SYSTEM_MODE_FILE); + std::string line; + std::string searchKey = systemMode + "_" + property; + + if (!infile.is_open()) { + std::cerr << "Failed to open file: " << SYSTEM_MODE_FILE << std::endl; + return false; + } + + while (std::getline(infile, line)) { + // Check if the line starts with the search key + if (line.find(searchKey) == 0) { + // Extract the value after the '=' character + size_t pos = line.find('='); + if (pos != std::string::npos) { + value = line.substr(pos + 1); + infile.close(); + return true; + } + } + } + + infile.close(); + return false; +} + +} // namespace Plugin +} // namespace WPEFramework diff --git a/SystemMode/SystemModeImplementation.h b/SystemMode/SystemModeImplementation.h new file mode 100755 index 0000000000..181ab53ad1 --- /dev/null +++ b/SystemMode/SystemModeImplementation.h @@ -0,0 +1,81 @@ +/* +* 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 "Module.h" +#include +#include +#include +#include "tracing/Logging.h" +#include +#include "UtilsString.h" + +#include +#include +#include + +#define SYSTEM_MODE_COUNT 1 //Number of system mode define in Exchange::ISystemMode::SystemMode enum +#define SYSTEM_MODE_FILE "/tmp/SystemMode.txt" + +namespace WPEFramework { +namespace Plugin { + class SystemModeImplementation : public Exchange::ISystemMode{ + + public: + // We do not allow this plugin to be copied !! + SystemModeImplementation(); + ~SystemModeImplementation() override; + + static SystemModeImplementation* instance(SystemModeImplementation *SystemModeImpl = nullptr); + + // We do not allow this plugin to be copied !! + SystemModeImplementation(const SystemModeImplementation&) = delete; + SystemModeImplementation& operator=(const SystemModeImplementation&) = delete; + + BEGIN_INTERFACE_MAP(SystemModeImplementation) + INTERFACE_ENTRY(Exchange::ISystemMode) + END_INTERFACE_MAP + + public: + Core::hresult RequestState(const SystemMode systemMode, const State state) override; + Core::hresult GetState(const SystemMode systemMode, State &state )const override; + + virtual uint32_t ClientActivated(const string& callsign ,const string& systemMode) override ; + virtual uint32_t ClientDeactivated(const string& callsign, const string& systemMode) override ; + +//helper functions + void updateSystemModeFile(const std::string& systemMode, const std::string& property, const std::string& value, const std::string& action) ; + bool getSystemModePropertyValue(const std::string& systemMode, const std::string& property, std::string& value) const; + + private: + mutable Core::CriticalSection _adminLock; + std::map _clients; + Core::ProxyType> _engine; + Core::ProxyType _communicatorClient; + PluginHost::IShell *_controller; + std::map SystemModeMap; + std::map deviceOptimizeStateMap; + std::map SystemModesCurrentStateMap; + std::map SystemModeInterfaceMap; + bool stateRequested ; + + }; +} // namespace Plugin +} // namespace WPEFramework diff --git a/SystemMode/SystemModePlugin.json b/SystemMode/SystemModePlugin.json new file mode 100644 index 0000000000..22019ddd20 --- /dev/null +++ b/SystemMode/SystemModePlugin.json @@ -0,0 +1,13 @@ +{ + "$schema": "https://raw.githubusercontent.com/rdkcentral/rdkservices/main/Tools/json_generator/schemas/plugin.schema.json", + "info": { + "title": "System Mode Plugin", + "callsign": "org.rdk.SystemMode", + "locator": "libWPEFrameworkSystemMode.so", + "status": "production", + "description": "The `SystemMode` plugin coordinates state changes that take effect across multiple components in the system." + }, + "interface": { + "$ref": "SystemMode.json#" + } +} \ No newline at end of file diff --git a/Tests/L2Tests/L2TestsPlugin/CMakeLists.txt b/Tests/L2Tests/L2TestsPlugin/CMakeLists.txt index 9bdc5dfb94..c73df2362c 100755 --- a/Tests/L2Tests/L2TestsPlugin/CMakeLists.txt +++ b/Tests/L2Tests/L2TestsPlugin/CMakeLists.txt @@ -47,6 +47,9 @@ if(PLUGIN_USERSETTINGS) set(SRC_FILES ${SRC_FILES} tests/UserSettings_L2Test.cpp) endif() +if(PLUGIN_SYSTEMMODE) + set(SRC_FILES ${SRC_FILES} tests/SystemMode_L2Test.cpp) +endif() add_library(${MODULE_NAME} SHARED ${SRC_FILES}) set_target_properties(${MODULE_NAME} PROPERTIES diff --git a/Tests/L2Tests/L2TestsPlugin/tests/SystemMode_L2Test.cpp b/Tests/L2Tests/L2TestsPlugin/tests/SystemMode_L2Test.cpp new file mode 100755 index 0000000000..76e704bca4 --- /dev/null +++ b/Tests/L2Tests/L2TestsPlugin/tests/SystemMode_L2Test.cpp @@ -0,0 +1,119 @@ +#include +#include +#include "L2Tests.h" +#include "L2TestsMock.h" +#include +#include +#include +#include + +#define TEST_LOG(x, ...) fprintf(stderr, "\033[1;32m[%s:%d](%s)" x "\n\033[0m", __FILE__, __LINE__, __FUNCTION__, getpid(), gettid(), ##__VA_ARGS__); fflush(stderr); + +#define JSON_TIMEOUT (1000) +#define SYSTEMMODE_CALLSIGN _T("org.rdk.SystemMode") +#define SYSTEMMODEL2TEST_CALLSIGN _T("L2tests.1") + +using ::testing::NiceMock; +using namespace WPEFramework; +using testing::StrictMock; +using ::WPEFramework::Exchange::ISystemMode; + + +class AsyncHandlerMock +{ + public: + AsyncHandlerMock() + { + } +}; + +class SystemModeTest : public L2TestMocks { +protected: + virtual ~SystemModeTest() override; + + public: + SystemModeTest(); + + protected: + /** @brief Pointer to the IShell interface */ + PluginHost::IShell *m_controller_usersettings; + + /** @brief Pointer to the IUserSettings interface */ + //Exchange::IUserSettings *m_usersettingsplugin; +}; + +SystemModeTest:: SystemModeTest():L2TestMocks() +{ + Core::JSONRPC::Message message; + string response; + uint32_t status = Core::ERROR_GENERAL; + + /* Activate plugin in constructor */ + status = ActivateService("org.rdk.SystemMode"); + EXPECT_EQ(Core::ERROR_NONE, status); +} + +/** + * @brief Destructor for SystemServices L2 test class + */ +SystemModeTest::~SystemModeTest() +{ + uint32_t status = Core::ERROR_GENERAL; + + status = DeactivateService("org.rdk.SystemMode"); + EXPECT_EQ(Core::ERROR_NONE, status); +} + +TEST_F(SystemModeTest,GetStatedefault) +{ + JSONRPC::LinkType jsonrpc(SYSTEMMODE_CALLSIGN,SYSTEMMODEL2TEST_CALLSIGN); + uint32_t status = Core::ERROR_GENERAL; + JsonObject params; + JsonObject result; + std::string message; + std::string reply; + + params["systemMode"] = "DeviceOptimize"; + status = InvokeServiceMethod("org.rdk.SystemMode", "GetState", params, result); + EXPECT_EQ(Core::ERROR_NONE, status); + +} + +TEST_F(SystemModeTest,RequestStateGame) +{ + JSONRPC::LinkType jsonrpc(SYSTEMMODE_CALLSIGN,SYSTEMMODEL2TEST_CALLSIGN); + uint32_t status = Core::ERROR_GENERAL; + JsonObject params; + JsonObject result; + std::string message; + std::string reply; + + params["systemMode"] = "DeviceOptimize"; + params["state"] = "Game"; + status = InvokeServiceMethod("org.rdk.SystemMode", "RequestState", params, result); + EXPECT_EQ(Core::ERROR_NONE, status); + + status = InvokeServiceMethod("org.rdk.SystemMode", "GetState", params, result); + EXPECT_EQ(Core::ERROR_NONE, status); + +} + +TEST_F(SystemModeTest,RequestStateVideo) +{ + JSONRPC::LinkType jsonrpc(SYSTEMMODE_CALLSIGN,SYSTEMMODEL2TEST_CALLSIGN); + uint32_t status = Core::ERROR_GENERAL; + JsonObject params; + JsonObject result; + std::string message; + std::string reply; + + params["systemMode"] = "DeviceOptimize"; + params["state"] = "Video"; + status = InvokeServiceMethod("org.rdk.SystemMode", "RequestState", params, result); + EXPECT_EQ(Core::ERROR_NONE, status); + + status = InvokeServiceMethod("org.rdk.SystemMode", "GetState", params, result); + EXPECT_EQ(Core::ERROR_NONE, status); + +} + diff --git a/Tests/L2Tests/patches/RDK-51362-System-Mode-Thunder-Plugin.patch b/Tests/L2Tests/patches/RDK-51362-System-Mode-Thunder-Plugin.patch new file mode 100644 index 0000000000..5ee09042da --- /dev/null +++ b/Tests/L2Tests/patches/RDK-51362-System-Mode-Thunder-Plugin.patch @@ -0,0 +1,139 @@ +diff --git a/interfaces/IDeviceOptimizeStateActivator.h b/interfaces/IDeviceOptimizeStateActivator.h +new file mode 100644 +index 0000000..168c0e0 +--- /dev/null ++++ b/interfaces/IDeviceOptimizeStateActivator.h +@@ -0,0 +1,36 @@ ++/* ++ * 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 "Module.h" ++ ++namespace WPEFramework { ++namespace Exchange { ++ ++ /// Interface implemented by each Thunder component that needs to react to DEVICE_OPTIMIZE system mode state activation requests. ++ struct EXTERNAL IDeviceOptimizeStateActivator : virtual public Core::IUnknown { ++ enum { ID = ID_DEVICE_OPTIMIZE_STATE_ACTIVATOR }; ++ ++ /// Requests the component to asynchronously transition to the new state. ++ /// @param[in] newState The new target state to transition to. ++ virtual void Request(const string& newState /* @in @text newState*/) = 0; ++ }; ++} ++} +diff --git a/interfaces/ISystemMode.h b/interfaces/ISystemMode.h +new file mode 100644 +index 0000000..dea68e6 +--- /dev/null ++++ b/interfaces/ISystemMode.h +@@ -0,0 +1,72 @@ ++/* ++ * 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 "Module.h" ++ ++namespace WPEFramework { ++namespace Exchange { ++ // @json ++struct EXTERNAL ISystemMode : virtual public Core::IUnknown { ++ enum { ID = ID_SYSTEM_MODE }; ++ ++ /// Enumeration of system modes. ++ enum SystemMode : uint8_t { ++ DEVICE_OPTIMIZE = 1 ++ }; ++ ++ /// Enumeration of states for all system modes. ++ enum State : uint32_t { ++ // DEVICE_OPTIMIZE states ++ VIDEO = (DEVICE_OPTIMIZE << 24) | 1 , ++ GAME = (DEVICE_OPTIMIZE << 24) | 2 , ++ ++ // next system mode states... ++ }; ++ ++ // @alt RequestState ++ // @brief Requests a new system mode state in the device. Thunder components asynchronously reconfigure themselves so the caller cannot be guaranteed a full state transition upon return. ++ // @param[in] systemMode The system mode. ++ // @param[in] state The requested state. ++ // @returns Core::hresult ++ virtual Core::hresult RequestState(const SystemMode systemMode /* @in @text systemMode */ , const State state /* @in @text state */) = 0; ++ ++ // @alt GetState ++ // @brief Gets the current state for a given system property ++ // @param[in] systemMode The system mode to get the state of. ++ // @param[out] state Receives the state of the system mode. ++ // @returns Core::hresult ++ virtual Core::hresult GetState(const SystemMode systemMode /* @in @text systemMode */ , State &state /* @out @text state */) const = 0; ++ ++ // @alt ClientActivated ++ // @brief To put client plugin entry in map. ++ // @param[in] callsign callsign of client. ++ // @param[in] systemMode The system mode. ++ // @returns uint32_t ++ virtual uint32_t ClientActivated(const string& callsign /* @in @text callsign*/ ,const string& systemMode) = 0; ++ ++ // @alt ClientDeactivated ++ // @brief To put client plugin entry in map. ++ // @param[in] callsign callsign of client. ++ // @param[in] systemMode The system mode. ++ // @returns uint32_t ++ virtual uint32_t ClientDeactivated(const string& callsign /* @in @text callsign*/, const string& systemMode) = 0; ++}; ++} // namespace Exchange ++} // namespace WPEFramework + +diff --git a/interfaces/Ids.h b/interfaces/Ids.h +index e66cb22..7d53320 100644 +--- a/interfaces/Ids.h ++++ b/interfaces/Ids.h +@@ -363,7 +363,12 @@ namespace Exchange { + ID_TEXT_TO_SPEECH_NOTIFICATION = ID_TEXT_TO_SPEECH + 1, + + ID_USER_SETTINGS = RPC::IDS::ID_EXTERNAL_INTERFACE_OFFSET + 0x4D0, +- ID_USER_SETTINGS_NOTIFICATION = ID_USER_SETTINGS + 1 ++ ID_USER_SETTINGS_NOTIFICATION = ID_USER_SETTINGS + 1, ++ ++ ID_DEVICE_OPTIMIZE_STATE_ACTIVATOR = RPC::IDS::ID_EXTERNAL_INTERFACE_OFFSET + 0x510, ++ ++ ID_SYSTEM_MODE = RPC::IDS::ID_EXTERNAL_INTERFACE_OFFSET + 0x520, ++ ID_SYSTEM_MODE_NOTIFICATION = ID_SYSTEM_MODE + 1 + }; + } + } diff --git a/l2tests.cmake b/l2tests.cmake index 19ff775582..210d8e474a 100755 --- a/l2tests.cmake +++ b/l2tests.cmake @@ -117,6 +117,7 @@ set(PLUGIN_USBACCESS ON) if (USE_THUNDER_R4) set(PLUGIN_PERSISTENTSTORE ON) set(PLUGIN_USERSETTINGS ON) + set(PLUGIN_SYSTEMMODE ON) endif (USE_THUNDER_R4) set(PLUGIN_L2Tests ON) set(BUILD_SHARED_LIBS ON) From 5beb047c18d065eaa41eeb805597b27ef68bbfea Mon Sep 17 00:00:00 2001 From: ramkumarpraba Date: Mon, 16 Sep 2024 08:04:28 +0000 Subject: [PATCH 03/21] RDK-51450 IDeviceOptimizeStateActivator Thunder Interface for DisplaySettings - Broadcom Reason for change: IDeviceOptimizeStateActivator interface changes Test Procedure: verify build success and basic test Risks: Low Priority: P1 Signed-off-by: ramkumar_prabaharan@comcast.com --- DisplaySettings/DisplaySettings.cpp | 151 ++++++++++++++++++++++++++-- DisplaySettings/DisplaySettings.h | 17 +++- 2 files changed, 161 insertions(+), 7 deletions(-) diff --git a/DisplaySettings/DisplaySettings.cpp b/DisplaySettings/DisplaySettings.cpp index d344d4b342..453d6d60d2 100644 --- a/DisplaySettings/DisplaySettings.cpp +++ b/DisplaySettings/DisplaySettings.cpp @@ -244,6 +244,10 @@ namespace WPEFramework { DisplaySettings::DisplaySettings() : PluginHost::JSONRPC() + , _engine(Core::ProxyType>::Create()) + , _communicatorClient(Core::ProxyType::Create(Core::NodeId("/tmp/communicator"), Core::ProxyType(_engine))) + , _controller(nullptr) + , _remotStoreObject(nullptr) { LOGINFO("ctor"); DisplaySettings::_instance = this; @@ -251,6 +255,38 @@ namespace WPEFramework { CreateHandler({ 2 }); + if (!_communicatorClient.IsValid()) + { + LOGWARN("Invalid _communicatorClient \n"); + } + else + { + +#if ((THUNDER_VERSION == 2) || ((THUNDER_VERSION == 4) && (THUNDER_VERSION_MINOR == 2))) + _engine->Announcements(_communicatorClient->Announcement()); +#endif + + LOGINFO("Connect the COM-RPC socket\n"); + _controller = _communicatorClient->Open(_T("org.rdk.SystemMode"), ~0, 3000); + + if (_controller) + { + _remotStoreObject = _controller->QueryInterface(); + + if(_remotStoreObject) + { + _remotStoreObject->AddRef(); + } + } + else + { + LOGERR("Failed to create SystemMode Controller\n"); + } + + ASSERT (nullptr != _remotStoreObject); + + } + registerMethodLockedApi("getConnectedVideoDisplays", &DisplaySettings::getConnectedVideoDisplays, this); registerMethodLockedApi("getConnectedAudioPorts", &DisplaySettings::getConnectedAudioPorts, this); registerMethodLockedApi("setEnableAudioPort", &DisplaySettings::setEnableAudioPort, this); @@ -368,12 +404,36 @@ namespace WPEFramework { } DisplaySettings::~DisplaySettings() - { - LOGINFO ("dtor"); - isResCacheUpdated = false; - isDisplayConnectedCacheUpdated = false; - isStbHDRcapabilitiesCache = false; - } + { + if (_controller) + { + _controller->Release(); + _controller = nullptr; + } + + LOGINFO("Disconnect from the COM-RPC socket\n"); + // Disconnect from the COM-RPC socket + _communicatorClient->Close(RPC::CommunicationTimeOut); + if (_communicatorClient.IsValid()) + { + _communicatorClient.Release(); + } + + if(_engine.IsValid()) + { + _engine.Release(); + } + + if(_remotStoreObject) + { + _remotStoreObject->Release(); + } + + LOGINFO ("dtor"); + isResCacheUpdated = false; + isDisplayConnectedCacheUpdated = false; + isStbHDRcapabilitiesCache = false; + } void DisplaySettings::AudioPortsReInitialize() { @@ -557,12 +617,27 @@ namespace WPEFramework { LOGWARN("Current power state %d", m_powerState); } LOGWARN ("DisplaySettings::Initialize completes line:%d", __LINE__); + + + if(_remotStoreObject) + { + const string& callsign = "org.rdk.DisplaySettings"; + const string& systemMode = "DEVICE_OPTIMIZE"; + _remotStoreObject->ClientActivated(callsign,systemMode); + } + // On success return empty, to indicate there is no error text. return (string()); } void DisplaySettings::Deinitialize(PluginHost::IShell* service) { + if(_remotStoreObject) + { + const string& callsign = "org.rdk.DisplaySettings"; + const string& systemMode = "DEVICE_OPTIMIZE"; + _remotStoreObject->ClientDeactivated(callsign,systemMode); + } LOGINFO("Enetering DisplaySettings::Deinitialize"); { std::unique_lock lock(DisplaySettings::_instance->m_sendMsgMutex); @@ -5880,6 +5955,14 @@ void DisplaySettings::sendMsgThread() sendNotify("connectedVideoDisplaysUpdated", params); } previousStatus = hdmiHotPlugEvent; + + //If HDMI hotplug event occurs, DisplaySettings re-evaluate whether it should be signalling ALLM output of the HDMI port + std::string currentAllmState = ""; + currentAllmState = getcurrentAllmStateHelper("DEVICE_OPTIMIZE_currentstate="); + if(currentAllmState == "VIDEO" || currentAllmState == "GAME") + { + Request(currentAllmState); + } } void DisplaySettings::connectedAudioPortUpdated (int iAudioPortType, bool isPortConnected) @@ -6164,5 +6247,61 @@ void DisplaySettings::sendMsgThread() return mode; } + + void DisplaySettings::Request(const string& newState) + { + vector connectedDisplays; + getConnectedVideoDisplaysHelper(connectedDisplays); + for (int i = 0; i < (int)connectedDisplays.size(); i++) + { + try + { + std::string strVideoPort = connectedDisplays.at(i);; + device::VideoOutputPort vPort = device::Host::getInstance().getVideoOutputPort(strVideoPort.c_str()); + if (isDisplayConnected(strVideoPort)) + { + bool enable = (newState == "GAME") ? true : false; + vPort.setAllmEnabled(enable); + } + else + { + LOGWARN("failure: HDMI0 not connected!"); + } + } + catch (const device::Exception& err) + { + LOG_DEVICE_EXCEPTION0(); + } + } + } + std::string DisplaySettings::getcurrentAllmStateHelper(string targetKey) + { + std::ifstream file("/tmp/SystemMode.txt"); // Open the file + std::string line; + std::string currentState = ""; + + if (file.is_open()) { + // Read the file line by line + while (std::getline(file, line)) { + // Check if the line contains the target key + size_t pos = line.find(targetKey); + if (pos != std::string::npos) { + // Extract the value after the key + currentState = line.substr(pos + targetKey.length()); + break; // Stop after finding the key + } + } + file.close(); // Close the file + + if (!currentState.empty()) { + LOGINFO("DEVICE_OPTIMIZE_currentstate: %s \n", currentState.c_str()); + } else { + LOGINFO("DEVICE_OPTIMIZE_currentstate not found.\n"); + } + } else { + LOGINFO("Unable to open file /tmp/SystemMode.txt.\n"); } + + return currentState; + } } // namespace Plugin } // namespace WPEFramework diff --git a/DisplaySettings/DisplaySettings.h b/DisplaySettings/DisplaySettings.h index ffffeca8be..bc1030418a 100644 --- a/DisplaySettings/DisplaySettings.h +++ b/DisplaySettings/DisplaySettings.h @@ -28,6 +28,10 @@ #include "irMgr.h" #include "pwrMgr.h" #include "rfcapi.h" +#include +#include +#include +#include namespace WPEFramework { @@ -45,7 +49,7 @@ namespace WPEFramework { // As the registration/unregistration of notifications is realized by the class PluginHost::JSONRPC, // this class exposes a public method called, Notify(), using this methods, all subscribed clients // will receive a JSONRPC message as a notification, in case this method is called. - class DisplaySettings : public PluginHost::IPlugin, public PluginHost::JSONRPC { + class DisplaySettings : public PluginHost::IPlugin, public PluginHost::JSONRPC ,Exchange::IDeviceOptimizeStateActivator { private: typedef Core::JSON::String JString; typedef Core::JSON::ArrayType JStringArray; @@ -192,8 +196,12 @@ namespace WPEFramework { BEGIN_INTERFACE_MAP(DisplaySettings) INTERFACE_ENTRY(PluginHost::IPlugin) INTERFACE_ENTRY(PluginHost::IDispatcher) + INTERFACE_ENTRY(Exchange::IDeviceOptimizeStateActivator) END_INTERFACE_MAP + void Request(const string& newState); + std::string getcurrentAllmStateHelper(string targetKey); + private: void InitializeIARM(); void DeinitializeIARM(); @@ -316,6 +324,13 @@ namespace WPEFramework { public: static DisplaySettings* _instance; + private: + mutable Core::CriticalSection _adminLock; + Core::ProxyType> _engine; + Core::ProxyType _communicatorClient; + PluginHost::IShell *_controller; + Exchange::ISystemMode* _remotStoreObject; + }; } // namespace Plugin } // namespace WPEFramework From 79230123ff9a99a427cc21e423562e6c21eb3ff6 Mon Sep 17 00:00:00 2001 From: ramkumarpraba Date: Tue, 17 Sep 2024 06:14:57 +0000 Subject: [PATCH 04/21] RDK-51362 : System Mode Thunder Plugin to support ALLM Reason for change: Testcase extented for Display setting IDeviceOptimizeStateActivator interface changes Test Procedure: verify build success and basic test Risks: Low Priority: P1 Signed-off-by: ramkumar_prabaharan@comcast.com --- Tests/L1Tests/tests/.test_HdmiCecSink.cpp.swo | Bin 0 -> 16384 bytes .../L2TestsPlugin/tests/SystemMode_L2Test.cpp | 23 ++++++++++++++++++ Tests/mocks/HdmiCec.h | 7 ++++++ Tests/mocks/Iarm.h | 1 + 4 files changed, 31 insertions(+) create mode 100644 Tests/L1Tests/tests/.test_HdmiCecSink.cpp.swo diff --git a/Tests/L1Tests/tests/.test_HdmiCecSink.cpp.swo b/Tests/L1Tests/tests/.test_HdmiCecSink.cpp.swo new file mode 100644 index 0000000000000000000000000000000000000000..29af8fb8db49115cc3fe4dbed175248c93560b0c GIT binary patch literal 16384 zcmeHOTZ|i58J^OXLV5v#gpiQXsf$+QmDk?QrA?jeN?v<5F|56g?aii5s$q8Kcz3k3 zGozXDZk8zRLnZo#5CS161zw>9@e;%vk+{4dp#l#`@K7Wk`cQ$y3lE64d}q!X`^?zu zln5k5W~6T?KDYlr-~XT6eXVW9jrs zmN(6Act4PN zzb76l(tDZwcSU|*r2iz7|BlFiUZg)J1SE1E6zQsX4>I{8Ie+C0iU3w#>*B=E-*$Omo#J3tk97Wm7D73IgkZNLVe2F?I~`;emi68Hu1GEf6E^r&@0*?T%KBOp@fDZ6y1TAg@J>a(ppnL;( z4yXfnz$fGMiz1G37t@eq9_>m;tM~POcT-b$4cBsLK%QJC?$B}kC@7v&rq#0tL{-Bm zz^4;xv(|0ttD8N&(Q94k>g`%fE0X19BC@?hmj-QPpB9T`ZjPw*fVxrBVkI&)waZ$& zuU~AmntHRXU)<<-);BMp){Utu+?<-ql=TmT)=tp!ELum0cBsZAUKCwhCZdzmJI3n& z=NRd1b?=oDQI&Jj+GuF?i?#Lztud94t8*`?rsswcF?Wq%o{TszagJjKnwB0B!M>a> zm_epsCd+tv%XXaAqXr!qLnl(JRrW0mEMKiQ-2-orstRL`JsWMkj_+>Nd0)4UV1IQO zHurs}g)er5K&0qhx?_hC4P>*(jp`*LiOBpa78NBH#s3_yT9-z{!0pn3TG#4p0sOC8 z-JwwvBpI$r)nZX{ZAtHa8iodZ#x>zTa3ZEUjep2Gwv5Q!rNMbl`X)Xrs(Wq}cuprk zeQM3E$fb1%leH%Q8)`R<$XIpI!ztRP)MZ@Xl=)%_$usZo9)&f_VjU;TL>=00bn2uY z6&J5Boji5=%+t@Dog8Y+VUvPHZegnLb*WE{h+58(%xc#8#IQ{q(6P7cF#Xs8Vf_wN zwN1kj>dLLbMk&vVyEnDd(Qe=!5;WcRYUZAH-K2hGd#)<^Q^L)7T&{aNl3+472)z9g z;qKFC4eFH4Szi3lsT};f;}1={)MSc{8Sp*FN%c8B(xx$x^knus^2jixB-*89AO1va zjC#6{S=V3+R9L#jXAiPXcZ~zv3y3#}%MU!Cx@0hPV_ga3g=__e9}?3s!mvDFQ4-m4 zao$@alF-}4Ot%M6=6qN=A?B~awoHA$R10WCcl-M z4`m%DXUdcgli4$LNK0WRkU3cALs=G{8Qm$#nYR@d&2-%b^tTeTx*i6kOCX)-z zwvDhOuaKI42v*4STnEn??a&FYk?s`=pia7H6IC+ak2?H8&Fm1$N}C+7qpDNJeYW

1(qmgsCJXhB z%}6(5;S+a!*Dk(hPv`acNAHs@2_`2q)(m`VAJ{ZrT*nJ}x>J}Ulj+{*KoeC0%w6|fPdmF{}12}@KfNcKo@uvI01YIXZzQHZvig= zSAov}f5qAUCE!KiQ^4B>A6gU5P^(qh3d7! zQu*|?Lg`u|9Gcj0g-DBnA-!2h;$!31_#r~;b~g|e-)L*2b6i=3uEv|)64Co=0TC+v z??NH0P~?d>&~#~Z7E7ckqirw#!NOEhoFvH#;t(j=YP33fZxg|=UXPy@k^=0Fvz}}E zN2(u29Rp!f78G1qIWU|dEfLn)0?4qxK)u1VB8fV3i(>-B4S;XPEmOpN<9mQHyN!6) zTIR2&JMhX^^lsyGb=(7VYwHX3jh5bBtC!bsW*r8!EblnSRv9sW7bWV3gS(Ap18fS# z3Q~g;tz1P&Jr1V(W>PZ=*d^(yZj}gB)khra(L9kkm4kY5_;-Uvp`}1~Hk?`R+c;9F zOZ=o>nU}+x>4RN~z;Pgaq>kKdCVoB<@w=h)wO(IeQzb6gsi#C5&0cMFU2Etmw=62k z`x-UWHMSjUiQ(~I8!s9cbNpaYm{%Mdrx;&e!Jm?=n&hqmS6U*K-@-I%S_?M?&33cj ztgSbn*BT`~P8#IK)Z20)%_gc8>VAXd5y@xm`er@^|i(+#hN$z4;RbH#s>uFta z5qGS@>8rVE#%sEEWE&2KtQALD8X-5QurDW!Yc#UutU$|{BI!0uqUgAbswv#Wwipps z1{+2h*D(<-o5O&qM9K2#PEfSl+1S#$y?(8)>G<1jtUkxtn%WG4xp!}7qn)u5lLRYq zwxCnmG_lgMZDx^m@8h8sV #include #include +#include "HdmiCec.h" #define TEST_LOG(x, ...) fprintf(stderr, "\033[1;32m[%s:%d](%s)" x "\n\033[0m", __FILE__, __LINE__, __FUNCTION__, getpid(), gettid(), ##__VA_ARGS__); fflush(stderr); @@ -90,6 +91,17 @@ TEST_F(SystemModeTest,RequestStateGame) params["systemMode"] = "DeviceOptimize"; params["state"] = "Game"; + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) + .Times(::testing::AnyNumber()) + .WillRepeatedly( + [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { + EXPECT_EQ(string(ownerName), string(_T(IARM_BUS_MFRLIB_NAME))); + EXPECT_EQ(string(methodName), string(_T(IARM_BUS_DSMGR_API_dsSetAllmEnabled))); + auto param = static_cast(arg); + param->result =dsERR_NONE; + return IARM_RESULT_SUCCESS; + }); + status = InvokeServiceMethod("org.rdk.SystemMode", "RequestState", params, result); EXPECT_EQ(Core::ERROR_NONE, status); @@ -109,6 +121,17 @@ TEST_F(SystemModeTest,RequestStateVideo) params["systemMode"] = "DeviceOptimize"; params["state"] = "Video"; + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) + .Times(::testing::AnyNumber()) + .WillRepeatedly( + [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { + EXPECT_EQ(string(ownerName), string(_T(IARM_BUS_MFRLIB_NAME))); + EXPECT_EQ(string(methodName), string(_T(IARM_BUS_DSMGR_API_dsSetAllmEnabled))); + auto param = static_cast(arg); + param->result =dsERR_NONE; + return IARM_RESULT_SUCCESS; + }); + status = InvokeServiceMethod("org.rdk.SystemMode", "RequestState", params, result); EXPECT_EQ(Core::ERROR_NONE, status); diff --git a/Tests/mocks/HdmiCec.h b/Tests/mocks/HdmiCec.h index 2919995146..e725415b0d 100644 --- a/Tests/mocks/HdmiCec.h +++ b/Tests/mocks/HdmiCec.h @@ -55,6 +55,13 @@ typedef struct _dsGetHDMIARCPortIdParam_t { int portId; } dsGetHDMIARCPortIdParam_t; +typedef struct _dsSetAllmEnabledParam_t +{ + dsError_t result; + intptr_t handle; + bool enabled; +}dsSetAllmEnabledParam_t; + typedef struct _Throw_e { } Throw_e; diff --git a/Tests/mocks/Iarm.h b/Tests/mocks/Iarm.h index 175f27249a..d08985a61b 100644 --- a/Tests/mocks/Iarm.h +++ b/Tests/mocks/Iarm.h @@ -214,6 +214,7 @@ typedef struct _DeepSleepMgr_WakeupKeyCode_Param_t { #define IARM_BUS_MFRLIB_API_GetSerializedData "mfrGetManufacturerData" #define IARM_BUS_MFRLIB_API_SetFsrFlag "mfrSetFSRflag" #define IARM_BUS_MFRLIB_API_GetFsrFlag "mfrGetFSRflag" +#define IARM_BUS_DSMGR_API_dsSetAllmEnabled "dsSetAllmEnabled" typedef enum _mfrSerializedType_t { mfrSERIALIZED_TYPE_MANUFACTURER = 0, From 612335d0aa75857290a8f3f6e88f2014cdf60875 Mon Sep 17 00:00:00 2001 From: ramkumarpraba Date: Tue, 17 Sep 2024 06:14:57 +0000 Subject: [PATCH 05/21] RDK-51362 : System Mode Thunder Plugin to support ALLM Reason for change: Testcase extented for Display setting IDeviceOptimizeStateActivator interface changes Test Procedure: verify build success and basic test Risks: Low Priority: P1 Signed-off-by: ramkumar_prabaharan@comcast.com --- DisplaySettings/DisplaySettings.cpp | 54 +++---- DisplaySettings/DisplaySettings.h | 1 - SystemMode/SystemMode.conf.in | 2 +- SystemMode/SystemMode.config | 2 +- SystemMode/SystemModeImplementation.cpp | 134 ++---------------- SystemMode/SystemModeImplementation.h | 4 - .../L2TestsPlugin/tests/SystemMode_L2Test.cpp | 23 +++ Tests/mocks/HdmiCec.h | 7 + Tests/mocks/Iarm.h | 1 + helpers/UtilsString.h | 125 ++++++++++++++++ 10 files changed, 190 insertions(+), 163 deletions(-) diff --git a/DisplaySettings/DisplaySettings.cpp b/DisplaySettings/DisplaySettings.cpp index 453d6d60d2..6fff2dddae 100644 --- a/DisplaySettings/DisplaySettings.cpp +++ b/DisplaySettings/DisplaySettings.cpp @@ -625,6 +625,10 @@ namespace WPEFramework { const string& systemMode = "DEVICE_OPTIMIZE"; _remotStoreObject->ClientActivated(callsign,systemMode); } + else + { + Utils::String::updateSystemModeFile( "DEVICE_OPTIMIZE", "callsign", "org.rdk.DisplaySettings","add") ; + } // On success return empty, to indicate there is no error text. return (string()); @@ -638,6 +642,11 @@ namespace WPEFramework { const string& systemMode = "DEVICE_OPTIMIZE"; _remotStoreObject->ClientDeactivated(callsign,systemMode); } + else + { + Utils::String::updateSystemModeFile( "DEVICE_OPTIMIZE", "callsign", "org.rdk.DisplaySettings","delete") ; + } + LOGINFO("Enetering DisplaySettings::Deinitialize"); { std::unique_lock lock(DisplaySettings::_instance->m_sendMsgMutex); @@ -5958,11 +5967,11 @@ void DisplaySettings::sendMsgThread() //If HDMI hotplug event occurs, DisplaySettings re-evaluate whether it should be signalling ALLM output of the HDMI port std::string currentAllmState = ""; - currentAllmState = getcurrentAllmStateHelper("DEVICE_OPTIMIZE_currentstate="); - if(currentAllmState == "VIDEO" || currentAllmState == "GAME") - { - Request(currentAllmState); - } + Utils::String::getSystemModePropertyValue("DEVICE_OPTIMIZE" ,"currentstate" , currentAllmState); + if(currentAllmState == "VIDEO" || currentAllmState == "GAME") + { + Request(currentAllmState); + } } void DisplaySettings::connectedAudioPortUpdated (int iAudioPortType, bool isPortConnected) @@ -6265,7 +6274,7 @@ void DisplaySettings::sendMsgThread() } else { - LOGWARN("failure: HDMI0 not connected!"); + LOGWARN("failure: %s is not connected!",strVideoPort.c_str()); } } catch (const device::Exception& err) @@ -6273,35 +6282,10 @@ void DisplaySettings::sendMsgThread() LOG_DEVICE_EXCEPTION0(); } } - } - std::string DisplaySettings::getcurrentAllmStateHelper(string targetKey) - { - std::ifstream file("/tmp/SystemMode.txt"); // Open the file - std::string line; - std::string currentState = ""; - - if (file.is_open()) { - // Read the file line by line - while (std::getline(file, line)) { - // Check if the line contains the target key - size_t pos = line.find(targetKey); - if (pos != std::string::npos) { - // Extract the value after the key - currentState = line.substr(pos + targetKey.length()); - break; // Stop after finding the key - } - } - file.close(); // Close the file - - if (!currentState.empty()) { - LOGINFO("DEVICE_OPTIMIZE_currentstate: %s \n", currentState.c_str()); - } else { - LOGINFO("DEVICE_OPTIMIZE_currentstate not found.\n"); - } - } else { - LOGINFO("Unable to open file /tmp/SystemMode.txt.\n"); } - - return currentState; + if( 0 == (int)connectedDisplays.size()) + { + LOGWARN("No display connected to device (or)device's powerstate is not ON"); + } } } // namespace Plugin } // namespace WPEFramework diff --git a/DisplaySettings/DisplaySettings.h b/DisplaySettings/DisplaySettings.h index bc1030418a..e2140c0af3 100644 --- a/DisplaySettings/DisplaySettings.h +++ b/DisplaySettings/DisplaySettings.h @@ -200,7 +200,6 @@ namespace WPEFramework { END_INTERFACE_MAP void Request(const string& newState); - std::string getcurrentAllmStateHelper(string targetKey); private: void InitializeIARM(); diff --git a/SystemMode/SystemMode.conf.in b/SystemMode/SystemMode.conf.in index 13940e5550..e361d2c917 100755 --- a/SystemMode/SystemMode.conf.in +++ b/SystemMode/SystemMode.conf.in @@ -1,4 +1,4 @@ -autostart = "@PLUGIN_SYSTEMMODE_AUTOSTART@" +autostart = "true" precondition = ["Platform"] callsign = "org.rdk.SystemMode" startuporder = "@PLUGIN_SYSTEMMODE_STARTUPORDER@" diff --git a/SystemMode/SystemMode.config b/SystemMode/SystemMode.config index e4fa1b96f3..e2faf71aa4 100755 --- a/SystemMode/SystemMode.config +++ b/SystemMode/SystemMode.config @@ -1,4 +1,4 @@ -set(autostart ${PLUGIN_SYSTEMMODE_AUTOSTART}) +set(autostart true) if(PLUGIN_SYSTEMMODE_STARTUPORDER) set (startuporder ${PLUGIN_SYSTEMMODE_STARTUPORDER}) diff --git a/SystemMode/SystemModeImplementation.cpp b/SystemMode/SystemModeImplementation.cpp index 3956ad4afe..2c05d4af06 100755 --- a/SystemMode/SystemModeImplementation.cpp +++ b/SystemMode/SystemModeImplementation.cpp @@ -74,7 +74,7 @@ SystemModeImplementation::SystemModeImplementation() LOGINFO("File created successfully: %s\n", SYSTEM_MODE_FILE); //set default value for each SystemMode - updateSystemModeFile("DEVICE_OPTIMIZE" ,"currentstate" , "VIDEO" , "add"); + Utils::String::updateSystemModeFile("DEVICE_OPTIMIZE" ,"currentstate" , "VIDEO" , "add"); } else { LOGERR("Error creating file: %s\n", SYSTEM_MODE_FILE); } @@ -84,10 +84,10 @@ SystemModeImplementation::SystemModeImplementation() { std::string value = ""; std::string systemMode = SystemModeMap[static_cast(i)] ; - getSystemModePropertyValue(systemMode, "callsign", value); + Utils::String::getSystemModePropertyValue(systemMode, "callsign", value); if (value != "") { - updateSystemModeFile( systemMode, "callsign", "","deleteall") ; + Utils::String::updateSystemModeFile( systemMode, "callsign", "","deleteall") ; std::vector callSignList; Utils::String::split(callSignList, value , "|") ; for (const auto& token : callSignList) { @@ -161,12 +161,12 @@ Core::hresult SystemModeImplementation::RequestState(const SystemMode pSystemMod { std::string new_state = deviceOptimizeStateMapIterator->second; std::string old_state = ""; - getSystemModePropertyValue(systemMode_str ,"currentstate" , old_state); + Utils::String::getSystemModePropertyValue(systemMode_str ,"currentstate" , old_state); for (auto it = _clients.begin(); it != _clients.end(); ++it) { if (it->second) { // Check if the pointer is not null it->second->Request(new_state); // Call Request() on the object SystemModesCurrentStateMap[pSystemMode] = pState; - updateSystemModeFile(systemMode_str,"currentstate",new_state,"add"); + Utils::String::updateSystemModeFile(systemMode_str,"currentstate",new_state,"add"); LOGINFO("SystemMode state change from %s to new %s" ,old_state.c_str(),new_state.c_str()); } } @@ -207,7 +207,7 @@ Core::hresult SystemModeImplementation::GetState(const SystemMode pSystemMode, S { std::string value = ""; std::string systemMode_str = SystemModeMapIterator->second; - getSystemModePropertyValue(systemMode_str ,"currentstate" , value); + Utils::String::getSystemModePropertyValue(systemMode_str ,"currentstate" , value); switch (pSystemMode) { case DEVICE_OPTIMIZE:{ @@ -244,7 +244,11 @@ uint32_t SystemModeImplementation::ClientActivated(const string& callsign , cons if (callsign != "") { - _controller = nullptr; + if (_controller) + { + _controller->Release(); + _controller = nullptr; + } _controller = _communicatorClient->Open(_T(callsign), ~0, 3000); if (_controller) @@ -261,7 +265,7 @@ uint32_t SystemModeImplementation::ClientActivated(const string& callsign , cons if (index == _clients.end()) { _clients.insert({callsign,deviceOptimizeStateActivator}); - updateSystemModeFile( SystemModeMap[pSystemMode], "callsign", callsign,"add") ; + Utils::String::updateSystemModeFile( SystemModeMap[pSystemMode], "callsign", callsign,"add") ; TRACE(Trace::Information, (_T("%s plugin is add to deviceOptimizeStateActivator map"), callsign.c_str())); //If For Ex The plugins P1,P2,P3 who implement IDeviceOptimizeStateActivator . P1 ,P2 only activated . P3 is not in activated state .If org.rdk.SystemMode.RequestState (DeviceOptimize,GAME) is called then SystemMode trigger P1.Request() and P2.Request() . After 5 min if P3 come to activate state , then SystemMode need to trigger P3. Request()i @@ -307,7 +311,7 @@ uint32_t SystemModeImplementation::ClientDeactivated(const string& callsign ,con Exchange::IDeviceOptimizeStateActivator *temp = index->second; temp->Release(); _clients.erase(index); - updateSystemModeFile( SystemModeMap[pSystemMode], "callsign", callsign,"delete") ; + Utils::String::updateSystemModeFile( SystemModeMap[pSystemMode], "callsign", callsign,"delete") ; TRACE(Trace::Information, (_T("%s plugin is removed from power control list"), callsign.c_str())); } break; @@ -321,117 +325,5 @@ uint32_t SystemModeImplementation::ClientDeactivated(const string& callsign ,con return 0; } -void SystemModeImplementation::updateSystemModeFile(const std::string& systemMode, const std::string& property, const std::string& value, const std::string& action) { - - if (systemMode.empty() || property.empty()) { - LOGINFO("Error: systemMode or property is empty. systemMode: %s property: %s", systemMode.c_str(), property.c_str()); - return; - } - - if (action != "add" && action != "delete" && action != "deleteall") { - LOGINFO("Error: Invalid action. Action must be 'add', 'delete', or 'deleteall'."); - return; - } - - std::ifstream infile(SYSTEM_MODE_FILE); - std::string line; - std::stringstream buffer; - bool propertyFound = false; - std::string searchKey = systemMode + "_" + property; - - // Read the file content and process it line by line - if (infile.is_open()) { - while (std::getline(infile, line)) { - // If the line starts with the searchKey - if (line.find(searchKey) == 0) { - propertyFound = true; - if (action == "deleteall" && value.empty()) { - // Skip adding this line to the buffer, effectively removing it - continue; - } else if (property == "currentstate") { - if (action == "add") { - // Replace the value for currentstate - line = searchKey + "=" + value; - } else if (action == "delete") { - // To delete a currentstate, we might want to clear or remove the line - line.clear(); // This effectively removes the line - } - } else if (property == "callsign") { - if (action == "add") { - // Append the value to the callsign, ensuring no duplicate entries - if (line.find(value) == std::string::npos) { - line += value + "|"; - } - } else if (action == "delete") { - // Remove the value from the callsign - size_t pos = line.find(value); - if (pos != std::string::npos) { - line.erase(pos, value.length() + 1); // +1 to remove the trailing '|' - } - } - } - } - if (!line.empty()) { - buffer << line << std::endl; - } - } - infile.close(); - } - - // If the property wasn't found and the action is "add", add it to the file - if (!propertyFound && action == "add") { - if (property == "currentstate") { - buffer << searchKey + "=" + value << std::endl; - } else if (property == "callsign") { - buffer << searchKey + "=" + value + "|" << std::endl; - } - } - - // Write the modified content back to the file - std::ofstream outfile(SYSTEM_MODE_FILE); - if (outfile.is_open()) { - outfile << buffer.str(); - outfile.close(); - LOGINFO("Updated file %s successfully.", SYSTEM_MODE_FILE); - } else { - LOGINFO("Failed to open file %s for writing.", SYSTEM_MODE_FILE); - } -} - - - -bool SystemModeImplementation::getSystemModePropertyValue(const std::string& systemMode, const std::string& property, std::string& value) const -{ - if (systemMode.empty() || property.empty() ) { - LOGINFO("Error: systemMode or property is empty. systemMode: %s property: %s ",systemMode.c_str(),property.c_str()); - return false; - } - - std::ifstream infile(SYSTEM_MODE_FILE); - std::string line; - std::string searchKey = systemMode + "_" + property; - - if (!infile.is_open()) { - std::cerr << "Failed to open file: " << SYSTEM_MODE_FILE << std::endl; - return false; - } - - while (std::getline(infile, line)) { - // Check if the line starts with the search key - if (line.find(searchKey) == 0) { - // Extract the value after the '=' character - size_t pos = line.find('='); - if (pos != std::string::npos) { - value = line.substr(pos + 1); - infile.close(); - return true; - } - } - } - - infile.close(); - return false; -} - } // namespace Plugin } // namespace WPEFramework diff --git a/SystemMode/SystemModeImplementation.h b/SystemMode/SystemModeImplementation.h index 181ab53ad1..66518cad24 100755 --- a/SystemMode/SystemModeImplementation.h +++ b/SystemMode/SystemModeImplementation.h @@ -60,10 +60,6 @@ namespace Plugin { virtual uint32_t ClientActivated(const string& callsign ,const string& systemMode) override ; virtual uint32_t ClientDeactivated(const string& callsign, const string& systemMode) override ; -//helper functions - void updateSystemModeFile(const std::string& systemMode, const std::string& property, const std::string& value, const std::string& action) ; - bool getSystemModePropertyValue(const std::string& systemMode, const std::string& property, std::string& value) const; - private: mutable Core::CriticalSection _adminLock; std::map _clients; diff --git a/Tests/L2Tests/L2TestsPlugin/tests/SystemMode_L2Test.cpp b/Tests/L2Tests/L2TestsPlugin/tests/SystemMode_L2Test.cpp index 76e704bca4..b2486ad1e1 100755 --- a/Tests/L2Tests/L2TestsPlugin/tests/SystemMode_L2Test.cpp +++ b/Tests/L2Tests/L2TestsPlugin/tests/SystemMode_L2Test.cpp @@ -6,6 +6,7 @@ #include #include #include +#include "HdmiCec.h" #define TEST_LOG(x, ...) fprintf(stderr, "\033[1;32m[%s:%d](%s)" x "\n\033[0m", __FILE__, __LINE__, __FUNCTION__, getpid(), gettid(), ##__VA_ARGS__); fflush(stderr); @@ -90,6 +91,17 @@ TEST_F(SystemModeTest,RequestStateGame) params["systemMode"] = "DeviceOptimize"; params["state"] = "Game"; + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) + .Times(::testing::AnyNumber()) + .WillRepeatedly( + [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { + EXPECT_EQ(string(ownerName), string(_T(IARM_BUS_MFRLIB_NAME))); + EXPECT_EQ(string(methodName), string(_T(IARM_BUS_DSMGR_API_dsSetAllmEnabled))); + auto param = static_cast(arg); + param->result =dsERR_NONE; + return IARM_RESULT_SUCCESS; + }); + status = InvokeServiceMethod("org.rdk.SystemMode", "RequestState", params, result); EXPECT_EQ(Core::ERROR_NONE, status); @@ -109,6 +121,17 @@ TEST_F(SystemModeTest,RequestStateVideo) params["systemMode"] = "DeviceOptimize"; params["state"] = "Video"; + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) + .Times(::testing::AnyNumber()) + .WillRepeatedly( + [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { + EXPECT_EQ(string(ownerName), string(_T(IARM_BUS_MFRLIB_NAME))); + EXPECT_EQ(string(methodName), string(_T(IARM_BUS_DSMGR_API_dsSetAllmEnabled))); + auto param = static_cast(arg); + param->result =dsERR_NONE; + return IARM_RESULT_SUCCESS; + }); + status = InvokeServiceMethod("org.rdk.SystemMode", "RequestState", params, result); EXPECT_EQ(Core::ERROR_NONE, status); diff --git a/Tests/mocks/HdmiCec.h b/Tests/mocks/HdmiCec.h index 2919995146..e725415b0d 100644 --- a/Tests/mocks/HdmiCec.h +++ b/Tests/mocks/HdmiCec.h @@ -55,6 +55,13 @@ typedef struct _dsGetHDMIARCPortIdParam_t { int portId; } dsGetHDMIARCPortIdParam_t; +typedef struct _dsSetAllmEnabledParam_t +{ + dsError_t result; + intptr_t handle; + bool enabled; +}dsSetAllmEnabledParam_t; + typedef struct _Throw_e { } Throw_e; diff --git a/Tests/mocks/Iarm.h b/Tests/mocks/Iarm.h index 175f27249a..d08985a61b 100644 --- a/Tests/mocks/Iarm.h +++ b/Tests/mocks/Iarm.h @@ -214,6 +214,7 @@ typedef struct _DeepSleepMgr_WakeupKeyCode_Param_t { #define IARM_BUS_MFRLIB_API_GetSerializedData "mfrGetManufacturerData" #define IARM_BUS_MFRLIB_API_SetFsrFlag "mfrSetFSRflag" #define IARM_BUS_MFRLIB_API_GetFsrFlag "mfrGetFSRflag" +#define IARM_BUS_DSMGR_API_dsSetAllmEnabled "dsSetAllmEnabled" typedef enum _mfrSerializedType_t { mfrSERIALIZED_TYPE_MANUFACTURER = 0, diff --git a/helpers/UtilsString.h b/helpers/UtilsString.h index 67c6e878f5..ffa1372a7f 100644 --- a/helpers/UtilsString.h +++ b/helpers/UtilsString.h @@ -1,4 +1,8 @@ #pragma once +#include +#include +#include "UtilsLogging.h" +#define SYSTEM_MODE_FILE "/tmp/SystemMode.txt" namespace Utils { namespace String { @@ -191,5 +195,126 @@ namespace String { return sentence; } + void updateSystemModeFile(const std::string& systemMode, const std::string& property, const std::string& value, const std::string& action) { + + if (systemMode.empty() || property.empty()) { + LOGINFO("Error: systemMode or property is empty. systemMode: %s property: %s", systemMode.c_str(), property.c_str()); + return; + } + + if (action != "add" && action != "delete" && action != "deleteall") { + LOGINFO("Error: Invalid action. Action must be 'add', 'delete', or 'deleteall'."); + return; + } + + std::ifstream infile(SYSTEM_MODE_FILE); + if (!infile.good()) { + // File doesn't exist, so create it + std::ofstream outfile(SYSTEM_MODE_FILE); + if (outfile) { + LOGINFO("File created successfully: %s\n", SYSTEM_MODE_FILE); + + //set default value for each SystemMode + Utils::String::updateSystemModeFile("DEVICE_OPTIMIZE" ,"currentstate" , "VIDEO" , "add"); + } else { + LOGERR("Error creating file: %s\n", SYSTEM_MODE_FILE); + return; + } + } + std::string line; + std::stringstream buffer; + bool propertyFound = false; + std::string searchKey = systemMode + "_" + property; + + // Read the file content and process it line by line + if (infile.is_open()) { + while (std::getline(infile, line)) { + // If the line starts with the searchKey + if (line.find(searchKey) == 0) { + propertyFound = true; + if (action == "deleteall" && value.empty()) { + // Skip adding this line to the buffer, effectively removing it + continue; + } else if (property == "currentstate") { + if (action == "add") { + // Replace the value for currentstate + line = searchKey + "=" + value; + } else if (action == "delete") { + // To delete a currentstate, we might want to clear or remove the line + line.clear(); // This effectively removes the line + } + } else if (property == "callsign") { + if (action == "add") { + // Append the value to the callsign, ensuring no duplicate entries + if (line.find(value) == std::string::npos) { + line += value + "|"; + } + } else if (action == "delete") { + // Remove the value from the callsign + size_t pos = line.find(value); + if (pos != std::string::npos) { + line.erase(pos, value.length() + 1); // +1 to remove the trailing '|' + } + } + } + } + if (!line.empty()) { + buffer << line << std::endl; + } + } + infile.close(); + } + + // If the property wasn't found and the action is "add", add it to the file + if (!propertyFound && action == "add") { + if (property == "currentstate") { + buffer << searchKey + "=" + value << std::endl; + } else if (property == "callsign") { + buffer << searchKey + "=" + value + "|" << std::endl; + } + } + + // Write the modified content back to the file + std::ofstream outfile(SYSTEM_MODE_FILE); + if (outfile.is_open()) { + outfile << buffer.str(); + outfile.close(); + LOGINFO("Updated file %s successfully.", SYSTEM_MODE_FILE); + } else { + LOGINFO("Failed to open file %s for writing.", SYSTEM_MODE_FILE); + } + } + bool getSystemModePropertyValue(const std::string& systemMode, const std::string& property, std::string& value) + { + if (systemMode.empty() || property.empty() ) { + LOGINFO("Error: systemMode or property is empty. systemMode: %s property: %s ",systemMode.c_str(),property.c_str()); + return false; + } + + std::ifstream infile(SYSTEM_MODE_FILE); + std::string line; + std::string searchKey = systemMode + "_" + property; + + if (!infile.is_open()) { + std::cerr << "Failed to open file: " << SYSTEM_MODE_FILE << std::endl; + return false; + } + + while (std::getline(infile, line)) { + // Check if the line starts with the search key + if (line.find(searchKey) == 0) { + // Extract the value after the '=' character + size_t pos = line.find('='); + if (pos != std::string::npos) { + value = line.substr(pos + 1); + infile.close(); + return true; + } + } + } + + infile.close(); + return false; + } } } From 8858b6dafe22845ed600cc8dc3604c61a5fa4d20 Mon Sep 17 00:00:00 2001 From: ramkumarpraba Date: Thu, 19 Sep 2024 15:06:00 +0000 Subject: [PATCH 06/21] RDK-51362 : System Mode Thunder Plugin to support ALLM Reason for change: New plugin SystemMode added Test Procedure: verify build success and basic test Risks: Low Priority: P1 Signed-off-by: ramkumar_prabaharan@comcast.com --- SystemMode/SystemModeImplementation.cpp | 4 ++++ Tests/L1Tests/tests/.test_HdmiCecSink.cpp.swo | Bin 16384 -> 0 bytes helpers/UtilsString.h | 22 ++++++++++-------- 3 files changed, 16 insertions(+), 10 deletions(-) delete mode 100644 Tests/L1Tests/tests/.test_HdmiCecSink.cpp.swo diff --git a/SystemMode/SystemModeImplementation.cpp b/SystemMode/SystemModeImplementation.cpp index 2c05d4af06..a3cf96f8c6 100755 --- a/SystemMode/SystemModeImplementation.cpp +++ b/SystemMode/SystemModeImplementation.cpp @@ -80,6 +80,10 @@ SystemModeImplementation::SystemModeImplementation() } } else { LOGINFO("File already exists: %s\n", SYSTEM_MODE_FILE); + + //set default value for each SystemMode + Utils::String::updateSystemModeFile("DEVICE_OPTIMIZE" ,"currentstate" , "VIDEO" , "checkandadd"); + for (int i =1 ;i <=SYSTEM_MODE_COUNT ; i++ ) { std::string value = ""; diff --git a/Tests/L1Tests/tests/.test_HdmiCecSink.cpp.swo b/Tests/L1Tests/tests/.test_HdmiCecSink.cpp.swo deleted file mode 100644 index 29af8fb8db49115cc3fe4dbed175248c93560b0c..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 16384 zcmeHOTZ|i58J^OXLV5v#gpiQXsf$+QmDk?QrA?jeN?v<5F|56g?aii5s$q8Kcz3k3 zGozXDZk8zRLnZo#5CS161zw>9@e;%vk+{4dp#l#`@K7Wk`cQ$y3lE64d}q!X`^?zu zln5k5W~6T?KDYlr-~XT6eXVW9jrs zmN(6Act4PN zzb76l(tDZwcSU|*r2iz7|BlFiUZg)J1SE1E6zQsX4>I{8Ie+C0iU3w#>*B=E-*$Omo#J3tk97Wm7D73IgkZNLVe2F?I~`;emi68Hu1GEf6E^r&@0*?T%KBOp@fDZ6y1TAg@J>a(ppnL;( z4yXfnz$fGMiz1G37t@eq9_>m;tM~POcT-b$4cBsLK%QJC?$B}kC@7v&rq#0tL{-Bm zz^4;xv(|0ttD8N&(Q94k>g`%fE0X19BC@?hmj-QPpB9T`ZjPw*fVxrBVkI&)waZ$& zuU~AmntHRXU)<<-);BMp){Utu+?<-ql=TmT)=tp!ELum0cBsZAUKCwhCZdzmJI3n& z=NRd1b?=oDQI&Jj+GuF?i?#Lztud94t8*`?rsswcF?Wq%o{TszagJjKnwB0B!M>a> zm_epsCd+tv%XXaAqXr!qLnl(JRrW0mEMKiQ-2-orstRL`JsWMkj_+>Nd0)4UV1IQO zHurs}g)er5K&0qhx?_hC4P>*(jp`*LiOBpa78NBH#s3_yT9-z{!0pn3TG#4p0sOC8 z-JwwvBpI$r)nZX{ZAtHa8iodZ#x>zTa3ZEUjep2Gwv5Q!rNMbl`X)Xrs(Wq}cuprk zeQM3E$fb1%leH%Q8)`R<$XIpI!ztRP)MZ@Xl=)%_$usZo9)&f_VjU;TL>=00bn2uY z6&J5Boji5=%+t@Dog8Y+VUvPHZegnLb*WE{h+58(%xc#8#IQ{q(6P7cF#Xs8Vf_wN zwN1kj>dLLbMk&vVyEnDd(Qe=!5;WcRYUZAH-K2hGd#)<^Q^L)7T&{aNl3+472)z9g z;qKFC4eFH4Szi3lsT};f;}1={)MSc{8Sp*FN%c8B(xx$x^knus^2jixB-*89AO1va zjC#6{S=V3+R9L#jXAiPXcZ~zv3y3#}%MU!Cx@0hPV_ga3g=__e9}?3s!mvDFQ4-m4 zao$@alF-}4Ot%M6=6qN=A?B~awoHA$R10WCcl-M z4`m%DXUdcgli4$LNK0WRkU3cALs=G{8Qm$#nYR@d&2-%b^tTeTx*i6kOCX)-z zwvDhOuaKI42v*4STnEn??a&FYk?s`=pia7H6IC+ak2?H8&Fm1$N}C+7qpDNJeYW

1(qmgsCJXhB z%}6(5;S+a!*Dk(hPv`acNAHs@2_`2q)(m`VAJ{ZrT*nJ}x>J}Ulj+{*KoeC0%w6|fPdmF{}12}@KfNcKo@uvI01YIXZzQHZvig= zSAov}f5qAUCE!KiQ^4B>A6gU5P^(qh3d7! zQu*|?Lg`u|9Gcj0g-DBnA-!2h;$!31_#r~;b~g|e-)L*2b6i=3uEv|)64Co=0TC+v z??NH0P~?d>&~#~Z7E7ckqirw#!NOEhoFvH#;t(j=YP33fZxg|=UXPy@k^=0Fvz}}E zN2(u29Rp!f78G1qIWU|dEfLn)0?4qxK)u1VB8fV3i(>-B4S;XPEmOpN<9mQHyN!6) zTIR2&JMhX^^lsyGb=(7VYwHX3jh5bBtC!bsW*r8!EblnSRv9sW7bWV3gS(Ap18fS# z3Q~g;tz1P&Jr1V(W>PZ=*d^(yZj}gB)khra(L9kkm4kY5_;-Uvp`}1~Hk?`R+c;9F zOZ=o>nU}+x>4RN~z;Pgaq>kKdCVoB<@w=h)wO(IeQzb6gsi#C5&0cMFU2Etmw=62k z`x-UWHMSjUiQ(~I8!s9cbNpaYm{%Mdrx;&e!Jm?=n&hqmS6U*K-@-I%S_?M?&33cj ztgSbn*BT`~P8#IK)Z20)%_gc8>VAXd5y@xm`er@^|i(+#hN$z4;RbH#s>uFta z5qGS@>8rVE#%sEEWE&2KtQALD8X-5QurDW!Yc#UutU$|{BI!0uqUgAbswv#Wwipps z1{+2h*D(<-o5O&qM9K2#PEfSl+1S#$y?(8)>G<1jtUkxtn%WG4xp!}7qn)u5lLRYq zwxCnmG_lgMZDx^m@8h8sV Date: Thu, 19 Sep 2024 15:06:00 +0000 Subject: [PATCH 07/21] RDK-51362 : System Mode Thunder Plugin to support ALLM Reason for change: New plugin SystemMode added Test Procedure: verify build success and basic test Risks: Low Priority: P1 Signed-off-by: ramkumar_prabaharan@comcast.com --- DisplaySettings/DisplaySettings.cpp | 145 +++++++++++------- SystemMode/SystemModeImplementation.cpp | 40 ++++- SystemMode/SystemModeImplementation.h | 2 +- Tests/L1Tests/tests/.test_HdmiCecSink.cpp.swo | Bin 16384 -> 0 bytes helpers/UtilsString.h | 22 +-- 5 files changed, 135 insertions(+), 74 deletions(-) delete mode 100644 Tests/L1Tests/tests/.test_HdmiCecSink.cpp.swo diff --git a/DisplaySettings/DisplaySettings.cpp b/DisplaySettings/DisplaySettings.cpp index 6fff2dddae..06b875931c 100644 --- a/DisplaySettings/DisplaySettings.cpp +++ b/DisplaySettings/DisplaySettings.cpp @@ -269,21 +269,6 @@ namespace WPEFramework { LOGINFO("Connect the COM-RPC socket\n"); _controller = _communicatorClient->Open(_T("org.rdk.SystemMode"), ~0, 3000); - if (_controller) - { - _remotStoreObject = _controller->QueryInterface(); - - if(_remotStoreObject) - { - _remotStoreObject->AddRef(); - } - } - else - { - LOGERR("Failed to create SystemMode Controller\n"); - } - - ASSERT (nullptr != _remotStoreObject); } @@ -618,6 +603,25 @@ namespace WPEFramework { } LOGWARN ("DisplaySettings::Initialize completes line:%d", __LINE__); + if (_controller) + { + _remotStoreObject = _controller->QueryInterface(); + + if(_remotStoreObject) + { + _remotStoreObject->AddRef(); + } + else + { + LOGERR("Failed to create SystemMode _controller\n"); + } + } + else + { + LOGERR("Failed to create SystemMode Controller\n"); + } + ASSERT (nullptr != _remotStoreObject); + if(_remotStoreObject) { @@ -635,54 +639,79 @@ namespace WPEFramework { } void DisplaySettings::Deinitialize(PluginHost::IShell* service) - { - if(_remotStoreObject) - { - const string& callsign = "org.rdk.DisplaySettings"; - const string& systemMode = "DEVICE_OPTIMIZE"; - _remotStoreObject->ClientDeactivated(callsign,systemMode); - } - else - { - Utils::String::updateSystemModeFile( "DEVICE_OPTIMIZE", "callsign", "org.rdk.DisplaySettings","delete") ; - } + { + LOGINFO("Enetering DisplaySettings::Deinitialize"); - LOGINFO("Enetering DisplaySettings::Deinitialize"); - { - std::unique_lock lock(DisplaySettings::_instance->m_sendMsgMutex); - DisplaySettings::_instance->m_sendMsgThreadExit = true; - DisplaySettings::_instance->m_sendMsgThreadRun = true; - DisplaySettings::_instance->m_sendMsgCV.notify_one(); - } - int count = 0; - while(audioPortInitActive && count < 20){ - sleep(100); - count++; - } - try - { - if (m_sendMsgThread.joinable()) - m_sendMsgThread.join(); - } - catch(const std::system_error& e) - { - LOGERR("system_error exception in thread join %s", e.what()); - } - catch(const std::exception& e) - { - LOGERR("exception in thread join %s", e.what()); - } + //During DisplaySettings plugin activation the SystemMode may not be added .But it will be added /tmp/SystemMode.txt . If after 5 min SystemMode got activated then SystemMode fill the client map from /tmp/SystemMode.txt. In this case if we deactivate DisplaySettings then _remotStoreObject will be null here . So we try to QueryInterface the ISystemMode one more time + if(_remotStoreObject == nullptr) + { + if (_controller) + { + _remotStoreObject = _controller->QueryInterface(); - stopCecTimeAndUnsubscribeEvent(); + if(_remotStoreObject) + { + _remotStoreObject->AddRef(); + } + else + { + LOGERR("Failed to create SystemMode _controller\n"); + } + } + else + { + LOGERR("Failed to create SystemMode Controller\n"); + } + } - DeinitializeIARM(); - DisplaySettings::_instance = nullptr; + ASSERT (nullptr != _remotStoreObject); - ASSERT(service == m_service); + if(_remotStoreObject) + { + const string& callsign = "org.rdk.DisplaySettings"; + const string& systemMode = "DEVICE_OPTIMIZE"; + _remotStoreObject->ClientDeactivated(callsign,systemMode); + } + else + { + Utils::String::updateSystemModeFile( "DEVICE_OPTIMIZE", "callsign", "org.rdk.DisplaySettings","delete") ; + } - m_service->Release(); - m_service = nullptr; - } + { + std::unique_lock lock(DisplaySettings::_instance->m_sendMsgMutex); + DisplaySettings::_instance->m_sendMsgThreadExit = true; + DisplaySettings::_instance->m_sendMsgThreadRun = true; + DisplaySettings::_instance->m_sendMsgCV.notify_one(); + } + int count = 0; + while(audioPortInitActive && count < 20){ + sleep(100); + count++; + } + try + { + if (m_sendMsgThread.joinable()) + m_sendMsgThread.join(); + } + catch(const std::system_error& e) + { + LOGERR("system_error exception in thread join %s", e.what()); + } + catch(const std::exception& e) + { + LOGERR("exception in thread join %s", e.what()); + } + + stopCecTimeAndUnsubscribeEvent(); + + DeinitializeIARM(); + DisplaySettings::_instance = nullptr; + + ASSERT(service == m_service); + + m_service->Release(); + m_service = nullptr; + } void DisplaySettings::InitializeIARM() { diff --git a/SystemMode/SystemModeImplementation.cpp b/SystemMode/SystemModeImplementation.cpp index 2c05d4af06..8815d0ff75 100755 --- a/SystemMode/SystemModeImplementation.cpp +++ b/SystemMode/SystemModeImplementation.cpp @@ -60,7 +60,9 @@ SystemModeImplementation::SystemModeImplementation() //set default value for each SystemMode SystemModeMap[DEVICE_OPTIMIZE] = "DEVICE_OPTIMIZE"; - + + SystemModeInterfaceMap["DEVICE_OPTIMIZE"]= DEVICE_OPTIMIZE; + deviceOptimizeStateMap[VIDEO] ="VIDEO"; deviceOptimizeStateMap[GAME] ="GAME"; @@ -80,6 +82,10 @@ SystemModeImplementation::SystemModeImplementation() } } else { LOGINFO("File already exists: %s\n", SYSTEM_MODE_FILE); + + //set default value for each SystemMode + Utils::String::updateSystemModeFile("DEVICE_OPTIMIZE" ,"currentstate" , "VIDEO" , "checkandadd"); + for (int i =1 ;i <=SYSTEM_MODE_COUNT ; i++ ) { std::string value = ""; @@ -157,8 +163,10 @@ Core::hresult SystemModeImplementation::RequestState(const SystemMode pSystemMod case DEVICE_OPTIMIZE:{ auto deviceOptimizeStateMapIterator = deviceOptimizeStateMap.find(pState); + if (deviceOptimizeStateMapIterator != deviceOptimizeStateMap.end()) { + std::string new_state = deviceOptimizeStateMapIterator->second; std::string old_state = ""; Utils::String::getSystemModePropertyValue(systemMode_str ,"currentstate" , old_state); @@ -238,17 +246,27 @@ Core::hresult SystemModeImplementation::GetState(const SystemMode pSystemMode, S } -uint32_t SystemModeImplementation::ClientActivated(const string& callsign , const string& __SystemMode) +uint32_t SystemModeImplementation::ClientActivated(const string& callsign , const string& systemMode) { - SystemMode pSystemMode = DEVICE_OPTIMIZE; + SystemMode pSystemMode ; + auto it = SystemModeInterfaceMap.find(systemMode); + + if (it != SystemModeInterfaceMap.end()) { + pSystemMode = it->second; + } else { + LOGERR("Invalid systemMode %s",systemMode.c_str()); + return 0; + } if (callsign != "") { + if (_controller) { _controller->Release(); _controller = nullptr; } + _controller = _communicatorClient->Open(_T(callsign), ~0, 3000); if (_controller) @@ -263,7 +281,9 @@ uint32_t SystemModeImplementation::ClientActivated(const string& callsign , cons std::map::iterator index(_clients.find(callsign)); - if (index == _clients.end()) { + { + + //Insert _clients detail directly to map .even some junk value is there for callsign it will be replaced by new entry _clients.insert({callsign,deviceOptimizeStateActivator}); Utils::String::updateSystemModeFile( SystemModeMap[pSystemMode], "callsign", callsign,"add") ; TRACE(Trace::Information, (_T("%s plugin is add to deviceOptimizeStateActivator map"), callsign.c_str())); @@ -300,7 +320,17 @@ uint32_t SystemModeImplementation::ClientActivated(const string& callsign , cons } uint32_t SystemModeImplementation::ClientDeactivated(const string& callsign ,const string& systemMode) { - SystemMode pSystemMode = DEVICE_OPTIMIZE; + SystemMode pSystemMode ; + + auto it = SystemModeInterfaceMap.find(systemMode); + + if (it != SystemModeInterfaceMap.end()) { + pSystemMode = it->second; + } else { + LOGERR("Invalid systemMode %s",systemMode.c_str()); + return 0; + } + _adminLock.Lock(); switch (pSystemMode) { case DEVICE_OPTIMIZE: diff --git a/SystemMode/SystemModeImplementation.h b/SystemMode/SystemModeImplementation.h index 66518cad24..3ca2020f37 100755 --- a/SystemMode/SystemModeImplementation.h +++ b/SystemMode/SystemModeImplementation.h @@ -69,7 +69,7 @@ namespace Plugin { std::map SystemModeMap; std::map deviceOptimizeStateMap; std::map SystemModesCurrentStateMap; - std::map SystemModeInterfaceMap; + std::map SystemModeInterfaceMap; bool stateRequested ; }; diff --git a/Tests/L1Tests/tests/.test_HdmiCecSink.cpp.swo b/Tests/L1Tests/tests/.test_HdmiCecSink.cpp.swo deleted file mode 100644 index 29af8fb8db49115cc3fe4dbed175248c93560b0c..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 16384 zcmeHOTZ|i58J^OXLV5v#gpiQXsf$+QmDk?QrA?jeN?v<5F|56g?aii5s$q8Kcz3k3 zGozXDZk8zRLnZo#5CS161zw>9@e;%vk+{4dp#l#`@K7Wk`cQ$y3lE64d}q!X`^?zu zln5k5W~6T?KDYlr-~XT6eXVW9jrs zmN(6Act4PN zzb76l(tDZwcSU|*r2iz7|BlFiUZg)J1SE1E6zQsX4>I{8Ie+C0iU3w#>*B=E-*$Omo#J3tk97Wm7D73IgkZNLVe2F?I~`;emi68Hu1GEf6E^r&@0*?T%KBOp@fDZ6y1TAg@J>a(ppnL;( z4yXfnz$fGMiz1G37t@eq9_>m;tM~POcT-b$4cBsLK%QJC?$B}kC@7v&rq#0tL{-Bm zz^4;xv(|0ttD8N&(Q94k>g`%fE0X19BC@?hmj-QPpB9T`ZjPw*fVxrBVkI&)waZ$& zuU~AmntHRXU)<<-);BMp){Utu+?<-ql=TmT)=tp!ELum0cBsZAUKCwhCZdzmJI3n& z=NRd1b?=oDQI&Jj+GuF?i?#Lztud94t8*`?rsswcF?Wq%o{TszagJjKnwB0B!M>a> zm_epsCd+tv%XXaAqXr!qLnl(JRrW0mEMKiQ-2-orstRL`JsWMkj_+>Nd0)4UV1IQO zHurs}g)er5K&0qhx?_hC4P>*(jp`*LiOBpa78NBH#s3_yT9-z{!0pn3TG#4p0sOC8 z-JwwvBpI$r)nZX{ZAtHa8iodZ#x>zTa3ZEUjep2Gwv5Q!rNMbl`X)Xrs(Wq}cuprk zeQM3E$fb1%leH%Q8)`R<$XIpI!ztRP)MZ@Xl=)%_$usZo9)&f_VjU;TL>=00bn2uY z6&J5Boji5=%+t@Dog8Y+VUvPHZegnLb*WE{h+58(%xc#8#IQ{q(6P7cF#Xs8Vf_wN zwN1kj>dLLbMk&vVyEnDd(Qe=!5;WcRYUZAH-K2hGd#)<^Q^L)7T&{aNl3+472)z9g z;qKFC4eFH4Szi3lsT};f;}1={)MSc{8Sp*FN%c8B(xx$x^knus^2jixB-*89AO1va zjC#6{S=V3+R9L#jXAiPXcZ~zv3y3#}%MU!Cx@0hPV_ga3g=__e9}?3s!mvDFQ4-m4 zao$@alF-}4Ot%M6=6qN=A?B~awoHA$R10WCcl-M z4`m%DXUdcgli4$LNK0WRkU3cALs=G{8Qm$#nYR@d&2-%b^tTeTx*i6kOCX)-z zwvDhOuaKI42v*4STnEn??a&FYk?s`=pia7H6IC+ak2?H8&Fm1$N}C+7qpDNJeYW

1(qmgsCJXhB z%}6(5;S+a!*Dk(hPv`acNAHs@2_`2q)(m`VAJ{ZrT*nJ}x>J}Ulj+{*KoeC0%w6|fPdmF{}12}@KfNcKo@uvI01YIXZzQHZvig= zSAov}f5qAUCE!KiQ^4B>A6gU5P^(qh3d7! zQu*|?Lg`u|9Gcj0g-DBnA-!2h;$!31_#r~;b~g|e-)L*2b6i=3uEv|)64Co=0TC+v z??NH0P~?d>&~#~Z7E7ckqirw#!NOEhoFvH#;t(j=YP33fZxg|=UXPy@k^=0Fvz}}E zN2(u29Rp!f78G1qIWU|dEfLn)0?4qxK)u1VB8fV3i(>-B4S;XPEmOpN<9mQHyN!6) zTIR2&JMhX^^lsyGb=(7VYwHX3jh5bBtC!bsW*r8!EblnSRv9sW7bWV3gS(Ap18fS# z3Q~g;tz1P&Jr1V(W>PZ=*d^(yZj}gB)khra(L9kkm4kY5_;-Uvp`}1~Hk?`R+c;9F zOZ=o>nU}+x>4RN~z;Pgaq>kKdCVoB<@w=h)wO(IeQzb6gsi#C5&0cMFU2Etmw=62k z`x-UWHMSjUiQ(~I8!s9cbNpaYm{%Mdrx;&e!Jm?=n&hqmS6U*K-@-I%S_?M?&33cj ztgSbn*BT`~P8#IK)Z20)%_gc8>VAXd5y@xm`er@^|i(+#hN$z4;RbH#s>uFta z5qGS@>8rVE#%sEEWE&2KtQALD8X-5QurDW!Yc#UutU$|{BI!0uqUgAbswv#Wwipps z1{+2h*D(<-o5O&qM9K2#PEfSl+1S#$y?(8)>G<1jtUkxtn%WG4xp!}7qn)u5lLRYq zwxCnmG_lgMZDx^m@8h8sV Date: Fri, 20 Sep 2024 12:32:53 +0000 Subject: [PATCH 08/21] RDK-51362 : System Mode Thunder Plugin to support ALLM Reason for change: New plugin SystemMode added Test Procedure: verify build success and basic test Risks: Low Priority: P1 Signed-off-by: ramkumar_prabaharan@comcast.com --- SystemMode/SystemModeImplementation.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/SystemMode/SystemModeImplementation.cpp b/SystemMode/SystemModeImplementation.cpp index 8815d0ff75..2ac8034f5c 100755 --- a/SystemMode/SystemModeImplementation.cpp +++ b/SystemMode/SystemModeImplementation.cpp @@ -82,9 +82,14 @@ SystemModeImplementation::SystemModeImplementation() } } else { LOGINFO("File already exists: %s\n", SYSTEM_MODE_FILE); - - //set default value for each SystemMode - Utils::String::updateSystemModeFile("DEVICE_OPTIMIZE" ,"currentstate" , "VIDEO" , "checkandadd"); + + std::string currentstate =""; + Utils::String::getSystemModePropertyValue("DEVICE_OPTIMIZE" ,"currentstate",currentstate); + if(currentstate == "") + { + //File already exists but currentstate not set then set default value + Utils::String::updateSystemModeFile("DEVICE_OPTIMIZE" ,"currentstate" , "VIDEO" , "add"); + } for (int i =1 ;i <=SYSTEM_MODE_COUNT ; i++ ) { From 7656fdb53a96224ca3eae3928593321f6d04ef4c Mon Sep 17 00:00:00 2001 From: ramkumarpraba Date: Mon, 23 Sep 2024 20:54:47 +0000 Subject: [PATCH 09/21] RDK-51362 : System Mode Thunder Plugin to support ALLM Reason for change: New plugin SystemMode added Test Procedure: verify build success and basic test Risks: Low Priority: P1 Signed-off-by: ramkumar_prabaharan@comcast.com --- SystemMode/SystemModeImplementation.cpp | 16 ++- SystemMode/SystemModeImplementation.h | 4 +- .../L2TestsPlugin/tests/SystemMode_L2Test.cpp | 125 +++++++++++++++--- 3 files changed, 123 insertions(+), 22 deletions(-) diff --git a/SystemMode/SystemModeImplementation.cpp b/SystemMode/SystemModeImplementation.cpp index 2ac8034f5c..1803253c65 100755 --- a/SystemMode/SystemModeImplementation.cpp +++ b/SystemMode/SystemModeImplementation.cpp @@ -156,10 +156,11 @@ SystemModeImplementation::~SystemModeImplementation() } -Core::hresult SystemModeImplementation::RequestState(const SystemMode pSystemMode, const State pState) +Core::hresult SystemModeImplementation::RequestState(const SystemMode pSystemMode, const State pState , SuccessResult& successResult) { auto SystemModeMapIterator = SystemModeMap.find(pSystemMode); Core::hresult result = Core::ERROR_NONE; + successResult.success = true; if(SystemModeMapIterator != SystemModeMap.end()) { @@ -185,11 +186,13 @@ Core::hresult SystemModeImplementation::RequestState(const SystemMode pSystemMod } stateRequested =true; + successResult.success = true; result = Core::ERROR_NONE; } else { LOGERR("Invalid state %d for systemMode %s" ,pState,systemMode_str.c_str()); + successResult.success = false; result = Core::ERROR_GENERAL; } break; @@ -197,6 +200,7 @@ Core::hresult SystemModeImplementation::RequestState(const SystemMode pSystemMod default: { LOGERR("Invalid systemMode %s",systemMode_str.c_str()); + successResult.success = false; result = Core::ERROR_GENERAL; break; } @@ -206,15 +210,17 @@ Core::hresult SystemModeImplementation::RequestState(const SystemMode pSystemMod else { LOGERR("Invalid systemMode %d",pSystemMode); + successResult.success = false; result = Core::ERROR_GENERAL; } return result; } -Core::hresult SystemModeImplementation::GetState(const SystemMode pSystemMode, State &pState )const +Core::hresult SystemModeImplementation::GetState(const SystemMode pSystemMode, State &pState , SuccessResult& successResult)const { Core::hresult result = Core::ERROR_NONE; + successResult.success = true; auto SystemModeMapIterator = SystemModeMap.find(pSystemMode); if(SystemModeMapIterator != SystemModeMap.end()) { @@ -231,12 +237,14 @@ Core::hresult SystemModeImplementation::GetState(const SystemMode pSystemMode, S break; } } + successResult.success = true; result = Core::ERROR_NONE; break; } default: { LOGERR("Invalid systemMode %d",static_cast(pSystemMode)); + successResult.success = false; result = Core::ERROR_GENERAL; break; } @@ -245,6 +253,7 @@ Core::hresult SystemModeImplementation::GetState(const SystemMode pSystemMode, S else { LOGERR("Invalid systemMode %d",static_cast(pSystemMode)); + successResult.success = false; return Core::ERROR_GENERAL; } return result; @@ -297,7 +306,8 @@ uint32_t SystemModeImplementation::ClientActivated(const string& callsign , cons if(stateRequested) { State state ; - if(GetState(pSystemMode, state ) == Core::ERROR_NONE) + SuccessResult successResult; + if(GetState(pSystemMode, state ,successResult ) == Core::ERROR_NONE) { std::string state_str = deviceOptimizeStateMap[state]; deviceOptimizeStateActivator->Request(state_str) ; diff --git a/SystemMode/SystemModeImplementation.h b/SystemMode/SystemModeImplementation.h index 3ca2020f37..d2eb46efe2 100755 --- a/SystemMode/SystemModeImplementation.h +++ b/SystemMode/SystemModeImplementation.h @@ -54,8 +54,8 @@ namespace Plugin { END_INTERFACE_MAP public: - Core::hresult RequestState(const SystemMode systemMode, const State state) override; - Core::hresult GetState(const SystemMode systemMode, State &state )const override; + Core::hresult RequestState(const SystemMode systemMode, const State state ,SuccessResult& successResult) override; + Core::hresult GetState(const SystemMode systemMode, State &state, SuccessResult& successResult)const override; virtual uint32_t ClientActivated(const string& callsign ,const string& systemMode) override ; virtual uint32_t ClientDeactivated(const string& callsign, const string& systemMode) override ; diff --git a/Tests/L2Tests/L2TestsPlugin/tests/SystemMode_L2Test.cpp b/Tests/L2Tests/L2TestsPlugin/tests/SystemMode_L2Test.cpp index b2486ad1e1..0a35079894 100755 --- a/Tests/L2Tests/L2TestsPlugin/tests/SystemMode_L2Test.cpp +++ b/Tests/L2Tests/L2TestsPlugin/tests/SystemMode_L2Test.cpp @@ -8,7 +8,7 @@ #include #include "HdmiCec.h" -#define TEST_LOG(x, ...) fprintf(stderr, "\033[1;32m[%s:%d](%s)" x "\n\033[0m", __FILE__, __LINE__, __FUNCTION__, getpid(), gettid(), ##__VA_ARGS__); fflush(stderr); +#define TEST_LOG(x, ...) fprintf( stderr, "\033[1;32m[%s:%d](%s)" x "\n\033[0m", __FILE__, __LINE__, __FUNCTION__, getpid(), gettid(), ##__VA_ARGS__); fflush(stderr); #define JSON_TIMEOUT (1000) #define SYSTEMMODE_CALLSIGN _T("org.rdk.SystemMode") @@ -36,7 +36,7 @@ class SystemModeTest : public L2TestMocks { SystemModeTest(); protected: - /** @brief Pointer to the IShell interface */ + /** @brief Pointer to the IShell interface */ PluginHost::IShell *m_controller_usersettings; /** @brief Pointer to the IUserSettings interface */ @@ -65,7 +65,7 @@ SystemModeTest::~SystemModeTest() EXPECT_EQ(Core::ERROR_NONE, status); } -TEST_F(SystemModeTest,GetStatedefault) +TEST_F(SystemModeTest,getStatedefault) { JSONRPC::LinkType jsonrpc(SYSTEMMODE_CALLSIGN,SYSTEMMODEL2TEST_CALLSIGN); uint32_t status = Core::ERROR_GENERAL; @@ -74,13 +74,16 @@ TEST_F(SystemModeTest,GetStatedefault) std::string message; std::string reply; - params["systemMode"] = "DeviceOptimize"; - status = InvokeServiceMethod("org.rdk.SystemMode", "GetState", params, result); - EXPECT_EQ(Core::ERROR_NONE, status); + params["systemMode"] = "device_optimize"; + status = InvokeServiceMethod("org.rdk.SystemMode", "getState", params, result); + EXPECT_EQ(Core::ERROR_NONE, status); + if (result.HasLabel("state")) { + EXPECT_STREQ("VIDEO", result["state"].String().c_str()); + } } -TEST_F(SystemModeTest,RequestStateGame) +TEST_F(SystemModeTest,getStateNegativeCase) { JSONRPC::LinkType jsonrpc(SYSTEMMODE_CALLSIGN,SYSTEMMODEL2TEST_CALLSIGN); uint32_t status = Core::ERROR_GENERAL; @@ -88,9 +91,35 @@ TEST_F(SystemModeTest,RequestStateGame) JsonObject result; std::string message; std::string reply; +//Case 1 empty systemMode + params["systemMode"] = ""; + status = InvokeServiceMethod("org.rdk.SystemMode", "getState", params, result); + EXPECT_FALSE(result["success"].Boolean()); + if (result.HasLabel("error")) { + EXPECT_STREQ("{\"code\":1,\"message\":\"ERROR_GENERAL\"}", result["error"].String().c_str()); + } + +//Case 2 Invalid systemMode + params["systemMode"] = "abc"; + status = InvokeServiceMethod("org.rdk.SystemMode", "getState", params, result); + EXPECT_FALSE(result["success"].Boolean()); + if (result.HasLabel("error")) { + EXPECT_STREQ("{\"code\":1,\"message\":\"ERROR_GENERAL\"}", result["error"].String().c_str()); + } + +} - params["systemMode"] = "DeviceOptimize"; - params["state"] = "Game"; +TEST_F(SystemModeTest,requestStateGame) +{ + JSONRPC::LinkType jsonrpc(SYSTEMMODE_CALLSIGN,SYSTEMMODEL2TEST_CALLSIGN); + uint32_t status = Core::ERROR_GENERAL; + JsonObject params; + JsonObject result; + std::string message; + std::string reply; + + params["systemMode"] = "device_optimize"; + params["state"] = "game"; EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .Times(::testing::AnyNumber()) .WillRepeatedly( @@ -102,15 +131,20 @@ TEST_F(SystemModeTest,RequestStateGame) return IARM_RESULT_SUCCESS; }); - status = InvokeServiceMethod("org.rdk.SystemMode", "RequestState", params, result); + status = InvokeServiceMethod("org.rdk.SystemMode", "requestState", params, result); EXPECT_EQ(Core::ERROR_NONE, status); - - status = InvokeServiceMethod("org.rdk.SystemMode", "GetState", params, result); + EXPECT_TRUE(result["success"].Boolean()); + + status = InvokeServiceMethod("org.rdk.SystemMode", "getState", params, result); EXPECT_EQ(Core::ERROR_NONE, status); + if (result.HasLabel("state")) { + EXPECT_STREQ("GAME", result["state"].String().c_str()); + } + } -TEST_F(SystemModeTest,RequestStateVideo) +TEST_F(SystemModeTest,requestStateVideo) { JSONRPC::LinkType jsonrpc(SYSTEMMODE_CALLSIGN,SYSTEMMODEL2TEST_CALLSIGN); uint32_t status = Core::ERROR_GENERAL; @@ -119,8 +153,9 @@ TEST_F(SystemModeTest,RequestStateVideo) std::string message; std::string reply; - params["systemMode"] = "DeviceOptimize"; - params["state"] = "Video"; + params["systemMode"] = "device_optimize"; + params["state"] = "video"; + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .Times(::testing::AnyNumber()) .WillRepeatedly( @@ -132,11 +167,67 @@ TEST_F(SystemModeTest,RequestStateVideo) return IARM_RESULT_SUCCESS; }); - status = InvokeServiceMethod("org.rdk.SystemMode", "RequestState", params, result); + status = InvokeServiceMethod("org.rdk.SystemMode", "requestState", params, result); EXPECT_EQ(Core::ERROR_NONE, status); + EXPECT_TRUE(result["success"].Boolean()); - status = InvokeServiceMethod("org.rdk.SystemMode", "GetState", params, result); + status = InvokeServiceMethod("org.rdk.SystemMode", "getState", params, result); EXPECT_EQ(Core::ERROR_NONE, status); + if (result.HasLabel("state")) { + EXPECT_STREQ("VIDEO", result["state"].String().c_str()); + } + +} + +TEST_F(SystemModeTest,requestStateNegativeCase) +{ + JSONRPC::LinkType jsonrpc(SYSTEMMODE_CALLSIGN,SYSTEMMODEL2TEST_CALLSIGN); + uint32_t status = Core::ERROR_GENERAL; + JsonObject params; + JsonObject result; + std::string message; + std::string reply; + +// case1 empty systemMode and state + params["systemMode"] = ""; + params["state"] = ""; + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) + .Times(::testing::AnyNumber()) + .WillRepeatedly( + [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { + EXPECT_EQ(string(ownerName), string(_T(IARM_BUS_MFRLIB_NAME))); + EXPECT_EQ(string(methodName), string(_T(IARM_BUS_DSMGR_API_dsSetAllmEnabled))); + auto param = static_cast(arg); + param->result =dsERR_NONE; + return IARM_RESULT_SUCCESS; + }); + + status = InvokeServiceMethod("org.rdk.SystemMode", "requestState", params, result); + if (result.HasLabel("error")) { + EXPECT_STREQ("{\"code\":1,\"message\":\"ERROR_GENERAL\"}", result["error"].String().c_str()); + } +// Case 2 Invalid systemMode and state + + params["systemMode"] = "abc"; + params["state"] = "bcd"; + EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) + .Times(::testing::AnyNumber()) + .WillRepeatedly( + [](const char* ownerName, const char* methodName, void* arg, size_t argLen) { + EXPECT_EQ(string(ownerName), string(_T(IARM_BUS_MFRLIB_NAME))); + EXPECT_EQ(string(methodName), string(_T(IARM_BUS_DSMGR_API_dsSetAllmEnabled))); + auto param = static_cast(arg); + param->result =dsERR_NONE; + return IARM_RESULT_SUCCESS; + }); + + status = InvokeServiceMethod("org.rdk.SystemMode", "requestState", params, result); + EXPECT_FALSE(result["success"].Boolean()); + if (result.HasLabel("error")) { + EXPECT_STREQ("{\"code\":1,\"message\":\"ERROR_GENERAL\"}", result["error"].String().c_str()); + } + } + From dfad491d521f8bf1bf5a7b8de5ac17a9230ee048 Mon Sep 17 00:00:00 2001 From: ramkumarpraba <103193010+ramkumarpraba@users.noreply.github.com> Date: Tue, 24 Sep 2024 02:35:33 +0530 Subject: [PATCH 10/21] Update RDK-51362-System-Mode-Thunder-Plugin.patch --- ...RDK-51362-System-Mode-Thunder-Plugin.patch | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/Tests/L2Tests/patches/RDK-51362-System-Mode-Thunder-Plugin.patch b/Tests/L2Tests/patches/RDK-51362-System-Mode-Thunder-Plugin.patch index 5ee09042da..9404ff7789 100644 --- a/Tests/L2Tests/patches/RDK-51362-System-Mode-Thunder-Plugin.patch +++ b/Tests/L2Tests/patches/RDK-51362-System-Mode-Thunder-Plugin.patch @@ -42,10 +42,10 @@ index 0000000..168c0e0 +} diff --git a/interfaces/ISystemMode.h b/interfaces/ISystemMode.h new file mode 100644 -index 0000000..dea68e6 +index 0000000..29b9f4e --- /dev/null +++ b/interfaces/ISystemMode.h -@@ -0,0 +1,72 @@ +@@ -0,0 +1,75 @@ +/* + * If not stated otherwise in this file or this component's LICENSE file the + * following copyright and licenses apply: @@ -70,7 +70,7 @@ index 0000000..dea68e6 + +namespace WPEFramework { +namespace Exchange { -+ // @json ++ // @json @text:keep +struct EXTERNAL ISystemMode : virtual public Core::IUnknown { + enum { ID = ID_SYSTEM_MODE }; + @@ -88,28 +88,31 @@ index 0000000..dea68e6 + // next system mode states... + }; + -+ // @alt RequestState ++ struct EXTERNAL SuccessResult { ++ bool success; ++ }; ++ // @text requestState + // @brief Requests a new system mode state in the device. Thunder components asynchronously reconfigure themselves so the caller cannot be guaranteed a full state transition upon return. + // @param[in] systemMode The system mode. + // @param[in] state The requested state. + // @returns Core::hresult -+ virtual Core::hresult RequestState(const SystemMode systemMode /* @in @text systemMode */ , const State state /* @in @text state */) = 0; ++ virtual Core::hresult RequestState(const SystemMode systemMode /* @in @text systemMode */ , const State state /* @in @text state */ , SuccessResult& successResult /* @out */) = 0; + -+ // @alt GetState ++ // @text getState + // @brief Gets the current state for a given system property + // @param[in] systemMode The system mode to get the state of. + // @param[out] state Receives the state of the system mode. + // @returns Core::hresult -+ virtual Core::hresult GetState(const SystemMode systemMode /* @in @text systemMode */ , State &state /* @out @text state */) const = 0; ++ virtual Core::hresult GetState(const SystemMode systemMode /* @in @text systemMode */ , State &state /* @out @text state */ , SuccessResult& successResult /* @out */) const = 0; + -+ // @alt ClientActivated ++ // @text clientActivated + // @brief To put client plugin entry in map. + // @param[in] callsign callsign of client. + // @param[in] systemMode The system mode. + // @returns uint32_t + virtual uint32_t ClientActivated(const string& callsign /* @in @text callsign*/ ,const string& systemMode) = 0; + -+ // @alt ClientDeactivated ++ // @text clientDeactivated + // @brief To put client plugin entry in map. + // @param[in] callsign callsign of client. + // @param[in] systemMode The system mode. @@ -118,7 +121,6 @@ index 0000000..dea68e6 +}; +} // namespace Exchange +} // namespace WPEFramework - diff --git a/interfaces/Ids.h b/interfaces/Ids.h index e66cb22..7d53320 100644 --- a/interfaces/Ids.h From 15f428d00da111d6fe9aab6f386f72d789897758 Mon Sep 17 00:00:00 2001 From: ramkumarpraba <103193010+ramkumarpraba@users.noreply.github.com> Date: Tue, 24 Sep 2024 02:48:41 +0530 Subject: [PATCH 11/21] Update SystemMode_L2Test.cpp --- Tests/L2Tests/L2TestsPlugin/tests/SystemMode_L2Test.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Tests/L2Tests/L2TestsPlugin/tests/SystemMode_L2Test.cpp b/Tests/L2Tests/L2TestsPlugin/tests/SystemMode_L2Test.cpp index 0a35079894..e5613258dd 100755 --- a/Tests/L2Tests/L2TestsPlugin/tests/SystemMode_L2Test.cpp +++ b/Tests/L2Tests/L2TestsPlugin/tests/SystemMode_L2Test.cpp @@ -118,8 +118,7 @@ TEST_F(SystemModeTest,requestStateGame) std::string message; std::string reply; - params["systemMode"] = "device_optimize"; - params["state"] = "game"; + params["systemMode"] = "device_optimize"; EXPECT_CALL(*p_iarmBusImplMock, IARM_Bus_Call) .Times(::testing::AnyNumber()) .WillRepeatedly( @@ -131,6 +130,7 @@ TEST_F(SystemModeTest,requestStateGame) return IARM_RESULT_SUCCESS; }); + params["state"] = "game"; status = InvokeServiceMethod("org.rdk.SystemMode", "requestState", params, result); EXPECT_EQ(Core::ERROR_NONE, status); EXPECT_TRUE(result["success"].Boolean()); From 7e28bd9ee34cf6189189c23f92c958a12964e467 Mon Sep 17 00:00:00 2001 From: ramkumarpraba Date: Tue, 24 Sep 2024 11:53:59 +0000 Subject: [PATCH 12/21] RDK-51362 : System Mode Thunder Plugin to support ALLM Reason for change: New plugin SystemMode added Test Procedure: verify build success and basic test Risks: Low Priority: P1 Signed-off-by: ramkumar_prabaharan@comcast.com --- SystemMode/SystemModeImplementation.cpp | 6 ++---- SystemMode/SystemModeImplementation.h | 1 - 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/SystemMode/SystemModeImplementation.cpp b/SystemMode/SystemModeImplementation.cpp index 1803253c65..2a39e3dae0 100755 --- a/SystemMode/SystemModeImplementation.cpp +++ b/SystemMode/SystemModeImplementation.cpp @@ -179,12 +179,10 @@ Core::hresult SystemModeImplementation::RequestState(const SystemMode pSystemMod for (auto it = _clients.begin(); it != _clients.end(); ++it) { if (it->second) { // Check if the pointer is not null it->second->Request(new_state); // Call Request() on the object - SystemModesCurrentStateMap[pSystemMode] = pState; - Utils::String::updateSystemModeFile(systemMode_str,"currentstate",new_state,"add"); - LOGINFO("SystemMode state change from %s to new %s" ,old_state.c_str(),new_state.c_str()); } } - + Utils::String::updateSystemModeFile(systemMode_str,"currentstate",new_state,"add"); + LOGINFO("SystemMode state change from %s to new %s" ,old_state.c_str(),new_state.c_str()); stateRequested =true; successResult.success = true; result = Core::ERROR_NONE; diff --git a/SystemMode/SystemModeImplementation.h b/SystemMode/SystemModeImplementation.h index d2eb46efe2..4d2585aacb 100755 --- a/SystemMode/SystemModeImplementation.h +++ b/SystemMode/SystemModeImplementation.h @@ -68,7 +68,6 @@ namespace Plugin { PluginHost::IShell *_controller; std::map SystemModeMap; std::map deviceOptimizeStateMap; - std::map SystemModesCurrentStateMap; std::map SystemModeInterfaceMap; bool stateRequested ; From aed8556c98277da7e696f30a716dca01fec20363 Mon Sep 17 00:00:00 2001 From: ramkumarpraba Date: Tue, 24 Sep 2024 12:17:40 +0000 Subject: [PATCH 13/21] RDK-51362 : System Mode Thunder Plugin to support ALLM Reason for change: @text added in ISystemMode Test Procedure: verify build success and basic test Risks: Low Priority: P1 Signed-off-by: ramkumar_prabaharan@comcast.com --- Tests/L2Tests/L2TestsPlugin/tests/SystemMode_L2Test.cpp | 6 +++--- .../patches/RDK-51362-System-Mode-Thunder-Plugin.patch | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Tests/L2Tests/L2TestsPlugin/tests/SystemMode_L2Test.cpp b/Tests/L2Tests/L2TestsPlugin/tests/SystemMode_L2Test.cpp index e5613258dd..eaec206f3a 100755 --- a/Tests/L2Tests/L2TestsPlugin/tests/SystemMode_L2Test.cpp +++ b/Tests/L2Tests/L2TestsPlugin/tests/SystemMode_L2Test.cpp @@ -78,7 +78,7 @@ TEST_F(SystemModeTest,getStatedefault) status = InvokeServiceMethod("org.rdk.SystemMode", "getState", params, result); EXPECT_EQ(Core::ERROR_NONE, status); if (result.HasLabel("state")) { - EXPECT_STREQ("VIDEO", result["state"].String().c_str()); + EXPECT_STREQ("video", result["state"].String().c_str()); } } @@ -138,7 +138,7 @@ TEST_F(SystemModeTest,requestStateGame) status = InvokeServiceMethod("org.rdk.SystemMode", "getState", params, result); EXPECT_EQ(Core::ERROR_NONE, status); if (result.HasLabel("state")) { - EXPECT_STREQ("GAME", result["state"].String().c_str()); + EXPECT_STREQ("game", result["state"].String().c_str()); } @@ -174,7 +174,7 @@ TEST_F(SystemModeTest,requestStateVideo) status = InvokeServiceMethod("org.rdk.SystemMode", "getState", params, result); EXPECT_EQ(Core::ERROR_NONE, status); if (result.HasLabel("state")) { - EXPECT_STREQ("VIDEO", result["state"].String().c_str()); + EXPECT_STREQ("video", result["state"].String().c_str()); } } diff --git a/Tests/L2Tests/patches/RDK-51362-System-Mode-Thunder-Plugin.patch b/Tests/L2Tests/patches/RDK-51362-System-Mode-Thunder-Plugin.patch index 9404ff7789..eaf2a1ae93 100644 --- a/Tests/L2Tests/patches/RDK-51362-System-Mode-Thunder-Plugin.patch +++ b/Tests/L2Tests/patches/RDK-51362-System-Mode-Thunder-Plugin.patch @@ -76,14 +76,14 @@ index 0000000..29b9f4e + + /// Enumeration of system modes. + enum SystemMode : uint8_t { -+ DEVICE_OPTIMIZE = 1 ++ DEVICE_OPTIMIZE = 1 /* @text: device_optimize */ + }; + + /// Enumeration of states for all system modes. + enum State : uint32_t { + // DEVICE_OPTIMIZE states -+ VIDEO = (DEVICE_OPTIMIZE << 24) | 1 , -+ GAME = (DEVICE_OPTIMIZE << 24) | 2 , ++ VIDEO = (DEVICE_OPTIMIZE << 24) | 1 /* @text: video */, ++ GAME = (DEVICE_OPTIMIZE << 24) | 2 /* @text: game */, + + // next system mode states... + }; From ac4e53f27f9890f9875b4cb98b99892097758498 Mon Sep 17 00:00:00 2001 From: ramkumarpraba <103193010+ramkumarpraba@users.noreply.github.com> Date: Tue, 24 Sep 2024 22:03:29 +0530 Subject: [PATCH 14/21] RDK-51362 : System Mode Thunder Plugin to support ALLM Reason for change: update ISystemMode.h Test Procedure: verify build success and basic test Risks: Low Priority: P1 Signed-off-by: ramkumar_prabaharan@comcast.com --- .../patches/RDK-51362-System-Mode-Thunder-Plugin.patch | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Tests/L2Tests/patches/RDK-51362-System-Mode-Thunder-Plugin.patch b/Tests/L2Tests/patches/RDK-51362-System-Mode-Thunder-Plugin.patch index eaf2a1ae93..0233ab7544 100644 --- a/Tests/L2Tests/patches/RDK-51362-System-Mode-Thunder-Plugin.patch +++ b/Tests/L2Tests/patches/RDK-51362-System-Mode-Thunder-Plugin.patch @@ -91,6 +91,10 @@ index 0000000..29b9f4e + struct EXTERNAL SuccessResult { + bool success; + }; ++ struct EXTERNAL GetStateResult { ++ State state ; ++ bool success; ++ }; + // @text requestState + // @brief Requests a new system mode state in the device. Thunder components asynchronously reconfigure themselves so the caller cannot be guaranteed a full state transition upon return. + // @param[in] systemMode The system mode. @@ -103,7 +107,7 @@ index 0000000..29b9f4e + // @param[in] systemMode The system mode to get the state of. + // @param[out] state Receives the state of the system mode. + // @returns Core::hresult -+ virtual Core::hresult GetState(const SystemMode systemMode /* @in @text systemMode */ , State &state /* @out @text state */ , SuccessResult& successResult /* @out */) const = 0; ++ virtual Core::hresult GetState(const SystemMode systemMode /* @in @text systemMode */ , GetStateResult& result /* @out */) const = 0; + + // @text clientActivated + // @brief To put client plugin entry in map. From 857d6a82b8469206da4e202218ebbf98cbaedd87 Mon Sep 17 00:00:00 2001 From: ramkumarpraba Date: Tue, 24 Sep 2024 16:49:50 +0000 Subject: [PATCH 15/21] RDK-51362 : System Mode Thunder Plugin to support ALLM Reason for change: Testcase update Test Procedure: verify build success and basic test Risks: Low Priority: P1 Signed-off-by: ramkumar_prabaharan@comcast.com --- SystemMode/SystemModeImplementation.cpp | 10 ++++++---- SystemMode/SystemModeImplementation.h | 2 +- .../L2Tests/L2TestsPlugin/tests/SystemMode_L2Test.cpp | 9 ++++++++- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/SystemMode/SystemModeImplementation.cpp b/SystemMode/SystemModeImplementation.cpp index 2a39e3dae0..e26175e7bc 100755 --- a/SystemMode/SystemModeImplementation.cpp +++ b/SystemMode/SystemModeImplementation.cpp @@ -214,7 +214,7 @@ Core::hresult SystemModeImplementation::RequestState(const SystemMode pSystemMod return result; } -Core::hresult SystemModeImplementation::GetState(const SystemMode pSystemMode, State &pState , SuccessResult& successResult)const +Core::hresult SystemModeImplementation::GetState(const SystemMode pSystemMode, GetStateResult& successResult)const { Core::hresult result = Core::ERROR_NONE; @@ -231,12 +231,13 @@ Core::hresult SystemModeImplementation::GetState(const SystemMode pSystemMode, S // Iterate over the map to find the corresponding enum value for (const auto& pair : deviceOptimizeStateMap) { if (pair.second == value) { - pState = pair.first; + successResult.state = pair.first; break; } } successResult.success = true; result = Core::ERROR_NONE; + std::cout<<"RamTesting successResult.state :"<< successResult.state <<"successResult.success"<Request(state_str) ; } diff --git a/SystemMode/SystemModeImplementation.h b/SystemMode/SystemModeImplementation.h index 4d2585aacb..36afb84b3a 100755 --- a/SystemMode/SystemModeImplementation.h +++ b/SystemMode/SystemModeImplementation.h @@ -55,7 +55,7 @@ namespace Plugin { public: Core::hresult RequestState(const SystemMode systemMode, const State state ,SuccessResult& successResult) override; - Core::hresult GetState(const SystemMode systemMode, State &state, SuccessResult& successResult)const override; + Core::hresult GetState(const SystemMode systemMode , GetStateResult& successResult)const override; virtual uint32_t ClientActivated(const string& callsign ,const string& systemMode) override ; virtual uint32_t ClientDeactivated(const string& callsign, const string& systemMode) override ; diff --git a/Tests/L2Tests/L2TestsPlugin/tests/SystemMode_L2Test.cpp b/Tests/L2Tests/L2TestsPlugin/tests/SystemMode_L2Test.cpp index eaec206f3a..18bdf4aa5c 100755 --- a/Tests/L2Tests/L2TestsPlugin/tests/SystemMode_L2Test.cpp +++ b/Tests/L2Tests/L2TestsPlugin/tests/SystemMode_L2Test.cpp @@ -79,8 +79,15 @@ TEST_F(SystemModeTest,getStatedefault) EXPECT_EQ(Core::ERROR_NONE, status); if (result.HasLabel("state")) { EXPECT_STREQ("video", result["state"].String().c_str()); + std::string state_str = result["state"].String(); + std::cout<<"RamTest success 1:" < Date: Tue, 24 Sep 2024 22:41:58 +0530 Subject: [PATCH 16/21] Update RDK-51362-System-Mode-Thunder-Plugin.patch --- ...RDK-51362-System-Mode-Thunder-Plugin.patch | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/Tests/L2Tests/patches/RDK-51362-System-Mode-Thunder-Plugin.patch b/Tests/L2Tests/patches/RDK-51362-System-Mode-Thunder-Plugin.patch index 0233ab7544..804daf82ed 100644 --- a/Tests/L2Tests/patches/RDK-51362-System-Mode-Thunder-Plugin.patch +++ b/Tests/L2Tests/patches/RDK-51362-System-Mode-Thunder-Plugin.patch @@ -42,10 +42,10 @@ index 0000000..168c0e0 +} diff --git a/interfaces/ISystemMode.h b/interfaces/ISystemMode.h new file mode 100644 -index 0000000..29b9f4e +index 0000000..98637d4 --- /dev/null +++ b/interfaces/ISystemMode.h -@@ -0,0 +1,75 @@ +@@ -0,0 +1,79 @@ +/* + * If not stated otherwise in this file or this component's LICENSE file the + * following copyright and licenses apply: @@ -76,24 +76,24 @@ index 0000000..29b9f4e + + /// Enumeration of system modes. + enum SystemMode : uint8_t { -+ DEVICE_OPTIMIZE = 1 /* @text: device_optimize */ ++ DEVICE_OPTIMIZE = 1 /* @text: device_optimize */ + }; + + /// Enumeration of states for all system modes. + enum State : uint32_t { -+ // DEVICE_OPTIMIZE states -+ VIDEO = (DEVICE_OPTIMIZE << 24) | 1 /* @text: video */, -+ GAME = (DEVICE_OPTIMIZE << 24) | 2 /* @text: game */, ++ // DEVICE_OPTIMIZE states ++ VIDEO = (DEVICE_OPTIMIZE << 24) | 1 /* @text: video */, ++ GAME = (DEVICE_OPTIMIZE << 24) | 2 /* @text: game */, + -+ // next system mode states... ++ // next system mode states... + }; + + struct EXTERNAL SuccessResult { -+ bool success; ++ bool success; + }; + struct EXTERNAL GetStateResult { -+ State state ; -+ bool success; ++ State state /* @text state */; ++ bool success; + }; + // @text requestState + // @brief Requests a new system mode state in the device. Thunder components asynchronously reconfigure themselves so the caller cannot be guaranteed a full state transition upon return. @@ -107,7 +107,7 @@ index 0000000..29b9f4e + // @param[in] systemMode The system mode to get the state of. + // @param[out] state Receives the state of the system mode. + // @returns Core::hresult -+ virtual Core::hresult GetState(const SystemMode systemMode /* @in @text systemMode */ , GetStateResult& result /* @out */) const = 0; ++ virtual Core::hresult GetState(const SystemMode systemMode /* @in @text systemMode */ , GetStateResult& getStateResult /* @out */) const = 0; + + // @text clientActivated + // @brief To put client plugin entry in map. From b30022cc177de9826ac8e3f708598e59e5cf3123 Mon Sep 17 00:00:00 2001 From: ramkumarpraba <103193010+ramkumarpraba@users.noreply.github.com> Date: Tue, 24 Sep 2024 22:51:13 +0530 Subject: [PATCH 17/21] Update SystemModeImplementation.cpp --- SystemMode/SystemModeImplementation.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SystemMode/SystemModeImplementation.cpp b/SystemMode/SystemModeImplementation.cpp index e26175e7bc..9abed2238e 100755 --- a/SystemMode/SystemModeImplementation.cpp +++ b/SystemMode/SystemModeImplementation.cpp @@ -305,7 +305,7 @@ uint32_t SystemModeImplementation::ClientActivated(const string& callsign , cons if(stateRequested) { State state ; - GetStateResult successResult + GetStateResult successResult; if(GetState(pSystemMode, successResult ) == Core::ERROR_NONE) { state = successResult.state; From 075fc3a18c23286f972cafbfc73649a208193bf5 Mon Sep 17 00:00:00 2001 From: ramkumarpraba Date: Tue, 24 Sep 2024 17:41:46 +0000 Subject: [PATCH 18/21] RDK-51362 : System Mode Thunder Plugin to support ALLM Reason for change: New plugin SystemMode added. Test Procedure: verify build success and basic test Risks: Low Priority: P1 Signed-off-by: ramkumar_prabaharan@comcast.com --- SystemMode/SystemModeImplementation.cpp | 1 - Tests/L2Tests/L2TestsPlugin/tests/SystemMode_L2Test.cpp | 4 ---- 2 files changed, 5 deletions(-) diff --git a/SystemMode/SystemModeImplementation.cpp b/SystemMode/SystemModeImplementation.cpp index 9abed2238e..d1ec354b0e 100755 --- a/SystemMode/SystemModeImplementation.cpp +++ b/SystemMode/SystemModeImplementation.cpp @@ -237,7 +237,6 @@ Core::hresult SystemModeImplementation::GetState(const SystemMode pSystemMode, G } successResult.success = true; result = Core::ERROR_NONE; - std::cout<<"RamTesting successResult.state :"<< successResult.state <<"successResult.success"< Date: Wed, 25 Sep 2024 09:41:57 +0000 Subject: [PATCH 19/21] RDK-51362 : System Mode Thunder Plugin to support ALLM Reason for change: New plugin SystemMode added. Test Procedure: verify build success and basic test Risks: Low Priority: P1 Signed-off-by: ramkumar_prabaharan@comcast.com --- SystemMode/SystemModeImplementation.cpp | 11 +---------- SystemMode/SystemModeImplementation.h | 2 +- .../L2Tests/L2TestsPlugin/tests/SystemMode_L2Test.cpp | 6 ------ 3 files changed, 2 insertions(+), 17 deletions(-) diff --git a/SystemMode/SystemModeImplementation.cpp b/SystemMode/SystemModeImplementation.cpp index d1ec354b0e..edb97e3ed2 100755 --- a/SystemMode/SystemModeImplementation.cpp +++ b/SystemMode/SystemModeImplementation.cpp @@ -156,11 +156,10 @@ SystemModeImplementation::~SystemModeImplementation() } -Core::hresult SystemModeImplementation::RequestState(const SystemMode pSystemMode, const State pState , SuccessResult& successResult) +Core::hresult SystemModeImplementation::RequestState(const SystemMode pSystemMode, const State pState ) { auto SystemModeMapIterator = SystemModeMap.find(pSystemMode); Core::hresult result = Core::ERROR_NONE; - successResult.success = true; if(SystemModeMapIterator != SystemModeMap.end()) { @@ -184,13 +183,11 @@ Core::hresult SystemModeImplementation::RequestState(const SystemMode pSystemMod Utils::String::updateSystemModeFile(systemMode_str,"currentstate",new_state,"add"); LOGINFO("SystemMode state change from %s to new %s" ,old_state.c_str(),new_state.c_str()); stateRequested =true; - successResult.success = true; result = Core::ERROR_NONE; } else { LOGERR("Invalid state %d for systemMode %s" ,pState,systemMode_str.c_str()); - successResult.success = false; result = Core::ERROR_GENERAL; } break; @@ -198,7 +195,6 @@ Core::hresult SystemModeImplementation::RequestState(const SystemMode pSystemMod default: { LOGERR("Invalid systemMode %s",systemMode_str.c_str()); - successResult.success = false; result = Core::ERROR_GENERAL; break; } @@ -208,7 +204,6 @@ Core::hresult SystemModeImplementation::RequestState(const SystemMode pSystemMod else { LOGERR("Invalid systemMode %d",pSystemMode); - successResult.success = false; result = Core::ERROR_GENERAL; } return result; @@ -218,7 +213,6 @@ Core::hresult SystemModeImplementation::GetState(const SystemMode pSystemMode, G { Core::hresult result = Core::ERROR_NONE; - successResult.success = true; auto SystemModeMapIterator = SystemModeMap.find(pSystemMode); if(SystemModeMapIterator != SystemModeMap.end()) { @@ -235,14 +229,12 @@ Core::hresult SystemModeImplementation::GetState(const SystemMode pSystemMode, G break; } } - successResult.success = true; result = Core::ERROR_NONE; break; } default: { LOGERR("Invalid systemMode %d",static_cast(pSystemMode)); - successResult.success = false; result = Core::ERROR_GENERAL; break; } @@ -251,7 +243,6 @@ Core::hresult SystemModeImplementation::GetState(const SystemMode pSystemMode, G else { LOGERR("Invalid systemMode %d",static_cast(pSystemMode)); - successResult.success = false; return Core::ERROR_GENERAL; } return result; diff --git a/SystemMode/SystemModeImplementation.h b/SystemMode/SystemModeImplementation.h index 36afb84b3a..95e8498619 100755 --- a/SystemMode/SystemModeImplementation.h +++ b/SystemMode/SystemModeImplementation.h @@ -54,7 +54,7 @@ namespace Plugin { END_INTERFACE_MAP public: - Core::hresult RequestState(const SystemMode systemMode, const State state ,SuccessResult& successResult) override; + Core::hresult RequestState(const SystemMode systemMode, const State state ) override; Core::hresult GetState(const SystemMode systemMode , GetStateResult& successResult)const override; virtual uint32_t ClientActivated(const string& callsign ,const string& systemMode) override ; diff --git a/Tests/L2Tests/L2TestsPlugin/tests/SystemMode_L2Test.cpp b/Tests/L2Tests/L2TestsPlugin/tests/SystemMode_L2Test.cpp index 6e4c5e662d..abdac39b22 100755 --- a/Tests/L2Tests/L2TestsPlugin/tests/SystemMode_L2Test.cpp +++ b/Tests/L2Tests/L2TestsPlugin/tests/SystemMode_L2Test.cpp @@ -80,10 +80,6 @@ TEST_F(SystemModeTest,getStatedefault) if (result.HasLabel("state")) { EXPECT_STREQ("video", result["state"].String().c_str()); } - if (result.HasLabel("success")) - { - EXPECT_TRUE(result["success"].Boolean()); - } } TEST_F(SystemModeTest,getStateNegativeCase) @@ -136,7 +132,6 @@ TEST_F(SystemModeTest,requestStateGame) params["state"] = "game"; status = InvokeServiceMethod("org.rdk.SystemMode", "requestState", params, result); EXPECT_EQ(Core::ERROR_NONE, status); - EXPECT_TRUE(result["success"].Boolean()); status = InvokeServiceMethod("org.rdk.SystemMode", "getState", params, result); EXPECT_EQ(Core::ERROR_NONE, status); @@ -172,7 +167,6 @@ TEST_F(SystemModeTest,requestStateVideo) status = InvokeServiceMethod("org.rdk.SystemMode", "requestState", params, result); EXPECT_EQ(Core::ERROR_NONE, status); - EXPECT_TRUE(result["success"].Boolean()); status = InvokeServiceMethod("org.rdk.SystemMode", "getState", params, result); EXPECT_EQ(Core::ERROR_NONE, status); From cb1c37cc7cb92797065eae70fc5622880775d57c Mon Sep 17 00:00:00 2001 From: ramkumarpraba Date: Wed, 25 Sep 2024 10:17:51 +0000 Subject: [PATCH 20/21] RDK-51362 : System Mode Thunder Plugin to support ALLM Reason for change: New plugin SystemMode added. Test Procedure: verify build success and basic test Risks: Low Priority: P1 Signed-off-by: ramkumar_prabaharan@comcast.com --- ...RDK-51362-System-Mode-Thunder-Plugin.patch | 22 ++++++++----------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/Tests/L2Tests/patches/RDK-51362-System-Mode-Thunder-Plugin.patch b/Tests/L2Tests/patches/RDK-51362-System-Mode-Thunder-Plugin.patch index 804daf82ed..1d99f674b0 100644 --- a/Tests/L2Tests/patches/RDK-51362-System-Mode-Thunder-Plugin.patch +++ b/Tests/L2Tests/patches/RDK-51362-System-Mode-Thunder-Plugin.patch @@ -42,10 +42,10 @@ index 0000000..168c0e0 +} diff --git a/interfaces/ISystemMode.h b/interfaces/ISystemMode.h new file mode 100644 -index 0000000..98637d4 +index 0000000..2c33b6d --- /dev/null +++ b/interfaces/ISystemMode.h -@@ -0,0 +1,79 @@ +@@ -0,0 +1,75 @@ +/* + * If not stated otherwise in this file or this component's LICENSE file the + * following copyright and licenses apply: @@ -76,31 +76,27 @@ index 0000000..98637d4 + + /// Enumeration of system modes. + enum SystemMode : uint8_t { -+ DEVICE_OPTIMIZE = 1 /* @text: device_optimize */ ++ DEVICE_OPTIMIZE = 1 /* @text: device_optimize */ + }; + + /// Enumeration of states for all system modes. + enum State : uint32_t { -+ // DEVICE_OPTIMIZE states -+ VIDEO = (DEVICE_OPTIMIZE << 24) | 1 /* @text: video */, -+ GAME = (DEVICE_OPTIMIZE << 24) | 2 /* @text: game */, ++ // DEVICE_OPTIMIZE states ++ VIDEO = (DEVICE_OPTIMIZE << 24) | 1 /* @text: video */, ++ GAME = (DEVICE_OPTIMIZE << 24) | 2 /* @text: game */, + -+ // next system mode states... ++ // next system mode states... + }; + -+ struct EXTERNAL SuccessResult { -+ bool success; -+ }; + struct EXTERNAL GetStateResult { -+ State state /* @text state */; -+ bool success; ++ State state /* @text state */; + }; + // @text requestState + // @brief Requests a new system mode state in the device. Thunder components asynchronously reconfigure themselves so the caller cannot be guaranteed a full state transition upon return. + // @param[in] systemMode The system mode. + // @param[in] state The requested state. + // @returns Core::hresult -+ virtual Core::hresult RequestState(const SystemMode systemMode /* @in @text systemMode */ , const State state /* @in @text state */ , SuccessResult& successResult /* @out */) = 0; ++ virtual Core::hresult RequestState(const SystemMode systemMode /* @in @text systemMode */ , const State state /* @in @text state */ ) = 0; + + // @text getState + // @brief Gets the current state for a given system property From 21ccc7abd0b5ec175efb0ea0404f769ca20152ff Mon Sep 17 00:00:00 2001 From: ramkumarpraba <103193010+ramkumarpraba@users.noreply.github.com> Date: Wed, 25 Sep 2024 16:03:58 +0530 Subject: [PATCH 21/21] Update SystemModeImplementation.cpp --- SystemMode/SystemModeImplementation.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SystemMode/SystemModeImplementation.cpp b/SystemMode/SystemModeImplementation.cpp index edb97e3ed2..36397a2fa5 100755 --- a/SystemMode/SystemModeImplementation.cpp +++ b/SystemMode/SystemModeImplementation.cpp @@ -2,7 +2,7 @@ * If not stated otherwise in this file or this component's LICENSE file the * following copyright and licenses apply: * -* Copyright 2024 RDK Management +* 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.