#ifndef RVC_MOD_UPGRADEMGR_H_ #define RVC_MOD_UPGRADEMGR_H_ #include "stdafx.h" #include "SpBase.h" #include "SimpleString.h" #include "UpgradeManager_server_g.h" #include "UpgradeManager_UserErrorCode.h" #ifdef RVC_OS_WIN #else #include "SpTest.h" #include "modVer.h" #endif #include "UpgradeTaskFSM.h" using namespace UpgradeManager; #define UPGRADE_MGR_NOT_IMPLEMENT 0xF0000000 // 新升级模式未实现 // 升级管理 UpgradeManager 0x506 class CUpgradeMgrEntity : public CEntityBase, public ISysVarListener, public ILogListener { public: CUpgradeMgrEntity(){ m_IsSM3listSucc=0; m_beginSM3HashTime=0; m_strSM3Hash=""; m_bStartUp=false;//首页是否进入 m_initSucc=false;//状态机是否启动成功 m_testResult=Error_Succeed;//默认是成功的 m_iBlackFileSum=0; } virtual ~CUpgradeMgrEntity() {} virtual const char *GetEntityName() const { return "UpgradeManager"; } virtual bool IsService()const{return true;} #ifdef RVC_OS_WIN #else const char* GetEntityVersion() const override { return MODULE_VERSION_FULL; } ON_ENTITYT_TEST() #endif virtual void OnStarted(); virtual void OnSelfTest(EntityTestEnum eTestType,CSmartPointer pTransactionContext); virtual void OnPreClose(EntityCloseCauseEnum eCloseCause,CSmartPointer pTransactionContext); virtual CServerSessionBase *OnNewSession(const char* /*pszRemoteEntityName*/, const char * /*pszParam*/); virtual void OnSysVarEvent(const char *pszKey, const char *pszValue,const char *pszOldValue,const char *pszEntityName); static char GetInstallStateVal(const InstallStateEnum enumVal); ErrorCodeEnum RegistLocalPack(const CSimpleStringA &strPackFile); DWORD RegistManualPack(const CSimpleStringA &strPackFile); DWORD GetManualPacks(CSimpleStringA &strManualPacks); ErrorCodeEnum CancelUpdate(const CSimpleStringA &strPackName); ErrorCodeEnum RollbackUpdate(const CSimpleStringA &strVersion); ErrorCodeEnum SwitchUpgrade(const CSimpleStringA &strPack); ErrorCodeEnum GetUpgradeState(bool &bInstalling, CSimpleStringA &strPackFile, CSimpleStringA &strExecID, char &nInstallState, bool &bSysInstall, bool &bLightPack, CSimpleStringA &strNewVersion); //检测active文件是否被锁 ErrorCodeEnum testActive(); //modify by lwt 新状态机加入方法 ErrorCodeEnum NewStopMediaPlay(); static void HttpsLogCallBack(const char* logtxt); virtual void OnLog(const CAutoArray& SubIDs, const CUUID nLogID, const LogTypeEnum eLogType, const SeverityLevelEnum eLevel, const DWORD dwSysError, const DWORD dwUserCode, const DWORD dwEntityInstanceID, const WORD wEntityDevelID, const CAutoArray& Param, const char* pszEntityName, const char* pszModuleName, const char* pszMessage, const linkContext& pLinkInfo); public: map m_FileHashMap; // 版本文件hash值集合 CSimpleStringA m_strMD5List; CSimpleStringA m_strSM3Hash;//SM3 32位hash int m_IsSM3listSucc;//获取SM3哈希list是否成功,0:还未计算完毕,1:表示成功 ,-1表示计算失败 DWORD m_beginSM3HashTime;//开始计算sm3hahs时间 bool m_bStartUp;//是否系统首页启动成功 //bool m_bSystemStartUp;//框架启动成功 CUpgradeTaskFSM m_taskFSM; bool bNewUpgradeMgr;//是否启用新状态机(很重要的变量) ErrorCodeEnum m_testResult;//实体级别握手变量 CSimpleStringA m_grayLaunchUrl;//灰度发布url地址 int m_CenterModel;//集中配置模式 0:旧模式 1:新旧并存模式 2:新模式 bool m_initSucc;//状态机是否启动成功 int m_iBlackFileSum;//黑名单文件数量 private: CUUID m_uuidHeartBeat; }; class CUpgradeMgrSession : public UpgradeMgrService_ServerSessionBase { public: CUpgradeMgrSession(CUpgradeMgrEntity *pEntity) : m_pEntity(pEntity) {} virtual ~CUpgradeMgrSession() {} virtual void Handle_RegistLocalPack(SpReqAnsContext::Pointer ctx) { DbgToBeidou(ctx->link, __FUNCTION__)(); ErrorCodeEnum rc = m_pEntity->RegistLocalPack(ctx->Req.strPackFile); ctx->Answer(rc); } virtual void Handle_RegistManualPack(SpReqAnsContext::Pointer ctx) { LOG_FUNCTION(); DbgToBeidou(ctx->link, __FUNCTION__)(); DbgWithLink(LOG_LEVEL_INFO, ctx->link.checkEmpty() ? LOG_TYPE_SYSTEM : LOG_TYPE_USER).setAPI(__FUNCTION__)("RegistManualPack received!"); DWORD dwRet = 0; CSimpleStringA strErrmsg="RegistManualPack new UpgradeMgr is not deal with"; dwRet = m_pEntity->RegistManualPack(ctx->Req.strPackFile); ctx->Ans.Errcode = dwRet; ctx->Ans.ErrMsg = strErrmsg; ctx->Answer(Error_Succeed); } virtual void Handle_CancelUpdate(SpReqAnsContext::Pointer ctx) { DbgToBeidou(ctx->link, __FUNCTION__)(); DbgWithLink(LOG_LEVEL_INFO, ctx->link.checkEmpty() ? LOG_TYPE_SYSTEM : LOG_TYPE_USER).setAPI(__FUNCTION__)("CancelUpdate received!"); ErrorCodeEnum rc = m_pEntity->CancelUpdate(ctx->Req.strPackFile); ctx->Answer(rc); } virtual void Handle_RollbackUpdate(SpReqAnsContext::Pointer ctx) { DbgToBeidou(ctx->link, __FUNCTION__)(); DbgWithLink(LOG_LEVEL_INFO, ctx->link.checkEmpty() ? LOG_TYPE_SYSTEM : LOG_TYPE_USER).setAPI(__FUNCTION__)("RollbackUpdate received!"); auto rc = m_pEntity->RollbackUpdate(ctx->Req.strVersion); ctx->Answer(rc); } virtual void Handle_GetUpgradeState(SpReqAnsContext::Pointer ctx) { DbgToBeidou(ctx->link, __FUNCTION__)(); DbgWithLink(LOG_LEVEL_INFO, ctx->link.checkEmpty() ? LOG_TYPE_SYSTEM : LOG_TYPE_USER).setAPI(__FUNCTION__)("GetUpgradeState received!"); auto rc = m_pEntity->GetUpgradeState(ctx->Ans.bInstalling, ctx->Ans.strPackFile, ctx->Ans.strExecID, ctx->Ans.cInstallState, ctx->Ans.bSysInstall, ctx->Ans.bLightPack, ctx->Ans.strNewVersion); ctx->Answer(rc); } virtual void Handle_SwitchUpgrade(SpReqAnsContext::Pointer ctx) { DbgToBeidou(ctx->link, __FUNCTION__)(); DbgWithLink(LOG_LEVEL_INFO, ctx->link.checkEmpty() ? LOG_TYPE_SYSTEM : LOG_TYPE_USER).setAPI(__FUNCTION__)("SwitchUpgrade received!"); auto rc = m_pEntity->SwitchUpgrade(ctx->Req.strPackFile); ctx->Answer(rc); } virtual void Handle_GetManualPacks(SpReqAnsContext::Pointer ctx) { LOG_FUNCTION(); DbgToBeidou(ctx->link, __FUNCTION__)(); DbgWithLink(LOG_LEVEL_INFO, ctx->link.checkEmpty() ? LOG_TYPE_SYSTEM : LOG_TYPE_USER).setAPI(__FUNCTION__)("GetManualPacks received!"); DWORD dwRet = 0; CSimpleStringA strErrmsg= "GetManualPacks new UpgradeMgr is not deal with"; CSimpleStringA strPackList=""; dwRet = m_pEntity->GetManualPacks(strPackList); ctx->Ans.Errcode = dwRet; ctx->Ans.ErrMsg = strErrmsg; ctx->Answer(Error_Succeed); } private: CUpgradeMgrEntity *m_pEntity; }; #endif //RVC_MOD_UPGRADEMGR_H_