123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- #include "stdafx.h"
- #include "SpBase.h"
- #include "SpTest.h"
- #include "modVer.h"
- #include "UpsFSM.h"
- #include "DevEntityCommBase.hpp"
- using namespace Ups;
- class CUpsEntity;
- class UpsServerSession : public UpsService_ServerSessionBase
- {
- public:
- UpsServerSession(CUpsEntity* pEntity) : m_pEntity(pEntity){}
- virtual ~UpsServerSession(){}
- virtual void Handle_Open(SpReqAnsContext<UpsService_Open_Req, UpsService_Open_Ans>::Pointer ctx);
- virtual void Handle_GetStatus(SpReqAnsContext<UpsService_GetStatus_Req, UpsService_GetStatus_Ans>::Pointer ctx);
- virtual void Handle_Shutdown(SpReqAnsContext<UpsService_Shutdown_Req, UpsService_Shutdown_Ans>::Pointer ctx);
- virtual void Handle_Close(SpReqAnsContext<UpsService_Close_Req, UpsService_Close_Ans>::Pointer ctx);
- private:
- CUpsEntity* m_pEntity;
- };
- class CUpsEntity : public CDevAdptEntityBase
- {
- public:
- CUpsEntity(){}
- virtual ~CUpsEntity(){}
- virtual const char *GetEntityName() const { return "Ups"; }
- const char* GetEntityVersion() const { return MODULE_VERSION_FULL; }
- virtual void OnPreStart(CAutoArray<CSimpleStringA> strArgs,CSmartPointer<ITransactionContext> pTransactionContext)
- {
- LOG_FUNCTION();
- ErrorCodeEnum err = m_fsm.Init(this);
- pTransactionContext->SendAnswer(err);
- }
- ON_ENTITYT_TEST()
- virtual void OnPrePause(CSmartPointer<ITransactionContext> pTransactionContext)
- {
- pTransactionContext->SendAnswer(Error_Succeed);
- }
- virtual void OnPreClose(EntityCloseCauseEnum eCloseCause,CSmartPointer<ITransactionContext> pTransactionContext)
- {
- pTransactionContext->SendAnswer(Error_Succeed);
- }
- virtual CServerSessionBase* OnNewSession(const char*,const char*)
- {
- LOG_FUNCTION();
- return new UpsServerSession(this);
- }
- void Open(SpReqAnsContext<UpsService_Open_Req, UpsService_Open_Ans>::Pointer ctx)
- {
- //OpenUpsEvent* e = new OpenUpsEvent();
- //e->ctx = ctx;
- //m_fsm.PostEventFIFO(e);
- ctx->Answer(Error_NotImpl);
- }
- void GetStatus(SpReqAnsContext<UpsService_GetStatus_Req, UpsService_GetStatus_Ans>::Pointer ctx)
- {
- GetStatusEvent* e = new GetStatusEvent();
- e->ctx = ctx;
- m_fsm.PostEventFIFO(e);
- }
- void Shutdown(SpReqAnsContext<UpsService_Shutdown_Req, UpsService_Shutdown_Ans>::Pointer ctx)
- {
- ShutDownEvent* e = new ShutDownEvent();
- e->ctx = ctx;
- m_fsm.PostEventFIFO(e);
- }
- void Close(SpReqAnsContext<UpsService_Close_Req, UpsService_Close_Ans>::Pointer ctx)
- {
- ctx->Answer(Error_NotImpl);
- }
- virtual bool IsService()const{return true;}
- virtual bool IsMultiThread()const{return false;}
- private:
- CUpsFSM m_fsm;
- };
- void UpsServerSession::Handle_Open(SpReqAnsContext<UpsService_Open_Req, UpsService_Open_Ans>::Pointer ctx)
- {
- m_pEntity->Open(ctx);
- }
- void UpsServerSession::Handle_GetStatus(SpReqAnsContext<UpsService_GetStatus_Req, UpsService_GetStatus_Ans>::Pointer ctx)
- {
- m_pEntity->GetStatus(ctx);
- }
- void UpsServerSession::Handle_Shutdown(SpReqAnsContext<UpsService_Shutdown_Req, UpsService_Shutdown_Ans>::Pointer ctx)
- {
- m_pEntity->Shutdown(ctx);
- }
- void UpsServerSession::Handle_Close(SpReqAnsContext<UpsService_Close_Req, UpsService_Close_Ans>::Pointer ctx)
- {
- m_pEntity->Close(ctx);
- }
- SP_BEGIN_ENTITY_MAP()
- SP_ENTITY(CUpsEntity)
- SP_END_ENTITY_MAP()
|