#ifndef _MOD_PORTABLESCANNER_H__ #define _MOD_PORTABLESCANNER_H__ #pragma once #include "PortableScannerFSM.h" using namespace PortableScanner; class CPortableScannerEntity; class CPortableScannerServerSession: public PortableScannerService_ServerSessionBase { public: CPortableScannerServerSession(CPortableScannerEntity *pEntity):m_pEntity(pEntity){} virtual ~CPortableScannerServerSession(){} virtual void Handle_BindCameraDevice(SpReqAnsContext::Pointer ctx); virtual void Handle_DropOffDevice( SpOnewayCallContext::Pointer ctx); virtual void Handle_StartPreview(SpReqAnsContext::Pointer ctx); virtual void Handle_CancelPreview(SpReqAnsContext::Pointer ctx); virtual void Handle_ScanImage(SpReqAnsContext::Pointer ctx); virtual void Handle_ScanImageEx(SpReqAnsContext::Pointer ctx); virtual void Handle_SetProperty(SpReqAnsContext::Pointer ctx); virtual void Handle_SetWinPos(SpReqAnsContext::Pointer ctx); virtual void Handle_ShowProperty(SpReqAnsContext::Pointer ctx); virtual void Handle_GetDevStatus(SpReqAnsContext::Pointer ctx); virtual void Handle_GetDevInfo(SpReqAnsContext::Pointer ctx); virtual void Handle_Exit(SpOnewayCallContext::Pointer ctx); private: CPortableScannerEntity *m_pEntity; }; class CPortableScannerEntity : public CEntityBase { public: CPortableScannerEntity() {} virtual ~CPortableScannerEntity() {} virtual const char *GetEntityName() const { return "PortableScanner"; } virtual CServerSessionBase* OnNewSession(const char* , const char * ) { //LOG_FUNCTION(); return new CPortableScannerServerSession(this); } virtual void OnPreStart(CAutoArray strArgs, CSmartPointer pTransactionContext) { ErrorCodeEnum erroCode = m_fsm.Init(this); pTransactionContext->SendAnswer(erroCode); } virtual void OnPrePause(CSmartPointer pTransactionContext) { ErrorCodeEnum ec = Error_Succeed; ec = m_fsm.UnitTest(); pTransactionContext->SendAnswer(ec); } virtual void OnPreContinue(CSmartPointer pTransactionContext) { pTransactionContext->SendAnswer(Error_Succeed); } virtual void OnPreClose(EntityCloseCauseEnum eCloseCause, CSmartPointer pTransactionContext) { LOG_FUNCTION(); ErrorCodeEnum erroCode = m_fsm.OnExit(); pTransactionContext->SendAnswer(erroCode); } void BindDevice(SpReqAnsContext::Pointer ctx) { BindDeviceEvent* pEvent = new BindDeviceEvent(); pEvent->m_ctx = ctx; m_fsm.PostEventFIFO(pEvent); } void DropOffDevice(SpOnewayCallContext::Pointer ctx) { m_fsm.PostEventFIFO(new FSMEvent(USER_EVT_DROP_OFF_DEVICE)); return; } void Preview(SpReqAnsContext::Pointer ctx) { StartPreviewEvent* pEvent = new StartPreviewEvent(); pEvent->m_ctx = ctx; m_fsm.PostEventFIFO(pEvent); } void CancelPreview(SpReqAnsContext::Pointer ctx) { StopPreviewEvent* pEvent = new StopPreviewEvent(); pEvent->m_ctx = ctx; m_fsm.PostEventFIFO(pEvent); } void ScanImage(SpReqAnsContext::Pointer ctx) { ScanImageEvent* pEvent = new ScanImageEvent(); pEvent->m_ctx = ctx; m_fsm.PostEventFIFO(pEvent); } void ScanImageEx(SpReqAnsContext::Pointer ctx) { ScanImageExEvent* pEvent = new ScanImageExEvent(); pEvent->m_ctx = ctx; m_fsm.PostEventFIFO(pEvent); } void Exit(SpOnewayCallContext::Pointer ctx) { LOG_FUNCTION(); m_fsm.PostEventFIFO(new FSMEvent(USER_EVT_EXIT)); } void GetDevInfo(SpReqAnsContext::Pointer ctx) { GetDevInfoEvent* pEvent = new GetDevInfoEvent(); pEvent->m_ctx = ctx; m_fsm.PostEventFIFO(pEvent); } void GetDevStatus(SpReqAnsContext::Pointer ctx) { GetDevStatusEvent* pEvent = new GetDevStatusEvent(); pEvent->m_ctx = ctx; m_fsm.PostEventFIFO(pEvent); } void SetWinPos(SpReqAnsContext::Pointer ctx) { SetWinPosEvent* pEvent = new SetWinPosEvent(); pEvent->m_ctx = ctx; m_fsm.PostEventFIFO(pEvent); } void ShowProperty(SpReqAnsContext::Pointer ctx) { ShowPropertyEvent* pEvent = new ShowPropertyEvent(); pEvent->m_ctx = ctx; m_fsm.PostEventFIFO(pEvent); } void SetProperty(SpReqAnsContext::Pointer ctx) { SetPropertyEvent* pEvent = new SetPropertyEvent(); pEvent->m_ctx = ctx; m_fsm.PostEventFIFO(pEvent); } void OnSelfTest(EntityTestEnum eTestType, CSmartPointer pTransactionContext) { m_fsm.SelfTest(eTestType, pTransactionContext); } virtual bool IsService() const { return true; } virtual bool IsMultiThread() const { return true; }; private: CPortableScannerFSM m_fsm; }; #endif