RDKEMW-13117: Use IARM for PowerManager clients#168
RDKEMW-13117: Use IARM for PowerManager clients#168yuvaramachandran-gurusamy wants to merge 2 commits intotopic/support-2p16p9_Testfrom
Conversation
Signed-off-by: apatel859 <amit_patel5@comcast.com>
There was a problem hiding this comment.
Pull request overview
This PR migrates power management functionality from WPEFramework's PowerManager plugin to IARM-based power management for XCast and MiracastService plugins. This change simplifies the architecture by removing the COM-RPC dependency on PowerManager and using direct IARM bus communication instead.
Changes:
- Replaced WPEFramework PowerManager COM-RPC interface with IARM bus calls for power state management
- Converted power state types from
IPowerManager::PowerStatetoIARM_Bus_PWRMgr_PowerState_t - Removed PowerManager notification classes and replaced with IARM event handlers
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 7 comments.
| File | Description |
|---|---|
| XCast/XCast.h | Removed PowerManager interface dependencies, added pwrMgr.h header, removed PowerManagerNotification class, changed power state type to IARM enum |
| XCast/XCast.cpp | Replaced InitializePowerManager with InitializeIARM, converted power state handling to use IARM bus calls, implemented IARM event handlers |
| Miracast/MiracastService/MiracastService.h | Removed PowerManager interface dependencies, added pwrMgr.h header, removed PowerManagerNotification class, updated method signatures |
| Miracast/MiracastService/MiracastService.cpp | Replaced PowerManager initialization with InitializeIARM, implemented IARM event handlers, updated power state handling logic |
Comments suppressed due to low confidence (2)
XCast/XCast.cpp:425
- DeinitializeIARM is never called. The InitializeIARM method is called during plugin initialization (line 359), but there is no corresponding call to DeinitializeIARM in the Deinitialize method. This means IARM event handlers are never unregistered when the plugin is deinitialized, leading to resource leaks and potential crashes if events fire after the plugin object is destroyed.
void XCast::Deinitialize(PluginHost::IShell* service)
{
int count = 0;
while(powerModeChangeActive && count < 20){
sleep(100);
count++;
}
ASSERT(_service == service);
ASSERT(_xcast != nullptr);
getSystemPlugin();
if (m_SystemPluginObj)
{
m_SystemPluginObj->Unsubscribe(THUNDER_RPC_TIMEOUT, "onFriendlyNameChanged");
delete m_SystemPluginObj;
m_SystemPluginObj = nullptr;
}
if(_xcast)
{
_xcast->Deinitialize();
_xcast->Unregister(&_notification);
}
if(_service)
_service->Unregister(&_notification);
if(_xcast) {
if(_xcast->Release() != Core::ERROR_DESTRUCTION_SUCCEEDED) {
ASSERT(_connectionId != 0);
LOGINFO("XCast Plugin is not properly destructed. %d", _connectionId);
if(_service) {
RPC::IRemoteConnection* connection(_service->RemoteConnection(_connectionId));
// The process can disappear in the meantime...
if (connection != nullptr) {
// But if it did not dissapear in the meantime, forcefully terminate it. Shoot to kill :-)
connection->Terminate();
connection->Release();
}
}
}
}
_xcast = nullptr;
_service = nullptr;
}
XCast/XCast.cpp:304
- Missing null check for m_instance before dereferencing. In event handlers that run in detached threads, m_instance is accessed without checking if it's nullptr first. If the plugin is destroyed or the Deinitialize method is called before these threads complete, this will cause a crash. Similar issue exists on line 309.
Add null checks before accessing m_instance->_xcast, e.g., "if (m_instance && m_instance->_xcast)".
void XCast::threadPowerModeChangeEvent(void)
{
powerModeChangeActive = true;
LOGINFO(" threadPowerModeChangeEvent m_standbyBehavior:%d , m_powerState:%d ",m_standbyBehavior,m_powerState);
if(m_powerState == IARM_BUS_PWRMGR_POWERSTATE_ON)
{
m_sleeptime = 1;
if (m_is_restart_req)
{
m_instance->_xcast->Deinitialize();
sleep(1);
m_instance->_xcast->Initialize(m_networkStandbyMode);
m_is_restart_req = false;
}
}
else if (m_powerState == IARM_BUS_PWRMGR_POWERSTATE_STANDBY_DEEP_SLEEP )
{
m_sleeptime = 3;
m_is_restart_req = true; //After DEEPSLEEP, restart xdial again for next transition.
}
if(m_standbyBehavior == false)
{
if(m_xcastEnable && ( m_powerState == IARM_BUS_PWRMGR_POWERSTATE_ON))
m_instance->_xcast->enableCastService(m_friendlyName,true);
else
m_instance->_xcast->enableCastService(m_friendlyName,false);
}
powerModeChangeActive = false;
}
| if ((strcmp(owner, IARM_BUS_PWRMGR_NAME) == 0) && ( eventId == IARM_BUS_PWRMGR_EVENT_NETWORK_STANDBYMODECHANGED )) { | ||
| IARM_Bus_PWRMgr_EventData_t *param = (IARM_Bus_PWRMgr_EventData_t *)data; | ||
| m_networkStandbyMode = param->data.bNetworkStandbyMode; | ||
| LOGWARN("creating worker thread for threadNetworkStandbyModeChangeEvent Mode :%u",m_networkStandbyMode); | ||
| std::thread networkStandbyModeChangeThread = std::thread(networkStandbyModeChangeEvent); | ||
| networkStandbyModeChangeThread.detach(); | ||
| } |
There was a problem hiding this comment.
Inconsistent indentation. The networkStandbyModeChange function body uses 2-space indentation (lines 266-272) while the surrounding code and powerModeChange function use 4-space indentation. This inconsistency makes the code harder to read and should be corrected to match the project's coding style.
| if ((strcmp(owner, IARM_BUS_PWRMGR_NAME) == 0) && ( eventId == IARM_BUS_PWRMGR_EVENT_NETWORK_STANDBYMODECHANGED )) { | |
| IARM_Bus_PWRMgr_EventData_t *param = (IARM_Bus_PWRMgr_EventData_t *)data; | |
| m_networkStandbyMode = param->data.bNetworkStandbyMode; | |
| LOGWARN("creating worker thread for threadNetworkStandbyModeChangeEvent Mode :%u",m_networkStandbyMode); | |
| std::thread networkStandbyModeChangeThread = std::thread(networkStandbyModeChangeEvent); | |
| networkStandbyModeChangeThread.detach(); | |
| } | |
| if ((strcmp(owner, IARM_BUS_PWRMGR_NAME) == 0) && ( eventId == IARM_BUS_PWRMGR_EVENT_NETWORK_STANDBYMODECHANGED )) { | |
| IARM_Bus_PWRMgr_EventData_t *param = (IARM_Bus_PWRMgr_EventData_t *)data; | |
| m_networkStandbyMode = param->data.bNetworkStandbyMode; | |
| LOGWARN("creating worker thread for threadNetworkStandbyModeChangeEvent Mode :%u",m_networkStandbyMode); | |
| std::thread networkStandbyModeChangeThread = std::thread(networkStandbyModeChangeEvent); | |
| networkStandbyModeChangeThread.detach(); | |
| } |
| m_isTestNotifierEnabled = false; | ||
| Register(METHOD_MIRACAST_TEST_NOTIFIER, &MiracastService::testNotifier, this); |
There was a problem hiding this comment.
Inconsistent indentation in constructor. The constructor body mixes tabs and spaces for indentation. Lines 109-111 and 130 use tabs, while lines 113-129 appear to use spaces. This inconsistency can cause issues with different editor settings and makes the code harder to maintain. All lines should use the same indentation style (likely tabs based on the surrounding code).
| m_isTestNotifierEnabled = false; | |
| Register(METHOD_MIRACAST_TEST_NOTIFIER, &MiracastService::testNotifier, this); | |
| m_isTestNotifierEnabled = false; | |
| Register(METHOD_MIRACAST_TEST_NOTIFIER, &MiracastService::testNotifier, this); |
| LOGINFO("Disconnect from the COM-RPC socket\n"); | ||
| // Disconnect from the COM-RPC socket | ||
| if (_communicatorClient.IsValid()) { | ||
| _communicatorClient->Close(RPC::CommunicationTimeOut); | ||
| _communicatorClient.Release(); | ||
| } | ||
|
|
||
| if (_engine.IsValid()) { | ||
| _engine.Release(); | ||
| } |
There was a problem hiding this comment.
References to removed member variables _engine and _communicatorClient. These member variables were removed from the header file but are still being referenced in the Deinitialize method. This will cause compilation errors.
| void XCast::threadPowerModeChangeEvent(void) | ||
| { | ||
| powerModeChangeActive = true; | ||
| LOGINFO(" threadPowerModeChangeEvent m_standbyBehavior:%d , m_powerState:%d ",m_standbyBehavior,m_powerState); | ||
| if(m_powerState == WPEFramework::Exchange::IPowerManager::POWER_STATE_ON) | ||
| if(m_powerState == IARM_BUS_PWRMGR_POWERSTATE_ON) | ||
| { | ||
| m_sleeptime = 1; | ||
| if (m_is_restart_req) |
There was a problem hiding this comment.
Potential race condition and null pointer dereference. The detached thread accesses m_instance->_xcast without checking if m_instance is nullptr. Since this is a static method called from a detached thread, there's a race condition where the plugin could be deinitialized while the thread is running, leading to a crash.
Add a null check: "if (m_instance && m_instance->_xcast)" before accessing m_instance->_xcast.
|
|
||
| if(m_standbyBehavior == false) | ||
| { | ||
| if(m_xcastEnable && ( m_powerState == WPEFramework::Exchange::IPowerManager::POWER_STATE_ON)) | ||
| if(m_xcastEnable && ( m_powerState == IARM_BUS_PWRMGR_POWERSTATE_ON)) | ||
| m_instance->_xcast->enableCastService(m_friendlyName,true); | ||
| else | ||
| m_instance->_xcast->enableCastService(m_friendlyName,false); |
There was a problem hiding this comment.
Potential race condition and null pointer dereference. The detached thread accesses m_instance->_xcast without checking if m_instance is nullptr. Since this is a static method called from a detached thread, there's a race condition where the plugin could be deinitialized while the thread is running, leading to a crash.
Add a null check: "if (m_instance && m_instance->_xcast)" before accessing m_instance->_xcast on line 299.
| @@ -218,49 +209,33 @@ void XCast::DeinitializeIARM() | |||
| Unregister(METHOD_SET_FRIENDLYNAME); | |||
| } | |||
There was a problem hiding this comment.
DeinitializeIARM contains unrelated method unregistrations. The DeinitializeIARM method is unregistering JSON RPC methods (lines 202-209) which are not related to IARM initialization. These method unregistrations should be in a separate function or in the Deinitialize method. This mixing of concerns makes the code harder to maintain and understand.
| @@ -218,49 +209,33 @@ void XCast::DeinitializeIARM() | |||
| Unregister(METHOD_SET_FRIENDLYNAME); | |||
| } | |||
There was a problem hiding this comment.
Missing event handler unregistration for IARM_BUS_PWRMGR_EVENT_NETWORK_STANDBYMODECHANGED. The InitializeIARM method registers two event handlers (MODECHANGED and NETWORK_STANDBYMODECHANGED on lines 177-178), but DeinitializeIARM only unregisters the MODECHANGED handler. This will cause a resource leak and potentially dangling callback references when the plugin is deinitialized.
Add the missing unregistration for the networkStandbyModeChange handler.
No description provided.