mod_PinPad.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. #ifndef __MOD_PINPAD_H
  2. #define __MOD_PINPAD_H
  3. #include "SpBase.h"
  4. #include "PinPadFSM.h"
  5. #include "DevEntityCommBase.hpp"
  6. class PinPadServerSession : public PinPad::PinPadService_ServerSessionBase
  7. {
  8. public:
  9. PinPadServerSession(CPinPadEntity* pEntity):m_pEntity(pEntity){}
  10. virtual ~PinPadServerSession(){}
  11. void Handle_GetInput(SpReqAnsContext<PinPadService_GetInput_Req, PinPadService_GetInput_Ans>::Pointer ctx);
  12. void Handle_InputWaitMore(SpOnewayCallContext<PinPadService_InputWaitMore_Info>::Pointer ctx);
  13. void Handle_InputCancel(SpOnewayCallContext<PinPadService_InputCancel_Info>::Pointer ctx);
  14. void Handle_Exit(SpOnewayCallContext<PinPadService_Exit_Info>::Pointer ctx);
  15. void Handle_LoadKeys(SpReqAnsContext<PinPadService_LoadKeys_Req, PinPadService_LoadKeys_Ans>::Pointer ctx);
  16. void Handle_EncryptData(SpReqAnsContext<PinPadService_EncryptData_Req, PinPadService_EncryptData_Ans>::Pointer ctx);
  17. void Handle_GetDevInfo(SpReqAnsContext<PinPadService_GetDevInfo_Req, PinPadService_GetDevInfo_Ans>::Pointer ctx);
  18. void Handle_GetInputSM(SpReqAnsContext<PinPadService_GetInputSM_Req, PinPadService_GetInputSM_Ans>::Pointer ctx);
  19. void Handle_LoadKeysSM(SpReqAnsContext<PinPadService_LoadKeysSM_Req, PinPadService_LoadKeysSM_Ans>::Pointer ctx);
  20. void Handle_EncryptDataSM(SpReqAnsContext<PinPadService_EncryptDataSM_Req, PinPadService_EncryptDataSM_Ans>::Pointer ctx);
  21. void Handle_QueryFunc(SpReqAnsContext<PinPadService_QueryFunc_Req, PinPadService_QueryFunc_Ans>::Pointer ctx);
  22. void Handle_GetCheckCode(SpReqAnsContext<PinPadService_GetCheckCode_Req, PinPadService_GetCheckCode_Ans>::Pointer ctx);
  23. void Handle_CrossTermCall(SpReqAnsContext<PinPadService_CrossTermCall_Req, PinPadService_CrossTermCall_Ans>::Pointer ctx);
  24. void Handle_CrossTermInvokeInfo(SpOnewayCallContext<PinPadService_CrossTermInvokeInfo_Info>::Pointer ctx);
  25. private:
  26. CPinPadEntity* m_pEntity;
  27. };
  28. class CPinPadEntity : public CDevAdptEntityBase, public ISysVarListener
  29. {
  30. public:
  31. CPinPadEntity():m_state(-1){}
  32. virtual ~CPinPadEntity(){}
  33. virtual const char *GetEntityName() const { return "PinPad"; }
  34. virtual void OnPreStart(CAutoArray<CSimpleStringA> strArgs,CSmartPointer<ITransactionContext> pTransactionContext)
  35. {
  36. GetVendorLibName();
  37. ErrorCodeEnum Error = __OnStart(Error_Succeed);
  38. GetFunction()->RegistSysVarEvent("UIState", this);
  39. pTransactionContext->SendAnswer(Error);
  40. }
  41. virtual void OnPreClose(EntityCloseCauseEnum eCloseCause,CSmartPointer<ITransactionContext> pTransactionContext)
  42. {
  43. //ErrorCodeEnum Error = __OnClose(Error_Succeed);
  44. //MessageBoxA(0,0,0,0);
  45. //m_fsm.OnExit();
  46. m_fsm.PostExitEvent();
  47. pTransactionContext->SendAnswer(Error_Succeed);
  48. }
  49. virtual void OnPrePause(CSmartPointer<ITransactionContext> pTransactionContext)
  50. {
  51. ErrorCodeEnum Error = __OnPause(Error_Succeed);
  52. pTransactionContext->SendAnswer(Error);
  53. }
  54. virtual ErrorCodeEnum __OnStart(ErrorCodeEnum preOperationError)
  55. {
  56. LOG_FUNCTION();
  57. //MessageBoxA(0,0,0,0);
  58. ErrorCodeEnum Error = m_fsm.Init(this);
  59. return Error;
  60. }
  61. virtual ErrorCodeEnum __OnPause(ErrorCodeEnum preOperationError)
  62. {
  63. LOG_FUNCTION();
  64. return Error_Succeed;
  65. }
  66. virtual CServerSessionBase* OnNewSession(const char*,const char*)
  67. {
  68. LOG_FUNCTION();
  69. return new PinPadServerSession(this);
  70. }
  71. void GetInput(SpReqAnsContext<PinPadService_GetInput_Req, PinPadService_GetInput_Ans>::Pointer ctx)
  72. {
  73. LOG_FUNCTION();
  74. GetInputEvent *e = new GetInputEvent();
  75. e->ctx = ctx;
  76. m_fsm.SetCtx(ctx,NULL);
  77. m_fsm.PostEventFIFO(e);
  78. }
  79. void InputWaitMore(SpOnewayCallContext<PinPadService_InputWaitMore_Info>::Pointer ctx)
  80. {
  81. LOG_FUNCTION();
  82. InputWaitingMoreEvent *e = new InputWaitingMoreEvent();
  83. m_fsm.PostEventFIFO(e);
  84. }
  85. void InputCancel(SpOnewayCallContext<PinPadService_InputCancel_Info>::Pointer ctx)
  86. {
  87. LOG_FUNCTION();
  88. InputCancelEvent *e = new InputCancelEvent();
  89. m_fsm.PostEventFIFO(e);
  90. }
  91. void Exit(SpOnewayCallContext<PinPadService_Exit_Info>::Pointer ctx)
  92. {
  93. //LOG_FUNCTION();
  94. FSMEvent *evt = new FSMEvent(USER_EVT_EXIT);
  95. m_fsm.PostEventFIFO(evt);
  96. }
  97. void LoadKeys(SpReqAnsContext<PinPadService_LoadKeys_Req, PinPadService_LoadKeys_Ans>::Pointer ctx)
  98. {
  99. LOG_FUNCTION();
  100. LoadKeyEvent *evt = new LoadKeyEvent();
  101. evt->ctx = ctx;
  102. m_fsm.PostEventFIFO(evt);
  103. }
  104. void EncryptData(SpReqAnsContext<PinPadService_EncryptData_Req, PinPadService_EncryptData_Ans>::Pointer ctx)
  105. {
  106. LOG_FUNCTION();
  107. EncryptEvent *evt = new EncryptEvent();
  108. evt->ctx = ctx;
  109. m_fsm.PostEventFIFO(evt);
  110. }
  111. void GetInputSM(SpReqAnsContext<PinPadService_GetInputSM_Req, PinPadService_GetInputSM_Ans>::Pointer ctx)
  112. {
  113. LOG_FUNCTION();
  114. m_fsm.SetCtx(NULL, ctx, true);
  115. if (m_fsm.IsRVCIL())
  116. {
  117. CBlob bbSend;
  118. SpObject2Blob(ctx->Req, bbSend);
  119. //m_fsm.SaveCtx(PinPadService_Method_GetInputSM, ctx);
  120. //ctx.AddRef();
  121. m_fsm.LocalCallHeartBeat(PinPadService_Method_GetInputSM, bbSend,true);
  122. }
  123. else
  124. {
  125. GetInputSMEvent *e = new GetInputSMEvent();
  126. e->ctx = ctx;
  127. m_fsm.PostEventFIFO(e);
  128. }
  129. }
  130. void LoadKeysSM(SpReqAnsContext<PinPadService_LoadKeysSM_Req, PinPadService_LoadKeysSM_Ans>::Pointer ctx)
  131. {
  132. LOG_FUNCTION();
  133. LoadKeySMEvent *evt = new LoadKeySMEvent();
  134. evt->ctx = ctx;
  135. m_fsm.PostEventFIFO(evt);
  136. }
  137. void EncryptDataSM(SpReqAnsContext<PinPadService_EncryptDataSM_Req, PinPadService_EncryptDataSM_Ans>::Pointer ctx)
  138. {
  139. LOG_FUNCTION();
  140. EncryptSMEvent *evt = new EncryptSMEvent();
  141. evt->ctx = ctx;
  142. m_fsm.PostEventFIFO(evt);
  143. }
  144. void QueryFunc(SpReqAnsContext<PinPadService_QueryFunc_Req, PinPadService_QueryFunc_Ans>::Pointer ctx)
  145. {
  146. LOG_FUNCTION();
  147. if (m_fsm.GetDevInitFlag())
  148. {
  149. m_fsm.GetEncryptKey(ctx->Ans.encryptkey, ctx->Ans.reserved1);
  150. ctx->Answer(Error_Succeed);
  151. }
  152. else
  153. ctx->Answer(Error_DevNotAvailable);
  154. }
  155. void GetCheckCode(SpReqAnsContext<PinPadService_GetCheckCode_Req, PinPadService_GetCheckCode_Ans>::Pointer ctx)
  156. {
  157. GetCheckCodeEvent *evt = new GetCheckCodeEvent();
  158. evt->ctx = ctx;
  159. m_fsm.PostEventFIFO(evt);
  160. }
  161. void CrossTermCall(SpReqAnsContext<PinPadService_CrossTermCall_Req, PinPadService_CrossTermCall_Ans>::Pointer ctx)
  162. {
  163. m_fsm.CrossTermCall(ctx);
  164. }
  165. void CrossTermInvokeInfo(SpOnewayCallContext<PinPadService_CrossTermInvokeInfo_Info>::Pointer ctx)
  166. {
  167. m_fsm.CrossTermInvokeInfo(ctx);
  168. }
  169. void GetDevInfo(SpReqAnsContext<PinPadService_GetDevInfo_Req, PinPadService_GetDevInfo_Ans>::Pointer ctx)
  170. {
  171. if(m_fsm.IsNeedPinPad())
  172. {
  173. DevCategoryInfo devInfo;
  174. if (m_fsm.GetDevInfo(devInfo))
  175. {
  176. ctx->Ans.model = devInfo.szModel;
  177. ctx->Ans.type = devInfo.szType;
  178. Dbg("szModel:%s", (const char*)ctx->Ans.model);
  179. }
  180. ctx->Ans.state = devInfo.eState;
  181. }
  182. else // 回单打印设备 --Josephus at 8:08:22 201746
  183. {
  184. ctx->Ans.model = "";
  185. ctx->Ans.type = "";
  186. ctx->Ans.state = DEVICE_STATUS_NORMAL;
  187. }
  188. ctx->Answer(Error_Succeed);
  189. }
  190. bool GetDevInitInfo() { return m_fsm.GetDevInitFlag(); }
  191. virtual void OnSysVarEvent(const char *pszKey,
  192. const char *pszValue, const char *pszOldValue, const char *pszEntityName);
  193. virtual bool IsService()const{return true;}
  194. virtual bool IsMultiThread()const{return true;}
  195. virtual void OnSelfTest(EntityTestEnum eTestType,CSmartPointer<ITransactionContext> pTransactionContext)
  196. {
  197. m_fsm.SelfTest(eTestType,pTransactionContext);
  198. }
  199. protected:
  200. private:
  201. CPinPadFSM m_fsm;
  202. int m_state;
  203. };
  204. #endif //__MOD_PINPAD_H