123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484 |
- #ifndef FINGERPRINT_FSM_H
- #define FINGERPRINT_FSM_H
- #include "SpFSM.h"
- #include "DevFSMCommBase.hpp"
- #include "FingerPrintClass.h"
- #include "FingerPrint_UserErrorCode.h"
- #include <set>
- #include <mutex>
- #include "CommEntityUtil.hpp"
- using namespace std;
- enum EvtType
- {
- USER_EVT_TEST = EVT_USER + 1,
- USER_EVT_INIT,
- USER_EVT_INIT_FINISHED,
- USER_EVT_GET_DEVINFO,
- USER_EVT_SCAN,
- USER_EVT_SCAN_FINISHED,
- USER_EVT_SCANEX,
- USER_EVT_SCANEX_FINISHED,
- USER_EVT_MATCH,
- USER_EVT_MATCH_FINISHED,
- USER_EVT_GETFINGER,
- USER_EVT_GETFINGER_FINISHED,
- USER_EVT_GENERATE_TEMPLATE,
- USER_EVT_GENERATE_TEMPLATE_FINISHED,
- USER_EVT_MATCH_FINGERPRINT,
- USER_EVT_MATCH_FINGERPRINT_FINISHED,
- USER_EVT_CANCEL_SCAN,
- USER_EVT_CANCEL_MATCH,
- USER_EVT_CANCEL_SCAN_FINISHED,
- USER_EVT_QUIT,
- USER_EVT_ERROR,
- USER_EVT_EXIT,
- USER_EVT_FWB_OPEN_SUC,
- USER_EVT_FWB_OPEN_SUC_FINISHED,
- USER_EVT_JS_GET_FINGERPRINT,
- USER_EVT_JS_GET_FINGERPRINT_FINISHED,
- USER_EVT_JS_GENERATE_TEMPLATE,
- USER_EVT_JS_GENERATE_TEMPLATE_FINISHED,
- USER_EVT_JS_CANCEL_SCAN,
- USER_EVT_JS_CANCEL_SCAN_FINISHED
- };
- enum BmpType
- {
- BmpImage = 1,
- TestImage
- };
- #include "FingerPrint_server_g.h"
- #include "FingerPrintClass.h"
- using namespace FingerPrint;
- class ScanEvent : public FSMEvent
- {
- public:
- ScanEvent() : FSMEvent(USER_EVT_SCAN){}
- virtual ~ScanEvent(){}
- SpReqAnsContext<FingerPrintService_GetImageAndFeature_Req, FingerPrintService_GetImageAndFeature_Ans>::Pointer ctx;
- virtual void OnUnhandled()
- {
- if (ctx != NULL) {
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setResultCode("RTA242H")("ScanEvent unhandled.");
- ctx->Answer(Error_InvalidState);
- }
- }
- };
- class ScanExEvent : public FSMEvent
- {
- public:
- ScanExEvent() : FSMEvent(USER_EVT_SCANEX) {}
- virtual ~ScanExEvent() {}
- SpReqAnsContext<FingerPrintService_GetImageAndFeatureEx_Req, FingerPrintService_GetImageAndFeatureEx_Ans>::Pointer ctx;
- virtual void OnUnhandled()
- {
- if (ctx != NULL)
- {
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setResultCode("RTA242H")("ScanEx unhandled");
- ctx->Answer(Error_InvalidState);
- }
- }
- };
- class GetFingerEvent : public FSMEvent
- {
- public:
- GetFingerEvent() : FSMEvent(USER_EVT_GETFINGER) {}
- virtual ~GetFingerEvent() {}
- SpReqAnsContext<FingerPrintService_GetFingerPrint_Req, FingerPrintService_GetFingerPrint_Ans>::Pointer ctx;
- virtual void OnUnhandled()
- {
- if (ctx != NULL)
- {
- ctx->Answer(Error_InvalidState);
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setResultCode("RTA242H")("GetFinger unhandled");
- }
- }
- };
- class GenerateTemplateEvent : public FSMEvent
- {
- public:
- GenerateTemplateEvent() : FSMEvent(USER_EVT_GENERATE_TEMPLATE) {}
- virtual ~GenerateTemplateEvent() {}
- SpReqAnsContext<FingerPrintService_GenerateTemplate_Req, FingerPrintService_GenerateTemplate_Ans>::Pointer ctx;
- virtual void OnUnhandled()
- {
- if (ctx != NULL)
- {
- ctx->Answer(Error_InvalidState);
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setResultCode("RTA242H")("GenerateTemplate unhandled.");
- }
- }
- };
- class CancelRegisterEvent : public FSMEvent
- {
- public:
- CancelRegisterEvent() : FSMEvent(USER_EVT_CANCEL_SCAN){}
- virtual ~CancelRegisterEvent(){}
- virtual void OnUnhandled()
- {
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setResultCode("RTA242H")("Cancel scan not handled");
- }
- };
- class MatchEvent : public FSMEvent
- {
- public:
- MatchEvent() : FSMEvent(USER_EVT_MATCH){}
- virtual ~MatchEvent(){}
- SpReqAnsContext<FingerPrintService_Match_Req, FingerPrintService_Match_Ans>::Pointer ctx;
- virtual void OnUnhandled()
- {
- if (ctx != NULL)
- {
- ctx->Answer(Error_InvalidState);
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setResultCode("RTA242H")("Match unhandled.");
- }
- }
- };
- class MatchFinishedEvent : public FSMEvent
- {
- public:
- MatchFinishedEvent() : FSMEvent(USER_EVT_MATCH_FINISHED){}
- ~MatchFinishedEvent(){}
- SpReqAnsContext<FingerPrintService_Match_Req, FingerPrintService_Match_Ans>::Pointer ctx;
- virtual void OnUnhandled()
- {
- if (ctx != NULL)
- {
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setResultCode("RTA242H")("Match finished unhandled.");
- }
- }
- };
- class GetFingerFinishedEvent : public FSMEvent
- {
- public:
- GetFingerFinishedEvent() : FSMEvent(USER_EVT_GETFINGER_FINISHED) {}
- ~GetFingerFinishedEvent() {}
- SpReqAnsContext<FingerPrintService_GetFingerPrint_Req, FingerPrintService_GetFingerPrint_Ans>::Pointer ctx;
- virtual void OnUnhandled()
- {
- if (ctx != NULL)
- {
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setResultCode("RTA242H")("GetFingerFinished unhandled.");
- }
- }
- };
- class CancelMatchEvent : public FSMEvent
- {
- public:
- CancelMatchEvent() : FSMEvent(USER_EVT_CANCEL_MATCH){}
- virtual ~CancelMatchEvent(){}
- virtual void OnUnhandled()
- {
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setResultCode("RTA242H")("Cancel match not handled");
- }
- };
- class GetDevInfoEvent : public FSMEvent
- {
- public:
- GetDevInfoEvent() : FSMEvent(USER_EVT_GET_DEVINFO){}
- virtual ~GetDevInfoEvent(){}
- SpReqAnsContext<FingerPrintService_GetDevInfo_Req, FingerPrintService_GetDevInfo_Ans>::Pointer ctx;
- virtual void OnUnhandled()
- {
- if(ctx != NULL)
- ctx->Answer(Error_InvalidState);
- }
- };
- //JS
- class GetFingerPrintJSEvent : public FSMEvent
- {
- public:
- GetFingerPrintJSEvent() : FSMEvent(USER_EVT_JS_GET_FINGERPRINT) {}
- virtual ~GetFingerPrintJSEvent() {}
- SpReqAnsContext<FingerPrintService_GetFingerPrintJS_Req, FingerPrintService_GetFingerPrintJS_Ans>::Pointer ctx;
- virtual void OnUnhandled()
- {
- if (ctx != NULL)
- {
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setResultCode("RTA242H")("GetFingerPrintJS unhandled");
- }
- }
- };
- class GenerateTemplateJSEvent : public FSMEvent
- {
- public:
- GenerateTemplateJSEvent() : FSMEvent(USER_EVT_JS_GENERATE_TEMPLATE) {}
- virtual ~GenerateTemplateJSEvent() {}
- SpReqAnsContext<FingerPrintService_GenerateTemplateJS_Req, FingerPrintService_GenerateTemplateJS_Ans>::Pointer ctx;
- virtual void OnUnhandled()
- {
- if (ctx != NULL)
- {
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setResultCode("RTA242H")("GenerateTemplateJS unhandled.");
- }
- }
- };
- class CancelScanJSEvent : public FSMEvent
- {
- public:
- CancelScanJSEvent() : FSMEvent(USER_EVT_JS_CANCEL_SCAN) {}
- virtual ~CancelScanJSEvent() {}
- SpReqAnsContext<FingerPrintService_CancelScanJS_Req, FingerPrintService_CancelScanJS_Ans>::Pointer ctx;
- virtual void OnUnhandled()
- {
- if (ctx != NULL)
- {
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM).setResultCode("RTA242H")("GenerateTemplateJS unhandled.");
- }
- }
- };
- class CFingerPrintFSM : public CCommDevFSM<CFingerPrintFSM, FingerPrintClass>
- {
- public:
- enum {s0, s1, s2, s3, s4};
- BEGIN_FSM_STATE(CFingerPrintFSM)
- FSM_STATE_ENTRY(s0, "Normal", s0_on_entry,s0_on_exit,s0_on_event)
- FSM_STATE_ENTRY(s1, "Scan", s1_on_entry,s1_on_exit,s1_on_event)
- FSM_STATE_ENTRY(s2, "Fail", s2_on_entry,s2_on_exit,s2_on_event)
- FSM_STATE_ENTRY(s3, "Match", s3_on_entry,s3_on_exit,s3_on_event)//废弃的状态
- FSM_STATE_ENTRY(s4, "Init", s4_on_entry,s4_on_exit,s4_on_event)
- END_FSM_STATE()
- BEGIN_FSM_RULE(CFingerPrintFSM, s4)
- FSM_RULE_ENTRY(s0, FSM_STATE_EXIT, USER_EVT_QUIT, 0)
- FSM_RULE_ENTRY(s0, s1, USER_EVT_SCAN, 0)
- FSM_RULE_ENTRY(s0, s1, USER_EVT_SCANEX, 0)
- FSM_RULE_ENTRY(s0, s1, USER_EVT_GETFINGER, 0)
- FSM_RULE_ENTRY(s0, s1, USER_EVT_GENERATE_TEMPLATE, 0)
- FSM_RULE_ENTRY(s0, s1, USER_EVT_SCANEX, 0)
- FSM_RULE_ENTRY(s0, s2, USER_EVT_ERROR, 0)
- FSM_RULE_ENTRY(s0, s3, USER_EVT_MATCH, 0)
- FSM_RULE_ENTRY(s0, s4, USER_EVT_FWB_OPEN_SUC_FINISHED, 0)
- FSM_RULE_ENTRY(s0, s1, USER_EVT_JS_GET_FINGERPRINT, 0)//js 扫描
- FSM_RULE_ENTRY(s0, s1, USER_EVT_JS_GENERATE_TEMPLATE, 0)//js 指纹模版
- FSM_RULE_ENTRY(s1, FSM_STATE_EXIT, USER_EVT_QUIT, 0)
- FSM_RULE_ENTRY(s1, s0, USER_EVT_SCAN_FINISHED, 0)
- FSM_RULE_ENTRY(s1, s2, USER_EVT_SCAN_FINISHED, 2)
- FSM_RULE_ENTRY(s1, s0, USER_EVT_SCANEX_FINISHED, 0)
- FSM_RULE_ENTRY(s1, s2, USER_EVT_SCANEX_FINISHED, 2)
- FSM_RULE_ENTRY(s1, s0, USER_EVT_GETFINGER_FINISHED, 0)
- FSM_RULE_ENTRY(s1, s2, USER_EVT_GETFINGER_FINISHED, 2)
- FSM_RULE_ENTRY(s1, s0, USER_EVT_GENERATE_TEMPLATE_FINISHED, 0)
- FSM_RULE_ENTRY(s1, s2, USER_EVT_GENERATE_TEMPLATE_FINISHED, 2)
- FSM_RULE_ENTRY(s1, s0, USER_EVT_JS_GET_FINGERPRINT_FINISHED, 0)//js 扫描
- FSM_RULE_ENTRY(s1, s0, USER_EVT_JS_GENERATE_TEMPLATE_FINISHED, 0)//js 指纹模版
- FSM_RULE_ENTRY(s2, s4, USER_EVT_FWB_OPEN_SUC_FINISHED, 0)
- FSM_RULE_ENTRY(s3, FSM_STATE_EXIT, USER_EVT_QUIT, 0)
- FSM_RULE_ENTRY(s3, s0, USER_EVT_MATCH_FINISHED, 0)
- FSM_RULE_ENTRY(s3, s2, USER_EVT_MATCH_FINISHED, 2)
- FSM_RULE_ENTRY(s4, s0, USER_EVT_INIT_FINISHED, 0)
- FSM_RULE_ENTRY(s4, s2, USER_EVT_INIT_FINISHED, 2)
- END_FSM_RULE()
- CFingerPrintFSM():m_bCancelRegister(false), m_bCancelMatch(false), m_bExit(false),
- m_testResult(Error_Succeed),
- m_bCancelScan(false), m_bExitMainPage(false)
- {
- HARDWARE_ENTITY_RESET_ENTITYID(m_entCode, 0x204);
- }
- virtual ErrorCodeEnum OnInit();
- virtual ErrorCodeEnum OnExit();
- void s0_on_entry();
- void s0_on_exit();
- unsigned int s0_on_event(FSMEvent* e);
- void s4_on_entry();
- void s4_on_exit();
- unsigned int s4_on_event(FSMEvent* e);
- void s1_on_entry();
- void s1_on_exit();
- unsigned int s1_on_event(FSMEvent* e);
- void s2_on_entry();
- void s2_on_exit();
- unsigned int s2_on_event(FSMEvent* e);
- void s3_on_entry();
- void s3_on_exit();
- unsigned int s3_on_event(FSMEvent* e);
- int GetFingerPrint(SpReqAnsContext<FingerPrintService_GetFingerPrint_Req, FingerPrintService_GetFingerPrint_Ans>::Pointer ctx);
- int GenerateTemplate(SpReqAnsContext<FingerPrintService_GenerateTemplate_Req, FingerPrintService_GenerateTemplate_Ans>::Pointer ctx);
- void DeleteBmp(int type);
- ErrorCodeEnum DeleteFileIfExisted(const char* fileName);
- ErrorCodeEnum GetDevCatInfo(DevCategoryInfo& devInfo);
- ErrorCodeEnum GetCurDevState(int &state);
- int Initial();
- CSimpleStringA getRTACode(DWORD dwUserCode) {
- return this->GetEntityBase()->GetFunction()->UserCodeToRTACode(dwUserCode);
- }
- void SelfTest(EntityTestEnum eTestType,CSmartPointer<ITransactionContext> pTransactionContext);
- private:
- ErrorCodeEnum m_testResult;
- DevCategoryInfo m_devCatInfo;
-
- bool m_bCancelRegister;
- bool m_bCancelMatch;
- bool m_bExit;
-
- public:
- int GetFingerPrintJS(SpReqAnsContext<FingerPrintService_GetFingerPrintJS_Req, FingerPrintService_GetFingerPrintJS_Ans>::Pointer ctx);
- int GenerateTemplateJS(SpReqAnsContext<FingerPrintService_GenerateTemplateJS_Req, FingerPrintService_GenerateTemplateJS_Ans>::Pointer ctx);
- ErrorCodeEnum GetImgBlob(CBlob& data, CSimpleStringA imgPath);
- ErrorCodeEnum DeleteFingerBmp(CSimpleStringA imgPath);
- ErrorCodeEnum DeleteRegisterFingerBmp();
- void insertRegisterFingerBmp(CSimpleStringA bmpPath);
- DWORD GetFsmStateErrCode();
- private:
- bool m_bCancelScan;
- bool m_bExitMainPage;
- set<CSimpleStringA> m_fingerPrintFileSet;
- std::mutex m_fingerfileMtx;
- };
- //废弃
- struct ScanTask : public ITaskSp
- {
- CFingerPrintFSM* fsm;
- SpReqAnsContext<FingerPrintService_GetImageAndFeature_Req, FingerPrintService_GetImageAndFeature_Ans>::Pointer ctx;
- ScanTask(CFingerPrintFSM* f) : fsm(f){}
- void Process()
- {
- //LOG_FUNCTION();
- //FSMEvent* e = new FSMEvent(USER_EVT_SCAN_FINISHED);
- //e->param1 = fsm->GetImageAndFeature(ctx);
- //fsm->PostEventFIFO(e);
- }
- };
- //废弃
- struct ScanExTask : public ITaskSp
- {
- CFingerPrintFSM* fsm;
- SpReqAnsContext<FingerPrintService_GetImageAndFeatureEx_Req, FingerPrintService_GetImageAndFeatureEx_Ans>::Pointer ctx;
- ScanExTask(CFingerPrintFSM* f) : fsm(f) {}
- void Process()
- {
- //LOG_FUNCTION();
- //FSMEvent* e = new FSMEvent(USER_EVT_SCANEX_FINISHED);
- //e->param1 = fsm->GetImageAndFeatureEx(ctx);
- //fsm->PostEventFIFO(e);
- }
- };
- //有用
- struct GetFingerTask : public ITaskSp
- {
- CFingerPrintFSM* fsm;
- SpReqAnsContext<FingerPrintService_GetFingerPrint_Req, FingerPrintService_GetFingerPrint_Ans>::Pointer ctx;
- GetFingerTask(CFingerPrintFSM* f) : fsm(f) {}
- void Process()
- {
- LOG_FUNCTION();
- FSMEvent* e = new FSMEvent(USER_EVT_GETFINGER_FINISHED);
- e->param1 = fsm->GetFingerPrint(ctx);
- fsm->PostEventFIFO(e);
- }
- };
- //有用
- struct GenerateTemplateTask : public ITaskSp
- {
- CFingerPrintFSM* fsm;
- SpReqAnsContext<FingerPrintService_GenerateTemplate_Req, FingerPrintService_GenerateTemplate_Ans>::Pointer ctx;
- GenerateTemplateTask(CFingerPrintFSM* f) : fsm(f) {}
- void Process()
- {
- LOG_FUNCTION();
- FSMEvent* e = new FSMEvent(USER_EVT_GENERATE_TEMPLATE_FINISHED);
- e->param1 = fsm->GenerateTemplate(ctx);
- fsm->PostEventFIFO(e);
- }
- };
- //废弃
- struct MatchTask : public ITaskSp
- {
- CFingerPrintFSM* fsm;
- SpReqAnsContext<FingerPrintService_Match_Req, FingerPrintService_Match_Ans>::Pointer ctx;
- MatchTask(CFingerPrintFSM* f) : fsm(f){}
- void Process()
- {
- //LOG_FUNCTION();
- //MatchFinishedEvent* e = new MatchFinishedEvent();
- //e->param1 = fsm->Match(ctx);
- //e->ctx = ctx;
- //fsm->PostEventFIFO(e);
- }
- };
- //有用
- struct InitTask : public ITaskSp
- {
- CFingerPrintFSM* fsm;
- InitTask(CFingerPrintFSM* f) : fsm(f) {}
- void Process()
- {
- FSMEvent* e = new FSMEvent(USER_EVT_INIT_FINISHED);
- fsm->m_bOpening = true;
- e->param1 = fsm->Initial();
- fsm->m_bOpening = false;
- fsm->PostEventFIFO(e);
- }
- };
- //JS
- struct GetFingerPrintJSTask : public ITaskSp
- {
- CFingerPrintFSM* fsm;
- SpReqAnsContext<FingerPrintService_GetFingerPrintJS_Req, FingerPrintService_GetFingerPrintJS_Ans>::Pointer ctx;
- GetFingerPrintJSTask(CFingerPrintFSM* f) : fsm(f) {}
- void Process()
- {
- LOG_FUNCTION();
- FSMEvent* e = new FSMEvent(USER_EVT_JS_GET_FINGERPRINT_FINISHED);
- e->param1 = fsm->GetFingerPrintJS(ctx);
- fsm->PostEventFIFO(e);
- }
- };
- struct GenerateTemplateJSTask : public ITaskSp
- {
- CFingerPrintFSM* fsm;
- SpReqAnsContext<FingerPrintService_GenerateTemplateJS_Req, FingerPrintService_GenerateTemplateJS_Ans>::Pointer ctx;
- GenerateTemplateJSTask(CFingerPrintFSM* f) : fsm(f) {}
- void Process()
- {
- LOG_FUNCTION();
- FSMEvent* e = new FSMEvent(USER_EVT_JS_GENERATE_TEMPLATE_FINISHED);
- e->param1 = fsm->GenerateTemplateJS(ctx);
- fsm->PostEventFIFO(e);
- }
- };
- #endif
|