mod_ContactlessCard.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. #ifndef _MOD_CONTACTLESS_H
  2. #define _MOD_CONTACTLESS_H
  3. #pragma once
  4. #include "stdafx.h"
  5. #include "ContactlessFSM.h"
  6. #include "modVer.h"
  7. #include "SpTest.h"
  8. class CContactlessCardEntity;
  9. class ContactlessCardServerSession : public ContactlessCardService_ServerSessionBase
  10. {
  11. public:
  12. ContactlessCardServerSession(CContactlessCardEntity* pEntity):m_pEntity(pEntity){}
  13. virtual ~ContactlessCardServerSession(){}
  14. virtual void Handle_Insert(SpReqAnsContext<ContactlessCardService_Insert_Req, ContactlessCardService_Insert_Ans>::Pointer ctx);
  15. virtual void Handle_CancelInsert(SpOnewayCallContext<ContactlessCardService_CancelInsert_Info>::Pointer ctx);
  16. virtual void Handle_InsertWaitMore(SpOnewayCallContext<ContactlessCardService_InsertWaitMore_Info>::Pointer ctx);
  17. virtual void Handle_PreOnline(SpReqAnsContext<ContactlessCardService_PreOnline_Req, ContactlessCardService_PreOnline_Ans>::Pointer ctx);
  18. virtual void Handle_PostOnline(SpReqAnsContext<ContactlessCardService_PostOnline_Req, ContactlessCardService_PostOnline_Ans>::Pointer ctx);
  19. virtual void Handle_Eject(SpReqAnsContext<ContactlessCardService_Eject_Req, ContactlessCardService_Eject_Ans>::Pointer ctx);
  20. virtual void Handle_Exit(SpOnewayCallContext<ContactlessCardService_Exit_Info>::Pointer ctx);
  21. virtual void Handle_QueryCardInfo(SpReqAnsContext<ContactlessCardService_QueryCardInfo_Req, ContactlessCardService_QueryCardInfo_Ans>::Pointer ctx);
  22. virtual void Handle_GetDevInfo(SpReqAnsContext<ContactlessCardService_GetDevInfo_Req, ContactlessCardService_GetDevInfo_Ans>::Pointer ctx);
  23. private:
  24. CContactlessCardEntity* m_pEntity;
  25. };
  26. class CContactlessCardEntity : public CDevAdptEntityBase
  27. {
  28. public:
  29. CContactlessCardEntity()
  30. {
  31. }
  32. virtual ~CContactlessCardEntity(){}
  33. virtual const char *GetEntityName() const { return "ContactlessCard"; }
  34. virtual const char* GetEntityVersion() const { return MODULE_VERSION_FULL; }
  35. ON_ENTITYT_TEST()
  36. virtual void OnPreStart(CAutoArray<CSimpleStringA> strArgs,CSmartPointer<ITransactionContext> pTransactionContext)
  37. {
  38. LOG_FUNCTION();
  39. //MessageBoxA(0,0,0,0);
  40. ErrorCodeEnum eStart = m_fsm.Init(this);
  41. if (eStart == Error_Succeed)
  42. {
  43. }
  44. pTransactionContext->SendAnswer(eStart);
  45. }
  46. virtual void OnPreClose(EntityCloseCauseEnum eCloseCause,CSmartPointer<ITransactionContext> pTransactionContext)
  47. {
  48. ErrorCodeEnum Error = __OnStart(Error_Succeed);
  49. pTransactionContext->SendAnswer(Error);
  50. }
  51. virtual void OnPrePause(CSmartPointer<ITransactionContext> pTransactionContext)
  52. {
  53. ErrorCodeEnum Error = __OnPause(Error_Succeed);
  54. pTransactionContext->SendAnswer(Error);
  55. }
  56. virtual ErrorCodeEnum __OnStart(ErrorCodeEnum preOperationError)
  57. {
  58. return Error_Succeed;
  59. }
  60. virtual ErrorCodeEnum __OnPause(ErrorCodeEnum preOperationError)
  61. {
  62. return Error_Succeed;
  63. }
  64. virtual ErrorCodeEnum __OnClose(ErrorCodeEnum preOperationError)
  65. {
  66. return Error_Succeed;
  67. }
  68. void Insert(SpReqAnsContext<ContactlessCardService_Insert_Req, ContactlessCardService_Insert_Ans>::Pointer ctx)
  69. {
  70. LOG_FUNCTION();
  71. m_fsm.SetExitFlag(false);
  72. CardAcceptEvent* e = new CardAcceptEvent();
  73. e->ctx = ctx;
  74. m_fsm.PostEventFIFO(e);
  75. }
  76. void CancelInsert(SpOnewayCallContext<ContactlessCardService_CancelInsert_Info>::Pointer ctx)
  77. {
  78. LOG_FUNCTION();
  79. FSMEvent *evt = new FSMEvent(USER_EVT_ACCEPT_CANCEL);
  80. m_fsm.PostEventFIFO(evt);
  81. }
  82. void InsertWaitMore(SpOnewayCallContext<ContactlessCardService_InsertWaitMore_Info>::Pointer ctx)
  83. {
  84. if (m_fsm.GetWaitFlag())
  85. m_fsm.SetWaitMore();
  86. }
  87. void PreOnline(SpReqAnsContext<ContactlessCardService_PreOnline_Req, ContactlessCardService_PreOnline_Ans>::Pointer ctx)
  88. {
  89. LOG_FUNCTION();
  90. PreOnlineEvent* e = new PreOnlineEvent();
  91. e->ctx = ctx;
  92. m_fsm.PostEventFIFO(e);
  93. }
  94. void PostOnline(SpReqAnsContext<ContactlessCardService_PostOnline_Req, ContactlessCardService_PostOnline_Ans>::Pointer ctx)
  95. {
  96. LOG_FUNCTION();
  97. PostOnlineEvent* e = new PostOnlineEvent();
  98. e->ctx = ctx;
  99. m_fsm.PostEventFIFO(e);
  100. }
  101. void Eject(SpReqAnsContext<ContactlessCardService_Eject_Req, ContactlessCardService_Eject_Ans>::Pointer ctx)
  102. {
  103. LOG_FUNCTION();
  104. CardEjectEvent* e = new CardEjectEvent();
  105. e->ctx = ctx;
  106. m_fsm.PostEventFIFO(e);
  107. }
  108. void Exit(SpOnewayCallContext<ContactlessCardService_Exit_Info>::Pointer ctx)
  109. {
  110. LOG_FUNCTION();
  111. FSMEvent *evt = new FSMEvent(USER_EVT_EXIT);
  112. m_fsm.PostEventFIFO(evt);
  113. }
  114. void QueryCardInfo(SpReqAnsContext<ContactlessCardService_QueryCardInfo_Req, ContactlessCardService_QueryCardInfo_Ans>::Pointer ctx)
  115. {
  116. LOG_FUNCTION();
  117. QueryCardInfoEvent* e = new QueryCardInfoEvent();
  118. e->ctx = ctx;
  119. m_fsm.PostEventFIFO(e);
  120. }
  121. void GetDevInfo(SpReqAnsContext<ContactlessCardService_GetDevInfo_Req, ContactlessCardService_GetDevInfo_Ans>::Pointer ctx)
  122. {
  123. LOG_FUNCTION();
  124. }
  125. virtual void OnSelfTest(EntityTestEnum eTestType,CSmartPointer<ITransactionContext> pTransactionContext)
  126. {
  127. m_fsm.SelfTest(eTestType,pTransactionContext);
  128. }
  129. virtual CServerSessionBase* OnNewSession(const char*,const char*)
  130. {
  131. return new ContactlessCardServerSession(this);
  132. }
  133. virtual bool IsService()const{return true;}
  134. virtual bool IsMultiThread()const{return true;}
  135. protected:
  136. private:
  137. CContactlessCardFSM m_fsm;
  138. private:
  139. };
  140. #endif //_MOD_CONTACTLESS_H