mod_UpgradeMgr.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622
  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. if (pFunc->GetSysVar("RunState", strValue) == Error_Succeed && strValue.Compare("N") ==0)
  221. {
  222. // 已经进入终端启动成功状态
  223. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("====framework is start up 1====");
  224. m_bSystemStartUp =true;
  225. }
  226. else
  227. {
  228. // 否则启动监控RunState
  229. rc= pFunc->RegistSysVarEvent("RunState", this);
  230. if (rc != Error_Succeed)
  231. {
  232. LogWarn(Severity_Middle, rc, ERR_WRAN_REGIST_SYS_VAR_FAIL, CSimpleStringA::Format("RegistSysVarEvent RunState is fail,%d",(int)rc).GetData());
  233. m_testResult=Error_InvalidState;//自检失败
  234. }else{
  235. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("RegistSysVarEvent RunState succ");
  236. }
  237. }
  238. GetFunction()->SubscribeLog(m_uuidHeartBeat, this, Log_Event, Severity_Middle, Error_IgnoreAll, -1, "HeartBeat", false);
  239. //启动灰度控制判断,看启动什么状态机
  240. Task::InitFSMTask* task = new Task::InitFSMTask(this);
  241. rc = this->GetFunction()->PostThreadPoolTask(task);
  242. if (rc != Error_Succeed)
  243. {
  244. LogWarn(Severity_Middle, rc, ERR_TASK_INIT_NEW_UPGRADE, CSimpleStringA::Format("Post InitFSMTask task to Thread is fail,%d",(int)rc).GetData());
  245. m_testResult=Error_InvalidState;//自检失败
  246. }
  247. }
  248. void CUpgradeMgrEntity::OnSelfTest(EntityTestEnum eTestType,CSmartPointer<ITransactionContext> pTransactionContext)
  249. {
  250. if (Test_ShakeHand == eTestType)
  251. {
  252. //根据不同情况返回握手情况,监控实体根据不同情况杀死实体进程
  253. pTransactionContext->SendAnswer(m_testResult);
  254. }
  255. }
  256. void CUpgradeMgrEntity::OnPreClose(EntityCloseCauseEnum eCloseCause,CSmartPointer<ITransactionContext> pTransactionContext)
  257. {
  258. pTransactionContext->SendAnswer(Error_Succeed);
  259. }
  260. void CUpgradeMgrEntity::OnSysVarEvent(const char *pszKey, const char *pszValue,const char *pszOldValue,const char *pszEntityName)
  261. {
  262. if(strcmp("UIState",pszKey)==0){
  263. if(!m_bStartUp){
  264. if (strcmp(pszValue, "M") ==0){
  265. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("system page isStartup 2");
  266. m_bStartUp = true;
  267. }
  268. }
  269. }
  270. if(strcmp("RunState",pszKey)==0){
  271. if(!m_bSystemStartUp){
  272. if (strcmp(pszValue, "N") ==0){
  273. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("====framework is start up 2====");
  274. m_bSystemStartUp = true;
  275. }
  276. }
  277. }
  278. }
  279. 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)
  280. {
  281. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("user code:%x,from entity:%s", dwUserCode, pszEntityName);
  282. switch (dwUserCode) {
  283. case LOG_EVT_INC_VERSION_ROLLBACK:
  284. {
  285. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("receive heartBeat instruction version to be rollback to %s", pszMessage);
  286. CSimpleStringA rollbackStr = pszMessage;
  287. this->RollbackUpdate(rollbackStr);
  288. }
  289. break;
  290. default:
  291. return;
  292. }
  293. }
  294. char CUpgradeMgrEntity::GetInstallStateVal(const InstallStateEnum enumVal)
  295. {
  296. const struct {
  297. int ch;
  298. InstallStateEnum val;
  299. } tbl[] = {
  300. {'A', Install_Active},
  301. {'I', Install_Pending},
  302. {'S', Install_SetToStart},
  303. {'F', Install_FailRun},
  304. {'R', Install_RollBack},
  305. {'U', Install_Upgraded},
  306. {'C',Install_Cancelled},
  307. {'W',Install_WaitConfirm},
  308. {'D', Install_Installed},
  309. };
  310. int i;
  311. for (i = 0; i < sizeof(tbl)/sizeof(tbl[0]); ++i) {
  312. if (tbl[i].val == enumVal) {
  313. return tbl[i].ch;
  314. }
  315. }
  316. return ' '; // error
  317. }
  318. //新状态机不处理
  319. ErrorCodeEnum CUpgradeMgrEntity::RegistLocalPack(const CSimpleStringA &strPackFile)
  320. {
  321. if(m_initSucc){
  322. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("RegistLocalPack new UpgradeMgr is not deal with");
  323. return Error_NotImpl;
  324. }else{
  325. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("initFSM is not end");
  326. return Error_Pending;//状态机还未启动
  327. }
  328. }
  329. //新状态机不处理
  330. DWORD CUpgradeMgrEntity::RegistManualPack(const CSimpleStringA &strPackFile)
  331. {
  332. if(m_initSucc){
  333. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("RegistManualPack new UpgradeMgr is not deal with");
  334. return UPGRADE_MGR_NOT_IMPLEMENT;
  335. }else{
  336. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("initFSM is not end");
  337. return Error_Pending;//状态机还未启动
  338. }
  339. }
  340. //新状态机不处理
  341. ErrorCodeEnum CUpgradeMgrEntity::CancelUpdate(const CSimpleStringA &strPackFile)
  342. {
  343. if(m_initSucc){
  344. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("CancelUpdate new UpgradeMgr is not deal with");
  345. return Error_NotImpl;
  346. }else{
  347. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("initFSM is not end");
  348. return Error_Pending;//状态机还未启动
  349. }
  350. }
  351. //新状态机处理
  352. ErrorCodeEnum CUpgradeMgrEntity::RollbackUpdate(const CSimpleStringA &strVersion)
  353. {
  354. if(m_initSucc){
  355. if(bNewUpgradeMgr){
  356. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("RollbackUpdate new UpgradeMgr deal with");
  357. if(strVersion.GetLength()==0){
  358. LogWarn(Severity_Low, Error_NotImpl, ERR_TASK_ROLLBACK_FAIL, "version is empty , rollback upgrade fail");
  359. return Error_NotImpl;
  360. }else{
  361. //判定适配器or应用心跳回退
  362. string failReason = "";
  363. CSimpleStringA strErrMsg = "";
  364. ErrorCodeEnum err = this->m_taskFSM.judgeRollbackTaskClass(strVersion, failReason, strErrMsg);
  365. if (err != Error_Succeed) {
  366. LogWarn(Severity_Low, Error_Exception, ERR_TASK_ROLLBACK_FAIL, CSimpleStringA::Format("judgeRollbackTaskClass fail,err=%s", strErrMsg.GetData()).GetData());
  367. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("judgeRollbackTaskClass fail,err=%s", strErrMsg.GetData());
  368. return err;
  369. }
  370. else {
  371. if (!this->m_taskFSM.m_TempDepUpgradeFlag) {
  372. ErrorCodeEnum rc = Error_Succeed;
  373. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("try rollback to version: [%s]", (const char*)strVersion);
  374. int w1, w2, w3, w4;
  375. int ret = sscanf(strVersion, "%d.%d.%d.%d", &w1, &w2, &w3, &w4);
  376. if (ret < 4)
  377. {
  378. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("version [%s] parse fail", (const char*)strVersion);
  379. return Error_Param;
  380. }
  381. else
  382. { //回退放入线程当中
  383. if (!m_taskFSM.m_bRollbackTask) {
  384. Task::RollBackTask* rTask = new Task::RollBackTask(this, CVersion(w1, w2, w3, w4));
  385. ErrorCodeEnum rc = this->GetFunction()->PostThreadPoolTask(rTask);
  386. if (Error_Succeed == rc) {
  387. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("RollbackFlag thread start succ");
  388. m_taskFSM.m_bRollbackTask = true;//启动线程
  389. return Error_Succeed;
  390. }
  391. else {
  392. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("RollbackFlag thread start fail : %d", (int)rc);
  393. return rc;
  394. }
  395. }
  396. else {
  397. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("RollbackFlag thread is exist");
  398. return Error_Succeed;
  399. }
  400. }
  401. }
  402. else {
  403. //回退放入线程当中
  404. if (!m_taskFSM.m_bRollbackTask) {
  405. Task::RollBackDepTask* rTask = new Task::RollBackDepTask(this, strVersion);
  406. ErrorCodeEnum rc = this->GetFunction()->PostThreadPoolTask(rTask);
  407. if (Error_Succeed == rc) {
  408. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("RollbackFlag Dep thread start succ");
  409. m_taskFSM.m_bRollbackTask = true;//启动线程
  410. return Error_Succeed;
  411. }
  412. else {
  413. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("RollbackFlag Dep thread start fail : %d", (int)rc);
  414. return rc;
  415. }
  416. }
  417. else {
  418. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("RollbackFlag Dep thread is exist");
  419. return Error_Succeed;
  420. }
  421. }
  422. }
  423. }
  424. }else{
  425. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("RollbackUpdate old UpgradeMgr deal not with");
  426. return Error_Succeed;
  427. }
  428. }else{
  429. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("initFSM is not end");
  430. return Error_Pending;//状态机还未启动
  431. }
  432. }
  433. //新状态机不处理
  434. DWORD CUpgradeMgrEntity::GetManualPacks(CSimpleStringA &strManualPacks)
  435. {
  436. if(m_initSucc){
  437. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("GetManualPacks new UpgradeMgr is not deal with");
  438. return UPGRADE_MGR_NOT_IMPLEMENT;
  439. }else{
  440. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("initFSM is not end");
  441. return Error_Pending;//状态机还未启动
  442. }
  443. }
  444. CServerSessionBase* CUpgradeMgrEntity::OnNewSession(const char* /*pszRemoteEntityName*/, const char * /*pszParam*/)
  445. {
  446. return new CUpgradeMgrSession(this);
  447. }
  448. //新状态机不处理
  449. ErrorCodeEnum CUpgradeMgrEntity::SwitchUpgrade(const CSimpleStringA &strPack)
  450. {
  451. if(m_initSucc){
  452. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("SwitchUpgrade new UpgradeMgr is not deal with");
  453. return Error_NotImpl;
  454. }else{
  455. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("initFSM is not end");
  456. return Error_Pending;//状态机还未启动
  457. }
  458. }
  459. //新状态机处理
  460. ErrorCodeEnum CUpgradeMgrEntity::GetUpgradeState(bool &bInstalling, CSimpleStringA &strPackFile, CSimpleStringA &strExecID,
  461. char &cInstallState, bool &bSysInstall, bool &bLightPack, CSimpleStringA &strNewVersion)
  462. {
  463. if(m_initSucc){
  464. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("GetUpgradeState new UpgradeMgr deal with");
  465. return m_taskFSM.GetUpgradeState(bInstalling, strPackFile, strExecID, cInstallState, bSysInstall, bLightPack, strNewVersion);
  466. }else{
  467. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("initFSM is not end");
  468. return Error_Pending;//状态机还未启动
  469. }
  470. }
  471. ErrorCodeEnum CUpgradeMgrEntity::testActive()
  472. {
  473. CSimpleStringA rootVerPath;
  474. ErrorCodeEnum rc = this->GetFunction()->GetPath("RootVer",rootVerPath);//获取version根路径
  475. if(rc!=Error_Succeed){
  476. LogWarn(Severity_Middle, Error_Exception, ERR_WRAN_OPEN_ACTIVE_FAIL,"testActive fail , get RootVer path is fai");
  477. return Error_Bug;
  478. }
  479. CSimpleStringA strActiveFile = CSimpleStringA::Format("%s" SPLIT_SLASH_STR "active.txt", rootVerPath.GetData());
  480. FILE* fp = fopen(strActiveFile.GetData(),"rb+");
  481. if(fp==NULL){
  482. #ifdef RVC_OS_WIN
  483. 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());
  484. #else
  485. 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());
  486. #endif
  487. return Error_Unexpect;
  488. }
  489. fclose(fp);
  490. return Error_Succeed;
  491. }
  492. ErrorCodeEnum CUpgradeMgrEntity::NewStopMediaPlay()
  493. {
  494. #ifdef RVC_OS_WIN
  495. // 通知媒体停止播放广告和声音
  496. LocalMediaPlay::PlayService_ClientBase *pClient = new LocalMediaPlay::PlayService_ClientBase(this);
  497. ErrorCodeEnum rc = pClient->Connect();
  498. if (rc == Error_Succeed)
  499. {
  500. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("connect to entity [LocalMediaPlay] succeed, start StopMediaPlay now");
  501. //采用新接口停止所有音视频播放
  502. LocalMediaPlay::PlayService_StopPlayAllMedias_Req req1 = {};
  503. LocalMediaPlay::PlayService_StopPlayAllMedias_Ans ans1 = {};
  504. if (Error_Succeed == (*pClient)(EntityResource::getLink().upgradeLink())->StopPlayAllMedias(req1, ans1, 10000))
  505. {
  506. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("StopPlayAllMedias success");
  507. }else{
  508. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("StopPlayAllMedias fail");
  509. pClient->GetFunction()->CloseSession();
  510. pClient->SafeDelete();
  511. return rc;
  512. }
  513. pClient->GetFunction()->CloseSession();
  514. }
  515. else
  516. {
  517. LogWarn(Severity_Low, rc, ERR_TASK_STOP_MEDIA_FAIL, "connect to entity [LocalMediaPlay] fail");
  518. }
  519. pClient->SafeDelete();
  520. return rc;
  521. #else
  522. // 通知媒体停止播放广告和声音
  523. LocalMediaPlay::PlayService_ClientBase *pClient = new LocalMediaPlay::PlayService_ClientBase(this);
  524. ErrorCodeEnum rc = pClient->Connect();
  525. if (rc == Error_Succeed)
  526. {
  527. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("connect to entity [LocalMediaPlay] succeed, start StopMediaPlay now");
  528. LocalMediaPlay::PlayService_StopPlayVideo_Req req1 = {};
  529. LocalMediaPlay::PlayService_StopPlayVideo_Ans ans1 = {};
  530. req1.CfgInx = 1;
  531. rc = (*pClient)(EntityResource::getLink().upgradeLink())->StopPlayVideo(req1, ans1, 10000);
  532. if (Error_Succeed == rc)
  533. {
  534. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("StopPlayVideo success");
  535. }else{
  536. Dbg("StopPlayVideo fail");
  537. pClient->GetFunction()->CloseSession();
  538. pClient->SafeDelete();
  539. return rc;
  540. }
  541. LocalMediaPlay::PlayService_StopPlayAudio_Req req2 = {};
  542. LocalMediaPlay::PlayService_StopPlayAudio_Ans ans2 = {};
  543. rc = (*pClient)(EntityResource::getLink().upgradeLink())->StopPlayAudio(req2, ans2, 10000);
  544. if (Error_Succeed == rc)
  545. {
  546. Dbg("StopPlayAudio success");
  547. }else{
  548. Dbg("StopPlayAudio fail");
  549. pClient->GetFunction()->CloseSession();
  550. pClient->SafeDelete();
  551. return rc;
  552. }
  553. pClient->GetFunction()->CloseSession();
  554. }
  555. else
  556. {
  557. LogWarn(Severity_Low, rc, ERR_TASK_STOP_MEDIA_FAIL, "connect to entity [LocalMediaPlay] fail");
  558. pClient->SafeDelete();
  559. }
  560. return rc;
  561. #endif
  562. }
  563. SP_BEGIN_ENTITY_MAP()
  564. SP_ENTITY(CUpgradeMgrEntity)
  565. SP_END_ENTITY_MAP()
  566. void CUpgradeMgrEntity::HttpsLogCallBack(const char* logtxt)
  567. {
  568. if(logtxt!=NULL){
  569. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("http dbg: %s",logtxt);
  570. }
  571. }