mod_PinPad.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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_InputWaitMore(SpOnewayCallContext<PinPadService_InputWaitMore_Info>::Pointer ctx);
  12. void Handle_InputCancel(SpOnewayCallContext<PinPadService_InputCancel_Info>::Pointer ctx);
  13. void Handle_Exit(SpOnewayCallContext<PinPadService_Exit_Info>::Pointer ctx);
  14. void Handle_GetDevInfo(SpReqAnsContext<PinPadService_GetDevInfo_Req, PinPadService_GetDevInfo_Ans>::Pointer ctx);
  15. void Handle_GetInputSM(SpReqAnsContext<PinPadService_GetInputSM_Req, PinPadService_GetInputSM_Ans>::Pointer ctx);
  16. void Handle_LoadKeysSM(SpReqAnsContext<PinPadService_LoadKeysSM_Req, PinPadService_LoadKeysSM_Ans>::Pointer ctx);
  17. void Handle_EncryptDataSM(SpReqAnsContext<PinPadService_EncryptDataSM_Req, PinPadService_EncryptDataSM_Ans>::Pointer ctx);
  18. void Handle_QueryFunc(SpReqAnsContext<PinPadService_QueryFunc_Req, PinPadService_QueryFunc_Ans>::Pointer ctx);
  19. void Handle_GetCheckCode(SpReqAnsContext<PinPadService_GetCheckCode_Req, PinPadService_GetCheckCode_Ans>::Pointer ctx);
  20. private:
  21. CPinPadEntity* m_pEntity;
  22. };
  23. class CPinPadEntity : public CDevAdptEntityBase, public ISysVarListener
  24. {
  25. public:
  26. CPinPadEntity():m_state(-1){}
  27. virtual ~CPinPadEntity(){}
  28. virtual const char *GetEntityName() const { return "PinPad"; }
  29. virtual void OnPreStart(CAutoArray<CSimpleStringA> strArgs,CSmartPointer<ITransactionContext> pTransactionContext)
  30. {
  31. ErrorCodeEnum Error = __OnStart(Error_Succeed);
  32. GetFunction()->RegistSysVarEvent("UIState", this);
  33. #if defined(RVC_OS_WIN)
  34. GetFunction()->RegistSysVarEvent("FWBReConn", this);
  35. #endif
  36. pTransactionContext->SendAnswer(Error);
  37. }
  38. virtual void OnPreClose(EntityCloseCauseEnum eCloseCause,CSmartPointer<ITransactionContext> pTransactionContext)
  39. {
  40. //ErrorCodeEnum Error = __OnClose(Error_Succeed);
  41. //MessageBoxA(0,0,0,0);
  42. //m_fsm.OnExit();
  43. m_fsm.PostExitEvent();
  44. pTransactionContext->SendAnswer(Error_Succeed);
  45. }
  46. virtual void OnPrePause(CSmartPointer<ITransactionContext> pTransactionContext)
  47. {
  48. ErrorCodeEnum Error = __OnPause(Error_Succeed);
  49. pTransactionContext->SendAnswer(Error);
  50. }
  51. virtual ErrorCodeEnum __OnStart(ErrorCodeEnum preOperationError)
  52. {
  53. LOG_FUNCTION();
  54. //MessageBoxA(0,0,0,0);
  55. ErrorCodeEnum Error = m_fsm.Init(this);
  56. return Error;
  57. }
  58. virtual ErrorCodeEnum __OnPause(ErrorCodeEnum preOperationError)
  59. {
  60. LOG_FUNCTION();
  61. return Error_Succeed;
  62. }
  63. virtual CServerSessionBase* OnNewSession(const char*,const char*)
  64. {
  65. return new PinPadServerSession(this);
  66. }
  67. void InputWaitMore(SpOnewayCallContext<PinPadService_InputWaitMore_Info>::Pointer ctx)
  68. {
  69. LOG_FUNCTION();
  70. InputWaitingMoreEvent *e = new InputWaitingMoreEvent();
  71. m_fsm.PostEventFIFO(e);
  72. }
  73. void InputCancel(SpOnewayCallContext<PinPadService_InputCancel_Info>::Pointer ctx)
  74. {
  75. LOG_FUNCTION();
  76. InputCancelEvent *e = new InputCancelEvent();
  77. m_fsm.PostEventFIFO(e);
  78. }
  79. void Exit(SpOnewayCallContext<PinPadService_Exit_Info>::Pointer ctx)
  80. {
  81. //LOG_FUNCTION();
  82. FSMEvent *evt = new FSMEvent(USER_EVT_EXIT);
  83. m_fsm.PostEventFIFO(evt);
  84. }
  85. void GetInputSM(SpReqAnsContext<PinPadService_GetInputSM_Req, PinPadService_GetInputSM_Ans>::Pointer ctx)
  86. {
  87. if (!m_fsm.GetDevInitFlag())
  88. {
  89. ctx->Answer(Error_DevNotAvailable, PinPad_UserErrorCode_PinPad_DevOpenFailed);
  90. LogWarn(Severity_Middle, Error_DevNotAvailable, PinPad_UserErrorCode_PinPad_DevOpenFailed, "Open PinPad failed(GetInputSM)");
  91. }else{
  92. m_fsm.SetCtx(ctx);
  93. GetInputSMEvent* e = new GetInputSMEvent();
  94. e->ctx = ctx;
  95. m_fsm.PostEventFIFO(e);
  96. }
  97. }
  98. void LoadKeysSM(SpReqAnsContext<PinPadService_LoadKeysSM_Req, PinPadService_LoadKeysSM_Ans>::Pointer ctx)
  99. {
  100. LOG_FUNCTION();
  101. if(!m_fsm.GetDevInitFlag())
  102. ctx->Answer(Error_DevNotAvailable, PinPad_UserErrorCode_PinPad_DevOpenFailed);
  103. else{
  104. LoadKeySMEvent *evt = new LoadKeySMEvent();
  105. evt->ctx = ctx;
  106. m_fsm.PostEventFIFO(evt);
  107. }
  108. }
  109. void EncryptDataSM(SpReqAnsContext<PinPadService_EncryptDataSM_Req, PinPadService_EncryptDataSM_Ans>::Pointer ctx)
  110. {
  111. LOG_FUNCTION();
  112. if(!m_fsm.GetDevInitFlag())
  113. ctx->Answer(Error_DevNotAvailable, PinPad_UserErrorCode_PinPad_DevOpenFailed);
  114. else{
  115. EncryptSMEvent *evt = new EncryptSMEvent();
  116. evt->ctx = ctx;
  117. m_fsm.PostEventFIFO(evt);
  118. }
  119. }
  120. void QueryFunc(SpReqAnsContext<PinPadService_QueryFunc_Req, PinPadService_QueryFunc_Ans>::Pointer ctx)
  121. {
  122. if (m_fsm.GetDevInitFlag())
  123. {
  124. m_fsm.GetEncryptKey(ctx->Ans.encryptkey, ctx->Ans.reserved1);
  125. ctx->Answer(Error_Succeed);
  126. }
  127. else{
  128. ctx->Answer(Error_DevNotAvailable, PinPad_UserErrorCode_PinPad_DevOpenFailed);
  129. }
  130. }
  131. void GetCheckCode(SpReqAnsContext<PinPadService_GetCheckCode_Req, PinPadService_GetCheckCode_Ans>::Pointer ctx)
  132. {
  133. if(!m_fsm.GetDevInitFlag())
  134. ctx->Answer(Error_DevNotAvailable, PinPad_UserErrorCode_PinPad_DevOpenFailed);
  135. else{
  136. GetCheckCodeEvent *evt = new GetCheckCodeEvent();
  137. evt->ctx = ctx;
  138. m_fsm.PostEventFIFO(evt);
  139. }
  140. }
  141. void GetDevInfo(SpReqAnsContext<PinPadService_GetDevInfo_Req, PinPadService_GetDevInfo_Ans>::Pointer ctx)
  142. {
  143. if (m_fsm.GetDevInitFlag())
  144. {
  145. DevCategoryInfo devInfo;
  146. memset(&devInfo, 0, sizeof(devInfo));
  147. if (m_fsm.GetDevInfo(devInfo))
  148. {
  149. ctx->Ans.model = devInfo.szModel;
  150. ctx->Ans.type = devInfo.szType;
  151. }
  152. ctx->Ans.state = devInfo.eState;
  153. ctx->Answer(Error_Succeed);
  154. }
  155. else
  156. ctx->Answer(Error_DevNotAvailable, PinPad_UserErrorCode_PinPad_DevOpenFailed);
  157. }
  158. bool GetDevInitInfo() { return m_fsm.GetDevInitFlag(); }
  159. virtual void OnSysVarEvent(const char *pszKey,
  160. const char *pszValue, const char *pszOldValue, const char *pszEntityName);
  161. virtual bool IsService()const{return true;}
  162. virtual bool IsMultiThread()const{return true;}
  163. virtual void OnSelfTest(EntityTestEnum eTestType,CSmartPointer<ITransactionContext> pTransactionContext)
  164. {
  165. m_fsm.SelfTest(eTestType,pTransactionContext);
  166. }
  167. protected:
  168. private:
  169. CPinPadFSM m_fsm;
  170. int m_state;
  171. };
  172. #endif //__MOD_PINPAD_H