FingerPrintFSM.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382
  1. #ifndef FINGERPRINT_FSM_H
  2. #define FINGERPRINT_FSM_H
  3. #include "SpFSM.h"
  4. #include "DevFSMCommBase.hpp"
  5. #include "FingerPrintClass.h"
  6. #include "FingerPrint_UserErrorCode.h"
  7. #include "CommEntityUtil.hpp"
  8. using namespace std;
  9. enum EvtType
  10. {
  11. USER_EVT_TEST = EVT_USER + 1,
  12. USER_EVT_INIT,
  13. USER_EVT_INIT_FINISHED,
  14. USER_EVT_GET_DEVINFO,
  15. USER_EVT_SCAN,
  16. USER_EVT_SCAN_FINISHED,
  17. USER_EVT_SCANEX,
  18. USER_EVT_SCANEX_FINISHED,
  19. USER_EVT_MATCH,
  20. USER_EVT_MATCH_FINISHED,
  21. USER_EVT_GETFINGER,
  22. USER_EVT_GETFINGER_FINISHED,
  23. USER_EVT_GENERATE_TEMPLATE,
  24. USER_EVT_GENERATE_TEMPLATE_FINISHED,
  25. USER_EVT_MATCH_FINGERPRINT,
  26. USER_EVT_MATCH_FINGERPRINT_FINISHED,
  27. USER_EVT_CANCEL_SCAN,
  28. USER_EVT_CANCEL_MATCH,
  29. USER_EVT_CANCEL_SCAN_FINISHED,
  30. USER_EVT_QUIT,
  31. USER_EVT_ERROR,
  32. USER_EVT_EXIT,
  33. USER_EVT_FWB_OPEN_SUC,
  34. USER_EVT_FWB_OPEN_SUC_FINISHED,
  35. };
  36. enum BmpType
  37. {
  38. BmpImage = 1,
  39. TestImage
  40. };
  41. #include "FingerPrint_server_g.h"
  42. #include "FingerPrintClass.h"
  43. using namespace FingerPrint;
  44. class ScanEvent : public FSMEvent
  45. {
  46. public:
  47. ScanEvent() : FSMEvent(USER_EVT_SCAN){}
  48. virtual ~ScanEvent(){}
  49. SpReqAnsContext<FingerPrintService_GetImageAndFeature_Req, FingerPrintService_GetImageAndFeature_Ans>::Pointer ctx;
  50. virtual void OnUnhandled()
  51. {
  52. if (ctx != NULL) {
  53. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("ScanEvent unhandled.");
  54. ctx->Answer(Error_InvalidState);
  55. }
  56. }
  57. };
  58. class ScanExEvent : public FSMEvent
  59. {
  60. public:
  61. ScanExEvent() : FSMEvent(USER_EVT_SCANEX) {}
  62. virtual ~ScanExEvent() {}
  63. SpReqAnsContext<FingerPrintService_GetImageAndFeatureEx_Req, FingerPrintService_GetImageAndFeatureEx_Ans>::Pointer ctx;
  64. virtual void OnUnhandled()
  65. {
  66. if (ctx != NULL)
  67. {
  68. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("ScanEx unhandled");
  69. ctx->Answer(Error_InvalidState);
  70. }
  71. }
  72. };
  73. class GetFingerEvent : public FSMEvent
  74. {
  75. public:
  76. GetFingerEvent() : FSMEvent(USER_EVT_GETFINGER) {}
  77. virtual ~GetFingerEvent() {}
  78. SpReqAnsContext<FingerPrintService_GetFingerPrint_Req, FingerPrintService_GetFingerPrint_Ans>::Pointer ctx;
  79. virtual void OnUnhandled()
  80. {
  81. if (ctx != NULL)
  82. {
  83. ctx->Answer(Error_InvalidState);
  84. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("GetFinger unhandled");
  85. }
  86. }
  87. };
  88. class GenerateTemplateEvent : public FSMEvent
  89. {
  90. public:
  91. GenerateTemplateEvent() : FSMEvent(USER_EVT_GENERATE_TEMPLATE) {}
  92. virtual ~GenerateTemplateEvent() {}
  93. SpReqAnsContext<FingerPrintService_GenerateTemplate_Req, FingerPrintService_GenerateTemplate_Ans>::Pointer ctx;
  94. virtual void OnUnhandled()
  95. {
  96. if (ctx != NULL)
  97. {
  98. ctx->Answer(Error_InvalidState);
  99. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("GenerateTemplate unhandled.");
  100. }
  101. }
  102. };
  103. class CancelRegisterEvent : public FSMEvent
  104. {
  105. public:
  106. CancelRegisterEvent() : FSMEvent(USER_EVT_CANCEL_SCAN){}
  107. virtual ~CancelRegisterEvent(){}
  108. virtual void OnUnhandled()
  109. {
  110. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("Cancel scan not handled");
  111. }
  112. };
  113. class MatchEvent : public FSMEvent
  114. {
  115. public:
  116. MatchEvent() : FSMEvent(USER_EVT_MATCH){}
  117. virtual ~MatchEvent(){}
  118. SpReqAnsContext<FingerPrintService_Match_Req, FingerPrintService_Match_Ans>::Pointer ctx;
  119. virtual void OnUnhandled()
  120. {
  121. if (ctx != NULL)
  122. {
  123. ctx->Answer(Error_InvalidState);
  124. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("Match unhandled.");
  125. }
  126. }
  127. };
  128. class MatchFinishedEvent : public FSMEvent
  129. {
  130. public:
  131. MatchFinishedEvent() : FSMEvent(USER_EVT_MATCH_FINISHED){}
  132. ~MatchFinishedEvent(){}
  133. SpReqAnsContext<FingerPrintService_Match_Req, FingerPrintService_Match_Ans>::Pointer ctx;
  134. virtual void OnUnhandled()
  135. {
  136. if (ctx != NULL)
  137. {
  138. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("Match finished unhandled.");
  139. }
  140. }
  141. };
  142. class GetFingerFinishedEvent : public FSMEvent
  143. {
  144. public:
  145. GetFingerFinishedEvent() : FSMEvent(USER_EVT_GETFINGER_FINISHED) {}
  146. ~GetFingerFinishedEvent() {}
  147. SpReqAnsContext<FingerPrintService_GetFingerPrint_Req, FingerPrintService_GetFingerPrint_Ans>::Pointer ctx;
  148. virtual void OnUnhandled()
  149. {
  150. if (ctx != NULL)
  151. {
  152. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("GetFingerFinished unhandled.");
  153. }
  154. }
  155. };
  156. class CancelMatchEvent : public FSMEvent
  157. {
  158. public:
  159. CancelMatchEvent() : FSMEvent(USER_EVT_CANCEL_MATCH){}
  160. virtual ~CancelMatchEvent(){}
  161. virtual void OnUnhandled()
  162. {
  163. DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("Cancel match not handled");
  164. }
  165. };
  166. class GetDevInfoEvent : public FSMEvent
  167. {
  168. public:
  169. GetDevInfoEvent() : FSMEvent(USER_EVT_GET_DEVINFO){}
  170. virtual ~GetDevInfoEvent(){}
  171. SpReqAnsContext<FingerPrintService_GetDevInfo_Req, FingerPrintService_GetDevInfo_Ans>::Pointer ctx;
  172. virtual void OnUnhandled()
  173. {
  174. if(ctx != NULL)
  175. ctx->Answer(Error_InvalidState);
  176. }
  177. };
  178. class CFingerPrintFSM : public CCommDevFSM<CFingerPrintFSM, FingerPrintClass>
  179. {
  180. public:
  181. enum {s0, s1, s2, s3, s4};
  182. BEGIN_FSM_STATE(CFingerPrintFSM)
  183. FSM_STATE_ENTRY(s0, "Normal", s0_on_entry,s0_on_exit,s0_on_event)
  184. FSM_STATE_ENTRY(s1, "Scan", s1_on_entry,s1_on_exit,s1_on_event)
  185. FSM_STATE_ENTRY(s2, "Fail", s2_on_entry,s2_on_exit,s2_on_event)
  186. FSM_STATE_ENTRY(s3, "Match", s3_on_entry,s3_on_exit,s3_on_event)//废弃的状态
  187. FSM_STATE_ENTRY(s4, "Init", s4_on_entry,s4_on_exit,s4_on_event)
  188. END_FSM_STATE()
  189. BEGIN_FSM_RULE(CFingerPrintFSM, s4)
  190. FSM_RULE_ENTRY(s0, FSM_STATE_EXIT, USER_EVT_QUIT, 0)
  191. FSM_RULE_ENTRY(s0, s1, USER_EVT_SCAN, 0)
  192. FSM_RULE_ENTRY(s0, s1, USER_EVT_SCANEX, 0)
  193. FSM_RULE_ENTRY(s0, s1, USER_EVT_GETFINGER, 0)
  194. FSM_RULE_ENTRY(s0, s1, USER_EVT_GENERATE_TEMPLATE, 0)
  195. FSM_RULE_ENTRY(s0, s1, USER_EVT_SCANEX, 0)
  196. FSM_RULE_ENTRY(s0, s2, USER_EVT_ERROR, 0)
  197. FSM_RULE_ENTRY(s0, s3, USER_EVT_MATCH, 0)
  198. FSM_RULE_ENTRY(s0, s4, USER_EVT_FWB_OPEN_SUC_FINISHED, 0)
  199. FSM_RULE_ENTRY(s1, FSM_STATE_EXIT, USER_EVT_QUIT, 0)
  200. FSM_RULE_ENTRY(s1, s0, USER_EVT_SCAN_FINISHED, 0)
  201. FSM_RULE_ENTRY(s1, s2, USER_EVT_SCAN_FINISHED, 2)
  202. FSM_RULE_ENTRY(s1, s0, USER_EVT_SCANEX_FINISHED, 0)
  203. FSM_RULE_ENTRY(s1, s2, USER_EVT_SCANEX_FINISHED, 2)
  204. FSM_RULE_ENTRY(s1, s0, USER_EVT_GETFINGER_FINISHED, 0)
  205. FSM_RULE_ENTRY(s1, s2, USER_EVT_GETFINGER_FINISHED, 2)
  206. FSM_RULE_ENTRY(s1, s0, USER_EVT_GENERATE_TEMPLATE_FINISHED, 0)
  207. FSM_RULE_ENTRY(s1, s2, USER_EVT_GENERATE_TEMPLATE_FINISHED, 2)
  208. FSM_RULE_ENTRY(s2, s4, USER_EVT_FWB_OPEN_SUC_FINISHED, 0)
  209. FSM_RULE_ENTRY(s3, FSM_STATE_EXIT, USER_EVT_QUIT, 0)
  210. FSM_RULE_ENTRY(s3, s0, USER_EVT_MATCH_FINISHED, 0)
  211. FSM_RULE_ENTRY(s3, s2, USER_EVT_MATCH_FINISHED, 2)
  212. FSM_RULE_ENTRY(s4, s0, USER_EVT_INIT_FINISHED, 0)
  213. FSM_RULE_ENTRY(s4, s2, USER_EVT_INIT_FINISHED, 2)
  214. END_FSM_RULE()
  215. CFingerPrintFSM():m_bCancelRegister(false), m_bCancelMatch(false), m_bExit(false),
  216. m_testResult(Error_Succeed), m_csDevSN(""), m_iInWhatPage(PageType_Init),
  217. m_csMachineType(""), m_terminalNo(""), m_machineVersion("")
  218. {
  219. HARDWARE_ENTITY_RESET_ENTITYID(m_entCode, 0x204);
  220. }
  221. virtual ErrorCodeEnum OnInit();
  222. virtual ErrorCodeEnum OnExit();
  223. void s0_on_entry();
  224. void s0_on_exit();
  225. unsigned int s0_on_event(FSMEvent* e);
  226. void s4_on_entry();
  227. void s4_on_exit();
  228. unsigned int s4_on_event(FSMEvent* e);
  229. void s1_on_entry();
  230. void s1_on_exit();
  231. unsigned int s1_on_event(FSMEvent* e);
  232. void s2_on_entry();
  233. void s2_on_exit();
  234. unsigned int s2_on_event(FSMEvent* e);
  235. void s3_on_entry();
  236. void s3_on_exit();
  237. unsigned int s3_on_event(FSMEvent* e);
  238. int GetFingerPrint(SpReqAnsContext<FingerPrintService_GetFingerPrint_Req, FingerPrintService_GetFingerPrint_Ans>::Pointer ctx);
  239. int GenerateTemplate(SpReqAnsContext<FingerPrintService_GenerateTemplate_Req, FingerPrintService_GenerateTemplate_Ans>::Pointer ctx);
  240. void DeleteBmp(int type);
  241. ErrorCodeEnum DeleteFileIfExisted(const char* fileName);
  242. ErrorCodeEnum GetDevCatInfo(DevCategoryInfo& devInfo);
  243. ErrorCodeEnum GetDevState(int &state);
  244. int Initial();
  245. bool GetDevInitFlag() { return m_bOpened; }
  246. void SetInWhatPage(int bValue) { m_iInWhatPage = bValue; }
  247. DevStateEnum GetDevState(){
  248. return m_devState;
  249. }
  250. void SelfTest(EntityTestEnum eTestType,CSmartPointer<ITransactionContext> pTransactionContext);
  251. private:
  252. ErrorCodeEnum m_testResult;
  253. DevCategoryInfo m_devCatInfo;
  254. DevStateEnum m_devState;
  255. bool m_bCancelRegister;
  256. bool m_bCancelMatch;
  257. bool m_bExit;
  258. int m_iInWhatPage/*在哪个页面,区分首页,用户桌面,其他页*/;
  259. CSimpleStringA m_csDevSN, m_csMachineType, m_terminalNo, m_machineVersion;
  260. };
  261. //废弃
  262. struct ScanTask : public ITaskSp
  263. {
  264. CFingerPrintFSM* fsm;
  265. SpReqAnsContext<FingerPrintService_GetImageAndFeature_Req, FingerPrintService_GetImageAndFeature_Ans>::Pointer ctx;
  266. ScanTask(CFingerPrintFSM* f) : fsm(f){}
  267. void Process()
  268. {
  269. //LOG_FUNCTION();
  270. //FSMEvent* e = new FSMEvent(USER_EVT_SCAN_FINISHED);
  271. //e->param1 = fsm->GetImageAndFeature(ctx);
  272. //fsm->PostEventFIFO(e);
  273. }
  274. };
  275. //废弃
  276. struct ScanExTask : public ITaskSp
  277. {
  278. CFingerPrintFSM* fsm;
  279. SpReqAnsContext<FingerPrintService_GetImageAndFeatureEx_Req, FingerPrintService_GetImageAndFeatureEx_Ans>::Pointer ctx;
  280. ScanExTask(CFingerPrintFSM* f) : fsm(f) {}
  281. void Process()
  282. {
  283. //LOG_FUNCTION();
  284. //FSMEvent* e = new FSMEvent(USER_EVT_SCANEX_FINISHED);
  285. //e->param1 = fsm->GetImageAndFeatureEx(ctx);
  286. //fsm->PostEventFIFO(e);
  287. }
  288. };
  289. //有用
  290. struct GetFingerTask : public ITaskSp
  291. {
  292. CFingerPrintFSM* fsm;
  293. SpReqAnsContext<FingerPrintService_GetFingerPrint_Req, FingerPrintService_GetFingerPrint_Ans>::Pointer ctx;
  294. GetFingerTask(CFingerPrintFSM* f) : fsm(f) {}
  295. void Process()
  296. {
  297. LOG_FUNCTION();
  298. FSMEvent* e = new FSMEvent(USER_EVT_GETFINGER_FINISHED);
  299. e->param1 = fsm->GetFingerPrint(ctx);
  300. fsm->PostEventFIFO(e);
  301. }
  302. };
  303. //有用
  304. struct GenerateTemplateTask : public ITaskSp
  305. {
  306. CFingerPrintFSM* fsm;
  307. SpReqAnsContext<FingerPrintService_GenerateTemplate_Req, FingerPrintService_GenerateTemplate_Ans>::Pointer ctx;
  308. GenerateTemplateTask(CFingerPrintFSM* f) : fsm(f) {}
  309. void Process()
  310. {
  311. LOG_FUNCTION();
  312. FSMEvent* e = new FSMEvent(USER_EVT_GENERATE_TEMPLATE_FINISHED);
  313. e->param1 = fsm->GenerateTemplate(ctx);
  314. fsm->PostEventFIFO(e);
  315. }
  316. };
  317. //废弃
  318. struct MatchTask : public ITaskSp
  319. {
  320. CFingerPrintFSM* fsm;
  321. SpReqAnsContext<FingerPrintService_Match_Req, FingerPrintService_Match_Ans>::Pointer ctx;
  322. MatchTask(CFingerPrintFSM* f) : fsm(f){}
  323. void Process()
  324. {
  325. //LOG_FUNCTION();
  326. //MatchFinishedEvent* e = new MatchFinishedEvent();
  327. //e->param1 = fsm->Match(ctx);
  328. //e->ctx = ctx;
  329. //fsm->PostEventFIFO(e);
  330. }
  331. };
  332. //有用
  333. struct InitTask : public ITaskSp
  334. {
  335. CFingerPrintFSM* fsm;
  336. InitTask(CFingerPrintFSM* f) : fsm(f) {}
  337. void Process()
  338. {
  339. FSMEvent* e = new FSMEvent(USER_EVT_INIT_FINISHED);
  340. e->param1 = fsm->Initial();
  341. fsm->PostEventFIFO(e);
  342. }
  343. };
  344. #endif