From f6650a71b7a0815ab7310f03f1390d6b5e296b5a Mon Sep 17 00:00:00 2001 From: yuvaramachandran_gurusamy Date: Wed, 10 Apr 2024 13:12:03 +0000 Subject: [PATCH 01/23] RDKTV-30016 - [miracast] Connection fails with "ENT-32203/ENT-32102/ENT-32103" after Thunder restart Signed-off-by: yuvaramachandran_gurusamy --- .../MiracastService/MiracastController.cpp | 52 ++++++++++++++++++- Miracast/RTSP/MiracastRtspMsg.cpp | 7 +++ Miracast/include/MiracastController.h | 4 ++ 3 files changed, 62 insertions(+), 1 deletion(-) diff --git a/Miracast/MiracastService/MiracastController.cpp b/Miracast/MiracastService/MiracastController.cpp index 3cc84e146d..5a798d0ba9 100644 --- a/Miracast/MiracastService/MiracastController.cpp +++ b/Miracast/MiracastService/MiracastController.cpp @@ -206,6 +206,53 @@ std::string MiracastController::parse_p2p_event_data(const char *tmpBuff, const return std::string(" "); } +std::string MiracastController::getifNameByIPv4(std::string ip_address) +{ + struct ifaddrs *ifaddrList = nullptr, *currentifa = nullptr; + int family, s; + char host[MAX_IFACE_NAME_LEN]; + std::string ifaceName = ""; + + // Get list of all network interfaces + if ( -1 == getifaddrs(&ifaddrList)) + { + MIRACASTLOG_ERROR("getifaddrs failed[%s]",strerror(errno)); + } + else + { + // Iterate through the list of network interfaces + for ( currentifa = ifaddrList; nullptr != currentifa; currentifa = currentifa->ifa_next) + { + if ( nullptr == currentifa->ifa_addr ) + { + continue; + } + family = currentifa->ifa_addr->sa_family; + // Check for IPv4 address + if ( AF_INET == family ) + { + s = getnameinfo(currentifa->ifa_addr, sizeof(struct sockaddr_in), host, MAX_IFACE_NAME_LEN, NULL, 0, NI_NUMERICHOST); + if (s != 0) + { + MIRACASTLOG_ERROR("getnameinfo failed[%s]",strerror(errno)); + break; + } + // Compare IP address with the given IP + if ( 0 == strcmp(host, ip_address.c_str())) + { + ifaceName = currentifa->ifa_name; + } + } + } + if ( nullptr != ifaddrList ) + { + freeifaddrs(ifaddrList); + ifaddrList = nullptr; + } + } + return ifaceName; +} + std::string MiracastController::start_DHCPClient(std::string interface, std::string &default_gw_ip_addr) { MIRACASTLOG_TRACE("Entering..."); @@ -484,7 +531,10 @@ MiracastError MiracastController::set_WFDParameters(void) { MIRACASTLOG_TRACE("Entering..."); MiracastError ret = MIRACAST_FAIL; - if (nullptr != m_p2p_ctrl_obj){ + if (nullptr != m_p2p_ctrl_obj) + { + std::string ifName = getifNameByIPv4("192.168.59.1"); + m_p2p_ctrl_obj->remove_GroupInterface(ifName); ret = m_p2p_ctrl_obj->set_WFDParameters(); } MIRACASTLOG_TRACE("Exiting..."); diff --git a/Miracast/RTSP/MiracastRtspMsg.cpp b/Miracast/RTSP/MiracastRtspMsg.cpp index 74d335d700..d68744b97d 100644 --- a/Miracast/RTSP/MiracastRtspMsg.cpp +++ b/Miracast/RTSP/MiracastRtspMsg.cpp @@ -1024,6 +1024,13 @@ MiracastError MiracastRTSPMsg::initiate_TCP(std::string goIP) MIRACASTLOG_ERROR("TCP Socket creation error %s", strerror(errno)); continue; } + // Set SO_REUSEADDR option + int optval = 1; + if (setsockopt(m_tcpSockfd, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(optval)) == -1) + { + MIRACASTLOG_ERROR("Failed to set SO_REUSEADDR: %s", strerror(errno)); + continue; + } #if 0 /* Bind socket */ if (bind(m_tcpSockfd, (struct sockaddr *)&addr, sizeof(addr)) < 0) diff --git a/Miracast/include/MiracastController.h b/Miracast/include/MiracastController.h index e94e865c51..1f6d34b5c3 100644 --- a/Miracast/include/MiracastController.h +++ b/Miracast/include/MiracastController.h @@ -32,6 +32,8 @@ #include #include #include +#include +#include #include #include "MiracastP2P.h" #include "MiracastLogger.h" @@ -41,6 +43,7 @@ using namespace std; using namespace MIRACAST; #define THUNDER_REQ_THREAD_CLIENT_CONNECTION_WAITTIME (30) +#define MAX_IFACE_NAME_LEN 16 class MiracastController { @@ -124,6 +127,7 @@ class MiracastController MiracastError create_ControllerFramework(std::string p2p_ctrl_iface); MiracastError destroy_ControllerFramework(void); void checkAndInitiateP2PBackendDiscovery(void); + std::string getifNameByIPv4(std::string ip_address); void set_localIp(std::string ipAddr); From 0617d3f7df3801e2213c0507769e97d551778413 Mon Sep 17 00:00:00 2001 From: yuvaramachandran_gurusamy Date: Thu, 11 Apr 2024 19:11:25 +0000 Subject: [PATCH 02/23] RDKTV-29983 - [Element-X3] ENT-32102 Error observed when trying to connect through Miracast using Redmi Device Signed-off-by: yuvaramachandran_gurusamy --- .../MiracastService/MiracastController.cpp | 27 ++++++++--- Miracast/MiracastService/MiracastService.cpp | 47 +++++++++++++++---- Miracast/MiracastService/MiracastService.h | 6 ++- Miracast/P2P/MiracastP2P.cpp | 4 +- Miracast/include/MiracastCommon.h | 5 +- Miracast/include/MiracastController.h | 1 + 6 files changed, 70 insertions(+), 20 deletions(-) diff --git a/Miracast/MiracastService/MiracastController.cpp b/Miracast/MiracastService/MiracastController.cpp index 5a798d0ba9..e70d751df0 100644 --- a/Miracast/MiracastService/MiracastController.cpp +++ b/Miracast/MiracastService/MiracastController.cpp @@ -1061,21 +1061,31 @@ void MiracastController::Controller_Thread(void *args) if (!remote_address.empty()) { src_dev_ip = remote_address; + sink_dev_ip = local_address; src_dev_mac = get_WFDSourceMACAddress();; src_dev_name = get_WFDSourceName(); - sink_dev_ip = local_address; - MIRACASTLOG_INFO("#### MCAST-TRIAGE-OK-LAUNCH LAUNCH REQ FOR SRC_NAME[%s] SRC_MAC[%s] SRC_IP[%s] SINK_IP[%s] ####", + + if (!m_connect_req_notified && src_dev_mac.empty() && src_dev_name.empty()) + { + src_dev_mac = m_groupInfo->goDevAddr; + src_dev_name = get_device_name(src_dev_mac); + set_WFDSourceMACAddress(src_dev_mac); + set_WFDSourceName(src_dev_name); + } + MIRACASTLOG_INFO("#### MCAST-TRIAGE-OK-LAUNCH LAUNCH REQ FOR SRC_NAME[%s] SRC_MAC[%s] SRC_IP[%s] SINK_IP[%s] ConnectReq[%u]####", src_dev_name.c_str(), src_dev_mac.c_str(), src_dev_ip.c_str(), - sink_dev_ip.c_str()); + sink_dev_ip.c_str(), + m_connect_req_notified); if (nullptr != m_notify_handler) { - m_notify_handler->onMiracastServiceLaunchRequest(src_dev_ip, src_dev_mac, src_dev_name, sink_dev_ip); + m_notify_handler->onMiracastServiceLaunchRequest(src_dev_ip, src_dev_mac, src_dev_name, sink_dev_ip, m_connect_req_notified ); } checkAndInitiateP2PBackendDiscovery(); session_restart_required = false; p2p_group_instance_alive = true; + m_connect_req_notified = false; } else { @@ -1104,6 +1114,7 @@ void MiracastController::Controller_Thread(void *args) controller_msgq_data.state ); p2p_group_instance_alive = false; } + m_connect_req_notified = false; } if ( true == session_restart_required ) @@ -1151,17 +1162,17 @@ void MiracastController::Controller_Thread(void *args) break; case CONTROLLER_GO_STOP_FIND: { - MIRACASTLOG_TRACE("[CONTROLLER_GO_STOP_FIND] Received\n"); + MIRACASTLOG_TRACE("[CONTROLLER_GO_STOP_FIND] Received"); } break; case CONTROLLER_GO_NEG_SUCCESS: { - MIRACASTLOG_INFO("[CONTROLLER_GO_NEG_SUCCESS] Received\n"); + MIRACASTLOG_INFO("[CONTROLLER_GO_NEG_SUCCESS] Received"); } break; case CONTROLLER_GO_GROUP_FORMATION_SUCCESS: { - MIRACASTLOG_INFO("[CONTROLLER_GO_GROUP_FORMATION_SUCCESS] Received\n"); + MIRACASTLOG_INFO("[CONTROLLER_GO_GROUP_FORMATION_SUCCESS] Received"); } break; case CONTROLLER_GO_EVENT_ERROR: @@ -1216,6 +1227,7 @@ void MiracastController::Controller_Thread(void *args) another_thunder_req_client_connection_sent = false; session_restart_required = true; p2p_group_instance_alive = false; + m_connect_req_notified = false; } break; case CONTROLLER_START_STREAMING: @@ -1748,6 +1760,7 @@ void MiracastController::notify_ConnectionRequest(std::string device_name,std::s MIRACASTLOG_INFO("#### MCAST-TRIAGE-OK-CONNECT-REQ DEVICE[%s - %s] CONNECT REQUEST RECEIVED ####", m_current_device_name.c_str(), m_current_device_mac_addr.c_str()); + m_connect_req_notified = true; if (nullptr != m_notify_handler) { m_notify_handler->onMiracastServiceClientConnectionRequest(device_mac, device_name); diff --git a/Miracast/MiracastService/MiracastService.cpp b/Miracast/MiracastService/MiracastService.cpp index f7026421e7..235954e642 100644 --- a/Miracast/MiracastService/MiracastService.cpp +++ b/Miracast/MiracastService/MiracastService.cpp @@ -401,15 +401,36 @@ namespace WPEFramework std::string requestedStatus = ""; MIRACASTLOG_INFO("Entering..!!!"); - if (parameters.HasLabel("requestStatus")) { requestedStatus = parameters["requestStatus"].String(); if (("Accept" == requestedStatus) || ("Reject" == requestedStatus)) { - m_miracast_ctrler_obj->accept_client_connection(requestedStatus); success = true; - m_eService_state = MIRACAST_SERVICE_STATE_CONNECTION_ACCEPTED; + if ( MIRACAST_SERVICE_STATE_DIRECT_LAUCH_REQUESTED == m_eService_state ) + { + if ("Accept" == requestedStatus) + { + MIRACASTLOG_INFO("#### Notifying Launch Request ####"); + onMiracastServiceLaunchRequest(m_src_dev_ip, m_src_dev_mac, m_src_dev_name, m_sink_dev_ip , true ); + m_src_dev_ip.clear(); + m_src_dev_mac.clear(); + m_src_dev_name.clear(); + m_sink_dev_ip.clear(); + } + else + { + m_miracast_ctrler_obj->restart_session_discovery(); + m_miracast_ctrler_obj->m_ePlayer_state = MIRACAST_PLAYER_STATE_IDLE; + m_eService_state = MIRACAST_SERVICE_STATE_DISCOVERABLE; + MIRACASTLOG_INFO("#### Refreshing the Session ####"); + } + } + else + { + m_miracast_ctrler_obj->accept_client_connection(requestedStatus); + m_eService_state = MIRACAST_SERVICE_STATE_CONNECTION_ACCEPTED; + } } else { @@ -845,8 +866,8 @@ namespace WPEFramework is_another_connect_request = true; MIRACASTLOG_WARNING("Another Connect Request received while casting\n"); } - - if (0 == access("/opt/miracast_autoconnect", F_OK)) + if ((MIRACAST_SERVICE_STATE_DIRECT_LAUCH_REQUESTED != m_eService_state) && + (0 == access("/opt/miracast_autoconnect", F_OK))) { std::string system_command = ""; @@ -995,11 +1016,21 @@ namespace WPEFramework return timer_retry_state; } - void MiracastService::onMiracastServiceLaunchRequest(string src_dev_ip, string src_dev_mac, string src_dev_name, string sink_dev_ip) + void MiracastService::onMiracastServiceLaunchRequest(string src_dev_ip, string src_dev_mac, string src_dev_name, string sink_dev_ip, bool is_connect_req_reported ) { - MIRACASTLOG_INFO("Entering..!!!"); + MIRACASTLOG_INFO("Entering[%u]..!!!",is_connect_req_reported); - if ( MIRACAST_SERVICE_STATE_APP_REQ_TO_ABORT_CONNECTION == m_eService_state ) + if ( !is_connect_req_reported ) + { + m_eService_state = MIRACAST_SERVICE_STATE_DIRECT_LAUCH_REQUESTED; + m_src_dev_ip = src_dev_ip; + m_src_dev_mac = src_dev_mac; + m_src_dev_name = src_dev_name; + m_sink_dev_ip = sink_dev_ip; + MIRACASTLOG_INFO("Direct Launch request has received. So need to notify connect Request"); + onMiracastServiceClientConnectionRequest( src_dev_mac, src_dev_name ); + } + else if ( MIRACAST_SERVICE_STATE_APP_REQ_TO_ABORT_CONNECTION == m_eService_state ) { MIRACASTLOG_INFO("APP_REQ_TO_ABORT_CONNECTION has requested. So no need to notify Launch Request..!!!"); //m_miracast_ctrler_obj->restart_session_discovery(); diff --git a/Miracast/MiracastService/MiracastService.h b/Miracast/MiracastService/MiracastService.h index 9dd86e5abc..bed33f29cc 100644 --- a/Miracast/MiracastService/MiracastService.h +++ b/Miracast/MiracastService/MiracastService.h @@ -74,7 +74,7 @@ namespace WPEFramework virtual void onMiracastServiceClientConnectionRequest(string client_mac, string client_name) override; virtual void onMiracastServiceClientConnectionError(string client_mac, string client_name , eMIRACAST_SERVICE_ERR_CODE error_code ) override; - virtual void onMiracastServiceLaunchRequest(string src_dev_ip, string src_dev_mac, string src_dev_name, string sink_dev_ip) override; + virtual void onMiracastServiceLaunchRequest(string src_dev_ip, string src_dev_mac, string src_dev_name, string sink_dev_ip, bool is_connect_req_reported ) override; BEGIN_INTERFACE_MAP(MiracastService) INTERFACE_ENTRY(PluginHost::IPlugin) @@ -90,6 +90,10 @@ namespace WPEFramework bool m_isServiceEnabled; guint m_FriendlyNameMonitorTimerID{0}; eMIRA_SERVICE_STATES m_eService_state; + std::string m_src_dev_ip; + std::string m_src_dev_mac; + std::string m_src_dev_name; + std::string m_sink_dev_ip; WPEFramework::JSONRPC::LinkType *m_SystemPluginObj = NULL; uint32_t setEnable(const JsonObject ¶meters, JsonObject &response); uint32_t getEnable(const JsonObject ¶meters, JsonObject &response); diff --git a/Miracast/P2P/MiracastP2P.cpp b/Miracast/P2P/MiracastP2P.cpp index 652e676352..b28744e53c 100644 --- a/Miracast/P2P/MiracastP2P.cpp +++ b/Miracast/P2P/MiracastP2P.cpp @@ -437,8 +437,8 @@ MiracastError MiracastP2P::set_WFDParameters(void) command = "SET p2p_ssid_postfix -Element-Xumo-TV"; executeCommand(command, NON_GLOBAL_INTERFACE, retBuffer); - /* Set p2p_go_intent to 15 */ - command = "SET p2p_go_intent 15"; + /* Set p2p_go_intent to 14 */ + command = "SET p2p_go_intent 14"; executeCommand(command, NON_GLOBAL_INTERFACE, retBuffer); m_isWiFiDisplayParamsEnabled = true; diff --git a/Miracast/include/MiracastCommon.h b/Miracast/include/MiracastCommon.h index f9c8ccd325..cf81298773 100644 --- a/Miracast/include/MiracastCommon.h +++ b/Miracast/include/MiracastCommon.h @@ -160,7 +160,8 @@ typedef enum emira_service_states_e MIRACAST_SERVICE_STATE_CONNECTION_ACCEPTED, MIRACAST_SERVICE_STATE_CONNECTION_ERROR, MIRACAST_SERVICE_STATE_PLAYER_LAUNCHED, - MIRACAST_SERVICE_STATE_APP_REQ_TO_ABORT_CONNECTION + MIRACAST_SERVICE_STATE_APP_REQ_TO_ABORT_CONNECTION, + MIRACAST_SERVICE_STATE_DIRECT_LAUCH_REQUESTED } eMIRA_SERVICE_STATES; typedef enum miracast_player_states_e @@ -338,7 +339,7 @@ class MiracastServiceNotifier public: virtual void onMiracastServiceClientConnectionRequest(string client_mac, string client_name) = 0; virtual void onMiracastServiceClientConnectionError(string client_mac, string client_name , eMIRACAST_SERVICE_ERR_CODE error_code ) = 0; - virtual void onMiracastServiceLaunchRequest(string src_dev_ip, string src_dev_mac, string src_dev_name, string sink_dev_ip) = 0; + virtual void onMiracastServiceLaunchRequest(string src_dev_ip, string src_dev_mac, string src_dev_name, string sink_dev_ip, bool is_connect_req_reported ) = 0; }; /** diff --git a/Miracast/include/MiracastController.h b/Miracast/include/MiracastController.h index 1f6d34b5c3..bc0c5c5183 100644 --- a/Miracast/include/MiracastController.h +++ b/Miracast/include/MiracastController.h @@ -142,6 +142,7 @@ class MiracastController bool m_connectionStatus; bool m_p2p_backend_discovery{false}; bool m_start_discovering_enabled{false}; + bool m_connect_req_notified{false}; std::string m_current_device_name; std::string m_current_device_mac_addr; From cb727ed5e87343bcd85f8463ea6513579fe30344 Mon Sep 17 00:00:00 2001 From: gomathishankar37 Date: Tue, 16 Apr 2024 17:18:53 +0530 Subject: [PATCH 03/23] RDK-47149: Maintenance manager acquires deviceInitializationContext based on eventing mechanism --- MaintenanceManager/MaintenanceManager.cpp | 222 +++++++++++++++------- MaintenanceManager/MaintenanceManager.h | 7 +- 2 files changed, 155 insertions(+), 74 deletions(-) diff --git a/MaintenanceManager/MaintenanceManager.cpp b/MaintenanceManager/MaintenanceManager.cpp index 7a702b03ea..247606c0c5 100644 --- a/MaintenanceManager/MaintenanceManager.cpp +++ b/MaintenanceManager/MaintenanceManager.cpp @@ -288,7 +288,7 @@ namespace WPEFramework { uint8_t i=0; string cmd=""; bool internetConnectStatus=false; - + std::unique_lock lck(m_callMutex); LOGINFO("Executing Maintenance tasks"); m_statusMutex.lock(); MaintenanceManager::_instance->onMaintenanceStatusChange(MAINTENANCE_STARTED); @@ -320,14 +320,35 @@ namespace WPEFramework { #if defined(ENABLE_WHOAMI) string activation_status = checkActivatedStatus(); + bool whoAmIStatus = false; if (UNSOLICITED_MAINTENANCE == g_maintenance_type) { /* WhoAmI check*/ - bool whoAmIStatus = knowWhoAmI(activation_status); + bool whoAmIStatus = knowWhoAmI(); if (whoAmIStatus) { LOGINFO("knowWhoAmI() returned successfully"); } + else { + LOGINFO("DEBUG: knowWhoAmI() returned false"); + } + } + + if (false == whoAmIStatus && activation_status != "activated") { + bool debugReturnFlag = false; + LOGINFO("DEBUG: WhoAmI() returned false & Device is not Activated already"); + g_listen_to_deviceContextUpdate = true; + LOGINFO("DEBUG: Thread Wait"); + task_thread.wait(lck); + LOGINFO("DEBUG: Resuming Thread & Setting Device Initialization Data (via Event)"); + debugReturnFlag = setDeviceInitializationContext(g_jsonRespDeviceInitialization); + if (debugReturnFlag) { + LOGINFO("DEBUG: context data set success via Event"); + } + else { + LOGINFO("DEBUG: context data set failure via Event"); + } } - if ( false == internetConnectStatus && activation_status == "activated" ) { + else if ( false == internetConnectStatus && activation_status == "activated" ) { + LOGINFO("DEBUG: No Internet and Device Already Activated"); #else if ( false == internetConnectStatus ) { #endif @@ -387,8 +408,6 @@ namespace WPEFramework { tasks.push_back(task_names_foreground[2].c_str()); tasks.push_back(task_names_foreground[3].c_str()); #endif - std::unique_lock lck(m_callMutex); - for( i = 0; i < tasks.size() && !m_abort_flag; i++) { cmd = tasks[i]; cmd += " &"; @@ -409,8 +428,9 @@ namespace WPEFramework { } #if defined(ENABLE_WHOAMI) - bool MaintenanceManager::knowWhoAmI(string &activation_status) + bool MaintenanceManager::knowWhoAmI() { + LOGINFO("DEBUG: start knoWhoAmI"); bool success = false; int retryDelay = 10; int retryCount = 0; @@ -419,79 +439,36 @@ namespace WPEFramework { PluginHost::IShell::state state; WPEFramework::JSONRPC::LinkType* thunder_client = nullptr; - do { + if ((getServiceState(m_service, secMgr_callsign, state) == Core::ERROR_NONE) && (state == PluginHost::IShell::state::ACTIVATED)) { + LOGINFO("%s is active", secMgr_callsign); - if ((getServiceState(m_service, secMgr_callsign, state) == Core::ERROR_NONE) && (state == PluginHost::IShell::state::ACTIVATED)) { - LOGINFO("%s is active", secMgr_callsign); + thunder_client=getThunderPluginHandle(secMgr_callsign_ver); + if (thunder_client != nullptr) { + JsonObject params; + JsonObject joGetResult; - thunder_client=getThunderPluginHandle(secMgr_callsign_ver); - if (thunder_client == nullptr) { - LOGINFO("Failed to get plugin handle"); - } else { - JsonObject params; - JsonObject joGetResult; - - thunder_client->Invoke(5000, "getDeviceInitializationContext", params, joGetResult); - if (joGetResult.HasLabel("success") && joGetResult["success"].Boolean()) { - static const char* kDeviceInitializationContext = "deviceInitializationContext"; - if (joGetResult.HasLabel(kDeviceInitializationContext)) { - JsonObject getInitializationContext = joGetResult[kDeviceInitializationContext].Object(); - for (const string& key : kDeviceInitContextKeyVals) { - // Retrieve deviceInitializationContext Value - string paramValue = getInitializationContext[key.c_str()].String(); - - if (!paramValue.empty()) { - if (strcmp(key.c_str(), "regionalConfigService") == 0) { - paramValue = "https://" + paramValue; - } - LOGINFO("[%s] %s : %s", kDeviceInitializationContext, key.c_str(), paramValue.c_str()); - - // Retrieve tr181 parameter from m_param_map - string rfc_parameter = m_param_map[key]; - - // Retrieve parameter data type from m_paramType_map - DATA_TYPE rfc_dataType = m_paramType_map[key]; - - // Set the RFC values for deviceInitializationContext parameters - setRFC(rfc_parameter.c_str(), paramValue.c_str(), rfc_dataType); - - if (strcmp(key.c_str(), "partnerId") == 0) { - setPartnerId(paramValue); - } - } else { - LOGINFO("Not able to fetch %s value from %s", key.c_str(), kDeviceInitializationContext); - } - } - success = true; - } else { - LOGINFO("deviceInitializationContext is not available in the response"); - } - } else { - // Get retryDelay value and sleep for that much seconds - if (joGetResult.HasLabel("retryDelay")) { - retryDelay = joGetResult["retryDelay"].Number(); - } - LOGINFO("getDeviceInitializationContext failed"); + thunder_client->Invoke(5000, "getDeviceInitializationContext", params, joGetResult); + if (joGetResult.HasLabel("success") && joGetResult["success"].Boolean()) { + static const char* kDeviceInitializationContext = "deviceInitializationContext"; + if (joGetResult.HasLabel(kDeviceInitializationContext)) { + LOGINFO("DEBUG: Proper response, set the Data via API"); + success = setDeviceInitializationContext(joGetResult); + } + else { + LOGINFO("%s is not available in the response", kDeviceInitializationContext); } } - } else { - LOGINFO("%s is not active", secMgr_callsign); - } - - retryCount++; - if (retryCount == 4 && !success) { - if (activation_status == "activated") { - LOGINFO("Device is already activated. Exiting from knowWhoAmI()"); - success = true; + else { + LOGINFO("getDeviceInitializationContext failed"); } } - - if (!success) { - LOGINFO("Retrying in %d seconds", retryDelay); - sleep(retryDelay); + else { + LOGINFO("Failed to get plugin handle"); } - - } while (!success); + } + else { + LOGINFO("%s is not active", secMgr_callsign); + } return success; } #endif @@ -607,6 +584,25 @@ namespace WPEFramework { } } + void MaintenanceManager::deviceInitializationContextEventHandler(const JsonObject& parameters) + { + if (g_listen_to_deviceContextUpdate && UNSOLICITED_MAINTENANCE == g_maintenance_type) { + LOGINFO("DEBUG: Subscribed & Maint-Type is Unsolicited"); + if (parameters.HasLabel("deviceInitializationContext")) { + LOGINFO("Listening to deviceInitializationContextUpdate Events"); + g_jsonRespDeviceInitialization = parameters; + LOGINFO("g_jsonRespDeviceInitialization: %p | parameters: %p", &g_jsonRespDeviceInitialization, ¶meters); + } + g_listen_to_deviceContextUpdate = false; + LOGINFO("DEBUG: Toggle Subscribe Flag to false and Notify"); + task_thread.notify_one(); + + } + else { + LOGINFO("onDeviceInitializationContextUpdate event is not being listened or Maintenance Type is not Unsolicited"); + } + } + void MaintenanceManager::startCriticalTasks() { LOGINFO("Starting Script /lib/rdk/StartDCM_maintaince.sh"); @@ -834,6 +830,82 @@ namespace WPEFramework { return network_available; } + bool MaintenanceManager::setDeviceInitializationContext(JsonObject response_data) { + LOGINFO("DEBUG: start set init data"); + bool setDone = false; + bool paramEmpty = false; + JsonObject getInitializationContext = response_data["deviceInitializationContext"].Object(); + for (const string& key : kDeviceInitContextKeyVals) + { + // Retrieve deviceInitializationContext Value + string paramValue = getInitializationContext[key.c_str()].String(); + + if (!paramValue.empty()) + { + if (strcmp(key.c_str(), "regionalConfigService") == 0) + { + paramValue = "https://" + paramValue; + } + LOGINFO("[deviceInitializationContext] %s : %s", key.c_str(), paramValue.c_str()); + + // Retrieve tr181 parameter from m_param_map + string rfc_parameter = m_param_map[key]; + + // Retrieve parameter data type from m_paramType_map + DATA_TYPE rfc_dataType = m_paramType_map[key]; + + // Set the RFC values for deviceInitializationContext parameters + setRFC(rfc_parameter.c_str(), paramValue.c_str(), rfc_dataType); + + if (strcmp(key.c_str(), "partnerId") == 0) + { + setPartnerId(paramValue); + } + } + else + { + LOGINFO("Not able to fetch %s value from deviceInitializationContext", key.c_str()); + paramEmpty = true; + } + } + setDone = !paramEmpty; + return setDone; + } + + bool MaintenanceManager::subscribeToDeviceInitializationEvent() { + LOGINFO("DEBUG: start subscribe call"); + int32_t status = Core::ERROR_NONE; + bool result = false; + bool subscribe_status = false; + string event = "onDeviceInitializationContextUpdate"; + const char* secMgr_callsign_ver = "org.rdk.SecManager.1"; + WPEFramework::JSONRPC::LinkType* thunder_client = nullptr; + + // subscribe to onDeviceInitializationContextUpdate event + LOGINFO("Attempting to subscribe for %s events", event.c_str()); + + thunder_client = getThunderPluginHandle(secMgr_callsign_ver); + if (thunder_client == nullptr) { + LOGINFO("Failed to get plugin handle"); + } + else { + status = thunder_client->Subscribe(5000, event, &MaintenanceManager::deviceInitializationContextEventHandler, this); + if (status == Core::ERROR_NONE) { + LOGINFO("DEBUG: Subscription Success"); + result = true; + } + } + subscribe_status = result; + if(subscribe_status) { + LOGINFO("MaintenanceManager subscribed for %s event", event.c_str()); + return true; + } + else { + LOGINFO("Failed to subscribe for %s event", event.c_str()); + return false; + } + } + MaintenanceManager::~MaintenanceManager() { MaintenanceManager::_instance = nullptr; @@ -846,7 +918,11 @@ namespace WPEFramework { m_service = service; m_service->AddRef(); - +#if defined(ENABLE_WHOAMI) + LOGINFO("DEBUG: before subscribe call"); + subscribeToDeviceInitializationEvent(); + LOGINFO("DEBUG: after subscribe call"); +#endif #if defined(USE_IARMBUS) || defined(USE_IARM_BUS) InitializeIARM(); #endif /* defined(USE_IARMBUS) || defined(USE_IARM_BUS) */ diff --git a/MaintenanceManager/MaintenanceManager.h b/MaintenanceManager/MaintenanceManager.h index 0524b4aa16..f0a7d4d2ea 100644 --- a/MaintenanceManager/MaintenanceManager.h +++ b/MaintenanceManager/MaintenanceManager.h @@ -145,7 +145,9 @@ namespace WPEFramework { #if defined(ENABLE_WHOAMI) std::map m_param_map; std::map m_paramType_map; - bool knowWhoAmI(string &activation_status); + bool knowWhoAmI(); + JsonObject g_jsonRespDeviceInitialization; + bool g_listen_to_deviceContextUpdate = false; #endif PluginHost::IShell* m_service; @@ -161,8 +163,11 @@ namespace WPEFramework { bool stopMaintenanceTasks(); bool subscribeForInternetStatusEvent(string); void internetStatusChangeEventHandler(const JsonObject& parameters); + void deviceInitializationContextEventHandler(const JsonObject& parameters); void startCriticalTasks(); bool checkNetwork(); + bool subscribeToDeviceInitializationEvent(); + bool setDeviceInitializationContext(JsonObject joGetResult); bool getActivatedStatus(bool &skipFirmwareCheck); const string checkActivatedStatus(void); int abortTask(const char*, int sig = SIGABRT); From 95a79c63ef9dea1b45a3417b44fc36b1e871156a Mon Sep 17 00:00:00 2001 From: gomathishankar37 Date: Tue, 16 Apr 2024 17:26:36 +0530 Subject: [PATCH 04/23] RDK-47149: Maintenance manager acquires deviceInitializationContext based on eventing mechanism --- MaintenanceManager/MaintenanceManager.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/MaintenanceManager/MaintenanceManager.cpp b/MaintenanceManager/MaintenanceManager.cpp index 247606c0c5..ccb60a91c4 100644 --- a/MaintenanceManager/MaintenanceManager.cpp +++ b/MaintenanceManager/MaintenanceManager.cpp @@ -323,7 +323,7 @@ namespace WPEFramework { bool whoAmIStatus = false; if (UNSOLICITED_MAINTENANCE == g_maintenance_type) { /* WhoAmI check*/ - bool whoAmIStatus = knowWhoAmI(); + whoAmIStatus = knowWhoAmI(); if (whoAmIStatus) { LOGINFO("knowWhoAmI() returned successfully"); } @@ -432,8 +432,6 @@ namespace WPEFramework { { LOGINFO("DEBUG: start knoWhoAmI"); bool success = false; - int retryDelay = 10; - int retryCount = 0; const char* secMgr_callsign = "org.rdk.SecManager"; const char* secMgr_callsign_ver = "org.rdk.SecManager.1"; PluginHost::IShell::state state; From 71547fa3b9981cbd2a1e7899600f373e05801c44 Mon Sep 17 00:00:00 2001 From: bp-tdora114 Date: Tue, 16 Apr 2024 12:46:56 +0000 Subject: [PATCH 05/23] RDKTV-28858: Getting audio output when on mute/ 0 vol when AVR was connected Reason for change:Ignore CEC messages from Unregister device Test Procedure: getHdmiCecSinkCecEnableStatus when plugin becomes active. Risks: Low Priority: P1 Signed-off-by: bp-tdora114 --- DisplaySettings/DisplaySettings.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/DisplaySettings/DisplaySettings.cpp b/DisplaySettings/DisplaySettings.cpp index b9a81c5c1b..9e48828dba 100644 --- a/DisplaySettings/DisplaySettings.cpp +++ b/DisplaySettings/DisplaySettings.cpp @@ -5590,6 +5590,15 @@ void DisplaySettings::sendMsgThread() m_timer.stop(); } } + + if(!isCecEnabled){ + try { + isCecEnabled = getHdmiCecSinkCecEnableStatus(); + } + catch (const device::Exception& err){ + LOG_DEVICE_EXCEPTION1(string("HDMI_ARC0")); + } + } if(m_subscribed) { //Need to send power on request as this timer might have started based on standby out or boot up scenario From 75760eac159bfb7e04d0a2d84901afdbf5bcbc31 Mon Sep 17 00:00:00 2001 From: Jitha James Date: Fri, 5 Apr 2024 11:06:35 +0000 Subject: [PATCH 06/23] RDKDEV-1023: Make plugin autostart configurable from recipe Reason for change: Platform specific autostart configurations to be set in platform layers Test Procedure: Build and verify. Risks: Low Signed-off-by: Jitha James --- Bluetooth/Bluetooth.conf.in | 2 +- Bluetooth/Bluetooth.config | 2 +- Bluetooth/CMakeLists.txt | 1 + DataCapture/CMakeLists.txt | 1 + DataCapture/DataCapture.conf.in | 2 +- DataCapture/DataCapture.config | 2 +- DeviceDiagnostics/CMakeLists.txt | 1 + DeviceDiagnostics/DeviceDiagnostics.conf.in | 2 +- DeviceDiagnostics/DeviceDiagnostics.config | 2 +- FrameRate/CMakeLists.txt | 1 + FrameRate/FrameRate.conf.in | 2 +- FrameRate/FrameRate.config | 2 +- FrontPanel/CMakeLists.txt | 1 + FrontPanel/FrontPanel.conf.in | 2 +- FrontPanel/FrontPanel.config | 2 +- HdmiCec_2/CMakeLists.txt | 1 + HdmiCec_2/HdmiCec_2.conf.in | 2 +- HdmiCec_2/HdmiCec_2.config | 2 +- LoggingPreferences/CMakeLists.txt | 1 + LoggingPreferences/LoggingPreferences.conf.in | 2 +- LoggingPreferences/LoggingPreferences.config | 2 +- ScreenCapture/CMakeLists.txt | 1 + ScreenCapture/ScreenCapture.conf.in | 2 +- ScreenCapture/ScreenCapture.config | 2 +- Timer/CMakeLists.txt | 1 + Timer/Timer.conf.in | 2 +- Timer/Timer.config | 2 +- UsbAccess/CMakeLists.txt | 1 + UsbAccess/UsbAccess.conf.in | 2 +- UsbAccess/UsbAccess.config | 2 +- UserPreferences/CMakeLists.txt | 1 + UserPreferences/UserPreferences.conf.in | 2 +- UserPreferences/UserPreferences.config | 2 +- Warehouse/CMakeLists.txt | 1 + Warehouse/Warehouse.conf.in | 2 +- Warehouse/Warehouse.config | 2 +- 36 files changed, 36 insertions(+), 24 deletions(-) diff --git a/Bluetooth/Bluetooth.conf.in b/Bluetooth/Bluetooth.conf.in index 96b642f197..9949b7d1c0 100644 --- a/Bluetooth/Bluetooth.conf.in +++ b/Bluetooth/Bluetooth.conf.in @@ -1,4 +1,4 @@ precondition = ["Platform"] callsign = "org.rdk.Bluetooth" -autostart = "false" +autostart = "@PLUGIN_BLUETOOTH_AUTOSTART@" startuporder = "@PLUGIN_BLUETOOTH_STARTUPORDER@" diff --git a/Bluetooth/Bluetooth.config b/Bluetooth/Bluetooth.config index 44f233fefc..9f8ebf09c2 100644 --- a/Bluetooth/Bluetooth.config +++ b/Bluetooth/Bluetooth.config @@ -1,4 +1,4 @@ -set (autostart false) +set (autostart ${PLUGIN_BLUETOOTH_AUTOSTART}) set (preconditions Platform) set (callsign "org.rdk.Bluetooth") diff --git a/Bluetooth/CMakeLists.txt b/Bluetooth/CMakeLists.txt index 74db574382..4d404517c0 100644 --- a/Bluetooth/CMakeLists.txt +++ b/Bluetooth/CMakeLists.txt @@ -19,6 +19,7 @@ set(PLUGIN_NAME Bluetooth) set(MODULE_NAME ${NAMESPACE}${PLUGIN_NAME}) set(PLUGIN_BLUETOOTH_STARTUPORDER "" CACHE STRING "To configure startup order of Bluetooth plugin") +set(PLUGIN_BLUETOOTH_AUTOSTART false CACHE STRING "To automatically start Bluetooth plugin.") find_package(${NAMESPACE}Plugins REQUIRED) diff --git a/DataCapture/CMakeLists.txt b/DataCapture/CMakeLists.txt index 01fdfb7a43..f94fceebb1 100644 --- a/DataCapture/CMakeLists.txt +++ b/DataCapture/CMakeLists.txt @@ -19,6 +19,7 @@ set(PLUGIN_NAME DataCapture) set(MODULE_NAME ${NAMESPACE}${PLUGIN_NAME}) set(PLUGIN_DATACAPTURE_STARTUPORDER "" CACHE STRING "To configure startup order of DataCapture plugin") +set(PLUGIN_DATACAPTURE_AUTOSTART false CACHE STRING "To automatically start DataCapture plugin.") find_package(${NAMESPACE}Plugins REQUIRED) diff --git a/DataCapture/DataCapture.conf.in b/DataCapture/DataCapture.conf.in index b39fa0ac33..d167343c76 100644 --- a/DataCapture/DataCapture.conf.in +++ b/DataCapture/DataCapture.conf.in @@ -1,4 +1,4 @@ precondition = ["Platform"] callsign = "org.rdk.dataCapture" -autostart = "false" +autostart = "@PLUGIN_DATACAPTURE_AUTOSTART@" startuporder = "@PLUGIN_DATACAPTURE_STARTUPORDER@" diff --git a/DataCapture/DataCapture.config b/DataCapture/DataCapture.config index c47d8c391c..cf9e542769 100644 --- a/DataCapture/DataCapture.config +++ b/DataCapture/DataCapture.config @@ -1,4 +1,4 @@ -set (autostart false) +set (autostart ${PLUGIN_DATACAPTURE_AUTOSTART}) set (preconditions Platform) set (callsign org.rdk.dataCapture) diff --git a/DeviceDiagnostics/CMakeLists.txt b/DeviceDiagnostics/CMakeLists.txt index 085975c5e0..e85ec655b7 100644 --- a/DeviceDiagnostics/CMakeLists.txt +++ b/DeviceDiagnostics/CMakeLists.txt @@ -19,6 +19,7 @@ set(PLUGIN_NAME DeviceDiagnostics) set(MODULE_NAME ${NAMESPACE}${PLUGIN_NAME}) set(PLUGIN_DEVICEDIAGNOSTICS_STARTUPORDER "" CACHE STRING "To configure startup order of DeviceDiagnostics plugin") +set(PLUGIN_DEVICEDIAGNOSTICS_AUTOSTART false CACHE STRING "To automatically start DeviceDiagnostics plugin.") find_package(${NAMESPACE}Plugins REQUIRED) diff --git a/DeviceDiagnostics/DeviceDiagnostics.conf.in b/DeviceDiagnostics/DeviceDiagnostics.conf.in index 5db513bf33..b8e8dace07 100644 --- a/DeviceDiagnostics/DeviceDiagnostics.conf.in +++ b/DeviceDiagnostics/DeviceDiagnostics.conf.in @@ -1,4 +1,4 @@ precondition = ["Platform"] callsign = "org.rdk.DeviceDiagnostics" -autostart = "false" +autostart = "@PLUGIN_DEVICEDIAGNOSTICS_AUTOSTART@" startuporder = "@PLUGIN_DEVICEDIAGNOSTICS_STARTUPORDER@" diff --git a/DeviceDiagnostics/DeviceDiagnostics.config b/DeviceDiagnostics/DeviceDiagnostics.config index 0888e9a886..8a07319725 100644 --- a/DeviceDiagnostics/DeviceDiagnostics.config +++ b/DeviceDiagnostics/DeviceDiagnostics.config @@ -1,4 +1,4 @@ -set (autostart false) +set (autostart ${PLUGIN_DEVICEDIAGNOSTICS_AUTOSTART}) set (preconditions Platform) set (callsign "org.rdk.DeviceDiagnostics") diff --git a/FrameRate/CMakeLists.txt b/FrameRate/CMakeLists.txt index cd7c3aafca..92487dd02b 100644 --- a/FrameRate/CMakeLists.txt +++ b/FrameRate/CMakeLists.txt @@ -19,6 +19,7 @@ set(PLUGIN_NAME FrameRate) set(MODULE_NAME ${NAMESPACE}${PLUGIN_NAME}) set(PLUGIN_FRAMERATE_STARTUPORDER "" CACHE STRING "To configure startup order of FrameRate plugin") +set(PLUGIN_FRAMERATE_AUTOSTART false CACHE STRING "To automatically start FrameRate plugin.") find_package(${NAMESPACE}Plugins REQUIRED) diff --git a/FrameRate/FrameRate.conf.in b/FrameRate/FrameRate.conf.in index fddc79849e..38a5802cf6 100644 --- a/FrameRate/FrameRate.conf.in +++ b/FrameRate/FrameRate.conf.in @@ -1,4 +1,4 @@ precondition = ["Platform"] callsign = "org.rdk.FrameRate" -autostart = "false" +autostart = "@PLUGIN_FRAMERATE_AUTOSTART@" startuporder = "@PLUGIN_FRAMERATE_STARTUPORDER@" diff --git a/FrameRate/FrameRate.config b/FrameRate/FrameRate.config index 6108533aec..b842218b52 100644 --- a/FrameRate/FrameRate.config +++ b/FrameRate/FrameRate.config @@ -1,4 +1,4 @@ -set (autostart false) +set (autostart ${PLUGIN_FRAMERATE_AUTOSTART}) set (preconditions Platform) set (callsign "org.rdk.FrameRate") diff --git a/FrontPanel/CMakeLists.txt b/FrontPanel/CMakeLists.txt index 45b5a5f465..7ebda0a7d4 100644 --- a/FrontPanel/CMakeLists.txt +++ b/FrontPanel/CMakeLists.txt @@ -19,6 +19,7 @@ set(PLUGIN_NAME FrontPanel) set(MODULE_NAME ${NAMESPACE}${PLUGIN_NAME}) set(PLUGIN_FRONTPANEL_STARTUPORDER "" CACHE STRING "To configure startup order of FrontPanel plugin") +set(PLUGIN_FRONTPANEL_AUTOSTART false CACHE STRING "To automatically start FrontPanel plugin.") find_package(${NAMESPACE}Plugins REQUIRED) diff --git a/FrontPanel/FrontPanel.conf.in b/FrontPanel/FrontPanel.conf.in index 99ac9de041..d697f06f5c 100644 --- a/FrontPanel/FrontPanel.conf.in +++ b/FrontPanel/FrontPanel.conf.in @@ -1,4 +1,4 @@ precondition = ["Platform"] callsign = "org.rdk.FrontPanel" -autostart = "false" +autostart = "@PLUGIN_FRONTPANEL_AUTOSTART@" startuporder = "@PLUGIN_FRONTPANEL_STARTUPORDER@" diff --git a/FrontPanel/FrontPanel.config b/FrontPanel/FrontPanel.config index 37914fe31b..e25cd2c680 100644 --- a/FrontPanel/FrontPanel.config +++ b/FrontPanel/FrontPanel.config @@ -1,4 +1,4 @@ -set (autostart false) +set (autostart ${PLUGIN_FRONTPANEL_AUTOSTART}) set (preconditions Platform) set (callsign "org.rdk.FrontPanel") diff --git a/HdmiCec_2/CMakeLists.txt b/HdmiCec_2/CMakeLists.txt index 666a1e2b99..ffd7fe5d23 100644 --- a/HdmiCec_2/CMakeLists.txt +++ b/HdmiCec_2/CMakeLists.txt @@ -18,6 +18,7 @@ set(PLUGIN_NAME HdmiCec_2) set(MODULE_NAME ${NAMESPACE}${PLUGIN_NAME}) set(PLUGIN_HDMICEC2_STARTUPORDER "" CACHE STRING "To configure startup order of HdmiCec_2 plugin") +set(PLUGIN_HDMICEC2_AUTOSTART false CACHE STRING "To automatically start HdmiCec_2 plugin.") set_source_files_properties(HdmiCec_2.cpp PROPERTIES COMPILE_FLAGS "-fexceptions") find_package(${NAMESPACE}Plugins REQUIRED) diff --git a/HdmiCec_2/HdmiCec_2.conf.in b/HdmiCec_2/HdmiCec_2.conf.in index 3d51441363..b6e01f7e98 100644 --- a/HdmiCec_2/HdmiCec_2.conf.in +++ b/HdmiCec_2/HdmiCec_2.conf.in @@ -1,4 +1,4 @@ precondition = ["Platform"] callsign = "org.rdk.HdmiCec_2" -autostart = "false" +autostart = "@PLUGIN_HDMICEC2_AUTOSTART@" startuporder = "@PLUGIN_HDMICEC2_STARTUPORDER@" diff --git a/HdmiCec_2/HdmiCec_2.config b/HdmiCec_2/HdmiCec_2.config index 3be34983a2..df918d0c7e 100644 --- a/HdmiCec_2/HdmiCec_2.config +++ b/HdmiCec_2/HdmiCec_2.config @@ -1,4 +1,4 @@ -set (autostart false) +set (autostart ${PLUGIN_HDMICEC2_AUTOSTART}) set (preconditions Platform) set (callsign "org.rdk.HdmiCec_2") diff --git a/LoggingPreferences/CMakeLists.txt b/LoggingPreferences/CMakeLists.txt index 24a78e1393..10194bf0f9 100644 --- a/LoggingPreferences/CMakeLists.txt +++ b/LoggingPreferences/CMakeLists.txt @@ -19,6 +19,7 @@ set(PLUGIN_NAME LoggingPreferences) set(MODULE_NAME ${NAMESPACE}${PLUGIN_NAME}) set(PLUGIN_LOGGINGPREFERENCE_STARTUPORDER "" CACHE STRING "To configure startup order of LoggingPreferences plugin") +set(PLUGIN_LOGGINGPREFERENCES_AUTOSTART false CACHE STRING "To automatically start LoggingPreferences plugin.") find_package(${NAMESPACE}Plugins REQUIRED) diff --git a/LoggingPreferences/LoggingPreferences.conf.in b/LoggingPreferences/LoggingPreferences.conf.in index 6377cd2912..8379fd5ac0 100644 --- a/LoggingPreferences/LoggingPreferences.conf.in +++ b/LoggingPreferences/LoggingPreferences.conf.in @@ -1,4 +1,4 @@ precondition = ["Platform"] callsign = "org.rdk.LoggingPreferences" -autostart = "false" +autostart = "@PLUGIN_LOGGINGPREFERENCES_AUTOSTART@" startuporder = "@PLUGIN_LOGGINGPREFERENCE_STARTUPORDER@" diff --git a/LoggingPreferences/LoggingPreferences.config b/LoggingPreferences/LoggingPreferences.config index 1a8c060f8b..1bb721b42d 100644 --- a/LoggingPreferences/LoggingPreferences.config +++ b/LoggingPreferences/LoggingPreferences.config @@ -1,4 +1,4 @@ -set (autostart false) +set (autostart ${PLUGIN_LOGGINGPREFERENCES_AUTOSTART}) set (preconditions Platform) set (callsign "org.rdk.LoggingPreferences") diff --git a/ScreenCapture/CMakeLists.txt b/ScreenCapture/CMakeLists.txt index 0aa4391792..32b44b8504 100644 --- a/ScreenCapture/CMakeLists.txt +++ b/ScreenCapture/CMakeLists.txt @@ -19,6 +19,7 @@ set(PLUGIN_NAME ScreenCapture) set(MODULE_NAME ${NAMESPACE}${PLUGIN_NAME}) set(PLUGIN_SCREENCAPTURE_STARTUPORDER "" CACHE STRING "To configure startup order of ScreenCapture plugin") +set(PLUGIN_SCREENCAPTURE_AUTOSTART false CACHE STRING "To automatically start ScreenCapture plugin.") list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake") diff --git a/ScreenCapture/ScreenCapture.conf.in b/ScreenCapture/ScreenCapture.conf.in index fdfa97355f..02eed8a94e 100644 --- a/ScreenCapture/ScreenCapture.conf.in +++ b/ScreenCapture/ScreenCapture.conf.in @@ -1,4 +1,4 @@ precondition = ["Platform"] callsign = "org.rdk.ScreenCapture" -autostart = "false" +autostart = "@PLUGIN_SCREENCAPTURE_AUTOSTART@" startuporder = "@PLUGIN_SCREENCAPTURE_STARTUPORDER@" diff --git a/ScreenCapture/ScreenCapture.config b/ScreenCapture/ScreenCapture.config index 3e41b348dd..59a7793c05 100644 --- a/ScreenCapture/ScreenCapture.config +++ b/ScreenCapture/ScreenCapture.config @@ -1,4 +1,4 @@ -set (autostart false) +set (autostart ${PLUGIN_SCREENCAPTURE_AUTOSTART}) set (preconditions Platform) set (callsign "org.rdk.ScreenCapture") diff --git a/Timer/CMakeLists.txt b/Timer/CMakeLists.txt index 117598af1d..ad75ab6f65 100644 --- a/Timer/CMakeLists.txt +++ b/Timer/CMakeLists.txt @@ -19,6 +19,7 @@ set(PLUGIN_NAME Timer) set(MODULE_NAME ${NAMESPACE}${PLUGIN_NAME}) set(PLUGIN_TIMER_STARTUPORDER "" CACHE STRING "To configure startup order of Timer plugin") +set(PLUGIN_TIMER_AUTOSTART false CACHE STRING "To automatically start Timer plugin.") find_package(${NAMESPACE}Plugins REQUIRED) diff --git a/Timer/Timer.conf.in b/Timer/Timer.conf.in index ac7d2842be..d9de49f6e5 100644 --- a/Timer/Timer.conf.in +++ b/Timer/Timer.conf.in @@ -1,4 +1,4 @@ precondition = ["Platform"] callsign = "org.rdk.Timer" -autostart = "false" +autostart = "@PLUGIN_TIMER_AUTOSTART@" startuporder = "@PLUGIN_TIMER_STARTUPORDER@" diff --git a/Timer/Timer.config b/Timer/Timer.config index 838d9c6893..d7298238ad 100644 --- a/Timer/Timer.config +++ b/Timer/Timer.config @@ -1,4 +1,4 @@ -set (autostart false) +set (autostart ${PLUGIN_TIMER_AUTOSTART}) set (preconditions Platform) set (callsign "org.rdk.Timer") diff --git a/UsbAccess/CMakeLists.txt b/UsbAccess/CMakeLists.txt index 11ac8dda8d..e79aa1791a 100644 --- a/UsbAccess/CMakeLists.txt +++ b/UsbAccess/CMakeLists.txt @@ -2,6 +2,7 @@ set(PLUGIN_NAME UsbAccess) set(MODULE_NAME ${NAMESPACE}${PLUGIN_NAME}) set(PLUGIN_USBACCESS_STARTUPORDER "" CACHE STRING "To configure startup order of UsbAccess plugin") +set(PLUGIN_USBACCESS_AUTOSTART false CACHE STRING "To automatically start UsbAccess plugin.") find_package(${NAMESPACE}Plugins REQUIRED) diff --git a/UsbAccess/UsbAccess.conf.in b/UsbAccess/UsbAccess.conf.in index af4e40a00e..135a3231b2 100644 --- a/UsbAccess/UsbAccess.conf.in +++ b/UsbAccess/UsbAccess.conf.in @@ -1,4 +1,4 @@ precondition = ["Platform"] callsign = "org.rdk.UsbAccess" -autostart = "false" +autostart = "@PLUGIN_USBACCESS_AUTOSTART@" startuporder = "@PLUGIN_USBACCESS_STARTUPORDER@" diff --git a/UsbAccess/UsbAccess.config b/UsbAccess/UsbAccess.config index 2339dc91fa..0549a33ca1 100644 --- a/UsbAccess/UsbAccess.config +++ b/UsbAccess/UsbAccess.config @@ -1,4 +1,4 @@ -set (autostart false) +set (autostart ${PLUGIN_USBACCESS_AUTOSTART}) set (preconditions Platform) set (callsign "org.rdk.UsbAccess") diff --git a/UserPreferences/CMakeLists.txt b/UserPreferences/CMakeLists.txt index 73e7d172b8..02bda7cf47 100644 --- a/UserPreferences/CMakeLists.txt +++ b/UserPreferences/CMakeLists.txt @@ -19,6 +19,7 @@ set(PLUGIN_NAME UserPreferences) set(MODULE_NAME ${NAMESPACE}${PLUGIN_NAME}) set(PLUGIN_USERPREFERENCE_STARTUPORDER "" CACHE STRING "To configure startup order of UserPreferences plugin") +set(PLUGIN_USERPREFERENCES_AUTOSTART false CACHE STRING "To automatically start UserPreferences plugin.") find_package(${NAMESPACE}Plugins REQUIRED) find_package(DS) diff --git a/UserPreferences/UserPreferences.conf.in b/UserPreferences/UserPreferences.conf.in index dc4d89ec96..4cc2855096 100644 --- a/UserPreferences/UserPreferences.conf.in +++ b/UserPreferences/UserPreferences.conf.in @@ -1,4 +1,4 @@ precondition = ["Platform"] callsign = "org.rdk.UserPreferences" -autostart = "false" +autostart = "@PLUGIN_USERPREFERENCES_AUTOSTART@" startuporder = "@PLUGIN_USERPREFERENCE_STARTUPORDER@" diff --git a/UserPreferences/UserPreferences.config b/UserPreferences/UserPreferences.config index 27f837d937..895be297c1 100644 --- a/UserPreferences/UserPreferences.config +++ b/UserPreferences/UserPreferences.config @@ -1,4 +1,4 @@ -set (autostart false) +set (autostart ${PLUGIN_USERPREFERENCES_AUTOSTART}) set (preconditions Platform) set (callsign "org.rdk.UserPreferences") diff --git a/Warehouse/CMakeLists.txt b/Warehouse/CMakeLists.txt index f1ba7b7043..8975252513 100644 --- a/Warehouse/CMakeLists.txt +++ b/Warehouse/CMakeLists.txt @@ -19,6 +19,7 @@ set(PLUGIN_NAME Warehouse) set(MODULE_NAME ${NAMESPACE}${PLUGIN_NAME}) set(PLUGIN_WAREHOUSE_STARTUPORDER "" CACHE STRING "To configure startup order of Warehouse plugin") +set(PLUGIN_WAREHOUSE_AUTOSTART false CACHE STRING "To automatically start Warehouse plugin.") find_package(${NAMESPACE}Plugins REQUIRED) diff --git a/Warehouse/Warehouse.conf.in b/Warehouse/Warehouse.conf.in index c3aa6a3588..3322d30ca6 100644 --- a/Warehouse/Warehouse.conf.in +++ b/Warehouse/Warehouse.conf.in @@ -1,4 +1,4 @@ precondition = ["Platform"] callsign = "org.rdk.Warehouse" -autostart = "false" +autostart = "@PLUGIN_WAREHOUSE_AUTOSTART@" startuporder = "@PLUGIN_WAREHOUSE_STARTUPORDER@" diff --git a/Warehouse/Warehouse.config b/Warehouse/Warehouse.config index f4cfa9cdb4..3d761b0d23 100644 --- a/Warehouse/Warehouse.config +++ b/Warehouse/Warehouse.config @@ -1,4 +1,4 @@ -set (autostart false) +set (autostart ${PLUGIN_WAREHOUSE_AUTOSTART}) set (preconditions Platform) set (callsign "org.rdk.Warehouse") From 852d33b281a2fb82435c6517d8c898215d325ba3 Mon Sep 17 00:00:00 2001 From: selvakumar_mr Date: Fri, 19 Apr 2024 12:27:56 +0000 Subject: [PATCH 07/23] RDKDEV-1034 Make rdkservices plugin(SystemServices) autostart configurable from recipe Reason for change: Need SystemServices plugin to be made autostart true to reduce the startup delay and aid resident UI for user input handling Test Procedure: Build and verify. Risks: Low Signed-off-by: Selva Kumar MR --- SystemServices/CMakeLists.txt | 1 + SystemServices/SystemServices.conf.in | 2 +- SystemServices/SystemServices.config | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/SystemServices/CMakeLists.txt b/SystemServices/CMakeLists.txt index 1289134161..a4d5b1e756 100644 --- a/SystemServices/CMakeLists.txt +++ b/SystemServices/CMakeLists.txt @@ -18,6 +18,7 @@ set(PLUGIN_NAME SystemServices) set(MODULE_NAME ${NAMESPACE}${PLUGIN_NAME}) +set(PLUGIN_SYSTEM_AUTOSTART false CACHE STRING "To automatically start System plugin.") set(PLUGIN_SYSTEMSERVICE_STARTUPORDER "" CACHE STRING "To configure startup order of SystemServices plugin") find_package(${NAMESPACE}Plugins REQUIRED) diff --git a/SystemServices/SystemServices.conf.in b/SystemServices/SystemServices.conf.in index ead0ed6904..045ad15d60 100644 --- a/SystemServices/SystemServices.conf.in +++ b/SystemServices/SystemServices.conf.in @@ -1,4 +1,4 @@ precondition = ["Platform"] callsign = "org.rdk.System" -autostart = "false" +autostart = "@PLUGIN_SYSTEM_AUTOSTART@" startuporder = "@PLUGIN_SYSTEMSERVICE_STARTUPORDER@" diff --git a/SystemServices/SystemServices.config b/SystemServices/SystemServices.config index 52f450a28a..383ed06049 100644 --- a/SystemServices/SystemServices.config +++ b/SystemServices/SystemServices.config @@ -1,4 +1,4 @@ -set (autostart false) +set (autostart ${PLUGIN_SYSTEM_AUTOSTART}) set (preconditions Platform) set (callsign "org.rdk.System") From 751fce08c572d884a0fbd1c1ad76be2416179dac Mon Sep 17 00:00:00 2001 From: RAFI <103924677+cmuhammedrafi@users.noreply.github.com> Date: Fri, 19 Apr 2024 22:32:39 +0530 Subject: [PATCH 08/23] connectivty monitor updated (#5184) Connectivty monitor synced up with Network plugin --- .../service/NetworkConnectivity.cpp | 168 ++++++++++-------- NetworkManager/service/NetworkConnectivity.h | 16 +- 2 files changed, 99 insertions(+), 85 deletions(-) diff --git a/NetworkManager/service/NetworkConnectivity.cpp b/NetworkManager/service/NetworkConnectivity.cpp index e34688dc1c..d67e0d6a9b 100644 --- a/NetworkManager/service/NetworkConnectivity.cpp +++ b/NetworkManager/service/NetworkConnectivity.cpp @@ -178,9 +178,9 @@ namespace WPEFramework { else { if(isConnectivityMonitorEndpointSet()) - internetState = testConnectivity(getConnectivityMonitorEndpoints(), TEST_CONNECTIVITY_DEFAULT_TIMEOUT_MS, ipversion); + internetState = testConnectivity(getConnectivityMonitorEndpoints(), TEST_CONNECTIVITY_DEFAULT_TIMEOUT_MS, ipversion, true); else - internetState = testConnectivity(getConnectivityDefaultEndpoints(), TEST_CONNECTIVITY_DEFAULT_TIMEOUT_MS, ipversion); + internetState = testConnectivity(getConnectivityDefaultEndpoints(), TEST_CONNECTIVITY_DEFAULT_TIMEOUT_MS, ipversion, true); } return internetState; @@ -253,7 +253,7 @@ namespace WPEFramework { return size * nmemb; } - nsm_internetState Connectivity::testConnectivity(const std::vector& endpoints, long timeout_ms, nsm_ipversion ipversion) + nsm_internetState Connectivity::testConnectivity(const std::vector& endpoints, long timeout_ms, nsm_ipversion ipversion, bool connectOnly) { long deadline = current_time() + timeout_ms, time_now = 0, time_earlier = 0; if(endpoints.size() < 1) { @@ -288,8 +288,10 @@ namespace WPEFramework { curl_easy_setopt(curl_easy_handle, CURLOPT_HTTPHEADER, chunk); curl_easy_setopt(curl_easy_handle, CURLOPT_USERAGENT, "RDKCaptiveCheck/1.0"); /* set CURLOPT_HTTPGET option insted of CURLOPT_CONNECT_ONLY bcause we need to get the captiveportal URI not just connection only */ - /* HTTPGET request added insted of HTTPHEAD request fix for DELIA-61526 */ - curl_easy_setopt(curl_easy_handle, CURLOPT_HTTPGET, 1L); + if(connectOnly) + curl_easy_setopt(curl_easy_handle, CURLOPT_CONNECT_ONLY, 1L); + else + curl_easy_setopt(curl_easy_handle, CURLOPT_HTTPGET, 1L); /* HTTPGET request added insted of HTTPHEAD request fix for DELIA-61526 */ curl_easy_setopt(curl_easy_handle, CURLOPT_WRITEFUNCTION, writeFunction); curl_easy_setopt(curl_easy_handle, CURLOPT_TIMEOUT_MS, deadline - current_time()); if ((ipversion == CURL_IPRESOLVE_V4) || (ipversion == CURL_IPRESOLVE_V6)) @@ -309,7 +311,7 @@ namespace WPEFramework { #if LIBCURL_VERSION_NUM < 0x074200 int numfds, repeats = 0; #endif - char *endpoint; + char *endpoint = nullptr; while (1) { if (CURLM_OK != (mc = curl_multi_perform(curl_multi_handle, &handles))) @@ -324,19 +326,21 @@ namespace WPEFramework { continue; if (CURLE_OK == msg->data.result) { curl_easy_getinfo(msg->easy_handle, CURLINFO_PRIVATE, &endpoint); - if (curl_easy_getinfo(msg->easy_handle, CURLINFO_RESPONSE_CODE, &response_code) == CURLE_OK) { + if(connectOnly) + response_code = HttpStatus_204_No_Content; + else if (curl_easy_getinfo(msg->easy_handle, CURLINFO_RESPONSE_CODE, &response_code) == CURLE_OK) { if(curlVerboseEnabled()) NMLOG_INFO("endpoint = <%s> response code <%d>",endpoint, static_cast(response_code)); if (HttpStatus_302_Found == response_code) { if ( (curl_easy_getinfo(msg->easy_handle, CURLINFO_REDIRECT_URL, &url) == CURLE_OK) && url != nullptr) { - //NMLOG_WARNING("captive portal found !!!"); + NMLOG_WARNING("captive portal found !!!"); setCaptivePortal(url); } } } } else - NMLOG_TRACE("endpoint = <%s> error = %d (%s)", endpoint, msg->data.result, curl_easy_strerror(msg->data.result)); + NMLOG_TRACE("endpoint = <%s> curl error = %d (%s)", endpoint, msg->data.result, curl_easy_strerror(msg->data.result)); http_responses.push_back(response_code); } time_earlier = time_now; @@ -365,10 +369,12 @@ namespace WPEFramework { } #endif } + if(curlVerboseEnabled()) { NMLOG_INFO("endpoints count = %d response count %d, handles = %d, deadline = %ld, time_now = %ld, time_earlier = %ld", static_cast(endpoints.size()), static_cast(http_responses.size()), handles, deadline, time_now, time_earlier); } + for (const auto& curl_easy_handle : curl_easy_handles) { curl_easy_getinfo(curl_easy_handle, CURLINFO_PRIVATE, &endpoint); @@ -431,10 +437,13 @@ namespace WPEFramework { break; default: InternetConnectionState = NO_INTERNET; - NMLOG_INFO("Internet State: NO_INTERNET Response code: <%d> %.1f%%", static_cast(http_response_code), (percentage*100)); + if(http_response_code == -1) + NMLOG_ERROR("Internet State: NO_INTERNET curl error"); + else + NMLOG_INFO("Internet State: NO_INTERNET Received http response code: <%d> %.1f%%", static_cast(http_response_code), percentage * 100); + break; } } - return InternetConnectionState; } @@ -448,12 +457,11 @@ namespace WPEFramework { timeout.store(timeoutInSeconds >= MONITOR_TIMEOUT_INTERVAL_MIN ? timeoutInSeconds:defaultTimeoutInSec); - if (isMonitorThreadRunning()) + if (isMonitorThreadRunning() && stopFlag == false) { isContinuesMonitoringNeeded = true; + resetTimeout = true; cv_.notify_all(); - NMLOG_INFO("Connectivity monitor Restarted with %d", timeout.load()); - //TODO check still active } else { @@ -468,7 +476,6 @@ namespace WPEFramework { isContinuesMonitoringNeeded = true; stopFlag = false; thread_ = std::thread(&ConnectivityMonitor::connectivityMonitorFunction, this); - threadRunning = true; NMLOG_INFO("Connectivity monitor started with %d", timeout.load()); } @@ -483,7 +490,7 @@ namespace WPEFramework { return false; } - if (isMonitorThreadRunning()) + if (isMonitorThreadRunning() && stopFlag == false) { NMLOG_INFO("Connectivity Monitor Thread is active so notify"); cv_.notify_all(); @@ -501,7 +508,6 @@ namespace WPEFramework { stopFlag = false; timeout.store(timeoutInSeconds >= MONITOR_TIMEOUT_INTERVAL_MIN ? timeoutInSeconds:defaultTimeoutInSec); thread_ = std::thread(&ConnectivityMonitor::connectivityMonitorFunction, this); - threadRunning = true; NMLOG_INFO("Initial Connectivity Monitoring started with %d", timeout.load()); } @@ -510,58 +516,37 @@ namespace WPEFramework { bool ConnectivityMonitor::isMonitorThreadRunning() { - return threadRunning.load(); + return thread_.joinable(); } bool ConnectivityMonitor::stopInitialConnectivityMonitoring() { - if (isMonitorThreadRunning()) + if(isContinuesMonitoringNeeded) { - if(isContinuesMonitoringNeeded) - { - NMLOG_WARNING("Continuous Connectivity Monitor is running"); - return true; - } - else - { - stopFlag = true; - cv_.notify_all(); - - if (thread_.joinable()) { - thread_.join(); - threadRunning = false; - NMLOG_INFO("Stoping Initial Connectivity Monitor"); - } - else - NMLOG_WARNING("thread not joinable !"); - } + NMLOG_WARNING("Continuous Connectivity Monitor is running"); + return true; } - else - NMLOG_WARNING("Continuous Connectivity Monitor not running"); + stopFlag = true; + cv_.notify_all(); + + if (thread_.joinable()) + thread_.join(); + + NMLOG_INFO("Initial Connectivity Monitor stopped"); return true; } bool ConnectivityMonitor::stopContinuousConnectivityMonitoring() { - if (!isMonitorThreadRunning()) - { - NMLOG_WARNING("Connectivity monitor not running"); - return false; - } - - cv_.notify_all(); stopFlag = true; + cv_.notify_all(); if (thread_.joinable()) - { thread_.join(); - isContinuesMonitoringNeeded = false; - threadRunning = false; - NMLOG_INFO("Continuous Connectivity monitor stopped"); - } - else - NMLOG_WARNING("thread not joinable !"); + + isContinuesMonitoringNeeded = false; + NMLOG_INFO("Continuous Connectivity monitor stopped"); return true; } @@ -569,8 +554,8 @@ namespace WPEFramework { { if (isMonitorThreadRunning()) { - /* Reset the global value to UNKNOWN state*/ - resetConnectivityCache(); + /* Reset the global value to UNKNOWN state so the cache is reset */ + g_internetState = nsm_internetState::UNKNOWN; cv_.notify_all(); } } @@ -578,53 +563,82 @@ namespace WPEFramework { void ConnectivityMonitor::connectivityMonitorFunction() { nsm_internetState InternetConnectionState = nsm_internetState::UNKNOWN; + int notifyWaitCount = DEFAULT_MONITOR_RETRY_COUNT; + int tempTimeout = defaultTimeoutInSec; do { - InternetConnectionState = testConnectivity(getConnectivityMonitorEndpoints(), TEST_CONNECTIVITY_DEFAULT_TIMEOUT_MS, NSM_IPRESOLVE_WHATEVER); + if(g_internetState.load() == nsm_internetState::FULLY_CONNECTED) + /*if previous check was fully connected then do connect only curl check*/ + InternetConnectionState = testConnectivity(getConnectivityMonitorEndpoints(), TEST_CONNECTIVITY_DEFAULT_TIMEOUT_MS, NSM_IPRESOLVE_WHATEVER, true); + else + /*curl get request*/ + InternetConnectionState = testConnectivity(getConnectivityMonitorEndpoints(), TEST_CONNECTIVITY_DEFAULT_TIMEOUT_MS, NSM_IPRESOLVE_WHATEVER, false); + if(g_internetState.load() != InternetConnectionState) { - if(_instance != nullptr) + NMLOG_TRACE("notification count %d ", notifyWaitCount); + if(InternetConnectionState == nsm_internetState::NO_INTERNET && notifyWaitCount > 0) { - Exchange::INetworkManager::InternetStatus oldState = static_cast(g_internetState.load()); - Exchange::INetworkManager::InternetStatus newstate = static_cast(InternetConnectionState); - _instance->ReportInternetStatusChangedEvent(oldState , newstate); - NMLOG_TRACE("ReportInternetStatusChangedEvent called"); + /* Decrease the notification count to create a delay in posting the 'no internet' state. */ + notifyWaitCount--; + /* change the timeout value to 5 sec so that next check will happens with in 5 sec */ + tempTimeout = 5; + NMLOG_INFO("notification count change to %d timeout %d ", notifyWaitCount, tempTimeout); } else - NMLOG_WARNING("ReportInternetStatusChangedEvent callback not set"); - - g_internetState.store(InternetConnectionState); + { + g_internetState.store(InternetConnectionState); + if(_instance != nullptr) + { + Exchange::INetworkManager::InternetStatus oldState = static_cast(g_internetState.load()); + Exchange::INetworkManager::InternetStatus newstate = static_cast(InternetConnectionState); + _instance->ReportInternetStatusChangedEvent(oldState , newstate); + NMLOG_TRACE("ReportInternetStatusChangedEvent called"); + } + else + NMLOG_WARNING("ReportInternetStatusChangedEvent callback not set"); + notifyWaitCount = DEFAULT_MONITOR_RETRY_COUNT; + /* change the timeout value to actual requested value */ + tempTimeout = timeout.load(); + NMLOG_TRACE("notification count change to default %d ...", notifyWaitCount); + } } if(!isContinuesMonitoringNeeded && (g_internetState.load() == FULLY_CONNECTED)) { stopFlag = true; - NMLOG_INFO("Initial Connectivity Monitoring done Exiting ... Internet state FULLY_CONNECTED"); - threadRunning = false; + NMLOG_INFO("Initial Connectivity Monitoring done Exiting ... FULLY_CONNECTED"); break; } if(stopFlag) - { - NMLOG_WARNING("stopFlag true exiting"); - threadRunning = false; break; - } - //wait for next timout or conditon signal + // wait for next timout or conditon signal std::unique_lock lock(mutex_); - if (cv_.wait_for(lock, std::chrono::seconds(timeout.load())) == std::cv_status::timeout) - { - NMLOG_INFO("Connectivity monitor thread timeout"); - } - else + if (cv_.wait_for(lock, std::chrono::seconds(tempTimeout)) != std::cv_status::timeout) { if(!stopFlag) { - NMLOG_INFO("Connectivity monitor received a trigger"); + /* + * We don't need to notify immediately when restarting the thread. + * Immediate notification should occur only when any connection change happens. + */ + if(resetTimeout) + { + NMLOG_INFO("Connectivity monitor Restarted with %d", timeout.load()); + tempTimeout = timeout.load(); + resetTimeout = false; + } + else + { + notifyWaitCount = -1; + NMLOG_INFO("Connectivity monitor received trigger"); + } } } } while (!stopFlag); + g_internetState = nsm_internetState::UNKNOWN; NMLOG_WARNING("Connectivity monitor exiting"); } diff --git a/NetworkManager/service/NetworkConnectivity.h b/NetworkManager/service/NetworkConnectivity.h index 8b2144093c..573c1ebfd9 100644 --- a/NetworkManager/service/NetworkConnectivity.h +++ b/NetworkManager/service/NetworkConnectivity.h @@ -10,10 +10,11 @@ #include "Module.h" #include "NetworkManagerLogger.h" -#define CAPTIVEPORTAL_MAX_LEN 512 -#define DEFAULT_MONITOR_TIMEOUT 60 // in seconds -#define MONITOR_TIMEOUT_INTERVAL_MIN 5 -#define TEST_CONNECTIVITY_DEFAULT_TIMEOUT_MS 4000 +#define CAPTIVEPORTAL_MAX_LEN 512 +#define DEFAULT_MONITOR_TIMEOUT 60 // in seconds +#define MONITOR_TIMEOUT_INTERVAL_MIN 5 // in min +#define TEST_CONNECTIVITY_DEFAULT_TIMEOUT_MS 5000 // in ms +#define DEFAULT_MONITOR_RETRY_COUNT 2 // 1 failed + 2 new trys enum nsm_ipversion { NSM_IPRESOLVE_WHATEVER = 0, /* default, resolves addresses to all IP*/ @@ -82,7 +83,7 @@ namespace WPEFramework { } ~Connectivity(){} - nsm_internetState testConnectivity(const std::vector& endpoints, long timeout_ms, nsm_ipversion ipversion); + nsm_internetState testConnectivity(const std::vector& endpoints, long timeout_ms, nsm_ipversion ipversion, bool connectOnly); std::vector getConnectivityDefaultEndpoints() { return m_defaultEndpoints; }; std::string getCaptivePortal() { const std::lock_guard lock(capitiveMutex); return g_captivePortal; } void setCaptivePortal(const char* captivePortal) {const std::lock_guard lock(capitiveMutex); g_captivePortal = captivePortal; } @@ -113,9 +114,8 @@ namespace WPEFramework { bool isConnectivityMonitorEndpointSet(); bool isMonitorThreadRunning(); void signalConnectivityMonitor(); - void resetConnectivityCache() { g_internetState = nsm_internetState::UNKNOWN;} - ConnectivityMonitor() : stopFlag(false), threadRunning(false), isContinuesMonitoringNeeded(false) + ConnectivityMonitor() : stopFlag(false), resetTimeout(false), isContinuesMonitoringNeeded(false) { setConnectivityMonitorEndpoints(getConnectivityDefaultEndpoints()); } @@ -134,7 +134,7 @@ namespace WPEFramework { std::thread thread_; std::atomic stopFlag; - std::atomic threadRunning; + std::atomic resetTimeout; std::atomic isContinuesMonitoringNeeded; std::condition_variable cv_; std::atomic timeout; From b5cc4a1e8dd60c75dfd5eee1886fbbe441bd090d Mon Sep 17 00:00:00 2001 From: Gomathi Shankar Date: Mon, 22 Apr 2024 15:25:43 +0530 Subject: [PATCH 09/23] Update MaintenanceManager.cpp --- MaintenanceManager/MaintenanceManager.cpp | 37 ++++++++++------------- 1 file changed, 16 insertions(+), 21 deletions(-) diff --git a/MaintenanceManager/MaintenanceManager.cpp b/MaintenanceManager/MaintenanceManager.cpp index ccb60a91c4..9f6ab23751 100644 --- a/MaintenanceManager/MaintenanceManager.cpp +++ b/MaintenanceManager/MaintenanceManager.cpp @@ -257,9 +257,9 @@ namespace WPEFramework { /** * @brief Invoking Plugin API register to WPEFRAMEWORK. */ -#ifdef DEBUG +#ifdef Register("sampleMaintenanceManagerAPI", &MaintenanceManager::sampleAPI, this); -#endif /* DEBUG */ +#endif /* */ Register("getMaintenanceActivityStatus", &MaintenanceManager::getMaintenanceActivityStatus,this); Register("getMaintenanceStartTime", &MaintenanceManager::getMaintenanceStartTime,this); Register("setMaintenanceMode", &MaintenanceManager::setMaintenanceMode,this); @@ -328,27 +328,27 @@ namespace WPEFramework { LOGINFO("knowWhoAmI() returned successfully"); } else { - LOGINFO("DEBUG: knowWhoAmI() returned false"); + LOGINFO("knowWhoAmI() returned false"); } } if (false == whoAmIStatus && activation_status != "activated") { bool debugReturnFlag = false; - LOGINFO("DEBUG: WhoAmI() returned false & Device is not Activated already"); + LOGINFO("knoWhoAmI() returned false and Device is not already Activated"); g_listen_to_deviceContextUpdate = true; - LOGINFO("DEBUG: Thread Wait"); + LOGINFO("Waiting for thread.. "); task_thread.wait(lck); - LOGINFO("DEBUG: Resuming Thread & Setting Device Initialization Data (via Event)"); + LOGINFO("Resuming thread and Set Device Initialization Context Data (via Event Handler)"); debugReturnFlag = setDeviceInitializationContext(g_jsonRespDeviceInitialization); if (debugReturnFlag) { - LOGINFO("DEBUG: context data set success via Event"); + LOGINFO("Device Initialization Context data set via Event Handler success"); } else { - LOGINFO("DEBUG: context data set failure via Event"); + LOGINFO("Device Initilaization Context data set via Event Handler failed"); } } else if ( false == internetConnectStatus && activation_status == "activated" ) { - LOGINFO("DEBUG: No Internet and Device Already Activated"); + LOGINFO("Device is not connected to the Internet and Device is already Activated"); #else if ( false == internetConnectStatus ) { #endif @@ -430,7 +430,6 @@ namespace WPEFramework { #if defined(ENABLE_WHOAMI) bool MaintenanceManager::knowWhoAmI() { - LOGINFO("DEBUG: start knoWhoAmI"); bool success = false; const char* secMgr_callsign = "org.rdk.SecManager"; const char* secMgr_callsign_ver = "org.rdk.SecManager.1"; @@ -449,7 +448,7 @@ namespace WPEFramework { if (joGetResult.HasLabel("success") && joGetResult["success"].Boolean()) { static const char* kDeviceInitializationContext = "deviceInitializationContext"; if (joGetResult.HasLabel(kDeviceInitializationContext)) { - LOGINFO("DEBUG: Proper response, set the Data via API"); + LOGINFO("Set Device Initialization Context Data (via SecManager API)"); success = setDeviceInitializationContext(joGetResult); } else { @@ -585,19 +584,19 @@ namespace WPEFramework { void MaintenanceManager::deviceInitializationContextEventHandler(const JsonObject& parameters) { if (g_listen_to_deviceContextUpdate && UNSOLICITED_MAINTENANCE == g_maintenance_type) { - LOGINFO("DEBUG: Subscribed & Maint-Type is Unsolicited"); + LOGINFO("onDeviceInitializationContextUpdate event is already subscribed and Maintenance Type is Unsolicited Maintenance"); if (parameters.HasLabel("deviceInitializationContext")) { - LOGINFO("Listening to deviceInitializationContextUpdate Events"); + LOGINFO("Listening to onDeviceInitializationContextUpdate Events"); g_jsonRespDeviceInitialization = parameters; LOGINFO("g_jsonRespDeviceInitialization: %p | parameters: %p", &g_jsonRespDeviceInitialization, ¶meters); } g_listen_to_deviceContextUpdate = false; - LOGINFO("DEBUG: Toggle Subscribe Flag to false and Notify"); + LOGINFO("Notify waiting thread to resume.."); task_thread.notify_one(); } else { - LOGINFO("onDeviceInitializationContextUpdate event is not being listened or Maintenance Type is not Unsolicited"); + LOGINFO("onDeviceInitializationContextUpdate event is not listened already or Maintenance Type is not Unsolicited Maintenance"); } } @@ -829,7 +828,6 @@ namespace WPEFramework { } bool MaintenanceManager::setDeviceInitializationContext(JsonObject response_data) { - LOGINFO("DEBUG: start set init data"); bool setDone = false; bool paramEmpty = false; JsonObject getInitializationContext = response_data["deviceInitializationContext"].Object(); @@ -871,7 +869,6 @@ namespace WPEFramework { } bool MaintenanceManager::subscribeToDeviceInitializationEvent() { - LOGINFO("DEBUG: start subscribe call"); int32_t status = Core::ERROR_NONE; bool result = false; bool subscribe_status = false; @@ -889,7 +886,6 @@ namespace WPEFramework { else { status = thunder_client->Subscribe(5000, event, &MaintenanceManager::deviceInitializationContextEventHandler, this); if (status == Core::ERROR_NONE) { - LOGINFO("DEBUG: Subscription Success"); result = true; } } @@ -917,9 +913,8 @@ namespace WPEFramework { m_service = service; m_service->AddRef(); #if defined(ENABLE_WHOAMI) - LOGINFO("DEBUG: before subscribe call"); + LOGINFO("Initialize Device Context Event Subscription"); subscribeToDeviceInitializationEvent(); - LOGINFO("DEBUG: after subscribe call"); #endif #if defined(USE_IARMBUS) || defined(USE_IARM_BUS) InitializeIARM(); @@ -1261,7 +1256,7 @@ namespace WPEFramework { sendNotify(EVT_ONMAINTMGRSAMPLEEVENT, parameters); returnResponse(true); } -#endif /* DEBUG */ +#endif /* */ /* * @brief This function returns the status of the current From 785c57df308d05baa3fdd99eb5c7fa2c2e19df13 Mon Sep 17 00:00:00 2001 From: Gomathi Shankar Date: Mon, 22 Apr 2024 15:32:53 +0530 Subject: [PATCH 10/23] Modify MaintenanceManager.cpp --- MaintenanceManager/MaintenanceManager.cpp | 28 +++++++++++------------ 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/MaintenanceManager/MaintenanceManager.cpp b/MaintenanceManager/MaintenanceManager.cpp index 9f6ab23751..1a1c436c81 100644 --- a/MaintenanceManager/MaintenanceManager.cpp +++ b/MaintenanceManager/MaintenanceManager.cpp @@ -81,7 +81,7 @@ using namespace std; #define TR181_PARTNER_ID "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Bootstrap.PartnerName" #define TR181_TARGET_OS_CLASS "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Bootstrap.OsClass" #define TR181_XCONFURL "Device.DeviceInfo.X_RDKCENTRAL-COM_RFC.Bootstrap.XconfUrl" -#endif +#endif /* WhoAmI */ #define INTERNET_CONNECTED_STATE 3 @@ -244,7 +244,7 @@ namespace WPEFramework { "osClass", "regionalConfigService" }; -#endif +#endif /* WhoAmI */ /** * Register MaintenanceManager module as wpeframework plugin @@ -257,9 +257,9 @@ namespace WPEFramework { /** * @brief Invoking Plugin API register to WPEFRAMEWORK. */ -#ifdef +#ifdef DEBUG Register("sampleMaintenanceManagerAPI", &MaintenanceManager::sampleAPI, this); -#endif /* */ +#endif /* DEBUG */ Register("getMaintenanceActivityStatus", &MaintenanceManager::getMaintenanceActivityStatus,this); Register("getMaintenanceStartTime", &MaintenanceManager::getMaintenanceStartTime,this); Register("setMaintenanceMode", &MaintenanceManager::setMaintenanceMode,this); @@ -281,7 +281,7 @@ namespace WPEFramework { MaintenanceManager::m_paramType_map[kDeviceInitContextKeyVals[0].c_str()] = DATA_TYPE::WDMP_STRING; MaintenanceManager::m_paramType_map[kDeviceInitContextKeyVals[1].c_str()] = DATA_TYPE::WDMP_STRING; MaintenanceManager::m_paramType_map[kDeviceInitContextKeyVals[2].c_str()] = DATA_TYPE::WDMP_STRING; -#endif +#endif /* WhoAmI */ } void MaintenanceManager::task_execution_thread(){ @@ -314,7 +314,7 @@ namespace WPEFramework { /* Network check */ internetConnectStatus = isDeviceOnline(); } -#else +#else /* WhoAmI */ internetConnectStatus = isDeviceOnline(); #endif @@ -338,7 +338,7 @@ namespace WPEFramework { g_listen_to_deviceContextUpdate = true; LOGINFO("Waiting for thread.. "); task_thread.wait(lck); - LOGINFO("Resuming thread and Set Device Initialization Context Data (via Event Handler)"); + LOGINFO("Resuming thread and Set Device Initialization Context Data from SecManager onDeviceInitializationContextUpdate event"); debugReturnFlag = setDeviceInitializationContext(g_jsonRespDeviceInitialization); if (debugReturnFlag) { LOGINFO("Device Initialization Context data set via Event Handler success"); @@ -349,7 +349,7 @@ namespace WPEFramework { } else if ( false == internetConnectStatus && activation_status == "activated" ) { LOGINFO("Device is not connected to the Internet and Device is already Activated"); -#else +#else /* WhoAmI */ if ( false == internetConnectStatus ) { #endif m_statusMutex.lock(); @@ -369,7 +369,7 @@ namespace WPEFramework { LOGINFO("---------------UNSOLICITED_MAINTENANCE--------------"); #ifndef ENABLE_WHOAMI tasks.push_back(task_names_foreground[0].c_str()); -#endif +#endif /* WhoAmI */ } else if( SOLICITED_MAINTENANCE == g_maintenance_type){ LOGINFO("=============SOLICITED_MAINTENANCE==============="); @@ -448,7 +448,7 @@ namespace WPEFramework { if (joGetResult.HasLabel("success") && joGetResult["success"].Boolean()) { static const char* kDeviceInitializationContext = "deviceInitializationContext"; if (joGetResult.HasLabel(kDeviceInitializationContext)) { - LOGINFO("Set Device Initialization Context Data (via SecManager API)"); + LOGINFO("Set Device Initialization Context Data from via SecManager deviceInitializationContext API)"); success = setDeviceInitializationContext(joGetResult); } else { @@ -468,7 +468,7 @@ namespace WPEFramework { } return success; } -#endif +#endif /* WhoAmI */ // Thunder plugin communication WPEFramework::JSONRPC::LinkType* MaintenanceManager::getThunderPluginHandle(const char* callsign) @@ -596,7 +596,7 @@ namespace WPEFramework { } else { - LOGINFO("onDeviceInitializationContextUpdate event is not listened already or Maintenance Type is not Unsolicited Maintenance"); + LOGINFO("onDeviceInitializationContextUpdate event is not being listened already or Maintenance Type is not Unsolicited Maintenance"); } } @@ -915,7 +915,7 @@ namespace WPEFramework { #if defined(ENABLE_WHOAMI) LOGINFO("Initialize Device Context Event Subscription"); subscribeToDeviceInitializationEvent(); -#endif +#endif /* WhoAmI */ #if defined(USE_IARMBUS) || defined(USE_IARM_BUS) InitializeIARM(); #endif /* defined(USE_IARMBUS) || defined(USE_IARM_BUS) */ @@ -1256,7 +1256,7 @@ namespace WPEFramework { sendNotify(EVT_ONMAINTMGRSAMPLEEVENT, parameters); returnResponse(true); } -#endif /* */ +#endif /* DEBUG */ /* * @brief This function returns the status of the current From cdce2c976cf4865af79c92ce6fad963b77c2f485 Mon Sep 17 00:00:00 2001 From: Gomathi Shankar Date: Mon, 22 Apr 2024 16:46:20 +0530 Subject: [PATCH 11/23] Update MaintenanceManager.cpp --- MaintenanceManager/MaintenanceManager.cpp | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/MaintenanceManager/MaintenanceManager.cpp b/MaintenanceManager/MaintenanceManager.cpp index 1a1c436c81..32c638ab7e 100644 --- a/MaintenanceManager/MaintenanceManager.cpp +++ b/MaintenanceManager/MaintenanceManager.cpp @@ -333,18 +333,17 @@ namespace WPEFramework { } if (false == whoAmIStatus && activation_status != "activated") { - bool debugReturnFlag = false; + bool deviceContextSet = false; LOGINFO("knoWhoAmI() returned false and Device is not already Activated"); g_listen_to_deviceContextUpdate = true; - LOGINFO("Waiting for thread.. "); + LOGINFO("Waiting for onDeviceInitializationContextUpdate event"); task_thread.wait(lck); - LOGINFO("Resuming thread and Set Device Initialization Context Data from SecManager onDeviceInitializationContextUpdate event"); - debugReturnFlag = setDeviceInitializationContext(g_jsonRespDeviceInitialization); - if (debugReturnFlag) { - LOGINFO("Device Initialization Context data set via Event Handler success"); + deviceContextSet = setDeviceInitializationContext(g_jsonRespDeviceInitialization); + if (deviceContextSet) { + LOGINFO("setDeviceInitializationContext() success"); } else { - LOGINFO("Device Initilaization Context data set via Event Handler failed"); + LOGINFO("setDeviceInitializationContext() failed"); } } else if ( false == internetConnectStatus && activation_status == "activated" ) { @@ -448,7 +447,7 @@ namespace WPEFramework { if (joGetResult.HasLabel("success") && joGetResult["success"].Boolean()) { static const char* kDeviceInitializationContext = "deviceInitializationContext"; if (joGetResult.HasLabel(kDeviceInitializationContext)) { - LOGINFO("Set Device Initialization Context Data from via SecManager deviceInitializationContext API)"); + LOGINFO("%s found in the response", kDeviceInitializationContext); success = setDeviceInitializationContext(joGetResult); } else { @@ -586,12 +585,11 @@ namespace WPEFramework { if (g_listen_to_deviceContextUpdate && UNSOLICITED_MAINTENANCE == g_maintenance_type) { LOGINFO("onDeviceInitializationContextUpdate event is already subscribed and Maintenance Type is Unsolicited Maintenance"); if (parameters.HasLabel("deviceInitializationContext")) { - LOGINFO("Listening to onDeviceInitializationContextUpdate Events"); + LOGINFO("deviceInitializationContext found"); g_jsonRespDeviceInitialization = parameters; - LOGINFO("g_jsonRespDeviceInitialization: %p | parameters: %p", &g_jsonRespDeviceInitialization, ¶meters); } g_listen_to_deviceContextUpdate = false; - LOGINFO("Notify waiting thread to resume.."); + LOGINFO("Notify maintenance execution thread"); task_thread.notify_one(); } From 39df445433c22e9008b9e37d40ef6971592cd458 Mon Sep 17 00:00:00 2001 From: Gomathi Shankar Date: Mon, 22 Apr 2024 18:03:45 +0530 Subject: [PATCH 12/23] Modify MaintenanceManager.cpp --- MaintenanceManager/MaintenanceManager.cpp | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/MaintenanceManager/MaintenanceManager.cpp b/MaintenanceManager/MaintenanceManager.cpp index 32c638ab7e..ac825e5232 100644 --- a/MaintenanceManager/MaintenanceManager.cpp +++ b/MaintenanceManager/MaintenanceManager.cpp @@ -338,8 +338,7 @@ namespace WPEFramework { g_listen_to_deviceContextUpdate = true; LOGINFO("Waiting for onDeviceInitializationContextUpdate event"); task_thread.wait(lck); - deviceContextSet = setDeviceInitializationContext(g_jsonRespDeviceInitialization); - if (deviceContextSet) { + if (!g_listen_to_deviceContextUpdate) { LOGINFO("setDeviceInitializationContext() success"); } else { @@ -582,16 +581,25 @@ namespace WPEFramework { void MaintenanceManager::deviceInitializationContextEventHandler(const JsonObject& parameters) { + bool contextSet = false; if (g_listen_to_deviceContextUpdate && UNSOLICITED_MAINTENANCE == g_maintenance_type) { LOGINFO("onDeviceInitializationContextUpdate event is already subscribed and Maintenance Type is Unsolicited Maintenance"); if (parameters.HasLabel("deviceInitializationContext")) { LOGINFO("deviceInitializationContext found"); - g_jsonRespDeviceInitialization = parameters; - } - g_listen_to_deviceContextUpdate = false; - LOGINFO("Notify maintenance execution thread"); - task_thread.notify_one(); + contextSet = setDeviceInitializationContext(parameters); + if (contextSet) { + g_listen_to_deviceContextUpdate = false; + LOGINFO("Notify maintenance execution thread"); + task_thread.notify_one(); + } + else { + LOGINFO("setDeviceInitializationContext failed"); + } + } + else { + LOGINFO("deviceInitializationContext not found"); + } } else { LOGINFO("onDeviceInitializationContextUpdate event is not being listened already or Maintenance Type is not Unsolicited Maintenance"); From bcab598e58aeab206404279a843c9f747f5d3576 Mon Sep 17 00:00:00 2001 From: Gomathi Shankar Date: Mon, 22 Apr 2024 18:05:43 +0530 Subject: [PATCH 13/23] Modify MaintenanceManager.h --- MaintenanceManager/MaintenanceManager.h | 1 - 1 file changed, 1 deletion(-) diff --git a/MaintenanceManager/MaintenanceManager.h b/MaintenanceManager/MaintenanceManager.h index f0a7d4d2ea..2797530395 100644 --- a/MaintenanceManager/MaintenanceManager.h +++ b/MaintenanceManager/MaintenanceManager.h @@ -146,7 +146,6 @@ namespace WPEFramework { std::map m_param_map; std::map m_paramType_map; bool knowWhoAmI(); - JsonObject g_jsonRespDeviceInitialization; bool g_listen_to_deviceContextUpdate = false; #endif PluginHost::IShell* m_service; From 83d58e593844bcfa117b1aee90cda7cd89a69fa6 Mon Sep 17 00:00:00 2001 From: Gomathi Shankar Date: Mon, 22 Apr 2024 18:22:24 +0530 Subject: [PATCH 14/23] Update MaintenanceManager.cpp --- MaintenanceManager/MaintenanceManager.cpp | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/MaintenanceManager/MaintenanceManager.cpp b/MaintenanceManager/MaintenanceManager.cpp index ac825e5232..e603ac06db 100644 --- a/MaintenanceManager/MaintenanceManager.cpp +++ b/MaintenanceManager/MaintenanceManager.cpp @@ -338,12 +338,6 @@ namespace WPEFramework { g_listen_to_deviceContextUpdate = true; LOGINFO("Waiting for onDeviceInitializationContextUpdate event"); task_thread.wait(lck); - if (!g_listen_to_deviceContextUpdate) { - LOGINFO("setDeviceInitializationContext() success"); - } - else { - LOGINFO("setDeviceInitializationContext() failed"); - } } else if ( false == internetConnectStatus && activation_status == "activated" ) { LOGINFO("Device is not connected to the Internet and Device is already Activated"); @@ -589,12 +583,13 @@ namespace WPEFramework { contextSet = setDeviceInitializationContext(parameters); if (contextSet) { + LOGINFO("setDeviceInitializationContext() success"); g_listen_to_deviceContextUpdate = false; LOGINFO("Notify maintenance execution thread"); task_thread.notify_one(); } else { - LOGINFO("setDeviceInitializationContext failed"); + LOGINFO("setDeviceInitializationContext() failed"); } } else { From 4d3ca27d574aaa096b2549787971a87882a7da85 Mon Sep 17 00:00:00 2001 From: Gomathi Shankar Date: Mon, 22 Apr 2024 20:35:59 +0530 Subject: [PATCH 15/23] Update MaintenanceManager.cpp --- MaintenanceManager/MaintenanceManager.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/MaintenanceManager/MaintenanceManager.cpp b/MaintenanceManager/MaintenanceManager.cpp index e603ac06db..28a859fce9 100644 --- a/MaintenanceManager/MaintenanceManager.cpp +++ b/MaintenanceManager/MaintenanceManager.cpp @@ -914,7 +914,6 @@ namespace WPEFramework { m_service = service; m_service->AddRef(); #if defined(ENABLE_WHOAMI) - LOGINFO("Initialize Device Context Event Subscription"); subscribeToDeviceInitializationEvent(); #endif /* WhoAmI */ #if defined(USE_IARMBUS) || defined(USE_IARM_BUS) From 777d40f0fc29b317e6a0b56cf5a188f808677806 Mon Sep 17 00:00:00 2001 From: Nikita Poltorapavlo Date: Fri, 19 Apr 2024 17:10:08 +0300 Subject: [PATCH 16/23] DELIA-65017 : Out-of-process improvements to PersistentStore Reason for change: PersistentStore spawns 1 process. If spawning times out, activation should fail. If process crashes, plugin should deactivate. Test Procedure: None Risks: None Signed-off-by: Nikita Poltorapavlo --- .github/workflows/L2-PersistentStore-grpc.yml | 6 + .github/workflows/L2-PersistentStore.yml | 45 +++ PersistentStore/CMakeLists.txt | 3 +- PersistentStore/PersistentStore.cpp | 106 ++++--- PersistentStore/PersistentStore.h | 283 +++--------------- .../PersistentStoreImplementation.cpp | 77 +++++ .../PersistentStoreImplementation.h | 262 ++++++++++++++++ PersistentStore/PersistentStoreJsonRpc.cpp | 14 +- PersistentStore/grpc/Store2.cpp | 8 - PersistentStore/grpc/l2test/StubTest.cpp | 11 +- ....h => PersistentStoreImplementationMock.h} | 26 +- .../l0test/PersistentStoreTest.cpp | 210 ++++--------- PersistentStore/l0test/ServiceMock.h | 23 +- .../l1test/PersistentStoreTest.cpp | 2 +- PersistentStore/l1test/ServiceMock.h | 23 +- PersistentStore/sqlite/Store2.cpp | 8 - 16 files changed, 619 insertions(+), 488 deletions(-) create mode 100644 .github/workflows/L2-PersistentStore.yml create mode 100644 PersistentStore/PersistentStoreImplementation.cpp create mode 100644 PersistentStore/PersistentStoreImplementation.h delete mode 100644 PersistentStore/grpc/Store2.cpp rename PersistentStore/l0test/{Store2Mock.h => PersistentStoreImplementationMock.h} (56%) delete mode 100644 PersistentStore/sqlite/Store2.cpp diff --git a/.github/workflows/L2-PersistentStore-grpc.yml b/.github/workflows/L2-PersistentStore-grpc.yml index 4384d0fbc2..c2ca2eaf45 100644 --- a/.github/workflows/L2-PersistentStore-grpc.yml +++ b/.github/workflows/L2-PersistentStore-grpc.yml @@ -27,3 +27,9 @@ jobs: run: | cmake -S ${GITHUB_REPOSITORY}/PersistentStore/grpc/l2test -B build/grpcl2test -DCMAKE_INSTALL_PREFIX="install/usr" -DCMAKE_CXX_FLAGS="-Wall -Werror" cmake --build build/grpcl2test --target install + +# (Optional) +# Rebuild with real token (here: kToken = "Bearer TOKEN"): +# cmake --build build/grpcl2test --target install +# Run: +# PATH=${PWD}/install/usr/bin:${PATH} LD_LIBRARY_PATH=${PWD}/install/usr/lib:${LD_LIBRARY_PATH} valgrind --tool=memcheck --log-file=valgrind_log --leak-check=yes --show-reachable=yes --track-fds=yes --fair-sched=try grpcl2test diff --git a/.github/workflows/L2-PersistentStore.yml b/.github/workflows/L2-PersistentStore.yml new file mode 100644 index 0000000000..415fade572 --- /dev/null +++ b/.github/workflows/L2-PersistentStore.yml @@ -0,0 +1,45 @@ +name: L2-PersistentStore + +on: + push: + paths: + - PersistentStore/** + pull_request: + paths: + - PersistentStore/** + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v4 + with: + path: ${{github.repository}} + + - name: Install cmake, sqlite, protoc, grpc_cpp_plugin, grpc + run: | + sudo apt update + sudo apt install -y cmake libsqlite3-dev protobuf-compiler protobuf-compiler-grpc libgrpc++-dev + + - name: Build Thunder + working-directory: ${{github.workspace}} + run: sh +x ${GITHUB_REPOSITORY}/.github/workflows/BuildThunder.sh + + - name: Build + working-directory: ${{github.workspace}} + run: | + cmake -S ${GITHUB_REPOSITORY}/PersistentStore -B build/PersistentStore -DCMAKE_INSTALL_PREFIX="install/usr" -DCMAKE_CXX_FLAGS="-Wall -Werror" -DPLUGIN_PERSISTENTSTORE_PATH="/tmp/persistentstore/l2test/test" + cmake --build build/PersistentStore --target install + +# (Optional) +# Thunder startup: +# PATH=${PWD}/install/usr/bin:${PATH} LD_LIBRARY_PATH=${PWD}/install/usr/lib:${LD_LIBRARY_PATH} valgrind --tool=memcheck --log-file=valgrind_log --leak-check=yes --show-reachable=yes --track-fds=yes --fair-sched=try WPEFramework -f -c ${PWD}/install/etc/WPEFramework/config.json +# (to stop press q & enter) +# API test: +# curl -d '{"jsonrpc":"2.0","id":0,"method":"org.rdk.PersistentStore.setValue","params":{"namespace":"test","key":"key1","value":"1","ttl":100}}' http://localhost:55555/jsonrpc +# curl -d '{"jsonrpc":"2.0","id":0,"method":"org.rdk.PersistentStore.getValue","params":{"namespace":"test","key":"key1"}}' http://localhost:55555/jsonrpc +# Crash test: +# kill -SIGFPE $(pidof WPEProcess) +# Deactivate test: +# curl -d '{"jsonrpc":"2.0","id":0,"method":"Controller.1.deactivate", "params":{"callsign":"org.rdk.PersistentStore"}}' http://localhost:55555/jsonrpc diff --git a/PersistentStore/CMakeLists.txt b/PersistentStore/CMakeLists.txt index fdefac6b4f..a6fe7b596d 100644 --- a/PersistentStore/CMakeLists.txt +++ b/PersistentStore/CMakeLists.txt @@ -60,9 +60,8 @@ install(TARGETS ${MODULE_NAME} set(PLUGIN_IMPLEMENTATION ${MODULE_NAME}Implementation) add_library(${PLUGIN_IMPLEMENTATION} SHARED - sqlite/Store2.cpp - grpc/Store2.cpp Module.cpp + PersistentStoreImplementation.cpp ) target_link_libraries(${PLUGIN_IMPLEMENTATION} PRIVATE diff --git a/PersistentStore/PersistentStore.cpp b/PersistentStore/PersistentStore.cpp index cfce5e185c..f435edf26b 100644 --- a/PersistentStore/PersistentStore.cpp +++ b/PersistentStore/PersistentStore.cpp @@ -51,8 +51,20 @@ namespace Plugin { string result; ASSERT(service != nullptr); + ASSERT(_store == nullptr); + ASSERT(_store2 == nullptr); + ASSERT(_storeCache == nullptr); + ASSERT(_storeInspector == nullptr); + ASSERT(_storeLimit == nullptr); + ASSERT(_service == nullptr); + ASSERT(_connectionId == 0); - auto configLine = service->ConfigLine(); + SYSLOG(Logging::Startup, (_T("PersistentStore::Initialize: PID=%u"), getpid())); + + _service = service; + _service->AddRef(); + + auto configLine = _service->ConfigLine(); _config.FromString(configLine); { @@ -91,50 +103,70 @@ namespace Plugin { Core::SystemInfo::SetEnvironment(MAXVALUE_ENV, std::to_string(_config.MaxValue.Value())); Core::SystemInfo::SetEnvironment(LIMIT_ENV, std::to_string(_config.Limit.Value())); - uint32_t connectionId; + _service->Register(&_notification); - _deviceStore2 = service->Root(connectionId, RPC::CommunicationTimeOut, _T("SqliteStore2")); - if (_deviceStore2 != nullptr) { - _deviceStore2->Register(&_store2Sink); - _deviceStore2->Register(_store); - _deviceStoreCache = _deviceStore2->QueryInterface(); - _deviceStoreInspector = _deviceStore2->QueryInterface(); - _deviceStoreLimit = _deviceStore2->QueryInterface(); - } - - _accountStore2 = service->Root(connectionId, RPC::CommunicationTimeOut, _T("GrpcStore2")); - if (_accountStore2 != nullptr) { - _accountStore2->Register(&_store2Sink); + _store = _service->Root(_connectionId, RPC::CommunicationTimeOut, _T("PersistentStoreImplementation")); + if (_store != nullptr) { + _store2 = _store->QueryInterface(); + if (_store2 != nullptr) { + _store2->Register(&_store2Sink); + } + _storeCache = _store->QueryInterface(); + _storeInspector = _store->QueryInterface(); + _storeLimit = _store->QueryInterface(); + + ASSERT(_store2 != nullptr); + ASSERT(_storeCache != nullptr); + ASSERT(_storeInspector != nullptr); + ASSERT(_storeLimit != nullptr); + } else { + result = _T("Couldn't create implementation instance"); } return result; } - void PersistentStore::Deinitialize(PluginHost::IShell* /* service */) + void PersistentStore::Deinitialize(PluginHost::IShell* service) { - if (_deviceStore2 != nullptr) { - _deviceStore2->Unregister(&_store2Sink); - _deviceStore2->Unregister(_store); - _deviceStore2->Release(); - _deviceStore2 = nullptr; - } - if (_deviceStoreCache != nullptr) { - _deviceStoreCache->Release(); - _deviceStoreCache = nullptr; - } - if (_deviceStoreInspector != nullptr) { - _deviceStoreInspector->Release(); - _deviceStoreInspector = nullptr; - } - if (_deviceStoreLimit != nullptr) { - _deviceStoreLimit->Release(); - _deviceStoreLimit = nullptr; - } - if (_accountStore2 != nullptr) { - _accountStore2->Unregister(&_store2Sink); - _accountStore2->Release(); - _accountStore2 = nullptr; + ASSERT(_service == service); + + SYSLOG(Logging::Shutdown, (string(_T("DTV::Deinitialize")))); + + _service->Unregister(&_notification); + + if (_store != nullptr) { + if (_store2 != nullptr) { + _store2->Unregister(&_store2Sink); + _store2->Release(); + _store2 = nullptr; + } + if (_storeCache != nullptr) { + _storeCache->Release(); + _storeCache = nullptr; + } + if (_storeInspector != nullptr) { + _storeInspector->Release(); + _storeInspector = nullptr; + } + if (_storeLimit != nullptr) { + _storeLimit->Release(); + _storeLimit = nullptr; + } + + auto connection = _service->RemoteConnection(_connectionId); + VARIABLE_IS_NOT_USED auto result = _store->Release(); + _store = nullptr; + ASSERT(result == Core::ERROR_DESTRUCTION_SUCCEEDED); + if (connection != nullptr) { + connection->Terminate(); + connection->Release(); + } } + + _connectionId = 0; + _service->Release(); + _service = nullptr; + SYSLOG(Logging::Shutdown, (string(_T("PersistentStore de-initialised")))); } string PersistentStore::Information() const diff --git a/PersistentStore/PersistentStore.h b/PersistentStore/PersistentStore.h index c0886b645c..91c50655d2 100644 --- a/PersistentStore/PersistentStore.h +++ b/PersistentStore/PersistentStore.h @@ -93,243 +93,37 @@ namespace Plugin { PersistentStore& _parent; }; - // Deprecated - class Store : public Exchange::IStore, - public Exchange::IStore2::INotification { + class RemoteConnectionNotification : public RPC::IRemoteConnection::INotification { private: - Store(const Store&) = delete; - Store& operator=(const Store&) = delete; + RemoteConnectionNotification() = delete; + RemoteConnectionNotification(const RemoteConnectionNotification&) = delete; + RemoteConnectionNotification& operator=(const RemoteConnectionNotification&) = delete; public: - Store(PersistentStore& parent) + explicit RemoteConnectionNotification(PersistentStore& parent) : _parent(parent) { } - ~Store() override = default; + ~RemoteConnectionNotification() override = default; - public: - uint32_t Register(Exchange::IStore::INotification* notification) override - { - Core::SafeSyncType lock(_clientLock); - - ASSERT(std::find(_clients.begin(), _clients.end(), notification) == _clients.end()); - - notification->AddRef(); - _clients.push_back(notification); - - return Core::ERROR_NONE; - } - uint32_t Unregister(Exchange::IStore::INotification* notification) override - { - Core::SafeSyncType lock(_clientLock); - - std::list::iterator - index(std::find(_clients.begin(), _clients.end(), notification)); - - ASSERT(index != _clients.end()); - - if (index != _clients.end()) { - notification->Release(); - _clients.erase(index); - } - - return Core::ERROR_NONE; - } - uint32_t SetValue(const string& ns, const string& key, const string& value) override - { - if (_parent._deviceStore2 != nullptr) { - return _parent._deviceStore2->SetValue(Exchange::IStore2::ScopeType::DEVICE, ns, key, value, 0); - } - return Core::ERROR_NOT_SUPPORTED; - } - uint32_t GetValue(const string& ns, const string& key, string& value) override - { - if (_parent._deviceStore2 != nullptr) { - uint32_t ttl; - return _parent._deviceStore2->GetValue(Exchange::IStore2::ScopeType::DEVICE, ns, key, value, ttl); - } - return Core::ERROR_NOT_SUPPORTED; - } - uint32_t DeleteKey(const string& ns, const string& key) override - { - if (_parent._deviceStore2 != nullptr) { - return _parent._deviceStore2->DeleteKey(Exchange::IStore2::ScopeType::DEVICE, ns, key); - } - return Core::ERROR_NOT_SUPPORTED; - } - uint32_t DeleteNamespace(const string& ns) override - { - if (_parent._deviceStore2 != nullptr) { - return _parent._deviceStore2->DeleteNamespace(Exchange::IStore2::ScopeType::DEVICE, ns); - } - return Core::ERROR_NOT_SUPPORTED; - } - void ValueChanged(const Exchange::IStore2::ScopeType scope, const string& ns, const string& key, const string& value) override - { - ASSERT(scope == Exchange::IStore2::ScopeType::DEVICE); - - Core::SafeSyncType lock(_clientLock); - - std::list::iterator - index(_clients.begin()); - - while (index != _clients.end()) { - (*index)->ValueChanged(ns, key, value); - index++; - } - } - - BEGIN_INTERFACE_MAP(Store) - INTERFACE_ENTRY(Exchange::IStore) - INTERFACE_ENTRY(Exchange::IStore2::INotification) + BEGIN_INTERFACE_MAP(RemoteConnectionNotification) + INTERFACE_ENTRY(RPC::IRemoteConnection::INotification) END_INTERFACE_MAP - private: - PersistentStore& _parent; - std::list _clients; - Core::CriticalSection _clientLock; - }; - - class Store2 : public Exchange::IStore2, - public Exchange::IStoreCache, - public Exchange::IStoreInspector, - public Exchange::IStoreLimit { - private: - Store2(const Store2&) = delete; - Store2& operator=(const Store2&) = delete; - - public: - Store2(PersistentStore& parent) - : _parent(parent) - { - } - ~Store2() override = default; - - public: - uint32_t Register(INotification* notification) override - { - if (_parent._deviceStore2 != nullptr) { - _parent._deviceStore2->Register(notification); - } - if (_parent._accountStore2 != nullptr) { - _parent._accountStore2->Register(notification); - } - return Core::ERROR_NONE; - } - uint32_t Unregister(INotification* notification) override - { - if (_parent._deviceStore2 != nullptr) { - _parent._deviceStore2->Unregister(notification); - } - if (_parent._accountStore2 != nullptr) { - _parent._accountStore2->Unregister(notification); - } - return Core::ERROR_NONE; - } - uint32_t SetValue(const IStore2::ScopeType scope, const string& ns, const string& key, const string& value, const uint32_t ttl) override - { - if (scope == IStore2::ScopeType::ACCOUNT) { - if (_parent._accountStore2 != nullptr) { - return _parent._accountStore2->SetValue(scope, ns, key, value, ttl); - } - } else if (_parent._deviceStore2 != nullptr) { - return _parent._deviceStore2->SetValue(scope, ns, key, value, ttl); - } - return Core::ERROR_NOT_SUPPORTED; - } - uint32_t GetValue(const IStore2::ScopeType scope, const string& ns, const string& key, string& value, uint32_t& ttl) override - { - if (scope == IStore2::ScopeType::ACCOUNT) { - if (_parent._accountStore2 != nullptr) { - return _parent._accountStore2->GetValue(scope, ns, key, value, ttl); - } - } else if (_parent._deviceStore2 != nullptr) { - return _parent._deviceStore2->GetValue(scope, ns, key, value, ttl); - } - return Core::ERROR_NOT_SUPPORTED; - } - uint32_t DeleteKey(const IStore2::ScopeType scope, const string& ns, const string& key) override - { - if (scope == IStore2::ScopeType::ACCOUNT) { - if (_parent._accountStore2 != nullptr) { - return _parent._accountStore2->DeleteKey(scope, ns, key); - } - } else if (_parent._deviceStore2 != nullptr) { - return _parent._deviceStore2->DeleteKey(scope, ns, key); - } - return Core::ERROR_NOT_SUPPORTED; - } - uint32_t DeleteNamespace(const IStore2::ScopeType scope, const string& ns) override + void Activated(RPC::IRemoteConnection*) override { - if (scope == IStore2::ScopeType::ACCOUNT) { - if (_parent._accountStore2 != nullptr) { - return _parent._accountStore2->DeleteNamespace(scope, ns); - } - } else if (_parent._deviceStore2 != nullptr) { - return _parent._deviceStore2->DeleteNamespace(scope, ns); - } - return Core::ERROR_NOT_SUPPORTED; - } - uint32_t FlushCache() override - { - if (_parent._deviceStoreCache != nullptr) { - return _parent._deviceStoreCache->FlushCache(); - } - return Core::ERROR_NOT_SUPPORTED; } - uint32_t GetKeys(const IStoreInspector::ScopeType scope, const string& ns, RPC::IStringIterator*& keys) override + void Deactivated(RPC::IRemoteConnection* connection) override { - if (scope == IStoreInspector::ScopeType::DEVICE) { - if (_parent._deviceStoreInspector != nullptr) { - return _parent._deviceStoreInspector->GetKeys(scope, ns, keys); - } + if (connection->Id() == _parent._connectionId) { + ASSERT(_parent._service != nullptr); + Core::IWorkerPool::Instance().Schedule( + Core::Time::Now(), + PluginHost::IShell::Job::Create( + _parent._service, PluginHost::IShell::DEACTIVATED, PluginHost::IShell::FAILURE)); } - return Core::ERROR_NOT_SUPPORTED; - } - uint32_t GetNamespaces(const IStoreInspector::ScopeType scope, RPC::IStringIterator*& namespaces) override - { - if (scope == IStoreInspector::ScopeType::DEVICE) { - if (_parent._deviceStoreInspector != nullptr) { - return _parent._deviceStoreInspector->GetNamespaces(scope, namespaces); - } - } - return Core::ERROR_NOT_SUPPORTED; - } - uint32_t GetStorageSizes(const IStoreInspector::ScopeType scope, INamespaceSizeIterator*& storageList) override - { - if (scope == IStoreInspector::ScopeType::DEVICE) { - if (_parent._deviceStoreInspector != nullptr) { - return _parent._deviceStoreInspector->GetStorageSizes(scope, storageList); - } - } - return Core::ERROR_NOT_SUPPORTED; - } - uint32_t SetNamespaceStorageLimit(const IStoreLimit::ScopeType scope, const string& ns, const uint32_t size) override - { - if (scope == IStoreLimit::ScopeType::DEVICE) { - if (_parent._deviceStoreLimit != nullptr) { - return _parent._deviceStoreLimit->SetNamespaceStorageLimit(scope, ns, size); - } - } - return Core::ERROR_NOT_SUPPORTED; - } - uint32_t GetNamespaceStorageLimit(const IStoreLimit::ScopeType scope, const string& ns, uint32_t& size) override - { - if (scope == IStoreLimit::ScopeType::DEVICE) { - if (_parent._deviceStoreLimit != nullptr) { - return _parent._deviceStoreLimit->GetNamespaceStorageLimit(scope, ns, size); - } - } - return Core::ERROR_NOT_SUPPORTED; } - BEGIN_INTERFACE_MAP(Store2) - INTERFACE_ENTRY(IStore2) - INTERFACE_ENTRY(IStoreCache) - INTERFACE_ENTRY(IStoreInspector) - INTERFACE_ENTRY(IStoreLimit) - END_INTERFACE_MAP - private: PersistentStore& _parent; }; @@ -341,29 +135,21 @@ namespace Plugin { public: PersistentStore() : PluginHost::JSONRPC() - , _deviceStore2(nullptr) - , _deviceStoreCache(nullptr) - , _deviceStoreInspector(nullptr) - , _deviceStoreLimit(nullptr) - , _accountStore2(nullptr) - , _store(Core::Service::Create(*this)) - , _store2(Core::Service::Create(*this)) + , _service(nullptr) + , _connectionId(0) + , _store(nullptr) + , _store2(nullptr) + , _storeCache(nullptr) + , _storeInspector(nullptr) + , _storeLimit(nullptr) , _store2Sink(*this) + , _notification(*this) { RegisterAll(); } ~PersistentStore() override { UnregisterAll(); - - if (_store != nullptr) { - _store->Release(); - _store = nullptr; - } - if (_store2 != nullptr) { - _store2->Release(); - _store2 = nullptr; - } } BEGIN_INTERFACE_MAP(PersistentStore) @@ -371,9 +157,9 @@ namespace Plugin { INTERFACE_ENTRY(PluginHost::IDispatcher) INTERFACE_AGGREGATE(Exchange::IStore, _store) INTERFACE_AGGREGATE(Exchange::IStore2, _store2) - INTERFACE_AGGREGATE(Exchange::IStoreCache, _store2) - INTERFACE_AGGREGATE(Exchange::IStoreInspector, _store2) - INTERFACE_AGGREGATE(Exchange::IStoreLimit, _store2) + INTERFACE_AGGREGATE(Exchange::IStoreCache, _storeCache) + INTERFACE_AGGREGATE(Exchange::IStoreInspector, _storeInspector) + INTERFACE_AGGREGATE(Exchange::IStoreLimit, _storeLimit) END_INTERFACE_MAP public: @@ -404,14 +190,15 @@ namespace Plugin { private: Config _config; - Exchange::IStore2* _deviceStore2; - Exchange::IStoreCache* _deviceStoreCache; - Exchange::IStoreInspector* _deviceStoreInspector; - Exchange::IStoreLimit* _deviceStoreLimit; - Exchange::IStore2* _accountStore2; - Store* _store; // Deprecated - Store2* _store2; + PluginHost::IShell* _service; + uint32_t _connectionId; + Exchange::IStore* _store; + Exchange::IStore2* _store2; + Exchange::IStoreCache* _storeCache; + Exchange::IStoreInspector* _storeInspector; + Exchange::IStoreLimit* _storeLimit; Core::Sink _store2Sink; + Core::Sink _notification; }; } // namespace Plugin diff --git a/PersistentStore/PersistentStoreImplementation.cpp b/PersistentStore/PersistentStoreImplementation.cpp new file mode 100644 index 0000000000..8f93343328 --- /dev/null +++ b/PersistentStore/PersistentStoreImplementation.cpp @@ -0,0 +1,77 @@ +/* + * If not stated otherwise in this file or this component's LICENSE file the + * following copyright and licenses apply: + * + * Copyright 2022 RDK Management + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "PersistentStoreImplementation.h" +#include "grpc/Store2.h" +#include "sqlite/Store2.h" + +namespace WPEFramework { +namespace Plugin { + + SERVICE_REGISTRATION(PersistentStoreImplementation, 1, 0); + + PersistentStoreImplementation::PersistentStoreImplementation() + : _deviceStore2(Core::Service::Create()) + , _deviceStoreCache(nullptr) + , _deviceStoreInspector(nullptr) + , _deviceStoreLimit(nullptr) + , _accountStore2(Core::Service::Create()) + , _store2Sink(*this) + { + if (_deviceStore2 != nullptr) { + _deviceStore2->Register(&_store2Sink); + _deviceStoreCache = _deviceStore2->QueryInterface(); + _deviceStoreInspector = _deviceStore2->QueryInterface(); + _deviceStoreLimit = _deviceStore2->QueryInterface(); + } + + ASSERT(_deviceStore2 != nullptr); + ASSERT(_deviceStoreCache != nullptr); + ASSERT(_deviceStoreInspector != nullptr); + ASSERT(_deviceStoreLimit != nullptr); + ASSERT(_accountStore2 != nullptr); + } + + PersistentStoreImplementation::~PersistentStoreImplementation() + { + if (_deviceStore2 != nullptr) { + _deviceStore2->Unregister(&_store2Sink); + _deviceStore2->Release(); + _deviceStore2 = nullptr; + } + if (_deviceStoreCache != nullptr) { + _deviceStoreCache->Release(); + _deviceStoreCache = nullptr; + } + if (_deviceStoreInspector != nullptr) { + _deviceStoreInspector->Release(); + _deviceStoreInspector = nullptr; + } + if (_deviceStoreLimit != nullptr) { + _deviceStoreLimit->Release(); + _deviceStoreLimit = nullptr; + } + if (_accountStore2 != nullptr) { + _accountStore2->Release(); + _accountStore2 = nullptr; + } + } + +} // namespace Plugin +} // namespace WPEFramework diff --git a/PersistentStore/PersistentStoreImplementation.h b/PersistentStore/PersistentStoreImplementation.h new file mode 100644 index 0000000000..bf01e00632 --- /dev/null +++ b/PersistentStore/PersistentStoreImplementation.h @@ -0,0 +1,262 @@ +/* + * If not stated otherwise in this file or this component's LICENSE file the + * following copyright and licenses apply: + * + * Copyright 2022 RDK Management + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include "Module.h" +#include +#include +#include + +namespace WPEFramework { +namespace Plugin { + + class PersistentStoreImplementation : public Exchange::IStore, + public Exchange::IStore2, + public Exchange::IStoreCache, + public Exchange::IStoreInspector, + public Exchange::IStoreLimit { + private: + class Store2Notification : public IStore2::INotification { + private: + Store2Notification(const Store2Notification&) = delete; + Store2Notification& operator=(const Store2Notification&) = delete; + + public: + explicit Store2Notification(PersistentStoreImplementation& parent) + : _parent(parent) + { + } + ~Store2Notification() override = default; + + public: + void ValueChanged(const IStore2::ScopeType scope, const string& ns, const string& key, const string& value) override + { + ASSERT(scope == IStore2::ScopeType::DEVICE); + + Core::SafeSyncType lock(_parent._clientLock); + + std::list::iterator + index(_parent._clients.begin()); + + while (index != _parent._clients.end()) { + (*index)->ValueChanged(ns, key, value); + index++; + } + } + + BEGIN_INTERFACE_MAP(Store) + INTERFACE_ENTRY(IStore2::INotification) + END_INTERFACE_MAP + + private: + PersistentStoreImplementation& _parent; + }; + + private: + PersistentStoreImplementation(const PersistentStoreImplementation&) = delete; + PersistentStoreImplementation& operator=(const PersistentStoreImplementation&) = delete; + + public: + PersistentStoreImplementation(); + ~PersistentStoreImplementation() override; + + BEGIN_INTERFACE_MAP(PersistentStoreImplementation) + INTERFACE_ENTRY(IStore) + INTERFACE_ENTRY(IStore2) + INTERFACE_ENTRY(IStoreCache) + INTERFACE_ENTRY(IStoreInspector) + INTERFACE_ENTRY(IStoreLimit) + END_INTERFACE_MAP + + private: + uint32_t Register(IStore::INotification* notification) override + { + Core::SafeSyncType lock(_clientLock); + + ASSERT(std::find(_clients.begin(), _clients.end(), notification) == _clients.end()); + + notification->AddRef(); + _clients.push_back(notification); + + return Core::ERROR_NONE; + } + uint32_t Unregister(IStore::INotification* notification) override + { + Core::SafeSyncType lock(_clientLock); + + std::list::iterator + index(std::find(_clients.begin(), _clients.end(), notification)); + + ASSERT(index != _clients.end()); + + if (index != _clients.end()) { + notification->Release(); + _clients.erase(index); + } + + return Core::ERROR_NONE; + } + uint32_t SetValue(const string& ns, const string& key, const string& value) override + { + return SetValue(IStore2::ScopeType::DEVICE, ns, key, value, 0); + } + uint32_t GetValue(const string& ns, const string& key, string& value) override + { + uint32_t ttl; + return GetValue(IStore2::ScopeType::DEVICE, ns, key, value, ttl); + } + uint32_t DeleteKey(const string& ns, const string& key) override + { + return DeleteKey(IStore2::ScopeType::DEVICE, ns, key); + } + uint32_t DeleteNamespace(const string& ns) override + { + return DeleteNamespace(IStore2::ScopeType::DEVICE, ns); + } + uint32_t Register(IStore2::INotification* notification) override + { + if (_deviceStore2 != nullptr) { + _deviceStore2->Register(notification); + } + if (_accountStore2 != nullptr) { + _accountStore2->Register(notification); + } + return Core::ERROR_NONE; + } + uint32_t Unregister(IStore2::INotification* notification) override + { + if (_deviceStore2 != nullptr) { + _deviceStore2->Unregister(notification); + } + if (_accountStore2 != nullptr) { + _accountStore2->Unregister(notification); + } + return Core::ERROR_NONE; + } + uint32_t SetValue(const IStore2::ScopeType scope, const string& ns, const string& key, const string& value, const uint32_t ttl) override + { + if (scope == IStore2::ScopeType::ACCOUNT) { + if (_accountStore2 != nullptr) { + return _accountStore2->SetValue(scope, ns, key, value, ttl); + } + } else if (_deviceStore2 != nullptr) { + return _deviceStore2->SetValue(scope, ns, key, value, ttl); + } + return Core::ERROR_NOT_SUPPORTED; + } + uint32_t GetValue(const IStore2::ScopeType scope, const string& ns, const string& key, string& value, uint32_t& ttl) override + { + if (scope == IStore2::ScopeType::ACCOUNT) { + if (_accountStore2 != nullptr) { + return _accountStore2->GetValue(scope, ns, key, value, ttl); + } + } else if (_deviceStore2 != nullptr) { + return _deviceStore2->GetValue(scope, ns, key, value, ttl); + } + return Core::ERROR_NOT_SUPPORTED; + } + uint32_t DeleteKey(const IStore2::ScopeType scope, const string& ns, const string& key) override + { + if (scope == IStore2::ScopeType::ACCOUNT) { + if (_accountStore2 != nullptr) { + return _accountStore2->DeleteKey(scope, ns, key); + } + } else if (_deviceStore2 != nullptr) { + return _deviceStore2->DeleteKey(scope, ns, key); + } + return Core::ERROR_NOT_SUPPORTED; + } + uint32_t DeleteNamespace(const IStore2::ScopeType scope, const string& ns) override + { + if (scope == IStore2::ScopeType::ACCOUNT) { + if (_accountStore2 != nullptr) { + return _accountStore2->DeleteNamespace(scope, ns); + } + } else if (_deviceStore2 != nullptr) { + return _deviceStore2->DeleteNamespace(scope, ns); + } + return Core::ERROR_NOT_SUPPORTED; + } + uint32_t FlushCache() override + { + if (_deviceStoreCache != nullptr) { + return _deviceStoreCache->FlushCache(); + } + return Core::ERROR_NOT_SUPPORTED; + } + uint32_t GetKeys(const IStoreInspector::ScopeType scope, const string& ns, RPC::IStringIterator*& keys) override + { + if (scope == IStoreInspector::ScopeType::DEVICE) { + if (_deviceStoreInspector != nullptr) { + return _deviceStoreInspector->GetKeys(scope, ns, keys); + } + } + return Core::ERROR_NOT_SUPPORTED; + } + uint32_t GetNamespaces(const IStoreInspector::ScopeType scope, RPC::IStringIterator*& namespaces) override + { + if (scope == IStoreInspector::ScopeType::DEVICE) { + if (_deviceStoreInspector != nullptr) { + return _deviceStoreInspector->GetNamespaces(scope, namespaces); + } + } + return Core::ERROR_NOT_SUPPORTED; + } + uint32_t GetStorageSizes(const IStoreInspector::ScopeType scope, INamespaceSizeIterator*& storageList) override + { + if (scope == IStoreInspector::ScopeType::DEVICE) { + if (_deviceStoreInspector != nullptr) { + return _deviceStoreInspector->GetStorageSizes(scope, storageList); + } + } + return Core::ERROR_NOT_SUPPORTED; + } + uint32_t SetNamespaceStorageLimit(const IStoreLimit::ScopeType scope, const string& ns, const uint32_t size) override + { + if (scope == IStoreLimit::ScopeType::DEVICE) { + if (_deviceStoreLimit != nullptr) { + return _deviceStoreLimit->SetNamespaceStorageLimit(scope, ns, size); + } + } + return Core::ERROR_NOT_SUPPORTED; + } + uint32_t GetNamespaceStorageLimit(const IStoreLimit::ScopeType scope, const string& ns, uint32_t& size) override + { + if (scope == IStoreLimit::ScopeType::DEVICE) { + if (_deviceStoreLimit != nullptr) { + return _deviceStoreLimit->GetNamespaceStorageLimit(scope, ns, size); + } + } + return Core::ERROR_NOT_SUPPORTED; + } + + private: + IStore2* _deviceStore2; + IStoreCache* _deviceStoreCache; + IStoreInspector* _deviceStoreInspector; + IStoreLimit* _deviceStoreLimit; + IStore2* _accountStore2; + Core::Sink _store2Sink; + std::list _clients; + Core::CriticalSection _clientLock; + }; + +} // namespace Plugin +} // namespace WPEFramework diff --git a/PersistentStore/PersistentStoreJsonRpc.cpp b/PersistentStore/PersistentStoreJsonRpc.cpp index f8c4c6a700..a3b2858f8b 100644 --- a/PersistentStore/PersistentStoreJsonRpc.cpp +++ b/PersistentStore/PersistentStoreJsonRpc.cpp @@ -118,7 +118,7 @@ namespace Plugin { uint32_t PersistentStore::endpoint_getKeys(const DeleteNamespaceParamsInfo& params, GetKeysResultData& response) { RPC::IStringIterator* it; - auto result = _store2->GetKeys( + auto result = _storeInspector->GetKeys( Exchange::IStoreInspector::ScopeType(params.Scope.Value()), params.Namespace.Value(), it); @@ -137,7 +137,7 @@ namespace Plugin { uint32_t PersistentStore::endpoint_getNamespaces(const GetNamespacesParamsInfo& params, GetNamespacesResultData& response) { RPC::IStringIterator* it; - auto result = _store2->GetNamespaces( + auto result = _storeInspector->GetNamespaces( Exchange::IStoreInspector::ScopeType(params.Scope.Value()), it); if (result == Core::ERROR_NONE) { @@ -156,7 +156,7 @@ namespace Plugin { uint32_t PersistentStore::endpoint_getStorageSize(const GetNamespacesParamsInfo& params, JsonObject& response) { Exchange::IStoreInspector::INamespaceSizeIterator* it; - auto result = _store2->GetStorageSizes( + auto result = _storeInspector->GetStorageSizes( Exchange::IStoreInspector::ScopeType(params.Scope.Value()), it); if (result == Core::ERROR_NONE) { @@ -176,7 +176,7 @@ namespace Plugin { uint32_t PersistentStore::endpoint_getStorageSizes(const GetNamespacesParamsInfo& params, GetStorageSizesResultData& response) { Exchange::IStoreInspector::INamespaceSizeIterator* it; - auto result = _store2->GetStorageSizes( + auto result = _storeInspector->GetStorageSizes( Exchange::IStoreInspector::ScopeType(params.Scope.Value()), it); if (result == Core::ERROR_NONE) { @@ -194,7 +194,7 @@ namespace Plugin { uint32_t PersistentStore::endpoint_flushCache(DeleteKeyResultInfo& response) { - auto result = _store2->FlushCache(); + auto result = _storeCache->FlushCache(); if (result == Core::ERROR_NONE) { response.Success = true; } @@ -205,7 +205,7 @@ namespace Plugin { uint32_t PersistentStore::endpoint_getNamespaceStorageLimit(const DeleteNamespaceParamsInfo& params, GetNamespaceStorageLimitResultData& response) { uint32_t size; - auto result = _store2->GetNamespaceStorageLimit( + auto result = _storeLimit->GetNamespaceStorageLimit( Exchange::IStoreLimit::ScopeType(params.Scope.Value()), params.Namespace.Value(), size); @@ -218,7 +218,7 @@ namespace Plugin { uint32_t PersistentStore::endpoint_setNamespaceStorageLimit(const SetNamespaceStorageLimitParamsData& params) { - return _store2->SetNamespaceStorageLimit( + return _storeLimit->SetNamespaceStorageLimit( Exchange::IStoreLimit::ScopeType(params.Scope.Value()), params.Namespace.Value(), params.StorageLimit.Value()); diff --git a/PersistentStore/grpc/Store2.cpp b/PersistentStore/grpc/Store2.cpp deleted file mode 100644 index dcd1a008e6..0000000000 --- a/PersistentStore/grpc/Store2.cpp +++ /dev/null @@ -1,8 +0,0 @@ -#include "Store2.h" - -namespace WPEFramework { -namespace Plugin { - class GrpcStore2 : public Grpc::Store2 {}; - SERVICE_REGISTRATION(GrpcStore2, 1, 0); -} // namespace Plugin -} // namespace WPEFramework diff --git a/PersistentStore/grpc/l2test/StubTest.cpp b/PersistentStore/grpc/l2test/StubTest.cpp index e90b1aed3f..e6c07649f5 100644 --- a/PersistentStore/grpc/l2test/StubTest.cpp +++ b/PersistentStore/grpc/l2test/StubTest.cpp @@ -61,7 +61,7 @@ TEST_F(AStub, DoesNotUpdateValueWhenAppIdEmpty) auto status = stub->UpdateValue(&context, request, &response); ASSERT_THAT(status.ok(), IsFalse()); EXPECT_THAT(status.error_code(), Eq(3)); - EXPECT_THAT(status.error_message(), Eq("app_id is mandatory")); + EXPECT_THAT(status.error_message(), Eq("key's key and app_id fields are required")); } TEST_F(AStub, DoesNotUpdateValueWhenKeyEmpty) @@ -98,7 +98,7 @@ TEST_F(AStub, DoesNotGetValueWhenAppIdEmpty) auto status = stub->GetValue(&context, request, &response); ASSERT_THAT(status.ok(), IsFalse()); EXPECT_THAT(status.error_code(), Eq(3)); - EXPECT_THAT(status.error_message(), Eq("app_id is mandatory")); + EXPECT_THAT(status.error_message(), Eq("key's key and app_id fields are required")); } TEST_F(AStub, DoesNotGetValueWhenKeyEmpty) @@ -132,7 +132,7 @@ TEST_F(AStub, DoesNotDeleteValueWhenAppIdEmpty) auto status = stub->DeleteValue(&context, request, &response); ASSERT_THAT(status.ok(), IsFalse()); EXPECT_THAT(status.error_code(), Eq(3)); - EXPECT_THAT(status.error_message(), Eq("app_id is mandatory")); + EXPECT_THAT(status.error_message(), Eq("key's key and app_id fields are required")); } TEST_F(AStub, DoesNotDeleteValueWhenKeyEmpty) @@ -197,8 +197,7 @@ TEST_F(AStub, GetsValueWhenValueEmpty) ASSERT_THAT(response.has_value(), IsTrue()); EXPECT_THAT(response.value().value(), Eq(kEmpty)); EXPECT_THAT(response.value().has_ttl(), IsFalse()); - ASSERT_THAT(response.value().has_expire_time(), IsTrue()); - EXPECT_THAT(response.value().expire_time().seconds(), Eq(0)); + EXPECT_THAT(response.value().has_expire_time(), IsFalse()); } } @@ -378,7 +377,7 @@ TEST_F(AStub, DoesNotGetValueWhenTtlExpired) auto status = stub->UpdateValue(&context, request, &response); ASSERT_THAT(status.ok(), IsTrue()); } - sleep(kTtl); + sleep(kTtl + 1); { grpc::ClientContext context; context.AddMetadata("authorization", std::string(kToken)); diff --git a/PersistentStore/l0test/Store2Mock.h b/PersistentStore/l0test/PersistentStoreImplementationMock.h similarity index 56% rename from PersistentStore/l0test/Store2Mock.h rename to PersistentStore/l0test/PersistentStoreImplementationMock.h index a049bcbfc5..fe4d5095a9 100644 --- a/PersistentStore/l0test/Store2Mock.h +++ b/PersistentStore/l0test/PersistentStoreImplementationMock.h @@ -1,17 +1,26 @@ #pragma once #include +#include #include #include -class Store2Mock : public WPEFramework::Exchange::IStore2, - public WPEFramework::Exchange::IStoreCache, - public WPEFramework::Exchange::IStoreInspector, - public WPEFramework::Exchange::IStoreLimit { +class PersistentStoreImplementationMock + : public WPEFramework::Exchange::IStore, + public WPEFramework::Exchange::IStore2, + public WPEFramework::Exchange::IStoreCache, + public WPEFramework::Exchange::IStoreInspector, + public WPEFramework::Exchange::IStoreLimit { public: - ~Store2Mock() override = default; - MOCK_METHOD(uint32_t, Register, (INotification*), (override)); - MOCK_METHOD(uint32_t, Unregister, (INotification*), (override)); + ~PersistentStoreImplementationMock() override = default; + MOCK_METHOD(uint32_t, Register, (IStore::INotification * notification), (override)); + MOCK_METHOD(uint32_t, Unregister, (IStore::INotification * notification), (override)); + MOCK_METHOD(uint32_t, SetValue, (const string& ns, const string& key, const string& value), (override)); + MOCK_METHOD(uint32_t, GetValue, (const string& ns, const string& key, string& value), (override)); + MOCK_METHOD(uint32_t, DeleteKey, (const string& ns, const string& key), (override)); + MOCK_METHOD(uint32_t, DeleteNamespace, (const string& ns), (override)); + MOCK_METHOD(uint32_t, Register, (IStore2::INotification*), (override)); + MOCK_METHOD(uint32_t, Unregister, (IStore2::INotification*), (override)); MOCK_METHOD(uint32_t, SetValue, (const IStore2::ScopeType scope, const string& ns, const string& key, const string& value, const uint32_t ttl), (override)); MOCK_METHOD(uint32_t, GetValue, (const IStore2::ScopeType scope, const string& ns, const string& key, string& value, uint32_t& ttl), (override)); MOCK_METHOD(uint32_t, DeleteKey, (const IStore2::ScopeType scope, const string& ns, const string& key), (override)); @@ -22,7 +31,8 @@ class Store2Mock : public WPEFramework::Exchange::IStore2, MOCK_METHOD(uint32_t, GetStorageSizes, (const IStoreInspector::ScopeType scope, INamespaceSizeIterator*& storageList), (override)); MOCK_METHOD(uint32_t, GetNamespaceStorageLimit, (const IStoreLimit::ScopeType scope, const string& ns, uint32_t& size), (override)); MOCK_METHOD(uint32_t, SetNamespaceStorageLimit, (const IStoreLimit::ScopeType scope, const string& ns, const uint32_t size), (override)); - BEGIN_INTERFACE_MAP(Store2Mock) + BEGIN_INTERFACE_MAP(PersistentStoreImplementationMock) + INTERFACE_ENTRY(IStore) INTERFACE_ENTRY(IStore2) INTERFACE_ENTRY(IStoreCache) INTERFACE_ENTRY(IStoreInspector) diff --git a/PersistentStore/l0test/PersistentStoreTest.cpp b/PersistentStore/l0test/PersistentStoreTest.cpp index 6d65f5ffe3..1d72616ed3 100644 --- a/PersistentStore/l0test/PersistentStoreTest.cpp +++ b/PersistentStore/l0test/PersistentStoreTest.cpp @@ -2,8 +2,8 @@ #include #include "../PersistentStore.h" +#include "PersistentStoreImplementationMock.h" #include "ServiceMock.h" -#include "Store2Mock.h" using ::testing::_; using ::testing::Eq; @@ -61,9 +61,9 @@ class APersistentStore : public Test { TEST_F(APersistentStore, GetsValueInDeviceScopeViaJsonRpc) { - class SqliteStore2 : public NiceMock { + class PersistentStoreImplementation : public NiceMock { public: - SqliteStore2() + PersistentStoreImplementation() { EXPECT_CALL(*this, GetValue(_, _, _, _, _)) .WillRepeatedly(Invoke( @@ -77,7 +77,7 @@ TEST_F(APersistentStore, GetsValueInDeviceScopeViaJsonRpc) })); } }; - PublishedServiceType metadata(WPEFramework::Core::System::MODULE_NAME, 1, 0, 0); + PublishedServiceType metadata(WPEFramework::Core::System::MODULE_NAME, 1, 0, 0); ASSERT_THAT(plugin->Initialize(service), Eq("")); auto jsonRpc = plugin->QueryInterface(); ASSERT_THAT(jsonRpc, NotNull()); @@ -98,9 +98,9 @@ TEST_F(APersistentStore, GetsValueInDeviceScopeViaJsonRpc) TEST_F(APersistentStore, GetsValueInAccountScopeViaJsonRpc) { - class GrpcStore2 : public NiceMock { + class PersistentStoreImplementation : public NiceMock { public: - GrpcStore2() + PersistentStoreImplementation() { EXPECT_CALL(*this, GetValue(_, _, _, _, _)) .WillRepeatedly(Invoke( @@ -114,7 +114,7 @@ TEST_F(APersistentStore, GetsValueInAccountScopeViaJsonRpc) })); } }; - PublishedServiceType metadata(WPEFramework::Core::System::MODULE_NAME, 1, 0, 0); + PublishedServiceType metadata(WPEFramework::Core::System::MODULE_NAME, 1, 0, 0); ASSERT_THAT(plugin->Initialize(service), Eq("")); auto jsonRpc = plugin->QueryInterface(); ASSERT_THAT(jsonRpc, NotNull()); @@ -136,9 +136,9 @@ TEST_F(APersistentStore, GetsValueInAccountScopeViaJsonRpc) TEST_F(APersistentStore, SetsValueInDeviceScopeViaJsonRpc) { - class SqliteStore2 : public NiceMock { + class PersistentStoreImplementation : public NiceMock { public: - SqliteStore2() + PersistentStoreImplementation() { EXPECT_CALL(*this, SetValue(_, _, _, _, _)) .WillRepeatedly(Invoke( @@ -152,7 +152,7 @@ TEST_F(APersistentStore, SetsValueInDeviceScopeViaJsonRpc) })); } }; - PublishedServiceType metadata(WPEFramework::Core::System::MODULE_NAME, 1, 0, 0); + PublishedServiceType metadata(WPEFramework::Core::System::MODULE_NAME, 1, 0, 0); ASSERT_THAT(plugin->Initialize(service), Eq("")); auto jsonRpc = plugin->QueryInterface(); ASSERT_THAT(jsonRpc, NotNull()); @@ -171,9 +171,9 @@ TEST_F(APersistentStore, SetsValueInDeviceScopeViaJsonRpc) TEST_F(APersistentStore, SetsValueInAccountScopeViaJsonRpc) { - class GrpcStore2 : public NiceMock { + class PersistentStoreImplementation : public NiceMock { public: - GrpcStore2() + PersistentStoreImplementation() { EXPECT_CALL(*this, SetValue(_, _, _, _, _)) .WillRepeatedly(Invoke( @@ -187,7 +187,7 @@ TEST_F(APersistentStore, SetsValueInAccountScopeViaJsonRpc) })); } }; - PublishedServiceType metadata(WPEFramework::Core::System::MODULE_NAME, 1, 0, 0); + PublishedServiceType metadata(WPEFramework::Core::System::MODULE_NAME, 1, 0, 0); ASSERT_THAT(plugin->Initialize(service), Eq("")); auto jsonRpc = plugin->QueryInterface(); ASSERT_THAT(jsonRpc, NotNull()); @@ -207,9 +207,9 @@ TEST_F(APersistentStore, SetsValueInAccountScopeViaJsonRpc) TEST_F(APersistentStore, DeletesKeyInDeviceScopeViaJsonRpc) { - class SqliteStore2 : public NiceMock { + class PersistentStoreImplementation : public NiceMock { public: - SqliteStore2() + PersistentStoreImplementation() { EXPECT_CALL(*this, DeleteKey(_, _, _)) .WillRepeatedly(Invoke( @@ -221,7 +221,7 @@ TEST_F(APersistentStore, DeletesKeyInDeviceScopeViaJsonRpc) })); } }; - PublishedServiceType metadata(WPEFramework::Core::System::MODULE_NAME, 1, 0, 0); + PublishedServiceType metadata(WPEFramework::Core::System::MODULE_NAME, 1, 0, 0); ASSERT_THAT(plugin->Initialize(service), Eq("")); auto jsonRpc = plugin->QueryInterface(); ASSERT_THAT(jsonRpc, NotNull()); @@ -238,9 +238,9 @@ TEST_F(APersistentStore, DeletesKeyInDeviceScopeViaJsonRpc) TEST_F(APersistentStore, DeletesKeyInAccountScopeViaJsonRpc) { - class GrpcStore2 : public NiceMock { + class PersistentStoreImplementation : public NiceMock { public: - GrpcStore2() + PersistentStoreImplementation() { EXPECT_CALL(*this, DeleteKey(_, _, _)) .WillRepeatedly(Invoke( @@ -252,7 +252,7 @@ TEST_F(APersistentStore, DeletesKeyInAccountScopeViaJsonRpc) })); } }; - PublishedServiceType metadata(WPEFramework::Core::System::MODULE_NAME, 1, 0, 0); + PublishedServiceType metadata(WPEFramework::Core::System::MODULE_NAME, 1, 0, 0); ASSERT_THAT(plugin->Initialize(service), Eq("")); auto jsonRpc = plugin->QueryInterface(); ASSERT_THAT(jsonRpc, NotNull()); @@ -270,9 +270,9 @@ TEST_F(APersistentStore, DeletesKeyInAccountScopeViaJsonRpc) TEST_F(APersistentStore, DeletesNamespaceInDeviceScopeViaJsonRpc) { - class SqliteStore2 : public NiceMock { + class PersistentStoreImplementation : public NiceMock { public: - SqliteStore2() + PersistentStoreImplementation() { EXPECT_CALL(*this, DeleteNamespace(_, _)) .WillRepeatedly(Invoke( @@ -283,7 +283,7 @@ TEST_F(APersistentStore, DeletesNamespaceInDeviceScopeViaJsonRpc) })); } }; - PublishedServiceType metadata(WPEFramework::Core::System::MODULE_NAME, 1, 0, 0); + PublishedServiceType metadata(WPEFramework::Core::System::MODULE_NAME, 1, 0, 0); ASSERT_THAT(plugin->Initialize(service), Eq("")); auto jsonRpc = plugin->QueryInterface(); ASSERT_THAT(jsonRpc, NotNull()); @@ -299,9 +299,9 @@ TEST_F(APersistentStore, DeletesNamespaceInDeviceScopeViaJsonRpc) TEST_F(APersistentStore, DeletesNamespaceInAccountScopeViaJsonRpc) { - class GrpcStore2 : public NiceMock { + class PersistentStoreImplementation : public NiceMock { public: - GrpcStore2() + PersistentStoreImplementation() { EXPECT_CALL(*this, DeleteNamespace(_, _)) .WillRepeatedly(Invoke( @@ -312,7 +312,7 @@ TEST_F(APersistentStore, DeletesNamespaceInAccountScopeViaJsonRpc) })); } }; - PublishedServiceType metadata(WPEFramework::Core::System::MODULE_NAME, 1, 0, 0); + PublishedServiceType metadata(WPEFramework::Core::System::MODULE_NAME, 1, 0, 0); ASSERT_THAT(plugin->Initialize(service), Eq("")); auto jsonRpc = plugin->QueryInterface(); ASSERT_THAT(jsonRpc, NotNull()); @@ -329,15 +329,15 @@ TEST_F(APersistentStore, DeletesNamespaceInAccountScopeViaJsonRpc) TEST_F(APersistentStore, FlushesCacheViaJsonRpc) { - class SqliteStore2 : public NiceMock { + class PersistentStoreImplementation : public NiceMock { public: - SqliteStore2() + PersistentStoreImplementation() { EXPECT_CALL(*this, FlushCache()) .WillRepeatedly(Return(WPEFramework::Core::ERROR_NONE)); } }; - PublishedServiceType metadata(WPEFramework::Core::System::MODULE_NAME, 1, 0, 0); + PublishedServiceType metadata(WPEFramework::Core::System::MODULE_NAME, 1, 0, 0); ASSERT_THAT(plugin->Initialize(service), Eq("")); auto jsonRpc = plugin->QueryInterface(); ASSERT_THAT(jsonRpc, NotNull()); @@ -349,9 +349,9 @@ TEST_F(APersistentStore, FlushesCacheViaJsonRpc) TEST_F(APersistentStore, GetsKeysInDeviceScopeViaJsonRpc) { - class SqliteStore2 : public NiceMock { + class PersistentStoreImplementation : public NiceMock { public: - SqliteStore2() + PersistentStoreImplementation() { EXPECT_CALL(*this, GetKeys(_, _, _)) .WillRepeatedly(Invoke( @@ -363,7 +363,7 @@ TEST_F(APersistentStore, GetsKeysInDeviceScopeViaJsonRpc) })); } }; - PublishedServiceType metadata(WPEFramework::Core::System::MODULE_NAME, 1, 0, 0); + PublishedServiceType metadata(WPEFramework::Core::System::MODULE_NAME, 1, 0, 0); ASSERT_THAT(plugin->Initialize(service), Eq("")); auto jsonRpc = plugin->QueryInterface(); ASSERT_THAT(jsonRpc, NotNull()); @@ -385,27 +385,11 @@ TEST_F(APersistentStore, GetsKeysInDeviceScopeViaJsonRpc) plugin->Deinitialize(service); } -TEST_F(APersistentStore, DoesNotGetKeysInAccountScopeViaJsonRpc) -{ - ASSERT_THAT(plugin->Initialize(service), Eq("")); - auto jsonRpc = plugin->QueryInterface(); - ASSERT_THAT(jsonRpc, NotNull()); - DeleteNamespaceParamsInfo params; - params.Scope = WPEFramework::JsonData::PersistentStore::ScopeType::ACCOUNT; - params.Namespace = kAppId; - string paramsJsonStr; - params.ToString(paramsJsonStr); - string resultJsonStr; - EXPECT_THAT(jsonRpc->Invoke(0, 0, "", "getKeys", paramsJsonStr, resultJsonStr), Eq(WPEFramework::Core::ERROR_NOT_SUPPORTED)); - jsonRpc->Release(); - plugin->Deinitialize(service); -} - TEST_F(APersistentStore, GetsNamespacesInDeviceScopeViaJsonRpc) { - class SqliteStore2 : public NiceMock { + class PersistentStoreImplementation : public NiceMock { public: - SqliteStore2() + PersistentStoreImplementation() { EXPECT_CALL(*this, GetNamespaces(_, _)) .WillRepeatedly(Invoke( @@ -416,7 +400,7 @@ TEST_F(APersistentStore, GetsNamespacesInDeviceScopeViaJsonRpc) })); } }; - PublishedServiceType metadata(WPEFramework::Core::System::MODULE_NAME, 1, 0, 0); + PublishedServiceType metadata(WPEFramework::Core::System::MODULE_NAME, 1, 0, 0); ASSERT_THAT(plugin->Initialize(service), Eq("")); auto jsonRpc = plugin->QueryInterface(); ASSERT_THAT(jsonRpc, NotNull()); @@ -434,26 +418,11 @@ TEST_F(APersistentStore, GetsNamespacesInDeviceScopeViaJsonRpc) plugin->Deinitialize(service); } -TEST_F(APersistentStore, DoesNotGetNamespacesInAccountScopeViaJsonRpc) -{ - ASSERT_THAT(plugin->Initialize(service), Eq("")); - auto jsonRpc = plugin->QueryInterface(); - ASSERT_THAT(jsonRpc, NotNull()); - GetNamespacesParamsInfo params; - params.Scope = WPEFramework::JsonData::PersistentStore::ScopeType::ACCOUNT; - string paramsJsonStr; - params.ToString(paramsJsonStr); - string resultJsonStr; - EXPECT_THAT(jsonRpc->Invoke(0, 0, "", "getNamespaces", paramsJsonStr, resultJsonStr), Eq(WPEFramework::Core::ERROR_NOT_SUPPORTED)); - jsonRpc->Release(); - plugin->Deinitialize(service); -} - TEST_F(APersistentStore, GetsStorageSizesInDeviceScopeViaJsonRpc) { - class SqliteStore2 : public NiceMock { + class PersistentStoreImplementation : public NiceMock { public: - SqliteStore2() + PersistentStoreImplementation() { EXPECT_CALL(*this, GetStorageSizes(_, _)) .WillRepeatedly(Invoke( @@ -464,7 +433,7 @@ TEST_F(APersistentStore, GetsStorageSizesInDeviceScopeViaJsonRpc) })); } }; - PublishedServiceType metadata(WPEFramework::Core::System::MODULE_NAME, 1, 0, 0); + PublishedServiceType metadata(WPEFramework::Core::System::MODULE_NAME, 1, 0, 0); ASSERT_THAT(plugin->Initialize(service), Eq("")); auto jsonRpc = plugin->QueryInterface(); ASSERT_THAT(jsonRpc, NotNull()); @@ -484,26 +453,11 @@ TEST_F(APersistentStore, GetsStorageSizesInDeviceScopeViaJsonRpc) plugin->Deinitialize(service); } -TEST_F(APersistentStore, DoesNotGetStorageSizesInAccountScopeViaJsonRpc) -{ - ASSERT_THAT(plugin->Initialize(service), Eq("")); - auto jsonRpc = plugin->QueryInterface(); - ASSERT_THAT(jsonRpc, NotNull()); - GetNamespacesParamsInfo params; - params.Scope = WPEFramework::JsonData::PersistentStore::ScopeType::ACCOUNT; - string paramsJsonStr; - params.ToString(paramsJsonStr); - string resultJsonStr; - EXPECT_THAT(jsonRpc->Invoke(0, 0, "", "getStorageSizes", paramsJsonStr, resultJsonStr), Eq(WPEFramework::Core::ERROR_NOT_SUPPORTED)); - jsonRpc->Release(); - plugin->Deinitialize(service); -} - TEST_F(APersistentStore, GetsNamespaceStorageLimitInDeviceScopeViaJsonRpc) { - class SqliteStore2 : public NiceMock { + class PersistentStoreImplementation : public NiceMock { public: - SqliteStore2() + PersistentStoreImplementation() { EXPECT_CALL(*this, GetNamespaceStorageLimit(_, _, _)) .WillRepeatedly(Invoke( @@ -515,7 +469,7 @@ TEST_F(APersistentStore, GetsNamespaceStorageLimitInDeviceScopeViaJsonRpc) })); } }; - PublishedServiceType metadata(WPEFramework::Core::System::MODULE_NAME, 1, 0, 0); + PublishedServiceType metadata(WPEFramework::Core::System::MODULE_NAME, 1, 0, 0); ASSERT_THAT(plugin->Initialize(service), Eq("")); auto jsonRpc = plugin->QueryInterface(); ASSERT_THAT(jsonRpc, NotNull()); @@ -532,27 +486,11 @@ TEST_F(APersistentStore, GetsNamespaceStorageLimitInDeviceScopeViaJsonRpc) plugin->Deinitialize(service); } -TEST_F(APersistentStore, DoesNotGetNamespaceStorageLimitInAccountScopeViaJsonRpc) -{ - ASSERT_THAT(plugin->Initialize(service), Eq("")); - auto jsonRpc = plugin->QueryInterface(); - ASSERT_THAT(jsonRpc, NotNull()); - DeleteNamespaceParamsInfo params; - params.Scope = WPEFramework::JsonData::PersistentStore::ScopeType::ACCOUNT; - params.Namespace = kAppId; - string paramsJsonStr; - params.ToString(paramsJsonStr); - string resultJsonStr; - EXPECT_THAT(jsonRpc->Invoke(0, 0, "", "getNamespaceStorageLimit", paramsJsonStr, resultJsonStr), Eq(WPEFramework::Core::ERROR_NOT_SUPPORTED)); - jsonRpc->Release(); - plugin->Deinitialize(service); -} - TEST_F(APersistentStore, SetsNamespaceStorageLimitInDeviceScopeViaJsonRpc) { - class SqliteStore2 : public NiceMock { + class PersistentStoreImplementation : public NiceMock { public: - SqliteStore2() + PersistentStoreImplementation() { EXPECT_CALL(*this, SetNamespaceStorageLimit(_, _, _)) .WillRepeatedly(Invoke( @@ -564,7 +502,7 @@ TEST_F(APersistentStore, SetsNamespaceStorageLimitInDeviceScopeViaJsonRpc) })); } }; - PublishedServiceType metadata(WPEFramework::Core::System::MODULE_NAME, 1, 0, 0); + PublishedServiceType metadata(WPEFramework::Core::System::MODULE_NAME, 1, 0, 0); ASSERT_THAT(plugin->Initialize(service), Eq("")); auto jsonRpc = plugin->QueryInterface(); ASSERT_THAT(jsonRpc, NotNull()); @@ -579,33 +517,15 @@ TEST_F(APersistentStore, SetsNamespaceStorageLimitInDeviceScopeViaJsonRpc) plugin->Deinitialize(service); } -TEST_F(APersistentStore, DoesNotSetNamespaceStorageLimitInAccountScopeViaJsonRpc) -{ - ASSERT_THAT(plugin->Initialize(service), Eq("")); - auto jsonRpc = plugin->QueryInterface(); - ASSERT_THAT(jsonRpc, NotNull()); - SetNamespaceStorageLimitParamsData params; - params.Scope = WPEFramework::JsonData::PersistentStore::ScopeType::ACCOUNT; - params.Namespace = kAppId; - params.StorageLimit = kSize; - string paramsJsonStr; - params.ToString(paramsJsonStr); - string resultJsonStr; - EXPECT_THAT(jsonRpc->Invoke(0, 0, "", "setNamespaceStorageLimit", paramsJsonStr, resultJsonStr), Eq(WPEFramework::Core::ERROR_NOT_SUPPORTED)); - jsonRpc->Release(); - plugin->Deinitialize(service); -} - TEST_F(APersistentStore, GetsValueInDeviceScopeViaIStore) { - class SqliteStore2 : public NiceMock { + class PersistentStoreImplementation : public NiceMock { public: - SqliteStore2() + PersistentStoreImplementation() { - EXPECT_CALL(*this, GetValue(_, _, _, _, _)) + EXPECT_CALL(*this, GetValue(_, _, _)) .WillRepeatedly(Invoke( - [](const IStore2::ScopeType scope, const string& ns, const string& key, string& value, uint32_t& ttl) { - EXPECT_THAT(scope, Eq(IStore2::ScopeType::DEVICE)); + [](const string& ns, const string& key, string& value) { EXPECT_THAT(ns, Eq(kAppId)); EXPECT_THAT(key, Eq(kKey)); value = kValue; @@ -613,7 +533,7 @@ TEST_F(APersistentStore, GetsValueInDeviceScopeViaIStore) })); } }; - PublishedServiceType metadata(WPEFramework::Core::System::MODULE_NAME, 1, 0, 0); + PublishedServiceType metadata(WPEFramework::Core::System::MODULE_NAME, 1, 0, 0); ASSERT_THAT(plugin->Initialize(service), Eq("")); auto store = plugin->QueryInterface(); ASSERT_THAT(store, NotNull()); @@ -626,23 +546,21 @@ TEST_F(APersistentStore, GetsValueInDeviceScopeViaIStore) TEST_F(APersistentStore, SetsValueInDeviceScopeViaIStore) { - class SqliteStore2 : public NiceMock { + class PersistentStoreImplementation : public NiceMock { public: - SqliteStore2() + PersistentStoreImplementation() { - EXPECT_CALL(*this, SetValue(_, _, _, _, _)) + EXPECT_CALL(*this, SetValue(_, _, _)) .WillRepeatedly(Invoke( - [](const IStore2::ScopeType scope, const string& ns, const string& key, const string& value, const uint32_t ttl) { - EXPECT_THAT(scope, Eq(IStore2::ScopeType::DEVICE)); + [](const string& ns, const string& key, const string& value) { EXPECT_THAT(ns, Eq(kAppId)); EXPECT_THAT(key, Eq(kKey)); EXPECT_THAT(value, Eq(kValue)); - EXPECT_THAT(ttl, Eq(0)); return WPEFramework::Core::ERROR_NONE; })); } }; - PublishedServiceType metadata(WPEFramework::Core::System::MODULE_NAME, 1, 0, 0); + PublishedServiceType metadata(WPEFramework::Core::System::MODULE_NAME, 1, 0, 0); ASSERT_THAT(plugin->Initialize(service), Eq("")); auto store = plugin->QueryInterface(); ASSERT_THAT(store, NotNull()); @@ -653,21 +571,20 @@ TEST_F(APersistentStore, SetsValueInDeviceScopeViaIStore) TEST_F(APersistentStore, DeletesKeyInDeviceScopeViaIStore) { - class SqliteStore2 : public NiceMock { + class PersistentStoreImplementation : public NiceMock { public: - SqliteStore2() + PersistentStoreImplementation() { - EXPECT_CALL(*this, DeleteKey(_, _, _)) + EXPECT_CALL(*this, DeleteKey(_, _)) .WillRepeatedly(Invoke( - [](const IStore2::ScopeType scope, const string& ns, const string& key) { - EXPECT_THAT(scope, Eq(IStore2::ScopeType::DEVICE)); + [](const string& ns, const string& key) { EXPECT_THAT(ns, Eq(kAppId)); EXPECT_THAT(key, Eq(kKey)); return WPEFramework::Core::ERROR_NONE; })); } }; - PublishedServiceType metadata(WPEFramework::Core::System::MODULE_NAME, 1, 0, 0); + PublishedServiceType metadata(WPEFramework::Core::System::MODULE_NAME, 1, 0, 0); ASSERT_THAT(plugin->Initialize(service), Eq("")); auto store = plugin->QueryInterface(); ASSERT_THAT(store, NotNull()); @@ -678,20 +595,19 @@ TEST_F(APersistentStore, DeletesKeyInDeviceScopeViaIStore) TEST_F(APersistentStore, DeletesNamespaceInDeviceScopeViaIStore) { - class SqliteStore2 : public NiceMock { + class PersistentStoreImplementation : public NiceMock { public: - SqliteStore2() + PersistentStoreImplementation() { - EXPECT_CALL(*this, DeleteNamespace(_, _)) + EXPECT_CALL(*this, DeleteNamespace(_)) .WillRepeatedly(Invoke( - [](const IStore2::ScopeType scope, const string& ns) { - EXPECT_THAT(scope, Eq(IStore2::ScopeType::DEVICE)); + [](const string& ns) { EXPECT_THAT(ns, Eq(kAppId)); return WPEFramework::Core::ERROR_NONE; })); } }; - PublishedServiceType metadata(WPEFramework::Core::System::MODULE_NAME, 1, 0, 0); + PublishedServiceType metadata(WPEFramework::Core::System::MODULE_NAME, 1, 0, 0); ASSERT_THAT(plugin->Initialize(service), Eq("")); auto store = plugin->QueryInterface(); ASSERT_THAT(store, NotNull()); diff --git a/PersistentStore/l0test/ServiceMock.h b/PersistentStore/l0test/ServiceMock.h index 36c5c3c43d..8aea54a268 100644 --- a/PersistentStore/l0test/ServiceMock.h +++ b/PersistentStore/l0test/ServiceMock.h @@ -3,7 +3,8 @@ #include "../Module.h" #include -class ServiceMock : public WPEFramework::PluginHost::IShell { +class ServiceMock : public WPEFramework::PluginHost::IShell, + public WPEFramework::PluginHost::IShell::ICOMLink { public: ~ServiceMock() override = default; MOCK_METHOD(string, Versions, (), (const, override)); @@ -33,22 +34,28 @@ class ServiceMock : public WPEFramework::PluginHost::IShell { MOCK_METHOD(string, ProxyStubPath, (), (const, override)); MOCK_METHOD(string, HashKey, (), (const, override)); MOCK_METHOD(string, Substitute, (const string&), (const, override)); - MOCK_METHOD(WPEFramework::PluginHost::IShell::ICOMLink*, COMLink, (), (override)); MOCK_METHOD(uint32_t, Activate, (const reason), (override)); MOCK_METHOD(uint32_t, Deactivate, (const reason), (override)); MOCK_METHOD(uint32_t, Unavailable, (const reason), (override)); MOCK_METHOD(reason, Reason, (), (const, override)); - MOCK_METHOD(uint32_t, ConfigLine, (const string& config), (override)); + MOCK_METHOD(uint32_t, ConfigLine, (const string&), (override)); MOCK_METHOD(string, SystemRootPath, (), (const, override)); - MOCK_METHOD(uint32_t, SystemRootPath, (const string& systemRootPath), (override)); + MOCK_METHOD(uint32_t, SystemRootPath, (const string&), (override)); MOCK_METHOD(string, SystemPath, (), (const, override)); MOCK_METHOD(string, PluginPath, (), (const, override)); MOCK_METHOD(WPEFramework::PluginHost::IShell::startmode, StartMode, (), (const, override)); - MOCK_METHOD(WPEFramework::Core::hresult, StartMode, (const startmode value), (override)); - MOCK_METHOD(WPEFramework::Core::hresult, Resumed, (const bool value), (override)); - MOCK_METHOD(WPEFramework::Core::hresult, Metadata, (string & info /* @out */), (const, override)); - MOCK_METHOD(WPEFramework::Core::hresult, Hibernate, (const uint32_t timeout), (override)); + MOCK_METHOD(WPEFramework::Core::hresult, StartMode, (const startmode), (override)); + MOCK_METHOD(WPEFramework::Core::hresult, Resumed, (const bool), (override)); + MOCK_METHOD(WPEFramework::Core::hresult, Metadata, (string&), (const, override)); + MOCK_METHOD(WPEFramework::Core::hresult, Hibernate, (const uint32_t), (override)); + MOCK_METHOD(void, Register, (WPEFramework::RPC::IRemoteConnection::INotification*), (override)); + MOCK_METHOD(void, Unregister, (const WPEFramework::RPC::IRemoteConnection::INotification*), (override)); + MOCK_METHOD(void, Register, (IShell::ICOMLink::INotification*), (override)); + MOCK_METHOD(void, Unregister, (const IShell::ICOMLink::INotification*), (override)); + MOCK_METHOD(WPEFramework::RPC::IRemoteConnection*, RemoteConnection, (const uint32_t), (override)); + MOCK_METHOD(void*, Instantiate, (const WPEFramework::RPC::Object&, const uint32_t, uint32_t&), (override)); BEGIN_INTERFACE_MAP(ServiceMock) INTERFACE_ENTRY(IShell) + INTERFACE_ENTRY(IShell::ICOMLink) END_INTERFACE_MAP }; diff --git a/PersistentStore/l1test/PersistentStoreTest.cpp b/PersistentStore/l1test/PersistentStoreTest.cpp index e20200cacd..d16878b8b1 100644 --- a/PersistentStore/l1test/PersistentStoreTest.cpp +++ b/PersistentStore/l1test/PersistentStoreTest.cpp @@ -50,7 +50,7 @@ TEST_F(APersistentStore, MovesFileWhenInitializedWithNewAndPreviousPath) config.ToString(configJsonStr); ON_CALL(*service, ConfigLine()) .WillByDefault(Return(configJsonStr)); - ASSERT_THAT(plugin->Initialize(service), Eq("")); + plugin->Initialize(service); plugin->Deinitialize(service); ASSERT_THAT(WPEFramework::Core::File(kFile1).Exists(), IsFalse()); ASSERT_THAT(file2.Open(true), IsTrue()); diff --git a/PersistentStore/l1test/ServiceMock.h b/PersistentStore/l1test/ServiceMock.h index 36c5c3c43d..8aea54a268 100644 --- a/PersistentStore/l1test/ServiceMock.h +++ b/PersistentStore/l1test/ServiceMock.h @@ -3,7 +3,8 @@ #include "../Module.h" #include -class ServiceMock : public WPEFramework::PluginHost::IShell { +class ServiceMock : public WPEFramework::PluginHost::IShell, + public WPEFramework::PluginHost::IShell::ICOMLink { public: ~ServiceMock() override = default; MOCK_METHOD(string, Versions, (), (const, override)); @@ -33,22 +34,28 @@ class ServiceMock : public WPEFramework::PluginHost::IShell { MOCK_METHOD(string, ProxyStubPath, (), (const, override)); MOCK_METHOD(string, HashKey, (), (const, override)); MOCK_METHOD(string, Substitute, (const string&), (const, override)); - MOCK_METHOD(WPEFramework::PluginHost::IShell::ICOMLink*, COMLink, (), (override)); MOCK_METHOD(uint32_t, Activate, (const reason), (override)); MOCK_METHOD(uint32_t, Deactivate, (const reason), (override)); MOCK_METHOD(uint32_t, Unavailable, (const reason), (override)); MOCK_METHOD(reason, Reason, (), (const, override)); - MOCK_METHOD(uint32_t, ConfigLine, (const string& config), (override)); + MOCK_METHOD(uint32_t, ConfigLine, (const string&), (override)); MOCK_METHOD(string, SystemRootPath, (), (const, override)); - MOCK_METHOD(uint32_t, SystemRootPath, (const string& systemRootPath), (override)); + MOCK_METHOD(uint32_t, SystemRootPath, (const string&), (override)); MOCK_METHOD(string, SystemPath, (), (const, override)); MOCK_METHOD(string, PluginPath, (), (const, override)); MOCK_METHOD(WPEFramework::PluginHost::IShell::startmode, StartMode, (), (const, override)); - MOCK_METHOD(WPEFramework::Core::hresult, StartMode, (const startmode value), (override)); - MOCK_METHOD(WPEFramework::Core::hresult, Resumed, (const bool value), (override)); - MOCK_METHOD(WPEFramework::Core::hresult, Metadata, (string & info /* @out */), (const, override)); - MOCK_METHOD(WPEFramework::Core::hresult, Hibernate, (const uint32_t timeout), (override)); + MOCK_METHOD(WPEFramework::Core::hresult, StartMode, (const startmode), (override)); + MOCK_METHOD(WPEFramework::Core::hresult, Resumed, (const bool), (override)); + MOCK_METHOD(WPEFramework::Core::hresult, Metadata, (string&), (const, override)); + MOCK_METHOD(WPEFramework::Core::hresult, Hibernate, (const uint32_t), (override)); + MOCK_METHOD(void, Register, (WPEFramework::RPC::IRemoteConnection::INotification*), (override)); + MOCK_METHOD(void, Unregister, (const WPEFramework::RPC::IRemoteConnection::INotification*), (override)); + MOCK_METHOD(void, Register, (IShell::ICOMLink::INotification*), (override)); + MOCK_METHOD(void, Unregister, (const IShell::ICOMLink::INotification*), (override)); + MOCK_METHOD(WPEFramework::RPC::IRemoteConnection*, RemoteConnection, (const uint32_t), (override)); + MOCK_METHOD(void*, Instantiate, (const WPEFramework::RPC::Object&, const uint32_t, uint32_t&), (override)); BEGIN_INTERFACE_MAP(ServiceMock) INTERFACE_ENTRY(IShell) + INTERFACE_ENTRY(IShell::ICOMLink) END_INTERFACE_MAP }; diff --git a/PersistentStore/sqlite/Store2.cpp b/PersistentStore/sqlite/Store2.cpp deleted file mode 100644 index e14f855f8c..0000000000 --- a/PersistentStore/sqlite/Store2.cpp +++ /dev/null @@ -1,8 +0,0 @@ -#include "Store2.h" - -namespace WPEFramework { -namespace Plugin { - class SqliteStore2 : public Sqlite::Store2 {}; - SERVICE_REGISTRATION(SqliteStore2, 1, 0); -} // namespace Plugin -} // namespace WPEFramework From f6ea42c1000675e54f2d21b35e553892b1a58a6c Mon Sep 17 00:00:00 2001 From: Deva Date: Mon, 22 Apr 2024 21:18:42 +0530 Subject: [PATCH 17/23] Update MaintenanceManager.cpp Remove unused variable --- MaintenanceManager/MaintenanceManager.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/MaintenanceManager/MaintenanceManager.cpp b/MaintenanceManager/MaintenanceManager.cpp index 28a859fce9..57b0749757 100644 --- a/MaintenanceManager/MaintenanceManager.cpp +++ b/MaintenanceManager/MaintenanceManager.cpp @@ -333,7 +333,6 @@ namespace WPEFramework { } if (false == whoAmIStatus && activation_status != "activated") { - bool deviceContextSet = false; LOGINFO("knoWhoAmI() returned false and Device is not already Activated"); g_listen_to_deviceContextUpdate = true; LOGINFO("Waiting for onDeviceInitializationContextUpdate event"); From 16a97046b5370adbd1c653a5405bfc73541924fc Mon Sep 17 00:00:00 2001 From: Deva Date: Mon, 22 Apr 2024 21:27:27 +0530 Subject: [PATCH 18/23] Update MaintenanceManager.h Remove WAI compile flag --- MaintenanceManager/MaintenanceManager.h | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/MaintenanceManager/MaintenanceManager.h b/MaintenanceManager/MaintenanceManager.h index 2797530395..5fe5e43b68 100644 --- a/MaintenanceManager/MaintenanceManager.h +++ b/MaintenanceManager/MaintenanceManager.h @@ -135,6 +135,7 @@ namespace WPEFramework { bool g_unsolicited_complete; bool g_listen_to_nwevents = false; bool g_subscribed_for_nwevents = false; + bool g_listen_to_deviceContextUpdate = false; std::mutex m_callMutex; std::mutex m_statusMutex; @@ -142,12 +143,9 @@ namespace WPEFramework { std::thread m_thread; std::map m_task_map; -#if defined(ENABLE_WHOAMI) std::map m_param_map; std::map m_paramType_map; - bool knowWhoAmI(); - bool g_listen_to_deviceContextUpdate = false; -#endif + PluginHost::IShell* m_service; bool isDeviceOnline(); @@ -165,6 +163,7 @@ namespace WPEFramework { void deviceInitializationContextEventHandler(const JsonObject& parameters); void startCriticalTasks(); bool checkNetwork(); + bool knowWhoAmI(); bool subscribeToDeviceInitializationEvent(); bool setDeviceInitializationContext(JsonObject joGetResult); bool getActivatedStatus(bool &skipFirmwareCheck); From 8c5aaeb8dba3c7eb25e5819ea09ef67b601b4581 Mon Sep 17 00:00:00 2001 From: Deva Date: Mon, 22 Apr 2024 21:38:09 +0530 Subject: [PATCH 19/23] Update MaintenanceManager.cpp --- MaintenanceManager/MaintenanceManager.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/MaintenanceManager/MaintenanceManager.cpp b/MaintenanceManager/MaintenanceManager.cpp index 57b0749757..6222e82a6c 100644 --- a/MaintenanceManager/MaintenanceManager.cpp +++ b/MaintenanceManager/MaintenanceManager.cpp @@ -238,13 +238,11 @@ namespace WPEFramework { "uploadSTBLogs.sh" }; -#if defined(ENABLE_WHOAMI) static const array kDeviceInitContextKeyVals = { "partnerId", "osClass", "regionalConfigService" }; -#endif /* WhoAmI */ /** * Register MaintenanceManager module as wpeframework plugin From 854992e6ac3b87c0e53a25aa9b737855bc7acabd Mon Sep 17 00:00:00 2001 From: gururaajar <83449026+gururaajar@users.noreply.github.com> Date: Mon, 22 Apr 2024 15:36:43 -0400 Subject: [PATCH 20/23] Posting the events only for the eth0 and wlan0 interface (#5189) --- NetworkManager/service/NetworkManager.h | 4 +++ .../service/NetworkManagerRDKProxy.cpp | 29 +++++++++++++------ 2 files changed, 24 insertions(+), 9 deletions(-) diff --git a/NetworkManager/service/NetworkManager.h b/NetworkManager/service/NetworkManager.h index c059426591..95472b72f0 100644 --- a/NetworkManager/service/NetworkManager.h +++ b/NetworkManager/service/NetworkManager.h @@ -198,10 +198,14 @@ namespace WPEFramework oldInterface = "WIFI"; else if(prevActiveInterface == "eth0") oldInterface = "ETHERNET"; + else + oldInterface = prevActiveInterface; if(currentActiveinterface == "wlan0") newInterface = "WIFI"; else if(currentActiveinterface == "eth0") newInterface = "ETHERNET"; + else + newInterface = currentActiveinterface; legacyParams["oldInterfaceName"] = oldInterface; legacyParams["newInterfaceName"] = newInterface; _parent.Notify("onDefaultInterfaceChanged", legacyParams); diff --git a/NetworkManager/service/NetworkManagerRDKProxy.cpp b/NetworkManager/service/NetworkManagerRDKProxy.cpp index b2d6f918ec..c405fe56d1 100644 --- a/NetworkManager/service/NetworkManagerRDKProxy.cpp +++ b/NetworkManager/service/NetworkManagerRDKProxy.cpp @@ -406,20 +406,26 @@ namespace WPEFramework { IARM_BUS_NetSrvMgr_Iface_EventInterfaceEnabledStatus_t *e = (IARM_BUS_NetSrvMgr_Iface_EventInterfaceEnabledStatus_t*) data; NMLOG_INFO ("IARM_BUS_NETWORK_MANAGER_EVENT_INTERFACE_ENABLED_STATUS :: %s", e->interface); - if (e->status) - ::_instance->ReportInterfaceStateChangedEvent(Exchange::INetworkManager::INTERFACE_ADDED, string(e->interface)); - else - ::_instance->ReportInterfaceStateChangedEvent(Exchange::INetworkManager::INTERFACE_REMOVED, string(e->interface)); + if(e->interface == "eth0" || e->interface == "wlan0") + { + if (e->status) + ::_instance->ReportInterfaceStateChangedEvent(Exchange::INetworkManager::INTERFACE_ADDED, string(e->interface)); + else + ::_instance->ReportInterfaceStateChangedEvent(Exchange::INetworkManager::INTERFACE_REMOVED, string(e->interface)); + } break; } case IARM_BUS_NETWORK_MANAGER_EVENT_INTERFACE_CONNECTION_STATUS: { IARM_BUS_NetSrvMgr_Iface_EventInterfaceConnectionStatus_t *e = (IARM_BUS_NetSrvMgr_Iface_EventInterfaceConnectionStatus_t*) data; NMLOG_INFO ("IARM_BUS_NETWORK_MANAGER_EVENT_INTERFACE_CONNECTION_STATUS :: %s", e->interface); - if (e->status) - ::_instance->ReportInterfaceStateChangedEvent(Exchange::INetworkManager::INTERFACE_LINK_UP, string(e->interface)); - else - ::_instance->ReportInterfaceStateChangedEvent(Exchange::INetworkManager::INTERFACE_LINK_DOWN, string(e->interface)); + if(e->interface == "eth0" || e->interface == "wlan0") + { + if (e->status) + ::_instance->ReportInterfaceStateChangedEvent(Exchange::INetworkManager::INTERFACE_LINK_UP, string(e->interface)); + else + ::_instance->ReportInterfaceStateChangedEvent(Exchange::INetworkManager::INTERFACE_LINK_DOWN, string(e->interface)); + } break; } case IARM_BUS_NETWORK_MANAGER_EVENT_INTERFACE_IPADDRESS: @@ -427,13 +433,18 @@ namespace WPEFramework IARM_BUS_NetSrvMgr_Iface_EventInterfaceIPAddress_t *e = (IARM_BUS_NetSrvMgr_Iface_EventInterfaceIPAddress_t*) data; NMLOG_INFO ("IARM_BUS_NETWORK_MANAGER_EVENT_INTERFACE_IPADDRESS :: %s -- %s", e->interface, e->ip_address); - ::_instance->ReportIPAddressChangedEvent(string(e->interface), e->acquired, e->is_ipv6, string(e->ip_address)); + if(e->interface == "eth0" || e->interface == "wlan0") + ::_instance->ReportIPAddressChangedEvent(string(e->interface), e->acquired, e->is_ipv6, string(e->ip_address)); break; } case IARM_BUS_NETWORK_MANAGER_EVENT_DEFAULT_INTERFACE: { IARM_BUS_NetSrvMgr_Iface_EventDefaultInterface_t *e = (IARM_BUS_NetSrvMgr_Iface_EventDefaultInterface_t*) data; NMLOG_INFO ("IARM_BUS_NETWORK_MANAGER_EVENT_DEFAULT_INTERFACE %s :: %s..", e->oldInterface, e->newInterface); + if(e->oldInterface != "eth0" || e->oldInterface != "wlan0") + e->oldInterface == ""; /* assigning "null" if the interface is not eth0 or wlan0 */ + if(e->newInterface != "eth0" || e->newInterface != "wlan0") + e->newInterface == ""; /* assigning "null" if the interface is not eth0 or wlan0 */ ::_instance->ReportActiveInterfaceChangedEvent(e->oldInterface, e->newInterface); break; From 2d3a914313771deb04ea5468571e6f8ac3ac40ce Mon Sep 17 00:00:00 2001 From: tabbas651 <74683978+tabbas651@users.noreply.github.com> Date: Mon, 22 Apr 2024 15:53:23 -0400 Subject: [PATCH 21/23] XIONE-14377: [ALPACA_DE][UK][Alpaca IT][Foxtel] Ip linear (#5190) Reason for change: removed the unnecessary dispatcher release from invoke method which landed for R4.4.1 Test Procedure: Verified in Jenkins Build Signed-off-by: Thamim Razith Co-authored-by: Karunakaran A <48997923+karuna2git@users.noreply.github.com> --- RDKShell/RDKShell.cpp | 1 - ResourceManager/ResourceManager.cpp | 1 - SystemServices/platformcaps/platformcapsdata.h | 1 - 3 files changed, 3 deletions(-) diff --git a/RDKShell/RDKShell.cpp b/RDKShell/RDKShell.cpp index 6c87ae1edf..b3bfc40bf2 100755 --- a/RDKShell/RDKShell.cpp +++ b/RDKShell/RDKShell.cpp @@ -685,7 +685,6 @@ namespace WPEFramework { if (localDispatcher != nullptr) result = dispatcher_->Invoke(channelId, message->Id.Value(), sThunderSecurityToken, message->Designator.Value(), message->Parameters.Value(),output); - dispatcher_->Release(); } if (message.IsValid() == true) { diff --git a/ResourceManager/ResourceManager.cpp b/ResourceManager/ResourceManager.cpp index 5f7f6419cc..6474df67b0 100644 --- a/ResourceManager/ResourceManager.cpp +++ b/ResourceManager/ResourceManager.cpp @@ -375,7 +375,6 @@ namespace WPEFramework { if (localDispatcher != nullptr) result = dispatcher_->Invoke(channelId, message->Id.Value(), sThunderSecurityToken, message->Designator.Value(), message->Parameters.Value(),output); - dispatcher_->Release(); } if (message.IsValid() == true) { diff --git a/SystemServices/platformcaps/platformcapsdata.h b/SystemServices/platformcaps/platformcapsdata.h index ab74198e80..f346c3df93 100644 --- a/SystemServices/platformcaps/platformcapsdata.h +++ b/SystemServices/platformcaps/platformcapsdata.h @@ -172,7 +172,6 @@ class PlatformCapsData { if (localDispatcher != nullptr) result = dispatcher_->Invoke(channelId, message->Id.Value(), "", message->Designator.Value(), message->Parameters.Value(),output); - dispatcher_->Release(); } if (message.IsValid() == true) { From 90b8994df7e718a662d4d11147c5f3848f70c24e Mon Sep 17 00:00:00 2001 From: HarshiniRavichandran <166796069+HarshiniRavichandran@users.noreply.github.com> Date: Wed, 24 Apr 2024 14:50:18 +0530 Subject: [PATCH 22/23] RDKVREFPLT-721: [BCM72126] RDK Services: DeviceIdentification plugin is not enabled in the device Reason for change: Enabled the DeviceIdentification plugin and added methods for retrieving Serial number, Chip Id and Firmware version. Test Procedure: root@brcm972126ott-refboard-PR0013720:~# curl -X POST http://127.0.0.1:9998/jsonrpc -d '{"jsonrpc":"2.0","id":"42","method":"DeviceIdentification.1.deviceidentification"}';echo; {"jsonrpc":"2.0","id":42,"result":{"firmwareversion":"5.01.23.24","chipset":"BCM972126OTT_V20","deviceid":"OEUFIwMDEzNzIwAA"}} --- .../Implementation/Broadcom/Broadcom.cpp | 76 ++++++++++++------- 1 file changed, 50 insertions(+), 26 deletions(-) diff --git a/DeviceIdentification/Implementation/Broadcom/Broadcom.cpp b/DeviceIdentification/Implementation/Broadcom/Broadcom.cpp index f915abfb9d..44e5eb3412 100644 --- a/DeviceIdentification/Implementation/Broadcom/Broadcom.cpp +++ b/DeviceIdentification/Implementation/Broadcom/Broadcom.cpp @@ -78,39 +78,63 @@ class DeviceImplementation : public PluginHost::ISubSystem::IIdentifier { private: inline void UpdateDeviceInfo(string& identifier, string& chipset, string& firmwareVersion) const { - static constexpr uint8_t MaxInfoCollection = 3; - static constexpr const TCHAR ChipsetKey[] = _T("Chip ID"); - static constexpr const TCHAR IdentifierKey[] = _T("CHIPID"); - static constexpr const TCHAR FirmwareVersionKey[] = _T("Nexus Release"); + identifier.assign(extractSerialNumber()); + chipset.assign(extractChipId()); + firmwareVersion.assign(extractFirmwareVersion()); + } + + inline std::string extractSerialNumber() const + { + std::string serialNumber; + std::ifstream serialNumberFile("/proc/device-tree/serial-number"); + + if (serialNumberFile.is_open()) + { + getline(serialNumberFile,serialNumber); + serialNumberFile.close(); + } + + return serialNumber; + } + + inline std::string extractChipId() const + { + std::string chipId; + std::ifstream chipIdFile("/proc/device-tree/model"); + if (chipIdFile.is_open()) + { + getline(chipIdFile, chipId); + chipIdFile.close(); + } + + return chipId; + } + + inline std::string extractFirmwareVersion() const + { + std::string versionIdentifier("VERSION"); + std::ifstream versionFile("/version.txt"); std::string line; - std::ifstream file(PlatformFile); - uint32_t collectedInfo = 0; - - if (file.is_open()) { - while (getline(file, line) && (collectedInfo < MaxInfoCollection)) { - if ((identifier.empty() == true) && (line.find(IdentifierKey) != std::string::npos)) { - std::size_t position = line.find(IdentifierKey) + sizeof(IdentifierKey); - if (position != std::string::npos) { - identifier.assign(line.substr(position, line.find(']')-position)); - collectedInfo++; - } - } else if ((chipset.empty() == true) && (line.find(ChipsetKey) != std::string::npos)) { - std::size_t position = line.find(ChipsetKey) + sizeof(ChipsetKey); - if (position != std::string::npos) { - chipset.assign(line.substr(position, std::string::npos)); - collectedInfo++; - } - } else if ((firmwareVersion.empty() == true) && - (line.find(FirmwareVersionKey) != std::string::npos)) { - std::size_t position = line.find(FirmwareVersionKey) + sizeof(FirmwareVersionKey); - if (position != std::string::npos) { + std::string firmwareVersion; + + if (versionFile.is_open()) + { + while (getline(versionFile, line)) + { + if (0 == line.find(versionIdentifier)) + { + std::size_t position = line.find(versionIdentifier) + versionIdentifier.length() + 1; // +1 is to skip '=' + if (position != std::string::npos) + { firmwareVersion.assign(line.substr(position, std::string::npos)); - collectedInfo++; } } } + versionFile.close(); } + + return firmwareVersion; } private: From fcb8eb7731ebfa3ef12f6e23e98d9dbb309cae9c Mon Sep 17 00:00:00 2001 From: gururaajar <83449026+gururaajar@users.noreply.github.com> Date: Wed, 24 Apr 2024 14:02:58 -0400 Subject: [PATCH 23/23] RDK-46636 - NetworkManager backward compatibility (#5203) Reason for change: Added handler2 support for initiateWPSPairing Test Procedure: Build and verified Risks: Low Priority: P1 Signed-off-by: Gururaaja ESR --- NetworkManager/service/NetworkManagerLegacy.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/NetworkManager/service/NetworkManagerLegacy.cpp b/NetworkManager/service/NetworkManagerLegacy.cpp index 005ffcc7c0..729734bec6 100644 --- a/NetworkManager/service/NetworkManagerLegacy.cpp +++ b/NetworkManager/service/NetworkManagerLegacy.cpp @@ -73,6 +73,7 @@ namespace WPEFramework Register("getCurrentState", &NetworkManager::GetWifiState, this); GetHandler(2)->Register("setIPSettings", &NetworkManager::setIPSettings, this); GetHandler(2)->Register("getIPSettings", &NetworkManager::getIPSettings, this); + GetHandler(2)->Register("initiateWPSPairing", &NetworkManager::initiateWPSPairing, this); } /**