PinPadFSM.h 16 KB

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