mod_ups.cpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. #include "stdafx.h"
  2. #include "SpBase.h"
  3. #include "SpTest.h"
  4. #include "modVer.h"
  5. #include "UpsFSM.h"
  6. #include "DevEntityCommBase.hpp"
  7. using namespace Ups;
  8. class CUpsEntity;
  9. class UpsServerSession : public UpsService_ServerSessionBase
  10. {
  11. public:
  12. UpsServerSession(CUpsEntity* pEntity) : m_pEntity(pEntity){}
  13. virtual ~UpsServerSession(){}
  14. virtual void Handle_Open(SpReqAnsContext<UpsService_Open_Req, UpsService_Open_Ans>::Pointer ctx);
  15. virtual void Handle_GetStatus(SpReqAnsContext<UpsService_GetStatus_Req, UpsService_GetStatus_Ans>::Pointer ctx);
  16. virtual void Handle_Shutdown(SpReqAnsContext<UpsService_Shutdown_Req, UpsService_Shutdown_Ans>::Pointer ctx);
  17. virtual void Handle_Close(SpReqAnsContext<UpsService_Close_Req, UpsService_Close_Ans>::Pointer ctx);
  18. private:
  19. CUpsEntity* m_pEntity;
  20. };
  21. class CUpsEntity : public CDevAdptEntityBase
  22. {
  23. public:
  24. CUpsEntity(){}
  25. virtual ~CUpsEntity(){}
  26. virtual const char *GetEntityName() const { return "Ups"; }
  27. const char* GetEntityVersion() const { return MODULE_VERSION_FULL; }
  28. virtual void OnPreStart(CAutoArray<CSimpleStringA> strArgs,CSmartPointer<ITransactionContext> pTransactionContext)
  29. {
  30. LOG_FUNCTION();
  31. ErrorCodeEnum err = m_fsm.Init(this);
  32. pTransactionContext->SendAnswer(err);
  33. }
  34. ON_ENTITYT_TEST()
  35. virtual void OnPrePause(CSmartPointer<ITransactionContext> pTransactionContext)
  36. {
  37. pTransactionContext->SendAnswer(Error_Succeed);
  38. }
  39. virtual void OnPreClose(EntityCloseCauseEnum eCloseCause,CSmartPointer<ITransactionContext> pTransactionContext)
  40. {
  41. pTransactionContext->SendAnswer(Error_Succeed);
  42. }
  43. virtual CServerSessionBase* OnNewSession(const char*,const char*)
  44. {
  45. LOG_FUNCTION();
  46. return new UpsServerSession(this);
  47. }
  48. void Open(SpReqAnsContext<UpsService_Open_Req, UpsService_Open_Ans>::Pointer ctx)
  49. {
  50. //OpenUpsEvent* e = new OpenUpsEvent();
  51. //e->ctx = ctx;
  52. //m_fsm.PostEventFIFO(e);
  53. ctx->Answer(Error_NotImpl);
  54. }
  55. void GetStatus(SpReqAnsContext<UpsService_GetStatus_Req, UpsService_GetStatus_Ans>::Pointer ctx)
  56. {
  57. GetStatusEvent* e = new GetStatusEvent();
  58. e->ctx = ctx;
  59. m_fsm.PostEventFIFO(e);
  60. }
  61. void Shutdown(SpReqAnsContext<UpsService_Shutdown_Req, UpsService_Shutdown_Ans>::Pointer ctx)
  62. {
  63. ShutDownEvent* e = new ShutDownEvent();
  64. e->ctx = ctx;
  65. m_fsm.PostEventFIFO(e);
  66. }
  67. void Close(SpReqAnsContext<UpsService_Close_Req, UpsService_Close_Ans>::Pointer ctx)
  68. {
  69. ctx->Answer(Error_NotImpl);
  70. }
  71. virtual bool IsService()const{return true;}
  72. virtual bool IsMultiThread()const{return false;}
  73. private:
  74. CUpsFSM m_fsm;
  75. };
  76. void UpsServerSession::Handle_Open(SpReqAnsContext<UpsService_Open_Req, UpsService_Open_Ans>::Pointer ctx)
  77. {
  78. m_pEntity->Open(ctx);
  79. }
  80. void UpsServerSession::Handle_GetStatus(SpReqAnsContext<UpsService_GetStatus_Req, UpsService_GetStatus_Ans>::Pointer ctx)
  81. {
  82. m_pEntity->GetStatus(ctx);
  83. }
  84. void UpsServerSession::Handle_Shutdown(SpReqAnsContext<UpsService_Shutdown_Req, UpsService_Shutdown_Ans>::Pointer ctx)
  85. {
  86. m_pEntity->Shutdown(ctx);
  87. }
  88. void UpsServerSession::Handle_Close(SpReqAnsContext<UpsService_Close_Req, UpsService_Close_Ans>::Pointer ctx)
  89. {
  90. m_pEntity->Close(ctx);
  91. }
  92. SP_BEGIN_ENTITY_MAP()
  93. SP_ENTITY(CUpsEntity)
  94. SP_END_ENTITY_MAP()