123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290 |
- #ifndef _MOD_HSPSCANNER_H_
- #define _MOD_HSPSCANNER_H_
- #pragma once
- #include "modVer.h"
- #if defined(RVC_OS_LINUX)
- #include "SpTest.h"
- #endif //RVC_OS_LINUX
- #include "ScannerSetFSM.h"
- #include "EventCode.h"
- #include "ScannerSet_UserErrorCode.h"
- #include "HSPScanner_client_g.h"
- using namespace HSPScanner;
- using namespace ScannerSet;
- class CScannerEntity;
- class ScannerServerSession: public ScannerService_ServerSessionBase
- {
- public:
- ScannerServerSession(CScannerEntity *pEntity):m_pEntity(pEntity){}
- virtual ~ScannerServerSession(){}
- virtual void Handle_StartPreview(SpReqAnsContext<ScannerService_StartPreview_Req,
- ScannerService_StartPreview_Ans>::Pointer ctx);
- virtual void Handle_CancelPreview(SpReqAnsContext<ScannerService_CancelPreview_Req,
- ScannerService_CancelPreview_Ans>::Pointer ctx);
- virtual void Handle_ScanImage(SpReqAnsContext<ScannerService_ScanImage_Req,
- ScannerService_ScanImage_Ans>::Pointer ctx);
- virtual void Handle_SetWindowPos(SpReqAnsContext<ScannerService_SetWindowPos_Req,
- ScannerService_SetWindowPos_Ans>::Pointer ctx);
- virtual void Handle_SetProperty(SpReqAnsContext<ScannerService_SetProperty_Req,
- ScannerService_SetProperty_Ans>::Pointer ctx);
- virtual void Handle_ShowProperty(SpReqAnsContext<ScannerService_ShowProperty_Req,
- ScannerService_ShowProperty_Ans>::Pointer ctx);
- virtual void Handle_GetDevStatus(SpReqAnsContext<ScannerService_GetDevStatus_Req,
- ScannerService_GetDevStatus_Ans>::Pointer ctx);
- virtual void Handle_GetDevInfo(SpReqAnsContext<ScannerService_GetDevInfo_Req,
- ScannerService_GetDevInfo_Ans>::Pointer ctx);
- virtual void Handle_GetOnlineCameras(SpReqAnsContext<ScannerService_GetOnlineCameras_Req, ScannerService_GetOnlineCameras_Ans>::Pointer ctx);
- virtual void Handle_Exit(SpOnewayCallContext<ScannerService_Exit_Info>::Pointer ctx);
- private:
- CScannerEntity *m_pEntity;
- };
- class HSPScannerClient : public HSPScannerService_ClientBase
- {
- public:
- HSPScannerClient(CScannerEntity *pEntity);
- };
- class CScannerEntity : public CEntityBase, public IEntityStateListener
- {
- public:
- CScannerEntity() {}
- virtual ~CScannerEntity()
- {
- if(GetFunction()->HasPrivilege()) {
- CSmartPointer<IEntityFunction> pFunc = GetFunction();
- CSmartPointer<IEntityFunctionPrivilege> pFuncPrivilege = pFunc.ConvertCase<IEntityFunctionPrivilege>();
- pFuncPrivilege->UnregistEntityStateEvent(m_fsm.GetChildEntityName());
- }
- }
- virtual const char *GetEntityName() const { return "ScannerSet"; }
- const char* GetEntityVersion() const { return MODULE_VERSION_FULL; }
- #if defined(RVC_OS_LINUX)
- ON_ENTITYT_TEST()
- #endif //RVC_OS_LINUX
- virtual CServerSessionBase* OnNewSession(const char* , const char * )
- {
- return new ScannerServerSession(this);
- }
- virtual void OnPreStart(CAutoArray<CSimpleStringA> strArgs,
- CSmartPointer<ITransactionContext> pTransactionContext)
- {
- ErrorCodeEnum erroCode = m_fsm.Init(this);
- pTransactionContext->SendAnswer(erroCode);
- }
- void OnStarted()
- {
- if(GetFunction()->HasPrivilege()) {
- CSmartPointer<IEntityFunction> pFunc = GetFunction();
- CSmartPointer<IEntityFunctionPrivilege> pFuncPrivilege = pFunc.ConvertCase<IEntityFunctionPrivilege>();
- pFuncPrivilege->RegistEntityStateEvent(m_fsm.GetChildEntityName(), this);
- } else {
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("cur entity has no priviledge!");
- }
- m_fsm.AfterInit();
- }
- virtual void OnPrePause(CSmartPointer<ITransactionContext> pTransactionContext)
- {
- LOG_FUNCTION();
- #ifdef TWINKLE_LOCAL_DEBUG
- const UINT result = UniTest(this);
- if(result != 0) {
- LogError(Severity_High, Error_Unexpect, result, CSimpleStringA::Format("line: %u", result));
- }
- #endif
- SpReqAnsContext<ScannerService_StartPreview_Req,
- ScannerService_StartPreview_Ans>::Pointer ctx =
- new SpReqAnsContext<ScannerService_StartPreview_Req,
- ScannerService_StartPreview_Ans>(pTransactionContext);
- Preview(ctx);
- pTransactionContext->SendAnswer(Error_Succeed);
- }
- virtual void OnPreContinue(CSmartPointer<ITransactionContext> pTransactionContext)
- {
- Exit(NULL);
- pTransactionContext->SendAnswer(Error_Succeed);
- }
- virtual void OnPreClose(EntityCloseCauseEnum eCloseCause,
- CSmartPointer<ITransactionContext> pTransactionContext)
- {
- ErrorCodeEnum erroCode = m_fsm.OnExit();
- pTransactionContext->SendAnswer(erroCode);
- }
- void Preview(SpReqAnsContext<ScannerService_StartPreview_Req,
- ScannerService_StartPreview_Ans>::Pointer ctx)
- {
- StartPreviewEvent* pEvent = new StartPreviewEvent();
- pEvent->m_ctx = ctx;
- m_fsm.PostEventFIFO(pEvent);
- }
- void CancelPreview(SpReqAnsContext<ScannerService_CancelPreview_Req,
- ScannerService_CancelPreview_Ans>::Pointer ctx)
- {
- StopPreviewEvent* pEvent = new StopPreviewEvent();
- pEvent->m_ctx = ctx;
- m_fsm.PostEventFIFO(pEvent);
- }
- void ScanImage(SpReqAnsContext<ScannerService_ScanImage_Req,
- ScannerService_ScanImage_Ans>::Pointer ctx)
- {
- ScanImageEvent* pEvent = new ScanImageEvent();
- pEvent->m_ctx = ctx;
- m_fsm.PostEventFIFO(pEvent);
- }
- void Exit(SpOnewayCallContext<ScannerService_Exit_Info>::Pointer ctx)
- {
- ErrorCodeEnum erroCode = m_fsm.OnDevExit();
- }
- void GetDevInfo(SpReqAnsContext<ScannerService_GetDevInfo_Req,
- ScannerService_GetDevInfo_Ans>::Pointer ctx)
- {
- m_fsm.GetDevInfo(ctx);
- return;
- }
- void SetWinPos(SpReqAnsContext<ScannerService_SetWindowPos_Req,
- ScannerService_SetWindowPos_Ans>::Pointer ctx)
- {
- static ScannerService_SetWindowPos_Req lastReq = {-1, -1, -1, -1, -1};
- if((ctx->Req.type != lastReq.type
- || ctx->Req.pointX != lastReq.pointX
- || ctx->Req.pointY != lastReq.pointY
- || ctx->Req.nWidth != lastReq.nWidth
- /*|| ctx->Req.reserved4 != lastReq.reserved4*/)) {
- lastReq.type = ctx->Req.type;
- lastReq.pointX = ctx->Req.pointX;
- lastReq.pointY = ctx->Req.pointY;
- lastReq.nWidth = ctx->Req.nWidth;
- lastReq.reserved4 = ctx->Req.reserved4;
- PendingTask* pTask = new PendingTask(&m_fsm);
- pTask->SetContext(ctx);
- GetFunction()->PostThreadPoolTask(pTask);
- } else {
- LogWarn(Severity_Low, Error_Debug, LOG_WARN_DUPLICATE_SETWINPOS
- , CSimpleStringA::Format("same request with last-one: %d,%d,%d,%d,%d"
- , ctx->Req.type, ctx->Req.pointX, ctx->Req.pointY, ctx->Req.nWidth, ctx->Req.reserved4));
- ctx->Answer(Error_Succeed);
- }
- }
- void SetProperty(SpReqAnsContext<ScannerService_SetProperty_Req,
- ScannerService_SetProperty_Ans>::Pointer ctx)
- {
- WaitingFSMForIdle();
- SetPropertyEvent* pEvent = new SetPropertyEvent();
- pEvent->m_ctx = ctx;
- m_fsm.PostEventFIFO(pEvent);
- }
- void ShowProperty(SpReqAnsContext<ScannerService_ShowProperty_Req,
- ScannerService_ShowProperty_Ans>::Pointer ctx)
- {
- ShowPropertyEvent* pEvent = new ShowPropertyEvent();
- pEvent->m_ctx = ctx;
- m_fsm.PostEventFIFO(pEvent);
- }
- void GetDevStatus(SpReqAnsContext<ScannerService_GetDevStatus_Req,
- ScannerService_GetDevStatus_Ans>::Pointer ctx)
- {
- m_fsm.GetDevStatus(ctx);
- return;
- }
- void OnSelfTest(EntityTestEnum eTestType, CSmartPointer<ITransactionContext> pTransactionContext)
- {
- m_fsm.SelfTest(eTestType, pTransactionContext);
- }
- virtual bool IsService() const { return true; }
- virtual bool IsMultiThread() const { return true; };
- void OnEntityStateHook(const char *pszEntityName,const char *pszTriggerEntity,
- EntityStateEnum eState,EntityStateEnum eLastState)
- {
- }
- void OnUserStateHook(const char *pszEntityName,DWORD dwState,DWORD dwLastState)
- {
- }
- void OnCeateConnection(const char *pszCallerEntity,const char *pszServiceEntity)
- {
- }
- void OnCloseConnection(const char *pszCallerEntity,const char *pszServiceEntity)
- {
- }
- void WaitingFSMForIdle()
- {
- static const int waitTimes = 30;
- static const int waitEachTimeout = 300;
- int waitCurrTimes = 0;
- while(m_fsm.IsWorking() && (++waitCurrTimes <= waitTimes)) {
- Sleep(waitEachTimeout);
- }
- if(waitCurrTimes > waitTimes) {
- LogWarn(Severity_Low, Error_TimeOut, 0, "Waiting FSM to Idle timeout!");
- }
- }
- private:
- CScannerFSM m_fsm;
- };
- HSPScannerClient::HSPScannerClient(CScannerEntity *pEntity)
- :HSPScannerService_ClientBase(pEntity)
- {
- }
- #endif
|