| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- #pragma once
- #include "BranchDeviceFSM.h"
- using namespace BranchDevice;
- class CBranchDeviceEntity;
- class CBranchDeviceServerSession: public BranchDeviceService_ServerSessionBase
- {
- public:
- CBranchDeviceServerSession(CBranchDeviceEntity *pEntity):m_pEntity(pEntity){}
- virtual ~CBranchDeviceServerSession(){}
- virtual void Handle_OpCmd(SpReqAnsContext<BranchDeviceService_OpCmd_Req,
- BranchDeviceService_OpCmd_Ans>::Pointer ctx);
- virtual void Handle_Exit(SpOnewayCallContext<BranchDeviceService_Exit_Info>::Pointer ctx);
- virtual void Handle_GetDevInfo(SpReqAnsContext<BranchDeviceService_GetDevInfo_Req,
- BranchDeviceService_GetDevInfo_Ans>::Pointer ctx);
- private:
- CBranchDeviceEntity *m_pEntity;
- };
- class CBranchDeviceEntity : public CEntityBase
- {
- public:
- CBranchDeviceEntity(){}
- virtual ~CBranchDeviceEntity(){}
- virtual const char *GetEntityName() const { return "BranchDevice"; }
- virtual CServerSessionBase* OnNewSession(const char* , const char * )
- {
- LOG_FUNCTION();
- return new CBranchDeviceServerSession(this);
- }
- virtual void OnPreStart(CAutoArray<CSimpleStringA> strArgs,
- CSmartPointer<ITransactionContext> pTransactionContext)
- {
- ErrorCodeEnum erroCode = m_fsm.Init(this);
- pTransactionContext->SendAnswer(erroCode);
- }
- virtual void OnPrePause(CSmartPointer<ITransactionContext> pTransactionContext)
- {
- pTransactionContext->SendAnswer(Error_Succeed);
- }
- virtual void OnPreContinue(CSmartPointer<ITransactionContext> pTransactionContext)
- {
- pTransactionContext->SendAnswer(Error_Succeed);
- }
- virtual void OnPreClose(EntityCloseCauseEnum eCloseCause,
- CSmartPointer<ITransactionContext> pTransactionContext)
- {
- LOG_FUNCTION();
- ErrorCodeEnum erroCode = m_fsm.OnExit();
- pTransactionContext->SendAnswer(erroCode);
- }
- void OpenCMD(SpReqAnsContext<BranchDeviceService_OpCmd_Req,
- BranchDeviceService_OpCmd_Ans>::Pointer ctx)
- {
- //function@1
- //EnterCriticalSection(&m_fsm.s_cs);
- //m_fsm.m_ctx = ctx;
- //LeaveCriticalSection(&m_fsm.s_cs);
- //UINT threadID;
- //_beginthreadex(NULL, 0, CBranchDeviceFSM::DispatchThreadFunc, (void*)&m_fsm, 0, &threadID);
- //Dbg("ThreadID %d DevSN(%d) param(%s)", threadID, ctx->Req.DevSN, (LPCTSTR)ctx->Req.param);
-
- //function@2
- //m_fsm.HandleCMD(ctx);
- //ctx->Answer(Error_Succeed);
- //function@3
- OperateCMDEvent* evt = new OperateCMDEvent();
- evt->m_ctx = ctx;
- m_fsm.PostEventFIFO(evt);
- }
- void Exit(SpOnewayCallContext<BranchDeviceService_Exit_Info>::Pointer ctx)
- {
- //ErrorCodeEnum erroCode = m_fsm.OnExit();
- }
- void GetDevInfo(SpReqAnsContext<BranchDeviceService_GetDevInfo_Req,
- BranchDeviceService_GetDevInfo_Ans>::Pointer ctx)
- {
- GetInfoEvent* evt = new GetInfoEvent();
- evt->m_ctx = ctx;
- m_fsm.PostEventFIFO(evt);
- //ctx->Answer(Error_NotImpl);
- }
- void OnSelfTest(EntityTestEnum eTestType,CSmartPointer<ITransactionContext> pTransactionContext)
- {
- m_fsm.SelfTest(eTestType, pTransactionContext);
- }
- virtual bool IsService() const { return true; }
- virtual bool IsMultiThread() const { return true; }
- private:
- CBranchDeviceFSM m_fsm;
- };
|