mod_UpgradeMgr.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535
  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_DEBUG, 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_DEBUG, 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,use default value 0");
  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_DEBUG, 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_DEBUG,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_DEBUG,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_DEBUG,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::RollbackUpdate(const CSimpleStringA &strVersion)
  294. {
  295. if(m_initSucc){
  296. if(bNewUpgradeMgr){
  297. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("RollbackUpdate new UpgradeMgr deal with");
  298. if(strVersion.GetLength()==0){
  299. LogWarn(Severity_Low, Error_NotImpl, ERR_TASK_ROLLBACK_FAIL, "version is empty , rollback upgrade fail");
  300. return Error_NotImpl;
  301. }else{
  302. //判定适配器or应用心跳回退
  303. string failReason = "";
  304. CSimpleStringA strErrMsg = "";
  305. ErrorCodeEnum err = this->m_taskFSM.judgeRollbackTaskClass(strVersion, failReason, strErrMsg);
  306. if (err != Error_Succeed) {
  307. LogWarn(Severity_Low, Error_Exception, ERR_TASK_ROLLBACK_FAIL, CSimpleStringA::Format("judgeRollbackTaskClass fail,err=%s", strErrMsg.GetData()).GetData());
  308. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("judgeRollbackTaskClass fail,err=%s", strErrMsg.GetData());
  309. return err;
  310. }
  311. else {
  312. if (!this->m_taskFSM.m_TempDepUpgradeFlag) {
  313. ErrorCodeEnum rc = Error_Succeed;
  314. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("try rollback to version: [%s]", (const char*)strVersion);
  315. int w1, w2, w3, w4;
  316. int ret = sscanf(strVersion, "%d.%d.%d.%d", &w1, &w2, &w3, &w4);
  317. if (ret < 4)
  318. {
  319. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("version [%s] parse fail", (const char*)strVersion);
  320. return Error_Param;
  321. }
  322. else
  323. { //回退放入线程当中
  324. if (!m_taskFSM.m_bRollbackTask) {
  325. Task::RollBackTask* rTask = new Task::RollBackTask(this, CVersion(w1, w2, w3, w4));
  326. ErrorCodeEnum rc = this->GetFunction()->PostThreadPoolTask(rTask);
  327. if (Error_Succeed == rc) {
  328. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("RollbackFlag thread start succ");
  329. m_taskFSM.m_bRollbackTask = true;//启动线程
  330. return Error_Succeed;
  331. }
  332. else {
  333. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("RollbackFlag thread start fail : %d", (int)rc);
  334. return rc;
  335. }
  336. }
  337. else {
  338. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("RollbackFlag thread is exist");
  339. return Error_Succeed;
  340. }
  341. }
  342. }
  343. else {
  344. //回退放入线程当中
  345. if (!m_taskFSM.m_bRollbackTask) {
  346. Task::RollBackDepTask* rTask = new Task::RollBackDepTask(this, strVersion);
  347. ErrorCodeEnum rc = this->GetFunction()->PostThreadPoolTask(rTask);
  348. if (Error_Succeed == rc) {
  349. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("RollbackFlag Dep thread start succ");
  350. m_taskFSM.m_bRollbackTask = true;//启动线程
  351. return Error_Succeed;
  352. }
  353. else {
  354. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("RollbackFlag Dep thread start fail : %d", (int)rc);
  355. return rc;
  356. }
  357. }
  358. else {
  359. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("RollbackFlag Dep thread is exist");
  360. return Error_Succeed;
  361. }
  362. }
  363. }
  364. }
  365. }else{
  366. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("RollbackUpdate old UpgradeMgr deal not with");
  367. return Error_Succeed;
  368. }
  369. }else{
  370. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("initFSM is not end");
  371. return Error_Pending;//状态机还未启动
  372. }
  373. }
  374. CServerSessionBase* CUpgradeMgrEntity::OnNewSession(const char* /*pszRemoteEntityName*/, const char * /*pszParam*/)
  375. {
  376. return new CUpgradeMgrSession(this);
  377. }
  378. //新状态机处理
  379. ErrorCodeEnum CUpgradeMgrEntity::GetUpgradeState(bool &bInstalling, CSimpleStringA &strPackFile, CSimpleStringA &strExecID,
  380. char &cInstallState, bool &bSysInstall, bool &bLightPack, CSimpleStringA &strNewVersion)
  381. {
  382. if(m_initSucc){
  383. DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("GetUpgradeState new UpgradeMgr deal with");
  384. return m_taskFSM.GetUpgradeState(bInstalling, strPackFile, strExecID, cInstallState, bSysInstall, bLightPack, strNewVersion);
  385. }else{
  386. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("initFSM is not end");
  387. return Error_Pending;//状态机还未启动
  388. }
  389. }
  390. ErrorCodeEnum CUpgradeMgrEntity::testActive()
  391. {
  392. CSimpleStringA rootVerPath;
  393. ErrorCodeEnum rc = this->GetFunction()->GetPath("RootVer",rootVerPath);//获取version根路径
  394. if(rc!=Error_Succeed){
  395. LogWarn(Severity_Middle, Error_Exception, ERR_WRAN_OPEN_ACTIVE_FAIL,"testActive fail , get RootVer path is fai");
  396. return Error_Bug;
  397. }
  398. CSimpleStringA strActiveFile = CSimpleStringA::Format("%s" SPLIT_SLASH_STR "active.txt", rootVerPath.GetData());
  399. FILE* fp = fopen(strActiveFile.GetData(),"rb+");
  400. if(fp==NULL){
  401. #ifdef RVC_OS_WIN
  402. 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());
  403. #else
  404. 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());
  405. #endif
  406. return Error_Unexpect;
  407. }
  408. fclose(fp);
  409. return Error_Succeed;
  410. }
  411. ErrorCodeEnum CUpgradeMgrEntity::NewStopMediaPlay()
  412. {
  413. #ifdef RVC_OS_WIN
  414. // 通知媒体停止播放广告和声音
  415. LocalMediaPlay::PlayService_ClientBase *pClient = new LocalMediaPlay::PlayService_ClientBase(this);
  416. ErrorCodeEnum rc = pClient->Connect();
  417. if (rc == Error_Succeed)
  418. {
  419. DbgWithLink(LOG_LEVEL_DEBUG,LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("connect to entity [LocalMediaPlay] succeed, start StopMediaPlay now");
  420. //采用新接口停止所有音视频播放
  421. LocalMediaPlay::PlayService_StopPlayAllMedias_Req req1 = {};
  422. LocalMediaPlay::PlayService_StopPlayAllMedias_Ans ans1 = {};
  423. rc = (*pClient)(EntityResource::getLink().upgradeLink())->StopPlayAllMedias(req1, ans1, 30000);
  424. if (Error_Succeed == rc )
  425. {
  426. DbgWithLink(LOG_LEVEL_DEBUG,LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("StopPlayAllMedias success");
  427. }else{
  428. DbgWithLink(LOG_LEVEL_WARN,LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("StopPlayAllMedias fail, err=%d",(int)rc);
  429. pClient->GetFunction()->CloseSession();
  430. pClient->SafeDelete();
  431. return rc;
  432. }
  433. pClient->GetFunction()->CloseSession();
  434. }
  435. else
  436. {
  437. LogWarn(Severity_Low, rc, ERR_TASK_STOP_MEDIA_FAIL, "connect to entity [LocalMediaPlay] fail");
  438. }
  439. pClient->SafeDelete();
  440. return rc;
  441. #else
  442. // 通知媒体停止播放广告和声音
  443. LocalMediaPlay::PlayService_ClientBase *pClient = new LocalMediaPlay::PlayService_ClientBase(this);
  444. ErrorCodeEnum rc = pClient->Connect();
  445. if (rc == Error_Succeed)
  446. {
  447. DbgWithLink(LOG_LEVEL_DEBUG,LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("connect to entity [LocalMediaPlay] succeed, start StopMediaPlay now");
  448. LocalMediaPlay::PlayService_StopPlayVideo_Req req1 = {};
  449. LocalMediaPlay::PlayService_StopPlayVideo_Ans ans1 = {};
  450. req1.CfgInx = 1;
  451. rc = (*pClient)(EntityResource::getLink().upgradeLink())->StopPlayVideo(req1, ans1, 10000);
  452. if (Error_Succeed == rc)
  453. {
  454. DbgWithLink(LOG_LEVEL_DEBUG,LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("StopPlayVideo success");
  455. }else{
  456. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("StopPlayVideo fail, err=%d", (int)rc);
  457. pClient->GetFunction()->CloseSession();
  458. pClient->SafeDelete();
  459. return rc;
  460. }
  461. LocalMediaPlay::PlayService_StopPlayAudio_Req req2 = {};
  462. LocalMediaPlay::PlayService_StopPlayAudio_Ans ans2 = {};
  463. rc = (*pClient)(EntityResource::getLink().upgradeLink())->StopPlayAudio(req2, ans2, 10000);
  464. if (Error_Succeed == rc)
  465. {
  466. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("StopPlayAudio success");
  467. }else{
  468. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("StopPlayAudio fail, err=%d", (int)rc);
  469. pClient->GetFunction()->CloseSession();
  470. pClient->SafeDelete();
  471. return rc;
  472. }
  473. pClient->GetFunction()->CloseSession();
  474. }
  475. else
  476. {
  477. LogWarn(Severity_Low, rc, ERR_TASK_STOP_MEDIA_FAIL, "connect to entity [LocalMediaPlay] fail");
  478. pClient->SafeDelete();
  479. }
  480. return rc;
  481. #endif
  482. }
  483. SP_BEGIN_ENTITY_MAP()
  484. SP_ENTITY(CUpgradeMgrEntity)
  485. SP_END_ENTITY_MAP()
  486. void CUpgradeMgrEntity::HttpsLogCallBack(const char* logtxt)
  487. {
  488. if(logtxt!=NULL){
  489. DbgWithLink(LOG_LEVEL_INFO,LOG_TYPE_SYSTEM).setAPI(__FUNCTION__)("http dbg: %s",logtxt);
  490. }
  491. }