mod_cardswiper.h 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. #include "CardSwiper_server_g.h"
  2. #include "CardSwiper_def_g.h"
  3. #include "CardSwiperClass.h"
  4. #include "CardSwiperFSM.h"
  5. #include "DevEntityCommBase.hpp"
  6. #include "modVer.h"
  7. using namespace CardSwiper;
  8. class CCardSwiperEntity;
  9. class CardSwiperServerSession : public CardSwiperService_ServerSessionBase
  10. {
  11. public:
  12. CardSwiperServerSession(CCardSwiperEntity* pEntity):m_pEntity(pEntity){}
  13. virtual ~CardSwiperServerSession(){}
  14. virtual void Handle_Read(SpReqAnsContext<CardSwiperService_Read_Req, CardSwiperService_Read_Ans>::Pointer ctx);
  15. virtual void Handle_PreOnline(SpReqAnsContext<CardSwiperService_PreOnline_Req, CardSwiperService_PreOnline_Ans>::Pointer ctx);
  16. virtual void Handle_PostOnline(SpReqAnsContext<CardSwiperService_PostOnline_Req, CardSwiperService_PostOnline_Ans>::Pointer ctx);
  17. virtual void Handle_Exit(SpOnewayCallContext<CardSwiperService_Exit_Info>::Pointer ctx);
  18. virtual void Handle_GetDevInfo(SpReqAnsContext<CardSwiperService_GetDevInfo_Req, CardSwiperService_GetDevInfo_Ans>::Pointer ctx);
  19. virtual void Handle_CancelInsert(SpOnewayCallContext<CardSwiperService_CancelInsert_Info>::Pointer ctx);
  20. virtual void Handle_Eject(SpReqAnsContext<CardSwiperService_Eject_Req, CardSwiperService_Eject_Ans>::Pointer ctx);
  21. virtual void Handle_QueryCardInfo(SpReqAnsContext<CardSwiperService_QueryCardInfo_Req, CardSwiperService_QueryCardInfo_Ans>::Pointer ctx);
  22. virtual void Handle_MagTransferInit(SpReqAnsContext<CardSwiperService_MagTransferInit_Req, CardSwiperService_MagTransferInit_Ans>::Pointer ctx);
  23. virtual void Handle_QueryConnInfo(SpReqAnsContext<CardSwiperService_QueryConnInfo_Req, CardSwiperService_QueryConnInfo_Ans>::Pointer ctx);
  24. virtual void Handle_InsertWaitMore(SpOnewayCallContext<CardSwiperService_InsertWaitMore_Info>::Pointer ctx);
  25. virtual void Handle_QueryFWBList(SpReqAnsContext<CardSwiperService_QueryFWBList_Req, CardSwiperService_QueryFWBList_Ans>::Pointer ctx);
  26. virtual void Handle_BindFWB(SpReqAnsContext<CardSwiperService_BindFWB_Req, CardSwiperService_BindFWB_Ans>::Pointer ctx);
  27. private:
  28. CCardSwiperEntity* m_pEntity;
  29. };
  30. class CCardSwiperEntity : public CDevAdptEntityBase, public ILogListener, public ISysVarListener
  31. {
  32. public:
  33. CCardSwiperEntity()
  34. {
  35. }
  36. virtual ~CCardSwiperEntity(){}
  37. virtual const char *GetEntityName() const { return "CardSwiper"; }
  38. virtual const char* GetEntityVersion() const
  39. {
  40. return MODULE_VERSION_FULL;
  41. }
  42. virtual void OnPreStart(CAutoArray<CSimpleStringA> strArgs,CSmartPointer<ITransactionContext> pTransactionContext)
  43. {
  44. LOG_FUNCTION();
  45. GetVendorLibName();
  46. ErrorCodeEnum eStart = m_fsm.Init(this);
  47. GetFunction()->SubscribeLog(m_uuidAccessAuth, this,
  48. Log_Error, Severity_Middle, Error_IgnoreAll, -1, "AccessAuthorization");
  49. GetFunction()->SubscribeLog(m_uuidAccessAuth, this,
  50. Log_Event, Severity_Middle, Error_IgnoreAll, -1, "AccessAuthorization");
  51. GetFunction()->RegistSysVarEvent("UIState", this);
  52. pTransactionContext->SendAnswer(eStart);
  53. }
  54. virtual void OnPreClose(EntityCloseCauseEnum eCloseCause,CSmartPointer<ITransactionContext> pTransactionContext)
  55. {
  56. ErrorCodeEnum Error = __OnStart(Error_Succeed);
  57. pTransactionContext->SendAnswer(Error);
  58. }
  59. virtual void OnPrePause(CSmartPointer<ITransactionContext> pTransactionContext)
  60. {
  61. ErrorCodeEnum Error = __OnPause(Error_Succeed);
  62. pTransactionContext->SendAnswer(Error);
  63. }
  64. virtual ErrorCodeEnum __OnStart(ErrorCodeEnum preOperationError)
  65. {
  66. return Error_Succeed;
  67. }
  68. virtual ErrorCodeEnum __OnPause(ErrorCodeEnum preOperationError)
  69. {
  70. m_fsm.QueryFWBList(NULL, 2);//oiltest
  71. return Error_Succeed;
  72. }
  73. virtual ErrorCodeEnum __OnClose(ErrorCodeEnum preOperationError)
  74. {
  75. return Error_Succeed;
  76. }
  77. virtual void OnSelfTest(EntityTestEnum eTestType,CSmartPointer<ITransactionContext> pTransactionContext)
  78. {
  79. m_fsm.SelfTest(eTestType,pTransactionContext);
  80. }
  81. virtual CServerSessionBase* OnNewSession(const char*,const char*)
  82. {
  83. return new CardSwiperServerSession(this);
  84. }
  85. void Read(SpReqAnsContext<CardSwiperService_Read_Req, CardSwiperService_Read_Ans>::Pointer ctx)
  86. {
  87. LOG_FUNCTION();
  88. m_fsm.SetAcceptWaitMore(false);
  89. CardReadEvent* e = new CardReadEvent();
  90. e->ctx = ctx;
  91. m_fsm.PostEventFIFO(e);
  92. }
  93. void PreOnline(SpReqAnsContext<CardSwiperService_PreOnline_Req, CardSwiperService_PreOnline_Ans>::Pointer ctx)
  94. {
  95. LOG_FUNCTION();
  96. PreOnlineEvent* e = new PreOnlineEvent();
  97. e->ctx = ctx;
  98. m_fsm.PostEventFIFO(e);
  99. }
  100. void PostOnline(SpReqAnsContext<CardSwiperService_PostOnline_Req, CardSwiperService_PostOnline_Ans>::Pointer ctx)
  101. {
  102. LOG_FUNCTION();
  103. PostOnlineEvent* e = new PostOnlineEvent();
  104. e->ctx = ctx;
  105. m_fsm.PostEventFIFO(e);
  106. }
  107. void Exit(SpOnewayCallContext<CardSwiperService_Exit_Info>::Pointer ctx)
  108. {
  109. FSMEvent *evt = new FSMEvent(USER_EVT_EXIT);
  110. m_fsm.PostEventFIFO(evt);
  111. }
  112. void CancelInsert(SpOnewayCallContext<CardSwiperService_CancelInsert_Info>::Pointer ctx)
  113. {
  114. m_fsm.SetAcceptWaitMore(false);
  115. FSMEvent *evt = new FSMEvent(USER_EVT_CANCELINSERT);
  116. m_fsm.PostEventFIFO(evt);
  117. }
  118. void Eject(SpReqAnsContext<CardSwiperService_Eject_Req, CardSwiperService_Eject_Ans>::Pointer ctx)
  119. {
  120. ctx->Answer(Error_Succeed);
  121. FSMEvent *pEvt = new FSMEvent(USER_EVT_EJECT);
  122. m_fsm.PostEventFIFO(pEvt);
  123. }
  124. void QueryCardInfo(SpReqAnsContext<CardSwiperService_QueryCardInfo_Req, CardSwiperService_QueryCardInfo_Ans>::Pointer ctx)
  125. {
  126. LOG_FUNCTION();
  127. QueryCardInfoEvent* e = new QueryCardInfoEvent();
  128. e->ctx = ctx;
  129. m_fsm.PostEventFIFO(e);
  130. }
  131. void MagTransferInit(SpReqAnsContext<CardSwiperService_MagTransferInit_Req, CardSwiperService_MagTransferInit_Ans>::Pointer ctx)
  132. {
  133. LOG_FUNCTION();
  134. MagDataTransferInitEvent * e = new MagDataTransferInitEvent();
  135. e->ctx = ctx;
  136. m_fsm.PostEventFIFO(e);
  137. }
  138. void QueryConnInfo(SpReqAnsContext<CardSwiperService_QueryConnInfo_Req, CardSwiperService_QueryConnInfo_Ans>::Pointer ctx)
  139. {
  140. ctx->Ans.connect = m_fsm.QueryConnStatus();
  141. ctx->Answer(Error_Succeed);
  142. }
  143. void InsertWaitMore(SpOnewayCallContext<CardSwiperService_InsertWaitMore_Info>::Pointer ctx)
  144. {
  145. m_fsm.SetAcceptWaitMore(true);
  146. }
  147. void QueryFWBList(SpReqAnsContext<CardSwiperService_QueryFWBList_Req, CardSwiperService_QueryFWBList_Ans>::Pointer ctx)
  148. {
  149. QueryFWBListEvent* pEvt = new QueryFWBListEvent();
  150. pEvt->ctx = ctx;
  151. m_fsm.PostEventFIFO(pEvt);
  152. }
  153. void BindFWB(SpReqAnsContext<CardSwiperService_BindFWB_Req, CardSwiperService_BindFWB_Ans>::Pointer ctx)
  154. {
  155. BindFWBEvent* pEvt = new BindFWBEvent();
  156. pEvt->ctx = ctx;
  157. m_fsm.PostEventFIFO(pEvt);
  158. }
  159. void GetDevInfo(SpReqAnsContext<CardSwiperService_GetDevInfo_Req, CardSwiperService_GetDevInfo_Ans>::Pointer ctx)
  160. {
  161. ctx->Ans.state = m_fsm.GetDevState();
  162. ctx->Answer(Error_Succeed);
  163. }
  164. virtual bool IsService()const{return true;}
  165. virtual bool IsMultiThread()const{return true;}
  166. virtual void OnLog(const CAutoArray<CUUID> &SubIDs, const CUUID nLogID,
  167. const LogTypeEnum eLogType, const SeverityLevelEnum eLevel,
  168. const DWORD dwSysError, const DWORD dwUserCode,
  169. const DWORD dwEntityInstanceID, const WORD wEntityDevelID,
  170. const CAutoArray<DWORD> &Param, const char *pszEntityName,
  171. const char *pszModuleName, const char *pszMessage);
  172. virtual void OnSysVarEvent(const char* pszKey,const char* pszValue,
  173. const char* pszOldValue, const char* pszEntityName);
  174. private:
  175. CardSwiperClass* m_pCardIss;
  176. CCardSwiperFSM m_fsm;
  177. CUUID m_uuidAccessAuth;
  178. };