瀏覽代碼

Z991239-6089 #comment 把FrameworkState改成AppBootState,用于标识终端应用启动过程状态;调整健康相关逻辑

oilyang 9 月之前
父節點
當前提交
eae3a51cf6

+ 9 - 16
Framework/Common/SpBase.h

@@ -114,20 +114,13 @@ enum InstallStateEnum
 	Install_Installed,			// D, only used to LightPack
 };
 
-/** framework state*/
-enum FrameworkStateEnum
+/** terminal application boot state*/
+enum AppBootStateEnum
 {
-	FrameworkState_NotInit = 0,   /** the begin state*/
-    FrameworkState_NotConfig,   /** the factory mode, not config*/
-	FrameworkState_Booting,        /** the entity is starting*/
-	FrameworkState_Running,       /** the machine has enter business page*/
-	FrameworkState_Serving,        /** the machine is providing business service*/
-	FrameworkState_Breakdown,   /** the machine is sick*/
-	FrameworkState_Repairing,     /** the machine is being maintained*/
-	FrameworkState_Upgrading,   /** the software is upgrading*/
-	FrameworkState_Rollbacking, /** the software is rollback for some reason*/
-	FrameworkState_Recoving,     /** the machine is reaching running state from other state*/
-	FrameworkState_NotDisturb  /**/
+	AppBootState_Init = 0,   /** the begin(init) state*/
+	AppBootState_StartEntity,   /** begin to start entity*/
+	AppBootState_CallAccessAuth,        /** begin to call Regist*/
+	AppBootState_FirstEnterMainPage,       /** the first time received enter main page message*/
 };
 
 /** entity state */
@@ -532,7 +525,7 @@ struct CSystemRunInfo
 {
 	CSmallDateTime tmStart;
 	DebugLevelEnum eDebugLevel;
-	FrameworkStateEnum eState;
+	AppBootStateEnum eAppBootState;
 	DWORD dwBootOption;
 	BOOL autoTest;
 	CAutoArray<CSimpleStringA> strRunningEntityNames;
@@ -651,7 +644,7 @@ struct ISysVarListener
 };
 struct ITerminalStateChangedListener
 {
-	virtual void OnStateChanged(FrameworkStateEnum oldState, FrameworkStateEnum curState, const char* triggerEntity) = 0;
+	virtual void OnStateChanged(AppBootStateEnum oldState, AppBootStateEnum curState, const char* triggerEntity) = 0;
 };
 
 struct IBroadcastListener
@@ -1073,7 +1066,7 @@ struct IEntityFunctionPrivilege
 	virtual ~IEntityFunctionPrivilege() {}
 
 	/*upate terminal current state*/
-	virtual ErrorCodeEnum RefreshFrameworkState(FrameworkStateEnum eState) = 0;
+	virtual ErrorCodeEnum RefreshAppBootState(AppBootStateEnum eState) = 0;
 
 	/** start a remote entity,if restart itself only been call in OnClose event,will ignore pAsynWaitSp,and will not wait*/
 	virtual ErrorCodeEnum StartEntity(const char* pszEntityName, const char* pszCmdLine, CSmartPointer<IAsynWaitSp>& pAsynWaitSp) = 0;

+ 1 - 1
Framework/Common/SpHelper.h

@@ -375,7 +375,7 @@ SPBASE_API LPCTSTR SpStrRebootTrigger(const RebootTriggerEnum trigger);
 
 SPBASE_API LPCTSTR SpStrRebootWay(const RebootWayEnum way);
 
-SPBASE_API LPCTSTR SpStrFrameworkState(const FrameworkStateEnum state);
+SPBASE_API LPCTSTR SpStrAppBootState(const AppBootStateEnum state);
 
 #define IS_SUCCEED(hr)	((hr) == Error_Succeed)
 

+ 3 - 3
Framework/spbase/SpEntity.cpp

@@ -61,8 +61,8 @@ static void var_callback(sp_var_listener_t *listener,
 		if(strcmp(VAR_RSERVERD_KEY_TERM_STATE, key) != 0)
 			pListener->OnSysVarEvent(key, newstr, oldstr, ent->cfg->name);
 		else {
-			FrameworkStateEnum oldState = static_cast<FrameworkStateEnum>(atoi(oldstr));
-			FrameworkStateEnum newState = static_cast<FrameworkStateEnum>(atoi(newstr));
+			AppBootStateEnum oldState = static_cast<AppBootStateEnum>(atoi(oldstr));
+			AppBootStateEnum newState = static_cast<AppBootStateEnum>(atoi(newstr));
 			(static_cast<ITerminalStateChangedListener*>(user_data))->OnStateChanged(oldState, newState, ent->cfg->name);
 		}
 	}
