Explorar o código

#IQRV #comment: vtm拉取配置完成后设置更新集中配置的定时器

陈纪林80310970 hai 6 meses
pai
achega
69af1faeac

+ 47 - 2
Module/mod_vtmloader/VtmLoaderFSM.cpp

@@ -253,6 +253,7 @@ ErrorCodeEnum CVtmLoaderFSM::OnInit()
 
 ErrorCodeEnum CVtmLoaderFSM::OnExit()
 {
+	GetEntityBase()->GetFunction()->KillTimer(TIMER_CENTERSETTING_UPDATE_CHECK);
 	RemoveStateHooker(this);
 	return Error_Succeed;
 }
@@ -1762,8 +1763,10 @@ bool CVtmLoaderFSM::GetConfig()
 	}
 	refreshLogLevel();
 
-
-	//all cfg is ready, then init the entity
+	//all cfg is ready, then init the entity, set centersetting update timer
+	void* pTmpData = NULL;
+	ITimerListener* pListener = new TimerOutHelper<CVtmLoaderFSM>(this, &CVtmLoaderFSM::OnCentersettingUpdateTimeout, pTmpData);
+	GetEntityBase()->GetFunction()->SetTimer(TIMER_CENTERSETTING_UPDATE_CHECK, pListener, CENTERSETTING_UPDATE_CHECK_TIME);
 
 	eErr = SubscribeEntitysEvents();
 	if (eErr != Error_Succeed)
@@ -3032,4 +3035,46 @@ void CVtmLoaderFSM::DoSpecialJobInTestRoom()
 		Sleep(10000);
 		GetEntityBase()->GetFunction()->GetPrivilegeFunction()->Reboot(RebootTrigger_ManualLocal, RebootWayEnum::RebootWay_Framework);
 	}
+}
+
+DWORD CVtmLoaderFSM::GetCenterCfgThread()
+{
+	bool isUpdate = false, isReset = false;
+	CSimpleString version;
+	if (false == GetEntityBase()->GetFunction()->HasPrivilege())
+	{
+		LogWarn(Severity_High, Error_Unexpect, VtmLoader_CenterSettingConnectFailed,
+			CSimpleStringA::Format("下载集中配置失败:%s do not has privilege", __FUNCTION__));
+		DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER).setLogCode("QLR0402101Z01").setResultCode("RTA1104")("集中配置下载失败");
+		return -1;
+	}
+
+
+	auto ret = GetEntityBase()->GetFunction()->GetPrivilegeFunction()->TryUpdateCenterCfg(isUpdate, isReset, version);
+	if (ret != ErrorCodeEnum::Error_Succeed)
+	{
+		LogWarn(Severity_High, Error_Unexpect, VtmLoader_CenterSettingConnectFailed,
+			CSimpleStringA::Format("下载集中配置失败:%d", ret));
+		DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER).setLogCode("QLR0402101Z01").setResultCode("RTA1104")("集中配置下载失败");
+		return -1;
+	}
+
+	if (!isUpdate)
+	{
+		DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("GetCenterSetting")("Centersetting not changed from spshell");
+		return -1;
+	}
+
+	LogWarn(Severity_Low, Error_Succeed, VtmLoader_CenterSettingConnectFailed,
+		CSimpleStringA::Format("下载集中配置成功,版本号变更成:%s", version.GetData()));
+
+	if (isReset)
+		LogEvent(Severity_Middle, EVENT_MOD_CENTERSETTING_CRITICAL_UPDATE, "SpShell:Update centersetting with critical items.");
+	return 0;
+}
+
+void CVtmLoaderFSM::OnCentersettingUpdateTimeout(void* pData)
+{
+	GetCenterCfgThread();
+	GetEntityBase()->GetFunction()->ResetTimer(TIMER_CENTERSETTING_UPDATE_CHECK, CENTERSETTING_UPDATE_CHECK_TIME);
 }

+ 31 - 1
Module/mod_vtmloader/VtmLoaderFSM.h

@@ -7,6 +7,10 @@
 #include "VtmLoader_server_g.h"
 using namespace VtmLoader;
 
+//集中配置更新  
+#define CENTERSETTING_UPDATE_CHECK_TIME 60000 * 5 //集中配置更新时间5分钟
+#define TIMER_CENTERSETTING_UPDATE_CHECK 1
+
 enum EvtType
 {
 	USER_EVT_NetworkCheck_Passed = EVT_USER + 1,		// 网络检查通过,包括网卡及到总行服务的连通性
@@ -74,6 +78,30 @@ struct EntityLoadFault
 };
 class CVtmLoaderEntity;
 
