123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251 |
- #include "stdafx.h"
- #include "mod_UpgradeRun.h"
- #include "SpHelper.h"
- #include "PinPad_client_g.h"
- #include "DeviceBaseClass.h"
- #ifdef RVC_OS_WIN
- #include "WMIDeviceQuery.h"
- #endif // RVC_OS_WIN
- using namespace PinPad;
- CServerSessionBase *CUpgradeRunEntity::OnNewSession(const char* /*pszRemoteEntityName*/, const char * /*pszParam*/)
- {
- return new CUpgradeRunSession(this);
- }
- void CUpgradeRunEntity::OnStarted()
- {
- m_FSM.Init(this);
- // 由于客户感知不准,会导致升级长时间暂停 @20151202
- //auto pFunc = GetFunction();
- //assert(pFunc != NULL);
- //auto rc = pFunc->RegistSysVarEvent("CustomerHandle", this);
- //assert(rc == Error_Succeed);
- //rc = pFunc->RegistSysVarEvent("RunState", this);
- //assert(rc == Error_Succeed);
- //CSimpleStringA strCustomerHandle;
- //CSimpleStringA strRunState;
- //rc = pFunc->GetSysVar("CustomerHandle", strCustomerHandle);
- //assert(rc == Error_Succeed);
- //rc = pFunc->GetSysVar("RunState", strRunState);
- //assert(rc == Error_Succeed);
- //if ((strCustomerHandle[0] == 'N' || strCustomerHandle[0] == 'A') && strRunState[0] == 'O')
- m_FSM.PostEventFIFO(new FSMEvent(CUpgradeRunFSM::Event_EnableUpgrade));
- }
- void CUpgradeRunEntity::OnPreClose(EntityCloseCauseEnum eCloseCause,CSmartPointer<ITransactionContext> pTransactionContext)
- {
- //auto pFunc = GetFunction();
- //assert(pFunc != NULL);
- //pFunc->UnregistSysVarEvent("CustomerHandle");
- //pFunc->UnregistSysVarEvent("RunState");
-
- pTransactionContext->SendAnswer(Error_Succeed);
- }
- void CUpgradeRunEntity::OnSysVarEvent(const char *pszKey, const char *pszValue,const char *pszOldValue,const char *pszEntityName)
- {
- //if (strcmp(pszKey, "CustomerHandle") == 0)
- //{
- // if (*pszValue == 'N' || *pszValue == 'A') // 没有交互
- // {
- // CSimpleStringA strRunState;
- // auto rc = GetFunction()->GetSysVar("RunState", strRunState);
- // assert(rc == Error_Succeed);
- // if (strRunState[0] == 'O')
- // {
- // // 继续升级
- // m_FSM.PostEventFIFO(new FSMEvent(CUpgradeRunFSM::Event_EnableUpgrade));
- // return;
- // }
- // }
- //
- // // 暂停升级
- // m_FSM.PostEventFIFO(new FSMEvent(CUpgradeRunFSM::Event_DisableUpgrade));
- //}
- //else if (strcmp(pszKey, "RunState") ==0)
- //{
- // if (*pszValue == 'O') // 正常工作
- // {
- // CSimpleStringA strCustomerHandle;
- // auto rc = GetFunction()->GetSysVar("CustomerHandle", strCustomerHandle);
- // assert(rc == Error_Succeed);
- // if (strCustomerHandle[0] == 'N' || strCustomerHandle[0] == 'A')
- // {
- // // 继续升级
- // m_FSM.PostEventFIFO(new FSMEvent(CUpgradeRunFSM::Event_EnableUpgrade));
- // return;
- // }
- // }
- // // 暂停升级
- // m_FSM.PostEventFIFO(new FSMEvent(CUpgradeRunFSM::Event_DisableUpgrade));
- //}
- }
-
- ErrorCodeEnum CUpgradeRunEntity::PushUpdateTask(const CSimpleStringA &strPackName, const int nPackType)
- {
- LOG_TRACE("PushUpdateTask: [%s], [%d]", (const char*)strPackName, nPackType);
- m_FSM.PostEventFIFO(new CUpgradeRunFSM::StartUpgradeEvent(strPackName, nPackType));
- return Error_Succeed;
- }
- ErrorCodeEnum CUpgradeRunEntity::GetRunState(CSimpleStringA &strPackName, char &cState)
- {
- return m_FSM.GetRunState(strPackName, cState);
- }
- ErrorCodeEnum CUpgradeRunEntity::UpdateTaskCancel(const CSimpleStringA &strPackName)
- {
- LOG_TRACE("UpdateTaskCancel: [%s]", (const char*)strPackName);
- m_FSM.PostEventFIFO(new CUpgradeRunFSM::CancelUpgradeEvent(strPackName));
- return Error_Succeed;
- }
- ErrorCodeEnum CUpgradeRunEntity::BroadcastUpgradeCheckEvent(UpgradeCheckEvent &e)
- {
- return SpSendBroadcast(GetFunction(), eMsg_UpgradeCheckEvent, eMsgSig_UpgradeCheckEvent, e);
- }
- ErrorCodeEnum CUpgradeRunEntity::BroadcastUpgradeDoneEvent(UpgradeDoneEvent &e)
- {
- return SpSendBroadcast(GetFunction(), eMsg_UpgradeDoneEvent, eMsgSig_UpgradeDoneEvent, e);
- }
- //获取系统补丁升级结果(windows特有方法)
- bool CUpgradeRunEntity::GetServerPackUpgradeResult(const char *pszPackageName, CSimpleStringA &strVerison, CSimpleStringA &strErrMsg)
- {
- #ifdef RVC_OS_WIN
- char szTmp[4096] = {};
- int nTmpBufLen = 4096;//win7补丁可能有200多个,每个补丁(如KB3105211加分隔符;)需要10个字节
- if (!QueryWMIDevice(PatchList, "HotFixID", szTmp, &nTmpBufLen))
- {
- Dbg("query sys patch list fail");
- return false;
- }
- CSimpleStringA strPatchList = szTmp;
- CSimpleStringA strPatchName = m_FSM.GetSysPatchNameFromPackName(pszPackageName);
- if (strPatchName.IsNullOrEmpty())
- {
- return false;
- }
- if (strPatchList.IndexOf(strPatchName.GetData()) < 0 )
- {
- Dbg("can not find PatchName[%s] from PatchList[%s]", strPatchName, strPatchList);
- return false;
- }
- Dbg("find PatchName[%s] from PatchList[%s]", strPatchName, strPatchList);
- strVerison = strPatchName;
- return true;
- #else
- return true;
- #endif // RVC_OS_WIN
- }
- //获取固件升级结果
- bool CUpgradeRunEntity::GetFirmwarePackUpgradeResult(const char *pszPackageName, CSimpleStringA &strVerison, CSimpleStringA &strErrMsg)
- {
- // 根据PinPad实体状态确定是否连接密码键盘
- bool bUpdate = false;
- strVerison = "";
- auto pPinPadClient = new PinPadService_ClientBase(this);
- if (pPinPadClient->Connect() != Error_Succeed)
- {
- Dbg("connect PinPad fail, assume no pinpad");
- strErrMsg = "connect PinPad fail, assume no pinpad";
- }
- else
- {
- PinPadService_GetDevInfo_Req req = {};
- PinPadService_GetDevInfo_Ans ans = {};
- auto rc = pPinPadClient->GetDevInfo(req, ans, 3000);
- if (rc == Error_Succeed)
- {
- if (ans.state == DEVICE_STATUS_NORMAL)
- {
- Dbg("pinpad model: %s", (const char*)ans.model);
- // CM = V2.0#PM = V1.0#MID = 75500001#PID = 12345678#FWID = V1234567#Vendor = nantian
- // 密码键盘ID,PID,8到16字节; 设备ID,MID,8到16字节; 固件版本号,FWID,8字节
- CSimpleStringA str = ans.model;
- CSimpleStringA strFWID;
- if (!str.IsNullOrEmpty())
- {
- auto arr = str.Split('#');
- if (arr.GetCount() > 0)
- {
- for (int i = 0; i < arr.GetCount(); i++)
- {
- auto arr2 = arr[i].Split('=');
- if (arr2.GetCount() != 2)
- continue;
- if(!strnicmp((LPCTSTR)arr2[0], "FWID", strlen("FWID")))
- {
- strFWID = arr2[1];
- if (!strFWID.IsNullOrEmpty())
- {
- CSimpleStringA strPackName = pszPackageName;
- if (strPackName.IndexOf(strFWID.GetData()) > 0)
- {
- Dbg("find FWID[%] from strPackName[%s]", strFWID, strPackName);
- strVerison = strFWID;
- bUpdate = true;
- }
- else
- {
- Dbg("can not find FWID[%] from strPackName[%s]", strFWID, strPackName);
- strErrMsg = "can not find FWID from PackName";
- bUpdate = false;
- }
- }
- break;
- }
- }
- }
- }
- }
- else
- {
- Dbg("pinpad not exist, state: %d", ans.state);
- strErrMsg = "pinpad not exist";
- }
- }
- else
- {
- Dbg("PinPad::GetDevInfo() fail: 0x%X", rc);
- strErrMsg = "PinPad::GetDevInfo() fail";
- }
- pPinPadClient->GetFunction()->CloseSession();
- }
- pPinPadClient->SafeDelete();
- pPinPadClient = NULL;
- return bUpdate;
- }
- SP_BEGIN_ENTITY_MAP()
- SP_ENTITY(CUpgradeRunEntity)
- SP_END_ENTITY_MAP()
|