mod_ContactlessCard.h 5.0 KB

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