PinPadFSM.h 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559
  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("")
  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. }
  221. ~CPinPadFSM(){
  222. Dbg("~CPinPadFSM");
  223. m_bEntityExit = true;
  224. m_hInputConVar.Broadcast();
  225. }
  226. virtual ErrorCodeEnum OnInit();
  227. virtual ErrorCodeEnum OnExit();
  228. void DoWork();
  229. void s0_on_entry();
  230. void s0_on_exit();
  231. unsigned int s0_on_event(FSMEvent* event);
  232. void s1_on_entry();
  233. void s1_on_exit();
  234. unsigned int s1_on_event(FSMEvent* event);
  235. void s2_on_entry();
  236. void s2_on_exit();
  237. unsigned int s2_on_event(FSMEvent* event);
  238. void s3_on_entry();
  239. void s3_on_exit();
  240. unsigned int s3_on_event(FSMEvent* event);
  241. void s4_on_entry();
  242. void s4_on_exit();
  243. unsigned int s4_on_event(FSMEvent* event);
  244. void s5_on_entry();
  245. void s5_on_exit();
  246. unsigned int s5_on_event(FSMEvent* event);
  247. int Initial();
  248. int GetInput(SpReqAnsContext<PinPadService_GetInput_Req, PinPadService_GetInput_Ans>::Pointer ctx
  249. ,SpReqAnsContext<PinPadService_GetInputSM_Req, PinPadService_GetInputSM_Ans>::Pointer ctxSM,bool bSM=false);
  250. void push_char(char *buf, int *len, int c);
  251. void PushInputChar(char *buf, int c);
  252. void pop_char(char *buf, int *len,bool bClear=true);
  253. void clear_char(char *buf, int *len);
  254. bool Get12Account(char *szAcc);
  255. void OpenInputText(void *pUserdata);
  256. ErrorCodeEnum GetText(SpReqAnsContext<PinPadService_GetInput_Req, PinPadService_GetInput_Ans>::Pointer ctx
  257. ,SpReqAnsContext<PinPadService_GetInputSM_Req, PinPadService_GetInputSM_Ans>::Pointer ctxSM,bool bSM=false);
  258. ErrorCodeEnum GetEncryptText(SpReqAnsContext<PinPadService_GetInput_Req, PinPadService_GetInput_Ans>::Pointer ctx
  259. ,SpReqAnsContext<PinPadService_GetInputSM_Req, PinPadService_GetInputSM_Ans>::Pointer ctxSM,bool bSM=false);
  260. bool GetDevInitFlag(){ return m_bDevInit;}
  261. bool IsRVCIL() { /*return m_bRVCIL; */ return false;}//oilyang@20190123 方案改了,这里暂时不需要了
  262. void SetExitFlag(){m_bExit = true;}
  263. bool GetEntityExit() { return m_bEntityExit;}
  264. void SetCtx(SpReqAnsContext<PinPadService_GetInput_Req, PinPadService_GetInput_Ans>::Pointer ctx
  265. ,SpReqAnsContext<PinPadService_GetInputSM_Req, PinPadService_GetInputSM_Ans>::Pointer ctxSM,bool bSMCtx=false)
  266. {
  267. LOG_FUNCTION();
  268. if (!bSMCtx)
  269. {
  270. m_inputSMCtx = NULL;
  271. m_ctx = ctx;
  272. if (!ctx->Req.encrypt)
  273. m_inputCtx = ctx;
  274. 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);
  275. }
  276. else
  277. {
  278. m_ctx = NULL;
  279. m_inputSMCtx = ctxSM;
  280. 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);
  281. }
  282. Dbg("setpininput true");
  283. m_bPinInput = true;
  284. }
  285. bool GetCtx(SpReqAnsContext<PinPadService_GetInput_Req, PinPadService_GetInput_Ans>::Pointer &ctx
  286. ,SpReqAnsContext<PinPadService_GetInputSM_Req, PinPadService_GetInputSM_Ans>::Pointer &ctxSM,bool &smFlag)
  287. {
  288. if (m_ctx == NULL && m_inputSMCtx == NULL)
  289. {
  290. Dbg("both ctx is null");
  291. return false;
  292. }
  293. if (m_inputSMCtx != NULL)
  294. {
  295. ctxSM = m_inputSMCtx;
  296. smFlag = true;
  297. }
  298. else
  299. {
  300. ctx = m_ctx;
  301. smFlag = false;
  302. }
  303. return true;
  304. }
  305. template <class TReq, class TAns>
  306. void SaveCtx(int methodID, CSmartPointer<SpReqAnsContext<TReq, TAns> > ctx)
  307. {
  308. m_mapCtx[methodID].pCtx = static_cast<void*>(ctx.GetRawPointer());
  309. }
  310. LPVOID GetCtx(int methodID)
  311. {
  312. if (m_mapCtx.find(methodID) != m_mapCtx.end())
  313. return m_mapCtx[methodID].pCtx;
  314. else
  315. return NULL;
  316. }
  317. //HANDLE GetInputEvtHandle(){return m_hInputEvt;}
  318. bool GetDevInfo(DevCategoryInfo &devInfo);
  319. int LoadKey(SpReqAnsContext<PinPadService_LoadKeys_Req, PinPadService_LoadKeys_Ans>::Pointer ctx);
  320. int Encrypt(SpReqAnsContext<PinPadService_EncryptData_Req, PinPadService_EncryptData_Ans>::Pointer ctx);
  321. int LoadKeySM(SpReqAnsContext<PinPadService_LoadKeysSM_Req, PinPadService_LoadKeysSM_Ans>::Pointer ctx);
  322. int EncryptSM(SpReqAnsContext<PinPadService_EncryptDataSM_Req, PinPadService_EncryptDataSM_Ans>::Pointer ctx);
  323. int GetCheckCode(SpReqAnsContext<PinPadService_GetCheckCode_Req, PinPadService_GetCheckCode_Ans>::Pointer ctx);
  324. int GetEncryptKey(int &devFunc,int &loadFunc)
  325. {
  326. devFunc = loadFunc = 0;
  327. devFunc = m_encryptkey;
  328. int tmp = 0;
  329. if (m_b3DESLoaded)
  330. tmp = 1;
  331. if (m_bSMLoaded)
  332. tmp += 2;
  333. loadFunc = tmp;
  334. //20161216 oilyang add 为了兼容密钥更新有问题的设备
  335. if (loadFunc == 0)
  336. loadFunc = 1;
  337. return 0;
  338. }
  339. BOOL IsNeedPinPad()
  340. {
  341. return (!m_bPinPadNeedless);
  342. }
  343. void SetEnterMainPage(bool bValue);
  344. int LocalCallHeartBeat(int method, CBlob &bbSend, bool bTwoWay=false);
  345. void CrossTermCall(SpReqAnsContext<PinPadService_CrossTermCall_Req, PinPadService_CrossTermCall_Ans>::Pointer ctx);
  346. void CrossTermInvokeInfo(SpOnewayCallContext<PinPadService_CrossTermInvokeInfo_Info>::Pointer ctx);
  347. void SelfTest(EntityTestEnum eTestType,CSmartPointer<ITransactionContext> pTransactionContext);
  348. public:
  349. SP::Toolkit::CConditionVarPlus m_hInputConVar;
  350. SP::Toolkit::CConditionVarPlus m_hInitConVar;
  351. private:
  352. SpReqAnsContext<PinPadService_GetInput_Req, PinPadService_GetInput_Ans>::Pointer m_ctx;
  353. SpReqAnsContext<PinPadService_GetInput_Req, PinPadService_GetInput_Ans>::Pointer m_inputCtx;
  354. SpReqAnsContext<PinPadService_GetInputSM_Req, PinPadService_GetInputSM_Ans>::Pointer m_inputSMCtx;
  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. CSimpleStringA m_deviceNo,m_devCheckData,m_keySN,m_keySNSM,m_szModel,m_szType,m_szVendor;
  360. char m_buf[4];
  361. ErrorCodeEnum m_testResult;
  362. DWORD m_dwDevCommFailCount,m_dwPinPadRunCount;
  363. DevStateEnum m_eDevState;
  364. int m_encryptkey;
  365. CSimpleStringA m_csMachineType, m_csSite, m_terminalNo;
  366. BOOL m_bPinPadNeedless;
  367. //HardwareEntityCode m_entCode;
  368. CSimpleStringA m_csAlarmMsg;
  369. map<int, CtxInfo> m_mapCtx;
  370. DWORD UpdateDEC(DWORD dwVal = 0)
  371. {
  372. int reserved = 0;
  373. reserved = (dwVal & 0xFC000) >> 14;
  374. HARDWARE_ENTITY_SET_DEVCODE(m_entCode, dwVal, reserved);
  375. return GetDEC();
  376. }
  377. DWORD GetDEC() const
  378. {
  379. return HARDWARE_ENTITY_MAKE_ERRORCODE(m_entCode);
  380. }
  381. DWORD AlarmDEC(DWORD dwVal = 0) {
  382. if (dwVal > 0)
  383. UpdateDEC(dwVal);
  384. //oilyang@20200525 if have been set ErrorCode of entity defined (not device),use it directly
  385. DWORD dwCode = 0;
  386. if ((m_entCode.dwVendorErroCode >> 20) == m_entCode.dwEntityId)
  387. dwCode = m_entCode.dwVendorErroCode;
  388. else
  389. dwCode = HARDWARE_ENTITY_MAKE_ERRORCODE_TO_BUSINESS(m_entCode);
  390. return dwCode;
  391. }
  392. DWORD AlarmDECToBusiness(DWORD dwVal = 0) {
  393. if (dwVal > 0)
  394. UpdateDEC(dwVal);
  395. //oilyang@20200528 according the meeting result,throw a LogError while answering ctx
  396. //oilyang@20200525 if have been set ErrorCode of entity defined (not device),use it directly
  397. DWORD dwCode = 0;
  398. if ((m_entCode.dwVendorErroCode >> 20) == m_entCode.dwEntityId)
  399. dwCode = m_entCode.dwVendorErroCode;
  400. else
  401. dwCode = HARDWARE_ENTITY_MAKE_ERRORCODE_TO_BUSINESS(m_entCode);
  402. LogError(Severity_Middle, Error_Unexpect, dwCode, "");
  403. return dwCode;
  404. }
  405. void ClearRelatedDEC()
  406. {
  407. UpdateDEC();
  408. m_csAlarmMsg = "NO more information";
  409. }
  410. void LogErrMsg(const char *pMsgHead, ErrorCodeEnum eErrCode, DWORD defaultDevCode = 0, BOOL bAlarm = FALSE, BOOL bError = FALSE);
  411. bool GetAttachedTerminal(CSimpleStringA &csTerm);
  412. };
  413. struct InitTask : public ITaskSp
  414. {
  415. CPinPadFSM *fsm;
  416. InitTask(CPinPadFSM* f) : fsm(f) {}
  417. void Process()
  418. {
  419. FSMEvent *e = new FSMEvent(USER_EVT_INITFINISHED);
  420. e->param1 = fsm->Initial();
  421. fsm->PostEventFIFO(e);
  422. }
  423. };
  424. //struct GetInputTask : public ITaskSp
  425. //{
  426. // CPinPadFSM* fsm;
  427. // SpReqAnsContext<PinPadService_GetInput_Req, PinPadService_GetInput_Ans>::Pointer ctx;
  428. // GetInputTask(CPinPadFSM* f) : fsm(f) {}
  429. // void Process()
  430. // {
  431. // LOG_FUNCTION();
  432. // FSMEvent *e = new FSMEvent(USER_EVT_GETINPUTFINISHED);
  433. // e->param1 = fsm->GetInput(ctx);
  434. // fsm->PostEventFIFO(e);
  435. // }
  436. //};
  437. struct LoadKeyTask : public ITaskSp
  438. {
  439. CPinPadFSM* fsm;
  440. SpReqAnsContext<PinPadService_LoadKeys_Req, PinPadService_LoadKeys_Ans>::Pointer ctx;
  441. LoadKeyTask(CPinPadFSM* f) : fsm(f) {}
  442. void Process()
  443. {
  444. LOG_FUNCTION();
  445. FSMEvent *e = new FSMEvent(USER_EVT_LOADKEYFINISHED);
  446. e->param1 = fsm->LoadKey(ctx);
  447. fsm->PostEventFIFO(e);
  448. }
  449. };
  450. struct EncryptTask : public ITaskSp
  451. {
  452. CPinPadFSM* fsm;
  453. SpReqAnsContext<PinPadService_EncryptData_Req, PinPadService_EncryptData_Ans>::Pointer ctx;
  454. EncryptTask(CPinPadFSM* f) : fsm(f) {}
  455. void Process()
  456. {
  457. LOG_FUNCTION();
  458. FSMEvent *e = new FSMEvent(USER_EVT_ENCRYPTFINISHED);
  459. e->param1 = fsm->Encrypt(ctx);
  460. fsm->PostEventFIFO(e);
  461. }
  462. };
  463. //struct GetInputSMTask : public ITaskSp
  464. //{
  465. // CPinPadFSM* fsm;
  466. // SpReqAnsContext<PinPadService_GetInputSM_Req, PinPadService_GetInputSM_Ans>::Pointer ctx;
  467. // GetInputSMTask(CPinPadFSM* f) : fsm(f) {}
  468. // void Process()
  469. // {
  470. // LOG_FUNCTION();
  471. // FSMEvent *e = new FSMEvent(USER_EVT_GETINPUT_SM_FINISHED);
  472. // e->param1 = fsm->GetInput(ctx);
  473. // fsm->PostEventFIFO(e);
  474. // }
  475. //};
  476. struct LoadKeySMTask : public ITaskSp
  477. {
  478. CPinPadFSM* fsm;
  479. SpReqAnsContext<PinPadService_LoadKeysSM_Req, PinPadService_LoadKeysSM_Ans>::Pointer ctx;
  480. LoadKeySMTask(CPinPadFSM* f) : fsm(f) {}
  481. void Process()
  482. {
  483. LOG_FUNCTION();
  484. FSMEvent *e = new FSMEvent(USER_EVT_LOADKEY_SM_FINISHED);
  485. e->param1 = fsm->LoadKeySM(ctx);
  486. fsm->PostEventFIFO(e);
  487. }
  488. };
  489. struct EncryptSMTask : public ITaskSp
  490. {
  491. CPinPadFSM* fsm;
  492. SpReqAnsContext<PinPadService_EncryptDataSM_Req, PinPadService_EncryptDataSM_Ans>::Pointer ctx;
  493. EncryptSMTask(CPinPadFSM* f) : fsm(f) {}
  494. void Process()
  495. {
  496. LOG_FUNCTION();
  497. FSMEvent *e = new FSMEvent(USER_EVT_ENCRYPT_SM_FINISHED);
  498. e->param1 = fsm->EncryptSM(ctx);
  499. fsm->PostEventFIFO(e);
  500. }
  501. };
  502. struct GetCheckCodeTask : public ITaskSp
  503. {
  504. CPinPadFSM* fsm;
  505. SpReqAnsContext<PinPadService_GetCheckCode_Req, PinPadService_GetCheckCode_Ans>::Pointer ctx;
  506. GetCheckCodeTask(CPinPadFSM* f) : fsm(f) {}
  507. void Process()
  508. {
  509. LOG_FUNCTION();
  510. FSMEvent *e = new FSMEvent(USER_EVT_GET_CHECKCODE_FINISHED);
  511. e->param1 = fsm->GetCheckCode(ctx);
  512. fsm->PostEventFIFO(e);
  513. }
  514. };
  515. template<class T>
  516. class TimerOutHelper : public ITimerListener
  517. {
  518. public:
  519. typedef void (T::*FuncTimer)(void *pUserdata);
  520. TimerOutHelper(T *p, FuncTimer pTimerFunc, void *pUserData, bool bDeleteSelf = false)
  521. : m_pObject(p), m_pUserData(pUserData), m_pTimer(pTimerFunc), m_bDeleteSelf(bDeleteSelf) {}
  522. virtual void OnTimeout(DWORD dwTimerID)
  523. {
  524. (m_pObject->*m_pTimer)(m_pUserData);
  525. if (m_bDeleteSelf)
  526. delete this;
  527. }
  528. private:
  529. void *m_pUserData;
  530. T *m_pObject;
  531. FuncTimer m_pTimer;
  532. bool m_bDeleteSelf;
  533. };
  534. #endif //__PINPAD_FSM_H