#ifndef IDCERTFSM_H #define IDCERTFSM_H #pragma once #include "SpFSM.h" #include "SpTest.h" enum EvtType { USER_EVT_TEST = EVT_USER+1, USER_EVT_QUIT, USER_EVT_READ, USER_EVT_CANCEL_READ, USER_EVT_READ_FINISHED, USER_EVT_EXIT, USER_EVT_GET_DEVINFO, USER_EVT_ERROR, USER_EVT_READ_EX, USER_EVT_READ_EX_FINISHED, USER_EVT_EJECT, USER_EVT_WAIT_FETCH_IDCARD_FINISHED, USER_EVT_READ_AND_SCAN, USER_EVT_READ_AND_SCAN_FINISHED, USER_EVT_INIT_FINISHED, }; enum BmpType { Bmp_ZP = 1, Bmp_SCAN = 2, }; #include "IDCerClass.h" #include "IDCertificate_def_g.h" #pragma region forsonar typedef IDCertificate::IDCertService_Read_Req IDCert_Read_Req; typedef IDCertificate::IDCertService_Read_Ans IDCert_Read_Ans; typedef IDCertificate::IDCertService_CancelRead_Info IDCert_CancelRead_Info; typedef IDCertificate::IDCertService_ReadWaitMore_Info IDCert_ReadWaitMore_Info; typedef IDCertificate::IDCertService_Exit_Info IDCert_Exit_Info; typedef IDCertificate::IDCertService_ReadEx_Req IDCert_ReadEx_Req; typedef IDCertificate::IDCertService_ReadEx_Ans IDCert_ReadEx_Ans; typedef IDCertificate::IDCertService_Eject_Req IDCert_Eject_Req; typedef IDCertificate::IDCertService_Eject_Ans IDCert_Eject_Ans; typedef IDCertificate::IDCertService_ReadAndScan_Req IDCert_ReadAndScan_Req; typedef IDCertificate::IDCertService_ReadAndScan_Ans IDCert_ReadAndScan_Ans; typedef IDCertificate::IDCertService_CrossTermCall_Req IDCert_CrossTermCall_Req; typedef IDCertificate::IDCertService_CrossTermCall_Ans IDCert_CrossTermCall_Ans; typedef IDCertificate::IDCertService_CrossTermInvokeInfo_Info IDCert_CrossTermInvokeInfo_Info; typedef IDCertificate::IDCertService_GetDevInfo_Req IDCert_GetDevInfo_Req; typedef IDCertificate::IDCertService_GetDevInfo_Ans IDCert_GetDevInfo_Ans; #pragma endregion forsonar #include "mod_heartbeat/HeartBeat_client_g.h" using namespace HeartBeat; #include "DeviceCrossHelper.h" #include using namespace std; typedef ErrorCodeEnum ( *lpCreateDevCom)(DeviceBaseClass *&baseObj); typedef ErrorCodeEnum ( *lpReleaseDevCom)(DeviceBaseClass *&pBaseObj); #include "DevErrorCode.h" #include "DevFSMCommBase.hpp" struct CtxInfo { int dataSize; LPVOID pCtx; }; class ReadEvent : public FSMEvent { public: ReadEvent() : FSMEvent(USER_EVT_READ){} virtual ~ReadEvent(){} SpReqAnsContext::Pointer ctx; virtual void OnUnhandled() { if (ctx != NULL) ctx->Answer(Error_InvalidState); } }; class CancelReadEvent : public FSMEvent { public: CancelReadEvent() : FSMEvent(USER_EVT_CANCEL_READ){} virtual ~CancelReadEvent(){} virtual void OnUnhandled() { LOG_TRACE("idcer cancel read not handled"); } }; class GetDevInfoEvent : public FSMEvent { public: GetDevInfoEvent() : FSMEvent(USER_EVT_GET_DEVINFO){} virtual ~GetDevInfoEvent(){} SpReqAnsContext::Pointer ctx; virtual void OnUnhandled() { if (ctx != NULL) ctx->Answer(Error_InvalidState); } }; class ReadExEvent : public FSMEvent { public: ReadExEvent() : FSMEvent(USER_EVT_READ_EX){} virtual ~ReadExEvent(){} SpReqAnsContext::Pointer ctx; virtual void OnUnhandled() { if (ctx != NULL) ctx->Answer(Error_InvalidState); } }; class EjectEvent : public FSMEvent { public: EjectEvent() : FSMEvent(USER_EVT_EJECT){} virtual ~EjectEvent(){} SpReqAnsContext::Pointer ctx; virtual void OnUnhandled() { if (ctx != NULL) ctx->Answer(Error_InvalidState); } }; class ReadAndScanEvent : public FSMEvent { public: ReadAndScanEvent() : FSMEvent(USER_EVT_READ_AND_SCAN) {} virtual ~ReadAndScanEvent() {} SpReqAnsContext::Pointer ctx; virtual void OnUnhandled() { if (ctx != NULL) ctx->Answer(Error_InvalidState); } }; class CIDCertFSM : public CCommDevFSM { public: enum {s0,s1,s2,s3,s4,s5}; //ON_ENTITYT_TEST(); BEGIN_FSM_STATE(CIDCertFSM) FSM_STATE_ENTRY(s0,"Normal",s0_on_entry,s0_on_exit,s0_on_event) FSM_STATE_ENTRY(s1,"Reading",s1_on_entry,s1_on_exit,s1_on_event) FSM_STATE_ENTRY(s2,"Fail",s2_on_entry,s2_on_exit,s2_on_event) FSM_STATE_ENTRY(s3, "Eject", s3_on_entry, s3_on_exit, s3_on_event) FSM_STATE_ENTRY(s4, "WaitingFetch", s4_on_entry, s4_on_exit, s4_on_event) FSM_STATE_ENTRY(s5, "Init", s5_on_entry, s5_on_exit, s5_on_event) END_FSM_STATE() BEGIN_FSM_RULE(CIDCertFSM, s5) FSM_RULE_ENTRY(s0, s2, USER_EVT_ERROR, 0) FSM_RULE_ENTRY(s0, FSM_STATE_EXIT, USER_EVT_QUIT, 0) FSM_RULE_ENTRY(s0, s1, USER_EVT_READ, 0) FSM_RULE_ENTRY(s0, s1, USER_EVT_READ_EX, 0) FSM_RULE_ENTRY(s0, s1, USER_EVT_READ_AND_SCAN, 0) FSM_RULE_ENTRY(s1, s0, USER_EVT_READ_FINISHED, 0) FSM_RULE_ENTRY(s1, s2, USER_EVT_READ_FINISHED, 1) FSM_RULE_ENTRY(s1, s0, USER_EVT_READ_EX_FINISHED, 0) FSM_RULE_ENTRY(s1, s2, USER_EVT_READ_EX_FINISHED, 1) FSM_RULE_ENTRY(s1, s4, USER_EVT_READ_EX_FINISHED, 4) FSM_RULE_ENTRY(s1, s0, USER_EVT_READ_AND_SCAN_FINISHED, 0) FSM_RULE_ENTRY(s1, s2, USER_EVT_READ_AND_SCAN_FINISHED, 1) FSM_RULE_ENTRY(s1, s4, USER_EVT_READ_AND_SCAN_FINISHED, 4) FSM_RULE_ENTRY(s1, FSM_STATE_EXIT, USER_EVT_QUIT, 0) FSM_RULE_ENTRY(s4, s0, USER_EVT_WAIT_FETCH_IDCARD_FINISHED, 0) FSM_RULE_ENTRY(s5, s0, USER_EVT_INIT_FINISHED, 0) FSM_RULE_ENTRY(s5, s2, USER_EVT_INIT_FINISHED, 2) END_FSM_RULE() CIDCertFSM():m_devInit(false),m_bCancelRead(false),m_bReading(false),m_bWaitReadMore(false), m_bExit(false),m_testResult(Error_Succeed), m_csMachineType(""), m_csSite(""), m_terminalNo("") ,m_devVendor(""), m_devVer(""), m_devBatch("") , m_bRVCIL(false), m_pHBClient(nullptr){ HARDWARE_ENTITY_RESET_ENTITYID(m_entCode, 0x201); }; virtual ~CIDCertFSM() {}; virtual ErrorCodeEnum OnInit(); virtual ErrorCodeEnum OnExit(); virtual void s0_on_entry(); virtual void s0_on_exit(); virtual unsigned int s0_on_event(FSMEvent* e); virtual void s1_on_entry(); virtual void s1_on_exit(); virtual unsigned int s1_on_event(FSMEvent* e); virtual void s2_on_entry(); virtual void s2_on_exit(); virtual unsigned int s2_on_event(FSMEvent* e); virtual void s3_on_entry(); virtual void s3_on_exit(); virtual unsigned int s3_on_event(FSMEvent* e); virtual void s4_on_entry(); virtual void s4_on_exit(); virtual unsigned int s4_on_event(FSMEvent* e); virtual void s5_on_entry(); virtual void s5_on_exit(); virtual unsigned int s5_on_event(FSMEvent* e); int ReadInfo(SpReqAnsContext::Pointer ctx); int ReadInfoEx(SpReqAnsContext::Pointer ctx); int ReadAndScan(SpReqAnsContext::Pointer ctx); int WaitFetchIDCard(); void SetReadMore(){m_bWaitReadMore = true;} void SetExitFlag(){m_bExit = true;} bool GetReadFlag(){return m_bReading;} ErrorCodeEnum GetDevCatInfo(DevCategoryInfo &devInfo, CSimpleStringA& devType); void GetDevState(DevStateEnum &devState){ devState = m_devState; } int ReadHZCard(SpReqAnsContext::Pointer ctx); void DoExit(CSmartPointer pTransactionContext) { pTransactionContext->SendAnswer(Error_Succeed); } int LocalCallHeartBeat(int method, CBlob &bbSend, bool bTwoWay = false); bool GetDevInitFlag() { return m_devInit; } bool IsRVCIL() { /*return m_bRVCIL;*/return false; }//oilyang@20190123 方案改了,这里暂时不需要了 void CrossTermCall(SpReqAnsContext::Pointer ctx); template void SaveCtx(int methodID, CSmartPointer > ctx) { m_mapCtx[methodID].pCtx = static_cast(ctx.GetRawPointer()); } void SaveCtxAA(int methodID, SpReqAnsContext::Pointer ctx) { m_readAndScanCtx = ctx; } LPVOID GetCtx(int methodID) { if (m_mapCtx.find(methodID) != m_mapCtx.end()) return m_mapCtx[methodID].pCtx; else return NULL; } int Initial(); void CrossTermInvokeInfo(SpOnewayCallContext::Pointer ctx); void SelfTest(EntityTestEnum eTestType,CSmartPointer pTransactionContext); protected: ErrorCodeEnum GetVendorDllPath(CSimpleStringA &strPath); ErrorCodeEnum GetPngBlob(CBlob &data,bool bClear=false); ErrorCodeEnum GetPngBlobEx(CBlob &data, CSimpleStringA fileNamePrefix,bool bClear=false); //type:1,delete img about zp; type:2,delete img about scan ID;type:3,delete both zp and scan ID void DeleteZP(int type); //ErrorCodeEnum ConvertBmpToPng(CSimpleStringA &strBmpPath, CSimpleStringA &strPngPath); //Delete bmp file in dep directory, you should just convey fileName only without paths -Joseph ErrorCodeEnum DeleteFileIfExisted(LPCTSTR fileName); bool GetAttachedTerminal(CSimpleStringA &csTerm); DWORD UpdateDEC(DWORD dwVal = 0) { int reserved = 0; reserved = (dwVal & 0xFC000) >> 14; HARDWARE_ENTITY_SET_DEVCODE(m_entCode, dwVal, reserved); return GetDEC(); } DWORD GetDEC() const { return HARDWARE_ENTITY_MAKE_ERRORCODE(m_entCode); } DWORD AlarmDEC() const { return GetDEC(); } DWORD AlarmDECToBusiness(DWORD dwVal = 0) { if (dwVal > 0) UpdateDEC(dwVal); //oilyang@20200528 according the meeting result,throw a LogError while answering ctx //oilyang@20200525 if have been set ErrorCode of entity defined (not device),use it directly DWORD dwCode = 0; if ((m_entCode.dwVendorErroCode >> 20) == m_entCode.dwEntityId) dwCode = m_entCode.dwVendorErroCode; else dwCode = HARDWARE_ENTITY_MAKE_ERRORCODE_TO_BUSINESS(m_entCode); LogError(Severity_Middle, Error_Unexpect, dwCode, ""); return dwCode; } void ClearRelatedDEC() { UpdateDEC(); m_csAlarmMsg = "NO more information"; } void LogErrMsg(const char *pMsgHead, ErrorCodeEnum eErrCode, DWORD defaultDevCode = 0, BOOL bAlarm = FALSE); protected: bool m_devInit,m_bCancelRead,m_bReading,m_bWaitReadMore,m_bExit,m_bRVCIL; ErrorCodeEnum m_testResult; DevCategoryInfo m_devCatInfo; DevStateEnum m_devState; CSimpleStringA m_csMachineType,m_csSite,m_terminalNo; CSimpleStringA m_devVendor, m_devVer, m_devBatch; map m_mapCtx; HeartBeatService_ClientBase* m_pHBClient; SpReqAnsContext::Pointer m_readAndScanCtx; DevEntityErrorCode m_entCode; CSimpleStringA m_csAlarmMsg; }; struct ReadTask : public ITaskSp { CIDCertFSM* fsm; SpReqAnsContext::Pointer ctx; ReadTask(CIDCertFSM* f) : fsm(f) {} void Process() { FSMEvent *e = new FSMEvent(USER_EVT_READ_FINISHED); e->param1 = fsm->ReadInfo(ctx); fsm->PostEventFIFO(e); } }; struct ReadExTask : public ITaskSp { CIDCertFSM* fsm; SpReqAnsContext::Pointer ctx; ReadExTask(CIDCertFSM* f) : fsm(f) {} void Process() { FSMEvent *e = new FSMEvent(USER_EVT_READ_EX_FINISHED); e->param1 = fsm->ReadInfoEx(ctx); fsm->PostEventFIFO(e); } }; struct ReadAndScanTask : public ITaskSp { CIDCertFSM* fsm; SpReqAnsContext::Pointer ctx; ReadAndScanTask(CIDCertFSM* f) : fsm(f) {} void Process() { FSMEvent *e = new FSMEvent(USER_EVT_READ_AND_SCAN_FINISHED); e->param1 = fsm->ReadAndScan(ctx); fsm->PostEventFIFO(e); } }; struct WaitFetchIDCardTask : public ITaskSp { CIDCertFSM* fsm; WaitFetchIDCardTask(CIDCertFSM* f) : fsm(f) {} void Process() { FSMEvent *e = new FSMEvent(USER_EVT_WAIT_FETCH_IDCARD_FINISHED); e->param1 = fsm->WaitFetchIDCard(); fsm->PostEventFIFO(e); } }; struct InitTask : public ITaskSp { CIDCertFSM* fsm; InitTask(CIDCertFSM* f) : fsm(f) {} void Process() { FSMEvent* e = new FSMEvent(USER_EVT_INIT_FINISHED); e->param1 = fsm->Initial(); fsm->PostEventFIFO(e); } }; #endif //IDCERTFSM_H