123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375 |
- #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 <map>
- 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<IDCert_Read_Req, IDCert_Read_Ans>::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<IDCert_GetDevInfo_Req, IDCert_GetDevInfo_Ans>::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<IDCert_ReadEx_Req, IDCert_ReadEx_Ans>::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<IDCert_Eject_Req, IDCert_Eject_Ans>::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<IDCert_ReadAndScan_Req, IDCert_ReadAndScan_Ans>::Pointer ctx;
- virtual void OnUnhandled()
- {
- if (ctx != NULL)
- ctx->Answer(Error_InvalidState);
- }
- };
- class CIDCertFSM : public CCommDevFSM<CIDCertFSM, IDCerClass>
- {
- 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<IDCert_Read_Req, IDCert_Read_Ans>::Pointer ctx);
- int ReadInfoEx(SpReqAnsContext<IDCert_ReadEx_Req, IDCert_ReadEx_Ans>::Pointer ctx);
- int ReadAndScan(SpReqAnsContext<IDCert_ReadAndScan_Req, IDCert_ReadAndScan_Ans>::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<IDCert_ReadEx_Req, IDCert_ReadEx_Ans>::Pointer ctx);
- void DoExit(CSmartPointer<ITransactionContext> 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<IDCert_CrossTermCall_Req, IDCert_CrossTermCall_Ans>::Pointer ctx);
- template <class TReq,class TAns>
- void SaveCtx(int methodID, CSmartPointer<SpReqAnsContext<TReq, TAns> > ctx)
- {
- m_mapCtx[methodID].pCtx = static_cast<void*>(ctx.GetRawPointer());
- }
- void SaveCtxAA(int methodID, SpReqAnsContext<IDCert_ReadAndScan_Req, IDCert_ReadAndScan_Ans>::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<IDCert_CrossTermInvokeInfo_Info>::Pointer ctx);
- void SelfTest(EntityTestEnum eTestType,CSmartPointer<ITransactionContext> 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<int, CtxInfo> m_mapCtx;
- HeartBeatService_ClientBase* m_pHBClient;
- SpReqAnsContext<IDCert_ReadAndScan_Req, IDCert_ReadAndScan_Ans>::Pointer m_readAndScanCtx;
- DevEntityErrorCode m_entCode;
- CSimpleStringA m_csAlarmMsg;
- };
- struct ReadTask : public ITaskSp
- {
- CIDCertFSM* fsm;
- SpReqAnsContext<IDCert_Read_Req, IDCert_Read_Ans>::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<IDCert_ReadEx_Req, IDCert_ReadEx_Ans>::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<IDCert_ReadAndScan_Req, IDCert_ReadAndScan_Ans>::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
|