CustMngrAuthFSM.h 16 KB

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