@@ -1490,7 +1490,7 @@ ErrorCodeEnum SpEntity::GetSystemRunInfo(CSystemRunInfo &Info)
 	}
 	array_free(arr);
 
-	Info.eState = (FrameworkStateEnum)env->cfg->shell_ini->shell_state;
+	Info.eAppBootState = (AppBootStateEnum)env->cfg->shell_ini->shell_state;
 
 	if (env == NULL || env->cfg == NULL || env->cfg->root_ini == NULL)
 	{

+ 1 - 1
Framework/spbase/SpEntityNoPrivilege.h

@@ -105,7 +105,7 @@ public:
         return Error_NoPrivilege;
     }
 
-    virtual ErrorCodeEnum RefreshFrameworkState(FrameworkStateEnum eState)
+    virtual ErrorCodeEnum RefreshAppBootState(AppBootStateEnum eState)
     {
         return Error_NoPrivilege;
     }

+ 1 - 1
Framework/spbase/SpEntityPrivilege.cpp

@@ -424,7 +424,7 @@ ErrorCodeEnum SpEntityPrivilege::SetSysDebugLevel(const char *pszEntityName,Debu
 	return Error_Succeed;
 }
 
-ErrorCodeEnum SpEntityPrivilege::RefreshFrameworkState(FrameworkStateEnum eState)
+ErrorCodeEnum SpEntityPrivilege::RefreshAppBootState(AppBootStateEnum eState)
 {
 	int rc = Error_Succeed;
 	char n[12] = { '\0' };

+ 1 - 1
Framework/spbase/SpEntityPrivilege.h

@@ -76,7 +76,7 @@ public:
 	// debug
 	virtual ErrorCodeEnum SetSysDebugLevel(const char *pszEntityName,DebugLevelEnum eDebugLevel,bool bPersist=false);
 
-	virtual ErrorCodeEnum RefreshFrameworkState(FrameworkStateEnum eState);
+	virtual ErrorCodeEnum RefreshAppBootState(AppBootStateEnum eState);
 
 private:
 

+ 6 - 13
Framework/spbase/SpHelper.cpp

@@ -864,25 +864,18 @@ SPBASE_API LPCTSTR SpStrRebootWay(const RebootWayEnum way)
 }
 
 #undef ENT_ENUM_MAP
-#define ENT_ENUM_MAP(name) case FrameworkState_##name: return #name; break;
+#define ENT_ENUM_MAP(name) case AppBootState_##name: return #name; break;
 
