|
@@ -1,4 +1,3 @@
|
|
|
-#include "SpBase.h"
|
|
|
#include "SpHelper.h"
|
|
|
#include "path.h"
|
|
|
#include "CustMngrAuth_UserErrorCode.h"
|
|
@@ -9,11 +8,18 @@
|
|
|
#include <thread>
|
|
|
#include <chrono>
|
|
|
#include <ctime>
|
|
|
+#include <string>
|
|
|
+#include <cstring>
|
|
|
+
|
|
|
+using std::string;
|
|
|
|
|
|
const int UPDATEINTERNAL = 10*60*1000; //query data from branch server internal, 10min
|
|
|
const int CONNECTINTERNAL = 30*1000; //connect branch server internal, 30s
|
|
|
const int FINGERNUM = 8; //suuport max register finger num
|
|
|
|
|
|
+#define RUNINFOFILE "CustMngrAuth.ini"
|
|
|
+#define RUNINFOFILE_BAK "CustMngrAuth_bak.ini"
|
|
|
+
|
|
|
class CCustMngrAuthEntity;
|
|
|
|
|
|
void CCustMngrAuthFSM::s0_on_entry()
|
|
@@ -45,7 +51,7 @@ unsigned int CCustMngrAuthFSM::s0_on_event(FSMEvent* pEvt)
|
|
|
}
|
|
|
return 0;
|
|
|
}
|
|
|
-//Initializing
|
|
|
+
|
|
|
void CCustMngrAuthFSM::s1_on_entry()
|
|
|
{
|
|
|
LOG_FUNCTION();
|
|
@@ -54,6 +60,7 @@ void CCustMngrAuthFSM::s1_on_exit()
|
|
|
{
|
|
|
LOG_FUNCTION();
|
|
|
}
|
|
|
+
|
|
|
unsigned int CCustMngrAuthFSM::s1_on_event(FSMEvent* pEvt)
|
|
|
{
|
|
|
LOG_FUNCTION();
|
|
@@ -68,7 +75,7 @@ unsigned int CCustMngrAuthFSM::s1_on_event(FSMEvent* pEvt)
|
|
|
}
|
|
|
return 0;
|
|
|
}
|
|
|
-//Idle
|
|
|
+
|
|
|
void CCustMngrAuthFSM::s2_on_entry()
|
|
|
{
|
|
|
LOG_FUNCTION();
|
|
@@ -77,62 +84,62 @@ void CCustMngrAuthFSM::s2_on_exit()
|
|
|
{
|
|
|
LOG_FUNCTION();
|
|
|
}
|
|
|
+
|
|
|
unsigned int CCustMngrAuthFSM::s2_on_event(FSMEvent* pEvt)
|
|
|
{
|
|
|
Dbg("s2 evt(%d)", pEvt->iEvt);
|
|
|
- int ret = 0;
|
|
|
+
|
|
|
switch (pEvt->iEvt)
|
|
|
{
|
|
|
case USER_EVT_AUTHORIZE_START:
|
|
|
{
|
|
|
pEvt->SetHandled();
|
|
|
Dbg("start to authorize");
|
|
|
- AuthorizeStartEvent *ase = dynamic_cast<AuthorizeStartEvent*>(pEvt);
|
|
|
- if (ase->ctx->Req.TimeLimit <= 0)
|
|
|
+ AuthorizeStartEvent *authorEvt = dynamic_cast<AuthorizeStartEvent*>(pEvt);
|
|
|
+ if (authorEvt->ctx->Req.TimeLimit <= 0)
|
|
|
{
|
|
|
- LOG_TRACE("ERROR: receive timelimit lessequal than zero. ctx->Answer(error_Param)");
|
|
|
+ Dbg("ERROR: receive timelimit lessequal than zero. ctx->Answer(error_Param)");
|
|
|
AuthorizeFinishedEvent *e = new AuthorizeFinishedEvent();
|
|
|
- e->ctx = ase->ctx;
|
|
|
+ e->ctx = authorEvt->ctx;
|
|
|
e->param1 = Error_Param;
|
|
|
this->PostEventFIFO(e);
|
|
|
break;
|
|
|
}
|
|
|
- m_TimeLimit = (ase->ctx->Req.TimeLimit - 3) * 1000; //状态机流程会耗一些时间,这里要比前端传过来的时间小一些,及时返回给前端
|
|
|
-
|
|
|
- ErrorCodeEnum eErr;
|
|
|
+ //状态机流程会耗一些时间,这里要比前端传过来的时间小一些,及时返回给前端
|
|
|
+ m_TimeLimit = (authorEvt->ctx->Req.TimeLimit - 3) * 1000;
|
|
|
m_bCancelAuthorize = false;
|
|
|
- //打开USB
|
|
|
- eErr = SwitchUSB(true);
|
|
|
- if (eErr != Error_Succeed)
|
|
|
- Dbg("open usb failed with eErr(0x%x)", eErr);
|
|
|
+
|
|
|
+ ErrorCodeEnum errCode = SwitchUSB(true);
|
|
|
+ if (errCode != Error_Succeed)
|
|
|
+ Dbg("open usb failed with eErr(%s)", SpStrError(errCode));
|
|
|
else{
|
|
|
Dbg("open usb successfully.");
|
|
|
- m_ctx = ase->ctx;
|
|
|
+ m_ctx = authorEvt->ctx;
|
|
|
}
|
|
|
|
|
|
//起指纹匹配线程
|
|
|
- MatchFingerPrintTask *mTask = new MatchFingerPrintTask(this);
|
|
|
- mTask->ctx = ase->ctx;
|
|
|
- GetEntityBase()->GetFunction()->PostThreadPoolTask(mTask);
|
|
|
+ MatchFingerPrintTask *matchTask = new MatchFingerPrintTask(this);
|
|
|
+ matchTask->ctx = authorEvt->ctx;
|
|
|
+ GetEntityBase()->GetFunction()->PostThreadPoolTask(matchTask);
|
|
|
}
|
|
|
break;
|
|
|
case USER_EVT_COLLECTFINGERPRINT_START:
|
|
|
{
|
|
|
- CollectFingerPrintStartEvent *cfpe = dynamic_cast<CollectFingerPrintStartEvent*>(pEvt);
|
|
|
- CollectFingerPrintTask *ftask = new CollectFingerPrintTask(this);
|
|
|
- ftask->ctx = cfpe->ctx;
|
|
|
- GetEntityBase()->GetFunction()->PostThreadPoolTask(ftask);
|
|
|
- Dbg("collect_finger_print task posted");
|
|
|
pEvt->SetHandled();
|
|
|
+ CollectFingerPrintStartEvent *collectEvt = dynamic_cast<CollectFingerPrintStartEvent*>(pEvt);
|
|
|
+ CollectFingerPrintTask *collectTask = new CollectFingerPrintTask(this);
|
|
|
+ collectTask->ctx = collectEvt->ctx;
|
|
|
+ GetEntityBase()->GetFunction()->PostThreadPoolTask(collectTask);
|
|
|
+ Dbg("collect_finger_print task posted");
|
|
|
}
|
|
|
break;
|
|
|
case USER_EVT_SAVEFINGERPRINT_START:
|
|
|
{
|
|
|
pEvt->SetHandled();
|
|
|
- SaveFingerPrintStartEvent *sfpe = dynamic_cast<SaveFingerPrintStartEvent*>(pEvt);
|
|
|
- SaveFingerPrintTask *sTask = new SaveFingerPrintTask(this);
|
|
|
- sTask->ctx = sfpe->ctx;
|
|
|
- GetEntityBase()->GetFunction()->PostThreadPoolTask(sTask);
|
|
|
+ SaveFingerPrintStartEvent *saveEvtfpe = dynamic_cast<SaveFingerPrintStartEvent*>(pEvt);
|
|
|
+ SaveFingerPrintTask *saveTask = new SaveFingerPrintTask(this);
|
|
|
+ saveTask->ctx = saveEvtfpe->ctx;
|
|
|
+ GetEntityBase()->GetFunction()->PostThreadPoolTask(saveTask);
|
|
|
Dbg("save_finger_print task posted");
|
|
|
}
|
|
|
break;
|
|
@@ -167,23 +174,23 @@ unsigned int CCustMngrAuthFSM::s3_on_event(FSMEvent* pEvt)
|
|
|
{
|
|
|
case USER_EVT_HOLDON:
|
|
|
{
|
|
|
- HoldOnEvent *hoe = dynamic_cast<HoldOnEvent*>(pEvt);
|
|
|
+ pEvt->SetHandled();
|
|
|
+ HoldOnEvent *holdEvt = dynamic_cast<HoldOnEvent*>(pEvt);
|
|
|
Dbg(" Cancel old timer(1) and rescheduling timer(1)");
|
|
|
CancelTimer(1);
|
|
|
Dbg("Timer1 canceled");
|
|
|
- if (hoe->ctx == NULL)
|
|
|
+ if (holdEvt->ctx == NULL)
|
|
|
Dbg("HoldOnEvent->ctx is NULL");
|
|
|
- Dbg("HoldOn with MoreTime: %d second", hoe->ctx->Req.MoreTime);
|
|
|
- int moreTime = hoe->ctx->Req.MoreTime * 1000;
|
|
|
+ Dbg("HoldOn with MoreTime: %d second", holdEvt->ctx->Req.MoreTime);
|
|
|
+ int moreTime = holdEvt->ctx->Req.MoreTime * 1000;
|
|
|
Dbg("Adding more time: %d", moreTime);
|
|
|
ScheduleTimer(1, (moreTime > 0) ? moreTime : m_TimeLimit);
|
|
|
- pEvt->SetHandled();
|
|
|
}
|
|
|
break;
|
|
|
case EVT_TIMER:
|
|
|
{
|
|
|
- Dbg("Hit Timer");
|
|
|
pEvt->SetHandled();
|
|
|
+ Dbg("Hit Timer");
|
|
|
m_bAuthorizeTimeout = true;
|
|
|
m_bCancelAuthorize = true;
|
|
|
CancelAuthorize();
|
|
@@ -193,15 +200,14 @@ unsigned int CCustMngrAuthFSM::s3_on_event(FSMEvent* pEvt)
|
|
|
case USER_EVT_AUTHORIZE_FINISHED:
|
|
|
{
|
|
|
pEvt->SetHandled();
|
|
|
- ErrorCodeEnum eErr;
|
|
|
- AuthorizeFinishedEvent *afe = dynamic_cast<AuthorizeFinishedEvent*>(pEvt);
|
|
|
+ AuthorizeFinishedEvent *authorEvt = dynamic_cast<AuthorizeFinishedEvent*>(pEvt);
|
|
|
Dbg("Checking m_authCtx and answer ctx");
|
|
|
if(m_csMachineType.Compare("RVC.PAD", true))
|
|
|
{
|
|
|
//非PAD才去关闭U口
|
|
|
SwitchUSB(false);
|
|
|
}
|
|
|
- if (afe->param1 == 0)
|
|
|
+ if (authorEvt->param1 == 0)
|
|
|
{
|
|
|
Dbg("authorize finished with param1 as 0");
|
|
|
if (m_authCtx.eAuthByWhich == AuthByUkey)
|
|
@@ -212,22 +218,22 @@ unsigned int CCustMngrAuthFSM::s3_on_event(FSMEvent* pEvt)
|
|
|
Dbg("Invoke cancel match.");
|
|
|
m_pFingerPrint->CancelMatch();
|
|
|
}
|
|
|
- afe->ctx->Ans.WayofAuth = AuthByUkey;
|
|
|
- afe->ctx->Ans.UkeyID = m_authCtx.UkeyID;
|
|
|
- afe->ctx->Answer(Error_Succeed);
|
|
|
+ authorEvt->ctx->Ans.WayofAuth = AuthByUkey;
|
|
|
+ authorEvt->ctx->Ans.UkeyID = m_authCtx.UkeyID;
|
|
|
+ authorEvt->ctx->Answer(Error_Succeed);
|
|
|
}
|
|
|
else if (m_authCtx.eAuthByWhich == AuthByFngPrnt)
|
|
|
{
|
|
|
Dbg("m_authCtx.eAuthByWhich == AuthByFngPrnt");
|
|
|
- afe->ctx->Ans.WayofAuth = AuthByFngPrnt;
|
|
|
- afe->ctx->Ans.CustomerID = m_authCtx.CustomerID;
|
|
|
- afe->ctx->Answer(Error_Succeed);
|
|
|
+ authorEvt->ctx->Ans.WayofAuth = AuthByFngPrnt;
|
|
|
+ authorEvt->ctx->Ans.CustomerID = m_authCtx.CustomerID;
|
|
|
+ authorEvt->ctx->Answer(Error_Succeed);
|
|
|
}
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- Dbg("authorize finished with param1 as %d", afe->param1);
|
|
|
- afe->ctx->Answer((ErrorCodeEnum)afe->param1);
|
|
|
+ Dbg("authorize finished with param1 as %d", authorEvt->param1);
|
|
|
+ authorEvt->ctx->Answer((ErrorCodeEnum)authorEvt->param1);
|
|
|
}
|
|
|
|
|
|
if (m_pFingerPrint != NULL && !m_pFingerPrint->QuerySessionClosed())
|
|
@@ -269,7 +275,7 @@ void CCustMngrAuthFSM::s4_on_exit()
|
|
|
unsigned int CCustMngrAuthFSM::s4_on_event(FSMEvent* pEvt)
|
|
|
{
|
|
|
Dbg("s4 evt %d, %d", pEvt->iEvt, pEvt->param1);
|
|
|
- int ret = 0;
|
|
|
+
|
|
|
switch (pEvt->iEvt)
|
|
|
{
|
|
|
case USER_EVT_COLLECTFINGERPRINT_FINISHED:
|
|
@@ -335,11 +341,13 @@ ErrorCodeEnum CCustMngrAuthFSM::OnExit()
|
|
|
|
|
|
int CCustMngrAuthFSM::Initial()
|
|
|
{
|
|
|
- STR_FINGERINFO = "FingerInfo";
|
|
|
- ErrorCodeEnum eErr = GetEntityBase()->GetFunction()->GetPath("RunInfo", m_runInfoPath);
|
|
|
+ m_FingerSection = "FingerInfo";
|
|
|
+ ErrorCodeEnum eErr = GetEntityBase()->GetFunction()->GetPath("RunInfo", m_RunInfoPath);
|
|
|
if(eErr != Error_Succeed){
|
|
|
Dbg("get runinfo path failed.");
|
|
|
- LogError(Severity_High, Error_DevLoadFileFailed, LOG_ERR_CUSTMNGRAUTH_GET_RUNINFO_PATH_FAILED_Init, "get runinfo path failed while init");
|
|
|
+ LogError(Severity_High, Error_DevLoadFileFailed
|
|
|
+ , LOG_ERR_CUSTMNGRAUTH_GET_RUNINFO_PATH_FAILED_Init
|
|
|
+ , "get runinfo path failed while init");
|
|
|
return 1;
|
|
|
}
|
|
|
FeatureUpdateTask *pTask = new FeatureUpdateTask(this);
|
|
@@ -366,22 +374,20 @@ bool CCustMngrAuthFSM::ReadDataIntoMemory(bool& bHasData)
|
|
|
|
|
|
CSimpleStringA strPath;
|
|
|
CSimpleStringA runInfoFile;
|
|
|
- runInfoFile = CSimpleStringA::Format("%s" SPLIT_SLASH_STR "runcfg" SPLIT_SLASH_STR "CustMngrAuth.ini"
|
|
|
- , (const char*)m_runInfoPath);
|
|
|
-
|
|
|
- ifstream inFile(runInfoFile);
|
|
|
+ runInfoFile = CSimpleStringA::Format("%s" SPLIT_SLASH_STR "runcfg" SPLIT_SLASH_STR RUNINFOFILE
|
|
|
+ , (const char*)m_RunInfoPath);
|
|
|
+ std::ifstream inFile(runInfoFile);
|
|
|
string line;
|
|
|
int customerNum = 0;
|
|
|
|
|
|
- Dbg("read data timer start...");
|
|
|
-
|
|
|
clock_t startReadFile = clock();
|
|
|
clock_t endReadFile = clock();
|
|
|
|
|
|
- while(getline(inFile, line)){
|
|
|
- if(line.length() <= 0){
|
|
|
+ while(getline(inFile, line))
|
|
|
+ {
|
|
|
+ if(line.length() <= 0)
|
|
|
continue;
|
|
|
- }
|
|
|
+
|
|
|
string tempLine = ClearStringSpaceHeadTail(line);
|
|
|
if(!tempLine.compare("[UpdateTime]") || string::npos != tempLine.find("UpdateTime")
|
|
|
|| !tempLine.compare("[LatestTime]") || string::npos != tempLine.find("LatestTime")
|
|
@@ -390,22 +396,24 @@ bool CCustMngrAuthFSM::ReadDataIntoMemory(bool& bHasData)
|
|
|
continue;
|
|
|
}
|
|
|
string::size_type pos = tempLine.find("=");
|
|
|
- if(pos != 16){
|
|
|
+ if(pos != 16)
|
|
|
continue;
|
|
|
- }
|
|
|
+
|
|
|
string keys = tempLine.substr(0, pos);
|
|
|
- string values = tempLine.substr(pos+1);
|
|
|
+ string values = tempLine.substr(pos + 1);
|
|
|
|
|
|
Json::Reader reader;
|
|
|
Json::Value root;
|
|
|
- if (reader.parse((const char*)values.c_str(), root)){
|
|
|
+ if (reader.parse((const char*)values.c_str(), root))
|
|
|
+ {
|
|
|
customerNum++;
|
|
|
FeatureData *fd = new FeatureData();
|
|
|
fd->FingerIDArray.Init(FINGERNUM);
|
|
|
fd->FingerIDLenArray.Init(FINGERNUM);
|
|
|
- for (int i = 0; i < FINGERNUM; ++i){
|
|
|
- char index[20] = { 0 };
|
|
|
-
|
|
|
+ char index[20];
|
|
|
+ for (int i = 0; i < FINGERNUM; ++i)
|
|
|
+ {
|
|
|
+ memset(index, 0, sizeof(index));
|
|
|
#ifdef RVC_OS_WIN
|
|
|
_snprintf_s(index, 10, "FingerID%d", i + 1);
|
|
|
#else
|
|
@@ -417,10 +425,11 @@ bool CCustMngrAuthFSM::ReadDataIntoMemory(bool& bHasData)
|
|
|
}
|
|
|
//首次读取到内存,m_featureData为空,不用考虑其中已存在该key值
|
|
|
m_featureData[CSimpleStringA(keys.c_str())] = fd;
|
|
|
- //Dbg("CustomerID=%s success.", keys.c_str());
|
|
|
}else{
|
|
|
Dbg("Error: parse jsonFingerInfo failed.");
|
|
|
- LogWarn(Severity_High, Error_Unexpect, LOG_ERR_CUSTMNGRAUTH_AUTHORIZATION_READFEAT_FAILED, "Read fingerprint feature json failed.");
|
|
|
+ LogWarn(Severity_High, Error_Unexpect
|
|
|
+ , LOG_ERR_CUSTMNGRAUTH_AUTHORIZATION_READFEAT_FAILED
|
|
|
+ , "Read fingerprint feature json failed.");
|
|
|
return false;
|
|
|
}
|
|
|
}
|
|
@@ -428,32 +437,34 @@ bool CCustMngrAuthFSM::ReadDataIntoMemory(bool& bHasData)
|
|
|
Dbg("Total CustomerNum:%d in local file.", customerNum);
|
|
|
|
|
|
endReadFile = clock();
|
|
|
- int duration = (endReadFile - startReadFile) * 1000 / CLOCKS_PER_SEC;
|
|
|
- LogWarn(Severity_High, Error_Debug, LOG_ERR_CUSTMNGRAUTH_READ_INTO_MEMORY_TIME,
|
|
|
- GenerateAlarmJson("CustMngrAuth", duration).GetData());
|
|
|
-
|
|
|
- Dbg("read data timer end...");
|
|
|
- Dbg("cost time:%dms", duration) ;
|
|
|
+ DWORD duration = (endReadFile - startReadFile) * 1000 / CLOCKS_PER_SEC;
|
|
|
+ LogWarn(Severity_High, Error_Debug
|
|
|
+ , LOG_ERR_CUSTMNGRAUTH_READ_INTO_MEMORY_TIME
|
|
|
+ , GenerateAlarmJson("CustMngrAuth", duration).GetData());
|
|
|
bHasData = true;
|
|
|
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
-void CCustMngrAuthFSM::TransDataFromServer(CAutoArray<CSimpleStringA> &dataArray, CSimpleStringA latestTime, bool& bResumeTrans, bool bIsFirstTimeQueryData)
|
|
|
+void CCustMngrAuthFSM::TransDataFromServer(CAutoArray<CSimpleStringA> &dataArray
|
|
|
+ , CSimpleStringA latestTime
|
|
|
+ , bool& bResumeTrans
|
|
|
+ , bool bIsFirstTimeQueryData)
|
|
|
{
|
|
|
LOG_FUNCTION();
|
|
|
int transTime = 0;
|
|
|
char currAgent[16]="";
|
|
|
char branchID[16]="";
|
|
|
- while(bResumeTrans){
|
|
|
+ while(bResumeTrans)
|
|
|
+ {
|
|
|
transTime++;
|
|
|
if (bIsFirstTimeQueryData)
|
|
|
m_pConnection->SendFeatReq(currAgent, branchID);
|
|
|
else
|
|
|
m_pConnection->SendFeatReq(currAgent, branchID, (const char*)latestTime);
|
|
|
|
|
|
- ResetEvent(m_pConnection->hPkgAnswer);
|
|
|
- DWORD dw = WaitForSingleObject(m_pConnection->hPkgAnswer, 20000); //10->20 20200430@liuwentao
|
|
|
+ ResetEvent(m_pConnection->m_hPkgAnswer);
|
|
|
+ DWORD dw = WaitForSingleObject(m_pConnection->m_hPkgAnswer, 20000); //10->20 20200430@liuwentao
|
|
|
switch(dw)
|
|
|
{
|
|
|
case WAIT_FAILED:
|
|
@@ -465,20 +476,24 @@ void CCustMngrAuthFSM::TransDataFromServer(CAutoArray<CSimpleStringA> &dataArray
|
|
|
Dbg("WAIT_OBJECT_0");
|
|
|
break;
|
|
|
}
|
|
|
- ResetEvent(m_pConnection->hPkgAnswer);
|
|
|
- if (m_pConnection->m_reply == NULL){
|
|
|
- Dbg("m_reply still null after hPkgAnswer handled");
|
|
|
+ ResetEvent(m_pConnection->m_hPkgAnswer);
|
|
|
+ if (m_pConnection->m_reply == NULL)
|
|
|
+ {
|
|
|
+ Dbg("m_reply still null after m_hPkgAnswer handled");
|
|
|
break;
|
|
|
}else{
|
|
|
- if (m_pConnection->getErrMsg){
|
|
|
+ if (m_pConnection->m_GetErrMsg)
|
|
|
+ {
|
|
|
Dbg("get error message, check dbg log");
|
|
|
break;
|
|
|
}
|
|
|
- if (m_pConnection->m_reply->ResultCode == 2){
|
|
|
+ if (m_pConnection->m_reply->ResultCode == 2)
|
|
|
+ {
|
|
|
Dbg("remote server uninitialized yet, unable to excute query");
|
|
|
break;
|
|
|
}else{
|
|
|
- if (m_pConnection->m_reply->ResultCode == 0){
|
|
|
+ if (m_pConnection->m_reply->ResultCode == 0)
|
|
|
+ {
|
|
|
Dbg("All package downloaded from branch server.");
|
|
|
bResumeTrans = false;
|
|
|
}
|
|
@@ -498,7 +513,9 @@ bool CCustMngrAuthFSM::BackupFile(CSimpleStringA srcFile, CSimpleStringA dstFile
|
|
|
ifstream inFile;
|
|
|
ofstream outFile;
|
|
|
fileExist.open((const char*)srcFile, ios::in);
|
|
|
- if(!fileExist){
|
|
|
+
|
|
|
+ if(!fileExist)
|
|
|
+ {
|
|
|
fileExist.close();
|
|
|
return true;
|
|
|
}
|
|
@@ -511,7 +528,8 @@ bool CCustMngrAuthFSM::BackupFile(CSimpleStringA srcFile, CSimpleStringA dstFile
|
|
|
return false;
|
|
|
}
|
|
|
outFile.open((const char*)dstFile);
|
|
|
- if (outFile.fail()){
|
|
|
+ if (outFile.fail())
|
|
|
+ {
|
|
|
Dbg("Open CustMngrAuth_bak.ini failed.");
|
|
|
backupResult = false;
|
|
|
}else{
|
|
@@ -522,25 +540,33 @@ bool CCustMngrAuthFSM::BackupFile(CSimpleStringA srcFile, CSimpleStringA dstFile
|
|
|
return backupResult;
|
|
|
}
|
|
|
|
|
|
-void CCustMngrAuthFSM::FeatureUpdate()
|
|
|
+void CCustMngrAuthFSM::InitBeforeUpdateData()
|
|
|
{
|
|
|
- LOG_FUNCTION();
|
|
|
- //when start entity, read data into memory
|
|
|
bool bHasData = false;
|
|
|
bool bReadResult = ReadDataIntoMemory(bHasData);
|
|
|
if (bReadResult && bHasData)
|
|
|
{
|
|
|
Dbg("Read feature data into memory success.");
|
|
|
- }else if (bReadResult && !bHasData) {
|
|
|
+ }
|
|
|
+ else if (bReadResult && !bHasData) {
|
|
|
Dbg("Has no data in local file.");
|
|
|
- }else{
|
|
|
+ }
|
|
|
+ else {
|
|
|
Dbg("Read feature data into memory failed, wait next read.");
|
|
|
}
|
|
|
- int tWait = UPDATEINTERNAL;
|
|
|
- int connectFailedTimes = 0;
|
|
|
- ErrorCodeEnum eErr;
|
|
|
+}
|
|
|
|
|
|
- while(1){
|
|
|
+void CCustMngrAuthFSM::FeatureUpdate()
|
|
|
+{
|
|
|
+ LOG_FUNCTION();
|
|
|
+ //when start entity, read data into memory
|
|
|
+ InitBeforeUpdateData();
|
|
|
+
|
|
|
+ while(1)
|
|
|
+ {
|
|
|
+ int tWait = UPDATEINTERNAL;
|
|
|
+ int connectFailedTimes = 0;
|
|
|
+ ErrorCodeEnum eErr;
|
|
|
CSmartPointer<IConfigInfo> spConfig;
|
|
|
CAutoArray<CSimpleStringA> transArray;
|
|
|
m_pConnection = new FeatureUpdateConn(m_pEntity, this);
|
|
@@ -555,7 +581,9 @@ void CCustMngrAuthFSM::FeatureUpdate()
|
|
|
eErr = GetEntityBase()->GetFunction()->OpenConfig(Config_Run, spConfig);
|
|
|
if (eErr != Error_Succeed){
|
|
|
Dbg("Open runcfg file failed before query data.");
|
|
|
- LogError(Severity_High, Error_Unexpect, LOG_ERR_CUSTMNGRAUTH_OPEN_RUNINFO_FAILED_UPDATE, "open runcfg failed before query data.");
|
|
|
+ LogError(Severity_High, Error_Unexpect
|
|
|
+ , LOG_ERR_CUSTMNGRAUTH_OPEN_RUNINFO_FAILED_UPDATE
|
|
|
+ , "open runcfg failed before query data.");
|
|
|
LeaveCriticalSection(&m_cs);
|
|
|
goto Err;
|
|
|
}
|
|
@@ -568,7 +596,10 @@ void CCustMngrAuthFSM::FeatureUpdate()
|
|
|
CSimpleStringA newTime = GetCurrentDate();
|
|
|
|
|
|
//当前日期大于文件中日期时,需要做全量更新
|
|
|
- if (updateTime.GetLength() <= 0 || (updateTime.GetLength() > 0 && CompareTime(newTime, updateTime) > 0) || latestTime.GetLength() <= 0){
|
|
|
+ if (updateTime.GetLength() <= 0
|
|
|
+ || (updateTime.GetLength() > 0 && CompareTime(newTime, updateTime) > 0)
|
|
|
+ || latestTime.GetLength() <= 0)
|
|
|
+ {
|
|
|
isFirstTimeQueryData = true;
|
|
|
}
|
|
|
|
|
@@ -577,13 +608,10 @@ void CCustMngrAuthFSM::FeatureUpdate()
|
|
|
|
|
|
if(resumeTrans){
|
|
|
Dbg("ERROR: The last update of feature ended with resumetrans as true, might be timeout or some errors happened");
|
|
|
- //存在有时因分行服务升级导致连接断开,更新数据失败,暂时对业务无影响
|
|
|
- //LogError(Severity_High, Error_Unexpect, LOG_ERR_CUSTMNGRAUTH_FEATUPDATE_DOWNLOAD_FAILED, "Transmission of fingerprint feature failed.");
|
|
|
goto Err;
|
|
|
}
|
|
|
if (transArray.GetCount() <= 0){
|
|
|
Dbg("query no data from branchServer.(exact no data or the sql was deleted)");
|
|
|
- //LogWarn(Severity_High, Error_Unexpect, LOG_ERR_CUSTMNGRAUTH_FEATUPDATE_DOWNLOAD_FAILED, "query no data from branchServer.");
|
|
|
goto Err;
|
|
|
}
|
|
|
//续传成功结束,解析jbuf数组并写入本地
|
|
@@ -592,26 +620,27 @@ void CCustMngrAuthFSM::FeatureUpdate()
|
|
|
//写入文件前,先判断是否已存在CustMngrAuth.ini文件,若不存在则直接写入,若存在,则先备份该文件
|
|
|
CSimpleStringA srcFile(true);
|
|
|
CSimpleStringA backupFile(true);
|
|
|
- srcFile = CSimpleStringA::Format("%s" SPLIT_SLASH_STR "runcfg" SPLIT_SLASH_STR "CustMngrAuth.ini"
|
|
|
- , (const char*)m_runInfoPath);
|
|
|
- backupFile = CSimpleStringA::Format("%s" SPLIT_SLASH_STR "runcfg" SPLIT_SLASH_STR "CustMngrAuth_bak.ini"
|
|
|
- , (const char*)m_runInfoPath);
|
|
|
+ srcFile = CSimpleStringA::Format("%s" SPLIT_SLASH_STR "runcfg" SPLIT_SLASH_STR RUNINFOFILE
|
|
|
+ , (const char*)m_RunInfoPath);
|
|
|
+ backupFile = CSimpleStringA::Format("%s" SPLIT_SLASH_STR "runcfg" SPLIT_SLASH_STR RUNINFOFILE_BAK
|
|
|
+ , (const char*)m_RunInfoPath);
|
|
|
|
|
|
EnterCriticalSection(&m_cs);
|
|
|
if(!BackupFile(srcFile, backupFile)){
|
|
|
Dbg("Backup runinfo file failed.");
|
|
|
}
|
|
|
- if (isFirstTimeQueryData){
|
|
|
+ if (isFirstTimeQueryData)
|
|
|
+ {
|
|
|
//首次更新,需清除数据,全量写入,并更新时间
|
|
|
ofstream fileOut((const char*)srcFile, ios::trunc);
|
|
|
fileOut.close();
|
|
|
}
|
|
|
|
|
|
eErr = GetEntityBase()->GetFunction()->OpenConfig(Config_Run, spConfig);
|
|
|
- if (eErr != Error_Succeed){
|
|
|
+ if (eErr != Error_Succeed)
|
|
|
+ {
|
|
|
RecoverFile(srcFile, backupFile);//有失败情况,恢复原文件
|
|
|
- //LogError(Severity_High, Error_DevLoadFileFailed, LOG_ERR_CUSTMNGRAUTH_OPEN_RUNINFO__FAILED, "Open runinfo file failed.");
|
|
|
- Dbg("ERROR: Open runcfg failed with %d", eErr);
|
|
|
+ Dbg("ERROR: Open runcfg failed with %s", SpStrError(eErr));
|
|
|
LeaveCriticalSection(&m_cs);
|
|
|
goto Err;
|
|
|
}
|
|
@@ -623,12 +652,12 @@ void CCustMngrAuthFSM::FeatureUpdate()
|
|
|
}
|
|
|
map<CSimpleStringA, FeatureData*> tempFeature;//如果是全量更新,需要更新后全量传给m_featureData
|
|
|
CSimpleStringA maxUpdateTime = latestTime;
|
|
|
- for(int transTime = 0; transTime < transArray.GetCount(); ++transTime){
|
|
|
+ for(int transTime = 0; transTime < transArray.GetCount(); ++transTime)
|
|
|
+ {
|
|
|
Json::Value root;
|
|
|
Json::Reader reader;
|
|
|
Json::FastWriter writer;
|
|
|
CSimpleStringA transBuffer = transArray[transTime];//一次传输受大小限制,只能有3~4条
|
|
|
- //Dbg("transBuffer=%s", transBuffer.GetData());
|
|
|
if (reader.parse((const char*)transBuffer, root)){
|
|
|
for (int i = 0; i < (int)root.size(); ++i){
|
|
|
Json::Value jsonFingerInfo;
|
|
@@ -674,7 +703,7 @@ void CCustMngrAuthFSM::FeatureUpdate()
|
|
|
jstr[jlen]= '\0';
|
|
|
|
|
|
//不做这步处理的话runcfg里faceinfo节不同customerID间没有换行,fingerinfo节本来有,但以防万一也做同样处理。
|
|
|
- eErr = spConfig->WriteConfigValue(STR_FINGERINFO, root[i]["customerID"].asCString(), jstr);
|
|
|
+ eErr = spConfig->WriteConfigValue((const char*)m_FingerSection, root[i]["customerID"].asCString(), jstr);
|
|
|
delete []jstr;
|
|
|
if (eErr != Error_Succeed){
|
|
|
//如果写入失败,则将原文件恢复
|
|
@@ -684,7 +713,7 @@ void CCustMngrAuthFSM::FeatureUpdate()
|
|
|
}
|
|
|
}else if (fingerDataState == 2){
|
|
|
Dbg("state(2): customer %s is currently unavailable.", root[i]["customerID"].asCString());
|
|
|
- spConfig->WriteConfigValue(STR_FINGERINFO, root[i]["customerID"].asCString(), "");
|
|
|
+ spConfig->WriteConfigValue((const char*)m_FingerSection, root[i]["customerID"].asCString(), "");
|
|
|
}else{
|
|
|
Dbg("ERROR: unexpectedly customer(%s)'s state is either 0 or 2", root[i]["customerID"].asCString());
|
|
|
}
|
|
@@ -708,8 +737,11 @@ void CCustMngrAuthFSM::FeatureUpdate()
|
|
|
Dbg("ERROR: Fail to connect remote server! Try again in %d mm.", CONNECTINTERNAL);
|
|
|
connectFailedTimes++;
|
|
|
Dbg("connect time = %d", connectFailedTimes);
|
|
|
- if(connectFailedTimes >= 60){//如果一直连不上,则30分钟抛一次告警
|
|
|
- LogWarn(Severity_High, Error_Unexpect, LOG_ERR_CUSTMNGRAUTH_FEATUPDATE_CONNECT_FAILED, "Connect branch server failed.");
|
|
|
+ if(connectFailedTimes >= 60) //如果一直连不上,则30分钟抛一次告警
|
|
|
+ {
|
|
|
+ LogWarn(Severity_High, Error_Unexpect
|
|
|
+ , LOG_ERR_CUSTMNGRAUTH_FEATUPDATE_CONNECT_FAILED
|
|
|
+ , "Connect branch server failed.");
|
|
|
connectFailedTimes = 0;
|
|
|
}
|
|
|
tWait = CONNECTINTERNAL;
|
|
@@ -756,176 +788,216 @@ void CCustMngrAuthFSM::UpdateDataIntoMemory(map<CSimpleStringA, FeatureData*> te
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-ErrorCodeEnum CCustMngrAuthFSM::MatchFingerPrint(SpReqAnsContext<CustMngrAuthService_StartAuthorize_Req, CustMngrAuthService_StartAuthorize_Ans>::Pointer ctx, bool& bStopAuthorize)
|
|
|
+ErrorCodeEnum CCustMngrAuthFSM::InitBeforeMatch()
|
|
|
{
|
|
|
- //只有取消、超时、成功匹配、侦听到ukey插入触发这里的取消这些情况下才会终止授权,否则就算遇到异常退出本方法,也要继续等待直到超时或ukey或取消。
|
|
|
- LOG_FUNCTION();
|
|
|
- ErrorCodeEnum eErr;
|
|
|
+ ErrorCodeEnum errCode = Error_Succeed;
|
|
|
m_pFingerPrint = new FingerPrintService_ClientBase(m_pEntity);
|
|
|
- eErr = m_pFingerPrint->Connect();
|
|
|
- if (eErr != Error_Succeed){
|
|
|
+ errCode = m_pFingerPrint->Connect();
|
|
|
+ if (errCode != Error_Succeed)
|
|
|
+ {
|
|
|
Dbg("ERROR: connect to fingerprint entity failed!");
|
|
|
- m_pFingerPrint->SafeDelete();
|
|
|
- m_pFingerPrint=NULL;
|
|
|
- return Error_Unexpect; //TODO::give one other errCode
|
|
|
+ if (m_pFingerPrint != NULL)
|
|
|
+ {
|
|
|
+ m_pFingerPrint->SafeDelete();
|
|
|
+ m_pFingerPrint = NULL;
|
|
|
+ }
|
|
|
+
|
|
|
+ errCode = Error_Unexpect; //TODO::give one other errCode
|
|
|
}
|
|
|
+ return errCode;
|
|
|
+}
|
|
|
|
|
|
+ErrorCodeEnum CCustMngrAuthFSM::PrepareDataBeforeMatch(MatchParams *matchParam)
|
|
|
+{
|
|
|
EnterCriticalSection(&m_cs);
|
|
|
- //loop invoke match, only when have one match,stop;otherwise, continue loop
|
|
|
- FingerPrintService_Match_Req matchReq;
|
|
|
- FingerPrintService_Match_Ans matchAns;
|
|
|
- CAutoArray<CSimpleStringA> tempFeatureArray; //临时存放指纹数据,用于给入参赋值
|
|
|
+
|
|
|
+ CAutoArray<CSimpleStringA> tempFeatureArray;
|
|
|
CAutoArray<int> tempFeatureLenArray;
|
|
|
int totalCustomerID = m_featureData.size();
|
|
|
int totalTemplate = totalCustomerID * FINGERNUM;
|
|
|
- if (totalCustomerID <= 0){
|
|
|
+ tempFeatureArray.Init(totalTemplate);
|
|
|
+ tempFeatureLenArray.Init(totalTemplate);
|
|
|
+
|
|
|
+ if (totalCustomerID <= 0)
|
|
|
+ {
|
|
|
Dbg("No FingerPrint data in local file or read local file failed.");
|
|
|
LeaveCriticalSection(&m_cs);
|
|
|
+ if (matchParam != NULL)
|
|
|
+ delete matchParam;
|
|
|
return Error_NoTarget;
|
|
|
}
|
|
|
- tempFeatureArray.Init(totalTemplate);
|
|
|
- tempFeatureLenArray.Init(totalTemplate);
|
|
|
-
|
|
|
- vector<TemplateInfo> fingerCount;//存放CustomerID及其对应指纹个数(非空指纹)
|
|
|
|
|
|
Dbg("begin copy feature to reqParams");
|
|
|
- int i = 0, j = 0;
|
|
|
- int count = 0; //实际不为空的指纹模板总个数
|
|
|
- for (auto it = m_featureData.begin(); it != m_featureData.end(); ++it){
|
|
|
- int countPerCust = 0;//统计每个CustomerID不为空指纹个数
|
|
|
+ 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 < FINGERNUM; ++index){//
|
|
|
- if(index >= it->second->FingerIDArray.GetCount()){//旧版本可能只有2个
|
|
|
+
|
|
|
+ for (int index = 0; index < FINGERNUM; ++index)
|
|
|
+ {
|
|
|
+ if (index >= it->second->FingerIDArray.GetCount()) //旧版本可能只有2个
|
|
|
break;
|
|
|
- }
|
|
|
- if(it->second->FingerIDArray[index].GetLength() <= 0){
|
|
|
+
|
|
|
+ if (it->second->FingerIDArray[index].GetLength() <= 0)
|
|
|
continue;
|
|
|
- }
|
|
|
- tempFeatureArray[count] = it->second->FingerIDArray[index];
|
|
|
- tempFeatureLenArray[count] = it->second->FingerIDLenArray[index];
|
|
|
+
|
|
|
+ tempFeatureArray[matchParam->sTotalNumOfTemplate] = it->second->FingerIDArray[index];
|
|
|
+ tempFeatureLenArray[matchParam->sTotalNumOfTemplate] = it->second->FingerIDLenArray[index];
|
|
|
ti.TemplateNum = ti.TemplateNum + 1;
|
|
|
- ++count;
|
|
|
- }
|
|
|
-
|
|
|
- if(ti.TemplateNum > 0){
|
|
|
- fingerCount.push_back(ti);
|
|
|
+ ++matchParam->sTotalNumOfTemplate;
|
|
|
}
|
|
|
+
|
|
|
+ if (ti.TemplateNum > 0)
|
|
|
+ matchParam->sFingerCount.push_back(ti);
|
|
|
}
|
|
|
LeaveCriticalSection(&m_cs);
|
|
|
- Dbg("num of template not empty:%d", count);
|
|
|
- matchReq.templateNum = count;
|
|
|
- matchReq.templates.Init(count);
|
|
|
- matchReq.templateLen.Init(count);
|
|
|
- for(int i = 0; i < count; ++i){
|
|
|
- matchReq.templates[i] = tempFeatureArray[i];
|
|
|
- matchReq.templateLen[i] = tempFeatureLenArray[i];
|
|
|
+ Dbg("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];
|
|
|
}
|
|
|
|
|
|
Dbg("end copy feature to reqParams");
|
|
|
- Dbg("templateNum: %d", matchReq.templateNum);
|
|
|
+ Dbg("templateNum: %d", matchParam->sMatchReq.templateNum);
|
|
|
|
|
|
- while (true){
|
|
|
- if (m_pFingerPrint == NULL || m_pFingerPrint->QuerySessionClosed()){
|
|
|
+ return Error_Succeed;
|
|
|
+}
|
|
|
+
|
|
|
+ErrorCodeEnum CCustMngrAuthFSM::MatchProcess(MatchParams* matchParam, bool& bStopAuthorize)
|
|
|
+{
|
|
|
+ ErrorCodeEnum errCode = Error_Succeed;
|
|
|
+
|
|
|
+ while (true)
|
|
|
+ {
|
|
|
+ if (m_pFingerPrint == NULL || m_pFingerPrint->QuerySessionClosed())
|
|
|
+ {
|
|
|
Dbg("m_pFingerPrint is NULL or connection closed.");
|
|
|
return Error_Unexpect;
|
|
|
}
|
|
|
+ //fingerprint entity may not return immediately
|
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
|
|
- //Sleep(100);//如果指纹仪返回及时,这里可以考虑去掉
|
|
|
+
|
|
|
Dbg("begin next invoke match.");
|
|
|
- eErr = m_pFingerPrint->Match(matchReq, matchAns, 20000);
|
|
|
+ errCode = m_pFingerPrint->Match(matchParam->sMatchReq, matchParam->sMatchAns, 20000);
|
|
|
|
|
|
- if (m_bCancelAuthorize || eErr == Error_Cancel){
|
|
|
+ if (m_bCancelAuthorize || errCode == Error_Cancel)
|
|
|
+ {
|
|
|
+ Dbg("cancel authorize task.");
|
|
|
bStopAuthorize = true;
|
|
|
- Dbg("m_bCancelAuthorize=true or m_pFingerPrint->Match return Error_Cancel, closing authorization task and setting m_bCancelAuthorize=false");
|
|
|
m_bCancelAuthorize = false;
|
|
|
- if (m_bAuthorizeTimeout){
|
|
|
+ if (m_bAuthorizeTimeout)
|
|
|
+ {
|
|
|
m_bAuthorizeTimeout = false;
|
|
|
return Error_TimeOut;
|
|
|
}
|
|
|
return Error_Cancel;
|
|
|
- }else if (eErr == Error_Unexpect || eErr == Error_TimeOut){//调用指纹仪接口失败,但可以立即进行下一次授权
|
|
|
- Dbg("#################### Invoke Match Error %d ######################", eErr);
|
|
|
- BroadcastGetFinger(2);//调用match出错
|
|
|
- }else if (eErr == Error_Succeed){//指纹仪成功返回匹配结果数组
|
|
|
- Dbg("#################### Match Result Received And Analyzing ######################");
|
|
|
- int resTemplateNum = matchAns.result.GetCount();
|
|
|
- if (resTemplateNum != count){
|
|
|
- Dbg("Ans match result template num is not equale to the Req's ");
|
|
|
- continue;
|
|
|
- }
|
|
|
-
|
|
|
- int matchIndex = -1;//匹配的CustomerID对应的下标
|
|
|
- int matchCount = 0;//匹配的CustomerID个数
|
|
|
- int m = 0;
|
|
|
- int fingerNum = fingerCount[m].TemplateNum;
|
|
|
- for(int i = 0; i < resTemplateNum; i += fingerNum){
|
|
|
- //单人有多指纹匹配不报错(可能多个指纹都用同一个手指注册的)
|
|
|
- //Dbg("i=%d", i);
|
|
|
- int oneCustMatchResult = 0;
|
|
|
- fingerNum = fingerCount[m].TemplateNum;
|
|
|
- for(int j = 0; j < fingerNum; ++j){
|
|
|
- oneCustMatchResult += matchAns.result[i+j];
|
|
|
- }
|
|
|
- //Dbg("oneCustMatcnResult=%d", oneCustMatchResult);
|
|
|
- if(oneCustMatchResult > 0){//同一个CustomerID的指纹如果有多个匹配,算作一个
|
|
|
- matchCount++;
|
|
|
- matchIndex = m;
|
|
|
- }
|
|
|
- if(matchCount > 1){//有多个CustomerID的指纹都匹配上,则是多匹配
|
|
|
- break;
|
|
|
- }
|
|
|
- m++;
|
|
|
- }
|
|
|
- int matchResult = matchCount;//0:no match; 1:just one match; 2: muti match
|
|
|
-
|
|
|
- if (m_bCancelAuthorize){
|
|
|
- bStopAuthorize = true;
|
|
|
- Dbg("m_bCancelAuthorize=true, closing authorization task and setting m_bCancelAuthorize=false");
|
|
|
- m_bCancelAuthorize = false;
|
|
|
- if (m_bAuthorizeTimeout){
|
|
|
- m_bAuthorizeTimeout = false;
|
|
|
- return Error_TimeOut;
|
|
|
- }else
|
|
|
- return Error_Cancel;
|
|
|
- }
|
|
|
- //根据返回匹配结果数组,判断发送指纹授权失败提示广播还是授权结果广播
|
|
|
- switch (matchResult)
|
|
|
- {
|
|
|
- case 0:
|
|
|
- {
|
|
|
- Dbg("MatchResult: 0| no match");
|
|
|
- BroadcastGetFinger(0);
|
|
|
- }
|
|
|
- break;
|
|
|
- case 1:
|
|
|
- {
|
|
|
- Dbg("MatchResult: 1| one and only one match, authorize done.");
|
|
|
- Dbg("Match Finger(CustomerID=%s)", (const char*)fingerCount[matchIndex].CustomerID);
|
|
|
- m_authCtx.eAuthByWhich = AuthByFngPrnt;
|
|
|
- m_authCtx.CustomerID = fingerCount[matchIndex].CustomerID;
|
|
|
- bStopAuthorize = true;
|
|
|
- return Error_Succeed;
|
|
|
- }
|
|
|
- break;
|
|
|
- case 2:
|
|
|
- {
|
|
|
- Dbg("MatchResult: 2| two and more matches. be alerted");
|
|
|
- BroadcastGetFinger(1);
|
|
|
- }
|
|
|
- break;
|
|
|
- default:break;
|
|
|
- }
|
|
|
- }else{//指纹仪match返回其他错误(eg:Error_NotInit,Error_Param),不再调用指纹仪实体的match
|
|
|
- Dbg("Invoke Match Error %d, Stopping FingerPrint-Authorization", eErr);
|
|
|
+ }
|
|
|
+ else if (errCode == Error_Unexpect || errCode == Error_TimeOut)
|
|
|
+ {
|
|
|
+ Dbg("invoke match error with errCode(%s)", SpStrError(errCode));
|
|
|
+ BroadcastGetFinger(2);
|
|
|
+ }
|
|
|
+ else if (errCode == Error_Succeed)
|
|
|
+ {
|
|
|
+ Dbg("invoke match success, start analyze result.");
|
|
|
+ errCode = AnalyzeMatchResult(matchParam, bStopAuthorize);
|
|
|
+ if (errCode == Error_Succeed)
|
|
|
+ return Error_Succeed; //continue if other errCode
|
|
|
+ }else {
|
|
|
+ Dbg("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)
|
|
|
+ {
|
|
|
+ Dbg("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 fingerNum = tmpFingerCountInfo[fingerCountIndex].TemplateNum;
|
|
|
+ for (int i = 0; i < resTemplateNum; i += fingerNum)
|
|
|
+ {
|
|
|
+ int oneCustMatchResult = 0;
|
|
|
+ fingerNum = tmpFingerCountInfo[fingerCountIndex].TemplateNum;
|
|
|
+ for (int j = 0; j < fingerNum; ++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:
|
|
|
+ {
|
|
|
+ Dbg("MatchResult: 0| no match");
|
|
|
+ BroadcastGetFinger(0);
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ case 1:
|
|
|
+ {
|
|
|
+ Dbg("MatchResult: 1| one and only one match, authorize done.");
|
|
|
+ Dbg("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:
|
|
|
+ {
|
|
|
+ Dbg("MatchResult: 2 | two and more matches. be alerted");
|
|
|
+ BroadcastGetFinger(1);
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ default:break;
|
|
|
+ }
|
|
|
+ return Error_Unexpect;
|
|
|
+}
|
|
|
+
|
|
|
+ErrorCodeEnum CCustMngrAuthFSM::MatchFingerPrint(SpReqAnsContext<CustMngrAuthService_StartAuthorize_Req, CustMngrAuthService_StartAuthorize_Ans>::Pointer ctx, bool& bStopAuthorize)
|
|
|
+{
|
|
|
+ LOG_FUNCTION();
|
|
|
+ ErrorCodeEnum errCode = InitBeforeMatch();
|
|
|
+ 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::WaitForUkey(ErrorCodeEnum eErr)
|
|
|
{
|
|
|
int status = (eErr == Error_NoTarget) ? 4: 3;//与朱毅约定,4表示本地无指纹数据,3表示指纹仪实体异常,前端给予提示
|
|
@@ -957,12 +1029,14 @@ void CCustMngrAuthFSM::BroadcastPressFinger(int times, bool bPressFinger)
|
|
|
PressFinger pfEvt;//
|
|
|
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);
|
|
|
+ SpSendBroadcast(m_pEntity->GetFunction(), SP_MSG_OF(PressFinger)
|
|
|
+ , SP_MSG_SIG_OF(PressFinger), pfEvt);
|
|
|
}else{
|
|
|
LiftFinger lfEvt;
|
|
|
lfEvt.FingerNo = 1;
|
|
|
lfEvt.Times = times;
|
|
|
- SpSendBroadcast(m_pEntity->GetFunction(), SP_MSG_OF(LiftFinger), SP_MSG_SIG_OF(LiftFinger), lfEvt);
|
|
|
+ SpSendBroadcast(m_pEntity->GetFunction(), SP_MSG_OF(LiftFinger)
|
|
|
+ , SP_MSG_SIG_OF(LiftFinger), lfEvt);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -970,7 +1044,9 @@ void CCustMngrAuthFSM::BroadcastGetFinger(int status)
|
|
|
{
|
|
|
GetFinger evt;
|
|
|
evt.Status = status;
|
|
|
- SpSendBroadcast(GetEntityBase()->GetFunction(), SP_MSG_OF(GetFinger),SP_MSG_SIG_OF(GetFinger),evt);
|
|
|
+ SpSendBroadcast(GetEntityBase()->GetFunction()
|
|
|
+ , SP_MSG_OF(GetFinger),SP_MSG_SIG_OF(GetFinger)
|
|
|
+ , evt);
|
|
|
}
|
|
|
|
|
|
ErrorCodeEnum CCustMngrAuthFSM::CollectFingerPrint(SpReqAnsContext<CustMngrAuthService_CollectFingerPrint_Req, CustMngrAuthService_CollectFingerPrint_Ans>::Pointer ctx, DWORD& dwUserErrCode)
|
|
@@ -994,10 +1070,8 @@ ErrorCodeEnum CCustMngrAuthFSM::CollectFingerPrint(SpReqAnsContext<CustMngrAuthS
|
|
|
m_pEntity->GetFunction()->GetPath("Dep", strPath);
|
|
|
int getImgNum = 0;
|
|
|
for(int i = 0; i < NUM_COLLECT; ++i){
|
|
|
- if (i) {
|
|
|
+ if (i)
|
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(2000));
|
|
|
- //Sleep(2 * 1000);//internal for 2s between two times(actually finger entity cannot detect finger lift or not)
|
|
|
- }
|
|
|
|
|
|
BroadcastPressFinger(i+1, true);//press finger
|
|
|
|
|
@@ -1119,7 +1193,7 @@ ErrorCodeEnum CCustMngrAuthFSM::SaveFingerPrint(SpReqAnsContext<CustMngrAuthServ
|
|
|
}
|
|
|
|
|
|
Dbg("jsonvalue for fingerinfo created, writing config value......");
|
|
|
- eErr = spConfig->WriteConfigValue(STR_FINGERINFO, (const char*)ctx->Req.CustomerID, writer.write(fingerInfo).c_str());
|
|
|
+ eErr = spConfig->WriteConfigValue((const char*)m_FingerSection, (const char*)ctx->Req.CustomerID, writer.write(fingerInfo).c_str());
|
|
|
Dbg("spConfig->WriteConfigValue done");
|
|
|
if (eErr != Error_Succeed){
|
|
|
Dbg("write data into runinfo failed when commit.");
|
|
@@ -1206,17 +1280,11 @@ int CCustMngrAuthFSM::CompareTime(CSimpleStringA time1, CSimpleStringA time2)
|
|
|
int temp2 = year2 * 10000 + month2 * 100 + day2;
|
|
|
|
|
|
if (temp1 > temp2)
|
|
|
- {
|
|
|
return 1;
|
|
|
- }
|
|
|
else if(temp1 < temp2)
|
|
|
- {
|
|
|
return -1;
|
|
|
- }
|
|
|
else
|
|
|
- {
|
|
|
return 0;
|
|
|
- }
|
|
|
}
|
|
|
return 0;
|
|
|
}
|