123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261 |
- #ifndef MOD_FINGERPRINT_H
- #define MOD_FINGERPRINT_H
- #include "FingerPrintFSM.h"
- #include "FingerPrint_server_g.h"
- #include "modVer.h"
- #ifdef RVC_OS_WIN
- #else
- #include "SpTest.h"
- #endif
- class CFingerPrintEntity;
- class FingerPrintServerSession : public FingerPrint::FingerPrintService_ServerSessionBase
- {
- public:
- FingerPrintServerSession(CFingerPrintEntity* pEntity) : m_pEntity(pEntity){}
- virtual ~FingerPrintServerSession(){}
- virtual void Handle_GetImageAndFeature(SpReqAnsContext<FingerPrintService_GetImageAndFeature_Req, FingerPrintService_GetImageAndFeature_Ans>::Pointer ctx);
- virtual void Handle_GetImageAndFeatureEx(SpReqAnsContext<FingerPrintService_GetImageAndFeatureEx_Req, FingerPrintService_GetImageAndFeatureEx_Ans>::Pointer ctx);
- virtual void Handle_GetFingerPrint(SpReqAnsContext<FingerPrintService_GetFingerPrint_Req, FingerPrintService_GetFingerPrint_Ans>::Pointer ctx);
- virtual void Handle_GenerateTemplate(SpReqAnsContext<FingerPrintService_GenerateTemplate_Req, FingerPrintService_GenerateTemplate_Ans>::Pointer ctx);
- virtual void Handle_CancelRegister(SpOnewayCallContext<FingerPrintService_CancelRegister_Info>::Pointer ctx);
- virtual void Handle_CancelMatch(SpOnewayCallContext<FingerPrintService_CancelMatch_Info>::Pointer ctx);
- virtual void Handle_GetDevInfo(SpReqAnsContext<FingerPrintService_GetDevInfo_Req, FingerPrintService_GetDevInfo_Ans>::Pointer ctx);
- virtual void Handle_GetDevStatus(SpReqAnsContext<FingerPrintService_GetDevStatus_Req, FingerPrintService_GetDevStatus_Ans>::Pointer ctx);
- virtual void Handle_Match(SpReqAnsContext<FingerPrintService_Match_Req, FingerPrintService_Match_Ans>::Pointer ctx);
- virtual void Handle_Exit(SpOnewayCallContext<FingerPrintService_Exit_Info>::Pointer ctx);
- //新增接口
- virtual void Handle_GetFingerPrintJS(SpReqAnsContext<FingerPrintService_GetFingerPrintJS_Req, FingerPrintService_GetFingerPrintJS_Ans>::Pointer ctx);
- virtual void Handle_GenerateTemplateJS(SpReqAnsContext<FingerPrintService_GenerateTemplateJS_Req, FingerPrintService_GenerateTemplateJS_Ans>::Pointer ctx);
- virtual void Handle_CancelScanJS(SpReqAnsContext<FingerPrintService_CancelScanJS_Req, FingerPrintService_CancelScanJS_Ans>::Pointer ctx);
- private:
- CFingerPrintEntity* m_pEntity;
- };
- class CFingerPrintEntity : public CDevAdptEntityBase, public ISysVarListener
- {
- public:
- CFingerPrintEntity(){}
- virtual ~CFingerPrintEntity(){}
- virtual const char *GetEntityName() const { return "FingerPrint"; }
- virtual bool IsService() const {return true;}
- #ifdef RVC_OS_WIN
- #else
- virtual const char* GetEntityVersion() const { return MODULE_VERSION_FULL; }
- ON_ENTITYT_TEST()
- #endif
- virtual void OnPreStart(CAutoArray<CSimpleStringA> strArgs,CSmartPointer<ITransactionContext> pTransactionContext)
- {
- LOG_FUNCTION();
- ErrorCodeEnum ec = m_fsm.Init(this);
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("OnPreStart, Init:%d", ec);
- GetFunction()->RegistSysVarEvent("UIState", this);
- pTransactionContext->SendAnswer(ec);
- }
- virtual void OnPrePause(CSmartPointer<ITransactionContext> pTransactionContext)
- {
- LOG_FUNCTION();
- pTransactionContext->SendAnswer(Error_Succeed);
- }
- virtual void OnPreContinue(CSmartPointer<ITransactionContext> pTransactionContext)
- {
- LOG_FUNCTION();
- pTransactionContext->SendAnswer(Error_Succeed);
- }
- virtual void OnPreClose(EntityCloseCauseEnum eCloseCause, CSmartPointer<ITransactionContext> pTransactionContext)
- {
- LOG_FUNCTION();
- m_fsm.OnExit();
- pTransactionContext->SendAnswer(Error_Succeed);
- }
- virtual void OnSelfTest(EntityTestEnum eTestType, CSmartPointer<ITransactionContext> pTransactionContext)
- {
- //LOG_FUNCTION();
- m_fsm.SelfTest(eTestType, pTransactionContext);
- }
- virtual CServerSessionBase* OnNewSession(const char* , const char * )
- {
- //DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("A new connecting request arrived.");
- m_bNewSessionInit = true;
- return new FingerPrintServerSession(this);
- }
- //废弃
- void GetImageAndFeature(SpReqAnsContext<FingerPrintService_GetImageAndFeature_Req, FingerPrintService_GetImageAndFeature_Ans>::Pointer ctx)
- {
- //ScanEvent* e = new ScanEvent();
- //e->ctx = ctx;
- //m_fsm.PostEventFIFO(e);
- LogWarn(Severity_Low, Error_Unexpect, LOG_ERR_FINGERPRINT_REQUEST_REFUSE, "web invoke GetImageAndFeature request refuse");
- ctx->Answer(Error_Exception);
- }
- //废弃
- void GetImageAndFeatureEx(SpReqAnsContext<FingerPrintService_GetImageAndFeatureEx_Req, FingerPrintService_GetImageAndFeatureEx_Ans>::Pointer ctx)
- {
- //ScanExEvent* e = new ScanExEvent();
- //e->ctx = ctx;
- //m_fsm.PostEventFIFO(e);
- LogWarn(Severity_Low, Error_Unexpect, LOG_ERR_FINGERPRINT_REQUEST_REFUSE, "web invoke GetImageAndFeatureEx request refuse");
- ctx->Answer(Error_Exception);
- }
- //有用:扫描指纹(73294)
- void GetFingerPrint(SpReqAnsContext<FingerPrintService_GetFingerPrint_Req, FingerPrintService_GetFingerPrint_Ans>::Pointer ctx)
- {
- if(!m_fsm.GetDevInitFlag()){
- ctx->Answer(Error_DevNotAvailable, FingerPrint_UserErrorCode_DEVOPENFAILED_GETFINGERPRINT);
-
- }
- else{
- GetFingerEvent* e = new GetFingerEvent();
- e->ctx = ctx;
- m_fsm.PostEventFIFO(e);
- }
- }
- //有用:生成指纹模板(161)
- void GenerateTemplate(SpReqAnsContext<FingerPrintService_GenerateTemplate_Req, FingerPrintService_GenerateTemplate_Ans>::Pointer ctx)
- {
- GenerateTemplateEvent* e = new GenerateTemplateEvent();
- e->ctx = ctx;
- m_fsm.PostEventFIFO(e);
- }
- //有用:取消注册(7066)
- void CancelRegister(SpOnewayCallContext<FingerPrintService_CancelRegister_Info>::Pointer ctx)
- {
- CancelRegisterEvent* e = new CancelRegisterEvent();
- m_fsm.PostEventFIFO(e);
- }
- //有用:取消对比(56)
- void CancelMatch(SpOnewayCallContext<FingerPrintService_CancelMatch_Info>::Pointer ctx)
- {
- CancelMatchEvent* e = new CancelMatchEvent();
- m_fsm.PostEventFIFO(e);
- }
- //废弃
- void CheckAndMatch(SpReqAnsContext<FingerPrintService_Match_Req, FingerPrintService_Match_Ans>::Pointer ctx)
- {
- //MatchEvent* e = new MatchEvent();
- //e->ctx = ctx;
- //m_fsm.PostEventFIFO(e);
- LogWarn(Severity_Low, Error_Unexpect, LOG_ERR_FINGERPRINT_REQUEST_REFUSE, "web invoke CheckAndMatch request refuse");
- ctx->Answer(Error_Exception);
- }
- //设备安装状态使用
- void GetDevInfo(SpReqAnsContext<FingerPrintService_GetDevInfo_Req, FingerPrintService_GetDevInfo_Ans>::Pointer ctx)
- {
- LOG_FUNCTION();
- DevCategoryInfo devCatInfo;
- m_fsm.GetDevCatInfo(devCatInfo);
- ctx->Ans.model = devCatInfo.szModel;
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("GetDevInfo model is:%s", (const char*)ctx->Ans.model);
- ctx->Ans.state = (int)m_fsm.GetDevState();
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER)("GetDevInfo %d", ctx->Ans.state);
- if (m_fsm.GetDevInitingFlag()) {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("GetDevInfo device is opening,state return 0");
- ctx->Ans.state = DEVICE_STATUS_NOT_READY;
- ctx->Answer(Error_NotInit, FingerPrint_UserErrorCode_DevOpen_Failed);
- }
- else {
- if (!m_fsm.GetDevInitFlag()) {
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("GetDevInfo device is not open,state return 0");
- ctx->Ans.state = DEVICE_STATUS_NOT_READY;
- ctx->Answer(Error_DevNotAvailable, FingerPrint_UserErrorCode_DevOpen_Failed);
- }
- else {
- ctx->Answer(Error_Succeed);
- }
- }
- }
- //废弃
- void GetDevStatus(SpReqAnsContext<FingerPrintService_GetDevStatus_Req, FingerPrintService_GetDevStatus_Ans>::Pointer ctx)
- {
- int status = 0;
- m_fsm.GetCurDevState(status);
- ctx->Ans.status = status;
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("FingerPrint state is:%d", status);
- ctx->Answer(Error_Succeed);
- }
- //废弃
- void Exit(SpOnewayCallContext<FingerPrintService_Exit_Info>::Pointer ctx)
- {
- FSMEvent* e = new FSMEvent(USER_EVT_EXIT);
- m_fsm.PostEventFIFO(e);
- }
- //js接口
- void GetFingerPrintJS(SpReqAnsContext<FingerPrintService_GetFingerPrintJS_Req, FingerPrintService_GetFingerPrintJS_Ans>::Pointer ctx)
- {
- if (!m_fsm.GetDevInitFlag()) {
- ctx->Answer(Error_DevNotAvailable, FingerPrint_UserErrorCode_DEVOPENFAILED_GETFINGERPRINT);
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("GetFingerPrintJS but DevOpen failed.");
- }
- else if (_stricmp(m_fsm.GetCurrStateName(), "Normal") != 0) {
- //不符合请求调用,告知具体错误流程
- DWORD errCode = m_fsm.GetFsmStateErrCode();
- CSimpleStringA stateName = m_fsm.GetCurrStateName();
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setResultCode(m_fsm.getRTACode(errCode))("GetFingerPrintJS req is unhandled ,CurrState=%d", stateName.GetData());
- ctx->Answer(Error_Unexpect, errCode);
- }
- else {
- GetFingerPrintJSEvent* e = new GetFingerPrintJSEvent();
- e->ctx = ctx;
- m_fsm.PostEventFIFO(e);
- }
- }
- void GenerateTemplateJS(SpReqAnsContext<FingerPrintService_GenerateTemplateJS_Req, FingerPrintService_GenerateTemplateJS_Ans>::Pointer ctx)
- {
- if (!m_fsm.GetDevInitFlag()) {
- ctx->Answer(Error_DevNotAvailable, FingerPrint_UserErrorCode_DEVOPENFAILED_GenerateTemplate);
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("GenerateTemplateJS but DevOpen failed.");
- }
- else if (_stricmp(m_fsm.GetCurrStateName(), "Normal") != 0) {
- //不符合请求调用,告知具体错误流程
- DWORD errCode = m_fsm.GetFsmStateErrCode();
- CSimpleStringA stateName = m_fsm.GetCurrStateName();
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setResultCode(m_fsm.getRTACode(errCode))("GenerateTemplateJS req is unhandled ,CurrState=%d", stateName.GetData());
- ctx->Answer(Error_Unexpect, errCode);
- }
- else {
- GenerateTemplateJSEvent* e = new GenerateTemplateJSEvent();
- e->ctx = ctx;
- m_fsm.PostEventFIFO(e);
- }
- }
- void CancelScanJS(SpReqAnsContext<FingerPrintService_CancelScanJS_Req, FingerPrintService_CancelScanJS_Ans>::Pointer ctx)
- {
- if (!m_fsm.GetDevInitFlag()) {
- ctx->Answer(Error_DevNotAvailable, FingerPrint_UserErrorCode_DEVOPENFAILED_CANCELSCAN_FAIL);
- }
- else if (_stricmp(m_fsm.GetCurrStateName(), "Normal") != 0 && _stricmp(m_fsm.GetCurrStateName(), "Scan") != 0) {
- //不符合请求调用,告知具体错误流程
- DWORD errCode = m_fsm.GetFsmStateErrCode();
- CSimpleStringA stateName = m_fsm.GetCurrStateName();
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setResultCode(m_fsm.getRTACode(errCode))("CancelScanJS req is unhandled ,CurrState=%d", stateName.GetData());
- ctx->Answer(Error_Unexpect, errCode);
- }
- else {
- CancelScanJSEvent* e = new CancelScanJSEvent();
- e->ctx = ctx;
- m_fsm.PostEventFIFO(e);
- }
- }
- virtual void OnSysVarEvent(const char *pszKey,
- const char *pszValue, const char *pszOldValue, const char *pszEntityName);
- private:
- CFingerPrintFSM m_fsm;
- bool m_bNewSessionInit;
- };
- #endif
|