+template<class T>
+class TimerOutHelper : public ITimerListener
+{
+public:
+	typedef void (T::* FuncTimer)(void* pUserdata);
+
+	TimerOutHelper(T* p, FuncTimer pTimerFunc, void* pData, bool bDeleteSelf = false)
+		: m_pObject(p), m_pUserData(pData), m_pTimer(pTimerFunc), m_bDeleteSelf(bDeleteSelf)
+	{
+	}
+
+	virtual void OnTimeout(DWORD dwTimerID)
+	{
+		(m_pObject->*m_pTimer)(m_pUserData);
+		if (m_bDeleteSelf)
+			delete this;
+	}
+private:
+	void* m_pUserData;
+	T* m_pObject;
+	FuncTimer m_pTimer;
+	bool m_bDeleteSelf;
+};
+
 class CVtmLoaderFSM : public FSMImpl<CVtmLoaderFSM>, public IFSMStateHooker, public ICallbackListener
 {
 public:
@@ -198,7 +226,9 @@ private:
 	void CheckAudio(SpReqAnsContext<VtmLoaderService_CheckDeviceEntity_Req, VtmLoaderService_CheckDeviceEntity_Ans>::Pointer ctx);
 	void CheckVideo(SpReqAnsContext<VtmLoaderService_CheckDeviceEntity_Req, VtmLoaderService_CheckDeviceEntity_Ans>::Pointer ctx);
 	bool IfInExcludedLoadList(CSimpleStringA csEntityName);
-		
+	
+	DWORD GetCenterCfgThread();
+	void OnCentersettingUpdateTimeout(void* pData);
 	
 };
 class CheckDeviceEntityEvent : public FSMEvent

+ 0 - 42
Module/mod_vtmloader/mod_vtmloader.cpp

@@ -190,48 +190,6 @@ void CVtmLoaderEntity::EntityLostProc(CSimpleStringA entityName)
 		std::thread(dealOldEventThread).detach();
 	}
 
-	DWORD getCenterCfgThread(LPVOID param)
-	{
-		CVtmLoaderEntity* req = (CVtmLoaderEntity*)param;
-		bool isUpdate = false, isReset = false;
-		CSimpleString version;
-		if (false == req->GetFunction()->HasPrivilege())
-		{
-			LogWarn(Severity_High, Error_Unexpect, VtmLoader_CenterSettingConnectFailed,
-				CSimpleStringA::Format("下载集中配置失败:%s do not has privilege", __FUNCTION__));
-			DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER).setLogCode("QLR0402101Z01").setResultCode("RTA1104")("集中配置下载失败");
-			return -1;
-		}
-
-
-		auto ret = req->GetFunction()->GetPrivilegeFunction()->TryUpdateCenterCfg(isUpdate, isReset, version);
-		if (ret != ErrorCodeEnum::Error_Succeed)
-		{
-			LogWarn(Severity_High, Error_Unexpect, VtmLoader_CenterSettingConnectFailed,
-				CSimpleStringA::Format("下载集中配置失败:%d", ret));
-			DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER).setLogCode("QLR0402101Z01").setResultCode("RTA1104")("集中配置下载失败");
-			return -1;
-		}
-
-		if (!isUpdate)
-		{
-			DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("GetCenterSetting")("Centersetting not changed from spshell");
-			return -1;
-		}
-
-		LogWarn(Severity_Low, Error_Succeed, VtmLoader_CenterSettingConnectFailed,
-			CSimpleStringA::Format("下载集中配置成功,版本号变更成:%s", version.GetData()));
-
-		if (isReset)
-			LogEvent(Severity_Middle, EVENT_MOD_CENTERSETTING_CRITICAL_UPDATE, "SpShell:Update centersetting with critical items.");
-		return 0;
-	}
-
-	void CVtmLoaderEntity::OnTimeout(DWORD dwTimerID)
-	{
-		CloseHandle(CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)&getCenterCfgThread, this, 0, NULL));
-	}
-
 SP_BEGIN_ENTITY_MAP()
 	SP_ENTITY(CVtmLoaderEntity)
 SP_END_ENTITY_MAP()

+ 1 - 2
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, public ITimerListener
+class CVtmLoaderEntity : public CEntityBase, public ILogListener, public IEntityStateListener
 {
 public:
 	CVtmLoaderEntity() :m_SubLogID1(0), m_SubLogID2(0), m_dwBeginTime(0),
@@ -55,7 +55,6 @@ public:
 	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);
-	virtual void OnTimeout(DWORD dwTimerID);
 
 	ErrorCodeEnum UnsubscribeEntitysEvents();
 	CSimpleStringA GetCurMaintainer(){ return m_strUserID;}