diff --git a/CMakeLists.txt b/CMakeLists.txt index 6962c29..cbc9571 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -40,20 +40,16 @@ if(RDK_SERVICES_L1_TEST) add_subdirectory(Tests/L1Tests) endif() -if(PLUGIN_VOICECONTROL) - add_subdirectory(VoiceControl) -endif() - -if(PLUGIN_REMOTECONTROL) - add_subdirectory(RemoteControl) -endif() - - if(PLUGIN_MOTION_DETECTION) add_subdirectory(MotionDetection) endif() +# Add a dummy install target to prevent cmake install failures when no plugins are enabled. This is needed temporarily while plugins are moved to other repos. +if(NOT RDK_SERVICES_L1_TEST AND NOT PLUGIN_MOTION_DETECTION) + install(CODE "message(STATUS \"entservices-peripherals: No install target available, ignoring...\")") +endif() + if(WPEFRAMEWORK_CREATE_IPKG_TARGETS) set(CPACK_GENERATOR "DEB") set(CPACK_DEB_COMPONENT_INSTALL ON) diff --git a/RemoteControl/CHANGELOG.md b/RemoteControl/CHANGELOG.md deleted file mode 100644 index ed830fd..0000000 --- a/RemoteControl/CHANGELOG.md +++ /dev/null @@ -1,12 +0,0 @@ -# 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. - diff --git a/RemoteControl/CMakeLists.txt b/RemoteControl/CMakeLists.txt deleted file mode 100644 index 143a11d..0000000 --- a/RemoteControl/CMakeLists.txt +++ /dev/null @@ -1,51 +0,0 @@ -### -# If not stated otherwise in this file or this component's LICENSE -# file the following copyright and licenses apply: -# -# Copyright 2023 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 RemoteControl) -set(MODULE_NAME ${NAMESPACE}${PLUGIN_NAME}) - -find_package(${NAMESPACE}Plugins REQUIRED) - -add_subdirectory(test) - -add_library(${MODULE_NAME} SHARED - RemoteControl.cpp - Module.cpp) - -set_target_properties(${MODULE_NAME} PROPERTIES - CXX_STANDARD 11 - CXX_STANDARD_REQUIRED YES) - -target_include_directories(${MODULE_NAME} PRIVATE ../helpers) - -find_package(CTRLM) -if (CTRLM_FOUND) - find_package(IARMBus) - add_definitions(-DCTRLM_FOUND) - target_include_directories(${MODULE_NAME} PRIVATE ${IARMBUS_INCLUDE_DIRS}) - target_include_directories(${MODULE_NAME} PRIVATE ${CTRLM_INCLUDE_DIRS}) - target_link_libraries(${MODULE_NAME} PRIVATE ${NAMESPACE}Plugins::${NAMESPACE}Plugins ${IARMBUS_LIBRARIES}) -else (CTRLM_FOUND) - target_link_libraries(${MODULE_NAME} PRIVATE ${NAMESPACE}Plugins::${NAMESPACE}Plugins) -endif(CTRLM_FOUND) - -install(TARGETS ${MODULE_NAME} - DESTINATION lib/${STORAGE_DIRECTORY}/plugins) - -write_config(${PLUGIN_NAME}) diff --git a/RemoteControl/Module.cpp b/RemoteControl/Module.cpp deleted file mode 100644 index ab461e8..0000000 --- a/RemoteControl/Module.cpp +++ /dev/null @@ -1,22 +0,0 @@ -/** -* If not stated otherwise in this file or this component's LICENSE -* file the following copyright and licenses apply: -* -* Copyright 2023 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/RemoteControl/Module.h b/RemoteControl/Module.h deleted file mode 100644 index 5a85aa7..0000000 --- a/RemoteControl/Module.h +++ /dev/null @@ -1,29 +0,0 @@ -/** -* If not stated otherwise in this file or this component's LICENSE -* file the following copyright and licenses apply: -* -* Copyright 2023 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 RemoteControl -#endif - -#include -#include - -#undef EXTERNAL -#define EXTERNAL diff --git a/RemoteControl/README.md b/RemoteControl/README.md deleted file mode 100644 index 61d9b4d..0000000 --- a/RemoteControl/README.md +++ /dev/null @@ -1,18 +0,0 @@ ------------------ -Build: - -bitbake thunder-plugins - ------------------ -Test: - - -Methods common to typical plugins - getQuirks() and getApiVersionNumber() (not documented in official RemoteControl service API) - -curl --header "Content-Type: application/json" --request POST --data '{"jsonrpc":"2.0","id":"3","method": "org.rdk.RemoteControl.1.getQuirks"}' http://127.0.0.1:9998/jsonrpc - -curl -d '{"jsonrpc":"2.0","id":"4","method":"org.rdk.RemoteControl.1.getApiVersionNumber"}' http://127.0.0.1:9998/jsonrpc - - - - diff --git a/RemoteControl/RemoteControl.conf.in b/RemoteControl/RemoteControl.conf.in deleted file mode 100644 index b765c1e..0000000 --- a/RemoteControl/RemoteControl.conf.in +++ /dev/null @@ -1,3 +0,0 @@ -precondition = ["Platform"] -callsign = "org.rdk.RemoteControl" -autostart = "false" diff --git a/RemoteControl/RemoteControl.config b/RemoteControl/RemoteControl.config deleted file mode 100644 index 5a1edbd..0000000 --- a/RemoteControl/RemoteControl.config +++ /dev/null @@ -1,22 +0,0 @@ -### -# If not stated otherwise in this file or this component's LICENSE -# file the following copyright and licenses apply: -# -# Copyright 2023 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 (autostart false) -set (preconditions Platform) -set (callsign "org.rdk.RemoteControl") diff --git a/RemoteControl/RemoteControl.cpp b/RemoteControl/RemoteControl.cpp deleted file mode 100644 index bb2dbd6..0000000 --- a/RemoteControl/RemoteControl.cpp +++ /dev/null @@ -1,1112 +0,0 @@ -/** -* If not stated otherwise in this file or this component's LICENSE -* file the following copyright and licenses apply: -* -* Copyright 2023 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 "RemoteControl.h" -#include "libIBusDaemon.h" -#include "UtilsUnused.h" -#include "UtilsCStr.h" -#include "UtilsJsonRpc.h" -#include "UtilsIarm.h" -#include "UtilsString.h" - -#include - -#define IARM_FACTORY_RESET_TIMEOUT (15 * 1000) // 15 seconds, in milliseconds -#define IARM_IRDB_CALLS_TIMEOUT (10 * 1000) // 10 seconds, in milliseconds - -using namespace std; - -#define API_VERSION_NUMBER_MAJOR 1 -#define API_VERSION_NUMBER_MINOR 5 -#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 { - - SERVICE_REGISTRATION(RemoteControl, API_VERSION_NUMBER_MAJOR, API_VERSION_NUMBER_MINOR, API_VERSION_NUMBER_PATCH); - - RemoteControl* RemoteControl::_instance = nullptr; - - RemoteControl::RemoteControl() - : PluginHost::JSONRPC() - , m_apiVersionNumber((uint32_t)-1) /* default max uint32_t so everything gets enabled */ //TODO(MROLLINS) Can't we access this from jsonrpc interface? - { - LOGINFO("ctor"); - RemoteControl::_instance = this; - - Register("getApiVersionNumber", &RemoteControl::getApiVersionNumber, this); - Register("startPairing", &RemoteControl::startPairing, this); - Register("stopPairing", &RemoteControl::stopPairing, this); - Register("getNetStatus", &RemoteControl::getNetStatus, this); - Register("getIRDBManufacturers", &RemoteControl::getIRDBManufacturers, this); - Register("getIRDBModels", &RemoteControl::getIRDBModels, this); - Register("getIRCodesByAutoLookup", &RemoteControl::getIRCodesByAutoLookup,this); - Register("getIRCodesByNames", &RemoteControl::getIRCodesByNames, this); - Register("setIRCode", &RemoteControl::setIRCode, this); - Register("clearIRCodes", &RemoteControl::clearIRCodes, this); - Register("getLastKeypressSource", &RemoteControl::getLastKeypressSource, this); - Register("configureWakeupKeys", &RemoteControl::configureWakeupKeys, this); - Register("initializeIRDB", &RemoteControl::initializeIRDB, this); - Register("findMyRemote", &RemoteControl::findMyRemote, this); - Register("factoryReset", &RemoteControl::factoryReset, this); - Register("unpair", &RemoteControl::unpair, this); - Register("startFirmwareUpdate", &RemoteControl::startFirmwareUpdate, this); - Register("cancelFirmwareUpdate", &RemoteControl::cancelFirmwareUpdate, this); - Register("statusFirmwareUpdate", &RemoteControl::statusFirmwareUpdate, this); - - m_hasOwnProcess = false; - setApiVersionNumber(1); - } - - RemoteControl::~RemoteControl() - { - //LOGINFO("dtor"); - } - - const string RemoteControl::Initialize(PluginHost::IShell* /* service */) - { - InitializeIARM(); - // On success return empty, to indicate there is no error text. - return (string()); - } - - void RemoteControl::Deinitialize(PluginHost::IShell* /* service */) - { - DeinitializeIARM(); - RemoteControl::_instance = nullptr; - } - - void RemoteControl::InitializeIARM() - { - if (Utils::IARM::init()) - { - m_hasOwnProcess = true; - IARM_Result_t res; - IARM_CHECK( IARM_Bus_RegisterEventHandler(CTRLM_MAIN_IARM_BUS_NAME, CTRLM_RCU_IARM_EVENT_RCU_STATUS, remoteEventHandler) ); - IARM_CHECK( IARM_Bus_RegisterEventHandler(CTRLM_MAIN_IARM_BUS_NAME, CTRLM_RCU_IARM_EVENT_FIRMWARE_UPDATE_PROGRESS, remoteEventHandler) ); - // Register for ControlMgr pairing-related events - IARM_CHECK( IARM_Bus_RegisterEventHandler(CTRLM_MAIN_IARM_BUS_NAME, CTRLM_RCU_IARM_EVENT_VALIDATION_STATUS, remoteEventHandler) ); - IARM_CHECK( IARM_Bus_RegisterEventHandler(CTRLM_MAIN_IARM_BUS_NAME, CTRLM_RCU_IARM_EVENT_CONFIGURATION_COMPLETE, remoteEventHandler) ); - IARM_CHECK( IARM_Bus_RegisterEventHandler(CTRLM_MAIN_IARM_BUS_NAME, CTRLM_RCU_IARM_EVENT_RF4CE_PAIRING_WINDOW_TIMEOUT, remoteEventHandler) ); - } - else - m_hasOwnProcess = false; - } - - //TODO(MROLLINS) - we need to install crash handler to ensure DeinitializeIARM gets called - void RemoteControl::DeinitializeIARM() - { - if (m_hasOwnProcess) - { - IARM_Result_t res; - IARM_CHECK( IARM_Bus_RemoveEventHandler(CTRLM_MAIN_IARM_BUS_NAME, CTRLM_RCU_IARM_EVENT_RCU_STATUS, remoteEventHandler) ); - IARM_CHECK( IARM_Bus_RemoveEventHandler(CTRLM_MAIN_IARM_BUS_NAME, CTRLM_RCU_IARM_EVENT_FIRMWARE_UPDATE_PROGRESS, remoteEventHandler) ); - // Remove handlers for ControlMgr pairing-related events - IARM_CHECK( IARM_Bus_RemoveEventHandler(CTRLM_MAIN_IARM_BUS_NAME, CTRLM_RCU_IARM_EVENT_VALIDATION_STATUS, remoteEventHandler) ); - IARM_CHECK( IARM_Bus_RemoveEventHandler(CTRLM_MAIN_IARM_BUS_NAME, CTRLM_RCU_IARM_EVENT_CONFIGURATION_COMPLETE, remoteEventHandler) ); - IARM_CHECK( IARM_Bus_RemoveEventHandler(CTRLM_MAIN_IARM_BUS_NAME, CTRLM_RCU_IARM_EVENT_RF4CE_PAIRING_WINDOW_TIMEOUT, remoteEventHandler) ); - - IARM_CHECK( IARM_Bus_Disconnect() ); - IARM_CHECK( IARM_Bus_Term() ); - m_hasOwnProcess = false; - } - } - - void RemoteControl::remoteEventHandler(const char *owner, IARM_EventId_t eventId, void *data, size_t len) - { - if (RemoteControl::_instance) - RemoteControl::_instance->iarmEventHandler(owner, eventId, data, len); - else - LOGWARN("WARNING - cannot handle btremote IARM events without a RemoteControl plugin instance!"); - } - - //bt handlers - void RemoteControl::iarmEventHandler(const char *owner, IARM_EventId_t eventId, void *data, size_t len) - { - if (strcmp(owner, CTRLM_MAIN_IARM_BUS_NAME)) - { - LOGERR("ERROR - unexpected event: owner %s, eventId: %d, data: %p, size: %d.", - owner, (int)eventId, data, len); - return; - } - - if ((data == NULL) || (len == 0)) - { - LOGERR("ERROR - event with NO DATA: eventId: %d, data: %p, size: %d.", (int)eventId, data, len); - return; - } - ctrlm_main_iarm_event_json_t *eventData = static_cast(data); - - switch(eventId) { - case CTRLM_RCU_IARM_EVENT_RCU_STATUS: - case CTRLM_RCU_IARM_EVENT_CONFIGURATION_COMPLETE: - case CTRLM_RCU_IARM_EVENT_RF4CE_PAIRING_WINDOW_TIMEOUT: - LOGWARN("Got CTRLM_RCU_IARM_EVENT event."); - onStatus(eventData); - break; - case CTRLM_RCU_IARM_EVENT_VALIDATION_STATUS: - LOGWARN("Got CTRLM_RCU_IARM_EVENT_VALIDATION_STATUS event."); - onValidation(eventData); - break; - case CTRLM_RCU_IARM_EVENT_FIRMWARE_UPDATE_PROGRESS: - LOGWARN("Got CTRLM_RCU_IARM_FIRMWARE_EVENT event."); - onFirmwareUpdateProgress(eventData); - break; - default: - LOGERR("ERROR - unexpected ctrlm event: eventId: %d, data: %p, size: %d.", - (int)eventId, data, len); - break; - } - } // End iarmEventHandler() - - //Begin methods - uint32_t RemoteControl::getApiVersionNumber(const JsonObject& parameters, JsonObject& response) - { - LOGINFOMETHOD(); - response["version"] = m_apiVersionNumber; - returnResponse(true); - } - - uint32_t RemoteControl::startPairing(const JsonObject& parameters, JsonObject& response) - { - LOGINFOMETHOD(); - - ctrlm_main_iarm_call_json_t *call = NULL; - IARM_Result_t res; - string jsonParams; - bool bSuccess = false; - size_t totalsize = 0; - - parameters.ToString(jsonParams); - totalsize = sizeof(ctrlm_main_iarm_call_json_t) + jsonParams.size() + 1; - call = (ctrlm_main_iarm_call_json_t*)calloc(1, totalsize); - - if (call == NULL) - { - LOGERR("ERROR - Cannot allocate IARM structure - size: %u.", (unsigned)totalsize); - bSuccess = false; - returnResponse(bSuccess); - } - - call->api_revision = CTRLM_MAIN_IARM_BUS_API_REVISION; - size_t len = jsonParams.copy(call->payload, jsonParams.size()); - call->payload[len] = '\0'; - - res = IARM_Bus_Call(CTRLM_MAIN_IARM_BUS_NAME, CTRLM_MAIN_IARM_CALL_START_PAIRING, (void *)call, totalsize); - if (res != IARM_RESULT_SUCCESS) - { - LOGERR("ERROR - CTRLM_MAIN_IARM_CALL_START_PAIRING Bus Call FAILED, res: %d.", (int)res); - bSuccess = false; - free(call); - returnResponse(bSuccess); - } - - JsonObject result; - result.FromString(call->result); - bSuccess = result["success"].Boolean(); - response = std::move(result); - free(call); - - if (bSuccess) - LOGINFO("START PAIRING call SUCCESS!"); - else - LOGERR("ERROR - CTRLM_MAIN_IARM_CALL_START_PAIRING returned FAILURE!"); - - returnResponse(bSuccess); - } - - uint32_t RemoteControl::stopPairing(const JsonObject& parameters, JsonObject& response) - { - LOGINFOMETHOD(); - - ctrlm_main_iarm_call_json_t *call = NULL; - IARM_Result_t res; - string jsonParams; - bool bSuccess = false; - size_t totalsize = 0; - - parameters.ToString(jsonParams); - totalsize = sizeof(ctrlm_main_iarm_call_json_t) + jsonParams.size() + 1; - call = (ctrlm_main_iarm_call_json_t*)calloc(1, totalsize); - - if (call == NULL) - { - LOGERR("ERROR - Cannot allocate IARM structure - size: %u.", (unsigned)totalsize); - bSuccess = false; - returnResponse(bSuccess); - } - - call->api_revision = CTRLM_MAIN_IARM_BUS_API_REVISION; - size_t len = jsonParams.copy(call->payload, jsonParams.size()); - call->payload[len] = '\0'; - - res = IARM_Bus_Call(CTRLM_MAIN_IARM_BUS_NAME, CTRLM_MAIN_IARM_CALL_STOP_PAIRING, (void *)call, totalsize); - if (res != IARM_RESULT_SUCCESS) - { - LOGERR("ERROR - CTRLM_MAIN_IARM_CALL_STOP_PAIRING Bus Call FAILED, res: %d.", (int)res); - bSuccess = false; - free(call); - returnResponse(bSuccess); - } - - JsonObject result; - result.FromString(call->result); - bSuccess = result["success"].Boolean(); - response = std::move(result); - free(call); - - if (bSuccess) - LOGINFO("STOP PAIRING call SUCCESS!"); - else - LOGERR("ERROR - CTRLM_MAIN_IARM_CALL_STOP_PAIRING returned FAILURE!"); - - returnResponse(bSuccess); - } - - uint32_t RemoteControl::getNetStatus(const JsonObject& parameters, JsonObject& response) - { - LOGINFOMETHOD(); - - ctrlm_main_iarm_call_json_t *call = NULL; - IARM_Result_t res; - string jsonParams; - bool bSuccess = false; - size_t totalsize = 0; - - parameters.ToString(jsonParams); - totalsize = sizeof(ctrlm_main_iarm_call_json_t) + jsonParams.size() + 1; - call = (ctrlm_main_iarm_call_json_t*)calloc(1, totalsize); - - if (call == NULL) - { - LOGERR("ERROR - Cannot allocate IARM structure - size: %u.", (unsigned)totalsize); - bSuccess = false; - returnResponse(bSuccess); - } - - call->api_revision = CTRLM_MAIN_IARM_BUS_API_REVISION; - size_t len = jsonParams.copy(call->payload, jsonParams.size()); - call->payload[len] = '\0'; - - res = IARM_Bus_Call(CTRLM_MAIN_IARM_BUS_NAME, CTRLM_MAIN_IARM_CALL_GET_RCU_STATUS, (void *)call, totalsize); - if (res != IARM_RESULT_SUCCESS) - { - LOGERR("ERROR - CTRLM_MAIN_IARM_CALL_GET_RCU_STATUS Bus Call FAILED, res: %d.", (int)res); - bSuccess = false; - free(call); - returnResponse(bSuccess); - } - - JsonObject result; - result.FromString(call->result); - bSuccess = result["success"].Boolean(); - response = std::move(result); - free(call); - - if (bSuccess) - LOGINFO("GET RCU STATUS call SUCCESS!"); - else - LOGERR("ERROR - CTRLM_MAIN_IARM_CALL_GET_RCU_STATUS returned FAILURE!"); - - returnResponse(bSuccess); - } - - uint32_t RemoteControl::getIRDBManufacturers(const JsonObject& parameters, JsonObject& response) - { - LOGINFOMETHOD(); - - ctrlm_main_iarm_call_json_t *call = NULL; - IARM_Result_t res; - string jsonParams; - bool bSuccess = false; - size_t totalsize = 0; - - parameters.ToString(jsonParams); - totalsize = sizeof(ctrlm_main_iarm_call_json_t) + jsonParams.size() + 1; - call = (ctrlm_main_iarm_call_json_t*)calloc(1, totalsize); - - if (call == NULL) - { - LOGERR("ERROR - Cannot allocate IARM structure - size: %u.", (unsigned)totalsize); - bSuccess = false; - returnResponse(bSuccess); - } - - call->api_revision = CTRLM_MAIN_IARM_BUS_API_REVISION; - size_t len = jsonParams.copy(call->payload, jsonParams.size()); - call->payload[len] = '\0'; - - // The default timeout for IARM calls is 5 seconds, but this call could take longer since the results could come from a cloud IRDB. - // So increase the timeout to IARM_IRDB_CALLS_TIMEOUT - res = IARM_Bus_Call_with_IPCTimeout(CTRLM_MAIN_IARM_BUS_NAME, CTRLM_MAIN_IARM_CALL_IR_MANUFACTURERS, (void *)call, totalsize, IARM_IRDB_CALLS_TIMEOUT); - if (res != IARM_RESULT_SUCCESS) - { - LOGERR("ERROR - CTRLM_MAIN_IARM_CALL_IR_MANUFACTURERS Bus Call FAILED, res: %d.", (int)res); - bSuccess = false; - free(call); - returnResponse(bSuccess); - } - - JsonObject result; - result.FromString(call->result); - bSuccess = result["success"].Boolean(); - response = std::move(result); - free(call); - - if (bSuccess) - LOGINFO("IRDB MANUFACTURERS call SUCCESS!"); - else - LOGERR("ERROR - CTRLM_MAIN_IARM_CALL_IR_MANUFACTURERS returned FAILURE!"); - - returnResponse(bSuccess); - } - - uint32_t RemoteControl::getIRDBModels(const JsonObject& parameters, JsonObject& response) - { - LOGINFOMETHOD(); - - ctrlm_main_iarm_call_json_t *call = NULL; - IARM_Result_t res; - string jsonParams; - bool bSuccess = false; - size_t totalsize = 0; - - parameters.ToString(jsonParams); - totalsize = sizeof(ctrlm_main_iarm_call_json_t) + jsonParams.size() + 1; - call = (ctrlm_main_iarm_call_json_t*)calloc(1, totalsize); - - if (call == NULL) - { - LOGERR("ERROR - Cannot allocate IARM structure - size: %u.", (unsigned)totalsize); - bSuccess = false; - returnResponse(bSuccess); - } - - call->api_revision = CTRLM_MAIN_IARM_BUS_API_REVISION; - size_t len = jsonParams.copy(call->payload, jsonParams.size()); - call->payload[len] = '\0'; - - // The default timeout for IARM calls is 5 seconds, but this call could take longer since the results could come from a cloud IRDB. - // So increase the timeout to IARM_IRDB_CALLS_TIMEOUT - res = IARM_Bus_Call_with_IPCTimeout(CTRLM_MAIN_IARM_BUS_NAME, CTRLM_MAIN_IARM_CALL_IR_MODELS, (void *)call, totalsize, IARM_IRDB_CALLS_TIMEOUT); - if (res != IARM_RESULT_SUCCESS) - { - LOGERR("ERROR - CTRLM_MAIN_IARM_CALL_IR_MODELS Bus Call FAILED, res: %d.", (int)res); - bSuccess = false; - free(call); - returnResponse(bSuccess); - } - - JsonObject result; - result.FromString(call->result); - bSuccess = result["success"].Boolean(); - response = std::move(result); - free(call); - - if (bSuccess) - LOGINFO("IRDB MODELS call SUCCESS!"); - else - LOGERR("ERROR - CTRLM_MAIN_IARM_CALL_IR_MODELS returned FAILURE!"); - - returnResponse(bSuccess); - } - - uint32_t RemoteControl::getIRCodesByAutoLookup(const JsonObject& parameters, JsonObject& response) - { - LOGINFOMETHOD(); - - ctrlm_main_iarm_call_json_t *call = NULL; - IARM_Result_t res; - string jsonParams; - bool bSuccess = false; - size_t totalsize = 0; - - parameters.ToString(jsonParams); - totalsize = sizeof(ctrlm_main_iarm_call_json_t) + jsonParams.size() + 1; - call = (ctrlm_main_iarm_call_json_t*)calloc(1, totalsize); - - if (call == NULL) - { - LOGERR("ERROR - Cannot allocate IARM structure - size: %u.", (unsigned)totalsize); - bSuccess = false; - returnResponse(bSuccess); - } - - call->api_revision = CTRLM_MAIN_IARM_BUS_API_REVISION; - size_t len = jsonParams.copy(call->payload, jsonParams.size()); - call->payload[len] = '\0'; - - // The default timeout for IARM calls is 5 seconds, but this call could take longer since the results could come from a cloud IRDB. - // So increase the timeout to IARM_IRDB_CALLS_TIMEOUT - res = IARM_Bus_Call_with_IPCTimeout(CTRLM_MAIN_IARM_BUS_NAME, CTRLM_MAIN_IARM_CALL_IR_AUTO_LOOKUP, (void *)call, totalsize, IARM_IRDB_CALLS_TIMEOUT); - if (res != IARM_RESULT_SUCCESS) - { - LOGERR("ERROR - CTRLM_MAIN_IARM_CALL_IR_AUTO_LOOKUP Bus Call FAILED, res: %d.", (int)res); - bSuccess = false; - free(call); - returnResponse(bSuccess); - } - - JsonObject result; - result.FromString(call->result); - bSuccess = result["success"].Boolean(); - response = std::move(result); - free(call); - - if (bSuccess) - LOGINFO("IRDB AUTO LOOKUP call SUCCESS!"); - else - LOGERR("ERROR - CTRLM_MAIN_IARM_CALL_IR_AUTO_LOOKUP returned FAILURE!"); - - returnResponse(bSuccess); - } - - uint32_t RemoteControl::getIRCodesByNames(const JsonObject& parameters, JsonObject& response) - { - LOGINFOMETHOD(); - - ctrlm_main_iarm_call_json_t *call = NULL; - IARM_Result_t res; - string jsonParams; - bool bSuccess = false; - size_t totalsize = 0; - - parameters.ToString(jsonParams); - totalsize = sizeof(ctrlm_main_iarm_call_json_t) + jsonParams.size() + 1; - call = (ctrlm_main_iarm_call_json_t*)calloc(1, totalsize); - - if (call == NULL) - { - LOGERR("ERROR - Cannot allocate IARM structure - size: %u.", (unsigned)totalsize); - bSuccess = false; - returnResponse(bSuccess); - } - - call->api_revision = CTRLM_MAIN_IARM_BUS_API_REVISION; - size_t len = jsonParams.copy(call->payload, jsonParams.size()); - call->payload[len] = '\0'; - - // The default timeout for IARM calls is 5 seconds, but this call could take longer since the results could come from a cloud IRDB. - // So increase the timeout to IARM_IRDB_CALLS_TIMEOUT - res = IARM_Bus_Call_with_IPCTimeout(CTRLM_MAIN_IARM_BUS_NAME, CTRLM_MAIN_IARM_CALL_IR_CODES, (void *)call, totalsize, IARM_IRDB_CALLS_TIMEOUT); - if (res != IARM_RESULT_SUCCESS) - { - LOGERR("ERROR - CTRLM_MAIN_IARM_CALL_IR_CODES Bus Call FAILED, res: %d.", (int)res); - bSuccess = false; - free(call); - returnResponse(bSuccess); - } - - JsonObject result; - result.FromString(call->result); - bSuccess = result["success"].Boolean(); - response = std::move(result); - free(call); - - if (bSuccess) - LOGINFO("GET IR CODES call SUCCESS!"); - else - LOGERR("ERROR - CTRLM_MAIN_IARM_CALL_IR_CODES returned FAILURE!"); - - returnResponse(bSuccess); - } - - uint32_t RemoteControl::setIRCode(const JsonObject& parameters, JsonObject& response) - { - LOGINFOMETHOD(); - - ctrlm_main_iarm_call_json_t *call = NULL; - IARM_Result_t res; - string jsonParams; - bool bSuccess = false; - size_t totalsize = 0; - - parameters.ToString(jsonParams); - totalsize = sizeof(ctrlm_main_iarm_call_json_t) + jsonParams.size() + 1; - call = (ctrlm_main_iarm_call_json_t*)calloc(1, totalsize); - - if (call == NULL) - { - LOGERR("ERROR - Cannot allocate IARM structure - size: %u.", (unsigned)totalsize); - bSuccess = false; - returnResponse(bSuccess); - } - - call->api_revision = CTRLM_MAIN_IARM_BUS_API_REVISION; - size_t len = jsonParams.copy(call->payload, jsonParams.size()); - call->payload[len] = '\0'; - - res = IARM_Bus_Call(CTRLM_MAIN_IARM_BUS_NAME, CTRLM_MAIN_IARM_CALL_IR_SET_CODE, (void *)call, totalsize); - if (res != IARM_RESULT_SUCCESS) - { - LOGERR("ERROR - CTRLM_MAIN_IARM_CALL_IR_SET_CODE Bus Call FAILED, res: %d.", (int)res); - bSuccess = false; - free(call); - returnResponse(bSuccess); - } - - JsonObject result; - result.FromString(call->result); - bSuccess = result["success"].Boolean(); - response = std::move(result); - free(call); - - if (bSuccess) - LOGINFO("SET IR CODES call SUCCESS!"); - else - LOGERR("ERROR - CTRLM_MAIN_IARM_CALL_IR_SET_CODE returned FAILURE!"); - - returnResponse(bSuccess); - } - - uint32_t RemoteControl::clearIRCodes(const JsonObject& parameters, JsonObject& response) - { - LOGINFOMETHOD(); - - ctrlm_main_iarm_call_json_t *call = NULL; - IARM_Result_t res; - string jsonParams; - bool bSuccess = false; - size_t totalsize = 0; - - parameters.ToString(jsonParams); - totalsize = sizeof(ctrlm_main_iarm_call_json_t) + jsonParams.size() + 1; - call = (ctrlm_main_iarm_call_json_t*)calloc(1, totalsize); - - if (call == NULL) - { - LOGERR("ERROR - Cannot allocate IARM structure - size: %u.", (unsigned)totalsize); - bSuccess = false; - returnResponse(bSuccess); - } - - call->api_revision = CTRLM_MAIN_IARM_BUS_API_REVISION; - size_t len = jsonParams.copy(call->payload, jsonParams.size()); - call->payload[len] = '\0'; - - res = IARM_Bus_Call(CTRLM_MAIN_IARM_BUS_NAME, CTRLM_MAIN_IARM_CALL_IR_CLEAR_CODE, (void *)call, totalsize); - if (res != IARM_RESULT_SUCCESS) - { - LOGERR("ERROR - CTRLM_MAIN_IARM_CALL_IR_CLEAR_CODE Bus Call FAILED, res: %d.", (int)res); - bSuccess = false; - free(call); - returnResponse(bSuccess); - } - - JsonObject result; - result.FromString(call->result); - bSuccess = result["success"].Boolean(); - response = std::move(result); - free(call); - - if (bSuccess) - LOGINFO("CLEAR IR CODES call SUCCESS!"); - else - LOGERR("ERROR - CTRLM_MAIN_IARM_CALL_IR_CLEAR_CODE returned FAILURE!"); - - returnResponse(bSuccess); - } - - uint32_t RemoteControl::getLastKeypressSource(const JsonObject& parameters, JsonObject& response) - { - LOGINFOMETHOD(); - - ctrlm_main_iarm_call_json_t *call = NULL; - IARM_Result_t res; - string jsonParams; - bool bSuccess = false; - size_t totalsize = 0; - - parameters.ToString(jsonParams); - totalsize = sizeof(ctrlm_main_iarm_call_json_t) + jsonParams.size() + 1; - call = (ctrlm_main_iarm_call_json_t*)calloc(1, totalsize); - - if (call == NULL) - { - LOGERR("ERROR - Cannot allocate IARM structure - size: %u.", (unsigned)totalsize); - bSuccess = false; - returnResponse(bSuccess); - } - - call->api_revision = CTRLM_MAIN_IARM_BUS_API_REVISION; - size_t len = jsonParams.copy(call->payload, jsonParams.size()); - call->payload[len] = '\0'; - - res = IARM_Bus_Call(CTRLM_MAIN_IARM_BUS_NAME, CTRLM_MAIN_IARM_CALL_LAST_KEYPRESS_GET, (void *)call, totalsize); - if (res != IARM_RESULT_SUCCESS) - { - LOGERR("ERROR - CTRLM_MAIN_IARM_CALL_LAST_KEYPRESS_GET Bus Call FAILED, res: %d.", (int)res); - bSuccess = false; - free(call); - returnResponse(bSuccess); - } - - JsonObject result; - result.FromString(call->result); - bSuccess = result["success"].Boolean(); - response = std::move(result); - free(call); - - if (bSuccess) - LOGINFO("GET LAST KEYPRESS call SUCCESS!"); - else - LOGERR("ERROR - CTRLM_MAIN_IARM_CALL_LAST_KEYPRESS_GET returned FAILURE!"); - - returnResponse(bSuccess); - } - - uint32_t RemoteControl::configureWakeupKeys(const JsonObject& parameters, JsonObject& response) - { - LOGINFOMETHOD(); - - ctrlm_main_iarm_call_json_t *call = NULL; - IARM_Result_t res; - string jsonParams; - bool bSuccess = false; - size_t totalsize = 0; - - parameters.ToString(jsonParams); - totalsize = sizeof(ctrlm_main_iarm_call_json_t) + jsonParams.size() + 1; - call = (ctrlm_main_iarm_call_json_t*)calloc(1, totalsize); - - if (call == NULL) - { - LOGERR("ERROR - Cannot allocate IARM structure - size: %u.", (unsigned)totalsize); - bSuccess = false; - returnResponse(bSuccess); - } - - call->api_revision = CTRLM_MAIN_IARM_BUS_API_REVISION; - size_t len = jsonParams.copy(call->payload, jsonParams.size()); - call->payload[len] = '\0'; - - res = IARM_Bus_Call(CTRLM_MAIN_IARM_BUS_NAME, CTRLM_MAIN_IARM_CALL_WRITE_RCU_WAKEUP_CONFIG, (void *)call, totalsize); - if (res != IARM_RESULT_SUCCESS) - { - LOGERR("ERROR - CTRLM_MAIN_IARM_CALL_WRITE_RCU_WAKEUP_CONFIG Bus Call FAILED, res: %d.", (int)res); - bSuccess = false; - free(call); - returnResponse(bSuccess); - } - - JsonObject result; - result.FromString(call->result); - bSuccess = result["success"].Boolean(); - response = std::move(result); - free(call); - - if (bSuccess) - LOGINFO("WRITE RCU WAKEUP CONFIG call SUCCESS!"); - else - LOGERR("ERROR - CTRLM_MAIN_IARM_CALL_WRITE_RCU_WAKEUP_CONFIG returned FAILURE!"); - - returnResponse(bSuccess); - } - - uint32_t RemoteControl::initializeIRDB(const JsonObject& parameters, JsonObject& response) - { - LOGINFOMETHOD(); - - ctrlm_main_iarm_call_json_t *call = NULL; - IARM_Result_t res; - string jsonParams; - bool bSuccess = false; - size_t totalsize = 0; - - parameters.ToString(jsonParams); - totalsize = sizeof(ctrlm_main_iarm_call_json_t) + jsonParams.size() + 1; - call = (ctrlm_main_iarm_call_json_t*)calloc(1, totalsize); - - if (call == NULL) - { - LOGERR("ERROR - Cannot allocate IARM structure - size: %u.", (unsigned)totalsize); - bSuccess = false; - returnResponse(bSuccess); - } - - call->api_revision = CTRLM_MAIN_IARM_BUS_API_REVISION; - size_t len = jsonParams.copy(call->payload, jsonParams.size()); - call->payload[len] = '\0'; - - res = IARM_Bus_Call_with_IPCTimeout(CTRLM_MAIN_IARM_BUS_NAME, CTRLM_MAIN_IARM_CALL_IR_INITIALIZE, (void *)call, totalsize, IARM_IRDB_CALLS_TIMEOUT); - if (res != IARM_RESULT_SUCCESS) - { - LOGERR("ERROR - CTRLM_MAIN_IARM_CALL_IR_INITIALIZE Bus Call FAILED, res: %d.", (int)res); - bSuccess = false; - free(call); - returnResponse(bSuccess); - } - - JsonObject result; - result.FromString(call->result); - bSuccess = result["success"].Boolean(); - response = std::move(result); - free(call); - - if (bSuccess) - LOGINFO("INITIALIZE IRDB call SUCCESS!"); - else - LOGERR("ERROR - CTRLM_MAIN_IARM_CALL_IR_INITIALIZE returned FAILURE!"); - - returnResponse(bSuccess); - } - - uint32_t RemoteControl::findMyRemote(const JsonObject& parameters, JsonObject& response) - { - LOGINFOMETHOD(); - - ctrlm_main_iarm_call_json_t *call = NULL; - IARM_Result_t res; - string jsonParams; - bool bSuccess = false; - size_t totalsize = 0; - - parameters.ToString(jsonParams); - totalsize = sizeof(ctrlm_main_iarm_call_json_t) + jsonParams.size() + 1; - call = (ctrlm_main_iarm_call_json_t*)calloc(1, totalsize); - - if (call == NULL) - { - LOGERR("ERROR - Cannot allocate IARM structure - size: %u.", (unsigned)totalsize); - bSuccess = false; - returnResponse(bSuccess); - } - - call->api_revision = CTRLM_MAIN_IARM_BUS_API_REVISION; - size_t len = jsonParams.copy(call->payload, jsonParams.size()); - call->payload[len] = '\0'; - - res = IARM_Bus_Call(CTRLM_MAIN_IARM_BUS_NAME, CTRLM_MAIN_IARM_CALL_FIND_MY_REMOTE, (void *)call, totalsize); - if (res != IARM_RESULT_SUCCESS) - { - LOGERR("ERROR - CTRLM_MAIN_IARM_CALL_FIND_MY_REMOTE Bus Call FAILED, res: %d.", (int)res); - bSuccess = false; - free(call); - returnResponse(bSuccess); - } - - JsonObject result; - result.FromString(call->result); - bSuccess = result["success"].Boolean(); - response = std::move(result); - free(call); - - if (bSuccess) - LOGINFO("FIND MY REMOTE call SUCCESS!"); - else - LOGERR("ERROR - CTRLM_MAIN_IARM_CALL_FIND_MY_REMOTE returned FAILURE!"); - - returnResponse(bSuccess); - } - - uint32_t RemoteControl::factoryReset(const JsonObject& parameters, JsonObject& response) - { - LOGINFOMETHOD(); - - ctrlm_main_iarm_call_json_t *call = NULL; - IARM_Result_t res; - string jsonParams; - bool bSuccess = false; - size_t totalsize = 0; - - parameters.ToString(jsonParams); - totalsize = sizeof(ctrlm_main_iarm_call_json_t) + jsonParams.size() + 1; - call = (ctrlm_main_iarm_call_json_t*)calloc(1, totalsize); - - if (call == NULL) - { - LOGERR("ERROR - Cannot allocate IARM structure - size: %u.", (unsigned)totalsize); - bSuccess = false; - returnResponse(bSuccess); - } - - call->api_revision = CTRLM_MAIN_IARM_BUS_API_REVISION; - size_t len = jsonParams.copy(call->payload, jsonParams.size()); - call->payload[len] = '\0'; - - // The default timeout for IARM calls is 5 seconds, but this call could take longer and we need to ensure the remotes receive - // the message before the larger system factory reset operation continues. Therefore, make this timeout longer. - res = IARM_Bus_Call_with_IPCTimeout(CTRLM_MAIN_IARM_BUS_NAME, CTRLM_MAIN_IARM_CALL_FACTORY_RESET, (void *)call, totalsize, IARM_FACTORY_RESET_TIMEOUT); - if (res != IARM_RESULT_SUCCESS) - { - LOGERR("ERROR - CTRLM_MAIN_IARM_CALL_FACTORY_RESET Bus Call FAILED, res: %d.", (int)res); - bSuccess = false; - free(call); - returnResponse(bSuccess); - } - - JsonObject result; - result.FromString(call->result); - bSuccess = result["success"].Boolean(); - response = std::move(result); - free(call); - - if (bSuccess) - LOGINFO("FACTORY RESET call SUCCESS!"); - else - LOGERR("ERROR - CTRLM_MAIN_IARM_CALL_FACTORY_RESET returned FAILURE!"); - - returnResponse(bSuccess); - } - - uint32_t RemoteControl::unpair(const JsonObject& parameters, JsonObject& response) - { - LOGINFOMETHOD(); - - ctrlm_main_iarm_call_json_t *call = NULL; - IARM_Result_t res; - string jsonParams; - bool bSuccess = false; - size_t totalsize = 0; - - parameters.ToString(jsonParams); - totalsize = sizeof(ctrlm_main_iarm_call_json_t) + jsonParams.size() + 1; - call = (ctrlm_main_iarm_call_json_t*)calloc(1, totalsize); - - if (call == NULL) - { - LOGERR("ERROR - Cannot allocate IARM structure - size: %u.", (unsigned)totalsize); - bSuccess = false; - returnResponse(bSuccess); - } - - call->api_revision = CTRLM_MAIN_IARM_BUS_API_REVISION; - size_t len = jsonParams.copy(call->payload, jsonParams.size()); - call->payload[len] = '\0'; - - res = IARM_Bus_Call(CTRLM_MAIN_IARM_BUS_NAME, CTRLM_MAIN_IARM_CALL_UNPAIR, (void *)call, totalsize); - if (res != IARM_RESULT_SUCCESS) - { - LOGERR("ERROR - CTRLM_MAIN_IARM_CALL_UNPAIR Bus Call FAILED, res: %d.", (int)res); - bSuccess = false; - free(call); - returnResponse(bSuccess); - } - - JsonObject result; - result.FromString(call->result); - bSuccess = result["success"].Boolean(); - response = result; - free(call); - - if (bSuccess) - LOGINFO("UNPAIR call SUCCESS!"); - else - LOGERR("ERROR - CTRLM_MAIN_IARM_CALL_UNPAIR returned FAILURE!"); - - returnResponse(bSuccess); - } - - uint32_t RemoteControl::startFirmwareUpdate(const JsonObject& parameters, JsonObject& response) - { - LOGINFOMETHOD(); - - ctrlm_main_iarm_call_json_t *call = NULL; - IARM_Result_t res; - string jsonParams; - bool bSuccess = false; - size_t totalsize = 0; - - parameters.ToString(jsonParams); - totalsize = sizeof(ctrlm_main_iarm_call_json_t) + jsonParams.size() + 1; - call = (ctrlm_main_iarm_call_json_t*)calloc(1, totalsize); - - if (call == NULL) - { - LOGERR("ERROR - Cannot allocate IARM structure - size: %u.", (unsigned)totalsize); - bSuccess = false; - returnResponse(bSuccess); - } - - call->api_revision = CTRLM_MAIN_IARM_BUS_API_REVISION; - size_t len = jsonParams.copy(call->payload, jsonParams.size()); - call->payload[len] = '\0'; - - res = IARM_Bus_Call(CTRLM_MAIN_IARM_BUS_NAME, CTRLM_MAIN_IARM_CALL_START_FIRMWARE_UPDATE, (void *)call, totalsize); - if (res != IARM_RESULT_SUCCESS) - { - LOGERR("ERROR - CTRLM_MAIN_IARM_CALL_START_FIRMWARE_UPDATE Bus Call FAILED, res: %d.", (int)res); - bSuccess = false; - free(call); - returnResponse(bSuccess); - } - - JsonObject result; - result.FromString(call->result); - bSuccess = result["success"].Boolean(); - response = result; - free(call); - - if (bSuccess) - LOGINFO("START FIRMWARE UPDATE call SUCCESS!"); - else - LOGERR("ERROR - CTRLM_MAIN_IARM_CALL_START_FIRMWARE_UPDATE returned FAILURE!"); - - returnResponse(bSuccess); - } - - uint32_t RemoteControl::cancelFirmwareUpdate(const JsonObject& parameters, JsonObject& response) - { - LOGINFOMETHOD(); - - ctrlm_main_iarm_call_json_t *call = NULL; - IARM_Result_t res; - string jsonParams; - bool bSuccess = false; - size_t totalsize = 0; - - parameters.ToString(jsonParams); - totalsize = sizeof(ctrlm_main_iarm_call_json_t) + jsonParams.size() + 1; - call = (ctrlm_main_iarm_call_json_t*)calloc(1, totalsize); - - if (call == NULL) - { - LOGERR("ERROR - Cannot allocate IARM structure - size: %u.", (unsigned)totalsize); - bSuccess = false; - returnResponse(bSuccess); - } - - call->api_revision = CTRLM_MAIN_IARM_BUS_API_REVISION; - size_t len = jsonParams.copy(call->payload, jsonParams.size()); - call->payload[len] = '\0'; - - res = IARM_Bus_Call(CTRLM_MAIN_IARM_BUS_NAME, CTRLM_MAIN_IARM_CALL_CANCEL_FIRMWARE_UPDATE, (void *)call, totalsize); - if (res != IARM_RESULT_SUCCESS) - { - LOGERR("ERROR - CTRLM_MAIN_IARM_CALL_CANCEL_FIRMWARE_UPDATE Bus Call FAILED, res: %d.", (int)res); - bSuccess = false; - free(call); - returnResponse(bSuccess); - } - - JsonObject result; - result.FromString(call->result); - bSuccess = result["success"].Boolean(); - response = result; - free(call); - - if (bSuccess) - LOGINFO("CANCEL FIRMWARE UPDATE call SUCCESS!"); - else - LOGERR("ERROR - CTRLM_MAIN_IARM_CALL_CANCEL_FIRMWARE_UPDATE returned FAILURE!"); - - returnResponse(bSuccess); - } - - uint32_t RemoteControl::statusFirmwareUpdate(const JsonObject& parameters, JsonObject& response) - { - LOGINFOMETHOD(); - - ctrlm_main_iarm_call_json_t *call = NULL; - IARM_Result_t res; - string jsonParams; - bool bSuccess = false; - size_t totalsize = 0; - - parameters.ToString(jsonParams); - totalsize = sizeof(ctrlm_main_iarm_call_json_t) + jsonParams.size() + 1; - call = (ctrlm_main_iarm_call_json_t*)calloc(1, totalsize); - - if (call == NULL) - { - LOGERR("ERROR - Cannot allocate IARM structure - size: %u.", (unsigned)totalsize); - bSuccess = false; - returnResponse(bSuccess); - } - - call->api_revision = CTRLM_MAIN_IARM_BUS_API_REVISION; - size_t len = jsonParams.copy(call->payload, jsonParams.size()); - call->payload[len] = '\0'; - - res = IARM_Bus_Call(CTRLM_MAIN_IARM_BUS_NAME, CTRLM_MAIN_IARM_CALL_STATUS_FIRMWARE_UPDATE, (void *)call, totalsize); - if (res != IARM_RESULT_SUCCESS) - { - LOGERR("ERROR - CTRLM_MAIN_IARM_CALL_STATUS_FIRMWARE_UPDATE Bus Call FAILED, res: %d.", (int)res); - bSuccess = false; - free(call); - returnResponse(bSuccess); - } - - JsonObject result; - result.FromString(call->result); - bSuccess = result["success"].Boolean(); - response = result; - free(call); - - if (bSuccess) - LOGINFO("STATUS FIRMWARE UPDATE call SUCCESS!"); - else - LOGERR("ERROR - CTRLM_MAIN_IARM_CALL_STATUS_FIRMWARE_UPDATE returned FAILURE!"); - - returnResponse(bSuccess); - } - //End methods - - //Begin events - void RemoteControl::onStatus(ctrlm_main_iarm_event_json_t* eventData) - { - JsonObject params; - - params.FromString(eventData->payload); - - sendNotify("onStatus", params); - } - - void RemoteControl::onValidation(ctrlm_main_iarm_event_json_t* eventData) - { - JsonObject params; - - params.FromString(eventData->payload); - - sendNotify("onValidation", params); - } - void RemoteControl::onFirmwareUpdateProgress(ctrlm_main_iarm_event_json_t* eventData) - { - JsonObject params; - - params.FromString(eventData->payload); - - sendNotify("onFirmwareUpdateProgress", params); - } - //End events - - //Begin local private utility methods - void RemoteControl::setApiVersionNumber(unsigned int apiVersionNumber) - { - LOGINFO("setting version: %d", (int)apiVersionNumber); - m_apiVersionNumber = apiVersionNumber; - } - //End local private utility methods - } // namespace Plugin -} // namespace WPEFramework - diff --git a/RemoteControl/RemoteControl.h b/RemoteControl/RemoteControl.h deleted file mode 100644 index c830edf..0000000 --- a/RemoteControl/RemoteControl.h +++ /dev/null @@ -1,121 +0,0 @@ -/** -* If not stated otherwise in this file or this component's LICENSE -* file the following copyright and licenses apply: -* -* Copyright 2023 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 "libIBus.h" - -#include "ctrlm_ipc.h" -#include "ctrlm_ipc_rcu.h" -#include "ctrlm_ipc_ble.h" - -#define IARM_REMOTECONTROL_PLUGIN_NAME "Remote_Control" - - -namespace WPEFramework { - - namespace Plugin { - - class RemoteControl; // Forward declaration - - // This is a server for a JSONRPC communication channel. - // For a plugin to be capable to handle JSONRPC, inherit from PluginHost::JSONRPC. - // By inheriting from this class, the plugin realizes the interface PluginHost::IDispatcher. - // This realization of this interface implements, by default, the following methods on this plugin - // - exists - // - register - // - unregister - // Any other method to be handled by this plugin can be added can be added by using the - // templated methods Register on the PluginHost::JSONRPC class. - // 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. - // Note that most of the above is now inherited from the AbstractPlugin class. - class RemoteControl : public PluginHost::IPlugin, public PluginHost::JSONRPC { - private: - typedef Core::JSON::String JString; - typedef Core::JSON::ArrayType JStringArray; - typedef Core::JSON::ArrayType JObjectArray; - typedef Core::JSON::Boolean JBool; - - // We do not allow this plugin to be copied !! - RemoteControl(const RemoteControl&) = delete; - RemoteControl& operator=(const RemoteControl&) = delete; - - //Begin methods - uint32_t getApiVersionNumber(const JsonObject& parameters, JsonObject& response); - uint32_t startPairing(const JsonObject& parameters, JsonObject& response); - uint32_t stopPairing(const JsonObject& parameters, JsonObject& response); - uint32_t getNetStatus(const JsonObject& parameters, JsonObject& response); - uint32_t getIRDBManufacturers(const JsonObject& parameters, JsonObject& response); - uint32_t getIRDBModels(const JsonObject& parameters, JsonObject& response); - uint32_t getIRCodesByAutoLookup(const JsonObject& parameters, JsonObject& response); - uint32_t getIRCodesByNames(const JsonObject& parameters, JsonObject& response); - uint32_t setIRCode(const JsonObject& parameters, JsonObject& response); - uint32_t clearIRCodes(const JsonObject& parameters, JsonObject& response); - uint32_t getLastKeypressSource(const JsonObject& parameters, JsonObject& response); - uint32_t configureWakeupKeys(const JsonObject& parameters, JsonObject& response); - uint32_t initializeIRDB(const JsonObject& parameters, JsonObject& response); - uint32_t findMyRemote(const JsonObject& parameters, JsonObject& response); - uint32_t factoryReset(const JsonObject& parameters, JsonObject& response); - uint32_t unpair(const JsonObject& parameters, JsonObject& response); - uint32_t startFirmwareUpdate(const JsonObject& parameters, JsonObject& response); - uint32_t cancelFirmwareUpdate(const JsonObject& parameters, JsonObject& response); - uint32_t statusFirmwareUpdate(const JsonObject& parameters, JsonObject& response); - //End methods - - //Begin events - void onStatus(ctrlm_main_iarm_event_json_t* eventData); - void onValidation(ctrlm_main_iarm_event_json_t* eventData); - void onFirmwareUpdateProgress(ctrlm_main_iarm_event_json_t* eventData); - //End events - - public: - RemoteControl(); - virtual ~RemoteControl(); - //IPlugin methods - virtual const string Initialize(PluginHost::IShell* service) override; - virtual void Deinitialize(PluginHost::IShell* service) override; - virtual string Information() const override { return {}; } - - BEGIN_INTERFACE_MAP(RemoteControl) - INTERFACE_ENTRY(PluginHost::IPlugin) - INTERFACE_ENTRY(PluginHost::IDispatcher) - END_INTERFACE_MAP - - private: - void InitializeIARM(); - void DeinitializeIARM(); - // Handlers for ControlMgr BT Remote events - static void remoteEventHandler(const char *owner, IARM_EventId_t eventId, void *data, size_t len); - void iarmEventHandler(const char *owner, IARM_EventId_t eventId, void *data, size_t len); - - // Local utility methods - void setApiVersionNumber(uint32_t apiVersionNumber); - - public: - static RemoteControl* _instance; - private: - // Generic members - uint32_t m_apiVersionNumber; - bool m_hasOwnProcess; - }; - } // namespace Plugin -} // namespace WPEFramework diff --git a/RemoteControl/test/CMakeLists.txt b/RemoteControl/test/CMakeLists.txt deleted file mode 100644 index 12d256c..0000000 --- a/RemoteControl/test/CMakeLists.txt +++ /dev/null @@ -1,45 +0,0 @@ -### -# If not stated otherwise in this file or this component's LICENSE -# file the following copyright and licenses apply: -# -# Copyright 2024 RDK Management -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -### - -set(PLUGIN_NAME remoteControlTestClient) -find_package(${NAMESPACE}Core REQUIRED) - -if (USE_THUNDER_R4) - find_package(${NAMESPACE}COM REQUIRED) -else () - find_package(${NAMESPACE}Protocols REQUIRED) -endif (USE_THUNDER_R4) - -add_executable(${PLUGIN_NAME} remoteControlTestClient.cpp) - -set_target_properties(${PLUGIN_NAME} PROPERTIES - CXX_STANDARD 11 - CXX_STANDARD_REQUIRED YES - ) - -target_link_libraries(${PLUGIN_NAME} PRIVATE ${NAMESPACE}Core::${NAMESPACE}Core) - -if (USE_THUNDER_R4) -target_link_libraries(${PLUGIN_NAME} PRIVATE ${NAMESPACE}COM::${NAMESPACE}COM ${NAMESPACE}WebSocket::${NAMESPACE}WebSocket) -else () -target_link_libraries(${PLUGIN_NAME} PRIVATE ${NAMESPACE}Protocols::${NAMESPACE}Protocols) -endif (USE_THUNDER_R4) - - -install(TARGETS ${PLUGIN_NAME} DESTINATION bin) diff --git a/RemoteControl/test/Module.h b/RemoteControl/test/Module.h deleted file mode 100644 index 9b92fd2..0000000 --- a/RemoteControl/test/Module.h +++ /dev/null @@ -1,27 +0,0 @@ -/** -* If not stated otherwise in this file or this component's LICENSE -* file the following copyright and licenses apply: -* -* Copyright 2023 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 remoteControlTestClient -#endif - -#include -#include diff --git a/RemoteControl/test/remoteControlTestClient.cpp b/RemoteControl/test/remoteControlTestClient.cpp deleted file mode 100644 index 9cc9fd6..0000000 --- a/RemoteControl/test/remoteControlTestClient.cpp +++ /dev/null @@ -1,860 +0,0 @@ -/* - * If not stated otherwise in this file or this component's license file - * the following copyright and licenses apply: - * - * Copyright 2018 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. - */ - -/** - * @file remoteControlTestClient.cpp - * @brief Thunder Plugin based Implementation of CPP Test Client for RemoteControl service API's. - * @reference RDK-28622. - */ - -#include -#include -#include -#include - -#include "Module.h" - -#define SYSSRV_CALLSIGN "org.rdk.RemoteControl.1" -#define SERVER_DETAILS "127.0.0.1:9998" -#define INVOKE_TIMEOUT (5000) - -using namespace std; -using namespace WPEFramework; -// Global data used to for arguments to pass to the plugin methods -int deviceID = 1; - -string currentTVCode = ""; -string currentAMPCode = ""; -string currentModel = ""; -string avDevType = "TV"; -int infoFrameIndex = 0; -int netType = 1; -int timeout = 0; -int remoteId = 1; -string manufacturer; - -const std::vector beepLevels = {"off","mid","high"}; -size_t beepLevelIdx = 0; -string beepLevel = beepLevels[0]; - -/* Declare module name */ -MODULE_NAME_DECLARATION(BUILD_REFERENCE) - -/* This section can be used for API validation logic. */ -void showMenu() -{ - std::cout<< std::endl; - std::cout<< std::endl; - std::cout<<"RemoteControl API Methods: Current Parameter Settings:\n"; - std::cout<<"0.getQuirks a.Toggle 'netType' [0 for RF4CE | 1 for BLE]: " << netType << "\n"; - std::cout<<"1.getApiVersionNumber b.Enter the 'remoteId' values [1 thru 9]: " << remoteId << "\n"; - std::cout<<"2.startPairing c.Toggle 'avDevType' [TV | AMP]: " << avDevType << "\n"; - std::cout<<"3.getNetStatus d.Enter the 'timeout' value: [0 - use default | Greater than 0 - use value]: " << timeout << "\n"; - std::cout<<"4.getIRDBManufacturers e.Enter the 'tvCode' value: " << currentTVCode << "\n"; - std::cout<<"5.getIRDBModels f.Enter the 'avrCode' value: " << currentAMPCode << "\n"; - std::cout<<"6.getIRCodesByNames g.Enter the 'model' value (for getIRCodesByNames only): " << currentModel << "\n"; - std::cout<<"7.setIRCode h.Cycle thru 'level' values (for findMyRemote only): " << beepLevel << "\n"; - std::cout<<"8.clearIRCodes\n"; - std::cout<<"9.getIRCodesByAutoLookup\n"; - std::cout<<"10.getLastKeypressSource\n"; - std::cout<<"11.initializeIRDB\n"; - std::cout<<"12.findMyRemote\n"; - - std::cout<<"\nEnter your choice: "; -} - -void formatForDisplay(std::string& str) -{ - const int indent = 4; - int level = 0; - - for (size_t i = 0; i < str.size(); i++) - { - if (str[i] == ',') - { - str.insert((i+1), 1, '\n'); // insert after - if (level > 0) - { - str.insert((i+2), (level * indent), ' '); - } - } - else if (str[i] == '}') - { - level--; - if (level < 0) level = 0; - str.insert((i), 1, '\n'); // insert before - if (level > 0) - { - // after the newline, but before the curly brace - str.insert((i+1), (level * indent), ' '); - } - i += (level * indent) + 1; // put i back on the curly brace - } - else if (str[i] == '{') - { - level++; - str.insert((i+1), 1, '\n'); // insert after - if (level > 0) - { - str.insert((i+2), (level * indent), ' '); - } - } - } -} - -#define MAX_FORMATTED_COLUMNS 4 -// Takes output from above (formatForDisplay) as input. -// Intended to format "remoteData" info to display in less vertical space. -void formatColumns(std::string& str) -{ - const int colsize = 52; - int width, numcols; - std::size_t inidx = 0; - std::size_t idxRemoteData = std::string::npos; - - std::string outstr; - std::string colstr[MAX_FORMATTED_COLUMNS]; - int collines[MAX_FORMATTED_COLUMNS]; - - // Auto-sense how many columns we can display - struct winsize console; - ioctl(STDOUT_FILENO, TIOCGWINSZ, &console); - width = console.ws_col; - numcols = width / colsize; - if (numcols > MAX_FORMATTED_COLUMNS) numcols = MAX_FORMATTED_COLUMNS; - - //std::cout<<"width: "<< width <<"\n"; - - if (numcols < 2) - { - // If we can't have more than one column, there is nothing to do here. - return; - } - // Find index where "remoteData": is located - idxRemoteData = str.find("remoteData"); - if (idxRemoteData == std::string::npos) - { - // Failure - no remoteData in the input string. Just bail now. - return; - } - - for (inidx = 0; inidx < str.size(); inidx++) // outermost string transcribe character loop - { - outstr.push_back(str[inidx]); - - if (inidx > idxRemoteData) - { - if (str[inidx] == '{') - { - std::size_t idx; - std::size_t pad; - std::string outline; - int outlines = 0; - int totallines = 0; - int baselines = 0; - int xtra = 0; - - // We have encountered a remoteData block. - // Transcribe to include the curly brace newline... - do - { - inidx++; - outstr.push_back(str[inidx]); - } - while(str[inidx] != '\n'); - // ...then update the input index to the first character after the newline. - inidx++; - // Count the number of lines between here and the next closing curly brace. - for (std::size_t i = inidx; i < str.size(); i++) - { - if (str[i] == '\n') - totallines++; - else if (str[i] == '}') - break; - } - // Allocate the lines to the number of columns we have. - baselines = totallines / numcols; - xtra = totallines % numcols; - outlines = baselines + ((xtra > 0) ? 1 : 0); // We'll use this later... - for (int i = 0; i < numcols; i++) - { - collines[i] = baselines + ((xtra > 0) ? 1 : 0); - if (xtra > 0) xtra--; - } - // Load the column strings from the input. - // This will also advance the input index past the entire block. - for (int i = 0; i < numcols; i++) - { - colstr[i].clear(); - for (; inidx < str.size(); inidx++) - { - if (collines[i] > 0) - { - colstr[i].push_back(str[inidx]); - if (str[inidx] == '\n') - { - collines[i]--; - } - } - else - { - break; - } - } - } - // At this point, the input index is set to the character AFTER the final newline - // in the input block. But we want to leave the input index AT the final newline, - // to get the correct continuation of the outer transcription loop. So we must - // move it back by one, here. - inidx--; - - // Build line strings encompassing all the columns, - // and add them to the output string. - for (int i = 0; i < outlines; i++) - { - for (int j = 0; j < numcols; j++) - { - if (!colstr[j].empty() && (totallines > 0)) - { - idx = colstr[j].find('\n'); - if (idx != std::string::npos) - { - outline.append(colstr[j], 0, idx+1); - // Remove the line we just appended, from the start of the colstr. - colstr[j].erase(0, idx+1); - // Count the line as being handled - done with. - totallines--; - // Except for the last column, clobber the newline, - // and pad the line out to the column width, using spaces. - // We leave things as they are for the last column. - // We also leave the last line out of the total number - // of lines alone (newline intact), because even if it isn't - // in the rightmost column, there won't be any more lines! - if ((j < (numcols - 1)) && (totallines > 0)) - { - // Get rid of the newline - outline.pop_back(); // We all agree to use C++11, right? - // Determine how many spaces we need. - pad = ((std::size_t)colsize) - idx; - // Append spaces to the outline. - outline.append(pad, ' '); - } - } - } - } - // Add this cross-column line to the overall output, - outstr.append(outline); - outline.clear(); - } - } - } - } - - // Return the output in the original reference input string - str.clear(); - str.append(outstr); -} - -// Event parameters sent to JSONRPC::Client event handlers, have somehow -// acquired overall quotation marks, with internal quotes backslash-escaped. -// They weren't presented that way in the past, but now somehow they are. -// This function tries to detect and correct that, for console output. -// Should have no effect if the in/out string isn't inside double-quotes. -void removeJsonQuotes(std::string& str) -{ - if ((str.front() == '"') && (str.back() == '"')) - { - str.erase(0, 1); - str.pop_back(); - - for (size_t i = 0; i < str.size(); i++) - { - if ((i < (str.size() - 1)) && (str[i] == 0x5c) && (str[i+1] == '"')) - { - str.erase(i, 1); - } - } - } -} - -// Make changes in parameters -void handleParams(string& cmd) -{ - switch(cmd[0]) - { - case 'a': - { - // netType - if (netType == 1) - { - netType = 0; - } - else - { - netType = 1; - } - } - break; - - case 'b': - { - // Enter rf4ce remoteId - std::cout << "Enter the remoteId (in decimal): "; - std::cin >> remoteId; - if (std::cin.peek() == '\n') - { - string temp; - std::getline(std::cin, temp); - } - } - break; - - case 'c': - { - // avDevType - if (avDevType == "AMP") - { - avDevType = "TV"; - } - else - { - avDevType = "AMP"; - } - } - break; - - case 'd': - { - // Enter timeout - std::cout << "Enter the timeout (0 for default): "; - std::cin >> timeout; - if (std::cin.peek() == '\n') - { - string temp; - std::getline(std::cin, temp); - } - } - break; - - case 'e': - { - // Enter TV code - string digits; - while (digits.empty()) - { - std::cout << "Enter the TV code: "; - std::getline(std::cin, digits); - } - currentTVCode = std::move(digits); - } - break; - - case 'f': - { - // Enter AVR code - string digits; - while (digits.empty()) - { - std::cout << "Enter the AVR code: "; - std::getline(std::cin, digits); - } - currentAMPCode = std::move(digits); - } - break; - - case 'g': - { - // Enter model - string model = ""; - std::cout << "Enter the model (return for empty string): "; - std::getline(std::cin, model); - - if(!model.empty()) - { - currentModel = std::move(model); - } - else - { - currentModel = ""; - } - } - break; - - case 'h': - { - // Cycle through level values - beepLevelIdx++; - if (beepLevelIdx >= beepLevels.size()) - { - beepLevelIdx = 0; - } - beepLevel = beepLevels[beepLevelIdx]; - } - break; - } -} - -/* This section is related to the event handler implementation for RemoteControl Plugin Events. */ - -namespace Handlers { - /* Event Handlers */ - static void onStatus(const Core::JSON::String& parameters) { - std::string message; - parameters.ToString(message); - removeJsonQuotes(message); - std::cout << "\n[RemoteControlEvt] " << __FUNCTION__ << ": " << message << std::endl; - } -} - -int main(int argc, char** argv) -{ - int retStatus = -1; - JSONRPC::LinkType * remoteObject = NULL; - - int choice; - string cmd; - uint32_t ret; - string lastCmd; - - Core::SystemInfo::SetEnvironment(_T("THUNDER_ACCESS"), (_T(SERVER_DETAILS))); - - // Security Token - std::cout << "Retrieving security token" << std::endl; - std::string sToken; - - FILE *pSecurity = popen("/usr/bin/WPEFrameworkSecurityUtility", "r"); - if(pSecurity) { - JsonObject pSecurityJson; - std::string pSecurityOutput; - int pSecurityOutputTrimIndex; - std::array pSecurityBuffer; - - while(fgets(pSecurityBuffer.data(), 256, pSecurity) != NULL) { - pSecurityOutput += pSecurityBuffer.data(); - } - pclose(pSecurity); - - pSecurityOutputTrimIndex = (int)pSecurityOutput.find('{'); - if(pSecurityOutputTrimIndex == (int)std::string::npos) { - std::cout << "Security Utility returned unexpected output" << std::endl; - } else { - if(pSecurityOutputTrimIndex > 0) { - std::cout << "Trimming output from Security Utility" << std::endl; - pSecurityOutput = pSecurityOutput.substr(pSecurityOutputTrimIndex); - } - pSecurityJson.FromString(pSecurityOutput); - if(pSecurityJson["success"].Boolean() == true) { - std::cout << "Security Token retrieved successfully!" << std::endl; - sToken = "token=" + pSecurityJson["token"].String(); - } else { - std::cout << "Security Token retrieval failed!" << std::endl; - } - } - } else { - std::cout << "Failed to open security utility" << std::endl; - } - // End Security Token - - std::cout << "Using callsign: " << SYSSRV_CALLSIGN << std::endl; - - if (NULL == remoteObject) { - remoteObject = new JSONRPC::LinkType(_T(SYSSRV_CALLSIGN), _T(""), false, sToken); - if (NULL == remoteObject) { - std::cout << "JSONRPC::Client initialization failed" << std::endl; - - } else { - - { - // Create a controller client - static auto& controllerClient = *new WPEFramework::JSONRPC::LinkType("", "", false, sToken); - // In case the plugin isn't activated already, try to start it, BEFORE registering for the events! - string strres; - JsonObject params; - params["callsign"] = SYSSRV_CALLSIGN; - JsonObject result; - ret = controllerClient.Invoke(2000, "activate", params, result); - result.ToString(strres); - std::cout<<"\nstartup result : "<< strres <<"\n"; - } - - /* Register handlers for Event reception. */ - std::cout << "\nSubscribing to event handlers\n" << std::endl; - if (remoteObject->Subscribe(1000, _T("onStatus"), - &Handlers::onStatus) == Core::ERROR_NONE) { - std::cout << "Subscribed to : onStatus" << std::endl; - } else { - std::cout << "Failed to Subscribe notification handler : onStatus" << std::endl; - } - - /* API Validation Logic. */ - while (true) { - while (cmd.empty()) - { - showMenu(); - std::getline(std::cin, cmd); - lastCmd = cmd; - } - if ((cmd[0] >= '0') && (cmd[0] <= '9')) - { - choice = stoi(cmd); - } - else if ((cmd[0] >= 'a') && (cmd[0] <= 'h')) - { - handleParams(cmd); - cmd.clear(); - continue; - } - else return 0; - - { - JsonObject result; // The Clear method can leave crud. A new instance off the stack works better. - - switch (choice) { - case 0: - { - JsonObject params; - string res; - ret = remoteObject->Invoke(INVOKE_TIMEOUT, - _T("getQuirks"), params, result); - std::cout<<"RemoteControl Invoke ret : "<< ret <<"\n"; - result.ToString(res); - if (result["success"].Boolean()) { - std::cout<<"RemoteControl getQuirks call - Success!\n"; - } else { - std::cout<<"RemoteControl getQuirks call - failed!\n"; - } - std::cout<<"result : "<Invoke(INVOKE_TIMEOUT, - _T("getApiVersionNumber"), params, result); - std::cout<<"RemoteControl Invoke ret : "<< ret <<"\n"; - result.ToString(res); - if (result["success"].Boolean()) { - std::cout<<"RemoteControl getApiVersionNumber call - Success!\n"; - } else { - std::cout<<"RemoteControl getApiVersionNumber call - failed!\n"; - } - std::cout<<"result : "< 0) { - params["timeout"] = timeout; - } - - ret = remoteObject->Invoke(INVOKE_TIMEOUT, - _T("startPairing"), params, result); - std::cout<<"RemoteControl Invoke ret : "<< ret <<"\n"; - result.ToString(res); - if (result["success"].Boolean()) { - std::cout<<"\nRemoteControl startPairing call success\n"; - } else { - std::cout<<"\nRemoteControl startPairing call failure\n"; - } - std::cout<<"result : "<Invoke(INVOKE_TIMEOUT, - _T("getNetStatus"), params, result); - std::cout<<"RemoteControl Invoke ret : "<< ret <<"\n"; - result.ToString(res); - formatForDisplay(res); - formatColumns(res); - if (result["success"].Boolean()) { - std::cout<<"RemoteControl getNetStatus call - Success!\n"; - } else { - std::cout<<"RemoteControl getNetStatus call - failed!\n"; - } - std::cout<<"result : "<> manufacturer; - params["manufacturer"] = manufacturer; - - - ret = remoteObject->Invoke(INVOKE_TIMEOUT, - _T("getIRDBManufacturers"), params, result); - std::cout<<"RemoteControl Invoke ret : "<< ret <<"\n"; - result.ToString(res); - if (result["success"].Boolean()) { - std::cout<<"RemoteControl getIRDBManufacturers call - Success!\n"; - } else { - std::cout<<"RemoteControl getIRDBManufacturers call - failed!\n"; - } - std::cout<<"result : "<< res <<"\n"; - } - break; - - case 5: - { - JsonObject params; - string model; - string res; - - params["netType"] = netType; - params["avDevType"] = avDevType; - - std::cout<<"\nEnter the full manufacturer name : "; - std::cin>> manufacturer; - params["manufacturer"] = manufacturer; - - std::cout<<"\nEnter at least part of a model name : "; - std::cin>> model; - params["model"] = model; - - - ret = remoteObject->Invoke(INVOKE_TIMEOUT, - _T("getIRDBModels"), params, result); - std::cout<<"RemoteControl Invoke ret : "<< ret <<"\n"; - result.ToString(res); - if (result["success"].Boolean()) { - std::cout<<"RemoteControl getIRDBModels call - Success!\n"; - } else { - std::cout<<"RemoteControl getIRDBModels call - failed!\n"; - } - std::cout<<"result : "<< res <<"\n"; - } - break; - - case 6: - { - JsonObject params; - string model; - string res; - - params["netType"] = netType; - params["avDevType"] = avDevType; - - std::cout<<"\nEnter the full manufacturer name : "; - std::cin>> manufacturer; - params["manufacturer"] = manufacturer; - - if(!currentModel.empty()) - { - params["model"] = currentModel; - } - - - ret = remoteObject->Invoke(INVOKE_TIMEOUT, - _T("getIRCodesByNames"), params, result); - std::cout<<"RemoteControl Invoke ret : "<< ret <<"\n"; - result.ToString(res); - if (result["success"].Boolean()) { - std::cout<<"RemoteControl getIRCodesByNames call - Success!\n"; - } else { - std::cout<<"RemoteControl getIRCodesByNames call - failed!\n"; - } - std::cout<<"result : "<< res <<"\n"; - } - break; - - case 7: - { - JsonObject params; - string res; - params["netType"] = netType; - params["remoteId"] = remoteId; - params["avDevType"] = avDevType; - - if(avDevType=="TV") - { - params["code"] = currentTVCode; - } - else - { - params["code"] = currentAMPCode; - } - - ret = remoteObject->Invoke(INVOKE_TIMEOUT, - _T("setIRCode"), params, result); - std::cout<<"RemoteControl Invoke ret : "<< ret <<"\n"; - result.ToString(res); - formatForDisplay(res); - if (result["success"].Boolean()) { - std::cout<<"RemoteControl setIRCode call - Success!\n"; - } else { - std::cout<<"RemoteControl setIRCode call - failed!\n"; - } - std::cout<<"result : "<Invoke(INVOKE_TIMEOUT, - _T("clearIRCodes"), params, result); - std::cout<<"RemoteControl Invoke ret : "<< ret <<"\n"; - result.ToString(res); - formatForDisplay(res); - if (result["success"].Boolean()) { - std::cout<<"RemoteControl clearIRCodes call - Success!\n"; - } else { - std::cout<<"RemoteControl clearIRCodes call - failed!\n"; - } - std::cout<<"result : "<Invoke(INVOKE_TIMEOUT, - _T("getIRCodesByAutoLookup"), params, result); - std::cout<<"RemoteControl Invoke ret : "<< ret <<"\n"; - result.ToString(res); - if (result["success"].Boolean()) { - std::cout<<"RemoteControl getIRCodesByAutoLookup call - Success!\n"; - } else { - std::cout<<"RemoteControl getIRCodesByAutoLookup call - failed!\n"; - } - std::cout<<"result : "<< res <<"\n"; - } - break; - - case 10: - { - JsonObject params; - string res; - params["netType"] = netType; - ret = remoteObject->Invoke(1000, - _T("getLastKeypressSource"), params, result); - std::cout<<"RemoteControl Invoke ret : "<< ret <<"\n"; - result.ToString(res); - formatForDisplay(res); - if (result["success"].Boolean()) { - std::cout<<"RemoteControl getLastKeypressSource call - Success!\n"; - } else { - std::cout<<"RemoteControl getLastKeypressSource call - failed!\n"; - } - std::cout<<"result : "<Invoke(INVOKE_TIMEOUT, - _T("initializeIRDB"), params, result); - std::cout<<"RemoteControl Invoke ret : "<< ret <<"\n"; - result.ToString(res); - formatForDisplay(res); - if (result["success"].Boolean()) { - std::cout<<"RemoteControl initializeIRDB call - Success!\n"; - } else { - std::cout<<"RemoteControl initializeIRDB call - failed!\n"; - } - std::cout<<"result : "<Invoke(INVOKE_TIMEOUT, - _T("findMyRemote"), params, result); - std::cout<<"RemoteControl Invoke ret : "<< ret <<"\n"; - result.ToString(res); - if (result["success"].Boolean()) { - std::cout<<"RemoteControl findMyRemote call - Success!\n"; - } else { - std::cout<<"RemoteControl findMyRemote call - failed!\n"; - } - std::cout<<"result : "< "; - cmd.clear(); - - std::getline(std::cin, cmd); - if (cmd.empty()) - { - cmd.clear(); - lastCmd.clear(); - } - else if ((cmd[0] == 'r') || (cmd[0] == 'R')) - cmd = lastCmd; - else if ((cmd[0] >= '0') && (cmd[0] <= '9')) - { - choice = stoi(cmd); - lastCmd = cmd; - } - else if ((cmd[0] >= 'a') && (cmd[0] <= 'h')) - { - } - else - break; - - } - } - } - - return retStatus; -} diff --git a/VoiceControl/CHANGELOG.md b/VoiceControl/CHANGELOG.md deleted file mode 100644 index 2e200c4..0000000 --- a/VoiceControl/CHANGELOG.md +++ /dev/null @@ -1,16 +0,0 @@ -# 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. - diff --git a/VoiceControl/CMakeLists.txt b/VoiceControl/CMakeLists.txt deleted file mode 100644 index 5f0d9e7..0000000 --- a/VoiceControl/CMakeLists.txt +++ /dev/null @@ -1,51 +0,0 @@ -### -# If not stated otherwise in this file or this component's LICENSE -# file the following copyright and licenses apply: -# -# Copyright 2024 RDK Management -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. -### - -set(PLUGIN_NAME VoiceControl) -set(MODULE_NAME ${NAMESPACE}${PLUGIN_NAME}) - -set(PLUGIN_VOICECONTROL_STARTUPORDER "" CACHE STRING "To configure startup order of VoiceControl plugin") - -find_package(${NAMESPACE}Plugins REQUIRED) - -add_library(${MODULE_NAME} SHARED - VoiceControl.cpp - Module.cpp) - -set_target_properties(${MODULE_NAME} PROPERTIES - CXX_STANDARD 11 - CXX_STANDARD_REQUIRED YES) - -target_include_directories(${MODULE_NAME} PRIVATE ../helpers) - -find_package(CTRLM) -if (CTRLM_FOUND) - find_package(IARMBus) - add_definitions(-DCTRLM_FOUND) - target_include_directories(${MODULE_NAME} PRIVATE ${IARMBUS_INCLUDE_DIRS}) - target_include_directories(${MODULE_NAME} PRIVATE ${CTRLM_INCLUDE_DIRS}) - target_link_libraries(${MODULE_NAME} PRIVATE ${NAMESPACE}Plugins::${NAMESPACE}Plugins ${IARMBUS_LIBRARIES}) -else (CTRLM_FOUND) - target_link_libraries(${MODULE_NAME} PRIVATE ${NAMESPACE}Plugins::${NAMESPACE}Plugins) -endif(CTRLM_FOUND) - -install(TARGETS ${MODULE_NAME} - DESTINATION lib/${STORAGE_DIRECTORY}/plugins) - -write_config(${PLUGIN_NAME}) diff --git a/VoiceControl/Module.cpp b/VoiceControl/Module.cpp deleted file mode 100644 index cd6d4d1..0000000 --- a/VoiceControl/Module.cpp +++ /dev/null @@ -1,22 +0,0 @@ -/** -* If not stated otherwise in this file or this component's LICENSE -* file the following copyright and licenses apply: -* -* Copyright 2024 RDK Management -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -**/ - -#include "Module.h" - -MODULE_NAME_DECLARATION(BUILD_REFERENCE) diff --git a/VoiceControl/Module.h b/VoiceControl/Module.h deleted file mode 100644 index d85f7dc..0000000 --- a/VoiceControl/Module.h +++ /dev/null @@ -1,29 +0,0 @@ -/** -* If not stated otherwise in this file or this component's LICENSE -* file the following copyright and licenses apply: -* -* Copyright 2024 RDK Management -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -**/ - -#pragma once -#ifndef MODULE_NAME -#define MODULE_NAME VoiceControl -#endif - -#include -#include - -#undef EXTERNAL -#define EXTERNAL diff --git a/VoiceControl/README.md b/VoiceControl/README.md deleted file mode 100644 index b3e7302..0000000 --- a/VoiceControl/README.md +++ /dev/null @@ -1,18 +0,0 @@ ------------------ -Build: - -bitbake thunder-plugins - ------------------ -Test: - - -Methods common to typical plugins - getQuirks() and getApiVersionNumber() (not specific to the VoiceControl API) - -curl --header "Content-Type: application/json" --request POST --data '{"jsonrpc":"2.0","id":"3","method": "org.rdk.VoiceControl.1.getQuirks"}' http://127.0.0.1:9998/jsonrpc - -curl -d '{"jsonrpc":"2.0","id":"4","method":"org.rdk.VoiceControl.1.getApiVersionNumber"}' http://127.0.0.1:9998/jsonrpc - - - - diff --git a/VoiceControl/VoiceControl.conf.in b/VoiceControl/VoiceControl.conf.in deleted file mode 100644 index dcfbc06..0000000 --- a/VoiceControl/VoiceControl.conf.in +++ /dev/null @@ -1,4 +0,0 @@ -precondition = ["Platform"] -callsign = "org.rdk.VoiceControl" -autostart = "false" -startuporder = "@PLUGIN_VOICECONTROL_STARTUPORDER@" diff --git a/VoiceControl/VoiceControl.config b/VoiceControl/VoiceControl.config deleted file mode 100644 index fefc47a..0000000 --- a/VoiceControl/VoiceControl.config +++ /dev/null @@ -1,7 +0,0 @@ -set (autostart false) -set (preconditions Platform) -set (callsign "org.rdk.VoiceControl") - -if(PLUGIN_VOICECONTROL_STARTUPORDER) -set (startuporder ${PLUGIN_VOICECONTROL_STARTUPORDER}) -endif() diff --git a/VoiceControl/VoiceControl.cpp b/VoiceControl/VoiceControl.cpp deleted file mode 100644 index 6120f86..0000000 --- a/VoiceControl/VoiceControl.cpp +++ /dev/null @@ -1,828 +0,0 @@ -/** -* If not stated otherwise in this file or this component's LICENSE -* file the following copyright and licenses apply: -* -* Copyright 2024 RDK Management -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -**/ - -#include "VoiceControl.h" -#include "libIBusDaemon.h" -#include -#include "UtilsJsonRpc.h" -#include "UtilsIarm.h" - -#define API_VERSION_NUMBER_MAJOR 1 -#define API_VERSION_NUMBER_MINOR 4 -#define API_VERSION_NUMBER_PATCH 0 - -using namespace std; - -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 { - - SERVICE_REGISTRATION(VoiceControl, API_VERSION_NUMBER_MAJOR, API_VERSION_NUMBER_MINOR, API_VERSION_NUMBER_PATCH); - - VoiceControl* VoiceControl::_instance = nullptr; - - VoiceControl::VoiceControl() - : PluginHost::JSONRPC() - , m_apiVersionNumber((uint32_t)-1) /* default max uint32_t so everything gets enabled */ - { - LOGINFO("ctor"); - VoiceControl::_instance = this; - - Register("getApiVersionNumber", &VoiceControl::getApiVersionNumber, this); - - Register("voiceStatus", &VoiceControl::voiceStatus, this); - Register("configureVoice", &VoiceControl::configureVoice, this); - Register("setVoiceInit", &VoiceControl::setVoiceInit, this); - Register("sendVoiceMessage", &VoiceControl::sendVoiceMessage, this); - Register("voiceSessionByText", &VoiceControl::voiceSessionByText, this); - Register("voiceSessionTypes", &VoiceControl::voiceSessionTypes, this); - Register("voiceSessionRequest", &VoiceControl::voiceSessionRequest, this); - Register("voiceSessionTerminate", &VoiceControl::voiceSessionTerminate, this); - Register("voiceSessionAudioStreamStart", &VoiceControl::voiceSessionAudioStreamStart, this); - - setApiVersionNumber(1); - m_hasOwnProcess = false; - m_maskPii = false; - } - - VoiceControl::~VoiceControl() - { - //LOGINFO("dtor"); - } - - const string VoiceControl::Initialize(PluginHost::IShell* /* service */) - { - InitializeIARM(); - getMaskPii_(); - // On success return empty, to indicate there is no error text. - return (string()); - } - - void VoiceControl::Deinitialize(PluginHost::IShell* /* service */) - { - LOGINFO("Deinitialize"); - DeinitializeIARM(); - VoiceControl::_instance = nullptr; - } - - void VoiceControl::InitializeIARM() - { - if (Utils::IARM::init()) - { - // We have our own Linux process, so we need to connect and disconnect from the IARM Bus - m_hasOwnProcess = true; - - IARM_Result_t res; - IARM_CHECK( IARM_Bus_RegisterEventHandler(CTRLM_MAIN_IARM_BUS_NAME, CTRLM_VOICE_IARM_EVENT_JSON_SESSION_BEGIN, voiceEventHandler) ); - IARM_CHECK( IARM_Bus_RegisterEventHandler(CTRLM_MAIN_IARM_BUS_NAME, CTRLM_VOICE_IARM_EVENT_JSON_STREAM_BEGIN, voiceEventHandler) ); - IARM_CHECK( IARM_Bus_RegisterEventHandler(CTRLM_MAIN_IARM_BUS_NAME, CTRLM_VOICE_IARM_EVENT_JSON_KEYWORD_VERIFICATION, voiceEventHandler) ); - IARM_CHECK( IARM_Bus_RegisterEventHandler(CTRLM_MAIN_IARM_BUS_NAME, CTRLM_VOICE_IARM_EVENT_JSON_SERVER_MESSAGE, voiceEventHandler) ); - IARM_CHECK( IARM_Bus_RegisterEventHandler(CTRLM_MAIN_IARM_BUS_NAME, CTRLM_VOICE_IARM_EVENT_JSON_STREAM_END, voiceEventHandler) ); - IARM_CHECK( IARM_Bus_RegisterEventHandler(CTRLM_MAIN_IARM_BUS_NAME, CTRLM_VOICE_IARM_EVENT_JSON_SESSION_END, voiceEventHandler) ); - } - else - m_hasOwnProcess = false; - } - - //TODO(MROLLINS) - we need to install crash handler to ensure DeinitializeIARM gets called - void VoiceControl::DeinitializeIARM() - { - if (m_hasOwnProcess) - { - IARM_Result_t res; - IARM_CHECK( IARM_Bus_RemoveEventHandler(CTRLM_MAIN_IARM_BUS_NAME, CTRLM_VOICE_IARM_EVENT_JSON_SESSION_END, voiceEventHandler) ); - IARM_CHECK( IARM_Bus_RemoveEventHandler(CTRLM_MAIN_IARM_BUS_NAME, CTRLM_VOICE_IARM_EVENT_JSON_STREAM_END, voiceEventHandler) ); - IARM_CHECK( IARM_Bus_RemoveEventHandler(CTRLM_MAIN_IARM_BUS_NAME, CTRLM_VOICE_IARM_EVENT_JSON_KEYWORD_VERIFICATION, voiceEventHandler) ); - IARM_CHECK( IARM_Bus_RemoveEventHandler(CTRLM_MAIN_IARM_BUS_NAME, CTRLM_VOICE_IARM_EVENT_JSON_SERVER_MESSAGE, voiceEventHandler) ); - IARM_CHECK( IARM_Bus_RemoveEventHandler(CTRLM_MAIN_IARM_BUS_NAME, CTRLM_VOICE_IARM_EVENT_JSON_STREAM_BEGIN, voiceEventHandler) ); - IARM_CHECK( IARM_Bus_RemoveEventHandler(CTRLM_MAIN_IARM_BUS_NAME, CTRLM_VOICE_IARM_EVENT_JSON_SESSION_BEGIN, voiceEventHandler) ); - - m_hasOwnProcess = false; - } - } - - void VoiceControl::voiceEventHandler(const char *owner, IARM_EventId_t eventId, void *data, size_t len) - { - if (VoiceControl::_instance) - VoiceControl::_instance->iarmEventHandler(owner, eventId, data, len); - else - LOGWARN("WARNING - cannot handle IARM events without a VoiceControl plugin instance!"); - } - - void VoiceControl::iarmEventHandler(const char *owner, IARM_EventId_t eventId, void *data, size_t len) - { - LOGINFO("Event ID %u received, data: %p, len: %u.", (unsigned)eventId, data, (unsigned)len); - if (!strcmp(owner, CTRLM_MAIN_IARM_BUS_NAME)) - { - ctrlm_voice_iarm_event_json_t* eventData = (ctrlm_voice_iarm_event_json_t*)data; - - if ((data == NULL) || (len == 0) || (len <= sizeof(ctrlm_voice_iarm_event_json_t))) - { - LOGERR("ERROR - got eventId(%u) with INVALID DATA: data: %p, len: %zu.", (unsigned)eventId, data, len); - return; - } - - // Ensure there is a null character at the end of the data area. - char* str = (char*)data; - str[len - 1] = '\0'; - - if (CTRLM_VOICE_IARM_BUS_API_REVISION != eventData->api_revision) - { - LOGERR("ERROR - got eventId(%u) with wrong VOICE IARM API revision - should be %d, event has %d.", - (unsigned)eventId, CTRLM_VOICE_IARM_BUS_API_REVISION, (int)eventData->api_revision); - return; - } - - switch(eventId) { - case CTRLM_VOICE_IARM_EVENT_JSON_SESSION_BEGIN: - LOGWARN("Got CTRLM_VOICE_IARM_EVENT_JSON_SESSION_BEGIN event."); - - onSessionBegin(eventData); - break; - - case CTRLM_VOICE_IARM_EVENT_JSON_STREAM_BEGIN: - LOGWARN("Got CTRLM_VOICE_IARM_EVENT_JSON_STREAM_BEGIN event."); - - onStreamBegin(eventData); - break; - - case CTRLM_VOICE_IARM_EVENT_JSON_KEYWORD_VERIFICATION: - LOGWARN("Got CTRLM_VOICE_IARM_EVENT_JSON_KEYWORD_VERIFICATION event."); - - onKeywordVerification(eventData); - break; - - case CTRLM_VOICE_IARM_EVENT_JSON_SERVER_MESSAGE: - LOGWARN("Got CTRLM_VOICE_IARM_EVENT_JSON_SERVER_MESSAGE event."); - - onServerMessage(eventData); - break; - - case CTRLM_VOICE_IARM_EVENT_JSON_STREAM_END: - LOGWARN("Got CTRLM_VOICE_IARM_EVENT_JSON_STREAM_END event."); - - onStreamEnd(eventData); - break; - - case CTRLM_VOICE_IARM_EVENT_JSON_SESSION_END: - LOGWARN("Got CTRLM_VOICE_IARM_EVENT_JSON_SESSION_END event."); - - onSessionEnd(eventData); - break; - - default: - LOGERR("ERROR - unexpected ControlMgr event: eventId: %u, data: %p, size: %zu.", - (unsigned)eventId, data, len); - break; - } - } - else - { - LOGERR("ERROR - unexpected event: owner %s, eventId: %u, data: %p, size: %zu.", - owner, (unsigned)eventId, data, len); - } - } // End iarmEventHandler() - - //Begin methods - uint32_t VoiceControl::getApiVersionNumber(const JsonObject& parameters, JsonObject& response) - { - LOGINFOMETHOD(); - response["version"] = m_apiVersionNumber; - returnResponse(true); - } - - void VoiceControl::getMaskPii_() - { - JsonObject params; - JsonObject result; - voiceStatus(params, result); - m_maskPii = result["maskPii"].Boolean(); - LOGINFO("Mask pii set to %s.", (m_maskPii ? "True" : "False")); - } - - uint32_t VoiceControl::voiceStatus(const JsonObject& parameters, JsonObject& response) - { - LOGINFOMETHOD(); - - ctrlm_voice_iarm_call_json_t* call = NULL; - IARM_Result_t res; - string jsonParams; - bool bSuccess = true; - - // Just pass through the input parameters, without understanding or checking them. - parameters.ToString(jsonParams); - - // We must allocate the memory for the call structure. Determine what we will need. - size_t totalsize = sizeof(ctrlm_voice_iarm_call_json_t) + jsonParams.size() + 1; - call = (ctrlm_voice_iarm_call_json_t*)calloc(1, totalsize); - - if (call != NULL) - { - // Set the call structure members appropriately. - call->api_revision = CTRLM_VOICE_IARM_BUS_API_REVISION; - size_t len = jsonParams.copy(call->payload, jsonParams.size()); - call->payload[len] = '\0'; - } - else - { - LOGERR("ERROR - Cannot allocate IARM structure - size: %u.", (unsigned)totalsize); - bSuccess = false; - } - - if (bSuccess) - { - // Make the IARM call to controlMgr to configure the voice settings - res = IARM_Bus_Call(CTRLM_MAIN_IARM_BUS_NAME, CTRLM_VOICE_IARM_CALL_STATUS, (void *)call, totalsize); - if (res != IARM_RESULT_SUCCESS) - { - LOGERR("ERROR - CTRLM_VOICE_IARM_CALL_STATUS Bus Call FAILED, res: %d.", (int)res); - bSuccess = false; - } - else - { - JsonObject result; - - result.FromString(call->result); - bSuccess = result["success"].Boolean(); - response = std::move(result); - if(bSuccess) { - LOGINFO("CTRLM_VOICE_IARM_CALL_STATUS call SUCCESS!"); - } else { - LOGERR("ERROR - CTRLM_VOICE_IARM_CALL_STATUS returned FAILURE!"); - } - } - } - - if (call != NULL) - { - free(call); - } - - returnResponse(bSuccess); - } - - uint32_t VoiceControl::configureVoice(const JsonObject& parameters, JsonObject& response) - { - LOGINFOMETHOD(); - - ctrlm_voice_iarm_call_json_t* call = NULL; - IARM_Result_t res; - string jsonParams; - bool bSuccess = true; - - // Just pass through the input parameters, without understanding or checking them. - parameters.ToString(jsonParams); - - // We must allocate the memory for the call structure. Determine what we will need. - size_t totalsize = sizeof(ctrlm_voice_iarm_call_json_t) + jsonParams.size() + 1; - call = (ctrlm_voice_iarm_call_json_t*)calloc(1, totalsize); - - if (call != NULL) - { - // Set the call structure members appropriately. - call->api_revision = CTRLM_VOICE_IARM_BUS_API_REVISION; - size_t len = jsonParams.copy(call->payload, jsonParams.size()); - call->payload[len] = '\0'; - } - else - { - LOGERR("ERROR - Cannot allocate IARM structure - size: %u.", (unsigned)totalsize); - bSuccess = false; - } - - if (bSuccess) - { - // Make the IARM call to controlMgr to configure the voice settings - res = IARM_Bus_Call(CTRLM_MAIN_IARM_BUS_NAME, CTRLM_VOICE_IARM_CALL_CONFIGURE_VOICE, (void *)call, totalsize); - if (res != IARM_RESULT_SUCCESS) - { - LOGERR("ERROR - CTRLM_VOICE_IARM_CALL_CONFIGURE_VOICE Bus Call FAILED, res: %d.", (int)res); - bSuccess = false; - } - else - { - JsonObject result; - - result.FromString(call->result); - bSuccess = result["success"].Boolean(); - response = std::move(result); - if(bSuccess) { - LOGINFO("CONFIGURE_VOICE call SUCCESS!"); - } else { - LOGERR("ERROR - CTRLM_VOICE_IARM_CALL_CONFIGURE_VOICE returned FAILURE!"); - } - } - } - - if (call != NULL) - { - free(call); - } - - returnResponse(bSuccess); - } - - uint32_t VoiceControl::setVoiceInit(const JsonObject& parameters, JsonObject& response) - { - LOGINFOMETHOD(); - - ctrlm_voice_iarm_call_json_t* call = NULL; - IARM_Result_t res; - string jsonParams; - bool bSuccess = true; - - // Just pass through the input parameters, without understanding or checking them. - parameters.ToString(jsonParams); - - // We must allocate the memory for the call structure. Determine what we will need. - size_t totalsize = sizeof(ctrlm_voice_iarm_call_json_t) + jsonParams.size() + 1; - call = (ctrlm_voice_iarm_call_json_t*)calloc(1, totalsize); - - if (call != NULL) - { - // Set the call structure members appropriately. - call->api_revision = CTRLM_VOICE_IARM_BUS_API_REVISION; - size_t len = jsonParams.copy(call->payload, jsonParams.size()); - call->payload[len] = '\0'; - } - else - { - LOGERR("ERROR - Cannot allocate IARM structure - size: %u.", (unsigned)totalsize); - bSuccess = false; - } - - if (bSuccess) - { - // Make the IARM call to controlMgr to configure the voice settings - res = IARM_Bus_Call(CTRLM_MAIN_IARM_BUS_NAME, CTRLM_VOICE_IARM_CALL_SET_VOICE_INIT, (void *)call, totalsize); - if (res != IARM_RESULT_SUCCESS) - { - LOGERR("ERROR - CTRLM_VOICE_IARM_CALL_SET_VOICE_INIT Bus Call FAILED, res: %d.", (int)res); - bSuccess = false; - } - else - { - JsonObject result; - - result.FromString(call->result); - bSuccess = result["success"].Boolean(); - response = std::move(result); - if(bSuccess) { - LOGINFO("SET_VOICE_INIT call SUCCESS!"); - } else { - LOGERR("ERROR - CTRLM_VOICE_IARM_CALL_SET_VOICE_INIT returned FAILURE!"); - } - } - } - - if (call != NULL) - { - free(call); - } - - returnResponse(bSuccess); - } - - - uint32_t VoiceControl::sendVoiceMessage(const JsonObject& parameters, JsonObject& response) - { - LOGINFOMETHOD(); - - ctrlm_voice_iarm_call_json_t* call = NULL; - IARM_Result_t res; - string jsonParams; - bool bSuccess = true; - - // Just pass through the input parameters, without understanding or checking them. - parameters.ToString(jsonParams); - - // We must allocate the memory for the call structure. Determine what we will need. - size_t totalsize = sizeof(ctrlm_voice_iarm_call_json_t) + jsonParams.size() + 1; - call = (ctrlm_voice_iarm_call_json_t*)calloc(1, totalsize); - - if (call != NULL) - { - // Set the call structure members appropriately. - call->api_revision = CTRLM_VOICE_IARM_BUS_API_REVISION; - size_t len = jsonParams.copy(call->payload, jsonParams.size()); - call->payload[len] = '\0'; - } - else - { - LOGERR("ERROR - Cannot allocate IARM structure - size: %u.", (unsigned)totalsize); - bSuccess = false; - } - - if (bSuccess) - { - // Make the IARM call to controlMgr to configure the voice settings - res = IARM_Bus_Call(CTRLM_MAIN_IARM_BUS_NAME, CTRLM_VOICE_IARM_CALL_SEND_VOICE_MESSAGE, (void *)call, totalsize); - if (res != IARM_RESULT_SUCCESS) - { - LOGERR("ERROR - CTRLM_VOICE_IARM_CALL_SEND_VOICE_MESSAGE Bus Call FAILED, res: %d.", (int)res); - bSuccess = false; - } - else - { - JsonObject result; - - result.FromString(call->result); - bSuccess = result["success"].Boolean(); - response = std::move(result); - if(bSuccess) { - LOGINFO("SEND_VOICE_MESSAGE call SUCCESS!"); - } else { - LOGERR("ERROR - CTRLM_VOICE_IARM_CALL_SEND_VOICE_MESSAGE returned FAILURE!"); - } - } - } - - if (call != NULL) - { - free(call); - } - - returnResponse(bSuccess); - } - - uint32_t VoiceControl::voiceSessionByText(const JsonObject& parameters, JsonObject& response) // DEPRECATED - { - // Translate the input parameters then call voiceSessionRequest - JsonObject parameters_translated; - - if(!parameters.HasLabel("type")) { - parameters_translated["type"] = "ptt_transcription"; - } else { - std::string str_type = parameters["type"].String(); - transform(str_type.begin(), str_type.end(), str_type.begin(), ::tolower); - if(str_type == "ptt") { - parameters_translated["type"] = "ptt_transcription"; - } else if(str_type == "ff") { - parameters_translated["type"] = "ff_transcription"; - } else if(str_type == "mic") { - parameters_translated["type"] = "mic_transcription"; - } else { - parameters_translated["type"] = ""; - } - } - if(parameters.HasLabel("transcription")) { - parameters_translated["transcription"] = parameters["transcription"]; - } // else voiceSessionRequest will return an error if transcription field is not present - - return(voiceSessionRequest(parameters_translated, response)); - } - - uint32_t VoiceControl::voiceSessionTypes(const JsonObject& parameters, JsonObject& response) - { - LOGINFOMETHOD(); - - ctrlm_voice_iarm_call_json_t* call = NULL; - IARM_Result_t res; - string jsonParams; - bool bSuccess = true; - - // Just pass through the input parameters, without understanding or checking them. - parameters.ToString(jsonParams); - - // We must allocate the memory for the call structure. Determine what we will need. - size_t totalsize = sizeof(ctrlm_voice_iarm_call_json_t) + jsonParams.size() + 1; - call = (ctrlm_voice_iarm_call_json_t*)calloc(1, totalsize); - - if (call != NULL) - { - // Set the call structure members appropriately. - call->api_revision = CTRLM_VOICE_IARM_BUS_API_REVISION; - size_t len = jsonParams.copy(call->payload, jsonParams.size()); - call->payload[len] = '\0'; - } - else - { - LOGERR("ERROR - Cannot allocate IARM structure - size: %u.", (unsigned)totalsize); - bSuccess = false; - } - - if (bSuccess) - { - // Make the IARM call to controlMgr to configure the voice settings - res = IARM_Bus_Call(CTRLM_MAIN_IARM_BUS_NAME, CTRLM_VOICE_IARM_CALL_SESSION_TYPES, (void *)call, totalsize); - if (res != IARM_RESULT_SUCCESS) - { - LOGERR("ERROR - CTRLM_VOICE_IARM_CALL_SESSION_TYPES Bus Call FAILED, res: %d.", (int)res); - bSuccess = false; - } - else - { - JsonObject result; - - result.FromString(call->result); - bSuccess = result["success"].Boolean(); - response = std::move(result); - if(bSuccess) { - LOGINFO("SESSION_TYPES call SUCCESS!"); - } else { - LOGERR("ERROR - CTRLM_VOICE_IARM_CALL_SESSION_TYPES returned FAILURE!"); - } - } - } - - if (call != NULL) - { - free(call); - } - - returnResponse(bSuccess); - } - - uint32_t VoiceControl::voiceSessionRequest(const JsonObject& parameters, JsonObject& response) - { - LOGINFOMETHOD(); - - ctrlm_voice_iarm_call_json_t* call = NULL; - IARM_Result_t res; - string jsonParams; - bool bSuccess = true; - - // Just pass through the input parameters, without understanding or checking them. - parameters.ToString(jsonParams); - - // We must allocate the memory for the call structure. Determine what we will need. - size_t totalsize = sizeof(ctrlm_voice_iarm_call_json_t) + jsonParams.size() + 1; - call = (ctrlm_voice_iarm_call_json_t*)calloc(1, totalsize); - - if (call != NULL) - { - // Set the call structure members appropriately. - call->api_revision = CTRLM_VOICE_IARM_BUS_API_REVISION; - size_t len = jsonParams.copy(call->payload, jsonParams.size()); - call->payload[len] = '\0'; - } - else - { - LOGERR("ERROR - Cannot allocate IARM structure - size: %u.", (unsigned)totalsize); - bSuccess = false; - } - - if (bSuccess) - { - // Make the IARM call to controlMgr to configure the voice settings - res = IARM_Bus_Call(CTRLM_MAIN_IARM_BUS_NAME, CTRLM_VOICE_IARM_CALL_SESSION_REQUEST, (void *)call, totalsize); - if (res != IARM_RESULT_SUCCESS) - { - LOGERR("ERROR - CTRLM_VOICE_IARM_CALL_SESSION_REQUEST Bus Call FAILED, res: %d.", (int)res); - bSuccess = false; - } - else - { - JsonObject result; - - result.FromString(call->result); - bSuccess = result["success"].Boolean(); - response = std::move(result); - if(bSuccess) { - LOGINFO("SESSION_REQUEST call SUCCESS!"); - } else { - LOGERR("ERROR - CTRLM_VOICE_IARM_CALL_SESSION_REQUEST returned FAILURE!"); - } - } - } - - if (call != NULL) - { - free(call); - } - - returnResponse(bSuccess); - } - - uint32_t VoiceControl::voiceSessionTerminate(const JsonObject& parameters, JsonObject& response) - { - LOGINFOMETHOD(); - - ctrlm_voice_iarm_call_json_t* call = NULL; - IARM_Result_t res; - string jsonParams; - bool bSuccess = true; - - // Just pass through the input parameters, without understanding or checking them. - parameters.ToString(jsonParams); - - // We must allocate the memory for the call structure. Determine what we will need. - size_t totalsize = sizeof(ctrlm_voice_iarm_call_json_t) + jsonParams.size() + 1; - call = (ctrlm_voice_iarm_call_json_t*)calloc(1, totalsize); - - if (call != NULL) - { - // Set the call structure members appropriately. - call->api_revision = CTRLM_VOICE_IARM_BUS_API_REVISION; - size_t len = jsonParams.copy(call->payload, jsonParams.size()); - call->payload[len] = '\0'; - } - else - { - LOGERR("ERROR - Cannot allocate IARM structure - size: %u.", (unsigned)totalsize); - bSuccess = false; - } - - if (bSuccess) - { - // Make the IARM call to controlMgr to configure the voice settings - res = IARM_Bus_Call(CTRLM_MAIN_IARM_BUS_NAME, CTRLM_VOICE_IARM_CALL_SESSION_TERMINATE, (void *)call, totalsize); - if (res != IARM_RESULT_SUCCESS) - { - LOGERR("ERROR - CTRLM_VOICE_IARM_CALL_SESSION_TERMINATE Bus Call FAILED, res: %d.", (int)res); - bSuccess = false; - } - else - { - JsonObject result; - - result.FromString(call->result); - bSuccess = result["success"].Boolean(); - response = std::move(result); - if(bSuccess) { - LOGINFO("SESSION_TERMINATE call SUCCESS!"); - } else { - LOGERR("ERROR - CTRLM_VOICE_IARM_CALL_SESSION_TERMINATE returned FAILURE!"); - } - } - } - - if (call != NULL) - { - free(call); - } - - returnResponse(bSuccess); - } - - uint32_t VoiceControl::voiceSessionAudioStreamStart(const JsonObject& parameters, JsonObject& response) - { - LOGINFOMETHOD(); - - ctrlm_voice_iarm_call_json_t* call = NULL; - IARM_Result_t res; - string jsonParams; - bool bSuccess = true; - - // Just pass through the input parameters, without understanding or checking them. - parameters.ToString(jsonParams); - - // We must allocate the memory for the call structure. Determine what we will need. - size_t totalsize = sizeof(ctrlm_voice_iarm_call_json_t) + jsonParams.size() + 1; - call = (ctrlm_voice_iarm_call_json_t*)calloc(1, totalsize); - - if (call != NULL) - { - // Set the call structure members appropriately. - call->api_revision = CTRLM_VOICE_IARM_BUS_API_REVISION; - size_t len = jsonParams.copy(call->payload, jsonParams.size()); - call->payload[len] = '\0'; - } - else - { - LOGERR("ERROR - Cannot allocate IARM structure - size: %u.", (unsigned)totalsize); - bSuccess = false; - } - - if (bSuccess) - { - // Make the IARM call to controlMgr to start the audio stream - res = IARM_Bus_Call(CTRLM_MAIN_IARM_BUS_NAME, CTRLM_VOICE_IARM_CALL_SESSION_AUDIO_STREAM_START, (void *)call, totalsize); - if (res != IARM_RESULT_SUCCESS) - { - LOGERR("ERROR - CTRLM_VOICE_IARM_CALL_SESSION_AUDIO_STREAM_START Bus Call FAILED, res: %d.", (int)res); - bSuccess = false; - } - else - { - JsonObject result; - - result.FromString(call->result); - bSuccess = result["success"].Boolean(); - response = std::move(result); - if(bSuccess) { - LOGINFO("SESSION_AUDIO_STREAM_START call SUCCESS!"); - } else { - LOGERR("ERROR - CTRLM_VOICE_IARM_CALL_SESSION_AUDIO_STREAM_START returned FAILURE!"); - } - } - } - - if (call != NULL) - { - free(call); - } - - returnResponse(bSuccess); - } - //End methods - - //Begin events - void VoiceControl::onSessionBegin(ctrlm_voice_iarm_event_json_t* eventData) - { - JsonObject params; - - params.FromString(eventData->payload); - - sendNotify("onSessionBegin", params); - } - - void VoiceControl::onStreamBegin(ctrlm_voice_iarm_event_json_t* eventData) - { - JsonObject params; - - params.FromString(eventData->payload); - - sendNotify("onStreamBegin", params); - } - - void VoiceControl::onKeywordVerification(ctrlm_voice_iarm_event_json_t* eventData) - { - JsonObject params; - - params.FromString(eventData->payload); - - sendNotify("onKeywordVerification", params); - } - - void VoiceControl::onServerMessage(ctrlm_voice_iarm_event_json_t* eventData) - { - JsonObject params; - - params.FromString(eventData->payload); - - sendNotify_("onServerMessage", params); - } - - void VoiceControl::onStreamEnd(ctrlm_voice_iarm_event_json_t* eventData) - { - JsonObject params; - - params.FromString(eventData->payload); - - sendNotify("onStreamEnd", params); - } - - void VoiceControl::onSessionEnd(ctrlm_voice_iarm_event_json_t* eventData) - { - JsonObject params; - - params.FromString(eventData->payload); - - sendNotify_("onSessionEnd", params); - } - //End events - - //Begin local private utility methods - void VoiceControl::setApiVersionNumber(unsigned int apiVersionNumber) - { - LOGINFO("setting version: %d", (int)apiVersionNumber); - m_apiVersionNumber = apiVersionNumber; - } - - void VoiceControl::sendNotify_(const char* eventName, JsonObject& parameters) - { - if(m_maskPii) - { - sendNotifyMaskParameters(eventName, parameters); - } - else - { - sendNotify(eventName, parameters); - } - } - //End local private utility methods - - } // namespace Plugin -} // namespace WPEFramework - diff --git a/VoiceControl/VoiceControl.h b/VoiceControl/VoiceControl.h deleted file mode 100644 index 074123b..0000000 --- a/VoiceControl/VoiceControl.h +++ /dev/null @@ -1,95 +0,0 @@ -/** -* If not stated otherwise in this file or this component's LICENSE -* file the following copyright and licenses apply: -* -* Copyright 2024 RDK Management -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* -* http://www.apache.org/licenses/LICENSE-2.0 -* -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -**/ - -#pragma once - -#include "Module.h" -#include "libIBus.h" - -#include "ctrlm_ipc.h" -#include "ctrlm_ipc_voice.h" - -#define IARM_VOICECONTROL_PLUGIN_NAME "Voice_Control" - -namespace WPEFramework { - - namespace Plugin { - - class VoiceControl : public PluginHost::IPlugin, public PluginHost::JSONRPC { - private: - // We do not allow this plugin to be copied !! - VoiceControl(const VoiceControl&) = delete; - VoiceControl& operator=(const VoiceControl&) = delete; - - //Begin methods - uint32_t getApiVersionNumber(const JsonObject& parameters, JsonObject& response); - void sendNotify_(const char* eventName, JsonObject& parameters); - - uint32_t voiceStatus(const JsonObject& parameters, JsonObject& response); - uint32_t configureVoice(const JsonObject& parameters, JsonObject& response); - uint32_t setVoiceInit(const JsonObject& parameters, JsonObject& response); - uint32_t sendVoiceMessage(const JsonObject& parameters, JsonObject& response); - uint32_t voiceSessionByText(const JsonObject& parameters, JsonObject& response); // DEPRECATED - uint32_t voiceSessionTypes(const JsonObject& parameters, JsonObject& response); - uint32_t voiceSessionRequest(const JsonObject& parameters, JsonObject& response); - uint32_t voiceSessionTerminate(const JsonObject& parameters, JsonObject& response); - uint32_t voiceSessionAudioStreamStart(const JsonObject& parameters, JsonObject& response); - //End methods - - //Begin events - void onSessionBegin(ctrlm_voice_iarm_event_json_t* eventData); - void onStreamBegin(ctrlm_voice_iarm_event_json_t* eventData); - void onKeywordVerification(ctrlm_voice_iarm_event_json_t* eventData); - void onServerMessage(ctrlm_voice_iarm_event_json_t* eventData); - void onStreamEnd(ctrlm_voice_iarm_event_json_t* eventData); - void onSessionEnd(ctrlm_voice_iarm_event_json_t* eventData); - //End events - - public: - VoiceControl(); - virtual ~VoiceControl(); - //IPlugin methods - virtual const string Initialize(PluginHost::IShell* service) override; - virtual void Deinitialize(PluginHost::IShell* service) override; - virtual string Information() const override { return {}; } - - BEGIN_INTERFACE_MAP(VoiceControl) - INTERFACE_ENTRY(PluginHost::IPlugin) - INTERFACE_ENTRY(PluginHost::IDispatcher) - END_INTERFACE_MAP - - private: - void InitializeIARM(); - void DeinitializeIARM(); - // Handlers for ControlMgr BT Remote events - static void voiceEventHandler(const char *owner, IARM_EventId_t eventId, void *data, size_t len); - void iarmEventHandler(const char *owner, IARM_EventId_t eventId, void *data, size_t len); - - // Local utility methods - void setApiVersionNumber(uint32_t apiVersionNumber); - void getMaskPii_(); - public: - static VoiceControl* _instance; - private: - uint32_t m_apiVersionNumber; - bool m_hasOwnProcess; - bool m_maskPii; - }; - } // namespace Plugin -} // namespace WPEFramework