mod_cardswiper.h 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  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. using namespace CardSwiper;
  7. class CCardSwiperEntity;
  8. class CardSwiperServerSession : public CardSwiperService_ServerSessionBase
  9. {
  10. public:
  11. CardSwiperServerSession(CCardSwiperEntity* pEntity):m_pEntity(pEntity){}
  12. virtual ~CardSwiperServerSession(){}
  13. virtual void Handle_Read(SpReqAnsContext<CardSwiperService_Read_Req, CardSwiperService_Read_Ans>::Pointer ctx);
  14. virtual void Handle_PreOnline(SpReqAnsContext<CardSwiperService_PreOnline_Req, CardSwiperService_PreOnline_Ans>::Pointer ctx);
  15. virtual void Handle_PostOnline(SpReqAnsContext<CardSwiperService_PostOnline_Req, CardSwiperService_PostOnline_Ans>::Pointer ctx);
  16. virtual void Handle_Exit(SpOnewayCallContext<CardSwiperService_Exit_Info>::Pointer ctx);
  17. virtual void Handle_GetDevInfo(SpReqAnsContext<CardSwiperService_GetDevInfo_Req, CardSwiperService_GetDevInfo_Ans>::Pointer ctx);
  18. virtual void Handle_CancelInsert(SpOnewayCallContext<CardSwiperService_CancelInsert_Info>::Pointer ctx);
  19. virtual void Handle_Eject(SpReqAnsContext<CardSwiperService_Eject_Req, CardSwiperService_Eject_Ans>::Pointer ctx);
  20. virtual void Handle_QueryCardInfo(SpReqAnsContext<CardSwiperService_QueryCardInfo_Req, CardSwiperService_QueryCardInfo_Ans>::Pointer ctx);
  21. virtual void Handle_MagTransferInit(SpReqAnsContext<CardSwiperService_MagTransferInit_Req, CardSwiperService_MagTransferInit_Ans>::Pointer ctx);
  22. virtual void Handle_QueryConnInfo(SpReqAnsContext<CardSwiperService_QueryConnInfo_Req, CardSwiperService_QueryConnInfo_Ans>::Pointer ctx);
  23. virtual void Handle_InsertWaitMore(SpOnewayCallContext<CardSwiperService_InsertWaitMore_Info>::Pointer ctx);
  24. virtual void Handle_QueryFWBList(SpReqAnsContext<CardSwiperService_QueryFWBList_Req, CardSwiperService_QueryFWBList_Ans>::Pointer ctx);
  25. virtual void Handle_BindFWB(SpReqAnsContext<CardSwiperService_BindFWB_Req, CardSwiperService_BindFWB_Ans>::Pointer ctx);
  26. private:
  27. CCardSwiperEntity* m_pEntity;
  28. };
  29. class CCardSwiperEntity : public CDevAdptEntityBase, public ILogListener, public ISysVarListener
  30. {
  31. public:
  32. CCardSwiperEntity()
  33. {
  34. }
  35. virtual ~CCardSwiperEntity(){}
  36. virtual const char *GetEntityName() const { return "CardSwiper"; }
  37. virtual void OnPreStart(CAutoArray<CSimpleStringA> strArgs,CSmartPointer<ITransactionContext> pTransactionContext)
  38. {
  39. LOG_FUNCTION();
  40. GetVendorLibName();
  41. ErrorCodeEnum eStart = m_fsm.Init(this);
  42. GetFunction()->SubscribeLog(m_uuidAccessAuth, this,
  43. Log_Error, Severity_Middle, Error_IgnoreAll, -1, "AccessAuthorization");
  44. GetFunction()->SubscribeLog(m_uuidAccessAuth, this,
  45. Log_Event, Severity_Middle, Error_IgnoreAll, -1, "AccessAuthorization");
  46. GetFunction()->RegistSysVarEvent("UIState", this);
  47. if (eStart == Error_Succeed)
  48. {
  49. //oiltest no gpio for current
  50. //m_pGpioClient = new GpioService_ClientBase(this);
  51. //ErrorCodeEnum ErrorConn = m_pGpioClient->Connect();
  52. //if (ErrorConn != Error_Succeed) {
  53. // m_pGpioClient->SafeDelete();
  54. // m_pGpioClient = NULL;
  55. //}
  56. //else
  57. // Dbg("gpio connected.");
  58. }
  59. pTransactionContext->SendAnswer(eStart);
  60. //ErrorCodeEnum Error = __OnStart(Error_Succeed);
  61. //pTransactionContext->SendAnswer(Error);
  62. }
  63. virtual void OnPreClose(EntityCloseCauseEnum eCloseCause,CSmartPointer<ITransactionContext> pTransactionContext)
  64. {
  65. ErrorCodeEnum Error = __OnStart(Error_Succeed);
  66. pTransactionContext->SendAnswer(Error);
  67. }
  68. virtual void OnPrePause(CSmartPointer<ITransactionContext> pTransactionContext)
  69. {
  70. ErrorCodeEnum Error = __OnPause(Error_Succeed);
  71. pTransactionContext->SendAnswer(Error);
  72. }
  73. virtual ErrorCodeEnum __OnStart(ErrorCodeEnum preOperationError)
  74. {
  75. return Error_Succeed;
  76. }
  77. virtual ErrorCodeEnum __OnPause(ErrorCodeEnum preOperationError)
  78. {
  79. m_fsm.QueryFWBList(NULL, 2);//oiltest
  80. return Error_Succeed;
  81. }
  82. virtual ErrorCodeEnum __OnClose(ErrorCodeEnum preOperationError)
  83. {
  84. return Error_Succeed;
  85. }
  86. virtual void OnSelfTest(EntityTestEnum eTestType,CSmartPointer<ITransactionContext> pTransactionContext)
  87. {
  88. m_fsm.SelfTest(eTestType,pTransactionContext);
  89. }
  90. virtual CServerSessionBase* OnNewSession(const char*,const char*)
  91. {
  92. return new CardSwiperServerSession(this);
  93. }
  94. void Read(SpReqAnsContext<CardSwiperService_Read_Req, CardSwiperService_Read_Ans>::Pointer ctx)
  95. {
  96. LOG_FUNCTION();
  97. m_fsm.SetAcceptWaitMore(false);
  98. CardReadEvent* e = new CardReadEvent();
  99. e->ctx = ctx;
  100. m_fsm.PostEventFIFO(e);
  101. }
  102. void PreOnline(SpReqAnsContext<CardSwiperService_PreOnline_Req, CardSwiperService_PreOnline_Ans>::Pointer ctx)
  103. {
  104. LOG_FUNCTION();
  105. PreOnlineEvent* e = new PreOnlineEvent();
  106. e->ctx = ctx;
  107. m_fsm.PostEventFIFO(e);
  108. }
  109. void PostOnline(SpReqAnsContext<CardSwiperService_PostOnline_Req, CardSwiperService_PostOnline_Ans>::Pointer ctx)
  110. {
  111. LOG_FUNCTION();
  112. PostOnlineEvent* e = new PostOnlineEvent();
  113. e->ctx = ctx;
  114. m_fsm.PostEventFIFO(e);
  115. }
  116. void Exit(SpOnewayCallContext<CardSwiperService_Exit_Info>::Pointer ctx)
  117. {
  118. //LOG_FUNCTION();
  119. FSMEvent *evt = new FSMEvent(USER_EVT_EXIT);
  120. m_fsm.PostEventFIFO(evt);
  121. }
  122. void CancelInsert(SpOnewayCallContext<CardSwiperService_CancelInsert_Info>::Pointer ctx)
  123. {
  124. m_fsm.SetAcceptWaitMore(false);
  125. FSMEvent *evt = new FSMEvent(USER_EVT_CANCELINSERT);
  126. m_fsm.PostEventFIFO(evt);
  127. }
  128. void Eject(SpReqAnsContext<CardSwiperService_Eject_Req, CardSwiperService_Eject_Ans>::Pointer ctx)
  129. {
  130. ctx->Answer(Error_Succeed);
  131. FSMEvent *pEvt = new FSMEvent(USER_EVT_EJECT);
  132. m_fsm.PostEventFIFO(pEvt);
  133. }
  134. void QueryCardInfo(SpReqAnsContext<CardSwiperService_QueryCardInfo_Req, CardSwiperService_QueryCardInfo_Ans>::Pointer ctx)
  135. {
  136. LOG_FUNCTION();
  137. QueryCardInfoEvent* e = new QueryCardInfoEvent();
  138. e->ctx = ctx;
  139. m_fsm.PostEventFIFO(e);
  140. }
  141. void MagTransferInit(SpReqAnsContext<CardSwiperService_MagTransferInit_Req, CardSwiperService_MagTransferInit_Ans>::Pointer ctx)
  142. {
  143. LOG_FUNCTION();
  144. MagDataTransferInitEvent * e = new MagDataTransferInitEvent();
  145. e->ctx = ctx;
  146. m_fsm.PostEventFIFO(e);
  147. }
  148. void QueryConnInfo(SpReqAnsContext<CardSwiperService_QueryConnInfo_Req, CardSwiperService_QueryConnInfo_Ans>::Pointer ctx)
  149. {
  150. ctx->Ans.connect = m_fsm.QueryConnStatus();
  151. ctx->Answer(Error_Succeed);
  152. }
  153. void InsertWaitMore(SpOnewayCallContext<CardSwiperService_InsertWaitMore_Info>::Pointer ctx)
  154. {
  155. m_fsm.SetAcceptWaitMore(true);
  156. }
  157. void QueryFWBList(SpReqAnsContext<CardSwiperService_QueryFWBList_Req, CardSwiperService_QueryFWBList_Ans>::Pointer ctx)
  158. {
  159. QueryFWBListEvent* pEvt = new QueryFWBListEvent();
  160. pEvt->ctx = ctx;
  161. m_fsm.PostEventFIFO(pEvt);
  162. }
  163. void BindFWB(SpReqAnsContext<CardSwiperService_BindFWB_Req, CardSwiperService_BindFWB_Ans>::Pointer ctx)
  164. {
  165. BindFWBEvent* pEvt = new BindFWBEvent();
  166. pEvt->ctx = ctx;
  167. m_fsm.PostEventFIFO(pEvt);
  168. }
  169. void GetDevInfo(SpReqAnsContext<CardSwiperService_GetDevInfo_Req, CardSwiperService_GetDevInfo_Ans>::Pointer ctx)
  170. {
  171. ctx->Ans.state = m_fsm.GetDevState();
  172. ctx->Answer(Error_Succeed);
  173. }
  174. virtual bool IsService()const{return true;}
  175. virtual bool IsMultiThread()const{return true;}
  176. virtual void OnLog(const CAutoArray<CUUID> &SubIDs, const CUUID nLogID, const LogTypeEnum eLogType, const SeverityLevelEnum eLevel,
  177. const DWORD dwSysError, const DWORD dwUserCode, const DWORD dwEntityInstanceID, const WORD wEntityDevelID,
  178. const CAutoArray<DWORD> &Param, const char *pszEntityName, const char *pszModuleName, const char *pszMessage);
  179. virtual void OnSysVarEvent(const char* pszKey,const char* pszValue, const char* pszOldValue, const char* pszEntityName);
  180. protected:
  181. private:
  182. CardSwiperClass* m_pCardIss;
  183. CCardSwiperFSM m_fsm;
  184. LONG m_lenAPDU;
  185. BYTE m_APDUsendBuf[512];
  186. CUUID m_uuidAccessAuth;
  187. private:
  188. void ConstructAPDU(BYTE cls,BYTE ins,BYTE p1,BYTE p2,BYTE lc,LPBYTE data,LPBYTE le)
  189. {
  190. LOG_FUNCTION();
  191. m_lenAPDU = 0;
  192. m_APDUsendBuf[0] = cls;
  193. m_APDUsendBuf[1] = ins;
  194. m_APDUsendBuf[2] = p1;
  195. m_APDUsendBuf[3] = p2;
  196. m_lenAPDU = 4;
  197. if (lc != NULL && data != NULL)
  198. {
  199. m_APDUsendBuf[4] = lc;
  200. m_lenAPDU++;
  201. if (lc != 0)
  202. {
  203. memcpy(m_APDUsendBuf+m_lenAPDU,data,lc);
  204. m_lenAPDU += lc;
  205. }
  206. }
  207. if (le != NULL)
  208. m_APDUsendBuf[m_lenAPDU++] = (*le);
  209. if (!data)
  210. {
  211. delete[] data;
  212. data = NULL;
  213. }
  214. Dbg("cmd len[%d]",m_lenAPDU);
  215. }
  216. };