mod_BranchDevice.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. #pragma once
  2. #include "BranchDeviceFSM.h"
  3. using namespace BranchDevice;
  4. class CBranchDeviceEntity;
  5. class CBranchDeviceServerSession: public BranchDeviceService_ServerSessionBase
  6. {
  7. public:
  8. CBranchDeviceServerSession(CBranchDeviceEntity *pEntity):m_pEntity(pEntity){}
  9. virtual ~CBranchDeviceServerSession(){}
  10. virtual void Handle_OpCmd(SpReqAnsContext<BranchDeviceService_OpCmd_Req,
  11. BranchDeviceService_OpCmd_Ans>::Pointer ctx);
  12. virtual void Handle_Exit(SpOnewayCallContext<BranchDeviceService_Exit_Info>::Pointer ctx);
  13. virtual void Handle_GetDevInfo(SpReqAnsContext<BranchDeviceService_GetDevInfo_Req,
  14. BranchDeviceService_GetDevInfo_Ans>::Pointer ctx);
  15. private:
  16. CBranchDeviceEntity *m_pEntity;
  17. };
  18. class CBranchDeviceEntity : public CEntityBase
  19. {
  20. public:
  21. CBranchDeviceEntity(){}
  22. virtual ~CBranchDeviceEntity(){}
  23. virtual const char *GetEntityName() const { return "BranchDevice"; }
  24. virtual CServerSessionBase* OnNewSession(const char* , const char * )
  25. {
  26. LOG_FUNCTION();
  27. return new CBranchDeviceServerSession(this);
  28. }
  29. virtual void OnPreStart(CAutoArray<CSimpleStringA> strArgs,
  30. CSmartPointer<ITransactionContext> pTransactionContext)
  31. {
  32. ErrorCodeEnum erroCode = m_fsm.Init(this);
  33. pTransactionContext->SendAnswer(erroCode);
  34. }
  35. virtual void OnPrePause(CSmartPointer<ITransactionContext> pTransactionContext)
  36. {
  37. pTransactionContext->SendAnswer(Error_Succeed);
  38. }
  39. virtual void OnPreContinue(CSmartPointer<ITransactionContext> pTransactionContext)
  40. {
  41. pTransactionContext->SendAnswer(Error_Succeed);
  42. }
  43. virtual void OnPreClose(EntityCloseCauseEnum eCloseCause,
  44. CSmartPointer<ITransactionContext> pTransactionContext)
  45. {
  46. LOG_FUNCTION();
  47. ErrorCodeEnum erroCode = m_fsm.OnExit();
  48. pTransactionContext->SendAnswer(erroCode);
  49. }
  50. void OpenCMD(SpReqAnsContext<BranchDeviceService_OpCmd_Req,
  51. BranchDeviceService_OpCmd_Ans>::Pointer ctx)
  52. {
  53. //function@1
  54. //EnterCriticalSection(&m_fsm.s_cs);
  55. //m_fsm.m_ctx = ctx;
  56. //LeaveCriticalSection(&m_fsm.s_cs);
  57. //UINT threadID;
  58. //_beginthreadex(NULL, 0, CBranchDeviceFSM::DispatchThreadFunc, (void*)&m_fsm, 0, &threadID);
  59. //Dbg("ThreadID %d DevSN(%d) param(%s)", threadID, ctx->Req.DevSN, (LPCTSTR)ctx->Req.param);
  60. //function@2
  61. //m_fsm.HandleCMD(ctx);
  62. //ctx->Answer(Error_Succeed);
  63. //function@3
  64. OperateCMDEvent* evt = new OperateCMDEvent();
  65. evt->m_ctx = ctx;
  66. m_fsm.PostEventFIFO(evt);
  67. }
  68. void Exit(SpOnewayCallContext<BranchDeviceService_Exit_Info>::Pointer ctx)
  69. {
  70. //ErrorCodeEnum erroCode = m_fsm.OnExit();
  71. }
  72. void GetDevInfo(SpReqAnsContext<BranchDeviceService_GetDevInfo_Req,
  73. BranchDeviceService_GetDevInfo_Ans>::Pointer ctx)
  74. {
  75. GetInfoEvent* evt = new GetInfoEvent();
  76. evt->m_ctx = ctx;
  77. m_fsm.PostEventFIFO(evt);
  78. //ctx->Answer(Error_NotImpl);
  79. }
  80. void OnSelfTest(EntityTestEnum eTestType,CSmartPointer<ITransactionContext> pTransactionContext)
  81. {
  82. m_fsm.SelfTest(eTestType, pTransactionContext);
  83. }
  84. virtual bool IsService() const { return true; }
  85. virtual bool IsMultiThread() const { return true; }
  86. private:
  87. CBranchDeviceFSM m_fsm;
  88. };