CustMngrAuthFSM.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601
  1. #ifndef __CUSTMNGRAUTH_FSM_H
  2. #define __CUSTMNGRAUTH_FSM_H
  3. #pragma once
  4. #include "SpFSM.h"
  5. #include "SpSecureClient.h"
  6. #include "json/json.h"
  7. #include "CustMngrAuth_server_g.h"
  8. #include "CustMngrAuth_msg_g.h"
  9. using namespace CustMngrAuth;
  10. #include "FingerPrint_client_g.h"
  11. #include "MaintainWatcher_client_g.h"
  12. #include "MaintainWatcher_msg_g.h"
  13. #include "DeviceControl_client_g.h"
  14. //#include "DeviceCrossHelper.h"
  15. //#include <map>
  16. using namespace std;
  17. using namespace MaintainWatcher;
  18. using namespace DeviceControl;
  19. using namespace FingerPrint;
  20. //下载特征库所调用的分行服务接口
  21. #pragma pack(1)
  22. // [StructName("FETQYREQ")]
  23. struct FeatReq
  24. {
  25. char TerminalID[16];
  26. char BranchID[16];
  27. char CurrentAgent[16];
  28. char UpdateTime[20];
  29. };
  30. // [StructName("FETQYANS")]
  31. struct FeatReply
  32. {
  33. int ResultCode;
  34. char BranchID[16];
  35. char CurrentAgent[16];
  36. char Data[0];//no more than 45k
  37. };
  38. struct FeatureData{
  39. CAutoArray<CSimpleStringA> FingerIDArray;
  40. CAutoArray<int> FingerIDLenArray;
  41. };
  42. struct TemplateInfo{
  43. CSimpleStringA CustomerID;
  44. int TemplateNum;
  45. };
  46. #pragma pack()
  47. enum EvtType{
  48. USER_EVT_TEST = EVT_USER + 1,
  49. USER_EVT_QUIT,
  50. USER_EVT_INIT,
  51. USER_EVT_INIT_FINISHED,
  52. USER_EVT_AUTHORIZE_START,
  53. USER_EVT_AUTHORIZE_FINISHED,
  54. USER_EVT_AUTHORIZE_CANCEL,
  55. USER_EVT_COLLECTFINGERPRINT_START,
  56. USER_EVT_COLLECTFINGERPRINT_FINISHED,
  57. USER_EVT_COLLECTFINGERPRINT_CANCEL,
  58. USER_EVT_SAVEFINGERPRINT_START,
  59. USER_EVT_SAVEFINGERPRINT_FINISHED,
  60. USER_EVT_CHECKUKEY,
  61. USER_EVT_CHECKUKEY_FINISHED,
  62. USER_EVT_HOLDON,
  63. USER_EVT_EXIT,
  64. };
  65. enum AuthByWhich//授权结果
  66. {
  67. AuthByNone = 0,
  68. AuthByFngPrnt = 1,
  69. AuthByUkey = 2,
  70. };
  71. struct AuthContext
  72. {
  73. AuthByWhich eAuthByWhich;
  74. CSimpleStringA UkeyID;
  75. CSimpleStringA CustomerID;
  76. };
  77. class CCustMngrAuthEntity;
  78. class CCustMngrAuthFSM;
  79. class AuthorizeStartEvent : public FSMEvent
  80. {
  81. public:
  82. AuthorizeStartEvent() : FSMEvent(USER_EVT_AUTHORIZE_START){}
  83. ~AuthorizeStartEvent(){}
  84. SpReqAnsContext<CustMngrAuthService_StartAuthorize_Req, CustMngrAuthService_StartAuthorize_Ans>::Pointer ctx;
  85. virtual void OnUnhandled()
  86. {
  87. Dbg("authorize_start unhandled");
  88. }
  89. protected:
  90. private:
  91. };
  92. class AuthorizeFinishedEvent : public FSMEvent
  93. {
  94. public:
  95. AuthorizeFinishedEvent() : FSMEvent(USER_EVT_AUTHORIZE_FINISHED){}
  96. ~AuthorizeFinishedEvent(){}
  97. SpReqAnsContext<CustMngrAuthService_StartAuthorize_Req, CustMngrAuthService_StartAuthorize_Ans>::Pointer ctx;
  98. virtual void OnUnhandled()
  99. {
  100. Dbg("authorize_finished unhandled");
  101. }
  102. protected:
  103. private:
  104. };
  105. class AuthorizeCancelEvent : public FSMEvent
  106. {
  107. public:
  108. AuthorizeCancelEvent() : FSMEvent(USER_EVT_AUTHORIZE_CANCEL){}
  109. ~AuthorizeCancelEvent(){}
  110. SpReqAnsContext<CustMngrAuthService_StopAuthorize_Req, CustMngrAuthService_StopAuthorize_Ans>::Pointer ctx;
  111. virtual void OnUnhandled()
  112. {
  113. if (ctx!=NULL)
  114. {
  115. Dbg("authorize_cancel unhandled");
  116. ctx->Answer(Error_InvalidState);
  117. }
  118. Dbg("authorize_cancel unhandled");
  119. }
  120. protected:
  121. private:
  122. };
  123. class CollectFingerPrintStartEvent : public FSMEvent
  124. {
  125. public:
  126. CollectFingerPrintStartEvent() : FSMEvent(USER_EVT_COLLECTFINGERPRINT_START){}
  127. ~CollectFingerPrintStartEvent(){}
  128. SpReqAnsContext<CustMngrAuthService_CollectFingerPrint_Req, CustMngrAuthService_CollectFingerPrint_Ans>::Pointer ctx;
  129. virtual void OnUnhandled()
  130. {
  131. if (ctx!=NULL)
  132. {
  133. Dbg("collect_finger_print unhandled");
  134. ctx->Answer(Error_InvalidState);
  135. }
  136. }
  137. protected:
  138. private:
  139. };
  140. class CollectFingerPrintFinishedEvent : public FSMEvent
  141. {
  142. public:
  143. CollectFingerPrintFinishedEvent() : FSMEvent(USER_EVT_COLLECTFINGERPRINT_FINISHED){}
  144. ~CollectFingerPrintFinishedEvent(){}
  145. SpReqAnsContext<CustMngrAuthService_CollectFingerPrint_Req, CustMngrAuthService_CollectFingerPrint_Ans>::Pointer ctx;
  146. virtual void OnUnhandled()
  147. {
  148. if (ctx!=NULL)
  149. {
  150. Dbg("collect_finger_print_finished unhandled");
  151. ctx->Answer(Error_InvalidState);
  152. }
  153. }
  154. protected:
  155. private:
  156. };
  157. class CancelCollectFingerPrintEvent : public FSMEvent
  158. {
  159. public:
  160. CancelCollectFingerPrintEvent() : FSMEvent(USER_EVT_COLLECTFINGERPRINT_CANCEL){}
  161. ~CancelCollectFingerPrintEvent(){}
  162. virtual void OnUnhandled()
  163. {
  164. Dbg("cancel collect fingerprint unhandled");
  165. }
  166. };
  167. class SaveFingerPrintStartEvent : public FSMEvent
  168. {
  169. public:
  170. SaveFingerPrintStartEvent() : FSMEvent(USER_EVT_SAVEFINGERPRINT_START){}
  171. ~SaveFingerPrintStartEvent(){}
  172. SpReqAnsContext<CustMngrAuthService_SaveFingerPrint_Req, CustMngrAuthService_SaveFingerPrint_Ans>::Pointer ctx;
  173. virtual void OnUnhandled(){
  174. if (ctx!=NULL)
  175. {
  176. Dbg("save_finger_print_start unhandled");
  177. ctx->Answer(Error_InvalidState);
  178. }
  179. }
  180. };
  181. class SaveFingerPrintFinishedEvent : public FSMEvent
  182. {
  183. public:
  184. SaveFingerPrintFinishedEvent() : FSMEvent(USER_EVT_SAVEFINGERPRINT_FINISHED){}
  185. ~SaveFingerPrintFinishedEvent(){}
  186. SpReqAnsContext<CustMngrAuthService_SaveFingerPrint_Req, CustMngrAuthService_SaveFingerPrint_Ans>::Pointer ctx;
  187. virtual void OnUnhandled(){
  188. if (ctx!=NULL)
  189. {
  190. Dbg("save_finger_print_finished unhandled");
  191. ctx->Answer(Error_InvalidState);
  192. }
  193. }
  194. };
  195. class CheckUkeyEvent : public FSMEvent
  196. {
  197. public:
  198. CheckUkeyEvent() : FSMEvent(USER_EVT_CHECKUKEY){}
  199. ~CheckUkeyEvent(){}
  200. virtual void OnUnhandled()
  201. {
  202. Dbg("check_ukey unhandled");
  203. }
  204. };
  205. class CheckUkeyFinishedEvent : public FSMEvent
  206. {
  207. public:
  208. CheckUkeyFinishedEvent() : FSMEvent(USER_EVT_CHECKUKEY_FINISHED){}
  209. ~CheckUkeyFinishedEvent(){}
  210. virtual void OnUnhandled()
  211. {
  212. Dbg("check_ukey_finished unhandled");
  213. }
  214. };
  215. class HoldOnEvent : public FSMEvent
  216. {
  217. public:
  218. HoldOnEvent() : FSMEvent(USER_EVT_HOLDON){}
  219. ~HoldOnEvent(){}
  220. SpReqAnsContext<CustMngrAuthService_HoldOn_Req, CustMngrAuthService_HoldOn_Ans>::Pointer ctx;
  221. virtual void OnUnhandled(){
  222. if (ctx!=NULL)
  223. {
  224. Dbg("holdon unhandled");
  225. ctx->Answer(Error_InvalidState);
  226. }
  227. }
  228. };
  229. class FeatureUpdateConn;
  230. class CCustMngrAuthFSM : public FSMImpl<CCustMngrAuthFSM>
  231. {
  232. public:
  233. enum { s0, s1, s2, s3, s4, s5};
  234. BEGIN_FSM_STATE(CCustMngrAuthFSM)
  235. FSM_STATE_ENTRY(s0, "Init", s0_on_entry, s0_on_exit, s0_on_event)
  236. FSM_STATE_ENTRY(s1, "Initializing", s1_on_entry, s1_on_exit, s1_on_event)
  237. FSM_STATE_ENTRY(s2, "Idle", s2_on_entry, s2_on_exit, s2_on_event)
  238. FSM_STATE_ENTRY(s3, "Authorizing", s3_on_entry, s3_on_exit, s3_on_event)
  239. FSM_STATE_ENTRY(s4, "Registering", s4_on_entry, s4_on_exit, s4_on_event)
  240. FSM_STATE_ENTRY(s5, "Failed", s5_on_entry, s5_on_exit, s5_on_event)
  241. END_FSM_STATE()
  242. BEGIN_FSM_RULE(CCustMngrAuthFSM, s0)
  243. FSM_RULE_ENTRY(s0, s2, USER_EVT_TEST, 0)//oiltest?
  244. FSM_RULE_ENTRY(s0, s1, USER_EVT_INIT, 0)
  245. FSM_RULE_ENTRY(s0, FSM_STATE_EXIT, USER_EVT_QUIT, 0)
  246. FSM_RULE_ENTRY(s1, s2, USER_EVT_INIT_FINISHED, 0)
  247. FSM_RULE_ENTRY(s1, s5, USER_EVT_INIT_FINISHED, 1)
  248. FSM_RULE_ENTRY(s1, FSM_STATE_EXIT, USER_EVT_QUIT, 0)
  249. FSM_RULE_ENTRY(s2, s3, USER_EVT_AUTHORIZE_START, 0)
  250. FSM_RULE_ENTRY(s2, s4, USER_EVT_COLLECTFINGERPRINT_START, 0)
  251. FSM_RULE_ENTRY(s2, s4, USER_EVT_CHECKUKEY, 0)
  252. FSM_RULE_ENTRY(s2, s4, USER_EVT_SAVEFINGERPRINT_START, 0)
  253. FSM_RULE_ENTRY(s2, FSM_STATE_EXIT, USER_EVT_QUIT, 0)
  254. FSM_RULE_ENTRY(s3, s2, USER_EVT_EXIT, 0)
  255. FSM_RULE_ENTRY(s3, s2, USER_EVT_AUTHORIZE_FINISHED, 0)
  256. //FSM_RULE_ENTRY(s3, s2, USER_EVT_AUTHORIZE_CANCEL, 0)
  257. FSM_RULE_ENTRY(s4, s2, USER_EVT_COLLECTFINGERPRINT_START, 0)
  258. FSM_RULE_ENTRY(s4, s2, USER_EVT_COLLECTFINGERPRINT_FINISHED, 0)
  259. //FSM_RULE_ENTRY(s4, s2, USER_EVT_COLLECTFINGERPRINT_CANCEL, 0)
  260. FSM_RULE_ENTRY(s4, s2, USER_EVT_SAVEFINGERPRINT_FINISHED, 0)
  261. FSM_RULE_ENTRY(s4, s2, USER_EVT_CHECKUKEY_FINISHED, 0)
  262. FSM_RULE_ENTRY(s3, FSM_STATE_EXIT, USER_EVT_QUIT, 0)
  263. FSM_RULE_ENTRY(s5, FSM_STATE_EXIT, USER_EVT_QUIT, 0)
  264. END_FSM_RULE()
  265. CCustMngrAuthFSM(): m_pMaintainWatcher(NULL), m_pFingerPrint(NULL), m_pDeviceControl(NULL), m_bCancelCollectFP(false)
  266. , m_bCancelAuthorize(false), m_bAuthorizeTimeout(false) {
  267. hStopUpdate = ::CreateEventA(NULL, TRUE, FALSE, NULL);
  268. m_TimeLimit = 55;//默认授权超时秒数
  269. m_ctx = NULL;
  270. InitializeCriticalSection(&m_cs);
  271. }
  272. ~CCustMngrAuthFSM(){
  273. DeleteCriticalSection(&m_cs);
  274. }
  275. virtual ErrorCodeEnum OnInit();
  276. virtual ErrorCodeEnum OnExit();
  277. void s0_on_entry();
  278. void s0_on_exit();
  279. unsigned int s0_on_event(FSMEvent* event);
  280. void s1_on_entry();
  281. void s1_on_exit();
  282. unsigned int s1_on_event(FSMEvent* event);
  283. void s2_on_entry();
  284. void s2_on_exit();
  285. unsigned int s2_on_event(FSMEvent* event);
  286. void s3_on_entry();
  287. void s3_on_exit();
  288. unsigned int s3_on_event(FSMEvent* event);
  289. void s4_on_entry();
  290. void s4_on_exit();
  291. unsigned int s4_on_event(FSMEvent* event);
  292. void s5_on_entry();
  293. void s5_on_exit();
  294. unsigned int s5_on_event(FSMEvent* event);
  295. HANDLE hStopUpdate;
  296. int Initial();
  297. SpReqAnsContext<CustMngrAuthService_StartAuthorize_Req, CustMngrAuthService_StartAuthorize_Ans>::Pointer m_ctx;
  298. AuthContext m_authCtx;
  299. CSimpleStringA m_TerminalID;
  300. CSimpleStringA m_csMachineType;
  301. ErrorCodeEnum MatchFingerPrint(SpReqAnsContext<CustMngrAuthService_StartAuthorize_Req, CustMngrAuthService_StartAuthorize_Ans>::Pointer ctx, bool& bStopAuthorize);
  302. ErrorCodeEnum WaitForUkey(ErrorCodeEnum eErr);
  303. int OneFingerRecognitionEvaluate();
  304. void CancelAuthorize();
  305. void FeatureUpdate();
  306. ErrorCodeEnum CollectFingerPrint(SpReqAnsContext<CustMngrAuthService_CollectFingerPrint_Req, CustMngrAuthService_CollectFingerPrint_Ans>::Pointer ctx, DWORD& dwUserErrCode);
  307. ErrorCodeEnum GetImgBlob(CBlob &data, CSimpleStringA imgPath);
  308. void BroadcastPressFinger(int times, bool bPressFinger);
  309. ErrorCodeEnum SwitchUSB(bool bOpen);
  310. ErrorCodeEnum SaveFingerPrint(SpReqAnsContext<CustMngrAuthService_SaveFingerPrint_Req, CustMngrAuthService_SaveFingerPrint_Ans>::Pointer ctx);
  311. int CompareTime(CSimpleStringA time1, CSimpleStringA time2);
  312. int CompareUpdateTime(const char* time1, const char* time2);
  313. int RecoverFile(CSimpleStringA nowFileName, CSimpleStringA backupFileName);
  314. bool ReadDataIntoMemory(bool& bHasData);
  315. void UpdateDataIntoMemory(map<CSimpleStringA, FeatureData*> tempFeature, bool bIsFirstTimeQueryData);
  316. string ClearStringSpaceHeadTail(string& line);
  317. CSimpleStringA GetCurrentDate();
  318. void TransDataFromServer(CAutoArray<CSimpleStringA> &dataArray, CSimpleStringA latestTime, bool& bResumeTrans, bool bIsFirstTimeQueryData);
  319. bool BackupFile(CSimpleStringA srcFile, CSimpleStringA dstFile);
  320. CSimpleStringA GetMaxTime(CSimpleStringA maxTime, CSimpleStringA tempTime);
  321. CSimpleString GenerateAlarmJson(CSimpleString entityName, int cost);
  322. void BroadcastGetFinger(int status);
  323. protected:
  324. private:
  325. DeviceControlService_ClientBase *m_pDeviceControl;
  326. //FaceRecognitionService_ClientBase *m_pFaceRecognition;
  327. FingerPrintService_ClientBase *m_pFingerPrint;
  328. MaintainCertificate_ClientBase *m_pMaintainWatcher;
  329. FeatureUpdateConn *m_pConnection;//中台连接
  330. CSimpleStringA m_FaceFeaturePath;//人脸特征路径
  331. const char *STR_FINGERINFO;
  332. CSimpleStringA m_runInfoPath;
  333. bool m_bCancelCollectFP, m_bCancelAuthorize, m_bAuthorizeTimeout;
  334. int m_TimeLimit;
  335. map<CSimpleStringA, FeatureData*> m_featureData;
  336. CRITICAL_SECTION m_cs;//临界区变量
  337. };
  338. //特征更新连接
  339. class FeatureUpdateConn : public SpSecureClient
  340. {
  341. public:
  342. FeatureUpdateConn(CEntityBase *pEntity, CCustMngrAuthFSM *pFSM): SpSecureClient(pEntity), m_pFSM(pFSM), m_jsonLen(0), getErrMsg(false)
  343. {
  344. hPkgAnswer = ::CreateEventA(NULL, TRUE, FALSE, NULL);
  345. m_reply = NULL;
  346. }
  347. void SendFeatReq(const char* currAgent, const char* branchID, const char* lastTime = NULL)
  348. {
  349. //LOG_FUNCTION();
  350. ErrorCodeEnum eErr;
  351. //请求参数
  352. FeatReq req = {0};
  353. memcpy(req.BranchID, branchID, 16);
  354. memcpy(req.CurrentAgent, currAgent, 16);//续传标志(代表已查到的最后一个客户经理
  355. if (lastTime != NULL)
  356. {
  357. memcpy(req.UpdateTime, lastTime, 20);//本地指纹数据最新时间
  358. Dbg("req.UpdateTime:%s", req.UpdateTime);
  359. }
  360. strncpy_s(req.TerminalID, sizeof(req.TerminalID), m_pFSM->m_TerminalID, _TRUNCATE);
  361. CSmartPointer<IPackage> pkt = CreateNewPackage("FETQYREQ");
  362. pkt->AddStruct("FETQYREQ", false, false, (LPBYTE)&req, sizeof(FeatReq));
  363. m_reply = NULL;
  364. m_jsonLen = 0;
  365. SendPackage(pkt);
  366. }
  367. HANDLE hPkgAnswer;
  368. bool getErrMsg;
  369. FeatReply *m_reply;
  370. int m_jsonLen;
  371. protected:
  372. virtual ~FeatureUpdateConn() {}
  373. virtual void OnDisconnect()
  374. {
  375. Dbg("FeatureUpdateConnection disconnected");
  376. }
  377. virtual void OnPkgAnswer(const CSmartPointer<IPackage> &pRecvPkg)
  378. {
  379. //LOG_FUNCTION();
  380. DWORD dwSysCode, dwUserCode;
  381. string strErrMsg;
  382. ErrorCodeEnum rc = Error_Succeed;
  383. if (pRecvPkg->GetErrMsg(dwSysCode, dwUserCode, strErrMsg))
  384. {
  385. //错误处理
  386. Dbg("ERROR: package GetErrMsg!");
  387. rc = (ErrorCodeEnum)dwSysCode;
  388. string serviceCode = pRecvPkg->GetServiceCode();
  389. Dbg("receive %s ans packet is error, errormsg is %s", serviceCode.c_str(), strErrMsg.c_str());
  390. getErrMsg = true;
  391. SetEvent(hPkgAnswer);
  392. }
  393. else
  394. {
  395. //判断result接受buff,resultcode判断,
  396. Dbg("pRecvPkg get no errormessage.");
  397. string serviceCode = pRecvPkg->GetServiceCode();
  398. if (serviceCode == "FETQYREQ")
  399. {
  400. //Dbg("dealing with FETQYREQ package.");
  401. int nLen = pRecvPkg->GetStructLen("FETQYANS");
  402. //Dbg("GetStructLen structlen: %d", nLen);
  403. if ( nLen > 0 )
  404. {
  405. BYTE *pBuf = new BYTE[nLen];
  406. memset(pBuf, 0, nLen);
  407. Dbg("memeset done");
  408. int ArrayNum = 0;
  409. if (pRecvPkg->GetStructData("FETQYANS", pBuf, &nLen, &ArrayNum))
  410. {
  411. Dbg("GetStructData structlen: %d", nLen);
  412. //初始化
  413. LPBYTE pData = new BYTE[nLen+1];
  414. memcpy(pData, pBuf, nLen);
  415. Dbg("memcpy done");
  416. m_reply = (FeatReply*)pData;
  417. if (m_reply != NULL)
  418. {
  419. //Dbg("m_reply transformed successfully.");
  420. //Dbg("Resultcode: %d", m_reply->ResultCode);
  421. //Dbg("BranchID: %s", m_reply->BranchID);
  422. //Dbg("CurrentAgent: %s", m_reply->CurrentAgent);
  423. pData[nLen] = 0;
  424. m_jsonLen = nLen - sizeof(FeatReply);
  425. //Dbg("m_jsonLen:%d",m_jsonLen);
  426. }
  427. else
  428. {
  429. Dbg("ERROR: m_reply is null!");
  430. }
  431. }
  432. else
  433. {
  434. Dbg("ERROR: getstructdata(FETQYANS) failed!");
  435. }
  436. delete pBuf;
  437. }
  438. else
  439. {
  440. Dbg("ERROR: getstructlen(FETQYANS) = 0!");
  441. }
  442. //设m_pEvt为已通知,使下载线程从挂起中恢复,再设为未通知
  443. //isTimeOut = false;
  444. SetEvent(hPkgAnswer);
  445. }
  446. else
  447. {
  448. Dbg("ERROR: wrong service code!");
  449. }
  450. }
  451. }
  452. private:
  453. CCustMngrAuthFSM *m_pFSM;
  454. };
  455. //初始化:检查、配置路径、起特征更新任务
  456. struct InitTask : public ITaskSp
  457. {
  458. CCustMngrAuthFSM *fsm;
  459. InitTask(CCustMngrAuthFSM *f) : fsm(f) {}
  460. void Process()
  461. {
  462. LOG_FUNCTION();
  463. FSMEvent *e = new FSMEvent(USER_EVT_INIT_FINISHED);
  464. e->param1 = fsm->Initial();
  465. fsm->PostEventFIFO(e);
  466. }
  467. };
  468. //特征定期更新
  469. struct FeatureUpdateTask : public ITaskSp
  470. {
  471. CCustMngrAuthFSM *fsm;
  472. FeatureUpdateTask(CCustMngrAuthFSM *f) : fsm(f) {}
  473. void Process()
  474. {
  475. LOG_FUNCTION();
  476. fsm->FeatureUpdate();
  477. }
  478. };
  479. //调用指纹匹配服务,阻塞等待返回
  480. struct MatchFingerPrintTask : public ITaskSp
  481. {
  482. CCustMngrAuthFSM *fsm;
  483. MatchFingerPrintTask(CCustMngrAuthFSM *f) : fsm(f) {}
  484. SpReqAnsContext<CustMngrAuthService_StartAuthorize_Req, CustMngrAuthService_StartAuthorize_Ans>::Pointer ctx;
  485. void Process()
  486. {
  487. bool bStopAuthorize = false;
  488. ErrorCodeEnum eErr = fsm->MatchFingerPrint(ctx, bStopAuthorize);
  489. if (bStopAuthorize)
  490. {
  491. AuthorizeFinishedEvent *e = new AuthorizeFinishedEvent();
  492. e->ctx = ctx;
  493. e->param1 = eErr;
  494. fsm->PostEventFIFO(e);//指纹匹配结束,结束授权
  495. }
  496. else
  497. {
  498. AuthorizeFinishedEvent *e = new AuthorizeFinishedEvent();
  499. e->ctx = ctx;
  500. e->param1 = fsm->WaitForUkey(eErr);
  501. fsm->PostEventFIFO(e);//指纹匹配异常停止,继续等到超时或ukey插入结束授权,如果是ukey插入,这个event就不会被处理
  502. }
  503. }
  504. };
  505. //采集指纹
  506. struct CollectFingerPrintTask : public ITaskSp
  507. {
  508. CCustMngrAuthFSM *fsm;
  509. SpReqAnsContext<CustMngrAuthService_CollectFingerPrint_Req, CustMngrAuthService_CollectFingerPrint_Ans>::Pointer ctx;
  510. CollectFingerPrintTask(CCustMngrAuthFSM *f) : fsm(f){}
  511. void Process()
  512. {
  513. LOG_FUNCTION();
  514. CollectFingerPrintFinishedEvent *e = new CollectFingerPrintFinishedEvent();
  515. e->ctx = ctx;
  516. DWORD dwUserErrorCode = 0;
  517. ErrorCodeEnum eErr = fsm->CollectFingerPrint(ctx, dwUserErrorCode);
  518. if(eErr == Error_Unexpect && dwUserErrorCode > 0)
  519. ctx->Answer(eErr, dwUserErrorCode);
  520. else
  521. ctx->Answer(eErr);
  522. fsm->PostEventFIFO(e);
  523. }
  524. };
  525. struct SaveFingerPrintTask : public ITaskSp
  526. {
  527. CCustMngrAuthFSM *fsm;
  528. SpReqAnsContext<CustMngrAuthService_SaveFingerPrint_Req, CustMngrAuthService_SaveFingerPrint_Ans>::Pointer ctx;
  529. SaveFingerPrintTask(CCustMngrAuthFSM *f) : fsm(f) {}
  530. void Process()
  531. {
  532. LOG_FUNCTION();
  533. SaveFingerPrintFinishedEvent *e = new SaveFingerPrintFinishedEvent();
  534. e->ctx = ctx;
  535. ErrorCodeEnum eErr = fsm->SaveFingerPrint(ctx);
  536. ctx->Answer(eErr);
  537. fsm->PostEventFIFO(e);
  538. }
  539. };
  540. #endif //__CUSTMNGRAUTH_FSM_H