mod_UpgradeMgr.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595
  1. #include "stdafx.h"
  2. #include "mod_UpgradeMgr.h"
  3. #include "LocalMediaPlay_client_g.h"
  4. #include "fileutil.h"
  5. #include <regex>
  6. #include "RVCComm.h"
  7. #ifdef RVC_OS_WIN
  8. #include <io.h>
  9. #include "EventCode.h"
  10. #else
  11. #include <unistd.h>
  12. #include <dirent.h>
  13. #include <errno.h>
  14. #include "EventCode.h"
  15. #endif
  16. #include "json/json.h"
  17. namespace Task
  18. {
  19. //查询灰度控制
  20. struct QueryUpgradeControlTaskReq : CHTTPReq {
  21. string m_reqStr;
  22. string ToJson() {
  23. return m_reqStr;
  24. }
  25. };
  26. struct QueryUpgradeControlTaskRet : CHTTPRet {
  27. string m_retStr;
  28. bool Parse(string strData) {
  29. m_retStr = strData;
  30. return true;
  31. }
  32. };
  33. struct InitFSMTask : public ITaskSp {
  34. CUpgradeMgrEntity* Mgr;
  35. explicit InitFSMTask(CUpgradeMgrEntity* e) : Mgr(e) {}
  36. void Process() {
  37. LOG_FUNCTION();
  38. Mgr->bNewUpgradeMgr = true;//默认新模式
  39. CSystemStaticInfo info;
  40. ErrorCodeEnum Err = Mgr->GetFunction()->GetSystemStaticInfo(info);
  41. if (Err != Error_Succeed) {
  42. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("InitFSMTask")("load GetSystemStaticInfo fail ");
  43. LogWarn(Severity_Low, Error_Exception, WARN_TASK_START_NEW_MODE, "init new upgradeTaskMgr");
  44. }
  45. else {
  46. CSimpleStringA msgStr = CSimpleStringA::Format("init new upgradeTaskMgr, version = %s , dep = %s ", info.InstallVersion.ToString().GetData(), info.CurrDepVersion.GetData());
  47. LogWarn(Severity_Low, Error_Exception, WARN_TASK_START_NEW_MODE, msgStr.GetData());
  48. }
  49. if (Mgr->bNewUpgradeMgr) {
  50. ErrorCodeEnum rc = Mgr->m_taskFSM.Init(Mgr);//启动新状态机
  51. if (rc != Error_Succeed)
  52. {
  53. LogWarn(Severity_Middle, Error_Exception, ERR_TASK_INIT_NEW_UPGRADE, "init new upgradeTaskMgr FSM fail");
  54. Mgr->m_testResult = Error_InvalidState;//自检失败
  55. return;
  56. }
  57. else {
  58. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("InitFSMTask")("init new upgradeTaskMgr FSM succ");
  59. Mgr->m_initSucc = true;
  60. }
  61. Mgr->m_beginSM3HashTime = CSmallDateTime::GetNow();
  62. }
  63. else {
  64. LogWarn(Severity_Low, Error_Exception, WARN_TASK_START_OLD_MODE, "init old upgradeTaskMgr");
  65. }
  66. }
  67. };
  68. struct RollBackTask : public ITaskSp {
  69. CUpgradeMgrEntity* Mgr;
  70. CVersion historyVersion;
  71. explicit RollBackTask(CUpgradeMgrEntity* e, CVersion version) : Mgr(e) {
  72. historyVersion = version;
  73. }
  74. void Process() {
  75. bool loop = true;
  76. while (loop) {
  77. //判断是否继续执行
  78. CSmartPointer<IConfigInfo> spConfig;
  79. ErrorCodeEnum ret = Mgr->GetFunction()->OpenConfig(Config_CenterSetting, spConfig);
  80. int rollbackTemp = 0;
  81. if (ret == Error_Succeed) {
  82. spConfig->ReadConfigValueInt("UpgradeManager", "RollbackFlag", rollbackTemp);
  83. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("RollbackUpdate")("get centerSetting RollbackFlag=%d", rollbackTemp);
  84. }
  85. else {
  86. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("RollbackUpdate")("get centerSetting RollbackFlag fail");
  87. }
  88. if (rollbackTemp == 0) {
  89. //立即回退模式
  90. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Immediate mode,begin rollback version");
  91. ErrorCodeEnum rc = Mgr->m_taskFSM.RollBackToHistoryVersion(historyVersion);
  92. if (rc == Error_Succeed)
  93. {
  94. // 通过事件通知健康实体
  95. LogEvent(Severity_Middle, Event_Req_Framework_Rollback, "rollback upgrade succeed");
  96. }
  97. else
  98. {
  99. LogWarn(Severity_Low, rc, ERR_TASK_ROLLBACK_FAIL, "rollback upgrade fail");
  100. }
  101. loop = false;//退出
  102. }
  103. else {
  104. //等待首页回退模式
  105. CSimpleStringA strValue;
  106. if (Mgr->GetFunction()->GetSysVar("UIState", strValue) == Error_Succeed && strValue.Compare("M") == 0) {
  107. // 已经进入首页,开始回退
  108. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("enter main page, begin rollback version");
  109. ErrorCodeEnum rc = Mgr->m_taskFSM.RollBackToHistoryVersion(historyVersion);
  110. if (rc == Error_Succeed)
  111. {
  112. // 通过事件通知健康实体
  113. LogEvent(Severity_Middle, Event_Req_Framework_Rollback, "rollback upgrade succeed");
  114. }
  115. else
  116. {
  117. LogWarn(Severity_Low, rc, ERR_TASK_ROLLBACK_FAIL, "rollback upgrade fail");
  118. }
  119. loop = false;//退出
  120. }
  121. else {
  122. Sleep(30 * 1000);//继续循环
  123. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("enter not main page, rollback version delay 30s");
  124. }
  125. }
  126. }
  127. Mgr->m_taskFSM.m_bRollbackTask = false;//线程退出
  128. }
  129. };
  130. struct RollBackDepTask : public ITaskSp {
  131. CUpgradeMgrEntity* Mgr;
  132. CSimpleStringA historyVersion;
  133. explicit RollBackDepTask(CUpgradeMgrEntity* e, CSimpleStringA depVersion) : Mgr(e) {
  134. historyVersion = depVersion;
  135. }
  136. void Process() {
  137. bool loop = true;
  138. while (loop) {
  139. //判断是否继续执行
  140. CSmartPointer<IConfigInfo> spConfig;
  141. ErrorCodeEnum ret = Mgr->GetFunction()->OpenConfig(Config_CenterSetting, spConfig);
  142. int rollbackTemp = 0;
  143. if (ret == Error_Succeed) {
  144. spConfig->ReadConfigValueInt("UpgradeManager", "RollbackFlag", rollbackTemp);
  145. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("get centerSetting RollbackFlag=%d", rollbackTemp);
  146. }
  147. else {
  148. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("get centerSetting RollbackFlag fail");
  149. }
  150. if (rollbackTemp == 0) {
  151. //立即回退模式
  152. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("Immediate mode,begin rollback dep version");
  153. ErrorCodeEnum rc = Mgr->m_taskFSM.RollBackToHistoryDepVersion(historyVersion);
  154. if (rc == Error_Succeed)
  155. {
  156. // 通过事件通知健康实体
  157. LogEvent(Severity_Middle, Event_DeviceAdapterRollBack_Framework_Restart, "rollback upgrade succeed");
  158. }
  159. else
  160. {
  161. LogWarn(Severity_Low, rc, Event_DeviceAdapterRollBack_Framework_Restart, "rollback upgrade fail");
  162. }
  163. loop = false;//退出
  164. }
  165. else {
  166. //等待首页回退模式
  167. CSimpleStringA strValue;
  168. if (Mgr->GetFunction()->GetSysVar("UIState", strValue) == Error_Succeed && strValue.Compare("M") == 0) {
  169. // 已经进入首页,开始回退
  170. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("enter main page, begin rollback dep version");
  171. ErrorCodeEnum rc = Mgr->m_taskFSM.RollBackToHistoryDepVersion(historyVersion);
  172. if (rc == Error_Succeed)
  173. {
  174. // 通过事件通知健康实体
  175. LogEvent(Severity_Middle, Event_DeviceAdapterRollBack_Framework_Restart, "rollback upgrade succeed");
  176. }
  177. else
  178. {
  179. LogWarn(Severity_Low, rc, Event_DeviceAdapterRollBack_Framework_Restart, "rollback upgrade fail");
  180. }
  181. loop = false;//退出
  182. }
  183. else {
  184. Sleep(30 * 1000);//继续循环
  185. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("enter not main page, rollback dep version delay 30s");
  186. }
  187. }
  188. }
  189. Mgr->m_taskFSM.m_bRollbackTask = false;//线程退出
  190. }
  191. };
  192. }
  193. // 升级管理 UpgradeManager 0x506
  194. void CUpgradeMgrEntity::OnStarted()
  195. {
  196. // 初始化状态机
  197. //m_fsm.Init(this);
  198. auto pFunc = GetFunction();
  199. // 监视准入状态
  200. ErrorCodeEnum rc;
  201. CSimpleStringA strValue;
  202. if (pFunc->GetSysVar("UIState", strValue) == Error_Succeed && strValue.Compare("M") ==0)
  203. {
  204. // 已经进入首页状态
  205. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("system page isStartup 1");
  206. m_bStartUp =true;
  207. }
  208. else
  209. {
  210. // 否则启动监控
  211. rc= pFunc->RegistSysVarEvent("UIState", this);
  212. if (rc != Error_Succeed)
  213. {
  214. LogWarn(Severity_Middle, rc, ERR_WRAN_REGIST_SYS_VAR_FAIL, CSimpleStringA::Format("RegistSysVarEvent UIState is fail,%d",(int)rc).GetData());
  215. m_testResult=Error_InvalidState;//自检失败
  216. }else{
  217. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("RegistSysVarEvent UIState succ");
  218. }
  219. }
  220. GetFunction()->SubscribeLog(m_uuidHeartBeat, this, Log_Event, Severity_Middle, Error_IgnoreAll, -1, "HeartBeat", false);
  221. //启动灰度控制判断,看启动什么状态机
  222. Task::InitFSMTask* task = new Task::InitFSMTask(this);
  223. rc = this->GetFunction()->PostThreadPoolTask(task);
  224. if (rc != Error_Succeed)
  225. {
  226. LogWarn(Severity_Middle, rc, ERR_TASK_INIT_NEW_UPGRADE, CSimpleStringA::Format("Post InitFSMTask task to Thread is fail,%d",(int)rc).GetData());
  227. m_testResult=Error_InvalidState;//自检失败
  228. }
  229. }
  230. void CUpgradeMgrEntity::OnSelfTest(EntityTestEnum eTestType,CSmartPointer<ITransactionContext> pTransactionContext)
  231. {
  232. if (Test_ShakeHand == eTestType)
  233. {
  234. //根据不同情况返回握手情况,监控实体根据不同情况杀死实体进程
  235. pTransactionContext->SendAnswer(m_testResult);
  236. }
  237. }
  238. void CUpgradeMgrEntity::OnPreClose(EntityCloseCauseEnum eCloseCause,CSmartPointer<ITransactionContext> pTransactionContext)
  239. {
  240. pTransactionContext->SendAnswer(Error_Succeed);
  241. }
  242. void CUpgradeMgrEntity::OnSysVarEvent(const char *pszKey, const char *pszValue,const char *pszOldValue,const char *pszEntityName)
  243. {
  244. if(strcmp("UIState",pszKey)==0){
  245. if(!m_bStartUp){
  246. if (strcmp(pszValue, "M") ==0){
  247. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("system page isStartup 2");
  248. m_bStartUp = true;
  249. }
  250. }
  251. }
  252. }
  253. void CUpgradeMgrEntity::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)
  254. {
  255. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("user code:%x,from entity:%s", dwUserCode, pszEntityName);
  256. switch (dwUserCode) {
  257. case LOG_EVT_INC_VERSION_ROLLBACK:
  258. {
  259. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("receive heartBeat instruction version to be rollback to %s", pszMessage);
  260. CSimpleStringA rollbackStr = pszMessage;
  261. this->RollbackUpdate(rollbackStr);
  262. }
  263. break;
  264. default:
  265. return;
  266. }
  267. }
  268. char CUpgradeMgrEntity::GetInstallStateVal(const InstallStateEnum enumVal)
  269. {
  270. const struct {
  271. int ch;
  272. InstallStateEnum val;
  273. } tbl[] = {
  274. {'A', Install_Active},
  275. {'I', Install_Pending},
  276. {'S', Install_SetToStart},
  277. {'F', Install_FailRun},
  278. {'R', Install_RollBack},
  279. {'U', Install_Upgraded},
  280. {'C',Install_Cancelled},
  281. {'W',Install_WaitConfirm},
  282. {'D', Install_Installed},
  283. };
  284. int i;
  285. for (i = 0; i < sizeof(tbl)/sizeof(tbl[0]); ++i) {
  286. if (tbl[i].val == enumVal) {
  287. return tbl[i].ch;
  288. }
  289. }
  290. return ' '; // error
  291. }
  292. //新状态机不处理
  293. ErrorCodeEnum CUpgradeMgrEntity::RegistLocalPack(const CSimpleStringA &strPackFile)
  294. {
  295. if(m_initSucc){
  296. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("RegistLocalPack new UpgradeMgr is not deal with");
  297. return Error_NotImpl;
  298. }else{
  299. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("initFSM is not end");
  300. return Error_Pending;//状态机还未启动
  301. }
  302. }
  303. //新状态机不处理
  304. DWORD CUpgradeMgrEntity::RegistManualPack(const CSimpleStringA &strPackFile)
  305. {
  306. if(m_initSucc){
  307. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("RegistManualPack new UpgradeMgr is not deal with");
  308. return UPGRADE_MGR_NOT_IMPLEMENT;
  309. }else{
  310. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("initFSM is not end");
  311. return Error_Pending;//状态机还未启动
  312. }
  313. }
  314. //新状态机不处理
  315. ErrorCodeEnum CUpgradeMgrEntity::CancelUpdate(const CSimpleStringA &strPackFile)
  316. {
  317. if(m_initSucc){
  318. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("CancelUpdate new UpgradeMgr is not deal with");
  319. return Error_NotImpl;
  320. }else{
  321. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("initFSM is not end");
  322. return Error_Pending;//状态机还未启动
  323. }
  324. }
  325. //新状态机处理
  326. ErrorCodeEnum CUpgradeMgrEntity::RollbackUpdate(const CSimpleStringA &strVersion)
  327. {
  328. if(m_initSucc){
  329. if(bNewUpgradeMgr){
  330. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("RollbackUpdate new UpgradeMgr deal with");
  331. if(strVersion.GetLength()==0){
  332. LogWarn(Severity_Low, Error_NotImpl, ERR_TASK_ROLLBACK_FAIL, "version is empty , rollback upgrade fail");
  333. return Error_NotImpl;
  334. }else{
  335. //判定适配器or应用心跳回退
  336. string failReason = "";
  337. CSimpleStringA strErrMsg = "";
  338. ErrorCodeEnum err = this->m_taskFSM.judgeRollbackTaskClass(strVersion, failReason, strErrMsg);
  339. if (err != Error_Succeed) {
  340. LogWarn(Severity_Low, Error_Exception, ERR_TASK_ROLLBACK_FAIL, CSimpleStringA::Format("judgeRollbackTaskClass fail,err=%s", strErrMsg.GetData()).GetData());
  341. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("judgeRollbackTaskClass fail,err=%s", strErrMsg.GetData());
  342. return err;
  343. }
  344. else {
  345. if (!this->m_taskFSM.m_TempDepUpgradeFlag) {
  346. ErrorCodeEnum rc = Error_Succeed;
  347. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("try rollback to version: [%s]", (const char*)strVersion);
  348. int w1, w2, w3, w4;
  349. int ret = sscanf(strVersion, "%d.%d.%d.%d", &w1, &w2, &w3, &w4);
  350. if (ret < 4)
  351. {
  352. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("version [%s] parse fail", (const char*)strVersion);
  353. return Error_Param;
  354. }
  355. else
  356. { //回退放入线程当中
  357. if (!m_taskFSM.m_bRollbackTask) {
  358. Task::RollBackTask* rTask = new Task::RollBackTask(this, CVersion(w1, w2, w3, w4));
  359. ErrorCodeEnum rc = this->GetFunction()->PostThreadPoolTask(rTask);
  360. if (Error_Succeed == rc) {
  361. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("RollbackFlag thread start succ");
  362. m_taskFSM.m_bRollbackTask = true;//启动线程
  363. return Error_Succeed;
  364. }
  365. else {
  366. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("RollbackFlag thread start fail : %d", (int)rc);
  367. return rc;
  368. }
  369. }
  370. else {
  371. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("RollbackFlag thread is exist");
  372. return Error_Succeed;
  373. }
  374. }
  375. }
  376. else {
  377. //回退放入线程当中
  378. if (!m_taskFSM.m_bRollbackTask) {
  379. Task::RollBackDepTask* rTask = new Task::RollBackDepTask(this, strVersion);
  380. ErrorCodeEnum rc = this->GetFunction()->PostThreadPoolTask(rTask);
  381. if (Error_Succeed == rc) {
  382. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("RollbackFlag Dep thread start succ");
  383. m_taskFSM.m_bRollbackTask = true;//启动线程
  384. return Error_Succeed;
  385. }
  386. else {
  387. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("RollbackFlag Dep thread start fail : %d", (int)rc);
  388. return rc;
  389. }
  390. }
  391. else {
  392. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("RollbackFlag Dep thread is exist");
  393. return Error_Succeed;
  394. }
  395. }
  396. }
  397. }
  398. }else{
  399. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("RollbackUpdate old UpgradeMgr deal not with");
  400. return Error_Succeed;
  401. }
  402. }else{
  403. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("initFSM is not end");
  404. return Error_Pending;//状态机还未启动
  405. }
  406. }
  407. //新状态机不处理
  408. DWORD CUpgradeMgrEntity::GetManualPacks(CSimpleStringA &strManualPacks)
  409. {
  410. if(m_initSucc){
  411. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("GetManualPacks new UpgradeMgr is not deal with");
  412. return UPGRADE_MGR_NOT_IMPLEMENT;
  413. }else{
  414. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("initFSM is not end");
  415. return Error_Pending;//状态机还未启动
  416. }
  417. }
  418. CServerSessionBase* CUpgradeMgrEntity::OnNewSession(const char* /*pszRemoteEntityName*/, const char * /*pszParam*/)
  419. {
  420. return new CUpgradeMgrSession(this);
  421. }
  422. //新状态机不处理
  423. ErrorCodeEnum CUpgradeMgrEntity::SwitchUpgrade(const CSimpleStringA &strPack)
  424. {
  425. if(m_initSucc){
  426. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("SwitchUpgrade new UpgradeMgr is not deal with");
  427. return Error_NotImpl;
  428. }else{
  429. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("initFSM is not end");
  430. return Error_Pending;//状态机还未启动
  431. }
  432. }
  433. //新状态机处理
  434. ErrorCodeEnum CUpgradeMgrEntity::GetUpgradeState(bool &bInstalling, CSimpleStringA &strPackFile, CSimpleStringA &strExecID,
  435. char &cInstallState, bool &bSysInstall, bool &bLightPack, CSimpleStringA &strNewVersion)
  436. {
  437. if(m_initSucc){
  438. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("GetUpgradeState new UpgradeMgr deal with");
  439. return m_taskFSM.GetUpgradeState(bInstalling, strPackFile, strExecID, cInstallState, bSysInstall, bLightPack, strNewVersion);
  440. }else{
  441. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("initFSM is not end");
  442. return Error_Pending;//状态机还未启动
  443. }
  444. }
  445. ErrorCodeEnum CUpgradeMgrEntity::testActive()
  446. {
  447. CSimpleStringA rootVerPath;
  448. ErrorCodeEnum rc = this->GetFunction()->GetPath("RootVer",rootVerPath);//获取version根路径
  449. if(rc!=Error_Succeed){
  450. LogWarn(Severity_Middle, Error_Exception, ERR_WRAN_OPEN_ACTIVE_FAIL,"testActive fail , get RootVer path is fai");
  451. return Error_Bug;
  452. }
  453. CSimpleStringA strActiveFile = CSimpleStringA::Format("%s" SPLIT_SLASH_STR "active.txt", rootVerPath.GetData());
  454. FILE* fp = fopen(strActiveFile.GetData(),"rb+");
  455. if(fp==NULL){
  456. #ifdef RVC_OS_WIN
  457. LogWarn(Severity_Middle, Error_Exception, ERR_WRAN_OPEN_ACTIVE_FAIL,CSimpleStringA::Format("open write active.txt fail,please edit active attribute, err=%d",(int)GetLastError()).GetData());
  458. #else
  459. LogWarn(Severity_Middle, Error_Exception, ERR_WRAN_OPEN_ACTIVE_FAIL,CSimpleStringA::Format("open write active.txt fail,please edit active attribute, err=%d",errno).GetData());
  460. #endif
  461. return Error_Unexpect;
  462. }
  463. fclose(fp);
  464. return Error_Succeed;
  465. }
  466. ErrorCodeEnum CUpgradeMgrEntity::NewStopMediaPlay()
  467. {
  468. #ifdef RVC_OS_WIN
  469. // 通知媒体停止播放广告和声音
  470. LocalMediaPlay::PlayService_ClientBase *pClient = new LocalMediaPlay::PlayService_ClientBase(this);
  471. ErrorCodeEnum rc = pClient->Connect();
  472. if (rc == Error_Succeed)
  473. {
  474. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("connect to entity [LocalMediaPlay] succeed, start StopMediaPlay now");
  475. //采用新接口停止所有音视频播放
  476. LocalMediaPlay::PlayService_StopPlayAllMedias_Req req1 = {};
  477. LocalMediaPlay::PlayService_StopPlayAllMedias_Ans ans1 = {};
  478. if (Error_Succeed == (*pClient)(EntityResource::getLink().upgradeLink())->StopPlayAllMedias(req1, ans1, 10000))
  479. {
  480. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("StopPlayAllMedias success");
  481. }else{
  482. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("StopPlayAllMedias fail");
  483. pClient->GetFunction()->CloseSession();
  484. pClient->SafeDelete();
  485. return rc;
  486. }
  487. pClient->GetFunction()->CloseSession();
  488. }
  489. else
  490. {
  491. LogWarn(Severity_Low, rc, ERR_TASK_STOP_MEDIA_FAIL, "connect to entity [LocalMediaPlay] fail");
  492. }
  493. pClient->SafeDelete();
  494. return rc;
  495. #else
  496. // 通知媒体停止播放广告和声音
  497. LocalMediaPlay::PlayService_ClientBase *pClient = new LocalMediaPlay::PlayService_ClientBase(this);
  498. ErrorCodeEnum rc = pClient->Connect();
  499. if (rc == Error_Succeed)
  500. {
  501. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("connect to entity [LocalMediaPlay] succeed, start StopMediaPlay now");
  502. LocalMediaPlay::PlayService_StopPlayVideo_Req req1 = {};
  503. LocalMediaPlay::PlayService_StopPlayVideo_Ans ans1 = {};
  504. req1.CfgInx = 1;
  505. rc = (*pClient)(EntityResource::getLink().upgradeLink())->StopPlayVideo(req1, ans1, 10000);
  506. if (Error_Succeed == rc)
  507. {
  508. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("StopPlayVideo success");
  509. }else{
  510. Dbg("StopPlayVideo fail");
  511. pClient->GetFunction()->CloseSession();
  512. pClient->SafeDelete();
  513. return rc;
  514. }
  515. LocalMediaPlay::PlayService_StopPlayAudio_Req req2 = {};
  516. LocalMediaPlay::PlayService_StopPlayAudio_Ans ans2 = {};
  517. rc = (*pClient)(EntityResource::getLink().upgradeLink())->StopPlayAudio(req2, ans2, 10000);
  518. if (Error_Succeed == rc)
  519. {
  520. Dbg("StopPlayAudio success");
  521. }else{
  522. Dbg("StopPlayAudio fail");
  523. pClient->GetFunction()->CloseSession();
  524. pClient->SafeDelete();
  525. return rc;
  526. }
  527. pClient->GetFunction()->CloseSession();
  528. }
  529. else
  530. {
  531. LogWarn(Severity_Low, rc, ERR_TASK_STOP_MEDIA_FAIL, "connect to entity [LocalMediaPlay] fail");
  532. pClient->SafeDelete();
  533. }
  534. return rc;
  535. #endif
  536. }
  537. SP_BEGIN_ENTITY_MAP()
  538. SP_ENTITY(CUpgradeMgrEntity)
  539. SP_END_ENTITY_MAP()
  540. void CUpgradeMgrEntity::HttpsLogCallBack(const char* logtxt)
  541. {
  542. if(logtxt!=NULL){
  543. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("http dbg: %s",logtxt);
  544. }
  545. }