-SPBASE_API LPCTSTR SpStrFrameworkState(const FrameworkStateEnum state)
+SPBASE_API LPCTSTR SpStrAppBootState(const AppBootStateEnum state)
 {
 
 	static char content[128];
 
 	switch (state) {
-		ENT_ENUM_MAP(NotInit)
-		ENT_ENUM_MAP(NotConfig)
-		ENT_ENUM_MAP(Booting)
-		ENT_ENUM_MAP(Running)
-		ENT_ENUM_MAP(Serving)
-		ENT_ENUM_MAP(Breakdown)
-		ENT_ENUM_MAP(Repairing)
-		ENT_ENUM_MAP(Upgrading)
-		ENT_ENUM_MAP(Rollbacking)
-		ENT_ENUM_MAP(Recoving)
-		ENT_ENUM_MAP(NotDisturb)
+		ENT_ENUM_MAP(Init)
+		ENT_ENUM_MAP(StartEntity)
+		ENT_ENUM_MAP(CallAccessAuth)
+		ENT_ENUM_MAP(FirstEnterMainPage)
 	default:
 		sprintf(content, "UnRecorded(%d)", (int)state);
 		break;

+ 3 - 3
Framework/spshell/svc.cpp

@@ -561,9 +561,9 @@ void on_terminal_stage_change(sp_rpc_server_t* server, int epid, int svc_id, int
     sp_cfg_t* cfg = env->cfg;
     iobuffer_read(*info_pkt, IOBUF_T_I4, &newStage, 0);
     iobuffer_read(*info_pkt, IOBUF_T_I4, &oldStage, 0);
-    const FrameworkStateEnum eNewStage = (FrameworkStateEnum)newStage;
-    const FrameworkStateEnum eOldStage = (FrameworkStateEnum)oldStage;
-	DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("change teriminal state from %s to %s", SpStrFrameworkState(eOldStage), SpStrFrameworkState(eNewStage));
+    const AppBootStateEnum eNewStage = (AppBootStateEnum)newStage;
+    const AppBootStateEnum eOldStage = (AppBootStateEnum)oldStage;
+	DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("change teriminal state from %s to %s", SpStrAppBootState(eOldStage), SpStrAppBootState(eNewStage));
     auto app = get_app_instance();
 #if defined(RVC_OS_LINUX)
 	if (app->bsc_gui != NULL) {

+ 3 - 21
Module/mod_healthmanager/HealthManagerFSM.cpp

@@ -85,27 +85,6 @@ ErrorCodeEnum CHealthManagerFSM::Initial()
 ErrorCodeEnum CHealthManagerFSM::OnInit(void)
 {
 	DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Complied at: %s %s", __DATE__, __TIME__);
-
-	/*GifutTest20250314 begin*/
-	do 
-	{
-		CSystemRunInfo sysRunInfo;
-		GetEntityBase()->GetFunction()->GetSystemRunInfo(sysRunInfo);
-		DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("gifur test: FrameworkState: %s", SpStrFrameworkState(sysRunInfo.eState));
-	} while (false);
-
-	Sleep(200);
-	/** 更新框架变量  [Gifur@2025314]*/
-	GetEntityBase()->GetFunction()->GetPrivilegeFunction()->RefreshFrameworkState(FrameworkState_Upgrading);
-
-	do
-	{
-		CSystemRunInfo sysRunInfo;
-		GetEntityBase()->GetFunction()->GetSystemRunInfo(sysRunInfo);
-		DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("gifur test2: FrameworkState: %s", SpStrFrameworkState(sysRunInfo.eState));
-	} while (false);
-	/*GifutTest20250314 end*/
-
 	return Initial();
 }
 ErrorCodeEnum CHealthManagerFSM::OnExit(void)
@@ -400,6 +379,9 @@ int CHealthManagerFSM::AccessAuthDoWork()
 		if (m_pACClient != NULL)
 		{
 			DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("to call accessauth regist");
+			CSystemRunInfo sysRunInfo;
+			if (GetEntityBase()->GetFunction()->GetSystemRunInfo(sysRunInfo) != Error_Succeed || sysRunInfo.eAppBootState == AppBootState_StartEntity)
+				GetEntityBase()->GetFunction()->GetPrivilegeFunction()->RefreshAppBootState(AppBootState_CallAccessAuth);
 			m_ullAuthStart = SP::Module::Comm::RVCGetTickCount();
 			eErrCode = (*m_pACClient)(EntityResource::getLink().upgradeLink())->Regist();
 			m_bHasAuthEver = true;

+ 20 - 23
Module/mod_healthmanager/mod_healthmanager.cpp

@@ -257,7 +257,7 @@ void CHealthManagerEntity::OnCheckTimeTimeout()
 		eErrCode = GetFunction()->GetSysVar("TerminalStage", csTermStage);
 		Dbg("OnCheckTimeTimeout::ToRestartByCenterSetting to get termstage %s", csTermStage.GetData());
 		//oilyang@20250313 in Main page('UIState' is 'M') or TerminalStage is (NOT 'S') AND (NOT 'A'),that is in close page which caused by terminal app
-		if (CheckUIStateIsM() || (!CheckUIStateIsM() && csTermStage.Compare("S") != 0 && csTermStage.Compare("A") != 0) )
+		if (m_bInMainPage || (!m_bInMainPage && csTermStage.Compare("S") != 0 && csTermStage.Compare("A") != 0) )
 		{
 			DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("THE key CenterSetting updated,we must restart framework right now.");
 			m_fsm.QuitFrameworkAndSaveInfo(RebootTrigger_Resource, RebootWay_Framework);
@@ -299,13 +299,9 @@ void CHealthManagerEntity::OnCheckTimeTimeout()
 		//1、AccessAuth ok
 		//2、have ever enter main page OR 
 		if (!m_bSayIdle)
-			DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("m_fsm.GetAccessAuthFlag():%d, m_bEnterMainPageEver:%d, m_bInMainPage:%d", m_fsm.CheckIfAccessAuthSuc()
-				, m_bEnterMainPageEver, CheckUIStateIsM());
-		//oilyang@20241230 check accessauth flag AND if in Main page ever
-		//oilyang@20250313 "Main page ever" has two scenes
-		//1. have enter main page ever,that is "m_bEnterMainPageEver is true"
-		//2. healthmanager have been lost at some point in the past,we check the "UIState" value if 'M'
-		if (m_fsm.CheckIfAccessAuthSuc() && (m_bEnterMainPageEver || (!m_bEnterMainPageEver && CheckUIStateIsM())))
+			DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("m_fsm.GetAccessAuthFlag():%d, CheckIfHaveEnterMainPageEver:%d", m_fsm.CheckIfAccessAuthSuc(), CheckIfHaveEnterMainPageEver());
+		//oilyang@20241230 check if have enter Main page ever
+		if (CheckIfHaveEnterMainPageEver())
 		{
 			iCheckGuardian = CheckGuardianIsRun(true);
 			if (!m_bSayIdle)
@@ -1272,11 +1268,11 @@ void CHealthManagerEntity::OnSysVarEvent(const char *pszKey, const char *pszValu
 		if (_strnicmp(pszValue, "M", strlen("M")) == 0)
 		{
 			m_bInMainPage = true;
-			m_bEnterMainPageEver = true;
-
-			if (!m_bHaveThrowMainPage)
+			if (!CheckIfHaveEnterMainPageEver())
 			{
-				m_bHaveThrowMainPage = true;
+				CSystemRunInfo sysRunInfo;
+				if (GetFunction()->GetSystemRunInfo(sysRunInfo) != Error_Succeed || sysRunInfo.eAppBootState == AppBootState_CallAccessAuth)
+					GetFunction()->GetPrivilegeFunction()->RefreshAppBootState(AppBootState_FirstEnterMainPage);
 				
 				CSmartPointer<IConfigInfo> spConfigRun;
 				ErrorCodeEnum eErr = GetFunction()->OpenConfig(Config_Run, spConfigRun);
@@ -1302,8 +1298,6 @@ void CHealthManagerEntity::OnSysVarEvent(const char *pszKey, const char *pszValu
 		}
 		else
 			m_bInMainPage = false;
-
-
 	}
 }
 void CHealthManagerEntity::OnBroadcastEvent(CUUID SubID, const char *pszEntityName, DWORD dwMessageId, DWORD dwMessageSignature, CAutoBuffer Buffer)
@@ -1315,7 +1309,7 @@ void CHealthManagerEntity::OnTimeout(DWORD dwTimeID)
 	switch (dwTimeID)
 	{
 	case HEALTHMANAGER_WAIT_MAINPAGE_OPEN_TIMER_ID:
-		if (!m_bHaveThrowMainPage)
+		if (!CheckIfHaveEnterMainPageEver())
 			DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER).setResultCode("RTA5101")
 			("After receive accessauth success event, havn't receive enter main page.", m_maxWaitMainpageTime / 1000);
 		break;
@@ -1496,7 +1490,7 @@ void CHealthManagerEntity::OnEntityStateHook(const char* pszEntityName, const ch
 			DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER).setLogCode("QLR0402501S1").setResultCode(csResultCode.GetData())(tmpWarnMsg.GetData());
 			//doing nothing before enter main page. HandShake will take it.
 			//AND if selfcheck is doing, no action at all
-			if (m_bEnterMainPageEver && m_modRunInfo[pszEntityName].abnormalCount < m_maxAbnormalTimes && !m_modRunInfo[pszEntityName].bAbnormalBusy)
+			if (CheckIfHaveEnterMainPageEver() && m_modRunInfo[pszEntityName].abnormalCount < m_maxAbnormalTimes && !m_modRunInfo[pszEntityName].bAbnormalBusy)
 			{
 				m_modRunInfo[pszEntityName].bAbnormalBusy = true;
 				m_modRunInfo[pszEntityName].abnormalCount++;
@@ -1732,20 +1726,23 @@ void CHealthManagerEntity::EntityLostProc(CSimpleStringA entityName)
 	}
 	else
 		DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("on lost start %d", eErrCode);
-	if (m_bEnterMainPageEver && _strnicmp("TokenKeeper", entityName, strlen("TokenKeeper")) == 0)
+	if (CheckIfHaveEnterMainPageEver() && _strnicmp("TokenKeeper", entityName, strlen("TokenKeeper")) == 0)
 	{
 		DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("TokenKeeper lost");
 		m_fsm.ToReAccessAuth();
 	}
 	m_modRunInfo[entityName].bAbnormalBusy = false;
 }
-bool CHealthManagerEntity::CheckUIStateIsM()
+bool CHealthManagerEntity::CheckIfHaveEnterMainPageEver()
 {
-	if (m_bInMainPage)
-		return true;
-	CSimpleStringA uiState(true);
-	if (GetFunction()->GetSysVar("UIState", uiState) != Error_Succeed || uiState.Compare("M") != 0)
-		return false;
+	if (!m_bSayIdle)
+	{
+		CSystemRunInfo sysRunInfo;
+		if (GetFunction()->GetSystemRunInfo(sysRunInfo) == Error_Succeed && sysRunInfo.eAppBootState == AppBootState_FirstEnterMainPage)
+			return true;
+		else
+			return false;
+	}
 	else
 		return true;
 }

+ 2 - 4
Module/mod_healthmanager/mod_healthmanager.h

@@ -88,7 +88,6 @@ public:
 		, m_bSayIdle(false), m_bGuardianRun(false), m_ullGuardShakeCount(0)
 		, m_menuChoice(""), m_menuPre(""), m_netState("N")
 		, m_bInMainPage(false), m_stopSelfCheck(0)
-		, m_bEnterMainPageEver(false),m_bHaveThrowMainPage(false)
 		,m_bNeedAuthRetry(false), m_bNeedGuardianRestart(true), m_bNeedGuardian(true)
 		, m_bToRestartByCenterSetting(false){}
 	virtual ~CHealthManagerEntity() {}
@@ -265,8 +264,7 @@ private:
 	int m_stopSelfCheck;
 	int m_restartHour, m_restartMinute, m_lastHour, m_maxAbnormalTimes, m_rebootHourBegin, m_rebootHourEnd;;
 	bool m_bWaitRestartPC, m_bScreenLock, m_bSayIdle
-		, m_bGuardianRun
-		, m_bInMainPage, m_bEnterMainPageEver, m_bHaveThrowMainPage, m_bToRestartByCenterSetting;
+		, m_bGuardianRun, m_bInMainPage, m_bToRestartByCenterSetting;
 	bool m_bNeedAuthRetry/*需要重试准入*/, m_bNeedGuardianRestart/*需要重启*/, m_bNeedGuardian;
 	DWORD m_dwTimeOfAuthSuc;
 	int m_maxWaitMainpageTime;
@@ -297,7 +295,7 @@ private:
 	CSimpleStringA __ReadCenterConfigStr(CSimpleStringA key, CSimpleStringA entityName);
 
 	void ToCalcRebootHourAndMinute(int restartBegin, int restartEnd);
-	bool CheckUIStateIsM();
+	bool CheckIfHaveEnterMainPageEver();
 };
 #endif // __MOD_HEALTHMANAGER_H
 

+ 5 - 0
Module/mod_vtmloader/VtmLoaderFSM.cpp

@@ -1096,6 +1096,11 @@ int CVtmLoaderFSM::EntityLoad()
 	//oilyang@20240407 add check machine model in ST/UAT test room
 	if (!CheckConfigInfoInTestRoom())
 		return -1;
+	CSystemRunInfo sysRunInfo;
+	if (GetEntityBase()->GetFunction()->GetSystemRunInfo(sysRunInfo) != Error_Succeed || sysRunInfo.eAppBootState == AppBootState_Init)
+		GetEntityBase()->GetFunction()->GetPrivilegeFunction()->RefreshAppBootState(AppBootState_StartEntity);
+	else
+		DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_SYSTEM)("GetSystemRunInfo failed:%d");
 
 	LogWarn(Severity_Low, Error_Succeed, VtmLoader_BootInfoPrint, "开始加载实体");
 	DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("StartLoadEntity")("开始加载实体");

+ 6 - 6
Module/mod_vtmloader/mod_vtmloader.h

@@ -34,7 +34,7 @@ DWORD thread_testEvent(LPVOID param)
 	return 0;
 }
 
-class CVtmLoaderEntity : public CEntityBase, public ILogListener, public IEntityStateListener/*GifutTest20250314 begin*/, public ITerminalStateChangedListener/*GifutTest20250314 end*/
+class CVtmLoaderEntity : public CEntityBase, public ILogListener, public IEntityStateListener
 {
 public:
 	CVtmLoaderEntity() :m_SubLogID1(0), m_SubLogID2(0), m_dwBeginTime(0),
@@ -89,11 +89,11 @@ public:
 	void SetVideoEntityOK() { m_FSM.SetVideoEntityOK(); }
 
 	/*GifutTest20250314 begin*/
-	void OnStateChanged(FrameworkStateEnum oldState, FrameworkStateEnum curState, const char* triggerEntity)
-	{
-		LOG_FUNCTION();
-		DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("state changed from %s to %s by %s", SpStrFrameworkState(oldState), SpStrFrameworkState(curState), triggerEntity);
-	}
+	//void OnStateChanged(AppBootStateEnum oldState, AppBootStateEnum curState, const char* triggerEntity)
+	//{
+	//	LOG_FUNCTION();
+	//	DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("state changed from %s to %s by %s", SpStrAppBootState(oldState), SpStrAppBootState(curState), triggerEntity);
+	//}
 	/*GifutTest20250314 end*/
 
 protected: