123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521 |
- #ifndef __PINPAD_FSM_H
- #define __PINPAD_FSM_H
- #pragma once
- #include "SpFSM.h"
- #include "toolkit.h"
- #include "SpUtility.h"
- #include "DevFSMCommBase.hpp"
- #include "DeviceBaseHelper.h"
- enum EvtType
- {
- USER_EVT_TEST = EVT_USER+1,
- USER_EVT_ANY_INPUT_TIMER,
- USER_EVT_QUIT,
- USER_EVT_INIT,
- USER_EVT_INITFINISHED,
- USER_EVT_GETINPUT,
- USER_EVT_GETINPUTFINISHED,
- USER_EVT_SETACCOUNT,
- USER_EVT_SETACCOUNTFINISHED,
- USER_EVT_INPUTCANCEL,
- USER_EVT_INPUTWAITINGMORE,
- USER_EVT_EXIT,
- USER_EVT_LOADKEY,
- USER_EVT_LOADKEYFINISHED,
- USER_EVT_ENCRYPT,
- USER_EVT_ENCRYPTFINISHED,
- USER_EVT_GETINPUT_SM,
- USER_EVT_GETINPUT_SM_FINISHED,
- USER_EVT_LOADKEY_SM,
- USER_EVT_LOADKEY_SM_FINISHED,
- USER_EVT_ENCRYPT_SM,
- USER_EVT_ENCRYPT_SM_FINISHED,
- USER_EVT_GET_CHECKCODE,
- USER_EVT_GET_CHECKCODE_FINISHED,
- };
- #include "PinPad_server_g.h"
- #include "PinPad_msg_g.h"
- #include "PinPadClass.h"
- #include "DeviceCrossHelper.h"
- //using namespace PinPad;
- using PinPad::PinPadService_GetInput_Req;
- using PinPad::PinPadService_GetInput_Ans;
- using PinPad::PinPadService_InputWaitMore_Info;
- using PinPad::PinPadService_InputCancel_Info;
- using PinPad::PinPadService_Exit_Info;
- using PinPad::PinPadService_LoadKeys_Req;
- using PinPad::PinPadService_LoadKeys_Ans;
- using PinPad::PinPadService_EncryptData_Req;
- using PinPad::PinPadService_EncryptData_Ans;
- using PinPad::PinPadService_GetInputSM_Req;
- using PinPad::PinPadService_GetInputSM_Ans;
- using PinPad::PinPadService_LoadKeysSM_Req;
- using PinPad::PinPadService_LoadKeysSM_Ans;
- using PinPad::PinPadService_EncryptDataSM_Req;
- using PinPad::PinPadService_EncryptDataSM_Ans;
- using PinPad::PinPadService_QueryFunc_Req;
- using PinPad::PinPadService_QueryFunc_Ans;
- using PinPad::PinPadService_GetCheckCode_Req;
- using PinPad::PinPadService_GetCheckCode_Ans;
- using PinPad::PinPadService_CrossTermCall_Req;
- using PinPad::PinPadService_CrossTermCall_Ans;
- using PinPad::PinPadService_CrossTermInvokeInfo_Info;
- using PinPad::PinPadService_GetDevInfo_Req;
- using PinPad::PinPadService_GetDevInfo_Ans;
- using PinPad::InputContent;
- #include "HeartBeat_client_g.h"
- using namespace HeartBeat;
- #include <map>
- using namespace std;
- struct CtxInfo
- {
- int dataSize;
- LPVOID pCtx;
- };
- class CPinPadEntity;
- class CPinPadFSM;
- class PinPadInitFinishedEvent : public FSMEvent
- {
- public:
- PinPadInitFinishedEvent() : FSMEvent(USER_EVT_INITFINISHED){}
- ~PinPadInitFinishedEvent(){}
- };
- class InputCancelEvent : public FSMEvent
- {
- public:
- InputCancelEvent() : FSMEvent(USER_EVT_INPUTCANCEL){}
- ~InputCancelEvent(){}
- };
- class InputWaitingMoreEvent : public FSMEvent
- {
- public:
- InputWaitingMoreEvent() : FSMEvent(USER_EVT_INPUTWAITINGMORE){}
- ~InputWaitingMoreEvent(){}
- };
- class GetInputEvent : public FSMEvent
- {
- public:
- GetInputEvent() : FSMEvent(USER_EVT_GETINPUT){}
- ~GetInputEvent(){}
- SpReqAnsContext<PinPadService_GetInput_Req, PinPadService_GetInput_Ans>::Pointer ctx;
- virtual void OnUnhandled()
- {
- if (ctx != NULL)
- ctx->Answer(Error_InvalidState);
- }
- };
- class LoadKeyEvent : public FSMEvent
- {
- public:
- LoadKeyEvent() : FSMEvent(USER_EVT_LOADKEY){}
- ~LoadKeyEvent(){}
- SpReqAnsContext<PinPadService_LoadKeys_Req, PinPadService_LoadKeys_Ans>::Pointer ctx;
- virtual void OnUnhandled()
- {
- if (ctx != NULL)
- ctx->Answer(Error_InvalidState);
- }
- };
- class EncryptEvent : public FSMEvent
- {
- public:
- EncryptEvent() : FSMEvent(USER_EVT_ENCRYPT){}
- ~EncryptEvent(){}
- SpReqAnsContext<PinPadService_EncryptData_Req, PinPadService_EncryptData_Ans>::Pointer ctx;
- virtual void OnUnhandled()
- {
- if (ctx != NULL)
- ctx->Answer(Error_InvalidState);
- }
- };
- class GetInputSMEvent : public FSMEvent
- {
- public:
- GetInputSMEvent() : FSMEvent(USER_EVT_GETINPUT_SM){}
- ~GetInputSMEvent(){}
- SpReqAnsContext<PinPadService_GetInputSM_Req, PinPadService_GetInputSM_Ans>::Pointer ctx;
- virtual void OnUnhandled()
- {
- if (ctx != NULL)
- ctx->Answer(Error_InvalidState);
- }
- };
- class LoadKeySMEvent : public FSMEvent
- {
- public:
- LoadKeySMEvent() : FSMEvent(USER_EVT_LOADKEY_SM){}
- ~LoadKeySMEvent(){}
- SpReqAnsContext<PinPadService_LoadKeysSM_Req, PinPadService_LoadKeysSM_Ans>::Pointer ctx;
- virtual void OnUnhandled()
- {
- if (ctx != NULL)
- ctx->Answer(Error_InvalidState);
- }
- };
- class EncryptSMEvent : public FSMEvent
- {
- public:
- EncryptSMEvent() : FSMEvent(USER_EVT_ENCRYPT_SM){}
- ~EncryptSMEvent(){}
- SpReqAnsContext<PinPadService_EncryptDataSM_Req, PinPadService_EncryptDataSM_Ans>::Pointer ctx;
- virtual void OnUnhandled()
- {
- if (ctx != NULL)
- ctx->Answer(Error_InvalidState);
- }
- };
- class GetCheckCodeEvent : public FSMEvent
- {
- public:
- GetCheckCodeEvent() : FSMEvent(USER_EVT_GET_CHECKCODE){}
- ~GetCheckCodeEvent(){}
- SpReqAnsContext<PinPadService_GetCheckCode_Req, PinPadService_GetCheckCode_Ans>::Pointer ctx;
- virtual void OnUnhandled()
- {
- if (ctx != NULL)
- ctx->Answer(Error_InvalidState);
- }
- };
- class CPinPadFSM : public CCommDevFSM<CPinPadFSM, PinPadClass>
- {
- public:
- enum {s0,s1,s2,s3,s4,s5};
- BEGIN_FSM_STATE(CPinPadFSM)
- FSM_STATE_ENTRY(s0, "Init", s0_on_entry, s0_on_exit, s0_on_event)
- FSM_STATE_ENTRY(s1, "Initializing", s1_on_entry, s1_on_exit, s1_on_event)
- FSM_STATE_ENTRY(s2, "Idle", s2_on_entry, s2_on_exit, s2_on_event)
- FSM_STATE_ENTRY(s3, "Input", s3_on_entry, s3_on_exit, s3_on_event)
- FSM_STATE_ENTRY(s4, "AccessAuth", s4_on_entry, s4_on_exit, s4_on_event)
- FSM_STATE_ENTRY(s5, "Failed", s5_on_entry, s5_on_exit, s5_on_event)
- END_FSM_STATE()
- BEGIN_FSM_RULE(CPinPadFSM, s0)
- FSM_RULE_ENTRY(s0, s1, USER_EVT_INIT, 0)
- FSM_RULE_ENTRY(s1, s2, USER_EVT_INITFINISHED, 0)
- FSM_RULE_ENTRY(s1, s5, USER_EVT_INITFINISHED, 1)
- FSM_RULE_ENTRY(s2, s3, USER_EVT_GETINPUT, 0)
- FSM_RULE_ENTRY(s2, s3, USER_EVT_GETINPUT_SM, 0)
- FSM_RULE_ENTRY(s2, s4, USER_EVT_LOADKEY, 2)
- FSM_RULE_ENTRY(s2, s4, USER_EVT_ENCRYPT, 2)
- FSM_RULE_ENTRY(s2, s4, USER_EVT_LOADKEY_SM, 2)
- FSM_RULE_ENTRY(s2, s4, USER_EVT_ENCRYPT_SM, 2)
- //FSM_RULE_ENTRY(s2,s2,USER_EVT_ANY_INPUT_TIMER,0)
- //FSM_RULE_ENTRY(s2,s4,USER_EVT_GETINPUT,0)
- FSM_RULE_ENTRY(s3, s2, USER_EVT_GETINPUTFINISHED, 0)
- FSM_RULE_ENTRY(s3, s5, USER_EVT_GETINPUTFINISHED, 1)
- FSM_RULE_ENTRY(s4, s2, USER_EVT_LOADKEYFINISHED, 0)
- FSM_RULE_ENTRY(s4, s2, USER_EVT_ENCRYPTFINISHED, 0)
- FSM_RULE_ENTRY(s4, s2, USER_EVT_LOADKEY_SM_FINISHED, 0)
- FSM_RULE_ENTRY(s4, s2, USER_EVT_ENCRYPT_SM_FINISHED, 0)
- FSM_RULE_ENTRY(s5, s0, USER_EVT_GETINPUT, 0)
- FSM_RULE_ENTRY(s5, s0, USER_EVT_LOADKEY, 0)
- END_FSM_RULE()
- CPinPadFSM() : m_bDevInit(false), m_bFrontCancel(false),
- m_bWaitingMore(false), m_bExit(false), m_bPlainPin(true), m_ctx(NULL),
- m_bEntityExit(false), m_bPinInput(false), m_bPlainOpen(false), m_bLoadKey(false), m_bEncrypt(false)
- , m_dwDevCommFailCount(0), m_dwPinPadRunCount(0), m_eDevState(DEVICE_STATUS_NOT_READY), m_encryptkey(1)
- , m_bSM(false), m_b3DESLoaded(false), m_bSMLoaded(false), m_bInMainPage(true), m_szModel(""), m_szType(""), m_devSN("")
- , m_szVendor(""),m_csMachineType(true), m_csSite(true), m_terminalNo(true), m_bPinPadNeedless(FALSE)
- , m_csAlarmMsg("NO more information"), m_bRVCIL(false), m_keySN(""),m_keySNSM(""){
- HARDWARE_ENTITY_RESET_ENTITYID(m_entCode, 0x206);
- m_FirstStart = TRUE;
- ZeroMemory(&m_adapterInfo, sizeof(m_adapterInfo));
- }
- ~CPinPadFSM(){
- Dbg("~CPinPadFSM");
- m_bEntityExit = true;
- m_hInputConVar.Broadcast();
- }
- virtual ErrorCodeEnum OnInit();
- virtual ErrorCodeEnum OnExit();
- void DoWork();
- void s0_on_entry();
- void s0_on_exit();
- unsigned int s0_on_event(FSMEvent* event);
- void s1_on_entry();
- void s1_on_exit();
- unsigned int s1_on_event(FSMEvent* event);
- void s2_on_entry();
- void s2_on_exit();
- unsigned int s2_on_event(FSMEvent* event);
- void s3_on_entry();
- void s3_on_exit();
- unsigned int s3_on_event(FSMEvent* event);
- void s4_on_entry();
- void s4_on_exit();
- unsigned int s4_on_event(FSMEvent* event);
- void s5_on_entry();
- void s5_on_exit();
- unsigned int s5_on_event(FSMEvent* event);
- int Initial();
- int GetInput(SpReqAnsContext<PinPadService_GetInput_Req, PinPadService_GetInput_Ans>::Pointer ctx
- ,SpReqAnsContext<PinPadService_GetInputSM_Req, PinPadService_GetInputSM_Ans>::Pointer ctxSM,bool bSM=false);
- void push_char(char *buf, int *len, int c);
- void PushInputChar(char *buf, int c);
- void pop_char(char *buf, int *len,bool bClear=true);
- void clear_char(char *buf, int *len);
- bool Get12Account(char *szAcc);
- void OpenInputText(void *pUserdata);
- ErrorCodeEnum GetText(SpReqAnsContext<PinPadService_GetInput_Req, PinPadService_GetInput_Ans>::Pointer ctx
- ,SpReqAnsContext<PinPadService_GetInputSM_Req, PinPadService_GetInputSM_Ans>::Pointer ctxSM,bool bSM=false);
- ErrorCodeEnum GetEncryptText(SpReqAnsContext<PinPadService_GetInput_Req, PinPadService_GetInput_Ans>::Pointer ctx
- ,SpReqAnsContext<PinPadService_GetInputSM_Req, PinPadService_GetInputSM_Ans>::Pointer ctxSM,bool bSM=false);
- bool GetDevInitFlag(){ return m_bDevInit;}
- bool IsRVCIL() { /*return m_bRVCIL; */ return false;}//oilyang@20190123 方案改了,这里暂时不需要了
- void SetExitFlag(){m_bExit = true;}
- bool GetEntityExit() { return m_bEntityExit;}
- void SetCtx(SpReqAnsContext<PinPadService_GetInput_Req, PinPadService_GetInput_Ans>::Pointer ctx
- ,SpReqAnsContext<PinPadService_GetInputSM_Req, PinPadService_GetInputSM_Ans>::Pointer ctxSM,bool bSMCtx=false)
- {
- LOG_FUNCTION();
- if (!bSMCtx)
- {
- m_inputSMCtx = NULL;
- m_ctx = ctx;
- if (!ctx->Req.encrypt)
- m_inputCtx = ctx;
- Dbg("confirm,encrypt,len,timeout:%d,%d,%d,%d", m_ctx->Req.confirm, m_ctx->Req.encrypt, m_ctx->Req.length, m_ctx->Req.timeout);
- }
- else
- {
- m_ctx = NULL;
- m_inputSMCtx = ctxSM;
- Dbg("sm ctx,confirm,encrypt,len,timeout:%d,%d,%d,%d", m_inputSMCtx->Req.confirm, m_inputSMCtx->Req.encrypt, m_inputSMCtx->Req.length, m_inputSMCtx->Req.timeout);
- }
- Dbg("setpininput true");
- m_bPinInput = true;
- }
- bool GetCtx(SpReqAnsContext<PinPadService_GetInput_Req, PinPadService_GetInput_Ans>::Pointer &ctx
- ,SpReqAnsContext<PinPadService_GetInputSM_Req, PinPadService_GetInputSM_Ans>::Pointer &ctxSM,bool &smFlag)
- {
- if (m_ctx == NULL && m_inputSMCtx == NULL)
- {
- Dbg("both ctx is null");
- return false;
- }
- if (m_inputSMCtx != NULL)
- {
- ctxSM = m_inputSMCtx;
- smFlag = true;
- }
- else
- {
- ctx = m_ctx;
- smFlag = false;
- }
- return true;
- }
- template <class TReq, class TAns>
- void SaveCtx(int methodID, CSmartPointer<SpReqAnsContext<TReq, TAns> > ctx)
- {
- m_mapCtx[methodID].pCtx = static_cast<void*>(ctx.GetRawPointer());
- }
- LPVOID GetCtx(int methodID)
- {
- if (m_mapCtx.find(methodID) != m_mapCtx.end())
- return m_mapCtx[methodID].pCtx;
- else
- return NULL;
- }
- //HANDLE GetInputEvtHandle(){return m_hInputEvt;}
-
- bool GetDevInfo(DevCategoryInfo &devInfo);
- int LoadKey(SpReqAnsContext<PinPadService_LoadKeys_Req, PinPadService_LoadKeys_Ans>::Pointer ctx);
- int Encrypt(SpReqAnsContext<PinPadService_EncryptData_Req, PinPadService_EncryptData_Ans>::Pointer ctx);
- int LoadKeySM(SpReqAnsContext<PinPadService_LoadKeysSM_Req, PinPadService_LoadKeysSM_Ans>::Pointer ctx);
- int EncryptSM(SpReqAnsContext<PinPadService_EncryptDataSM_Req, PinPadService_EncryptDataSM_Ans>::Pointer ctx);
- int GetCheckCode(SpReqAnsContext<PinPadService_GetCheckCode_Req, PinPadService_GetCheckCode_Ans>::Pointer ctx);
- int GetEncryptKey(int &devFunc,int &loadFunc)
- {
- devFunc = loadFunc = 0;
- devFunc = m_encryptkey;
- int tmp = 0;
- if (m_b3DESLoaded)
- tmp = 1;
- if (m_bSMLoaded)
- tmp += 2;
- loadFunc = tmp;
- //20161216 oilyang add 为了兼容密钥更新有问题的设备
- if (loadFunc == 0)
- loadFunc = 1;
- return 0;
- }
- BOOL IsNeedPinPad()
- {
- return (!m_bPinPadNeedless);
- }
- void SetEnterMainPage(bool bValue);
- int LocalCallHeartBeat(int method, CBlob &bbSend, bool bTwoWay=false);
- void CrossTermCall(SpReqAnsContext<PinPadService_CrossTermCall_Req, PinPadService_CrossTermCall_Ans>::Pointer ctx);
- void CrossTermInvokeInfo(SpOnewayCallContext<PinPadService_CrossTermInvokeInfo_Info>::Pointer ctx);
- void SelfTest(EntityTestEnum eTestType,CSmartPointer<ITransactionContext> pTransactionContext);
- public:
- SP::Toolkit::CConditionVarPlus m_hInputConVar;
- SP::Toolkit::CConditionVarPlus m_hInitConVar;
- private:
- SpReqAnsContext<PinPadService_GetInput_Req, PinPadService_GetInput_Ans>::Pointer m_ctx;
- SpReqAnsContext<PinPadService_GetInput_Req, PinPadService_GetInput_Ans>::Pointer m_inputCtx;
- SpReqAnsContext<PinPadService_GetInputSM_Req, PinPadService_GetInputSM_Ans>::Pointer m_inputSMCtx;
- char m_szAccount[MAX_ACCOUNT_LEN];
- bool m_bDevInit,m_bFrontCancel,m_bWaitingMore,m_bExit,m_bPlainPin,m_bEntityExit
- ,m_bPinInput,m_bPlainOpen,m_bLoadKey,m_bEncrypt,m_bSM,m_b3DESLoaded,m_bSMLoaded,m_bInMainPage
- , m_bRVCIL;
- CSimpleStringA m_deviceNo,m_devCheckData,m_keySN,m_keySNSM,m_szModel,m_szType,m_szVendor, m_devSN;
- char m_buf[4];
- ErrorCodeEnum m_testResult;
- DWORD m_dwDevCommFailCount,m_dwPinPadRunCount;
- DevStateEnum m_eDevState;
- int m_encryptkey;
- CSimpleStringA m_csMachineType, m_csSite, m_terminalNo;
- BOOL m_bPinPadNeedless;
- //HardwareEntityCode m_entCode;
- CSimpleStringA m_csAlarmMsg;
- map<int, CtxInfo> m_mapCtx;
- ErrorPackage m_errPkg;
- AdapterInfo m_adapterInfo;
- bool GetAttachedTerminal(CSimpleStringA &csTerm);
- };
- struct InitTask : public ITaskSp
- {
- CPinPadFSM *fsm;
-
- InitTask(CPinPadFSM* f) : fsm(f) {}
- void Process()
- {
- FSMEvent *e = new FSMEvent(USER_EVT_INITFINISHED);
- e->param1 = fsm->Initial();
- fsm->PostEventFIFO(e);
- }
- };
- //struct GetInputTask : public ITaskSp
- //{
- // CPinPadFSM* fsm;
- // SpReqAnsContext<PinPadService_GetInput_Req, PinPadService_GetInput_Ans>::Pointer ctx;
- // GetInputTask(CPinPadFSM* f) : fsm(f) {}
- // void Process()
- // {
- // LOG_FUNCTION();
- // FSMEvent *e = new FSMEvent(USER_EVT_GETINPUTFINISHED);
- // e->param1 = fsm->GetInput(ctx);
- // fsm->PostEventFIFO(e);
- // }
- //};
- struct LoadKeyTask : public ITaskSp
- {
- CPinPadFSM* fsm;
- SpReqAnsContext<PinPadService_LoadKeys_Req, PinPadService_LoadKeys_Ans>::Pointer ctx;
- LoadKeyTask(CPinPadFSM* f) : fsm(f) {}
- void Process()
- {
- LOG_FUNCTION();
- FSMEvent *e = new FSMEvent(USER_EVT_LOADKEYFINISHED);
- e->param1 = fsm->LoadKey(ctx);
- fsm->PostEventFIFO(e);
- }
- };
- struct EncryptTask : public ITaskSp
- {
- CPinPadFSM* fsm;
- SpReqAnsContext<PinPadService_EncryptData_Req, PinPadService_EncryptData_Ans>::Pointer ctx;
- EncryptTask(CPinPadFSM* f) : fsm(f) {}
- void Process()
- {
- LOG_FUNCTION();
- FSMEvent *e = new FSMEvent(USER_EVT_ENCRYPTFINISHED);
- e->param1 = fsm->Encrypt(ctx);
- fsm->PostEventFIFO(e);
- }
- };
- //struct GetInputSMTask : public ITaskSp
- //{
- // CPinPadFSM* fsm;
- // SpReqAnsContext<PinPadService_GetInputSM_Req, PinPadService_GetInputSM_Ans>::Pointer ctx;
- // GetInputSMTask(CPinPadFSM* f) : fsm(f) {}
- // void Process()
- // {
- // LOG_FUNCTION();
- // FSMEvent *e = new FSMEvent(USER_EVT_GETINPUT_SM_FINISHED);
- // e->param1 = fsm->GetInput(ctx);
- // fsm->PostEventFIFO(e);
- // }
- //};
- struct LoadKeySMTask : public ITaskSp
- {
- CPinPadFSM* fsm;
- SpReqAnsContext<PinPadService_LoadKeysSM_Req, PinPadService_LoadKeysSM_Ans>::Pointer ctx;
- LoadKeySMTask(CPinPadFSM* f) : fsm(f) {}
- void Process()
- {
- LOG_FUNCTION();
- FSMEvent *e = new FSMEvent(USER_EVT_LOADKEY_SM_FINISHED);
- e->param1 = fsm->LoadKeySM(ctx);
- fsm->PostEventFIFO(e);
- }
- };
- struct EncryptSMTask : public ITaskSp
- {
- CPinPadFSM* fsm;
- SpReqAnsContext<PinPadService_EncryptDataSM_Req, PinPadService_EncryptDataSM_Ans>::Pointer ctx;
- EncryptSMTask(CPinPadFSM* f) : fsm(f) {}
- void Process()
- {
- LOG_FUNCTION();
- FSMEvent *e = new FSMEvent(USER_EVT_ENCRYPT_SM_FINISHED);
- e->param1 = fsm->EncryptSM(ctx);
- fsm->PostEventFIFO(e);
- }
- };
- struct GetCheckCodeTask : public ITaskSp
- {
- CPinPadFSM* fsm;
- SpReqAnsContext<PinPadService_GetCheckCode_Req, PinPadService_GetCheckCode_Ans>::Pointer ctx;
- GetCheckCodeTask(CPinPadFSM* f) : fsm(f) {}
- void Process()
- {
- LOG_FUNCTION();
- FSMEvent *e = new FSMEvent(USER_EVT_GET_CHECKCODE_FINISHED);
- e->param1 = fsm->GetCheckCode(ctx);
- fsm->PostEventFIFO(e);
- }
- };
- template<class T>
- class TimerOutHelper : public ITimerListener
- {
- public:
- typedef void (T::*FuncTimer)(void *pUserdata);
- TimerOutHelper(T *p, FuncTimer pTimerFunc, void *pUserData, bool bDeleteSelf = false)
- : m_pObject(p), m_pUserData(pUserData), m_pTimer(pTimerFunc), m_bDeleteSelf(bDeleteSelf) {}
- virtual void OnTimeout(DWORD dwTimerID)
- {
- (m_pObject->*m_pTimer)(m_pUserData);
- if (m_bDeleteSelf)
- delete this;
- }
- private:
- void *m_pUserData;
- T *m_pObject;
- FuncTimer m_pTimer;
- bool m_bDeleteSelf;
- };
- #endif //__PINPAD_FSM_H
|