From 88471559eaaa14edb81594919db5c7d04d8303d8 Mon Sep 17 00:00:00 2001 From: Ramesh Babu H Date: Wed, 12 Mar 2025 14:54:00 +0530 Subject: [PATCH 01/11] systimermgr Powercontroller changes, power_connect added, powerconnect retryy, cb event handler changes --- systimemgr.cpp | 6 + systimemgr.h | 2 +- systimerfactory/iarmsubscribe.cpp | 246 ++++++++++++++++++++++++++---- systimerfactory/iarmsubscribe.h | 44 +++++- 4 files changed, 261 insertions(+), 37 deletions(-) diff --git a/systimemgr.cpp b/systimemgr.cpp index 0aaf3e26..ff29eac0 100644 --- a/systimemgr.cpp +++ b/systimemgr.cpp @@ -171,6 +171,12 @@ void SysTimeMgr::run(bool forever) processThrd.join(); timerThrd.join(); pathMonitorThrd.join(); + + /* This is for the systemtime manager event handler thread and mutex variable Deinitalization */ + m_subscriber->SysTimeMgrDeinitPwrEvt(); + + /* This is for the Termination of systemtime manager's power controller client handler */ + PowerController_Term(); } else { diff --git a/systimemgr.h b/systimemgr.h index ec1821f4..d52ae1d5 100644 --- a/systimemgr.h +++ b/systimemgr.h @@ -35,7 +35,7 @@ #include "isubscribe.h" #include "itimermsg.h" #include - +#include "power_controller.h" using namespace std; diff --git a/systimerfactory/iarmsubscribe.cpp b/systimerfactory/iarmsubscribe.cpp index 8190509d..4e4554f6 100644 --- a/systimerfactory/iarmsubscribe.cpp +++ b/systimerfactory/iarmsubscribe.cpp @@ -19,10 +19,17 @@ #include "libIARM.h" #include "libIBus.h" #include "libIARMCore.h" -#include "pwrMgr.h" #include "irdklog.h" IarmSubscriber* IarmSubscriber::pInstance = NULL; + +std::mutex IarmSubscriber::m_pwrEvtQueueLock; +std::mutex IarmSubscriber::m_pwrEvtMutexLock; +std::condition_variable IarmSubscriber::m_pwrEvtCondVar; +std::thread IarmSubscriber::m_sysTimeMgrPwrEvtHandlerThread; +std::atomic IarmSubscriber::m_sysTimeMgrPwrStopThread{false}; +std::queue IarmSubscriber::m_pwrEvtQueue; + IarmSubscriber::IarmSubscriber(string sub):ISubscribe(sub),m_powerHandler(NULL) { int registered; @@ -38,43 +45,220 @@ bool IarmSubscriber::subscribe(string eventname,funcPtr fptr) RDK_LOG(RDK_LOG_INFO,LOG_SYSTIME,"[%s:%d]:IARMBUS Registering function for Event = %s \n",__FUNCTION__,__LINE__,eventname.c_str()); bool retCode = false; - if (eventname == POWER_CHANGE_MSG) { - m_powerHandler = fptr; - retCode = IARM_Bus_RegisterEventHandler(IARM_BUS_PWRMGR_NAME,IARM_BUS_PWRMGR_EVENT_MODECHANGED,IarmSubscriber::powereventHandler); - } - else { - retCode = IARM_Bus_RegisterCall(eventname.c_str(),(IARM_BusCall_t)fptr); - } + uint32_t retValPwrCtrl=0; + if (eventname == POWER_CHANGE_MSG) + { + /* This is for the initalization of refactored power controller client for IARM communication used in systemtime manager + All the Power Controller functions are handled here */ + PowerController_Init(); - return retCode; + /* This is for the systemtime manager event handler thread and mutex variable initalization */ + IarmSubscriber::sysTimeMgrInitPwrEvt(); + m_powerHandler = fptr; + + /* Check for Power Controller Connection and if failure, start a new thread and wait until connection established */ + if(POWER_CONTROLLER_ERROR_NONE == PowerController_Connect()) + { + /* The registration function returns different values for different errors and err none value is 0 */ + retValPwrCtrl = PowerController_RegisterPowerModeChangedCallback(IarmSubscriber::sysTimeMgrPwrEventHandler, nullptr); + if(POWER_CONTROLLER_ERROR_NONE != retValPwrCtrl) + { + /* The caller of the subscribe function does not check retCode, Only Error is Logged here for Failure */ + RDK_LOG(RDK_LOG_ERROR, LOG_SYSTIME, "[%s:%d]:Power Controller RegisterPowerModeChangedCallback Failed retValPwrCtrl=[%d]\n", __FUNCTION__, __LINE__,retValPwrCtrl); + } + else + { + RDK_LOG(RDK_LOG_INFO,LOG_SYSTIME,"[%s:%d]:Power Controller Registration Success \n",__FUNCTION__,__LINE__); + retCode = true; + } + } + else + { + std::thread pwrConnectHandlerThread; + pwrConnectHandlerThread = std::thread(&IarmSubscriber::sysTimeMgrPwrConnectHandlingThreadFunc, nullptr); + if (!pwrConnectHandlerThread.joinable()) + { + /* The caller of the subscribe function does not check retCode, Only Error is Logged here for Failure */ + RDK_LOG(RDK_LOG_ERROR, LOG_SYSTIME, "[%s:%d]:Thread Creation Power Controller Connect HandlerThread Failed\n", __FUNCTION__, __LINE__); + } + else + { + RDK_LOG(RDK_LOG_INFO,LOG_SYSTIME,"[%s:%d]:Power Controller Thread Creation Success \n",__FUNCTION__,__LINE__); + retCode = true; + pwrConnectHandlerThread.detach(); + } + } + } + else + { + retCode = IARM_Bus_RegisterCall(eventname.c_str(),(IARM_BusCall_t)fptr); + } + return retCode; +} + +void IarmSubscriber::sysTimeMgrPwrEventHandler(const PowerController_PowerState_t currentState, + const PowerController_PowerState_t newState, + void *userdata) +{ RDK_LOG(RDK_LOG_INFO, LOG_SYSTIME, "[%s:%d]:Entering \n", __FUNCTION__, __LINE__); + { + std::lock_guard lock(m_pwrEvtQueueLock); + m_pwrEvtQueue.emplace(currentState, newState); + } + RDK_LOG(RDK_LOG_INFO, LOG_SYSTIME, "[%s:%d]:Sending Signal to Thread for Processing Callback Event\n", __FUNCTION__, __LINE__); + m_pwrEvtCondVar.notify_one(); } -void IarmSubscriber::powereventHandler(const char *owner, int eventId, void *data, size_t len) +void IarmSubscriber::sysTimeMgrPwrConnectHandlingThreadFunc(void *arg) { - RDK_LOG(RDK_LOG_INFO,LOG_SYSTIME,"[%s:%d]:Power Change Event Received\n",__FUNCTION__,__LINE__); - if (eventId != IARM_BUS_PWRMGR_EVENT_MODECHANGED) { - return; - } + RDK_LOG(RDK_LOG_INFO, LOG_SYSTIME, "[%s:%d]: Entered \n", __FUNCTION__, __LINE__); + uint32_t retValPwrCtrl=0; - IARM_Bus_PWRMgr_EventData_t *param = (IARM_Bus_PWRMgr_EventData_t *)data; - RDK_LOG(RDK_LOG_INFO,LOG_SYSTIME,"[%s:%d]:Power Change Event Received. New State = %d\n",__FUNCTION__,__LINE__,param->data.state.newState); + /* Loop and check for Power controller connection and if fails sleep and retry */ + while(true) + { + if(POWER_CONTROLLER_ERROR_NONE == PowerController_Connect()) + { + RDK_LOG(RDK_LOG_INFO, LOG_SYSTIME, "[%s:%d]: PowerController_Connect is Success\n", __FUNCTION__, __LINE__); + break; + } + else + { + RDK_LOG(RDK_LOG_ERROR, LOG_SYSTIME, "[%s:%d]:PowerController_Connect Failed\n", __FUNCTION__, __LINE__); + /* Sleep for 300 msec */ + usleep(PWR_CNTRL_CONNECT_WAIT_TIME_MS); + } + } + retValPwrCtrl = PowerController_RegisterPowerModeChangedCallback(IarmSubscriber::sysTimeMgrPwrEventHandler, nullptr); + if(POWER_CONTROLLER_ERROR_NONE != retValPwrCtrl) + { + /* Ideally Call back should not fail and failure can happen only if reregister same function is done. + Only Error is Logged here for Failure as this is a separate thread*/ + RDK_LOG(RDK_LOG_ERROR, LOG_SYSTIME, "[%s:%d]:Power Controller RegisterPowerModeChangedCallback Failed retValPwrCtrl=[%d]\n", __FUNCTION__, __LINE__,retValPwrCtrl); + } + RDK_LOG(RDK_LOG_INFO,LOG_SYSTIME,"[%s:%d]:Power Controller Registration Thread Exits Gracefully retValPwrCtrl = %d\n",__FUNCTION__,__LINE__,retValPwrCtrl); +} - if ((param->data.state.newState == IARM_BUS_PWRMGR_POWERSTATE_OFF) || - (param->data.state.newState == IARM_BUS_PWRMGR_POWERSTATE_STANDBY_DEEP_SLEEP)) { +void IarmSubscriber::sysTimeMgrPwrEventHandlingThreadFunc(void *arg) +{ + RDK_LOG(RDK_LOG_INFO, LOG_SYSTIME, "[%s:%d]: Entered \n", __FUNCTION__, __LINE__); - RDK_LOG(RDK_LOG_INFO,LOG_SYSTIME,"[%s:%d]:Deep Sleep Event Received\n",__FUNCTION__,__LINE__); - if (IarmSubscriber::getInstance()) { + while (true) + { + std::unique_lock lkVar(m_pwrEvtMutexLock); + RDK_LOG(RDK_LOG_INFO, LOG_SYSTIME, "[%s:%d]: Waiting for Events from Power Manager\n", __FUNCTION__, __LINE__); + /* Wait until the queue is not empty or stop thread is signaled */ + m_pwrEvtCondVar.wait(lkVar, [] + { + return !m_pwrEvtQueue.empty() || m_sysTimeMgrPwrStopThread; + }); + if (m_sysTimeMgrPwrStopThread) + { + RDK_LOG(RDK_LOG_INFO, LOG_SYSTIME, "[%s:%d]: Exiting thread - stop flag set\n", __FUNCTION__, __LINE__); + lkVar.unlock(); + break; + } + /* Unlock before processing event from the Queue */ + lkVar.unlock(); + SysTimeMgr_Power_Event_State_t sysTimeMgrPwrEvent(POWER_STATE_UNKNOWN,POWER_STATE_UNKNOWN); + { + std::lock_guard queueLock(m_pwrEvtQueueLock); + if (!m_pwrEvtQueue.empty()) + { + sysTimeMgrPwrEvent = std::move(m_pwrEvtQueue.front()); + m_pwrEvtQueue.pop(); + } + } + IarmSubscriber::sysTimeMgrHandlePwrEventData(sysTimeMgrPwrEvent.currentState, sysTimeMgrPwrEvent.newState); + } + RDK_LOG(RDK_LOG_INFO, LOG_SYSTIME, "[%s:%d]: Exited thread\n", __FUNCTION__, __LINE__); +} - string powerstatus("DEEP_SLEEP_ON"); - IarmSubscriber::getInstance()->invokepowerhandler((void*)&powerstatus); - } - } - else if ((param->data.state.curState == IARM_BUS_PWRMGR_POWERSTATE_STANDBY_DEEP_SLEEP) && - ((param->data.state.newState == IARM_BUS_PWRMGR_POWERSTATE_ON) || - (param->data.state.newState == IARM_BUS_PWRMGR_POWERSTATE_STANDBY_LIGHT_SLEEP) || - (param->data.state.newState == IARM_BUS_PWRMGR_POWERSTATE_STANDBY))) { - string powerstatus("DEEP_SLEEP_OFF"); - IarmSubscriber::getInstance()->invokepowerhandler((void*)&powerstatus); - } +void IarmSubscriber::sysTimeMgrHandlePwrEventData(const PowerController_PowerState_t currentState, + const PowerController_PowerState_t newState) +{ + RDK_LOG(RDK_LOG_INFO,LOG_SYSTIME,"[%s:%d]:SysTimeMgrHandlePwrEventData currentState[%d] newState[%d]\n",__FUNCTION__,__LINE__,currentState,newState); + + if(IarmSubscriber::getInstance()) + { + switch(newState) + { + case POWER_STATE_OFF: + case POWER_STATE_STANDBY_DEEP_SLEEP: + RDK_LOG(RDK_LOG_INFO,LOG_SYSTIME,"[%s:%d]:Deep Sleep ON Invoked\n",__FUNCTION__,__LINE__); + string powerstatus("DEEP_SLEEP_ON"); + IarmSubscriber::getInstance()->invokepowerhandler((void*)&powerstatus); + break; + + case POWER_STATE_ON: + case POWER_STATE_STANDBY_LIGHT_SLEEP: + case POWER_STATE_STANDBY: + if(POWER_STATE_STANDBY_DEEP_SLEEP == currentState) + { + RDK_LOG(RDK_LOG_INFO,LOG_SYSTIME,"[%s:%d]:Deep Sleep OFF Invoked\n",__FUNCTION__,__LINE__); + string powerstatus("DEEP_SLEEP_OFF"); + IarmSubscriber::getInstance()->invokepowerhandler((void*)&powerstatus); + } + break; + + default: + RDK_LOG(RDK_LOG_INFO,LOG_SYSTIME,"[%s:%d]:Err: default case Unable to getInstance\n",__FUNCTION__,__LINE__); + break; + } + } + else + { + RDK_LOG(RDK_LOG_INFO,LOG_SYSTIME,"[%s:%d]:Err: Unable to getInstance\n",__FUNCTION__,__LINE__); + } } + + +void IarmSubscriber::sysTimeMgrInitPwrEvt(void) +{ + RDK_LOG(RDK_LOG_INFO,LOG_SYSTIME,"[%s:%d]:Entering \n",__FUNCTION__,__LINE__); + + /* Initialize the Mutex and waitsignal variable, Create the thread used to separate the context of power event Callback function */ + std::lock_guard lock(m_pwrEvtMutexLock); + + m_sysTimeMgrPwrStopThread = false; + + m_sysTimeMgrPwrEvtHandlerThread = std::thread(&IarmSubscriber::sysTimeMgrPwrEventHandlingThreadFunc, nullptr); + if (m_sysTimeMgrPwrEvtHandlerThread.joinable()) + { + RDK_LOG(RDK_LOG_INFO, LOG_SYSTIME, "[%s:%d]:Thread Creation is Success\n", __FUNCTION__, __LINE__); + } + else + { + RDK_LOG(RDK_LOG_ERROR, LOG_SYSTIME, "[%s:%d]:Thread Creation Failed\n", __FUNCTION__, __LINE__); + } +} + +void IarmSubscriber::sysTimeMgrDeinitPwrEvt(void) +{ + RDK_LOG(RDK_LOG_INFO,LOG_SYSTIME,"[%s:%d]:Entered \n",__FUNCTION__,__LINE__); + + { + /* Notify the Event thread function to Exit, send signal with stop thread true so that the new CB thread exits, + lock Guard is unlocked after out of scope after this block */ + std::lock_guard lock(m_pwrEvtMutexLock); + m_sysTimeMgrPwrStopThread=true; + m_pwrEvtCondVar.notify_one(); + } + + /* Clear the elements of the Queue */ + { + std::lock_guard lock(m_pwrEvtQueueLock); + m_pwrEvtQueue = std::queue(); + } + + /* Wait until the CB thread finishes and exits*/ + if (m_sysTimeMgrPwrEvtHandlerThread.joinable()) + { + RDK_LOG(RDK_LOG_INFO, LOG_SYSTIME, "[%s:%d]:Deinit Joining the thread\n", __FUNCTION__, __LINE__); + m_sysTimeMgrPwrEvtHandlerThread.join(); + RDK_LOG(RDK_LOG_INFO, LOG_SYSTIME, "[%s:%d]:Completed Deinit and Joined thread\n", __FUNCTION__, __LINE__); + } + + /* The clean up of mutex automatically happen after it is out of scope */ +} + diff --git a/systimerfactory/iarmsubscribe.h b/systimerfactory/iarmsubscribe.h index a56f2f0b..84e111b5 100644 --- a/systimerfactory/iarmsubscribe.h +++ b/systimerfactory/iarmsubscribe.h @@ -19,25 +19,59 @@ #define _IARMSUBSCRIBER_H_ #include +#include +#include +#include +#include +#include #include "isubscribe.h" +#include "power_controller.h" //Although we could use Lambda functions and higher order functions(which are available from c++11 onwards.) //Since the registration functions typically c functions. //Perhaps this can be cosidered at a later point of time. using namespace std; + +/* System Time Mgr Power Controller State Data Structure to Pass Queue Data to the Event handler Thread */ +typedef struct SysTimeMgr_Power_Event_State{ + PowerController_PowerState_t currentState; + PowerController_PowerState_t newState; + SysTimeMgr_Power_Event_State(PowerController_PowerState_t currSt, PowerController_PowerState_t newSt) + : currentState(currSt), newState(newSt) {} +}SysTimeMgr_Power_Event_State_t; + +/* power controller connect function retry delay of 300msec */ +#define PWR_CNTRL_CONNECT_WAIT_TIME_MS (300000) + class IarmSubscriber:public ISubscribe { - private: - static IarmSubscriber* pInstance; - funcPtr m_powerHandler; + private: + static IarmSubscriber* pInstance; + funcPtr m_powerHandler; + /* Power Controller queue and mutex to guard it*/ + static std::queue m_pwrEvtQueue; + static std::mutex m_pwrEvtQueueLock; + /* Power Controller Event Handling Thread variables*/ + static std::thread m_sysTimeMgrPwrEvtHandlerThread; + static std::mutex m_pwrEvtMutexLock; + static std::condition_variable m_pwrEvtCondVar; + static std::atomic m_sysTimeMgrPwrStopThread; + public: IarmSubscriber(string sub); bool subscribe(string eventname,funcPtr fptr); static IarmSubscriber* getInstance() { return pInstance;} void invokepowerhandler(void* args){ if (m_powerHandler) (*m_powerHandler)(args);} - static void powereventHandler(const char *owner, int eventId, void *data, size_t len); + static void sysTimeMgrPwrEventHandler(const PowerController_PowerState_t currentState, + const PowerController_PowerState_t newState, + void* userdata); + static void sysTimeMgrHandlePwrEventData(const PowerController_PowerState_t currentState, + const PowerController_PowerState_t newState); + static void sysTimeMgrPwrEventHandlingThreadFunc(void *arg); + static void sysTimeMgrPwrConnectHandlingThreadFunc(void *arg); + static void sysTimeMgrInitPwrEvt(void); + static void sysTimeMgrDeinitPwrEvt(void); }; - #endif// _IARMSUBSCRIBER_H_ From f0594133b8ad7932b28e8dc3682c7fbbad862ffa Mon Sep 17 00:00:00 2001 From: Ramesh Babu H Date: Thu, 13 Mar 2025 17:03:33 +0530 Subject: [PATCH 02/11] systimermgr temp build fix --- systimemgr.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/systimemgr.cpp b/systimemgr.cpp index ff29eac0..723fe465 100644 --- a/systimemgr.cpp +++ b/systimemgr.cpp @@ -173,7 +173,8 @@ void SysTimeMgr::run(bool forever) pathMonitorThrd.join(); /* This is for the systemtime manager event handler thread and mutex variable Deinitalization */ - m_subscriber->SysTimeMgrDeinitPwrEvt(); + //Temp ?: To fix + //m_subscriber->SysTimeMgrDeinitPwrEvt(); /* This is for the Termination of systemtime manager's power controller client handler */ PowerController_Term(); From f902beb5289268fcc40e375e02de3b0dee30b998 Mon Sep 17 00:00:00 2001 From: Ramesh Babu H Date: Fri, 14 Mar 2025 00:12:47 +0530 Subject: [PATCH 03/11] systimermgr done some fix and logs added --- systimemgr.cpp | 3 +-- systimerfactory/iarmsubscribe.cpp | 16 +++++++++++----- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/systimemgr.cpp b/systimemgr.cpp index 723fe465..5fe063de 100644 --- a/systimemgr.cpp +++ b/systimemgr.cpp @@ -173,8 +173,7 @@ void SysTimeMgr::run(bool forever) pathMonitorThrd.join(); /* This is for the systemtime manager event handler thread and mutex variable Deinitalization */ - //Temp ?: To fix - //m_subscriber->SysTimeMgrDeinitPwrEvt(); + m_subscriber->sysTimeMgrDeinitPwrEvt(); /* This is for the Termination of systemtime manager's power controller client handler */ PowerController_Term(); diff --git a/systimerfactory/iarmsubscribe.cpp b/systimerfactory/iarmsubscribe.cpp index 4e4554f6..15a4920d 100644 --- a/systimerfactory/iarmsubscribe.cpp +++ b/systimerfactory/iarmsubscribe.cpp @@ -48,12 +48,16 @@ bool IarmSubscriber::subscribe(string eventname,funcPtr fptr) uint32_t retValPwrCtrl=0; if (eventname == POWER_CHANGE_MSG) { + RDK_LOG(RDK_LOG_INFO,LOG_SYSTIME,"[%s:%d]:Registering function for Event = %s \n",__FUNCTION__,__LINE__,eventname.c_str()); + /* This is for the initalization of refactored power controller client for IARM communication used in systemtime manager All the Power Controller functions are handled here */ PowerController_Init(); + RDK_LOG(RDK_LOG_INFO,LOG_SYSTIME,"[%s:%d]:PowerController_Init Completed \n",__FUNCTION__,__LINE__); /* This is for the systemtime manager event handler thread and mutex variable initalization */ IarmSubscriber::sysTimeMgrInitPwrEvt(); + RDK_LOG(RDK_LOG_INFO,LOG_SYSTIME,"[%s:%d]:Initializing sysTimeMgrInitPwrEvt Completed \n",__FUNCTION__,__LINE__); m_powerHandler = fptr; /* Check for Power Controller Connection and if failure, start a new thread and wait until connection established */ @@ -91,6 +95,7 @@ bool IarmSubscriber::subscribe(string eventname,funcPtr fptr) } else { + RDK_LOG(RDK_LOG_INFO,LOG_SYSTIME,"[%s:%d]:IARMBUS Registering function for Event = %s \n",__FUNCTION__,__LINE__,eventname.c_str()); retCode = IARM_Bus_RegisterCall(eventname.c_str(),(IARM_BusCall_t)fptr); } return retCode; @@ -217,9 +222,6 @@ void IarmSubscriber::sysTimeMgrInitPwrEvt(void) { RDK_LOG(RDK_LOG_INFO,LOG_SYSTIME,"[%s:%d]:Entering \n",__FUNCTION__,__LINE__); - /* Initialize the Mutex and waitsignal variable, Create the thread used to separate the context of power event Callback function */ - std::lock_guard lock(m_pwrEvtMutexLock); - m_sysTimeMgrPwrStopThread = false; m_sysTimeMgrPwrEvtHandlerThread = std::thread(&IarmSubscriber::sysTimeMgrPwrEventHandlingThreadFunc, nullptr); @@ -258,7 +260,11 @@ void IarmSubscriber::sysTimeMgrDeinitPwrEvt(void) m_sysTimeMgrPwrEvtHandlerThread.join(); RDK_LOG(RDK_LOG_INFO, LOG_SYSTIME, "[%s:%d]:Completed Deinit and Joined thread\n", __FUNCTION__, __LINE__); } - - /* The clean up of mutex automatically happen after it is out of scope */ + + if(POWER_CONTROLLER_ERROR_NONE != + PowerController_UnRegisterPowerModeChangedCallback(IarmSubscriber::sysTimeMgrPwrEventHandler)) + { + RDK_LOG(RDK_LOG_ERROR, LOG_SYSTIME, "[%s:%d]:UnRegisterPowerModeChangedCallback Failed \n", __FUNCTION__, __LINE__); + } } From a52fe090aa7f7cfd8ffb90929260f3de1d6dca9e Mon Sep 17 00:00:00 2001 From: Ramesh Babu H Date: Fri, 14 Mar 2025 01:27:51 +0530 Subject: [PATCH 04/11] systimemgr build errors fix and changes --- interface/isubscribe.h | 1 + systimemgr.cpp | 2 +- systimerfactory/iarmsubscribe.cpp | 16 ++++++++++++++++ systimerfactory/iarmsubscribe.h | 1 + 4 files changed, 19 insertions(+), 1 deletion(-) diff --git a/interface/isubscribe.h b/interface/isubscribe.h index f66886dd..4afced31 100644 --- a/interface/isubscribe.h +++ b/interface/isubscribe.h @@ -39,6 +39,7 @@ class ISubscribe public: ISubscribe(string sub):m_subscriber(sub){} virtual bool subscribe(string eventname,funcPtr fptr) = 0; + virtual bool deInit(string eventname) = 0; }; diff --git a/systimemgr.cpp b/systimemgr.cpp index 5fe063de..286b7de1 100644 --- a/systimemgr.cpp +++ b/systimemgr.cpp @@ -173,7 +173,7 @@ void SysTimeMgr::run(bool forever) pathMonitorThrd.join(); /* This is for the systemtime manager event handler thread and mutex variable Deinitalization */ - m_subscriber->sysTimeMgrDeinitPwrEvt(); + m_subscriber->deInit(); /* This is for the Termination of systemtime manager's power controller client handler */ PowerController_Term(); diff --git a/systimerfactory/iarmsubscribe.cpp b/systimerfactory/iarmsubscribe.cpp index 15a4920d..cb8f872b 100644 --- a/systimerfactory/iarmsubscribe.cpp +++ b/systimerfactory/iarmsubscribe.cpp @@ -101,6 +101,22 @@ bool IarmSubscriber::subscribe(string eventname,funcPtr fptr) return retCode; } +bool IarmSubscriber::deInit(string eventname) +{ + RDK_LOG(RDK_LOG_INFO,LOG_SYSTIME,"[%s:%d]:deInit function for Event = %s \n",__FUNCTION__,__LINE__,eventname.c_str()); + + if (eventname == POWER_CHANGE_MSG) + { + /* This is for the systemtime manager deInit */ + IarmSubscriber::sysTimeMgrDeinitPwrEvt(); + RDK_LOG(RDK_LOG_INFO,LOG_SYSTIME,"[%s:%d]:DeInit Success \n",__FUNCTION__,__LINE__); + } + else + { + RDK_LOG(RDK_LOG_ERROR, LOG_SYSTIME, "[%s:%d]:Deinit not present for Event =[%s]\n", __FUNCTION__, __LINE__,eventname.c_str()); + } +} + void IarmSubscriber::sysTimeMgrPwrEventHandler(const PowerController_PowerState_t currentState, const PowerController_PowerState_t newState, void *userdata) diff --git a/systimerfactory/iarmsubscribe.h b/systimerfactory/iarmsubscribe.h index 84e111b5..86750f78 100644 --- a/systimerfactory/iarmsubscribe.h +++ b/systimerfactory/iarmsubscribe.h @@ -61,6 +61,7 @@ class IarmSubscriber:public ISubscribe public: IarmSubscriber(string sub); bool subscribe(string eventname,funcPtr fptr); + bool deInit(string eventname); static IarmSubscriber* getInstance() { return pInstance;} void invokepowerhandler(void* args){ if (m_powerHandler) (*m_powerHandler)(args);} static void sysTimeMgrPwrEventHandler(const PowerController_PowerState_t currentState, From f37983c8ec67440d1fe1ad7ce6b19b749cc6a65b Mon Sep 17 00:00:00 2001 From: Ramesh Babu H Date: Fri, 14 Mar 2025 07:04:45 +0530 Subject: [PATCH 05/11] systimemgr build errors fix --- systimemgr.cpp | 2 +- systimerfactory/iarmsubscribe.cpp | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/systimemgr.cpp b/systimemgr.cpp index 286b7de1..c1c57834 100644 --- a/systimemgr.cpp +++ b/systimemgr.cpp @@ -173,7 +173,7 @@ void SysTimeMgr::run(bool forever) pathMonitorThrd.join(); /* This is for the systemtime manager event handler thread and mutex variable Deinitalization */ - m_subscriber->deInit(); + m_subscriber->deInit(POWER_CHANGE_MSG); /* This is for the Termination of systemtime manager's power controller client handler */ PowerController_Term(); diff --git a/systimerfactory/iarmsubscribe.cpp b/systimerfactory/iarmsubscribe.cpp index cb8f872b..fd1764ef 100644 --- a/systimerfactory/iarmsubscribe.cpp +++ b/systimerfactory/iarmsubscribe.cpp @@ -115,6 +115,7 @@ bool IarmSubscriber::deInit(string eventname) { RDK_LOG(RDK_LOG_ERROR, LOG_SYSTIME, "[%s:%d]:Deinit not present for Event =[%s]\n", __FUNCTION__, __LINE__,eventname.c_str()); } + return true; } void IarmSubscriber::sysTimeMgrPwrEventHandler(const PowerController_PowerState_t currentState, From 31f8b4ab0d8de37235a59733f4ccc21d8d6ce5bc Mon Sep 17 00:00:00 2001 From: Ramesh Babu H Date: Fri, 14 Mar 2025 08:08:51 +0530 Subject: [PATCH 06/11] systimemgr fix and changes --- systimemgr.cpp | 3 ++- systimerfactory/iarmsubscribe.cpp | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/systimemgr.cpp b/systimemgr.cpp index c1c57834..77111a15 100644 --- a/systimemgr.cpp +++ b/systimemgr.cpp @@ -173,7 +173,8 @@ void SysTimeMgr::run(bool forever) pathMonitorThrd.join(); /* This is for the systemtime manager event handler thread and mutex variable Deinitalization */ - m_subscriber->deInit(POWER_CHANGE_MSG); + // Temp ?: To Fix + //m_subscriber->deInit(POWER_CHANGE_MSG); /* This is for the Termination of systemtime manager's power controller client handler */ PowerController_Term(); diff --git a/systimerfactory/iarmsubscribe.cpp b/systimerfactory/iarmsubscribe.cpp index fd1764ef..d256e37d 100644 --- a/systimerfactory/iarmsubscribe.cpp +++ b/systimerfactory/iarmsubscribe.cpp @@ -42,7 +42,7 @@ IarmSubscriber::IarmSubscriber(string sub):ISubscribe(sub),m_powerHandler(NULL) bool IarmSubscriber::subscribe(string eventname,funcPtr fptr) { - RDK_LOG(RDK_LOG_INFO,LOG_SYSTIME,"[%s:%d]:IARMBUS Registering function for Event = %s \n",__FUNCTION__,__LINE__,eventname.c_str()); + RDK_LOG(RDK_LOG_INFO,LOG_SYSTIME,"[%s:%d]:Entering Registering function for Event = %s \n",__FUNCTION__,__LINE__,eventname.c_str()); bool retCode = false; uint32_t retValPwrCtrl=0; From 76f9801b466667b9b87434500315a41783b9792f Mon Sep 17 00:00:00 2001 From: Ramesh Babu H Date: Fri, 14 Mar 2025 15:37:45 +0530 Subject: [PATCH 07/11] systimermgr deInit updated --- systimemgr.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/systimemgr.cpp b/systimemgr.cpp index 77111a15..c1c57834 100644 --- a/systimemgr.cpp +++ b/systimemgr.cpp @@ -173,8 +173,7 @@ void SysTimeMgr::run(bool forever) pathMonitorThrd.join(); /* This is for the systemtime manager event handler thread and mutex variable Deinitalization */ - // Temp ?: To Fix - //m_subscriber->deInit(POWER_CHANGE_MSG); + m_subscriber->deInit(POWER_CHANGE_MSG); /* This is for the Termination of systemtime manager's power controller client handler */ PowerController_Term(); From bcf1ea7e3474222afc479c912dd6fbb222f5484d Mon Sep 17 00:00:00 2001 From: Ramesh Babu H Date: Fri, 14 Mar 2025 16:46:38 +0530 Subject: [PATCH 08/11] systimermgr error power_state value --- systimerfactory/iarmsubscribe.cpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/systimerfactory/iarmsubscribe.cpp b/systimerfactory/iarmsubscribe.cpp index d256e37d..dc07e067 100644 --- a/systimerfactory/iarmsubscribe.cpp +++ b/systimerfactory/iarmsubscribe.cpp @@ -200,6 +200,7 @@ void IarmSubscriber::sysTimeMgrHandlePwrEventData(const PowerController_PowerSta const PowerController_PowerState_t newState) { RDK_LOG(RDK_LOG_INFO,LOG_SYSTIME,"[%s:%d]:SysTimeMgrHandlePwrEventData currentState[%d] newState[%d]\n",__FUNCTION__,__LINE__,currentState,newState); + string powerstatus("UNKNOWN"); if(IarmSubscriber::getInstance()) { @@ -208,20 +209,20 @@ void IarmSubscriber::sysTimeMgrHandlePwrEventData(const PowerController_PowerSta case POWER_STATE_OFF: case POWER_STATE_STANDBY_DEEP_SLEEP: RDK_LOG(RDK_LOG_INFO,LOG_SYSTIME,"[%s:%d]:Deep Sleep ON Invoked\n",__FUNCTION__,__LINE__); - string powerstatus("DEEP_SLEEP_ON"); + powerstatus("DEEP_SLEEP_ON"); IarmSubscriber::getInstance()->invokepowerhandler((void*)&powerstatus); break; case POWER_STATE_ON: case POWER_STATE_STANDBY_LIGHT_SLEEP: case POWER_STATE_STANDBY: - if(POWER_STATE_STANDBY_DEEP_SLEEP == currentState) - { - RDK_LOG(RDK_LOG_INFO,LOG_SYSTIME,"[%s:%d]:Deep Sleep OFF Invoked\n",__FUNCTION__,__LINE__); - string powerstatus("DEEP_SLEEP_OFF"); - IarmSubscriber::getInstance()->invokepowerhandler((void*)&powerstatus); - } - break; + if(POWER_STATE_STANDBY_DEEP_SLEEP == currentState) + { + RDK_LOG(RDK_LOG_INFO,LOG_SYSTIME,"[%s:%d]:Deep Sleep OFF Invoked\n",__FUNCTION__,__LINE__); + powerstatus("DEEP_SLEEP_OFF"); + IarmSubscriber::getInstance()->invokepowerhandler((void*)&powerstatus); + } + break; default: RDK_LOG(RDK_LOG_INFO,LOG_SYSTIME,"[%s:%d]:Err: default case Unable to getInstance\n",__FUNCTION__,__LINE__); From a68ca6897e6eb6533aef21c80c312fd3150e4431 Mon Sep 17 00:00:00 2001 From: Ramesh Babu H Date: Fri, 14 Mar 2025 17:47:40 +0530 Subject: [PATCH 09/11] systimemgr fix compiler changes --- systimerfactory/iarmsubscribe.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/systimerfactory/iarmsubscribe.cpp b/systimerfactory/iarmsubscribe.cpp index dc07e067..e700589f 100644 --- a/systimerfactory/iarmsubscribe.cpp +++ b/systimerfactory/iarmsubscribe.cpp @@ -200,7 +200,7 @@ void IarmSubscriber::sysTimeMgrHandlePwrEventData(const PowerController_PowerSta const PowerController_PowerState_t newState) { RDK_LOG(RDK_LOG_INFO,LOG_SYSTIME,"[%s:%d]:SysTimeMgrHandlePwrEventData currentState[%d] newState[%d]\n",__FUNCTION__,__LINE__,currentState,newState); - string powerstatus("UNKNOWN"); + string powerstatus = "UNKNOWN"; if(IarmSubscriber::getInstance()) { @@ -209,7 +209,7 @@ void IarmSubscriber::sysTimeMgrHandlePwrEventData(const PowerController_PowerSta case POWER_STATE_OFF: case POWER_STATE_STANDBY_DEEP_SLEEP: RDK_LOG(RDK_LOG_INFO,LOG_SYSTIME,"[%s:%d]:Deep Sleep ON Invoked\n",__FUNCTION__,__LINE__); - powerstatus("DEEP_SLEEP_ON"); + powerstatus = "DEEP_SLEEP_ON"; IarmSubscriber::getInstance()->invokepowerhandler((void*)&powerstatus); break; @@ -219,7 +219,7 @@ void IarmSubscriber::sysTimeMgrHandlePwrEventData(const PowerController_PowerSta if(POWER_STATE_STANDBY_DEEP_SLEEP == currentState) { RDK_LOG(RDK_LOG_INFO,LOG_SYSTIME,"[%s:%d]:Deep Sleep OFF Invoked\n",__FUNCTION__,__LINE__); - powerstatus("DEEP_SLEEP_OFF"); + powerstatus = "DEEP_SLEEP_OFF"; IarmSubscriber::getInstance()->invokepowerhandler((void*)&powerstatus); } break; From 4d710cc1015dcfcf31846d7aafc5fc27ce6cbaa5 Mon Sep 17 00:00:00 2001 From: Ramesh Babu H Date: Fri, 14 Mar 2025 18:57:38 +0530 Subject: [PATCH 10/11] systimermgr testsubsriber change --- systimerfactory/testsubscribe.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/systimerfactory/testsubscribe.h b/systimerfactory/testsubscribe.h index ef53ef43..d7f02557 100644 --- a/systimerfactory/testsubscribe.h +++ b/systimerfactory/testsubscribe.h @@ -36,6 +36,12 @@ class TestSubscriber:public ISubscribe RDK_LOG(RDK_LOG_INFO,LOG_SYSTIME,"[%s:%d]:Subscribed for Event = %s \n",__FUNCTION__,__LINE__,eventname.c_str()); return true; } + + bool deInit(string eventname) + { + RDK_LOG(RDK_LOG_INFO,LOG_SYSTIME,"[%s:%d]:deInit for Event = %s \n",__FUNCTION__,__LINE__,eventname.c_str()); + return true; + } }; From 96e2a1d4021d7a4df30108a12f3b97d9cb53a2d4 Mon Sep 17 00:00:00 2001 From: Ramesh Babu H Date: Mon, 17 Mar 2025 19:45:41 +0530 Subject: [PATCH 11/11] Systimemgr service file changes by adding wpeframework-powermanager.service --- systemd_units/systimemgr.service | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/systemd_units/systimemgr.service b/systemd_units/systimemgr.service index 4a7d875b..f2aa43c7 100644 --- a/systemd_units/systimemgr.service +++ b/systemd_units/systimemgr.service @@ -19,7 +19,7 @@ Description= System Time Mgr dameon provides quality of time. #DefaultDependencies=no #Before = systemd-timesyncd.service -After = mfrmgr.service +After = mfrmgr.service wpeframework-powermanager.service [Service] EnvironmentFile=/etc/device.properties