|
@@ -1,10 +1,22 @@
|
|
|
-
|
|
|
+#include "stdafx.h"
|
|
|
+#include "SpBase.h"
|
|
|
#include "SpHelper.h"
|
|
|
#include "CustMngrAuth_UserErrorCode.h"
|
|
|
#include "CustMngrAuthFSM.h"
|
|
|
+#include "CommEntityUtil.hpp"
|
|
|
|
|
|
#include <fstream>
|
|
|
#include <map>
|
|
|
+#ifdef RVC_OS_WIN
|
|
|
+
|
|
|
+#include <iostream>
|
|
|
+#include <iomanip>
|
|
|
+#include <random>
|
|
|
+#include <stdint.h>
|
|
|
+#include <sstream>
|
|
|
+
|
|
|
+using namespace std;
|
|
|
+#else
|
|
|
#include "fileutil.h"
|
|
|
#include <memory>
|
|
|
#include <thread>
|
|
@@ -14,16 +26,17 @@
|
|
|
#include <cstring>
|
|
|
|
|
|
using std::string;
|
|
|
+#endif
|
|
|
|
|
|
-const int UPDATE_INTERNAL = 10 * 60 * 1000; //query data from branch server internal, 10min
|
|
|
-const int CONNECT_INTERNAL = 10 * 60 * 1000; //connect branch server internal, 10min
|
|
|
-const int FINGER_NUM = 8; //suuport max register finger num
|
|
|
+//const int UPDATE_INTERNAL = 10 * 60 * 1000; //query data from branch server internal, 10min
|
|
|
+//const int CONNECT_INTERNAL = 10 * 60 * 1000; //connect branch server internal, 10min
|
|
|
+//const int FINGER_NUM = 8; //suuport max register finger num
|
|
|
#define IMAGE_NUM 3
|
|
|
-const int COLLECT_TIMES = 3; //press finger times
|
|
|
+//const int COLLECT_TIMES = 3; //press finger times
|
|
|
|
|
|
class CCustMngrAuthEntity;
|
|
|
|
|
|
-#pragma region event response
|
|
|
+
|
|
|
|
|
|
//Init
|
|
|
void CCustMngrAuthFSM::s0_on_entry()
|
|
@@ -94,7 +107,7 @@ void CCustMngrAuthFSM::s2_on_exit()
|
|
|
unsigned int CCustMngrAuthFSM::s2_on_event(FSMEvent* pEvt)
|
|
|
{
|
|
|
LOG_FUNCTION();
|
|
|
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("s2 evt(%d)", pEvt->iEvt);
|
|
|
+ DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("s2 evt(%d, %d)", pEvt->iEvt, pEvt->param1);
|
|
|
|
|
|
switch (pEvt->iEvt)
|
|
|
{
|
|
@@ -136,7 +149,7 @@ unsigned int CCustMngrAuthFSM::s2_on_event(FSMEvent* pEvt)
|
|
|
this->PostEventFIFO(e);
|
|
|
break;
|
|
|
}
|
|
|
- m_TimeLimit = (queryEvt->ctx->Req.TimeLimit - 2) * 1000;
|
|
|
+ m_TimeLimit = (queryEvt->ctx->Req.TimeLimit - 3) * 1000;
|
|
|
|
|
|
ErrorCodeEnum eErr;
|
|
|
m_bCancelAuthorize = false;
|
|
@@ -287,7 +300,7 @@ unsigned int CCustMngrAuthFSM::s3_on_event(FSMEvent* pEvt)
|
|
|
|
|
|
if (m_pFingerPrint != NULL && !m_pFingerPrint->QuerySessionClosed())
|
|
|
{
|
|
|
- //m_bCancelAuthorize = true; //已结束授权,无用?
|
|
|
+ m_bCancelAuthorize = true;
|
|
|
m_pFingerPrint->GetFunction()->CloseSession();
|
|
|
m_pFingerPrint = NULL;
|
|
|
DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("M_pFingerPrint disconnected.");
|
|
@@ -435,7 +448,6 @@ unsigned int CCustMngrAuthFSM::s5_on_event(FSMEvent* pEvt)
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
-#pragma endregion
|
|
|
|
|
|
#pragma region entity init
|
|
|
|
|
@@ -525,9 +537,9 @@ ErrorCodeEnum CCustMngrAuthFSM::CollectFingerPrintInfo(SpReqAnsContext<CustMngrA
|
|
|
}
|
|
|
|
|
|
ULLINT l_beginTime, l_endTime;
|
|
|
- l_beginTime = RVCGetTickCount();
|
|
|
+ l_beginTime = SP::Module::Comm::RVCGetTickCount();
|
|
|
errCode = m_pFingerPrint->GetFingerPrint(GetFingerReq, GetFingerAns, 30000, dwUserErrCode);
|
|
|
- l_endTime = RVCGetTickCount();
|
|
|
+ l_endTime = SP::Module::Comm::RVCGetTickCount();
|
|
|
//DbgInfo("GetFingerPrint", l_beginTime, l_endTime, errCode, CSimpleStringA::Format("reserved1[0]:%d", GetFingerAns.reserved1[0]));
|
|
|
DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("GetFingerPrint").setBeginTime(l_beginTime).setEndTime(l_endTime)("CollectFingerPrintInfo invoke GetFingerPrint return %s", SpStrError(errCode));
|
|
|
|
|
@@ -621,9 +633,9 @@ ErrorCodeEnum CCustMngrAuthFSM::GenerateTemplate(SpReqAnsContext<CustMngrAuthSer
|
|
|
}
|
|
|
|
|
|
ULLINT l_beginTime, l_endTime;
|
|
|
- l_beginTime = RVCGetTickCount();
|
|
|
+ l_beginTime = SP::Module::Comm::RVCGetTickCount();
|
|
|
errCode = (*m_pFingerPrint)(EntityResource::getLink().upgradeLink())->GenerateTemplate(generateReq, generateAns, 20000, dwUserErrCode);
|
|
|
- l_endTime = RVCGetTickCount();
|
|
|
+ l_endTime = SP::Module::Comm::RVCGetTickCount();
|
|
|
DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("GenerateTemplate").setBeginTime(l_beginTime).setEndTime(l_endTime)("GenerateTemplate invoke GenerateTemplate return %s", SpStrError(errCode));
|
|
|
|
|
|
if (errCode == Error_NotInit)
|
|
@@ -649,7 +661,7 @@ void CCustMngrAuthFSM::BroadcastPressFinger(int times, bool bPressFinger)
|
|
|
{
|
|
|
if (bPressFinger) {
|
|
|
PressFinger pfEvt;//
|
|
|
- pfEvt.FingerNo = 1;//maybe no use,control by @zhuyi
|
|
|
+ pfEvt.FingerNo = 1;//maybe no use,control by @zhuyi
|
|
|
pfEvt.Times = times;
|
|
|
SpSendBroadcast(m_pEntity->GetFunction(), SP_MSG_OF(PressFinger), SP_MSG_SIG_OF(PressFinger), pfEvt);
|
|
|
}
|
|
@@ -683,282 +695,12 @@ ErrorCodeEnum CCustMngrAuthFSM::GetImgBlob(CBlob& data, CSimpleStringA imgPath)
|
|
|
return eErr;
|
|
|
}
|
|
|
|
|
|
-ErrorCodeEnum CCustMngrAuthFSM::CollectFingerPrint(SpReqAnsContext<CustMngrAuthService_CollectFingerPrint_Req, CustMngrAuthService_CollectFingerPrint_Ans>::Pointer ctx, DWORD& dwUserErrCode)
|
|
|
-{
|
|
|
- LOG_FUNCTION();
|
|
|
- LogWarn(Severity_Low, Error_Unexpect, LOG_ERR_CUSTMNGRAUTH_INVOKE_GETIMAGE, "web invoke CollectFingerPrint");
|
|
|
-
|
|
|
- ErrorCodeEnum errCode = ConnectFingerPrintEntity();
|
|
|
- if (errCode != Error_Succeed)
|
|
|
- return errCode;
|
|
|
-
|
|
|
- errCode = CollectProcess(ctx, dwUserErrCode);
|
|
|
-
|
|
|
- if (errCode == Error_Succeed)
|
|
|
- {
|
|
|
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Register FingerPrint successfully.");
|
|
|
- return Error_Succeed;
|
|
|
- }
|
|
|
- else {
|
|
|
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("Register FingerPrint failed! %s", SpStrError(errCode));
|
|
|
- return errCode;
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-ErrorCodeEnum CCustMngrAuthFSM::CollectProcess(SpReqAnsContext<CustMngrAuthService_CollectFingerPrint_Req, CustMngrAuthService_CollectFingerPrint_Ans>::Pointer& ctx, DWORD& dwUserErrCode)
|
|
|
-{
|
|
|
- ErrorCodeEnum errCode = Error_Succeed;
|
|
|
-
|
|
|
- vector<CSimpleStringA> imgPaths;
|
|
|
- CSimpleStringA depPath(true);
|
|
|
- m_pEntity->GetFunction()->GetPath("Dep", depPath);
|
|
|
- ctx->Ans.FingerImgs.Init(COLLECT_TIMES);
|
|
|
-
|
|
|
- for (int i = 0; i < COLLECT_TIMES; ++i)
|
|
|
- {
|
|
|
- if (i) SLEEP(2000);
|
|
|
-
|
|
|
- if (m_pFingerPrint == NULL || m_pFingerPrint->QuerySessionClosed())
|
|
|
- {
|
|
|
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("m_pFingerPrint is NULL or connection closed.");
|
|
|
- return Error_NoTarget;
|
|
|
- }
|
|
|
-
|
|
|
- BroadcastPressFinger(i + 1, true);//press finger
|
|
|
-
|
|
|
- FingerPrintService_GetImageAndFeature_Req collecetReq;
|
|
|
- FingerPrintService_GetImageAndFeature_Ans collecetAns;
|
|
|
- collecetReq.times = i + 1;//the num from 1 start , 1/2/3
|
|
|
- errCode = (*m_pFingerPrint)(EntityResource::getLink().upgradeLink())->GetImageAndFeature(collecetReq, collecetAns, 16000, dwUserErrCode);//fingerprint entity loop duration is 15s
|
|
|
- if (errCode == Error_Succeed)
|
|
|
- {
|
|
|
- BroadcastPressFinger(i + 1, false);//lift finger
|
|
|
-
|
|
|
- CBlob data;
|
|
|
- CSimpleStringA imgFullPath(true);
|
|
|
- imgFullPath = CSimpleStringA::Format("%s" SPLIT_SLASH_STR "%s"
|
|
|
- , depPath.GetData(), collecetAns.imageName.GetData());
|
|
|
- errCode = GetImgBlob(data, imgFullPath);
|
|
|
- imgPaths.push_back(imgFullPath);
|
|
|
-
|
|
|
- if (errCode != Error_Succeed)
|
|
|
- {
|
|
|
- DbgWithLink(LOG_LEVEL_ERROR, LOG_TYPE_USER)("Failed to load finger image, %s", imgFullPath.GetData());
|
|
|
- errCode = Error_Unexpect;
|
|
|
- break;
|
|
|
- }
|
|
|
- switch (i)
|
|
|
- {
|
|
|
- case 0:
|
|
|
- ctx->Ans.FingerImg1 = data;
|
|
|
- break;
|
|
|
- case 1:
|
|
|
- ctx->Ans.FingerImg2 = data;
|
|
|
- break;
|
|
|
- case 2:
|
|
|
- ctx->Ans.FingerImg3 = data;
|
|
|
- break;
|
|
|
- }
|
|
|
- ctx->Ans.FingerImgs[i] = data;
|
|
|
-
|
|
|
- if (i == (COLLECT_TIMES - 1)) {
|
|
|
- ctx->Ans.feature = collecetAns.feature;
|
|
|
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("feature = %s", ctx->Ans.feature.GetData());
|
|
|
- }
|
|
|
- }
|
|
|
- else {
|
|
|
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER)("invoke GetImageAndFeature failed in %dth time, errCode(%s)", i + 1, SpStrError(errCode));
|
|
|
- break;
|
|
|
- }
|
|
|
- }
|
|
|
- for (size_t i = 0; i < imgPaths.size(); ++i)
|
|
|
- {
|
|
|
- if (ExistsFileA(imgPaths[i]))
|
|
|
- RemoveFileA(imgPaths[i]);
|
|
|
- }
|
|
|
-
|
|
|
- return errCode;
|
|
|
-}
|
|
|
-
|
|
|
-ErrorCodeEnum CCustMngrAuthFSM::CollectFingerPrintEx(SpReqAnsContext<CustMngrAuthService_CollectFingerPrintEx_Req, CustMngrAuthService_CollectFingerPrintEx_Ans>::Pointer ctx, DWORD& dwUserErrCode)
|
|
|
-{
|
|
|
- LOG_FUNCTION();
|
|
|
- LogWarn(Severity_Low, Error_Unexpect, LOG_ERR_CUSTMNGRAUTH_INVOKE_GETIMAGEEx, "web invoke CollectFingerPrintEx");
|
|
|
-
|
|
|
- ErrorCodeEnum errCode = ConnectFingerPrintEntity();
|
|
|
- if (errCode != Error_Succeed)
|
|
|
- return errCode;
|
|
|
|
|
|
- errCode = CollectProcessEx(ctx, dwUserErrCode);
|
|
|
-
|
|
|
- if (errCode == Error_Succeed)
|
|
|
- {
|
|
|
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Register FingerPrint successfully.");
|
|
|
- return Error_Succeed;
|
|
|
- }
|
|
|
- else {
|
|
|
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("Register FingerPrint failed: %s !", SpStrError(errCode));
|
|
|
- return errCode;
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-ErrorCodeEnum CCustMngrAuthFSM::CollectProcessEx(SpReqAnsContext<CustMngrAuthService_CollectFingerPrintEx_Req, CustMngrAuthService_CollectFingerPrintEx_Ans>::Pointer& ctx, DWORD& dwUserErrCode)
|
|
|
-{
|
|
|
- ErrorCodeEnum errCode = Error_Succeed;
|
|
|
-
|
|
|
- CSimpleStringA depPath(true);
|
|
|
- m_pEntity->GetFunction()->GetPath("Dep", depPath);
|
|
|
- ctx->Ans.FingerImgs.Init(COLLECT_TIMES);
|
|
|
-
|
|
|
- FingerPrintService_GetImageAndFeatureEx_Req collectExReq;
|
|
|
- FingerPrintService_GetImageAndFeatureEx_Ans collectExAns;
|
|
|
- collectExReq.times = ctx->Req.FingerId;
|
|
|
-
|
|
|
- if (m_pFingerPrint == NULL || m_pFingerPrint->QuerySessionClosed())
|
|
|
- {
|
|
|
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("m_pFingerPrint is NULL or connection closed.");
|
|
|
- return Error_NoTarget;
|
|
|
- }
|
|
|
-
|
|
|
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Start %dth scan fingerprint", collectExReq.times);
|
|
|
- errCode = (*m_pFingerPrint)(EntityResource::getLink().upgradeLink())->GetImageAndFeatureEx(collectExReq, collectExAns, 30000, dwUserErrCode);//fingerprint entity loop duration is 15s
|
|
|
-
|
|
|
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("reserverd1[0] = %d", collectExAns.reserved1[0]);
|
|
|
- if (errCode == Error_NotExist) {
|
|
|
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("cannot find finger img in dep!");
|
|
|
- return Error_NotExist;
|
|
|
- }
|
|
|
- if (errCode == Error_Succeed && collectExAns.reserved1[0] == 3) {
|
|
|
- return Error_Cancel;
|
|
|
- }
|
|
|
- if (errCode == Error_Succeed && collectExAns.reserved1[0] == 2) {
|
|
|
- return Error_TimeOut;
|
|
|
- }
|
|
|
-
|
|
|
- CBlob data;
|
|
|
- CSimpleStringA imgFullPath = CSimpleStringA::Format("%s" SPLIT_SLASH_STR "%s"
|
|
|
- , depPath.GetData(), collectExAns.imageName.GetData());
|
|
|
- ErrorCodeEnum imgErrCode = GetImgBlob(data, imgFullPath);
|
|
|
- if (imgErrCode != Error_Succeed)
|
|
|
- {
|
|
|
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER)("Failed to load image(%s)", imgFullPath.GetData());
|
|
|
- return Error_NotExist;
|
|
|
- }
|
|
|
-
|
|
|
- CSimpleStringA imageName(true);
|
|
|
- CSimpleStringA imgPrefix = "finger";
|
|
|
- CSimpleStringA imgSuffix = ".bmp";
|
|
|
- switch (ctx->Req.FingerId)
|
|
|
- {
|
|
|
- case 1:
|
|
|
- ctx->Ans.FingerImg1 = data;
|
|
|
- break;
|
|
|
- case 2:
|
|
|
- ctx->Ans.FingerImg2 = data;
|
|
|
- break;
|
|
|
- case 3:
|
|
|
- ctx->Ans.FingerImg3 = data;
|
|
|
- for (size_t i = 0; i < 10; ++i)
|
|
|
- {
|
|
|
- imageName = CSimpleStringA::Format("%s" SPLIT_SLASH_STR "%s%d%s", depPath.GetData(), imgPrefix.GetData(), i, imgSuffix.GetData());
|
|
|
- if (ExistsFileA(imageName))
|
|
|
- RemoveFileA(imageName);
|
|
|
- }
|
|
|
- imageName = CSimpleStringA::Format("%s" SPLIT_SLASH_STR "%s%s", depPath.GetData(), imgPrefix.GetData(), imgSuffix.GetData());
|
|
|
- if (ExistsFileA(imageName))
|
|
|
- RemoveFileA(imageName);
|
|
|
- break;
|
|
|
- default:
|
|
|
- break;
|
|
|
- }
|
|
|
-
|
|
|
- if (errCode == Error_Succeed && collectExAns.reserved1[0] == 1) {
|
|
|
- if (ctx->Req.FingerId == COLLECT_TIMES)
|
|
|
- ctx->Ans.feature = collectExAns.feature;
|
|
|
- }
|
|
|
- else if(errCode == Error_NotInit){
|
|
|
- errCode = Error_DevNotAvailable;
|
|
|
- }else {
|
|
|
- errCode = Error_Unexpect;
|
|
|
- }
|
|
|
-
|
|
|
- if (errCode == Error_Succeed) {
|
|
|
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Register FingerPrint successfully.");
|
|
|
- }
|
|
|
- else {
|
|
|
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER)("Register FingerPrint failed! %s", SpStrError(errCode));
|
|
|
- }
|
|
|
- return errCode;
|
|
|
-}
|
|
|
|
|
|
#pragma endregion
|
|
|
|
|
|
#pragma region Save fingerprint process
|
|
|
|
|
|
-ErrorCodeEnum CCustMngrAuthFSM::SaveFingerPrint(SpReqAnsContext<CustMngrAuthService_SaveFingerPrint_Req, CustMngrAuthService_SaveFingerPrint_Ans>::Pointer ctx)
|
|
|
-{
|
|
|
- LOG_FUNCTION();
|
|
|
- EnterCriticalSection(&m_cs);
|
|
|
- CSmartPointer<IConfigInfo> spConfig;
|
|
|
- Json::FastWriter writer;
|
|
|
- ErrorCodeEnum eErr;
|
|
|
- eErr = GetEntityBase()->GetFunction()->OpenConfig(Config_Run, spConfig);
|
|
|
- if (eErr != Error_Succeed) {
|
|
|
- LogError(Severity_High, Error_DevLoadFileFailed, LOG_ERR_CUSTMNGRAUTH_OPEN_RUNINFO_FAILED_SAVEFINGERPRINT, "open runinfo file failed while save data to local.");
|
|
|
- LeaveCriticalSection(&m_cs);
|
|
|
- return Error_Unexpect;
|
|
|
- }
|
|
|
- if (ctx->Req.FPFeatureList == nullptr) {
|
|
|
- return Error_Param;
|
|
|
- }
|
|
|
- int fingerIDNum = ctx->Req.FingerIdList.GetCount();
|
|
|
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("FingerIDNum=%d", fingerIDNum);
|
|
|
-
|
|
|
- FeatureData* fd = new FeatureData();
|
|
|
- fd->FingerIDArray.Init(fingerIDNum);
|
|
|
- fd->FingerIDLenArray.Init(fingerIDNum);
|
|
|
-
|
|
|
- char fingerID[20];
|
|
|
- Json::Value fingerInfo;
|
|
|
-
|
|
|
- for (int i = 0; i < fingerIDNum; ++i)
|
|
|
- {
|
|
|
- memset(fingerID, 0, sizeof(fingerID));
|
|
|
-
|
|
|
-#ifdef RVC_OS_WIN
|
|
|
- _snprintf_s(fingerID, 10, "FingerID%d", ctx->Req.FingerIdList[i]);
|
|
|
-#else
|
|
|
- snprintf(fingerID, 10, "FingerID%d", ctx->Req.FingerIdList[i]);
|
|
|
-#endif // RVC_OS_WIN
|
|
|
-
|
|
|
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("writing %s", fingerID);
|
|
|
- fingerInfo[fingerID] = ctx->Req.FPFeatureList[i].GetData();
|
|
|
- fd->FingerIDArray[i] = ctx->Req.FPFeatureList[i];
|
|
|
- fd->FingerIDLenArray[i] = fd->FingerIDArray[i].GetLength();
|
|
|
- }
|
|
|
- if (m_featureData.find(ctx->Req.CustomerID) == m_featureData.end()){
|
|
|
- //not exist, insert directly
|
|
|
- m_featureData[ctx->Req.CustomerID] = fd;
|
|
|
- }
|
|
|
- else {
|
|
|
- auto tempFD = m_featureData[ctx->Req.CustomerID];
|
|
|
- m_featureData[ctx->Req.CustomerID] = fd;
|
|
|
- if (tempFD) {
|
|
|
- delete tempFD;
|
|
|
- tempFD = NULL;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- eErr = spConfig->WriteConfigValue(m_FingerSection.GetData(), ctx->Req.CustomerID.GetData(), writer.write(fingerInfo).c_str());
|
|
|
- if (eErr != Error_Succeed) {
|
|
|
- LogError(Severity_High, Error_DevLoadFileFailed, LOG_ERR_CUSTMNGRAUTH_REGISTER_WRITE_RUNINFO_FAILED, "write data into runinfo failed when commit.");
|
|
|
- LeaveCriticalSection(&m_cs);
|
|
|
- return Error_Unexpect;
|
|
|
- }
|
|
|
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("write data into runinfo success when commit.");
|
|
|
- LeaveCriticalSection(&m_cs);
|
|
|
- return eErr;
|
|
|
-}
|
|
|
|
|
|
#pragma endregion
|
|
|
|
|
@@ -994,9 +736,9 @@ ErrorCodeEnum CCustMngrAuthFSM::MatchFingerPrintEx(SpReqAnsContext<CustMngrAuthS
|
|
|
}
|
|
|
|
|
|
ULLINT l_beginTime, l_endTime;
|
|
|
- l_beginTime = RVCGetTickCount();
|
|
|
+ l_beginTime = SP::Module::Comm::RVCGetTickCount();
|
|
|
errCode = (*m_pFingerPrint)(EntityResource::getLink().upgradeLink())->GetFingerPrint(GetFingerReq, GetFingerAns, 30000, dwUserErrCode);
|
|
|
- l_endTime = RVCGetTickCount();
|
|
|
+ l_endTime = SP::Module::Comm::RVCGetTickCount();
|
|
|
DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM).setAPI("GetFingerPrint").setBeginTime(l_beginTime).setEndTime(l_endTime)("MatchFingerPrintEx invoke GetFingerPrint return %s", SpStrError(errCode));
|
|
|
|
|
|
if (errCode == Error_DevNotAvailable) {
|
|
@@ -1097,6 +839,36 @@ void CCustMngrAuthFSM::DeleteBmp(int type)
|
|
|
|
|
|
ErrorCodeEnum CCustMngrAuthFSM::DeleteFileIfExisted(const char* fileName)
|
|
|
{
|
|
|
+#ifdef RVC_OS_WIN
|
|
|
+ if (strlen(fileName) == 0 || strchr(fileName, (int)'*') != NULL)
|
|
|
+ {
|
|
|
+ DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("Invalid or empty filename(%s)", fileName);
|
|
|
+ return Error_Param;
|
|
|
+ }
|
|
|
+ CSimpleStringA strPath, strObjPath;
|
|
|
+ ErrorCodeEnum errCode = m_pEntity->GetFunction()->GetPath("Dep", strPath);
|
|
|
+ strObjPath = strPath + "\\" + fileName;
|
|
|
+ WIN32_FIND_DATA findData;
|
|
|
+ if (FindFirstFileA((LPCTSTR)strObjPath, &findData) != INVALID_HANDLE_VALUE)
|
|
|
+ {
|
|
|
+ if (DeleteFileA((LPCTSTR)strObjPath) != 0)
|
|
|
+ {
|
|
|
+ DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("DeleteFile(%s) success.", strObjPath.GetData());
|
|
|
+ return Error_Succeed;
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("DeleteFile(%s) failed LastError(%s).", strObjPath.GetData(), GetLastError());
|
|
|
+ return Error_Unexpect;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (GetLastError() == ERROR_FILE_NOT_FOUND)
|
|
|
+ {
|
|
|
+ DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("file %s not exist.", fileName);
|
|
|
+ return Error_Succeed;
|
|
|
+ }
|
|
|
+ DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("DeleteFle(%s) Unexpect GetLastError(%s).", strObjPath.GetData(), GetLastError());
|
|
|
+ return Error_Unexpect;
|
|
|
+#else
|
|
|
if (strlen(fileName) == 0 || strchr(fileName, (int)'*') != NULL)
|
|
|
{
|
|
|
DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("Invalid or empty filename(%s)", fileName);
|
|
@@ -1122,6 +894,7 @@ ErrorCodeEnum CCustMngrAuthFSM::DeleteFileIfExisted(const char* fileName)
|
|
|
DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("file %s not exist.", fileName);
|
|
|
return Error_Succeed;
|
|
|
}
|
|
|
+#endif
|
|
|
}
|
|
|
|
|
|
void CCustMngrAuthFSM::BroadcastGetFinger(int status)
|
|
@@ -1131,199 +904,9 @@ void CCustMngrAuthFSM::BroadcastGetFinger(int status)
|
|
|
SpSendBroadcast(GetEntityBase()->GetFunction(), SP_MSG_OF(GetFinger), SP_MSG_SIG_OF(GetFinger), evt);
|
|
|
}
|
|
|
|
|
|
-ErrorCodeEnum CCustMngrAuthFSM::MatchFingerPrint(SpReqAnsContext<CustMngrAuthService_StartAuthorize_Req, CustMngrAuthService_StartAuthorize_Ans>::Pointer ctx, bool& bStopAuthorize)
|
|
|
-{
|
|
|
- LOG_FUNCTION();
|
|
|
- LogWarn(Severity_Low, Error_Unexpect, LOG_ERR_CUSTMNGRAUTH_INVOKE_MATCH, "web invoke MatchFingerPrint");
|
|
|
|
|
|
- ErrorCodeEnum errCode = ConnectFingerPrintEntity();
|
|
|
- if (errCode != Error_Succeed)
|
|
|
- return errCode;
|
|
|
|
|
|
- MatchParams* matchParam = new MatchParams();
|
|
|
- matchParam->sTotalNumOfTemplate = 0;
|
|
|
- errCode = PrepareDataBeforeMatch(matchParam);
|
|
|
- if (errCode != Error_Succeed)
|
|
|
- return errCode;
|
|
|
|
|
|
- errCode = MatchProcess(matchParam, bStopAuthorize);
|
|
|
- return errCode;
|
|
|
-}
|
|
|
-
|
|
|
-ErrorCodeEnum CCustMngrAuthFSM::PrepareDataBeforeMatch(MatchParams* matchParam)
|
|
|
-{
|
|
|
- EnterCriticalSection(&m_cs);
|
|
|
-
|
|
|
- CAutoArray<CSimpleStringA> tempFeatureArray;
|
|
|
- CAutoArray<int> tempFeatureLenArray;
|
|
|
- int totalCustomerID = m_featureData.size();
|
|
|
- int totalTemplate = totalCustomerID * FINGER_NUM;
|
|
|
- tempFeatureArray.Init(totalTemplate);
|
|
|
- tempFeatureLenArray.Init(totalTemplate);
|
|
|
-
|
|
|
- if (totalCustomerID <= 0)
|
|
|
- {
|
|
|
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("No FingerPrint data in local file or read local file failed.");
|
|
|
- LeaveCriticalSection(&m_cs);
|
|
|
- if (matchParam != NULL)
|
|
|
- delete matchParam;
|
|
|
- return Error_NoTarget;
|
|
|
- }
|
|
|
-
|
|
|
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("begin copy feature to reqParams");
|
|
|
- for (auto it = m_featureData.begin(); it != m_featureData.end(); ++it)
|
|
|
- {
|
|
|
- TemplateInfo ti;
|
|
|
- memset(&ti, 0, sizeof(ti));
|
|
|
- ti.CustomerID = it->first;
|
|
|
- ti.TemplateNum = 0;
|
|
|
-
|
|
|
- for (int index = 0; index < FINGER_NUM; ++index)
|
|
|
- {
|
|
|
- if (index >= it->second->FingerIDArray.GetCount()) //旧版本可能只有2个
|
|
|
- break;
|
|
|
-
|
|
|
- if (it->second->FingerIDArray[index].GetLength() <= 0)
|
|
|
- continue;
|
|
|
-
|
|
|
- tempFeatureArray[matchParam->sTotalNumOfTemplate] = it->second->FingerIDArray[index];
|
|
|
- tempFeatureLenArray[matchParam->sTotalNumOfTemplate] = it->second->FingerIDLenArray[index];
|
|
|
- ti.TemplateNum = ti.TemplateNum + 1;
|
|
|
- ++matchParam->sTotalNumOfTemplate;
|
|
|
- }
|
|
|
-
|
|
|
- if (ti.TemplateNum > 0)
|
|
|
- matchParam->sFingerCount.push_back(ti);
|
|
|
- }
|
|
|
- LeaveCriticalSection(&m_cs);
|
|
|
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("num of template not empty:%d", matchParam->sTotalNumOfTemplate);
|
|
|
-
|
|
|
- matchParam->sMatchReq.templateNum = matchParam->sTotalNumOfTemplate;
|
|
|
- matchParam->sMatchReq.templates.Init(matchParam->sTotalNumOfTemplate);
|
|
|
- matchParam->sMatchReq.templateLen.Init(matchParam->sTotalNumOfTemplate);
|
|
|
-
|
|
|
- for (int i = 0; i < matchParam->sTotalNumOfTemplate; ++i)
|
|
|
- {
|
|
|
- matchParam->sMatchReq.templates[i] = tempFeatureArray[i];
|
|
|
- matchParam->sMatchReq.templateLen[i] = tempFeatureLenArray[i];
|
|
|
- }
|
|
|
-
|
|
|
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("end copy feature to reqParams");
|
|
|
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("templateNum: %d", matchParam->sMatchReq.templateNum);
|
|
|
-
|
|
|
- return Error_Succeed;
|
|
|
-}
|
|
|
-
|
|
|
-ErrorCodeEnum CCustMngrAuthFSM::MatchProcess(MatchParams* matchParam, bool& bStopAuthorize)
|
|
|
-{
|
|
|
- ErrorCodeEnum errCode = Error_Succeed;
|
|
|
-
|
|
|
- while (true)
|
|
|
- {
|
|
|
- if (m_pFingerPrint == NULL || m_pFingerPrint->QuerySessionClosed())
|
|
|
- {
|
|
|
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("m_pFingerPrint is NULL or connection closed.");
|
|
|
- return Error_Unexpect;
|
|
|
- }
|
|
|
- //fingerprint entity may not return immediately
|
|
|
- SLEEP(100);
|
|
|
-
|
|
|
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("begin next invoke match.");
|
|
|
- errCode = (*m_pFingerPrint)(EntityResource::getLink().upgradeLink())->Match(matchParam->sMatchReq, matchParam->sMatchAns, 20000);
|
|
|
-
|
|
|
- if (m_bCancelAuthorize || errCode == Error_Cancel)
|
|
|
- {
|
|
|
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("cancel authorize task.");
|
|
|
- bStopAuthorize = true;
|
|
|
- m_bCancelAuthorize = false;
|
|
|
- if (m_bAuthorizeTimeout)
|
|
|
- {
|
|
|
- m_bAuthorizeTimeout = false;
|
|
|
- return Error_TimeOut;
|
|
|
- }
|
|
|
- return Error_Cancel;
|
|
|
- }
|
|
|
- else if (errCode == Error_Unexpect || errCode == Error_TimeOut)
|
|
|
- {
|
|
|
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("invoke match error with errCode(%s)", SpStrError(errCode));
|
|
|
- BroadcastGetFinger(2);
|
|
|
- }
|
|
|
- else if (errCode == Error_Succeed)
|
|
|
- {
|
|
|
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("invoke match success, start analyze result.");
|
|
|
- errCode = AnalyzeMatchResult(matchParam, bStopAuthorize);
|
|
|
- if (errCode == Error_Succeed)
|
|
|
- return Error_Succeed; //continue if other errCode
|
|
|
- }
|
|
|
- else {
|
|
|
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("invole match error(%s), stop authorize", SpStrError(errCode));
|
|
|
- return Error_Unexpect;
|
|
|
- }
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
-ErrorCodeEnum CCustMngrAuthFSM::AnalyzeMatchResult(MatchParams* matchParam, bool& bStopAuthorize)
|
|
|
-{
|
|
|
- int resTemplateNum = matchParam->sMatchAns.result.GetCount();
|
|
|
- if (resTemplateNum != matchParam->sTotalNumOfTemplate)
|
|
|
- {
|
|
|
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("result templateNum(%d) is not equale to the Req's(%d)."
|
|
|
- , resTemplateNum, matchParam->sTotalNumOfTemplate);
|
|
|
- return Error_Unexpect;
|
|
|
- }
|
|
|
- std::vector<TemplateInfo>tmpFingerCountInfo(matchParam->sFingerCount);
|
|
|
- int matchIndex = -1; //matched CustomerID's index in array
|
|
|
- int matchCount = 0; //num of matched
|
|
|
- int fingerCountIndex = 0; //index of fingerCountInfo
|
|
|
- int FINGER_NUM = tmpFingerCountInfo[fingerCountIndex].TemplateNum;
|
|
|
- for (int i = 0; i < resTemplateNum; i += FINGER_NUM)
|
|
|
- {
|
|
|
- int oneCustMatchResult = 0;
|
|
|
- FINGER_NUM = tmpFingerCountInfo[fingerCountIndex].TemplateNum;
|
|
|
- for (int j = 0; j < FINGER_NUM; ++j)
|
|
|
- {
|
|
|
- oneCustMatchResult += matchParam->sMatchAns.result[i + j];
|
|
|
- }
|
|
|
-
|
|
|
- if (oneCustMatchResult > 0) //one customer has more than one match, just as one
|
|
|
- {
|
|
|
- matchCount++;
|
|
|
- matchIndex = fingerCountIndex;
|
|
|
- }
|
|
|
- if (matchCount > 1) //more than one customer's finger matched
|
|
|
- break;
|
|
|
- fingerCountIndex++;
|
|
|
- }
|
|
|
- int matchResult = matchCount;//0:no match; 1:just one match; 2: muti match
|
|
|
-
|
|
|
- switch (matchResult)
|
|
|
- {
|
|
|
- case 0:
|
|
|
- {
|
|
|
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("MatchResult: 0| no match");
|
|
|
- BroadcastGetFinger(0);
|
|
|
- }
|
|
|
- break;
|
|
|
- case 1:
|
|
|
- {
|
|
|
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("MatchResult: 1| one and only one match, authorize done.");
|
|
|
- DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("Match Finger(CustomerID=%s)", (const char*)tmpFingerCountInfo[matchIndex].CustomerID);
|
|
|
- m_authCtx.eAuthByWhich = AuthByFngPrnt;
|
|
|
- m_authCtx.CustomerID = tmpFingerCountInfo[matchIndex].CustomerID;
|
|
|
- bStopAuthorize = true;
|
|
|
- return Error_Succeed;
|
|
|
- }
|
|
|
- break;
|
|
|
- case 2:
|
|
|
- {
|
|
|
- DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("MatchResult: 2 | two and more matches. be alerted");
|
|
|
- BroadcastGetFinger(1);
|
|
|
- }
|
|
|
- break;
|
|
|
- default:break;
|
|
|
- }
|
|
|
- return Error_Unexpect;
|
|
|
-}
|
|
|
|
|
|
#pragma endregion
|
|
|
|
|
@@ -1333,10 +916,16 @@ ErrorCodeEnum CCustMngrAuthFSM::WaitForUkey(ErrorCodeEnum eErr)
|
|
|
{
|
|
|
//与朱毅约定,4表示本地无指纹数据,3表示指纹仪实体异常(包括旧接口的其他错误码和新接口的Error_HardWare)
|
|
|
//4: no data in local, 3:enitty exception
|
|
|
+// DbgInfo(CSimpleStringA::Format("WaitForUkey, eErr:%d(0x%x)", eErr, eErr));
|
|
|
+ DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("WaitForUkey, eErr:%d(0x%x)", eErr, eErr);
|
|
|
int status = (eErr == Error_NoTarget) ? 4 : 3;
|
|
|
BroadcastGetFinger(status);
|
|
|
while (1) {
|
|
|
+#ifdef RVC_OS_WIN
|
|
|
+ Sleep(300);
|
|
|
+#else
|
|
|
SLEEP(300);
|
|
|
+#endif
|
|
|
if (m_bCancelAuthorize) {
|
|
|
m_bCancelAuthorize = false;
|
|
|
if (m_bAuthorizeTimeout){
|
|
@@ -1375,7 +964,7 @@ ErrorCodeEnum CCustMngrAuthFSM::SwitchUSB(bool bOpen)
|
|
|
if (m_pDeviceControl != NULL) {
|
|
|
eErr = m_pDeviceControl->Connect();
|
|
|
if (eErr != Error_Succeed) {
|
|
|
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("m_pDeviceControl connect failed with errCode(%s)", SpStrError(eErr));
|
|
|
+ DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("m_pDeviceControl connect failed with errCode %x0x", eErr);
|
|
|
m_pDeviceControl->SafeDelete();
|
|
|
}
|
|
|
else {
|
|
@@ -1406,21 +995,6 @@ ErrorCodeEnum CCustMngrAuthFSM::SwitchUSB(bool bOpen)
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-ErrorCodeEnum CCustMngrAuthFSM::ConnectFingerPrintEntity()
|
|
|
-{
|
|
|
- ErrorCodeEnum errCode = Error_Succeed;
|
|
|
- m_pFingerPrint = new FingerPrintService_ClientBase(m_pEntity);
|
|
|
- errCode = m_pFingerPrint->Connect();
|
|
|
- if (errCode != Error_Succeed)
|
|
|
- {
|
|
|
- DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("ERROR: connect to fingerprint entity failed! %s", SpStrError(errCode));
|
|
|
- m_pFingerPrint->SafeDelete();
|
|
|
-
|
|
|
- errCode = Error_NoTarget; //TODO::give one other errCode
|
|
|
- }
|
|
|
- return errCode;
|
|
|
-}
|
|
|
-
|
|
|
#pragma endregion
|
|
|
|
|
|
|
|
@@ -1453,6 +1027,8 @@ ErrorCodeEnum CCustMngrAuthFSM::ConnectFingerPrintEntity()
|
|
|
|
|
|
|
|
|
|
|
|
+
|
|
|
+
|
|
|
|
|
|
|
|
|
|