PinPadFSM.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520
  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. m_bEntityExit = true;
  225. m_hInputConVar.Broadcast();
  226. }
  227. virtual ErrorCodeEnum OnInit();
  228. virtual ErrorCodeEnum OnExit();
  229. void DoWork();
  230. void s0_on_entry();
  231. void s0_on_exit();
  232. unsigned int s0_on_event(FSMEvent* event);
  233. void s1_on_entry();
  234. void s1_on_exit();
  235. unsigned int s1_on_event(FSMEvent* event);
  236. void s2_on_entry();
  237. void s2_on_exit();
  238. unsigned int s2_on_event(FSMEvent* event);
  239. void s3_on_entry();
  240. void s3_on_exit();
  241. unsigned int s3_on_event(FSMEvent* event);
  242. void s4_on_entry();
  243. void s4_on_exit();
  244. unsigned int s4_on_event(FSMEvent* event);
  245. void s5_on_entry();
  246. void s5_on_exit();
  247. unsigned int s5_on_event(FSMEvent* event);
  248. int Initial();
  249. int GetInput(SpReqAnsContext<PinPadService_GetInput_Req, PinPadService_GetInput_Ans>::Pointer ctx
  250. ,SpReqAnsContext<PinPadService_GetInputSM_Req, PinPadService_GetInputSM_Ans>::Pointer ctxSM,bool bSM=false);
  251. void push_char(char *buf, int *len, int c);
  252. void PushInputChar(char *buf, int c);
  253. void pop_char(char *buf, int *len,bool bClear=true);
  254. void clear_char(char *buf, int *len);
  255. bool Get12Account(char *szAcc);
  256. void OpenInputText(void *pUserdata);
  257. ErrorCodeEnum GetText(SpReqAnsContext<PinPadService_GetInput_Req, PinPadService_GetInput_Ans>::Pointer ctx
  258. ,SpReqAnsContext<PinPadService_GetInputSM_Req, PinPadService_GetInputSM_Ans>::Pointer ctxSM,bool bSM=false);
  259. ErrorCodeEnum GetEncryptText(SpReqAnsContext<PinPadService_GetInput_Req, PinPadService_GetInput_Ans>::Pointer ctx
  260. ,SpReqAnsContext<PinPadService_GetInputSM_Req, PinPadService_GetInputSM_Ans>::Pointer ctxSM,bool bSM=false);
  261. bool GetDevInitFlag(){ return m_bDevInit;}
  262. bool IsRVCIL() { /*return m_bRVCIL; */ return false;}//oilyang@20190123 方案改了,这里暂时不需要了
  263. void SetExitFlag(){m_bExit = true;}
  264. bool GetEntityExit() { return m_bEntityExit;}
  265. void SetCtx(SpReqAnsContext<PinPadService_GetInput_Req, PinPadService_GetInput_Ans>::Pointer ctx
  266. ,SpReqAnsContext<PinPadService_GetInputSM_Req, PinPadService_GetInputSM_Ans>::Pointer ctxSM,bool bSMCtx=false)
  267. {
  268. LOG_FUNCTION();
  269. if (!bSMCtx)
  270. {
  271. m_inputSMCtx = NULL;
  272. m_ctx = ctx;
  273. if (!ctx->Req.encrypt)
  274. m_inputCtx = ctx;
  275. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("confirm,encrypt,len,timeout:%d,%d,%d,%d", m_ctx->Req.confirm, m_ctx->Req.encrypt, m_ctx->Req.length, m_ctx->Req.timeout);
  276. }
  277. else
  278. {
  279. m_ctx = NULL;
  280. m_inputSMCtx = ctxSM;
  281. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("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);
  282. }
  283. DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("setpininput true");
  284. m_bPinInput = true;
  285. }
  286. bool GetCtx(SpReqAnsContext<PinPadService_GetInput_Req, PinPadService_GetInput_Ans>::Pointer &ctx
  287. ,SpReqAnsContext<PinPadService_GetInputSM_Req, PinPadService_GetInputSM_Ans>::Pointer &ctxSM,bool &smFlag)
  288. {
  289. if (m_ctx == NULL && m_inputSMCtx == NULL)
  290. {
  291. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("both ctx is null");
  292. return false;
  293. }
  294. if (m_inputSMCtx != NULL)
  295. {
  296. ctxSM = m_inputSMCtx;
  297. smFlag = true;
  298. }
  299. else
  300. {
  301. ctx = m_ctx;
  302. smFlag = false;
  303. }
  304. return true;
  305. }
  306. template <class TReq, class TAns>
  307. void SaveCtx(int methodID, CSmartPointer<SpReqAnsContext<TReq, TAns> > ctx)
  308. {
  309. m_mapCtx[methodID].pCtx = static_cast<void*>(ctx.GetRawPointer());
  310. }
  311. LPVOID GetCtx(int methodID)
  312. {
  313. if (m_mapCtx.find(methodID) != m_mapCtx.end())
  314. return m_mapCtx[methodID].pCtx;
  315. else
  316. return NULL;
  317. }
  318. //HANDLE GetInputEvtHandle(){return m_hInputEvt;}
  319. bool GetDevInfo(DevCategoryInfo &devInfo);
  320. int LoadKey(SpReqAnsContext<PinPadService_LoadKeys_Req, PinPadService_LoadKeys_Ans>::Pointer ctx);
  321. int Encrypt(SpReqAnsContext<PinPadService_EncryptData_Req, PinPadService_EncryptData_Ans>::Pointer ctx);
  322. int LoadKeySM(SpReqAnsContext<PinPadService_LoadKeysSM_Req, PinPadService_LoadKeysSM_Ans>::Pointer ctx);
  323. int EncryptSM(SpReqAnsContext<PinPadService_EncryptDataSM_Req, PinPadService_EncryptDataSM_Ans>::Pointer ctx);
  324. int GetCheckCode(SpReqAnsContext<PinPadService_GetCheckCode_Req, PinPadService_GetCheckCode_Ans>::Pointer ctx);
  325. int GetEncryptKey(int &devFunc,int &loadFunc)
  326. {
  327. devFunc = loadFunc = 0;
  328. devFunc = m_encryptkey;
  329. int tmp = 0;
  330. if (m_b3DESLoaded)
  331. tmp = 1;
  332. if (m_bSMLoaded)
  333. tmp += 2;
  334. loadFunc = tmp;
  335. //20161216 oilyang add 为了兼容密钥更新有问题的设备
  336. if (loadFunc == 0)
  337. loadFunc = 1;
  338. return 0;
  339. }
  340. BOOL IsNeedPinPad()
  341. {
  342. return (!m_bPinPadNeedless);
  343. }
  344. void SetEnterMainPage(bool bValue);
  345. int LocalCallHeartBeat(int method, CBlob &bbSend, bool bTwoWay=false);
  346. void CrossTermCall(SpReqAnsContext<PinPadService_CrossTermCall_Req, PinPadService_CrossTermCall_Ans>::Pointer ctx);
  347. void CrossTermInvokeInfo(SpOnewayCallContext<PinPadService_CrossTermInvokeInfo_Info>::Pointer ctx);
  348. void SelfTest(EntityTestEnum eTestType,CSmartPointer<ITransactionContext> pTransactionContext);
  349. public:
  350. SP::Toolkit::CConditionVarPlus m_hInputConVar;
  351. SP::Toolkit::CConditionVarPlus m_hInitConVar;
  352. private:
  353. SpReqAnsContext<PinPadService_GetInput_Req, PinPadService_GetInput_Ans>::Pointer m_ctx;
  354. SpReqAnsContext<PinPadService_GetInput_Req, PinPadService_GetInput_Ans>::Pointer m_inputCtx;
  355. SpReqAnsContext<PinPadService_GetInputSM_Req, PinPadService_GetInputSM_Ans>::Pointer m_inputSMCtx;
  356. char m_szAccount[MAX_ACCOUNT_LEN];
  357. bool m_bDevInit,m_bFrontCancel,m_bWaitingMore,m_bExit,m_bPlainPin,m_bEntityExit
  358. ,m_bPinInput,m_bPlainOpen,m_bLoadKey,m_bEncrypt,m_bSM,m_b3DESLoaded,m_bSMLoaded,m_bInMainPage
  359. , m_bRVCIL;
  360. CSimpleStringA m_deviceNo,m_devCheckData,m_keySN,m_keySNSM,m_szModel,m_szType,m_szVendor, m_devSN;
  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. ErrorPackage m_errPkg;
  372. AdapterInfo m_adapterInfo;
  373. bool GetAttachedTerminal(CSimpleStringA &csTerm);
  374. };
  375. struct InitTask : public ITaskSp
  376. {
  377. CPinPadFSM *fsm;
  378. InitTask(CPinPadFSM* f) : fsm(f) {}
  379. void Process()
  380. {
  381. FSMEvent *e = new FSMEvent(USER_EVT_INITFINISHED);
  382. e->param1 = fsm->Initial();
  383. fsm->PostEventFIFO(e);
  384. }
  385. };
  386. //struct GetInputTask : public ITaskSp
  387. //{
  388. // CPinPadFSM* fsm;
  389. // SpReqAnsContext<PinPadService_GetInput_Req, PinPadService_GetInput_Ans>::Pointer ctx;
  390. // GetInputTask(CPinPadFSM* f) : fsm(f) {}
  391. // void Process()
  392. // {
  393. // LOG_FUNCTION();
  394. // FSMEvent *e = new FSMEvent(USER_EVT_GETINPUTFINISHED);
  395. // e->param1 = fsm->GetInput(ctx);
  396. // fsm->PostEventFIFO(e);
  397. // }
  398. //};
  399. struct LoadKeyTask : public ITaskSp
  400. {
  401. CPinPadFSM* fsm;
  402. SpReqAnsContext<PinPadService_LoadKeys_Req, PinPadService_LoadKeys_Ans>::Pointer ctx;
  403. LoadKeyTask(CPinPadFSM* f) : fsm(f) {}
  404. void Process()
  405. {
  406. LOG_FUNCTION();
  407. FSMEvent *e = new FSMEvent(USER_EVT_LOADKEYFINISHED);
  408. e->param1 = fsm->LoadKey(ctx);
  409. fsm->PostEventFIFO(e);
  410. }
  411. };
  412. struct EncryptTask : public ITaskSp
  413. {
  414. CPinPadFSM* fsm;
  415. SpReqAnsContext<PinPadService_EncryptData_Req, PinPadService_EncryptData_Ans>::Pointer ctx;
  416. EncryptTask(CPinPadFSM* f) : fsm(f) {}
  417. void Process()
  418. {
  419. LOG_FUNCTION();
  420. FSMEvent *e = new FSMEvent(USER_EVT_ENCRYPTFINISHED);
  421. e->param1 = fsm->Encrypt(ctx);
  422. fsm->PostEventFIFO(e);
  423. }
  424. };
  425. //struct GetInputSMTask : public ITaskSp
  426. //{
  427. // CPinPadFSM* fsm;
  428. // SpReqAnsContext<PinPadService_GetInputSM_Req, PinPadService_GetInputSM_Ans>::Pointer ctx;
  429. // GetInputSMTask(CPinPadFSM* f) : fsm(f) {}
  430. // void Process()
  431. // {
  432. // LOG_FUNCTION();
  433. // FSMEvent *e = new FSMEvent(USER_EVT_GETINPUT_SM_FINISHED);
  434. // e->param1 = fsm->GetInput(ctx);
  435. // fsm->PostEventFIFO(e);
  436. // }
  437. //};
  438. struct LoadKeySMTask : public ITaskSp
  439. {
  440. CPinPadFSM* fsm;
  441. SpReqAnsContext<PinPadService_LoadKeysSM_Req, PinPadService_LoadKeysSM_Ans>::Pointer ctx;
  442. LoadKeySMTask(CPinPadFSM* f) : fsm(f) {}
  443. void Process()
  444. {
  445. LOG_FUNCTION();
  446. FSMEvent *e = new FSMEvent(USER_EVT_LOADKEY_SM_FINISHED);
  447. e->param1 = fsm->LoadKeySM(ctx);
  448. fsm->PostEventFIFO(e);
  449. }
  450. };
  451. struct EncryptSMTask : public ITaskSp
  452. {
  453. CPinPadFSM* fsm;
  454. SpReqAnsContext<PinPadService_EncryptDataSM_Req, PinPadService_EncryptDataSM_Ans>::Pointer ctx;
  455. EncryptSMTask(CPinPadFSM* f) : fsm(f) {}
  456. void Process()
  457. {
  458. LOG_FUNCTION();
  459. FSMEvent *e = new FSMEvent(USER_EVT_ENCRYPT_SM_FINISHED);
  460. e->param1 = fsm->EncryptSM(ctx);
  461. fsm->PostEventFIFO(e);
  462. }
  463. };
  464. struct GetCheckCodeTask : public ITaskSp
  465. {
  466. CPinPadFSM* fsm;
  467. SpReqAnsContext<PinPadService_GetCheckCode_Req, PinPadService_GetCheckCode_Ans>::Pointer ctx;
  468. GetCheckCodeTask(CPinPadFSM* f) : fsm(f) {}
  469. void Process()
  470. {
  471. LOG_FUNCTION();
  472. FSMEvent *e = new FSMEvent(USER_EVT_GET_CHECKCODE_FINISHED);
  473. e->param1 = fsm->GetCheckCode(ctx);
  474. fsm->PostEventFIFO(e);
  475. }
  476. };
  477. template<class T>
  478. class TimerOutHelper : public ITimerListener
  479. {
  480. public:
  481. typedef void (T::*FuncTimer)(void *pUserdata);
  482. TimerOutHelper(T *p, FuncTimer pTimerFunc, void *pUserData, bool bDeleteSelf = false)
  483. : m_pObject(p), m_pUserData(pUserData), m_pTimer(pTimerFunc), m_bDeleteSelf(bDeleteSelf) {}
  484. virtual void OnTimeout(DWORD dwTimerID)
  485. {
  486. (m_pObject->*m_pTimer)(m_pUserData);
  487. if (m_bDeleteSelf)
  488. delete this;
  489. }
  490. private:
  491. void *m_pUserData;
  492. T *m_pObject;
  493. FuncTimer m_pTimer;
  494. bool m_bDeleteSelf;
  495. };
  496. #endif //__PINPAD_FSM_H