Browse Source

Z991239-4735 #comment 归并自检实体功能同步代码

Signed-Off-By: commit-hook
刘文涛80174520 2 years ago
parent
commit
6ec3b3c171

File diff suppressed because it is too large
+ 277 - 499
Module/mod_selfchecker/SelfCheckerFSM.cpp


+ 8 - 21
Module/mod_selfchecker/SelfCheckerFSM.h

@@ -10,14 +10,12 @@
 #include <cstring>
 #include <ctime>
 
-//#include <crtdbg.h>
+
 #ifdef RVC_OS_WIN
 #include <windows.h>
 #include <Psapi.h>
 #else
 #endif //RVC_OS_WIN
-//_CrtMemState startMemState;
-//_CrtMemState endMemState;
 
 #include <fstream>
 #include <string>
@@ -35,10 +33,7 @@ const int MAX_KEY_VALUE_SIZE = 1024;
 class	CSelfCheckerEntity;
 class CSelfCheckerFSM;
 #define SelfChecker_UserErrorCode_Start		0x50500200
-//reserve for other
 #define SelfChecker_UserErrorCode_EntityLost_Start		0x50500300
-//SelfChecker_UserErrorCode_EntityLost = SelfChecker_UserErrorCode_EntityLost_Start + entityDevelopID
-//#define SelfChecker_UserErrorCode_EntityLost	(SelfChecker_UserErrorCode_EntityLost_Start + 1)	//实体lost告警信息
 enum EvtType
 {
 	USER_EVT_TEST = EVT_USER+1,
@@ -100,7 +95,7 @@ struct EntityRunInfo
 	int eState;
 	int eTest;
 	int loadOpt;
-	int memoryHighCount;
+	int memoryHighCount;//此变量废弃使用
 	int cpuRatio;
 	FILETIME prevSysKernel, prevSysUser;
 	FILETIME prevProcKernel, prevProcUser;
@@ -122,7 +117,7 @@ struct EntityCfg
 struct EntityNameCompare
 {
 public:
-	bool operator()(const std::string x, const std::string y)const
+	bool operator()(const std::string x, const std::string y)
 	{
 		return x.compare(y) < 0;
 	}
@@ -178,28 +173,20 @@ public:
 	ErrorCodeEnum CheckEntity(const char *pszEntityName,EntityTestEnum eTestType);
 	int AddEntityState(const char *pszEntityName,EntityStateEnum eState);
 	ErrorCodeEnum GetEntityErrorList(int &warmLevel,CSimpleStringA &strList);
-	void SetEntityCfgInfo(const char *pszEntityName,int loadOpt){
-		m_entRunInfo[pszEntityName].loadOpt = loadOpt;
-		DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("%s,%d,%d",(LPCTSTR)pszEntityName,loadOpt,m_entRunInfo[pszEntityName].loadOpt);
-	};
+	void SetEntityCfgInfo(const char *pszEntityName,int loadOpt){m_entRunInfo[pszEntityName].loadOpt = loadOpt;};
 	void SetEntityRestarting(const char* pszEntityName,bool flag) { m_entRunInfo[pszEntityName].bRestarting = flag;}
 	int Proc(string entity, ProcType eType, DWORD dwCode,const char *pszMessage="");
 	void SetEverEnterMainPageFlag(bool bValue = true);
 private:
 	ErrorCodeEnum Initial();
 	void OnNormalWorkTimerout(void *pData);
-	void OnCalcCpuUsageTimerout(void *pData);
 
 	virtual void OnAnswer(CSmartPointer<IAsynWaitSp> pAsynWaitSp);
 	void LogErrInfo(const char* msgHead,const char* msgBody,const int errCode);
 	void LogActionProcess(const char *pszEntityName,ErrorCodeEnum errCode,TestActionEnum eAct);
 	void UpgradeActionProcess(const char *pszEntityName, const char *pAction);
 	void CheckEntityResouce(const char *pszEntityName,CEntityRunInfo &Info);
-	void CalcEntityCpuUsage(const char *pszEntityName, CEntityRunInfo &Info, bool bFirst);
-	void GetSystemMemoryStatus();
-	void GetSystemCPUStatus();
-	void GetSystemDiskStatus();
-	bool IsKeyEntity(const char *pszEntityName);
+	//bool IsKeyEntity(const char *pszEntityName);
 	bool ReadXmlFile(const char *szFileName);
 	ErrorCodeEnum ConnectToHealthManager();
 	
@@ -209,13 +196,13 @@ private:
 	map<string, EntityCfg, EntityNameCompare> m_mapEntity;
 	vector<CSimpleStringA> m_activeEntity,m_allEntity,m_vKeyEntity,m_vQueryStateEntity;
 	int m_restartNormal,m_restartSpecial,m_maxOsRestart,m_maxPowerRestart
-		,m_cpuHighPercent,m_memHighPercent,m_diskHighPercent,m_warmLevel,m_diskLastWarnHour;
+		,m_warmLevel,m_diskLastWarnHour;
 	DWORD m_dwIssueCount,m_dwCaptureCount;
 	bool m_bInIssue,m_bFirstCalcCpu, m_bEverInMainPage,m_bHaveGetEntityList;
-	int m_simulateTest;
-	CSimpleStringA m_csKeyEntity,m_csMachineType,m_csSite;
+	//CSimpleStringA m_csKeyEntity;
 	__int64  m_xIdlePre,m_xKernelPre,m_xUserPre;
 	HealthManagerService_ClientBase *m_pHealthClient;
+	CSystemStaticInfo m_sysInfo;
 };
 
 template<class T>

+ 115 - 121
Module/mod_selfchecker/mod_selfchecker.cpp

@@ -7,8 +7,6 @@
 #include "ModuleMix.h"
 #include "SpHelper.h"
 
-//read from config file? oiltmp
-const int MAX_RESTART_COUNT = 5;
 void SelfCheckerSession::Handle_RealCheck(SpReqAnsContext<SelfCheckerService_RealCheck_Req, SelfCheckerService_RealCheck_Ans>::Pointer ctx)
 {
 	LOG_FUNCTION();
@@ -18,23 +16,23 @@ void SelfCheckerSession::Handle_GetEntityErrorList(SpReqAnsContext<SelfCheckerSe
 {
 	m_pEntity->GetEntityErrorList(ctx);
 }
-ErrorCodeEnum CSelfCheckerEntity::GetLiveEntityList(CAutoArray<CSimpleString> &LiveEntitys)
+ErrorCodeEnum CSelfCheckerEntity::GetLiveEntityList(CAutoArray<CSimpleString>& LiveEntitys)
 {
 	ErrorCodeEnum errCode;
 	errCode = m_fsm.GetAllLiveEntity(LiveEntitys);
 	return errCode;
 }
-ErrorCodeEnum CSelfCheckerEntity::GetEntityTestCode(const char *pszEntityName,ErrorCodeEnum &LastTestError, TestActionEnum &eLastAction)
+ErrorCodeEnum CSelfCheckerEntity::GetEntityTestCode(const char* pszEntityName, ErrorCodeEnum& LastTestError, TestActionEnum& eLastAction)
 {
 	return Error_NotImpl;
 }
-ErrorCodeEnum CSelfCheckerEntity::ExamineEntity(const char *pszEntityName)
+ErrorCodeEnum CSelfCheckerEntity::ExamineEntity(const char* pszEntityName)
 {
 	CSmartPointer<IEntityFunction> pFunc = GetFunction();
 	CSmartPointer<IEntityFunctionPrivilege> pFuncPrivilege = pFunc.ConvertCase<IEntityFunctionPrivilege>();
 	CSmartPointer<IAsynWaitSp> spWait;
 	//ErrorCodeEnum errCode;
-	pFuncPrivilege->TestEntity(pszEntityName,Test_Examine,spWait);
+	pFuncPrivilege->TestEntity(pszEntityName, Test_Examine, spWait);
 	return Error_Succeed;
 }
 //ErrorCodeEnum CSelfCheckerEntity::AddEntity(const char *pszEntityName)
@@ -54,25 +52,25 @@ ErrorCodeEnum CSelfCheckerEntity::ExamineEntity(const char *pszEntityName)
 //	return Error_Succeed;
 //}
 // if pszTriggerEntity=null mean created by shell
-void CSelfCheckerEntity::OnCreated(const char *pszEntityName,ErrorCodeEnum eOnStartErrorCode,const char *pszCallerEntity)
+void CSelfCheckerEntity::OnCreated(const char* pszEntityName, ErrorCodeEnum eOnStartErrorCode, const char* pszCallerEntity)
 {
-	m_fsm.DoOnCreated(pszEntityName,eOnStartErrorCode,pszCallerEntity);
+	m_fsm.DoOnCreated(pszEntityName, eOnStartErrorCode, pszCallerEntity);
 }
 //Call after the entity has close or killed, eOnCloseErrorCode notic if the entity do OnClose normally and resource has beed release
-void CSelfCheckerEntity::OnClosed(const char *pszEntityName,EntityCloseCauseEnum eCloseCause,ErrorCodeEnum eOnCloseErrorCode,const char *pszCallerEntity)
+void CSelfCheckerEntity::OnClosed(const char* pszEntityName, EntityCloseCauseEnum eCloseCause, ErrorCodeEnum eOnCloseErrorCode, const char* pszCallerEntity)
 {
-	m_fsm.DoOnClosed(pszEntityName,eCloseCause,eOnCloseErrorCode,pszCallerEntity);
+	m_fsm.DoOnClosed(pszEntityName, eCloseCause, eOnCloseErrorCode, pszCallerEntity);
 }
 //the following OnException & OnEntityStateHook doing the same thing repeatly???
 //1 case is entity raise exception and catch by framework,but not mean the entity will close,2 case is the entity is enter lost state
-void CSelfCheckerEntity::OnException(const char *pszEntityName,const char *pszFunctionName,EntityStateEnum eState,EntityStateEnum eLastState,ErrorCodeEnum eErrorCode)
+void CSelfCheckerEntity::OnException(const char* pszEntityName, const char* pszFunctionName, EntityStateEnum eState, EntityStateEnum eLastState, ErrorCodeEnum eErrorCode)
 {
-	m_fsm.DoOnException(pszEntityName,pszFunctionName,eState,eLastState,eErrorCode);
+	m_fsm.DoOnException(pszEntityName, pszFunctionName, eState, eLastState, eErrorCode);
 }
-void CSelfCheckerEntity::OnEntityStateHook(const char *pszEntityName,const char *pszTriggerEntity,EntityStateEnum eState,EntityStateEnum eLastState)
+void CSelfCheckerEntity::OnEntityStateHook(const char* pszEntityName, const char* pszTriggerEntity, EntityStateEnum eState, EntityStateEnum eLastState)
 {
-	DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER)("%s trigger by %s: from %s to %s",pszEntityName,pszTriggerEntity, SpStrEntityState(eLastState), SpStrEntityState(eState));
-	m_fsm.AddEntityState(pszEntityName,eState);
+	DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("%s trigger by %s: from %s to %s",pszEntityName,pszTriggerEntity, SpStrEntityState(eLastState), SpStrEntityState(eState));
+	m_fsm.AddEntityState(pszEntityName, eState);
 	CSmartPointer<IEntityFunction> pFunc = GetFunction();
 	CSmartPointer<IEntityFunctionPrivilege> pFuncPrivilege = pFunc.ConvertCase<IEntityFunctionPrivilege>();
 	if (pFuncPrivilege == NULL)
@@ -83,66 +81,65 @@ void CSelfCheckerEntity::OnEntityStateHook(const char *pszEntityName,const char
 	CSmartPointer<IAsynWaitSp> spWait;
 	ErrorCodeEnum errCode;
 	int count = 0;
-	//oiltest
-	//if (!_strnicmp("MediaController",pszEntityName,strlen("MediaController")))
+
 	{
-		switch(eState)
+		switch (eState)
 		{
 		case EntityState_Lost:
-		{
-			//doing nothing except for loading stage. HandShake will take it.
-			//and only for MediaController module.
-			//oilyang@20210809 add entity lost LogWarn
-			char tmpWarnMsg[256] = {};
-			snprintf(tmpWarnMsg, sizeof(tmpWarnMsg), "%s lost. trig entity:%s,lastState:%d", pszEntityName, pszTriggerEntity, eLastState);
-			CEntityStaticInfo esi = { 0 };
-			ErrorCodeEnum ec = GetFunction()->GetEntityStaticInfo(pszEntityName, esi);
-			LogWarn(Severity_High, Error_Unexpect, SelfChecker_UserErrorCode_EntityLost_Start + esi.wEntityDevelopID, tmpWarnMsg);
-			if (m_bEverInMainPage && _strnicmp("TokenKeeper", pszEntityName, strlen("TokenKeeper")) == 0)
-			{
-				DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("TokenKeeper lost");
-				LogEvent(Severity_Middle, LOG_EVT_SELFCHECK_TOKEN_KEEPER_LOST, "TokenKeeper lost,restart and auth again.");
-				break;
-			}
-			if (m_bEverInMainPage)
-				break;
-			if (_strnicmp("MediaController", pszEntityName, strlen("MediaController")) != 0)
-				break;
-			count = m_entityProcInfo[pszEntityName].restartTimes;
-			if (count >= MAX_RESTART_COUNT)
-			{
-				DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("%s has restart %d times,give up to restart it again.", pszEntityName, count);
-				char xxx[256] = { 0 };
-				sprintf(xxx, "%s restart %d times,give up.", (LPCTSTR)pszEntityName, count);
-				DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("logwarn %s", xxx);
-				LogWarn(Severity_Middle, Error_Unexpect, LOG_WARN_SELFCHECK_ENTITY_LOST_TIMES, xxx);
-				break;
-			}
-			DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("%s lost count %d", pszEntityName, count);
-			errCode = pFuncPrivilege->TerminateEntity(pszEntityName, spWait);
-			if (errCode == Error_Succeed)
-			{
-				errCode = spWait->WaitAnswer(10000);
-				DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("onlost kill wait %d", errCode);
-			}
-			else
-				DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("onlost kill %d", errCode);
-			Sleep(5000);
-			DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("to start(lost)");
-			errCode = pFuncPrivilege->StartEntity(pszEntityName, NULL, spWait);
-			if (errCode == Error_Succeed)
 			{
-				errCode = spWait->WaitAnswer(10000);
-				DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("onlost start wait %d", errCode);
-			}
-			else
-				DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("onlost start %d", errCode);
+				//oilyang@20220415 special process of RVC.PAD with FWB
+				//doing nothing except for loading stage. HandShake will take it.
+				//and only for MediaController module.
+				//oilyang@20210809 add entity lost LogWarn
+				char tmpWarnMsg[256] = {};
+				snprintf(tmpWarnMsg, sizeof(tmpWarnMsg), "%s lost. trig entity:%s,lastState:%d", pszEntityName, pszTriggerEntity, eLastState);
+				CEntityStaticInfo esi = { 0 };
+				ErrorCodeEnum ec = GetFunction()->GetEntityStaticInfo(pszEntityName, esi);
+				LogWarn(Severity_High, Error_Unexpect, SelfChecker_UserErrorCode_EntityLost_Start + esi.wEntityDevelopID, tmpWarnMsg);
+				if (m_bEverInMainPage && _strnicmp("TokenKeeper", pszEntityName, strlen("TokenKeeper")) == 0)
+				{
+				    DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("TokenKeeper lost");
+					LogEvent(Severity_Middle, LOG_EVT_SELFCHECK_TOKEN_KEEPER_LOST, "TokenKeeper lost,restart and auth again.");
+					break;
+				}
+				if (m_bEverInMainPage)
+					break;
+				if (_strnicmp("MediaController", pszEntityName, strlen("MediaController")) != 0)
+					break;
+				count = m_entityProcInfo[pszEntityName].restartTimes;
+				if (count >= m_maxEtyRestartTimes)
+				{
+					DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("%s has restart %d times,give up to restart it again.", pszEntityName, count);
+					char xxx[256] = { 0 };
+					snprintf(xxx, sizeof(xxx), "%s restart %d times,give up.", (LPCTSTR)pszEntityName, count);
+					LogWarn(Severity_High, Error_Unexpect, LOG_WARN_SELFCHECK_ENTITY_LOST_TIMES, xxx);
+					break;
+				}
+				DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("%s lost count %d", pszEntityName, count);
+				errCode = pFuncPrivilege->TerminateEntity(pszEntityName, spWait);
+				if (errCode == Error_Succeed)
+				{
+					errCode = spWait->WaitAnswer(10000);
+					DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("onlost kill wait %d", errCode);
+				}
+				else
+					DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("onlost kill %d", errCode);
+				Sleep(5000);
+				errCode = pFuncPrivilege->StartEntity(pszEntityName, NULL, spWait);
+				if (errCode == Error_Succeed)
+				{
+					errCode = spWait->WaitAnswer(10000);
+					DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("onlost start wait %d", errCode);
+				}
+				else
+					DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("onlost start %d", errCode);
 
-			m_entityProcInfo[pszEntityName].restartTimes = count + 1;
-		}
+				m_entityProcInfo[pszEntityName].restartTimes = count + 1;
+			}
 			break;
 		case EntityState_Idle:
 		{
+			m_entityProcInfo[pszEntityName].restartTimes = 0;
 			if (!_strnicmp("AssistantChannel", pszEntityName, strlen("AssistantChannel")))
 			{
 				if (m_pAssChanClient != NULL)
@@ -150,30 +147,28 @@ void CSelfCheckerEntity::OnEntityStateHook(const char *pszEntityName,const char
 					m_pAssChanClient->SafeDelete();
 					m_pAssChanClient = NULL;
 				}
-
 				DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("AssistantChannel change to idle.");
 				LogEvent(Severity_Middle, LOG_EVT_SELFCHECK_ASSISTANTCHANNEL_IDLE, "AssistantChannel to idle.");
 				ConnectToAssistChannel();
 			}
-			if (!_strnicmp("SIPPhone", pszEntityName, strlen("SIPPhone")))
+			else if (!_strnicmp("SIPPhone", pszEntityName, strlen("SIPPhone")))
 			{
 				DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("SIPPhone change to idle.");
 				LogEvent(Severity_Middle, LOG_EVT_SELFCHECK_SIPPHONE_IDLE, "SIPPhone to idle.");
 			}
-			if (!_strnicmp("IEBrowser", pszEntityName, strlen("IEBrowser")))
+			else if (!_strnicmp("HealthManager", pszEntityName, strlen("HealthManager")))
 			{
-				DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("IEBrowser change to idle.");
-				LogEvent(Severity_Middle, LOG_EVT_SELFCHECK_IEBROWSER_IDLE, "IEBrowser to idle.");
-				m_bIEIdle = true;
 			}
-			if (!_strnicmp("HealthManager", pszEntityName, strlen("HealthManager")))
+			else if (!_strnicmp("LocalMediaPlay", pszEntityName, strlen("LocalMediaPlay")))
 			{
+				LogEvent(Severity_Middle, LOG_EVT_SELFCHECK_LOCALMEDIAPLAY_IDLE, "LocalMediaPlay to idle.");
 			}
-			if (!_strnicmp("LocalMediaPlay", pszEntityName, strlen("LocalMediaPlay")))
+			if (_strnicmp("Chromium", pszEntityName, strlen("Chromium")) == 0)
 			{
-				DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("LocalMediaPlay change to idle.");
-				LogEvent(Severity_Middle, LOG_EVT_SELFCHECK_LOCALMEDIAPLAY_IDLE, "LocalMediaPlay to idle.");
+				LogEvent(Severity_Middle, LOG_EVT_SELFCHECK_IEBROWSER_IDLE, "Chromium to idle.");
+				m_bIEIdle = true;
 			}
+
 		}
 			break;
 		default:
@@ -181,29 +176,29 @@ void CSelfCheckerEntity::OnEntityStateHook(const char *pszEntityName,const char
 		}
 	}
 }
-void CSelfCheckerEntity::OnUserStateHook(const char *pszEntityName,DWORD dwState,DWORD dwLastState)
+void CSelfCheckerEntity::OnUserStateHook(const char* pszEntityName, DWORD dwState, DWORD dwLastState)
 {
 }
-void CSelfCheckerEntity::OnCeateConnection(const char *pszCallerEntity,const char *pszServiceEntity)
+void CSelfCheckerEntity::OnCeateConnection(const char* pszCallerEntity, const char* pszServiceEntity)
 {
 }
-void CSelfCheckerEntity::OnCloseConnection(const char *pszCallerEntity,const char *pszServiceEntity)
+void CSelfCheckerEntity::OnCloseConnection(const char* pszCallerEntity, const char* pszServiceEntity)
 {
 }
 void CSelfCheckerEntity::RealCheck(SpReqAnsContext<SelfCheckerService_RealCheck_Req, SelfCheckerService_RealCheck_Ans>::Pointer ctx)
 {
-	DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Real check %s",(LPCTSTR)ctx->Req.name);
+	DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Real check %s", (LPCTSTR)ctx->Req.name);
 	m_fsm.CheckEntity(ctx->Req.name,Test_ShakeHand);
 	ctx->Answer(Error_Succeed);
 }
 void CSelfCheckerEntity::GetEntityErrorList(SpReqAnsContext<SelfCheckerService_GetEntityErrorList_Req, SelfCheckerService_GetEntityErrorList_Ans>::Pointer ctx)
 {
-	ErrorCodeEnum eErr = m_fsm.GetEntityErrorList(ctx->Ans.warmLevel,ctx->Ans.list);
+	ErrorCodeEnum eErr = m_fsm.GetEntityErrorList(ctx->Ans.warmLevel, ctx->Ans.list);
 	ctx->Answer(eErr);
 }
-void CSelfCheckerEntity::OnLog(const CAutoArray<CUUID> &SubIDs, const CUUID nLogID,const LogTypeEnum eLogType, const SeverityLevelEnum eLevel,
-	const DWORD dwSysError,const DWORD dwUserCode,const DWORD dwEntityInstanceID, const WORD wEntityDevelID, 
-	const CAutoArray<DWORD> &Param, const char *pszEntityName, const char *pszModuleName,const char *pszMessage, const linkContext& pLinkInfo)
+void CSelfCheckerEntity::OnLog(const CAutoArray<CUUID>& SubIDs, const CUUID nLogID, const LogTypeEnum eLogType, const SeverityLevelEnum eLevel,
+	const DWORD dwSysError, const DWORD dwUserCode, const DWORD dwEntityInstanceID, const WORD wEntityDevelID,
+	const CAutoArray<DWORD>& Param, const char* pszEntityName, const char* pszModuleName, const char* pszMessage, const linkContext& pLinkInfo)
 {
 	//oilyang@20200304 add process FWB open suc.
 	if (dwUserCode == LOG_EVT_CARDREADER_OPEN_SUC_FWB)
@@ -247,8 +242,8 @@ void CSelfCheckerEntity::OnLog(const CAutoArray<CUUID> &SubIDs, const CUUID nLog
 	//oilyang@20170918 only process the Log_Error of Severity_High
 	if (eLogType != Log_Error || eLevel != Severity_High)
 		return;
-	DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("user code %d,%s",dwUserCode,(LPCTSTR)pszMessage);
-	switch(dwUserCode)
+	DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("user code %d,%s", dwUserCode, (LPCTSTR)pszMessage);
+	switch (dwUserCode)
 	{
 	case LOG_ERR_PINPAD_FAILED:
 	case ERROR_MOD_MEDIACONTROLLER_ENVCAMERA_BUG:
@@ -257,23 +252,23 @@ void CSelfCheckerEntity::OnLog(const CAutoArray<CUUID> &SubIDs, const CUUID nLog
 	case ERROR_MOD_MEDIACONTROLLER_OPTCAM_OPEN:
 	case ERROR_MOD_MEDIACONTROLLER_ENVCAM_INITFAIL:
 	case ERROR_MOD_MEDIACONTROLLER_OPTCAM_INITFAIL:
-		MsgPushedByAssChannel(ACM_TYPE_DEVICE,ACM_DEVICE_ERROR,pszEntityName,pszMessage);
+		MsgPushedByAssChannel(ACM_TYPE_DEVICE, ACM_DEVICE_ERROR, pszEntityName, pszMessage);
 		break;
 	default:
 		break;
 	}
 	m_fsm.Proc(pszEntityName, ProcType_Warn, dwUserCode, pszMessage);
 }
-ErrorCodeEnum CSelfCheckerEntity::MsgPushedByAssChannel(const int type,const int sub_type,const char *pszEntityName,const char *pszMessage)
+ErrorCodeEnum CSelfCheckerEntity::MsgPushedByAssChannel(const int type, const int sub_type, const char* pszEntityName, const char* pszMessage)
 {
 	if (m_pAssChanClient == NULL)
 	{
-			ErrorCodeEnum eConn = ConnectToAssistChannel();
-			if (eConn != Error_Succeed)
-			{
-				DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("connect to AssistantChannel failed(%d).",eConn);
-				return Error_Resource;
-			}
+		ErrorCodeEnum eConn = ConnectToAssistChannel();
+		if (eConn != Error_Succeed)
+		{
+			DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("connect to AssistantChannel failed(%d).", eConn);
+			return Error_Resource;
+		}
 	}
 	ChannelService_Send_Info Info;
 	Info.compress = false;
@@ -284,14 +279,14 @@ ErrorCodeEnum CSelfCheckerEntity::MsgPushedByAssChannel(const int type,const int
 	Info.data.Alloc(sizeof(int));
 	SpBuffer buf;
 	buf.OpenWrite();
-	CSimpleStringA csEntityName(pszEntityName),csBlack(" "),csMsg(pszMessage);
-	buf & csEntityName & csBlack & csMsg;
+	CSimpleStringA csEntityName(pszEntityName), csBlack(" "), csMsg(pszMessage);
+	buf& csEntityName& csBlack& csMsg;
 	Info.data = buf.ToBlob();
 	m_pAssChanClient->Send(Info);
-	DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("send msg %d %d:%s %s",type,sub_type,pszEntityName,pszMessage);
+	DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("send msg %d %d:%s %s", type, sub_type, pszEntityName, pszMessage);
 	return Error_Succeed;
 }
-ErrorCodeEnum CSelfCheckerEntity::GetEntityStatusStr(CSimpleStringA &result)
+ErrorCodeEnum CSelfCheckerEntity::GetEntityStatusStr(CSimpleStringA& result)
 {
 	CSmartPointer<IEntityFunction> pFunc = GetFunction();
 	CEntityRunInfo runInfo;
@@ -299,15 +294,14 @@ ErrorCodeEnum CSelfCheckerEntity::GetEntityStatusStr(CSimpleStringA &result)
 	vector<CSimpleStringA>::iterator it;
 	for (it = m_vQueryStateEntity.begin(); it != m_vQueryStateEntity.end(); ++it)
 	{
-		eErr = pFunc->GetEntityRunInfo(*it,runInfo);
+		eErr = pFunc->GetEntityRunInfo(*it, runInfo);
 		if (eErr == Error_Succeed)
 		{
-			DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("%s,%d",(LPCTSTR)*it,runInfo.dwUserState);
 			result += UserDefEntityMsg[runInfo.dwUserState][0];
 			result += "  ;";
 		}
 	}
-	DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("state[%s]",(LPCTSTR)result);
+	DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("state[%s]", (LPCTSTR)result);
 	return Error_Succeed;
 }
 ErrorCodeEnum CSelfCheckerEntity::ConnectToAssistChannel()
@@ -324,11 +318,11 @@ ErrorCodeEnum CSelfCheckerEntity::ConnectToAssistChannel()
 		}
 		else
 		{
-			DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("AssistantChannel connected.");
+			DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("AssistantChannel connected.");
 			{
 				ChannelService_BeginState_Sub Sub;
 				ErrorConn = m_pAssChanClient->BeginState(Sub);
-				if (ErrorConn != Error_Succeed) 
+				if (ErrorConn != Error_Succeed)
 				{
 					DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("BeginState biz channel failed!");
 					m_pAssChanClient->GetFunction()->CloseSession();
@@ -337,7 +331,7 @@ ErrorCodeEnum CSelfCheckerEntity::ConnectToAssistChannel()
 				}
 				else
 				{
-					DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("BeginState biz channel success!");
+					DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("BeginState biz channel success!");
 				}
 			}
 
@@ -345,7 +339,7 @@ ErrorCodeEnum CSelfCheckerEntity::ConnectToAssistChannel()
 				ChannelService_BeginRecv_Sub Sub;
 				Sub.type = ACM_TYPE_DEVICE;
 				ErrorConn = m_pAssChanClient->BeginRecv(Sub);
-				if (ErrorConn != Error_Succeed) 
+				if (ErrorConn != Error_Succeed)
 				{
 					DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("Begin BeginRecv ACM_TYPE_DEVICE failed!");
 					m_pAssChanClient->GetFunction()->CloseSession();
@@ -354,7 +348,7 @@ ErrorCodeEnum CSelfCheckerEntity::ConnectToAssistChannel()
 				}
 				else
 				{
-					DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Begin BeginRecv ACM_TYPE_DEVICE success!");
+					DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Begin BeginRecv ACM_TYPE_DEVICE success!");
 				}
 			}
 		}
@@ -363,7 +357,7 @@ ErrorCodeEnum CSelfCheckerEntity::ConnectToAssistChannel()
 }
 ErrorCodeEnum CSelfCheckerEntity::RestartModule(const char* pEntityName)
 {
-	DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("to RestartModule:%s",pEntityName);
+	DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("to RestartModule:%s", pEntityName);
 	m_fsm.SetEntityRestarting(pEntityName, true);
 	CSmartPointer<IEntityFunction> pFunc = GetFunction();
 	CSmartPointer<IEntityFunctionPrivilege> pFuncPrivilege = pFunc.ConvertCase<IEntityFunctionPrivilege>();
@@ -380,7 +374,7 @@ ErrorCodeEnum CSelfCheckerEntity::RestartModule(const char* pEntityName)
 		eErrCode = spWait->WaitAnswer(10000);
 	if (eErrCode != Error_Succeed)
 	{
-		DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("kill %s %d", pEntityName, eErrCode);
+		DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("kill %s %d", pEntityName, eErrCode);
 		m_fsm.SetEntityRestarting(pEntityName, false);
 		return eErrCode;
 	}
@@ -390,7 +384,7 @@ ErrorCodeEnum CSelfCheckerEntity::RestartModule(const char* pEntityName)
 		eErrCode = spWait->WaitAnswer(10000);
 	if (eErrCode != Error_Succeed)
 	{
-		DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("start %s %d", pEntityName, eErrCode);
+		DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("start %s %d", pEntityName, eErrCode);
 		m_fsm.SetEntityRestarting(pEntityName, false);
 		return eErrCode;
 	}
@@ -408,25 +402,25 @@ void CSelfCheckerEntity::OnSysVarEvent(const char* pszKey, const char* pszValue,
 		}
 	}
 }
-void AssistChannelSelfCheckerClient::OnMessage(ErrorCodeEnum Error, ChannelService_State_Info &Msg,  CSmartPointer<IReleasable> pData)	
+void AssistChannelSelfCheckerClient::OnMessage(ErrorCodeEnum Error, ChannelService_State_Info& Msg, CSmartPointer<IReleasable> pData)
 {
 
 }
-void AssistChannelSelfCheckerClient::OnMessage(ErrorCodeEnum Error, ChannelService_Packet_Info &Msg, CSmartPointer<IReleasable> pData)
+void AssistChannelSelfCheckerClient::OnMessage(ErrorCodeEnum Error, ChannelService_Packet_Info& Msg, CSmartPointer<IReleasable> pData)
 {
 	LOG_FUNCTION();
-	if (Error == Error_Succeed) 
+	if (Error == Error_Succeed)
 	{
-		CSelfCheckerEntity *pEntity = static_cast<CSelfCheckerEntity*>(m_pEntityBase);
-		switch(Msg.sub_type)
+		CSelfCheckerEntity* pEntity = static_cast<CSelfCheckerEntity*>(m_pEntityBase);
+		switch (Msg.sub_type)
 		{
 		case ACM_ENTITY_STATE_REQ:
-			{
-				CSimpleStringA result;
-				pEntity->GetEntityStatusStr(result);
-				pEntity->MsgPushedByAssChannel(ACM_TYPE_DEVICE,ACM_ENTITY_STATE_ANS,result);
-			}
-			break;
+		{
+			CSimpleStringA result;
+			pEntity->GetEntityStatusStr(result);
+			pEntity->MsgPushedByAssChannel(ACM_TYPE_DEVICE, ACM_ENTITY_STATE_ANS, result);
+		}
+		break;
 		default:
 			break;
 		}

+ 25 - 10
Module/mod_selfchecker/mod_selfchecker.h

@@ -40,7 +40,7 @@ class CSelfCheckerEntity : public CEntityBase,public IEntityLifeListener,public
 	,public ILogListener
 {
 public:
-	CSelfCheckerEntity():m_bIEIdle(false),m_pAssChanClient(NULL), m_bEverInMainPage(false){ }
+	CSelfCheckerEntity():m_bIEIdle(false),m_pAssChanClient(NULL), m_bEverInMainPage(false), m_maxEtyRestartTimes(5){ }
 	virtual ~CSelfCheckerEntity() {}
 	virtual const char *GetEntityName() const { return "SelfChecker"; }
 	
@@ -72,19 +72,23 @@ public:
 			pTransactionContext->SendAnswer(errCode);
 			return;
 		}
-		DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("regist entity event ok.");
+		DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("regist entity event ok.");
 		GetFunction()->SubscribeLog(m_uuidCardIsuuer,this,Log_Error,Severity_High,Error_IgnoreAll,-1,NULL,false);
 		GetFunction()->SubscribeLog(m_uuidCardSwiper,this,Log_Event,Severity_High,Error_IgnoreAll,-1,"CardSwiper",false);
 		GetFunction()->SubscribeLog(m_uuidCardSwiper, this, Log_Error, Severity_Middle, Error_IgnoreAll, -1, "CardSwiper");
 		GetFunction()->RegistSysVarEvent("UIState", this);
-		CSmartPointer<IConfigInfo> spConfig;
-		ErrorCodeEnum eCfg = pFunc->OpenConfig(Config_Software, spConfig);
+		m_csQueryStateEntity = "CardIssuer,CardSwiper,IDCertificate,PinPad,MediaController,CounterConnector";
+		CSmartPointer<IConfigInfo> spCenterConfig;
+		CSimpleStringA csQueryStateEntity(true);
+		///**TODO(Gifur@1/9/2023): Ôö¼Ó¼¯ÖÐÅäÖà */
+		ErrorCodeEnum eCfg = pFunc->OpenConfig(Config_CenterSetting, spCenterConfig);
 		if (eCfg != Error_Succeed) {
-			DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("open cfg file failed(%s)!",SpStrError(eCfg));
-		}
-		else
-		{
-			spConfig->ReadConfigValue("init","QueryStateEntity",m_csQueryStateEntity);
+			DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("open cfg file failed(%s)!", SpStrError(eCfg));
+		} else {
+			spCenterConfig->ReadConfigValue(GetEntityName(), "QueryStateEntity", csQueryStateEntity);
+			if (!csQueryStateEntity.IsNullOrEmpty()) {
+				m_csQueryStateEntity = csQueryStateEntity;
+			}
 		}
 		auto list = m_csQueryStateEntity.Split(',');
 		for (int i = 0; i < list.GetCount(); ++i)
@@ -92,6 +96,15 @@ public:
 			CSimpleStringA entity = list[i];
 			m_vQueryStateEntity.push_back(entity);
 		}
+
+		spCenterConfig->ReadConfigValueInt(GetEntityName(), "EtyRestartTimes", m_maxEtyRestartTimes);
+		if (m_maxEtyRestartTimes < 5) {
+			m_maxEtyRestartTimes = 5;
+		}
+		if(GetFunction()->GetSystemStaticInfo(m_sysInfo) != Error_Succeed)
+		{
+			DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Get System Static info failed.");
+		}
 		pTransactionContext->SendAnswer(errCode);
 	}
 
@@ -120,7 +133,7 @@ public:
 	void GetEntityErrorList(SpReqAnsContext<SelfCheckerService_GetEntityErrorList_Req, SelfCheckerService_GetEntityErrorList_Ans>::Pointer ctx);
 	virtual void OnLog(const CAutoArray<CUUID> &SubIDs, const CUUID nLogID,const LogTypeEnum eLogType, const SeverityLevelEnum eLevel,
 		const DWORD dwSysError,const DWORD dwUserCode,const DWORD dwEntityInstanceID, const WORD wEntityDevelID, 
-		const CAutoArray<DWORD> &Param, const char *pszEntityName, const char *pszModuleName,const char *pszMessage, const linkContext& pLinkInfo);
+		const CAutoArray<DWORD> &Param, const char *pszEntityName, const char *pszModuleName,const char *pszMessage, const linkContext &pLinkInfo);
 	ErrorCodeEnum MsgPushedByAssChannel(const int type,const int sub_type,const char *pszEntityName="",const char *msg="");
 	ErrorCodeEnum GetEntityStatusStr(CSimpleStringA &result);
 	ErrorCodeEnum ConnectToAssistChannel();
@@ -141,6 +154,8 @@ private:
 	CSimpleStringA m_csQueryStateEntity;
 	vector<CSimpleStringA> m_vQueryStateEntity;
 	ErrorCodeEnum RestartModule(const char* pEntityName);
+	CSystemStaticInfo m_sysInfo;
+	int m_maxEtyRestartTimes;
 };
 AssistChannelSelfCheckerClient::AssistChannelSelfCheckerClient(CSelfCheckerEntity *pEntity):ChannelService_ClientBase(pEntity)
 {

Some files were not shown because too many files changed in this diff