mod_UpgradeRun.cpp 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. #include "stdafx.h"
  2. #include "mod_UpgradeRun.h"
  3. #include "SpHelper.h"
  4. #include "PinPad_client_g.h"
  5. #include "DeviceBaseClass.h"
  6. #ifdef RVC_OS_WIN
  7. #include "WMIDeviceQuery.h"
  8. #endif // RVC_OS_WIN
  9. using namespace PinPad;
  10. CServerSessionBase *CUpgradeRunEntity::OnNewSession(const char* /*pszRemoteEntityName*/, const char * /*pszParam*/)
  11. {
  12. return new CUpgradeRunSession(this);
  13. }
  14. void CUpgradeRunEntity::OnStarted()
  15. {
  16. m_FSM.Init(this);
  17. // 由于客户感知不准,会导致升级长时间暂停 @20151202
  18. //auto pFunc = GetFunction();
  19. //assert(pFunc != NULL);
  20. //auto rc = pFunc->RegistSysVarEvent("CustomerHandle", this);
  21. //assert(rc == Error_Succeed);
  22. //rc = pFunc->RegistSysVarEvent("RunState", this);
  23. //assert(rc == Error_Succeed);
  24. //CSimpleStringA strCustomerHandle;
  25. //CSimpleStringA strRunState;
  26. //rc = pFunc->GetSysVar("CustomerHandle", strCustomerHandle);
  27. //assert(rc == Error_Succeed);
  28. //rc = pFunc->GetSysVar("RunState", strRunState);
  29. //assert(rc == Error_Succeed);
  30. //if ((strCustomerHandle[0] == 'N' || strCustomerHandle[0] == 'A') && strRunState[0] == 'O')
  31. m_FSM.PostEventFIFO(new FSMEvent(CUpgradeRunFSM::Event_EnableUpgrade));
  32. }
  33. void CUpgradeRunEntity::OnPreClose(EntityCloseCauseEnum eCloseCause,CSmartPointer<ITransactionContext> pTransactionContext)
  34. {
  35. //auto pFunc = GetFunction();
  36. //assert(pFunc != NULL);
  37. //pFunc->UnregistSysVarEvent("CustomerHandle");
  38. //pFunc->UnregistSysVarEvent("RunState");
  39. pTransactionContext->SendAnswer(Error_Succeed);
  40. }
  41. void CUpgradeRunEntity::OnSysVarEvent(const char *pszKey, const char *pszValue,const char *pszOldValue,const char *pszEntityName)
  42. {
  43. //if (strcmp(pszKey, "CustomerHandle") == 0)
  44. //{
  45. // if (*pszValue == 'N' || *pszValue == 'A') // 没有交互
  46. // {
  47. // CSimpleStringA strRunState;
  48. // auto rc = GetFunction()->GetSysVar("RunState", strRunState);
  49. // assert(rc == Error_Succeed);
  50. // if (strRunState[0] == 'O')
  51. // {
  52. // // 继续升级
  53. // m_FSM.PostEventFIFO(new FSMEvent(CUpgradeRunFSM::Event_EnableUpgrade));
  54. // return;
  55. // }
  56. // }
  57. //
  58. // // 暂停升级
  59. // m_FSM.PostEventFIFO(new FSMEvent(CUpgradeRunFSM::Event_DisableUpgrade));
  60. //}
  61. //else if (strcmp(pszKey, "RunState") ==0)
  62. //{
  63. // if (*pszValue == 'O') // 正常工作
  64. // {
  65. // CSimpleStringA strCustomerHandle;
  66. // auto rc = GetFunction()->GetSysVar("CustomerHandle", strCustomerHandle);
  67. // assert(rc == Error_Succeed);
  68. // if (strCustomerHandle[0] == 'N' || strCustomerHandle[0] == 'A')
  69. // {
  70. // // 继续升级
  71. // m_FSM.PostEventFIFO(new FSMEvent(CUpgradeRunFSM::Event_EnableUpgrade));
  72. // return;
  73. // }
  74. // }
  75. // // 暂停升级
  76. // m_FSM.PostEventFIFO(new FSMEvent(CUpgradeRunFSM::Event_DisableUpgrade));
  77. //}
  78. }
  79. ErrorCodeEnum CUpgradeRunEntity::PushUpdateTask(const CSimpleStringA &strPackName, const int nPackType)
  80. {
  81. LOG_TRACE("PushUpdateTask: [%s], [%d]", (const char*)strPackName, nPackType);
  82. m_FSM.PostEventFIFO(new CUpgradeRunFSM::StartUpgradeEvent(strPackName, nPackType));
  83. return Error_Succeed;
  84. }
  85. ErrorCodeEnum CUpgradeRunEntity::GetRunState(CSimpleStringA &strPackName, char &cState)
  86. {
  87. return m_FSM.GetRunState(strPackName, cState);
  88. }
  89. ErrorCodeEnum CUpgradeRunEntity::UpdateTaskCancel(const CSimpleStringA &strPackName)
  90. {
  91. LOG_TRACE("UpdateTaskCancel: [%s]", (const char*)strPackName);
  92. m_FSM.PostEventFIFO(new CUpgradeRunFSM::CancelUpgradeEvent(strPackName));
  93. return Error_Succeed;
  94. }
  95. ErrorCodeEnum CUpgradeRunEntity::BroadcastUpgradeCheckEvent(UpgradeCheckEvent &e)
  96. {
  97. return SpSendBroadcast(GetFunction(), eMsg_UpgradeCheckEvent, eMsgSig_UpgradeCheckEvent, e);
  98. }
  99. ErrorCodeEnum CUpgradeRunEntity::BroadcastUpgradeDoneEvent(UpgradeDoneEvent &e)
  100. {
  101. return SpSendBroadcast(GetFunction(), eMsg_UpgradeDoneEvent, eMsgSig_UpgradeDoneEvent, e);
  102. }
  103. //获取系统补丁升级结果(windows特有方法)
  104. bool CUpgradeRunEntity::GetServerPackUpgradeResult(const char *pszPackageName, CSimpleStringA &strVerison, CSimpleStringA &strErrMsg)
  105. {
  106. #ifdef RVC_OS_WIN
  107. char szTmp[4096] = {};
  108. int nTmpBufLen = 4096;//win7补丁可能有200多个,每个补丁(如KB3105211加分隔符;)需要10个字节
  109. if (!QueryWMIDevice(PatchList, "HotFixID", szTmp, &nTmpBufLen))
  110. {
  111. Dbg("query sys patch list fail");
  112. return false;
  113. }
  114. CSimpleStringA strPatchList = szTmp;
  115. CSimpleStringA strPatchName = m_FSM.GetSysPatchNameFromPackName(pszPackageName);
  116. if (strPatchName.IsNullOrEmpty())
  117. {
  118. return false;
  119. }
  120. if (strPatchList.IndexOf(strPatchName.GetData()) < 0 )
  121. {
  122. Dbg("can not find PatchName[%s] from PatchList[%s]", strPatchName, strPatchList);
  123. return false;
  124. }
  125. Dbg("find PatchName[%s] from PatchList[%s]", strPatchName, strPatchList);
  126. strVerison = strPatchName;
  127. return true;
  128. #else
  129. return true;
  130. #endif // RVC_OS_WIN
  131. }
  132. //获取固件升级结果
  133. bool CUpgradeRunEntity::GetFirmwarePackUpgradeResult(const char *pszPackageName, CSimpleStringA &strVerison, CSimpleStringA &strErrMsg)
  134. {
  135. // 根据PinPad实体状态确定是否连接密码键盘
  136. bool bUpdate = false;
  137. strVerison = "";
  138. auto pPinPadClient = new PinPadService_ClientBase(this);
  139. if (pPinPadClient->Connect() != Error_Succeed)
  140. {
  141. Dbg("connect PinPad fail, assume no pinpad");
  142. strErrMsg = "connect PinPad fail, assume no pinpad";
  143. }
  144. else
  145. {
  146. PinPadService_GetDevInfo_Req req = {};
  147. PinPadService_GetDevInfo_Ans ans = {};
  148. auto rc = pPinPadClient->GetDevInfo(req, ans, 3000);
  149. if (rc == Error_Succeed)
  150. {
  151. if (ans.state == DEVICE_STATUS_NORMAL)
  152. {
  153. Dbg("pinpad model: %s", (const char*)ans.model);
  154. // CM = V2.0#PM = V1.0#MID = 75500001#PID = 12345678#FWID = V1234567#Vendor = nantian
  155. // 密码键盘ID,PID,8到16字节; 设备ID,MID,8到16字节; 固件版本号,FWID,8字节
  156. CSimpleStringA str = ans.model;
  157. CSimpleStringA strFWID;
  158. if (!str.IsNullOrEmpty())
  159. {
  160. auto arr = str.Split('#');
  161. if (arr.GetCount() > 0)
  162. {
  163. for (int i = 0; i < arr.GetCount(); i++)
  164. {
  165. auto arr2 = arr[i].Split('=');
  166. if (arr2.GetCount() != 2)
  167. continue;
  168. if(!strnicmp((LPCTSTR)arr2[0], "FWID", strlen("FWID")))
  169. {
  170. strFWID = arr2[1];
  171. if (!strFWID.IsNullOrEmpty())
  172. {
  173. CSimpleStringA strPackName = pszPackageName;
  174. if (strPackName.IndexOf(strFWID.GetData()) > 0)
  175. {
  176. Dbg("find FWID[%] from strPackName[%s]", strFWID, strPackName);
  177. strVerison = strFWID;
  178. bUpdate = true;
  179. }
  180. else
  181. {
  182. Dbg("can not find FWID[%] from strPackName[%s]", strFWID, strPackName);
  183. strErrMsg = "can not find FWID from PackName";
  184. bUpdate = false;
  185. }
  186. }
  187. break;
  188. }
  189. }
  190. }
  191. }
  192. }
  193. else
  194. {
  195. Dbg("pinpad not exist, state: %d", ans.state);
  196. strErrMsg = "pinpad not exist";
  197. }
  198. }
  199. else
  200. {
  201. Dbg("PinPad::GetDevInfo() fail: 0x%X", rc);
  202. strErrMsg = "PinPad::GetDevInfo() fail";
  203. }
  204. pPinPadClient->GetFunction()->CloseSession();
  205. }
  206. pPinPadClient->SafeDelete();
  207. pPinPadClient = NULL;
  208. return bUpdate;
  209. }
  210. SP_BEGIN_ENTITY_MAP()
  211. SP_ENTITY(CUpgradeRunEntity)
  212. SP_END_ENTITY_MAP()