PinPadFSM.h 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553
  1. #ifndef __PINPAD_FSM_H
  2. #define __PINPAD_FSM_H
  3. #pragma once
  4. #include "SpFSM.h"
  5. enum EvtType
  6. {
  7. USER_EVT_TEST = EVT_USER+1,
  8. USER_EVT_ANY_INPUT_TIMER,
  9. USER_EVT_QUIT,
  10. USER_EVT_INIT,
  11. USER_EVT_INITFINISHED,
  12. USER_EVT_GETINPUT,
  13. USER_EVT_GETINPUTFINISHED,
  14. USER_EVT_SETACCOUNT,
  15. USER_EVT_SETACCOUNTFINISHED,
  16. USER_EVT_INPUTCANCEL,
  17. USER_EVT_INPUTWAITINGMORE,
  18. USER_EVT_EXIT,
  19. USER_EVT_LOADKEY,
  20. USER_EVT_LOADKEYFINISHED,
  21. USER_EVT_ENCRYPT,
  22. USER_EVT_ENCRYPTFINISHED,
  23. USER_EVT_GETINPUT_SM,
  24. USER_EVT_GETINPUT_SM_FINISHED,
  25. USER_EVT_LOADKEY_SM,
  26. USER_EVT_LOADKEY_SM_FINISHED,
  27. USER_EVT_ENCRYPT_SM,
  28. USER_EVT_ENCRYPT_SM_FINISHED,
  29. USER_EVT_GET_CHECKCODE,
  30. USER_EVT_GET_CHECKCODE_FINISHED,
  31. };
  32. #include "PinPad_server_g.h"
  33. #include "PinPad_msg_g.h"
  34. #include "PinPadClass.h"
  35. #include "DevErrorCode.h"
  36. #include "DeviceCrossHelper.h"
  37. #include "DeviceBaseHelper.h"
  38. //using namespace PinPad;
  39. using PinPad::PinPadService_GetInput_Req;
  40. using PinPad::PinPadService_GetInput_Ans;
  41. using PinPad::PinPadService_InputWaitMore_Info;
  42. using PinPad::PinPadService_InputCancel_Info;
  43. using PinPad::PinPadService_Exit_Info;
  44. using PinPad::PinPadService_LoadKeys_Req;
  45. using PinPad::PinPadService_LoadKeys_Ans;
  46. using PinPad::PinPadService_EncryptData_Req;
  47. using PinPad::PinPadService_EncryptData_Ans;
  48. using PinPad::PinPadService_GetInputSM_Req;
  49. using PinPad::PinPadService_GetInputSM_Ans;
  50. using PinPad::PinPadService_LoadKeysSM_Req;
  51. using PinPad::PinPadService_LoadKeysSM_Ans;
  52. using PinPad::PinPadService_EncryptDataSM_Req;
  53. using PinPad::PinPadService_EncryptDataSM_Ans;
  54. using PinPad::PinPadService_QueryFunc_Req;
  55. using PinPad::PinPadService_QueryFunc_Ans;
  56. using PinPad::PinPadService_GetCheckCode_Req;
  57. using PinPad::PinPadService_GetCheckCode_Ans;
  58. using PinPad::PinPadService_CrossTermCall_Req;
  59. using PinPad::PinPadService_CrossTermCall_Ans;
  60. using PinPad::PinPadService_CrossTermInvokeInfo_Info;
  61. using PinPad::PinPadService_GetDevInfo_Req;
  62. using PinPad::PinPadService_GetDevInfo_Ans;
  63. using PinPad::InputContent;
  64. #include "HeartBeat_client_g.h"
  65. using namespace HeartBeat;
  66. #include <map>
  67. using namespace std;
  68. #include "DeviceBaseHelper.h"
  69. struct CtxInfo
  70. {
  71. int dataSize;
  72. LPVOID pCtx;
  73. };
  74. //typedef int (WINAPI *lpAa)();
  75. typedef ErrorCodeEnum (*lpCreateDevCom)(DeviceBaseClass *&baseObj);
  76. typedef ErrorCodeEnum ( *lpReleaseDevCom)(DeviceBaseClass *&pBaseObj);
  77. class CPinPadEntity;
  78. class CPinPadFSM;
  79. unsigned int __stdcall DoWork(void *pData);
  80. class PinPadInitFinishedEvent : public FSMEvent
  81. {
  82. public:
  83. PinPadInitFinishedEvent() : FSMEvent(USER_EVT_INITFINISHED){}
  84. ~PinPadInitFinishedEvent(){}
  85. };
  86. class InputCancelEvent : public FSMEvent
  87. {
  88. public:
  89. InputCancelEvent() : FSMEvent(USER_EVT_INPUTCANCEL){}
  90. ~InputCancelEvent(){}
  91. };
  92. class InputWaitingMoreEvent : public FSMEvent
  93. {
  94. public:
  95. InputWaitingMoreEvent() : FSMEvent(USER_EVT_INPUTWAITINGMORE){}
  96. ~InputWaitingMoreEvent(){}
  97. };
  98. class GetInputEvent : public FSMEvent
  99. {
  100. public:
  101. GetInputEvent() : FSMEvent(USER_EVT_GETINPUT){}
  102. ~GetInputEvent(){}
  103. SpReqAnsContext<PinPadService_GetInput_Req, PinPadService_GetInput_Ans>::Pointer ctx;
  104. virtual void OnUnhandled()
  105. {
  106. if (ctx != NULL)
  107. ctx->Answer(Error_InvalidState);
  108. }
  109. };
  110. class LoadKeyEvent : public FSMEvent
  111. {
  112. public:
  113. LoadKeyEvent() : FSMEvent(USER_EVT_LOADKEY){}
  114. ~LoadKeyEvent(){}
  115. SpReqAnsContext<PinPadService_LoadKeys_Req, PinPadService_LoadKeys_Ans>::Pointer ctx;
  116. virtual void OnUnhandled()
  117. {
  118. if (ctx != NULL)
  119. ctx->Answer(Error_InvalidState);
  120. }
  121. };
  122. class EncryptEvent : public FSMEvent
  123. {
  124. public:
  125. EncryptEvent() : FSMEvent(USER_EVT_ENCRYPT){}
  126. ~EncryptEvent(){}
  127. SpReqAnsContext<PinPadService_EncryptData_Req, PinPadService_EncryptData_Ans>::Pointer ctx;
  128. virtual void OnUnhandled()
  129. {
  130. if (ctx != NULL)
  131. ctx->Answer(Error_InvalidState);
  132. }
  133. };
  134. class GetInputSMEvent : public FSMEvent
  135. {
  136. public:
  137. GetInputSMEvent() : FSMEvent(USER_EVT_GETINPUT_SM){}
  138. ~GetInputSMEvent(){}
  139. SpReqAnsContext<PinPadService_GetInputSM_Req, PinPadService_GetInputSM_Ans>::Pointer ctx;
  140. virtual void OnUnhandled()
  141. {
  142. if (ctx != NULL)
  143. ctx->Answer(Error_InvalidState);
  144. }
  145. };
  146. class LoadKeySMEvent : public FSMEvent
  147. {
  148. public:
  149. LoadKeySMEvent() : FSMEvent(USER_EVT_LOADKEY_SM){}
  150. ~LoadKeySMEvent(){}
  151. SpReqAnsContext<PinPadService_LoadKeysSM_Req, PinPadService_LoadKeysSM_Ans>::Pointer ctx;
  152. virtual void OnUnhandled()
  153. {
  154. if (ctx != NULL)
  155. ctx->Answer(Error_InvalidState);
  156. }
  157. };
  158. class EncryptSMEvent : public FSMEvent
  159. {
  160. public:
  161. EncryptSMEvent() : FSMEvent(USER_EVT_ENCRYPT_SM){}
  162. ~EncryptSMEvent(){}
  163. SpReqAnsContext<PinPadService_EncryptDataSM_Req, PinPadService_EncryptDataSM_Ans>::Pointer ctx;
  164. virtual void OnUnhandled()
  165. {
  166. if (ctx != NULL)
  167. ctx->Answer(Error_InvalidState);
  168. }
  169. };
  170. class GetCheckCodeEvent : public FSMEvent
  171. {
  172. public:
  173. GetCheckCodeEvent() : FSMEvent(USER_EVT_GET_CHECKCODE){}
  174. ~GetCheckCodeEvent(){}
  175. SpReqAnsContext<PinPadService_GetCheckCode_Req, PinPadService_GetCheckCode_Ans>::Pointer ctx;
  176. virtual void OnUnhandled()
  177. {
  178. if (ctx != NULL)
  179. ctx->Answer(Error_InvalidState);
  180. }
  181. };
  182. class CPinPadFSM : public FSMImpl<CPinPadFSM>
  183. {
  184. public:
  185. enum {s0,s1,s2,s3,s4,s5};
  186. BEGIN_FSM_STATE(CPinPadFSM)
  187. FSM_STATE_ENTRY(s0, "Init", s0_on_entry, s0_on_exit, s0_on_event)
  188. FSM_STATE_ENTRY(s1, "Initializing", s1_on_entry, s1_on_exit, s1_on_event)
  189. FSM_STATE_ENTRY(s2, "Idle", s2_on_entry, s2_on_exit, s2_on_event)
  190. FSM_STATE_ENTRY(s3, "Input", s3_on_entry, s3_on_exit, s3_on_event)
  191. FSM_STATE_ENTRY(s4, "AccessAuth", s4_on_entry, s4_on_exit, s4_on_event)
  192. FSM_STATE_ENTRY(s5, "Failed", s5_on_entry, s5_on_exit, s5_on_event)
  193. END_FSM_STATE()
  194. BEGIN_FSM_RULE(CPinPadFSM, s0)
  195. FSM_RULE_ENTRY(s0, s1, USER_EVT_INIT, 0)
  196. FSM_RULE_ENTRY(s1, s2, USER_EVT_INITFINISHED, 0)
  197. FSM_RULE_ENTRY(s1, s5, USER_EVT_INITFINISHED, 1)
  198. FSM_RULE_ENTRY(s2, s3, USER_EVT_GETINPUT, 0)
  199. FSM_RULE_ENTRY(s2, s3, USER_EVT_GETINPUT_SM, 0)
  200. FSM_RULE_ENTRY(s2, s4, USER_EVT_LOADKEY, 2)
  201. FSM_RULE_ENTRY(s2, s4, USER_EVT_ENCRYPT, 2)
  202. FSM_RULE_ENTRY(s2, s4, USER_EVT_LOADKEY_SM, 2)
  203. FSM_RULE_ENTRY(s2, s4, USER_EVT_ENCRYPT_SM, 2)
  204. //FSM_RULE_ENTRY(s2,s2,USER_EVT_ANY_INPUT_TIMER,0)
  205. //FSM_RULE_ENTRY(s2,s4,USER_EVT_GETINPUT,0)
  206. FSM_RULE_ENTRY(s3, s2, USER_EVT_GETINPUTFINISHED, 0)
  207. FSM_RULE_ENTRY(s3, s5, USER_EVT_GETINPUTFINISHED, 1)
  208. FSM_RULE_ENTRY(s4, s2, USER_EVT_LOADKEYFINISHED, 0)
  209. FSM_RULE_ENTRY(s4, s2, USER_EVT_ENCRYPTFINISHED, 0)
  210. FSM_RULE_ENTRY(s4, s2, USER_EVT_LOADKEY_SM_FINISHED, 0)
  211. FSM_RULE_ENTRY(s4, s2, USER_EVT_ENCRYPT_SM_FINISHED, 0)
  212. FSM_RULE_ENTRY(s5, s0, USER_EVT_GETINPUT, 0)
  213. FSM_RULE_ENTRY(s5, s0, USER_EVT_LOADKEY, 0)
  214. END_FSM_RULE()
  215. CPinPadFSM() : m_bDevInit(false), m_hVerdorDll(NULL), m_pPinPad(NULL), m_bFrontCancel(false),
  216. m_bWaitingMore(false), m_bExit(false), m_bPlainPin(true), m_ctx(NULL), m_hInputEvt(NULL), m_hInitEvt(NULL),
  217. m_bEntityExit(false), m_bPinInput(false), m_bPlainOpen(false), m_bLoadKey(false), m_bEncrypt(false)
  218. , m_dwDevCommFailCount(0), m_dwPinPadRunCount(0), m_eDevState(DEVICE_STATUS_NOT_READY), m_encryptkey(1)
  219. , m_bSM(false), m_b3DESLoaded(false), m_bSMLoaded(false), m_bInMainPage(true), m_szModel(""), m_szType("")
  220. , m_szVendor(""),m_csMachineType(true), m_csSite(true), m_terminalNo(true), m_bPinPadNeedless(FALSE)
  221. , m_csAlarmMsg("NO more information"), m_bRVCIL(false){
  222. HARDWARE_ENTITY_RESET_ENTITYID(m_entCode, 0x206);
  223. }
  224. ~CPinPadFSM(){}
  225. virtual ErrorCodeEnum OnInit();
  226. virtual ErrorCodeEnum OnExit();
  227. void s0_on_entry();
  228. void s0_on_exit();
  229. unsigned int s0_on_event(FSMEvent* event);
  230. void s1_on_entry();
  231. void s1_on_exit();
  232. unsigned int s1_on_event(FSMEvent* event);
  233. void s2_on_entry();
  234. void s2_on_exit();
  235. unsigned int s2_on_event(FSMEvent* event);
  236. void s3_on_entry();
  237. void s3_on_exit();
  238. unsigned int s3_on_event(FSMEvent* event);
  239. void s4_on_entry();
  240. void s4_on_exit();
  241. unsigned int s4_on_event(FSMEvent* event);
  242. void s5_on_entry();
  243. void s5_on_exit();
  244. unsigned int s5_on_event(FSMEvent* event);
  245. int Initial();
  246. int GetInput(SpReqAnsContext<PinPadService_GetInput_Req, PinPadService_GetInput_Ans>::Pointer ctx
  247. ,SpReqAnsContext<PinPadService_GetInputSM_Req, PinPadService_GetInputSM_Ans>::Pointer ctxSM,bool bSM=false);
  248. void push_char(char *buf, int *len, int c);
  249. void PushInputChar(char *buf, int c);
  250. void pop_char(char *buf, int *len,bool bClear=true);
  251. void clear_char(char *buf, int *len);
  252. bool Get12Account(char *szAcc);
  253. void OpenInputText(void *pUserdata);
  254. ErrorCodeEnum GetText(SpReqAnsContext<PinPadService_GetInput_Req, PinPadService_GetInput_Ans>::Pointer ctx
  255. ,SpReqAnsContext<PinPadService_GetInputSM_Req, PinPadService_GetInputSM_Ans>::Pointer ctxSM,bool bSM=false);
  256. ErrorCodeEnum GetEncryptText(SpReqAnsContext<PinPadService_GetInput_Req, PinPadService_GetInput_Ans>::Pointer ctx
  257. ,SpReqAnsContext<PinPadService_GetInputSM_Req, PinPadService_GetInputSM_Ans>::Pointer ctxSM,bool bSM=false);
  258. bool GetDevInitFlag(){ return m_bDevInit;}
  259. bool IsRVCIL() { /*return m_bRVCIL; */ return false;}//oilyang@20190123 方案改了,这里暂时不需要了
  260. void SetExitFlag(){m_bExit = true;}
  261. bool GetEntityExit() { return m_bEntityExit;}
  262. void SetCtx(SpReqAnsContext<PinPadService_GetInput_Req, PinPadService_GetInput_Ans>::Pointer ctx
  263. ,SpReqAnsContext<PinPadService_GetInputSM_Req, PinPadService_GetInputSM_Ans>::Pointer ctxSM,bool bSMCtx=false)
  264. {
  265. LOG_FUNCTION();
  266. if (!bSMCtx)
  267. {
  268. m_inputSMCtx = NULL;
  269. m_ctx = ctx;
  270. if (!ctx->Req.encrypt)
  271. m_inputCtx = ctx;
  272. 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);
  273. }
  274. else
  275. {
  276. m_ctx = NULL;
  277. m_inputSMCtx = ctxSM;
  278. 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);
  279. }
  280. Dbg("setpininput true");
  281. m_bPinInput = true;
  282. }
  283. bool GetCtx(SpReqAnsContext<PinPadService_GetInput_Req, PinPadService_GetInput_Ans>::Pointer &ctx
  284. ,SpReqAnsContext<PinPadService_GetInputSM_Req, PinPadService_GetInputSM_Ans>::Pointer &ctxSM,bool &smFlag)
  285. {
  286. if (m_ctx == NULL && m_inputSMCtx == NULL)
  287. {
  288. Dbg("both ctx is null");
  289. return false;
  290. }
  291. if (m_inputSMCtx != NULL)
  292. {
  293. ctxSM = m_inputSMCtx;
  294. smFlag = true;
  295. }
  296. else
  297. {
  298. ctx = m_ctx;
  299. smFlag = false;
  300. }
  301. return true;
  302. }
  303. template <class TReq, class TAns>
  304. void SaveCtx(int methodID, CSmartPointer<SpReqAnsContext<TReq, TAns> > ctx)
  305. {
  306. m_mapCtx[methodID].pCtx = static_cast<void*>(ctx.GetRawPointer());
  307. }
  308. LPVOID GetCtx(int methodID)
  309. {
  310. if (m_mapCtx.find(methodID) != m_mapCtx.end())
  311. return m_mapCtx[methodID].pCtx;
  312. else
  313. return NULL;
  314. }
  315. HANDLE GetInputEvtHandle(){return m_hInputEvt;}
  316. bool GetDevInfo(DevCategoryInfo &devInfo);
  317. int LoadKey(SpReqAnsContext<PinPadService_LoadKeys_Req, PinPadService_LoadKeys_Ans>::Pointer ctx);
  318. int Encrypt(SpReqAnsContext<PinPadService_EncryptData_Req, PinPadService_EncryptData_Ans>::Pointer ctx);
  319. int LoadKeySM(SpReqAnsContext<PinPadService_LoadKeysSM_Req, PinPadService_LoadKeysSM_Ans>::Pointer ctx);
  320. int EncryptSM(SpReqAnsContext<PinPadService_EncryptDataSM_Req, PinPadService_EncryptDataSM_Ans>::Pointer ctx);
  321. int GetCheckCode(SpReqAnsContext<PinPadService_GetCheckCode_Req, PinPadService_GetCheckCode_Ans>::Pointer ctx);
  322. int GetEncryptKey(int &devFunc,int &loadFunc)
  323. {
  324. devFunc = loadFunc = 0;
  325. devFunc = m_encryptkey;
  326. int tmp = 0;
  327. if (m_b3DESLoaded)
  328. tmp = 1;
  329. if (m_bSMLoaded)
  330. tmp += 2;
  331. loadFunc = tmp;
  332. //20161216 oilyang add 为了兼容密钥更新有问题的设备
  333. if (loadFunc == 0)
  334. loadFunc = 1;
  335. return 0;
  336. }
  337. BOOL IsNeedPinPad()
  338. {
  339. return (!m_bPinPadNeedless);
  340. }
  341. void SetEnterMainPage(bool bValue);
  342. int LocalCallHeartBeat(int method, CBlob &bbSend, bool bTwoWay=false);
  343. void CrossTermCall(SpReqAnsContext<PinPadService_CrossTermCall_Req, PinPadService_CrossTermCall_Ans>::Pointer ctx);
  344. void CrossTermInvokeInfo(SpOnewayCallContext<PinPadService_CrossTermInvokeInfo_Info>::Pointer ctx);
  345. void SelfTest(EntityTestEnum eTestType,CSmartPointer<ITransactionContext> pTransactionContext);
  346. protected:
  347. private:
  348. HANDLE m_hInputEvt,m_hInitEvt;
  349. HMODULE m_hVerdorDll;
  350. SpReqAnsContext<PinPadService_GetInput_Req, PinPadService_GetInput_Ans>::Pointer m_ctx;
  351. SpReqAnsContext<PinPadService_GetInput_Req, PinPadService_GetInput_Ans>::Pointer m_inputCtx;
  352. SpReqAnsContext<PinPadService_GetInputSM_Req, PinPadService_GetInputSM_Ans>::Pointer m_inputSMCtx;
  353. lpCreateDevCom CreateDevComponent;
  354. lpReleaseDevCom ReleaseDevComponent;
  355. char m_szAccount[MAX_ACCOUNT_LEN];
  356. bool m_bDevInit,m_bFrontCancel,m_bWaitingMore,m_bExit,m_bPlainPin,m_bEntityExit
  357. ,m_bPinInput,m_bPlainOpen,m_bLoadKey,m_bEncrypt,m_bSM,m_b3DESLoaded,m_bSMLoaded,m_bInMainPage
  358. , m_bRVCIL;
  359. PinPadClass* m_pPinPad;
  360. CSimpleStringA m_deviceNo,m_devCheckData,m_keySN,m_keySNSM,m_szModel,m_szType,m_szVendor;
  361. char m_buf[4];
  362. ErrorCodeEnum m_testResult;
  363. DWORD m_dwDevCommFailCount,m_dwPinPadRunCount;
  364. DevStateEnum m_eDevState;
  365. int m_encryptkey;
  366. CSimpleStringA m_csMachineType, m_csSite, m_terminalNo;
  367. BOOL m_bPinPadNeedless;
  368. HardwareEntityCode m_entCode;
  369. CSimpleStringA m_csAlarmMsg;
  370. map<int, CtxInfo> m_mapCtx;
  371. DWORD UpdateDEC(DWORD dwVal = 0)
  372. {
  373. int reserved = 0;
  374. reserved = (dwVal & 0xFC000) >> 14;
  375. HARDWARE_ENTITY_SET_DEVCODE(m_entCode, dwVal, reserved);
  376. return GetDEC();
  377. }
  378. DWORD GetDEC() const
  379. {
  380. return HARDWARE_ENTITY_MAKE_ERRORCODE(m_entCode);
  381. }
  382. //DWORD AlarmDEC() const {
  383. // return GetDEC();
  384. //}
  385. DWORD AlarmDECToBusiness(DWORD dwVal = 0) {
  386. if (dwVal > 0)
  387. UpdateDEC(dwVal);
  388. //oilyang@20200528 according the meeting result,throw a LogError while answering ctx
  389. //oilyang@20200525 if have been set ErrorCode of entity defined (not device),use it directly
  390. DWORD dwCode = 0;
  391. if ((m_entCode.dwVendorErroCode >> 20) == m_entCode.dwEntityId)
  392. dwCode = m_entCode.dwVendorErroCode;
  393. else
  394. dwCode = HARDWARE_ENTITY_MAKE_ERRORCODE_TO_BUSINESS(m_entCode);
  395. LogError(Severity_Middle, Error_Unexpect, dwCode, "");
  396. return dwCode;
  397. }
  398. void ClearRelatedDEC()
  399. {
  400. UpdateDEC();
  401. m_csAlarmMsg = "NO more information";
  402. }
  403. void LogErrMsg(const char *pMsgHead, ErrorCodeEnum eErrCode, DWORD defaultDevCode = 0, BOOL bAlarm = FALSE);
  404. bool GetAttachedTerminal(CSimpleStringA &csTerm);
  405. };
  406. struct InitTask : public ITaskSp
  407. {
  408. CPinPadFSM *fsm;
  409. InitTask(CPinPadFSM* f) : fsm(f) {}
  410. void Process()
  411. {
  412. FSMEvent *e = new FSMEvent(USER_EVT_INITFINISHED);
  413. e->param1 = fsm->Initial();
  414. fsm->PostEventFIFO(e);
  415. }
  416. };
  417. //struct GetInputTask : public ITaskSp
  418. //{
  419. // CPinPadFSM* fsm;
  420. // SpReqAnsContext<PinPadService_GetInput_Req, PinPadService_GetInput_Ans>::Pointer ctx;
  421. // GetInputTask(CPinPadFSM* f) : fsm(f) {}
  422. // void Process()
  423. // {
  424. // LOG_FUNCTION();
  425. // FSMEvent *e = new FSMEvent(USER_EVT_GETINPUTFINISHED);
  426. // e->param1 = fsm->GetInput(ctx);
  427. // fsm->PostEventFIFO(e);
  428. // }
  429. //};
  430. struct LoadKeyTask : public ITaskSp
  431. {
  432. CPinPadFSM* fsm;
  433. SpReqAnsContext<PinPadService_LoadKeys_Req, PinPadService_LoadKeys_Ans>::Pointer ctx;
  434. LoadKeyTask(CPinPadFSM* f) : fsm(f) {}
  435. void Process()
  436. {
  437. LOG_FUNCTION();
  438. FSMEvent *e = new FSMEvent(USER_EVT_LOADKEYFINISHED);
  439. e->param1 = fsm->LoadKey(ctx);
  440. fsm->PostEventFIFO(e);
  441. }
  442. };
  443. struct EncryptTask : public ITaskSp
  444. {
  445. CPinPadFSM* fsm;
  446. SpReqAnsContext<PinPadService_EncryptData_Req, PinPadService_EncryptData_Ans>::Pointer ctx;
  447. EncryptTask(CPinPadFSM* f) : fsm(f) {}
  448. void Process()
  449. {
  450. LOG_FUNCTION();
  451. FSMEvent *e = new FSMEvent(USER_EVT_ENCRYPTFINISHED);
  452. e->param1 = fsm->Encrypt(ctx);
  453. fsm->PostEventFIFO(e);
  454. }
  455. };
  456. //struct GetInputSMTask : public ITaskSp
  457. //{
  458. // CPinPadFSM* fsm;
  459. // SpReqAnsContext<PinPadService_GetInputSM_Req, PinPadService_GetInputSM_Ans>::Pointer ctx;
  460. // GetInputSMTask(CPinPadFSM* f) : fsm(f) {}
  461. // void Process()
  462. // {
  463. // LOG_FUNCTION();
  464. // FSMEvent *e = new FSMEvent(USER_EVT_GETINPUT_SM_FINISHED);
  465. // e->param1 = fsm->GetInput(ctx);
  466. // fsm->PostEventFIFO(e);
  467. // }
  468. //};
  469. struct LoadKeySMTask : public ITaskSp
  470. {
  471. CPinPadFSM* fsm;
  472. SpReqAnsContext<PinPadService_LoadKeysSM_Req, PinPadService_LoadKeysSM_Ans>::Pointer ctx;
  473. LoadKeySMTask(CPinPadFSM* f) : fsm(f) {}
  474. void Process()
  475. {
  476. LOG_FUNCTION();
  477. FSMEvent *e = new FSMEvent(USER_EVT_LOADKEY_SM_FINISHED);
  478. e->param1 = fsm->LoadKeySM(ctx);
  479. fsm->PostEventFIFO(e);
  480. }
  481. };
  482. struct EncryptSMTask : public ITaskSp
  483. {
  484. CPinPadFSM* fsm;
  485. SpReqAnsContext<PinPadService_EncryptDataSM_Req, PinPadService_EncryptDataSM_Ans>::Pointer ctx;
  486. EncryptSMTask(CPinPadFSM* f) : fsm(f) {}
  487. void Process()
  488. {
  489. LOG_FUNCTION();
  490. FSMEvent *e = new FSMEvent(USER_EVT_ENCRYPT_SM_FINISHED);
  491. e->param1 = fsm->EncryptSM(ctx);
  492. fsm->PostEventFIFO(e);
  493. }
  494. };
  495. struct GetCheckCodeTask : public ITaskSp
  496. {
  497. CPinPadFSM* fsm;
  498. SpReqAnsContext<PinPadService_GetCheckCode_Req, PinPadService_GetCheckCode_Ans>::Pointer ctx;
  499. GetCheckCodeTask(CPinPadFSM* f) : fsm(f) {}
  500. void Process()
  501. {
  502. LOG_FUNCTION();
  503. FSMEvent *e = new FSMEvent(USER_EVT_GET_CHECKCODE_FINISHED);
  504. e->param1 = fsm->GetCheckCode(ctx);
  505. fsm->PostEventFIFO(e);
  506. }
  507. };
  508. template<class T>
  509. class TimerOutHelper : public ITimerListener
  510. {
  511. public:
  512. typedef void (T::*FuncTimer)(void *pUserdata);
  513. TimerOutHelper(T *p, FuncTimer pTimerFunc, void *pUserData, bool bDeleteSelf = false)
  514. : m_pObject(p), m_pUserData(pUserData), m_pTimer(pTimerFunc), m_bDeleteSelf(bDeleteSelf) {}
  515. virtual void OnTimeout(DWORD dwTimerID)
  516. {
  517. (m_pObject->*m_pTimer)(m_pUserData);
  518. if (m_bDeleteSelf)
  519. delete this;
  520. }
  521. private:
  522. void *m_pUserData;
  523. T *m_pObject;
  524. FuncTimer m_pTimer;
  525. bool m_bDeleteSelf;
  526. };
  527. #endif //__PINPAD_FSM_H