|
@@ -16,6 +16,7 @@ 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
|
|
|
+const int COLLECT_TIMES = 3; //press finger times
|
|
|
|
|
|
#define RUNINFOFILE "CustMngrAuth.ini"
|
|
|
#define RUNINFOFILE_BAK "CustMngrAuth_bak.ini"
|
|
@@ -98,14 +99,13 @@ unsigned int CCustMngrAuthFSM::s2_on_event(FSMEvent* pEvt)
|
|
|
AuthorizeStartEvent *authorEvt = dynamic_cast<AuthorizeStartEvent*>(pEvt);
|
|
|
if (authorEvt->ctx->Req.TimeLimit <= 0)
|
|
|
{
|
|
|
- Dbg("ERROR: receive timelimit lessequal than zero. ctx->Answer(error_Param)");
|
|
|
AuthorizeFinishedEvent *e = new AuthorizeFinishedEvent();
|
|
|
e->ctx = authorEvt->ctx;
|
|
|
e->param1 = Error_Param;
|
|
|
this->PostEventFIFO(e);
|
|
|
break;
|
|
|
}
|
|
|
- //状态机流程会耗一些时间,这里要比前端传过来的时间小一些,及时返回给前端
|
|
|
+ //time here should be less than the web
|
|
|
m_TimeLimit = (authorEvt->ctx->Req.TimeLimit - 3) * 1000;
|
|
|
m_bCancelAuthorize = false;
|
|
|
|
|
@@ -117,7 +117,6 @@ unsigned int CCustMngrAuthFSM::s2_on_event(FSMEvent* pEvt)
|
|
|
m_ctx = authorEvt->ctx;
|
|
|
}
|
|
|
|
|
|
- //起指纹匹配线程
|
|
|
MatchFingerPrintTask *matchTask = new MatchFingerPrintTask(this);
|
|
|
matchTask->ctx = authorEvt->ctx;
|
|
|
GetEntityBase()->GetFunction()->PostThreadPoolTask(matchTask);
|
|
@@ -204,7 +203,7 @@ unsigned int CCustMngrAuthFSM::s3_on_event(FSMEvent* pEvt)
|
|
|
Dbg("Checking m_authCtx and answer ctx");
|
|
|
if(m_csMachineType.Compare("RVC.PAD", true))
|
|
|
{
|
|
|
- //非PAD才去关闭U口
|
|
|
+ //close usb when device is not pad
|
|
|
SwitchUSB(false);
|
|
|
}
|
|
|
if (authorEvt->param1 == 0)
|
|
@@ -369,10 +368,7 @@ string CCustMngrAuthFSM::ClearStringSpaceHeadTail(string& line)
|
|
|
bool CCustMngrAuthFSM::ReadDataIntoMemory(bool& bHasData)
|
|
|
{
|
|
|
LOG_FUNCTION();
|
|
|
- CSmartPointer<IConfigInfo> spConfig;
|
|
|
- ErrorCodeEnum eErr;
|
|
|
|
|
|
- CSimpleStringA strPath;
|
|
|
CSimpleStringA runInfoFile;
|
|
|
runInfoFile = CSimpleStringA::Format("%s" SPLIT_SLASH_STR "runcfg" SPLIT_SLASH_STR RUNINFOFILE
|
|
|
, (const char*)m_RunInfoPath);
|
|
@@ -392,7 +388,8 @@ bool CCustMngrAuthFSM::ReadDataIntoMemory(bool& bHasData)
|
|
|
if(!tempLine.compare("[UpdateTime]") || string::npos != tempLine.find("UpdateTime")
|
|
|
|| !tempLine.compare("[LatestTime]") || string::npos != tempLine.find("LatestTime")
|
|
|
|| !tempLine.compare("[FingerInfo]") || !tempLine.compare("[FaceInfo]")
|
|
|
- || string::npos != tempLine.find("FaceInfo1") || string::npos != tempLine.find("FaceInfo2")){
|
|
|
+ || string::npos != tempLine.find("FaceInfo1") || string::npos != tempLine.find("FaceInfo2"))
|
|
|
+ {
|
|
|
continue;
|
|
|
}
|
|
|
string::size_type pos = tempLine.find("=");
|
|
@@ -446,22 +443,22 @@ bool CCustMngrAuthFSM::ReadDataIntoMemory(bool& bHasData)
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
-void CCustMngrAuthFSM::TransDataFromServer(CAutoArray<CSimpleStringA> &dataArray
|
|
|
- , CSimpleStringA latestTime
|
|
|
- , bool& bResumeTrans
|
|
|
- , bool bIsFirstTimeQueryData)
|
|
|
+ErrorCodeEnum CCustMngrAuthFSM::ReceiveDataFromServer(CAutoArray<CSimpleStringA> &dataArray, RunInfoParams runInfoParam)
|
|
|
{
|
|
|
LOG_FUNCTION();
|
|
|
- int transTime = 0;
|
|
|
- char currAgent[16]="";
|
|
|
- char branchID[16]="";
|
|
|
+ char currAgent[16];
|
|
|
+ char branchID[16];
|
|
|
+ memset(currAgent, 0, sizeof(currAgent));
|
|
|
+ memset(branchID, 0, sizeof(currAgent));
|
|
|
+ bool bResumeTrans = true;
|
|
|
+ ErrorCodeEnum errCode = Error_Unexpect;
|
|
|
+
|
|
|
while(bResumeTrans)
|
|
|
{
|
|
|
- transTime++;
|
|
|
- if (bIsFirstTimeQueryData)
|
|
|
+ if (runInfoParam.IsFirstTimeQueryData)
|
|
|
m_pConnection->SendFeatReq(currAgent, branchID);
|
|
|
else
|
|
|
- m_pConnection->SendFeatReq(currAgent, branchID, (const char*)latestTime);
|
|
|
+ m_pConnection->SendFeatReq(currAgent, branchID, (const char*)runInfoParam.LatestTime);
|
|
|
|
|
|
ResetEvent(m_pConnection->m_hPkgAnswer);
|
|
|
DWORD dw = WaitForSingleObject(m_pConnection->m_hPkgAnswer, 20000); //10->20 20200430@liuwentao
|
|
@@ -477,33 +474,42 @@ void CCustMngrAuthFSM::TransDataFromServer(CAutoArray<CSimpleStringA> &dataArray
|
|
|
break;
|
|
|
}
|
|
|
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->m_GetErrMsg)
|
|
|
- {
|
|
|
- Dbg("get error message, check dbg log");
|
|
|
- break;
|
|
|
- }
|
|
|
- if (m_pConnection->m_reply->ResultCode == 2)
|
|
|
+ }
|
|
|
+ if (m_pConnection->m_GetErrMsg)
|
|
|
+ {
|
|
|
+ Dbg("get error message, check dbg log");
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ 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)
|
|
|
{
|
|
|
- Dbg("remote server uninitialized yet, unable to excute query");
|
|
|
- break;
|
|
|
- }else{
|
|
|
- if (m_pConnection->m_reply->ResultCode == 0)
|
|
|
- {
|
|
|
- Dbg("All package downloaded from branch server.");
|
|
|
- bResumeTrans = false;
|
|
|
- }
|
|
|
- memcpy(currAgent, m_pConnection->m_reply->CurrentAgent, 16);
|
|
|
- memcpy(branchID, m_pConnection->m_reply->BranchID, 16);
|
|
|
- CSimpleStringA jbuf(m_pConnection->m_reply->Data, m_pConnection->m_jsonLen);
|
|
|
- dataArray.Append(&jbuf,0,1);
|
|
|
+ Dbg("All package downloaded from branch server.");
|
|
|
+ bResumeTrans = false;
|
|
|
+ errCode = Error_Succeed;
|
|
|
}
|
|
|
+ memcpy(currAgent, m_pConnection->m_reply->CurrentAgent, 16);
|
|
|
+ memcpy(branchID, m_pConnection->m_reply->BranchID, 16);
|
|
|
+ CSimpleStringA jbuf(m_pConnection->m_reply->Data, m_pConnection->m_jsonLen);
|
|
|
+ dataArray.Append(&jbuf, 0, 1);
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ if (bResumeTrans)
|
|
|
+ Dbg("some errors happened, check the related log");
|
|
|
+
|
|
|
+ if (dataArray.GetCount() <= 0)
|
|
|
+ Dbg("query no data from branchServer.");
|
|
|
+
|
|
|
+ return errCode;
|
|
|
}
|
|
|
|
|
|
bool CCustMngrAuthFSM::BackupFile(CSimpleStringA srcFile, CSimpleStringA dstFile)
|
|
@@ -556,205 +562,295 @@ void CCustMngrAuthFSM::InitBeforeUpdateData()
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-void CCustMngrAuthFSM::FeatureUpdate()
|
|
|
+ErrorCodeEnum CCustMngrAuthFSM::LoadRunConfig(CSmartPointer<IConfigInfo>& spConfig)
|
|
|
{
|
|
|
- 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);
|
|
|
- //connect branch server
|
|
|
- if (m_pConnection->ConnectFromCentralSetting() && m_pConnection->IsConnectionOK()){
|
|
|
- connectFailedTimes = 0;
|
|
|
- tWait = UPDATEINTERNAL;
|
|
|
- bool resumeTrans = true;
|
|
|
- bool isFirstTimeQueryData = false;
|
|
|
-
|
|
|
- EnterCriticalSection(&m_cs);//临时锁一下运行时,防止在写入
|
|
|
- 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.");
|
|
|
- LeaveCriticalSection(&m_cs);
|
|
|
- goto Err;
|
|
|
- }
|
|
|
+ ErrorCodeEnum errCode = Error_Succeed;
|
|
|
|
|
|
- CSimpleStringA latestTime(""), updateTime("");//latestTime表示最上一次传来的最新时间,updateTime表示更新日期(是否要做全量清除更新)
|
|
|
- spConfig->ReadConfigValue("LatestTime", "LatestTime", latestTime);
|
|
|
- spConfig->ReadConfigValue("UpdateTime", "UpdateTime", updateTime);
|
|
|
- LeaveCriticalSection(&m_cs);
|
|
|
- //query current time
|
|
|
- CSimpleStringA newTime = GetCurrentDate();
|
|
|
+ errCode = GetEntityBase()->GetFunction()->OpenConfig(Config_Run, spConfig);
|
|
|
|
|
|
- //当前日期大于文件中日期时,需要做全量更新
|
|
|
- if (updateTime.GetLength() <= 0
|
|
|
- || (updateTime.GetLength() > 0 && CompareTime(newTime, updateTime) > 0)
|
|
|
- || latestTime.GetLength() <= 0)
|
|
|
- {
|
|
|
- isFirstTimeQueryData = true;
|
|
|
- }
|
|
|
+ if (errCode != 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.");
|
|
|
+ }
|
|
|
+ return errCode;
|
|
|
+}
|
|
|
|
|
|
- //多次续传从分行服务获取数据(增量更新时,大于latestTime的才传下来)
|
|
|
- TransDataFromServer(transArray, latestTime, resumeTrans, isFirstTimeQueryData);
|
|
|
+void CCustMngrAuthFSM::InitTimeParams(RunInfoParams& runInfoParam, CSmartPointer<IConfigInfo> &spConfig)
|
|
|
+{
|
|
|
+ ErrorCodeEnum errCode = Error_Succeed;
|
|
|
|
|
|
- if(resumeTrans){
|
|
|
- Dbg("ERROR: The last update of feature ended with resumetrans as true, might be timeout or some errors happened");
|
|
|
- goto Err;
|
|
|
- }
|
|
|
- if (transArray.GetCount() <= 0){
|
|
|
- Dbg("query no data from branchServer.(exact no data or the sql was deleted)");
|
|
|
- goto Err;
|
|
|
- }
|
|
|
- //续传成功结束,解析jbuf数组并写入本地
|
|
|
- Dbg("Transmission finished successfully. Ready to decode json data and write into runcfg");
|
|
|
-
|
|
|
- //写入文件前,先判断是否已存在CustMngrAuth.ini文件,若不存在则直接写入,若存在,则先备份该文件
|
|
|
- CSimpleStringA srcFile(true);
|
|
|
- CSimpleStringA backupFile(true);
|
|
|
- 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)
|
|
|
- {
|
|
|
- //首次更新,需清除数据,全量写入,并更新时间
|
|
|
- ofstream fileOut((const char*)srcFile, ios::trunc);
|
|
|
- fileOut.close();
|
|
|
- }
|
|
|
+ runInfoParam.LatestTime = "";
|
|
|
+ runInfoParam.UpdateTime = "";
|
|
|
+ CSimpleStringA latestTime(""), updateTime("");
|
|
|
+ spConfig->ReadConfigValue("LatestTime", "LatestTime", latestTime);
|
|
|
+ spConfig->ReadConfigValue("UpdateTime", "UpdateTime", updateTime);
|
|
|
|
|
|
- eErr = GetEntityBase()->GetFunction()->OpenConfig(Config_Run, spConfig);
|
|
|
- if (eErr != Error_Succeed)
|
|
|
- {
|
|
|
- RecoverFile(srcFile, backupFile);//有失败情况,恢复原文件
|
|
|
- Dbg("ERROR: Open runcfg failed with %s", SpStrError(eErr));
|
|
|
- LeaveCriticalSection(&m_cs);
|
|
|
- goto Err;
|
|
|
- }
|
|
|
+ //query current time
|
|
|
+ CSimpleStringA newTime = GetCurrentDate();
|
|
|
|
|
|
- spConfig->WriteConfigValue("UpdateTime", "UpdateTime", (const char*)newTime);
|
|
|
- if (isFirstTimeQueryData){
|
|
|
- //首次全量更新或存量无LatestTime字段
|
|
|
- spConfig->WriteConfigValue("LatestTime", "LatestTime", "");
|
|
|
- }
|
|
|
- map<CSimpleStringA, FeatureData*> tempFeature;//如果是全量更新,需要更新后全量传给m_featureData
|
|
|
- CSimpleStringA maxUpdateTime = latestTime;
|
|
|
- for(int transTime = 0; transTime < transArray.GetCount(); ++transTime)
|
|
|
- {
|
|
|
- Json::Value root;
|
|
|
- Json::Reader reader;
|
|
|
- Json::FastWriter writer;
|
|
|
- CSimpleStringA transBuffer = transArray[transTime];//一次传输受大小限制,只能有3~4条
|
|
|
- if (reader.parse((const char*)transBuffer, root)){
|
|
|
- for (int i = 0; i < (int)root.size(); ++i){
|
|
|
- Json::Value jsonFingerInfo;
|
|
|
- FeatureData *fd = new FeatureData();
|
|
|
- fd->FingerIDArray.Init(FINGERNUM);
|
|
|
- fd->FingerIDLenArray.Init(FINGERNUM);
|
|
|
- for(int fingerIndex = 0; fingerIndex < FINGERNUM; ++fingerIndex){
|
|
|
- char FingerID[20];//运行时文件是"FingerID"
|
|
|
- char fingerId[20];//分行服务是"fingerId" 二者不一致,历史遗留
|
|
|
+ //当前日期大于文件中日期时,需要做全量更新
|
|
|
+ if (updateTime.GetLength() <= 0
|
|
|
+ || (updateTime.GetLength() > 0 && CompareTime(newTime, updateTime) > 0)
|
|
|
+ || latestTime.GetLength() <= 0)
|
|
|
+ {
|
|
|
+ runInfoParam.IsFirstTimeQueryData = true;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+ErrorCodeEnum CCustMngrAuthFSM::InitBeforeQueryData(RunInfoParams& runInfoParam, CSmartPointer<IConfigInfo>& spConfig)
|
|
|
+{
|
|
|
+ ErrorCodeEnum errCode = Error_Succeed;
|
|
|
+
|
|
|
+ EnterCriticalSection(&m_cs);//临时锁一下运行时,防止在写入
|
|
|
+
|
|
|
+ errCode = LoadRunConfig(spConfig);
|
|
|
+ if (Error_Succeed != errCode)
|
|
|
+ {
|
|
|
+ LeaveCriticalSection(&m_cs);
|
|
|
+ return errCode;
|
|
|
+ }
|
|
|
+
|
|
|
+ InitTimeParams(runInfoParam, spConfig);
|
|
|
+ LeaveCriticalSection(&m_cs);
|
|
|
+
|
|
|
+ return errCode;
|
|
|
+}
|
|
|
+
|
|
|
+ErrorCodeEnum CCustMngrAuthFSM::BackupBeforeWriteData(RunInfoParams& runInfoParam, CSmartPointer<IConfigInfo>& spConfig)
|
|
|
+{
|
|
|
+ ErrorCodeEnum errCode = Error_Succeed;
|
|
|
+
|
|
|
+ runInfoParam.SrcFile = CSimpleStringA::Format("%s" SPLIT_SLASH_STR "runcfg" SPLIT_SLASH_STR RUNINFOFILE
|
|
|
+ , (const char*)m_RunInfoPath);
|
|
|
+ runInfoParam.BackupFile = CSimpleStringA::Format("%s" SPLIT_SLASH_STR "runcfg" SPLIT_SLASH_STR RUNINFOFILE_BAK
|
|
|
+ , (const char*)m_RunInfoPath);
|
|
|
+
|
|
|
+ EnterCriticalSection(&m_cs);
|
|
|
+ if (!BackupFile(runInfoParam.SrcFile, runInfoParam.BackupFile))
|
|
|
+ Dbg("Backup runinfo file failed.");
|
|
|
+
|
|
|
+ if (runInfoParam.IsFirstTimeQueryData)
|
|
|
+ {
|
|
|
+ //首次更新,需清除数据,全量写入,并更新时间
|
|
|
+ ofstream fileOut((const char*)runInfoParam.SrcFile, ios::trunc);
|
|
|
+ fileOut.close();
|
|
|
+ }
|
|
|
+
|
|
|
+ errCode = GetEntityBase()->GetFunction()->OpenConfig(Config_Run, spConfig);
|
|
|
+ if (errCode != Error_Succeed)
|
|
|
+ {
|
|
|
+ Dbg("error: open runcfg failed with errCode(%s)", SpStrError(errCode));
|
|
|
+ RecoverFile(runInfoParam.SrcFile, runInfoParam.BackupFile); // if backup fail, recover
|
|
|
+ LeaveCriticalSection(&m_cs);
|
|
|
+ }
|
|
|
+
|
|
|
+ spConfig->WriteConfigValue("UpdateTime", "UpdateTime", (const char*)runInfoParam.CurrentTime);
|
|
|
+ if (runInfoParam.IsFirstTimeQueryData)
|
|
|
+ {
|
|
|
+ spConfig->WriteConfigValue("LatestTime", "LatestTime", "");
|
|
|
+ }
|
|
|
+ return errCode;
|
|
|
+}
|
|
|
+
|
|
|
+ErrorCodeEnum CCustMngrAuthFSM::ProcessFeatureData(JsonParams& jsonParam, TempFeatureData& tmpFeatureData
|
|
|
+ , RunInfoParams runinfoParam, CSmartPointer<IConfigInfo>& spConfig)
|
|
|
+{
|
|
|
+ ErrorCodeEnum errCode = Error_Succeed;
|
|
|
+ FeatureData* fd = new FeatureData();
|
|
|
+ fd->FingerIDArray.Init(FINGERNUM);
|
|
|
+ fd->FingerIDLenArray.Init(FINGERNUM);
|
|
|
+ char FingerID[20];//runinfo file is named "FingerID"
|
|
|
+ char fingerId[20];//branchserver is named "fingerId" , history bug
|
|
|
+
|
|
|
+ for (int fingerIndex = 0; fingerIndex < FINGERNUM; ++fingerIndex)
|
|
|
+ {
|
|
|
+ ZeroMemory(FingerID, sizeof(FingerID));
|
|
|
+ ZeroMemory(fingerId, sizeof(fingerId));
|
|
|
#ifdef RVC_OS_WIN
|
|
|
- _snprintf_s(FingerID, 10, "FingerID%d", fingerIndex + 1);
|
|
|
- _snprintf_s(fingerId, 10, "fingerId%d", fingerIndex + 1);
|
|
|
+ _snprintf_s(FingerID, 10, "FingerID%d", fingerIndex + 1);
|
|
|
+ _snprintf_s(fingerId, 10, "fingerId%d", fingerIndex + 1);
|
|
|
#else
|
|
|
- snprintf(FingerID, 10, "FingerID%d", fingerIndex + 1);
|
|
|
- snprintf(fingerId, 10, "fingerId%d", fingerIndex + 1);
|
|
|
+ snprintf(FingerID, 10, "FingerID%d", fingerIndex + 1);
|
|
|
+ snprintf(fingerId, 10, "fingerId%d", fingerIndex + 1);
|
|
|
#endif // RVC_OS_WIN
|
|
|
- jsonFingerInfo[FingerID] = root[i][fingerId].asCString();
|
|
|
- fd->FingerIDArray[fingerIndex] = CSimpleStringA(root[i][fingerId].asCString());
|
|
|
- fd->FingerIDLenArray[fingerIndex] = fd->FingerIDArray[fingerIndex].GetLength();
|
|
|
- }
|
|
|
-
|
|
|
- //插入临时map
|
|
|
- if(tempFeature.find(CSimpleStringA(root[i]["customerID"].asCString())) == tempFeature.end()){//不存在,直接插入
|
|
|
- tempFeature[CSimpleStringA(root[i]["customerID"].asCString())] = fd;
|
|
|
- }else{//已存在,需要释放原有内存
|
|
|
- auto tempFD = tempFeature[CSimpleStringA(root[i]["customerID"].asCString())];
|
|
|
- tempFeature[CSimpleStringA(root[i]["customerID"].asCString())] = fd;
|
|
|
- if(tempFD){
|
|
|
- delete tempFD;
|
|
|
- tempFD = NULL;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- CSimpleStringA tempMaxUpdateTime = CSimpleStringA(root[i]["updateTime"].asCString());
|
|
|
- maxUpdateTime = GetMaxTime(maxUpdateTime, tempMaxUpdateTime);
|
|
|
-
|
|
|
- int fingerDataState = root[i]["state"].asCString()[0] - '0';
|
|
|
- if (fingerDataState == 0){
|
|
|
- CSimpleStringA jsonFingerStr(writer.write(jsonFingerInfo).c_str());
|
|
|
- int jlen = jsonFingerStr.GetLength()-1;
|
|
|
- char *jstr = new char[jlen+1];
|
|
|
- memcpy(jstr, jsonFingerStr.GetData(), jlen);
|
|
|
- jstr[jlen]= '\0';
|
|
|
-
|
|
|
- //不做这步处理的话runcfg里faceinfo节不同customerID间没有换行,fingerinfo节本来有,但以防万一也做同样处理。
|
|
|
- eErr = spConfig->WriteConfigValue((const char*)m_FingerSection, root[i]["customerID"].asCString(), jstr);
|
|
|
- delete []jstr;
|
|
|
- if (eErr != Error_Succeed){
|
|
|
- //如果写入失败,则将原文件恢复
|
|
|
- RecoverFile(srcFile, backupFile);
|
|
|
- LeaveCriticalSection(&m_cs);
|
|
|
- goto Err;
|
|
|
- }
|
|
|
- }else if (fingerDataState == 2){
|
|
|
- Dbg("state(2): customer %s is currently unavailable.", 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());
|
|
|
- }
|
|
|
- }
|
|
|
- }else{
|
|
|
- Dbg("ERROR: fail to parse transArray[%d]!", transTime);
|
|
|
- //LogError(Severity_High, Error_Unexpect, LOG_ERR_CUSTMNGRAUTH_FEATUPDATE_WRITE_FAILED, "Failed to write fingerprint feature into runcfg.");
|
|
|
- LeaveCriticalSection(&m_cs);
|
|
|
- goto Err;
|
|
|
+ jsonParam.FingerInfo[FingerID] = jsonParam.Root[jsonParam.Index][fingerId].asCString();
|
|
|
+ fd->FingerIDArray[fingerIndex] = CSimpleStringA(jsonParam.Root[jsonParam.Index][fingerId].asCString());
|
|
|
+ fd->FingerIDLenArray[fingerIndex] = fd->FingerIDArray[fingerIndex].GetLength();
|
|
|
+ }
|
|
|
+
|
|
|
+ CSimpleStringA customerID = CSimpleStringA(jsonParam.Root[jsonParam.Index]["customerID"].asCString());
|
|
|
+ if (tmpFeatureData.tmpFeatureMap.find(customerID) == tmpFeatureData.tmpFeatureMap.end())
|
|
|
+ {
|
|
|
+ // if not exist , insert directly
|
|
|
+ tmpFeatureData.tmpFeatureMap[customerID] = fd;
|
|
|
+ }else {
|
|
|
+ auto tempFD = tmpFeatureData.tmpFeatureMap[customerID];
|
|
|
+ tmpFeatureData.tmpFeatureMap[customerID] = fd;
|
|
|
+ if (tempFD)
|
|
|
+ {
|
|
|
+ delete tempFD;
|
|
|
+ tempFD = NULL;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ CSimpleStringA tempMaxUpdateTime = CSimpleStringA(jsonParam.Root[jsonParam.Index]["updateTime"].asCString());
|
|
|
+ tmpFeatureData.MaxUpdateTime = GetMaxTime(tmpFeatureData.MaxUpdateTime, tempMaxUpdateTime);
|
|
|
+
|
|
|
+ int fingerDataState = jsonParam.Root[jsonParam.Index]["state"].asCString()[0] - '0';
|
|
|
+ if (fingerDataState == 0)
|
|
|
+ {
|
|
|
+ Json::FastWriter writer;
|
|
|
+ CSimpleStringA jsonFingerStr(writer.write(jsonParam.FingerInfo).c_str());
|
|
|
+ int jlen = jsonFingerStr.GetLength() - 1;
|
|
|
+ char* jstr = new char[jlen + 1];
|
|
|
+ memcpy(jstr, jsonFingerStr.GetData(), jlen);
|
|
|
+ jstr[jlen] = '\0';
|
|
|
+
|
|
|
+ //不做这步处理的话runcfg里faceinfo节不同customerID间没有换行,fingerinfo节本来有,但以防万一也做同样处理。
|
|
|
+ errCode = spConfig->WriteConfigValue((const char*)m_FingerSection, customerID.GetData(), jstr);
|
|
|
+ delete[] jstr;
|
|
|
+ if (errCode != Error_Succeed)
|
|
|
+ {
|
|
|
+ //如果写入失败,则将原文件恢复
|
|
|
+ RecoverFile(runinfoParam.SrcFile, runinfoParam.BackupFile);
|
|
|
+ LeaveCriticalSection(&m_cs);
|
|
|
+ errCode = Error_Unexpect;
|
|
|
+ }
|
|
|
+ }else if (fingerDataState == 2)
|
|
|
+ {
|
|
|
+ Dbg("state(2): customer %s is currently unavailable.", customerID.GetData());
|
|
|
+ spConfig->WriteConfigValue((const char*)m_FingerSection, customerID.GetData(), "");
|
|
|
+ }else {
|
|
|
+ Dbg("unexpected customer(%s)'s state is either 0 or 2", customerID.GetData());
|
|
|
+ }
|
|
|
+
|
|
|
+ return errCode;
|
|
|
+}
|
|
|
+
|
|
|
+ErrorCodeEnum CCustMngrAuthFSM::WriteData(RunInfoParams& runInfoParam
|
|
|
+ , CAutoArray<CSimpleStringA>& dataArray
|
|
|
+ , CSmartPointer<IConfigInfo>& spConfig)
|
|
|
+{
|
|
|
+ ErrorCodeEnum errCode = Error_Unexpect;
|
|
|
+ bool bExitLoop = false;
|
|
|
+
|
|
|
+ TempFeatureData tmpFeatureData;
|
|
|
+ ZeroMemory(&tmpFeatureData, sizeof(tmpFeatureData));
|
|
|
+ tmpFeatureData.MaxUpdateTime = runInfoParam.LatestTime;
|
|
|
+
|
|
|
+ for (int transTime = 0; transTime < dataArray.GetCount(); ++transTime)
|
|
|
+ {
|
|
|
+ Json::Value root;
|
|
|
+ Json::Reader reader;
|
|
|
+ CSimpleStringA transBuffer = dataArray[transTime];//一次传输受大小限制,只能有3~4条
|
|
|
+
|
|
|
+ if (reader.parse((const char*)transBuffer, root))
|
|
|
+ {
|
|
|
+ for (int i = 0; i < (int)root.size(); ++i)
|
|
|
+ {
|
|
|
+ JsonParams jsonParam;
|
|
|
+ jsonParam.Root = root;
|
|
|
+ jsonParam.Index = i;
|
|
|
+ errCode = ProcessFeatureData(jsonParam, tmpFeatureData, runInfoParam, spConfig);
|
|
|
+ if (Error_Succeed != errCode)
|
|
|
+ {
|
|
|
+ bExitLoop = true;
|
|
|
+ break;
|
|
|
}
|
|
|
}
|
|
|
- //数据写完,将最新时间更新到本地
|
|
|
- if (maxUpdateTime.GetLength() > 0){
|
|
|
- spConfig->WriteConfigValue("LatestTime", "LatestTime", (const char*)maxUpdateTime);
|
|
|
- }
|
|
|
- Dbg("updateNum=%d", tempFeature.size());
|
|
|
- //更新数据到内存
|
|
|
- UpdateDataIntoMemory(tempFeature, isFirstTimeQueryData);
|
|
|
+ if(bExitLoop)
|
|
|
+ break;
|
|
|
+ }else {
|
|
|
+ Dbg("ERROR: fail to parse transArray[%d]!", transTime);
|
|
|
+ //LogError(Severity_High, Error_Unexpect, LOG_ERR_CUSTMNGRAUTH_FEATUPDATE_WRITE_FAILED, "Failed to write fingerprint feature into runcfg.");
|
|
|
LeaveCriticalSection(&m_cs);
|
|
|
- }else{
|
|
|
- Dbg("ERROR: Fail to connect remote server! Try again in %d mm.", CONNECTINTERNAL);
|
|
|
- connectFailedTimes++;
|
|
|
- Dbg("connect time = %d", connectFailedTimes);
|
|
|
- if(connectFailedTimes >= 60) //如果一直连不上,则30分钟抛一次告警
|
|
|
+ bExitLoop = true;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (bExitLoop)
|
|
|
+ return Error_Unexpect;
|
|
|
+
|
|
|
+ if (tmpFeatureData.MaxUpdateTime.GetLength() > 0)
|
|
|
+ {
|
|
|
+ spConfig->WriteConfigValue("LatestTime", "LatestTime", tmpFeatureData.MaxUpdateTime.GetData());
|
|
|
+ }
|
|
|
+ Dbg("updateNum=%d", tmpFeatureData.tmpFeatureMap.size());
|
|
|
+
|
|
|
+ UpdateDataIntoMemory(tmpFeatureData.tmpFeatureMap, runInfoParam.IsFirstTimeQueryData);
|
|
|
+ LeaveCriticalSection(&m_cs);
|
|
|
+
|
|
|
+ return Error_Succeed;
|
|
|
+}
|
|
|
+
|
|
|
+void CCustMngrAuthFSM::FeatureUpdate()
|
|
|
+{
|
|
|
+ LOG_FUNCTION();
|
|
|
+ InitBeforeUpdateData();
|
|
|
+ int waitInternal = UPDATEINTERNAL;
|
|
|
+
|
|
|
+ while(true)
|
|
|
+ {
|
|
|
+ do
|
|
|
+ {
|
|
|
+ int connectFailedTimes = 0;
|
|
|
+ m_pConnection = new FeatureUpdateConn(m_pEntity, this);
|
|
|
+
|
|
|
+ if (m_pConnection->ConnectFromCentralSetting() && m_pConnection->IsConnectionOK())
|
|
|
{
|
|
|
- LogWarn(Severity_High, Error_Unexpect
|
|
|
- , LOG_ERR_CUSTMNGRAUTH_FEATUPDATE_CONNECT_FAILED
|
|
|
- , "Connect branch server failed.");
|
|
|
connectFailedTimes = 0;
|
|
|
+ waitInternal = UPDATEINTERNAL;
|
|
|
+
|
|
|
+ ErrorCodeEnum errCode;
|
|
|
+ CSmartPointer<IConfigInfo> spConfig;
|
|
|
+ CAutoArray<CSimpleStringA> transArray;
|
|
|
+ RunInfoParams runInfoParam;
|
|
|
+ memset(&runInfoParam, 0, sizeof(runInfoParam));
|
|
|
+
|
|
|
+ errCode = InitBeforeQueryData(runInfoParam, spConfig);
|
|
|
+ if(errCode != Error_Succeed)
|
|
|
+ break;
|
|
|
+
|
|
|
+ errCode = ReceiveDataFromServer(transArray, runInfoParam);
|
|
|
+ if(errCode != Error_Succeed)
|
|
|
+ break;
|
|
|
+
|
|
|
+ errCode = BackupBeforeWriteData(runInfoParam, spConfig);
|
|
|
+ if(errCode != Error_Succeed)
|
|
|
+ break;
|
|
|
+
|
|
|
+ errCode = WriteData(runInfoParam, transArray, spConfig);
|
|
|
+ if(errCode != Error_Succeed)
|
|
|
+ break;
|
|
|
+ }else {
|
|
|
+ connectFailedTimes++;
|
|
|
+ Dbg("connect branchserver failed for %d times, try again in %d ms."
|
|
|
+ , connectFailedTimes, CONNECTINTERNAL);
|
|
|
+
|
|
|
+ if (connectFailedTimes >= 60)
|
|
|
+ {
|
|
|
+ //30min give a warn
|
|
|
+ LogWarn(Severity_High, Error_Unexpect
|
|
|
+ , LOG_ERR_CUSTMNGRAUTH_FEATUPDATE_CONNECT_FAILED
|
|
|
+ , "Connect branch server failed.");
|
|
|
+ connectFailedTimes = 0;
|
|
|
+ }
|
|
|
+ waitInternal = CONNECTINTERNAL;
|
|
|
}
|
|
|
- tWait = CONNECTINTERNAL;
|
|
|
- }
|
|
|
- Err:
|
|
|
- if(m_pConnection){
|
|
|
+ } while (0);
|
|
|
+
|
|
|
+ if(m_pConnection)
|
|
|
+ {
|
|
|
m_pConnection->Close();
|
|
|
m_pConnection->DecRefCount();
|
|
|
m_pConnection = NULL;
|
|
|
}
|
|
|
Dbg("Feature-update processed, wait until next");
|
|
|
- //等待tWait时间后,进行下一次请求更新
|
|
|
- if (WaitForSingleObject(hStopUpdate, tWait) == WAIT_OBJECT_0)
|
|
|
+ //wait for next query
|
|
|
+ if (WaitForSingleObject(hStopUpdate, waitInternal) == WAIT_OBJECT_0)
|
|
|
break;
|
|
|
}
|
|
|
}
|
|
@@ -788,7 +884,7 @@ void CCustMngrAuthFSM::UpdateDataIntoMemory(map<CSimpleStringA, FeatureData*> te
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-ErrorCodeEnum CCustMngrAuthFSM::InitBeforeMatch()
|
|
|
+ErrorCodeEnum CCustMngrAuthFSM::ConnectFingerPrintEntity()
|
|
|
{
|
|
|
ErrorCodeEnum errCode = Error_Succeed;
|
|
|
m_pFingerPrint = new FingerPrintService_ClientBase(m_pEntity);
|
|
@@ -802,7 +898,7 @@ ErrorCodeEnum CCustMngrAuthFSM::InitBeforeMatch()
|
|
|
m_pFingerPrint = NULL;
|
|
|
}
|
|
|
|
|
|
- errCode = Error_Unexpect; //TODO::give one other errCode
|
|
|
+ errCode = Error_NoTarget; //TODO::give one other errCode
|
|
|
}
|
|
|
return errCode;
|
|
|
}
|
|
@@ -984,7 +1080,7 @@ ErrorCodeEnum CCustMngrAuthFSM::AnalyzeMatchResult(MatchParams* matchParam, bool
|
|
|
ErrorCodeEnum CCustMngrAuthFSM::MatchFingerPrint(SpReqAnsContext<CustMngrAuthService_StartAuthorize_Req, CustMngrAuthService_StartAuthorize_Ans>::Pointer ctx, bool& bStopAuthorize)
|
|
|
{
|
|
|
LOG_FUNCTION();
|
|
|
- ErrorCodeEnum errCode = InitBeforeMatch();
|
|
|
+ ErrorCodeEnum errCode = ConnectFingerPrintEntity();
|
|
|
if (errCode != Error_Succeed)
|
|
|
return errCode;
|
|
|
|
|
@@ -1049,54 +1145,51 @@ void CCustMngrAuthFSM::BroadcastGetFinger(int status)
|
|
|
, evt);
|
|
|
}
|
|
|
|
|
|
-ErrorCodeEnum CCustMngrAuthFSM::CollectFingerPrint(SpReqAnsContext<CustMngrAuthService_CollectFingerPrint_Req, CustMngrAuthService_CollectFingerPrint_Ans>::Pointer ctx, DWORD& dwUserErrCode)
|
|
|
+ErrorCodeEnum CCustMngrAuthFSM::CollectProcess(SpReqAnsContext<CustMngrAuthService_CollectFingerPrint_Req, CustMngrAuthService_CollectFingerPrint_Ans>::Pointer &ctx, DWORD& dwUserErrCode)
|
|
|
{
|
|
|
- LOG_FUNCTION();
|
|
|
- ErrorCodeEnum eErr;
|
|
|
- m_pFingerPrint = new FingerPrintService_ClientBase(GetEntityBase());
|
|
|
- eErr = m_pFingerPrint->Connect();
|
|
|
- if (eErr!= Error_Succeed)
|
|
|
- {
|
|
|
- m_pFingerPrint->SafeDelete();
|
|
|
- m_pFingerPrint = NULL;
|
|
|
- return Error_NoTarget;
|
|
|
- }
|
|
|
- //need to collect for 3 times
|
|
|
- const int NUM_COLLECT = 3;
|
|
|
- ctx->Ans.FingerImgs.Init(NUM_COLLECT);
|
|
|
- CAutoArray<CSimpleStringA> imgPaths;
|
|
|
- CSimpleStringA strPath;
|
|
|
- imgPaths.Init(NUM_COLLECT);
|
|
|
- m_pEntity->GetFunction()->GetPath("Dep", strPath);
|
|
|
+ ErrorCodeEnum errCode = Error_Succeed;
|
|
|
+
|
|
|
+ CAutoArray<CSimpleStringA> imgFullPaths;
|
|
|
+ imgFullPaths.Init(COLLECT_TIMES);
|
|
|
+ ctx->Ans.FingerImgs.Init(COLLECT_TIMES);
|
|
|
+ CSimpleStringA depPath;
|
|
|
+ m_pEntity->GetFunction()->GetPath("Dep", depPath);
|
|
|
int getImgNum = 0;
|
|
|
- for(int i = 0; i < NUM_COLLECT; ++i){
|
|
|
+
|
|
|
+ for (int i = 0; i < COLLECT_TIMES; ++i)
|
|
|
+ {
|
|
|
if (i)
|
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(2000));
|
|
|
|
|
|
- BroadcastPressFinger(i+1, true);//press finger
|
|
|
-
|
|
|
- FingerPrintService_GetImageAndFeature_Req gifReq;
|
|
|
- FingerPrintService_GetImageAndFeature_Ans gifAns;
|
|
|
- gifReq.times = i+1;//the num from 1 start , 1/2/3
|
|
|
-
|
|
|
- if (m_pFingerPrint == NULL || m_pFingerPrint->QuerySessionClosed()){
|
|
|
+ if (m_pFingerPrint == NULL || m_pFingerPrint->QuerySessionClosed())
|
|
|
+ {
|
|
|
Dbg("m_pFingerPrint is NULL or connection closed.");
|
|
|
- return Error_NoTarget;
|
|
|
+ return errCode;
|
|
|
}
|
|
|
- eErr = m_pFingerPrint->GetImageAndFeature(gifReq, gifAns, 16000, dwUserErrCode);//fingerprint entity loop duration is 15s
|
|
|
- if (eErr == Error_Succeed){
|
|
|
+
|
|
|
+ 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->GetImageAndFeature(collecetReq, collecetAns, 16000, dwUserErrCode);//fingerprint entity loop duration is 15s
|
|
|
+ if (errCode == Error_Succeed)
|
|
|
+ {
|
|
|
+ BroadcastPressFinger(i + 1, false);//lift finger
|
|
|
+
|
|
|
getImgNum += 1;
|
|
|
- BroadcastPressFinger(i+1, false);//lift finger
|
|
|
CBlob data;
|
|
|
- CSimpleStringA tempFullPath;
|
|
|
- tempFullPath = CSimpleStringA::Format("%s" SPLIT_SLASH_STR "%s"
|
|
|
- , (const char*)strPath, (const char*)gifAns.imageName);
|
|
|
- eErr = GetImgBlob(data, tempFullPath);
|
|
|
- if (eErr != Error_Succeed){
|
|
|
+ imgFullPaths[i] = CSimpleStringA::Format("%s" SPLIT_SLASH_STR "%s"
|
|
|
+ , (const char*)depPath, (const char*)collecetAns.imageName);
|
|
|
+ errCode = GetImgBlob(data, imgFullPaths[i]);
|
|
|
+
|
|
|
+ if (errCode != Error_Succeed)
|
|
|
+ {
|
|
|
Dbg("Failed to load finger image.");
|
|
|
+ errCode = Error_Unexpect;
|
|
|
break;
|
|
|
}
|
|
|
- switch(i)
|
|
|
+ switch (i)
|
|
|
{
|
|
|
case 0:
|
|
|
ctx->Ans.FingerImg1 = data;
|
|
@@ -1109,39 +1202,48 @@ ErrorCodeEnum CCustMngrAuthFSM::CollectFingerPrint(SpReqAnsContext<CustMngrAuthS
|
|
|
break;
|
|
|
}
|
|
|
ctx->Ans.FingerImgs[i] = data;
|
|
|
- imgPaths[i] = gifAns.imageName;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- Dbg("failed to collect fingerprint %th times, also failed to generate template failed.");
|
|
|
+ Dbg("invoke GetImageAndFeature failed in %dth time, errCode(%s)", i + 1, SpStrError(errCode));
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
//third times, get th template success
|
|
|
- if (i == (NUM_COLLECT-1)){
|
|
|
- ctx->Ans.feature = gifAns.feature;
|
|
|
+ if (i == (COLLECT_TIMES - 1))
|
|
|
+ {
|
|
|
+ ctx->Ans.feature = collecetAns.feature;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
//delete bmp files in dep
|
|
|
for (int j = 0; j < getImgNum; ++j)
|
|
|
{
|
|
|
- CSimpleStringA tempFullPath(true);
|
|
|
- tempFullPath = CSimpleStringA::Format("%s" SPLIT_SLASH_STR "%s"
|
|
|
- , (const char*)strPath, (const char*)imgPaths[j]);
|
|
|
-
|
|
|
- if(remove((const char*)tempFullPath) == 0)
|
|
|
- Dbg("finger image %s deleted!", (const char*)tempFullPath);
|
|
|
+ if (remove(imgFullPaths[j].GetData()) == 0)
|
|
|
+ Dbg("finger image %s deleted!", imgFullPaths[j].GetData());
|
|
|
else
|
|
|
- Dbg("fail to delete image %s!", (const char*)tempFullPath);
|
|
|
+ Dbg("fail to delete image %s!", imgFullPaths[j].GetData());
|
|
|
}
|
|
|
+
|
|
|
+ return errCode;
|
|
|
+}
|
|
|
+
|
|
|
+ErrorCodeEnum CCustMngrAuthFSM::CollectFingerPrint(SpReqAnsContext<CustMngrAuthService_CollectFingerPrint_Req, CustMngrAuthService_CollectFingerPrint_Ans>::Pointer ctx, DWORD& dwUserErrCode)
|
|
|
+{
|
|
|
+ LOG_FUNCTION();
|
|
|
+ ErrorCodeEnum errCode = ConnectFingerPrintEntity();
|
|
|
+ if (errCode != Error_Succeed)
|
|
|
+ return errCode;
|
|
|
+
|
|
|
+ errCode = CollectProcess(ctx, dwUserErrCode);
|
|
|
|
|
|
- if (eErr == Error_Succeed){
|
|
|
+ if (errCode == Error_Succeed)
|
|
|
+ {
|
|
|
Dbg("Register FingerPrint successfully.");
|
|
|
return Error_Succeed;
|
|
|
}else{
|
|
|
Dbg("Register FingerPrint failed!");
|
|
|
- return Error_Unexpect;
|
|
|
+ return errCode;
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -1151,37 +1253,43 @@ ErrorCodeEnum CCustMngrAuthFSM::SaveFingerPrint(SpReqAnsContext<CustMngrAuthServ
|
|
|
EnterCriticalSection(&m_cs);
|
|
|
CSmartPointer<IConfigInfo> spConfig;
|
|
|
Json::FastWriter writer;
|
|
|
- ErrorCodeEnum eErr;
|
|
|
- eErr = GetEntityBase()->GetFunction()->OpenConfig(Config_Run, spConfig);
|
|
|
- if (eErr != Error_Succeed){
|
|
|
- Dbg("ERROR: open config failed! eErr: %d", eErr);
|
|
|
- LogError(Severity_High, Error_DevLoadFileFailed, LOG_ERR_CUSTMNGRAUTH_OPEN_RUNINFO_FAILED_SAVEFINGERPRINT, "open runinfo file failed while save data to local.");
|
|
|
+ ErrorCodeEnum errCode;
|
|
|
+ errCode = GetEntityBase()->GetFunction()->OpenConfig(Config_Run, spConfig);
|
|
|
+ if (errCode != 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;
|
|
|
}
|
|
|
- Dbg("open Config_Run succeed, prepare to write feature data.");
|
|
|
- Json::Value fingerInfo;
|
|
|
-
|
|
|
+
|
|
|
int fingerIDNum = ctx->Req.FingerIdList.GetCount();
|
|
|
- FeatureData *fd = new FeatureData();
|
|
|
Dbg("FingerIDNum=%d", fingerIDNum);
|
|
|
+ FeatureData *fd = new FeatureData();
|
|
|
fd->FingerIDArray.Init(fingerIDNum);
|
|
|
fd->FingerIDLenArray.Init(fingerIDNum);
|
|
|
- for (int i = 0; i < fingerIDNum; ++i){
|
|
|
- char a[20]={0};
|
|
|
+ char fingerID[20];
|
|
|
+ Json::Value fingerInfo;
|
|
|
+
|
|
|
+ for (int i = 0; i < fingerIDNum; ++i)
|
|
|
+ {
|
|
|
+ memset(fingerID, 0, sizeof(fingerID));
|
|
|
|
|
|
#ifdef RVC_OS_WIN
|
|
|
- _snprintf_s(a, 10, "FingerID%d", ctx->Req.FingerIdList[i]);
|
|
|
+ _snprintf_s(fingerID, 10, "FingerID%d", ctx->Req.FingerIdList[i]);
|
|
|
#else
|
|
|
- snprintf(a, 10, "FingerID%d", ctx->Req.FingerIdList[i]);
|
|
|
+ snprintf(fingerID, 10, "FingerID%d", ctx->Req.FingerIdList[i]);
|
|
|
#endif // RVC_OS_WIN
|
|
|
|
|
|
- Dbg("writing %s",a);
|
|
|
- fingerInfo[a] = (const char*)ctx->Req.FPFeatureList[i];
|
|
|
+ Dbg("writing %s", fingerID);
|
|
|
+ fingerInfo[fingerID] = (const char*)ctx->Req.FPFeatureList[i];
|
|
|
fd->FingerIDArray[i] = ctx->Req.FPFeatureList[i];
|
|
|
fd->FingerIDLenArray[i] = fd->FingerIDArray[i].GetLength();
|
|
|
}
|
|
|
- if(m_featureData.find(ctx->Req.CustomerID) == m_featureData.end()){//不存在,直接插入
|
|
|
+
|
|
|
+ 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];
|
|
@@ -1192,31 +1300,36 @@ ErrorCodeEnum CCustMngrAuthFSM::SaveFingerPrint(SpReqAnsContext<CustMngrAuthServ
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- Dbg("jsonvalue for fingerinfo created, writing config value......");
|
|
|
- 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.");
|
|
|
- LogError(Severity_High, Error_DevLoadFileFailed, LOG_ERR_CUSTMNGRAUTH_REGISTER_WRITE_RUNINFO_FAILED, "write data into runinfo failed when commit.");
|
|
|
+ errCode = spConfig->WriteConfigValue((const char*)m_FingerSection
|
|
|
+ , (const char*)ctx->Req.CustomerID
|
|
|
+ , writer.write(fingerInfo).c_str());
|
|
|
+ if (errCode != 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;
|
|
|
}
|
|
|
Dbg("write data into runinfo success when commit.");
|
|
|
LeaveCriticalSection(&m_cs);
|
|
|
- return eErr;
|
|
|
+ return errCode;
|
|
|
}
|
|
|
|
|
|
ErrorCodeEnum CCustMngrAuthFSM::SwitchUSB(bool bOpen)
|
|
|
{
|
|
|
LOG_FUNCTION();
|
|
|
- ErrorCodeEnum eErr;
|
|
|
- //connect devicecontrol and open usb
|
|
|
+
|
|
|
Dbg("connecting DeviceControl");
|
|
|
+ ErrorCodeEnum errCode;
|
|
|
m_pDeviceControl = new DeviceControlService_ClientBase(GetEntityBase());
|
|
|
- if(m_pDeviceControl != NULL){
|
|
|
- eErr = m_pDeviceControl->Connect();
|
|
|
- if (eErr != Error_Succeed){
|
|
|
- Dbg("m_pDeviceControl connect failed with eErr %x0x", eErr);
|
|
|
+
|
|
|
+ if(m_pDeviceControl != NULL)
|
|
|
+ {
|
|
|
+ errCode = m_pDeviceControl->Connect();
|
|
|
+ if (errCode != Error_Succeed)
|
|
|
+ {
|
|
|
+ Dbg("m_pDeviceControl connect failed with errCode(%s)", SpStrError(errCode));
|
|
|
}else{
|
|
|
if(bOpen)
|
|
|
Dbg("Open USB");
|
|
@@ -1225,8 +1338,8 @@ ErrorCodeEnum CCustMngrAuthFSM::SwitchUSB(bool bOpen)
|
|
|
DeviceControlService_USB_Req usbReq;
|
|
|
DeviceControlService_USB_Ans usbAns;
|
|
|
usbReq.open = bOpen;//open or close usb
|
|
|
- eErr = m_pDeviceControl->USB(usbReq, usbAns, 2000);
|
|
|
- if (eErr != Error_Succeed)
|
|
|
+ errCode = m_pDeviceControl->USB(usbReq, usbAns, 2000);
|
|
|
+ if (errCode != Error_Succeed)
|
|
|
Dbg("Open/Close usb failed.");
|
|
|
else
|
|
|
Dbg("Open/Close usb success.");
|
|
@@ -1234,7 +1347,7 @@ ErrorCodeEnum CCustMngrAuthFSM::SwitchUSB(bool bOpen)
|
|
|
}
|
|
|
m_pDeviceControl->SafeDelete();
|
|
|
m_pDeviceControl = NULL;
|
|
|
- return eErr;
|
|
|
+ return errCode;
|
|
|
}else{
|
|
|
Dbg("DeviceControl is null.");
|
|
|
return Error_Unexpect;
|
|
@@ -1243,10 +1356,11 @@ ErrorCodeEnum CCustMngrAuthFSM::SwitchUSB(bool bOpen)
|
|
|
|
|
|
ErrorCodeEnum CCustMngrAuthFSM::GetImgBlob(CBlob &data, CSimpleStringA imgPath)
|
|
|
{
|
|
|
- Dbg("########Openning imgpath: %s", (const char*)imgPath);
|
|
|
- ErrorCodeEnum eErr;
|
|
|
+ Dbg("image full path: %s", (const char*)imgPath);
|
|
|
+
|
|
|
FILE* fp = fopen(imgPath, "rb");
|
|
|
- if (fp) {
|
|
|
+ if (fp)
|
|
|
+ {
|
|
|
Dbg("fopen succeed.");
|
|
|
fseek(fp, 0, SEEK_END);
|
|
|
long flen = ftell(fp);
|
|
@@ -1254,18 +1368,17 @@ ErrorCodeEnum CCustMngrAuthFSM::GetImgBlob(CBlob &data, CSimpleStringA imgPath)
|
|
|
data.Alloc(flen);
|
|
|
fread(data.m_pData, 1, flen, fp);
|
|
|
fclose(fp);
|
|
|
- eErr = Error_Succeed;
|
|
|
+ return Error_Succeed;
|
|
|
}
|
|
|
else {
|
|
|
- Dbg("fopen %s failed!", (LPCSTR)imgPath);
|
|
|
- eErr = Error_IO;
|
|
|
+ Dbg("fopen %s failed!", (const char*)imgPath);
|
|
|
+ return Error_IO;
|
|
|
}
|
|
|
- return eErr;
|
|
|
}
|
|
|
|
|
|
+//compare if the same day
|
|
|
int CCustMngrAuthFSM::CompareTime(CSimpleStringA time1, CSimpleStringA time2)
|
|
|
{
|
|
|
- //这里只比较是否是同一天
|
|
|
if (time1.GetLength() > 0 && time2.GetLength() > 0)
|
|
|
{
|
|
|
int year1 = atoi((const char*)time1.SubString(0, 4));
|
|
@@ -1324,14 +1437,17 @@ CSimpleStringA CCustMngrAuthFSM::GetCurrentDate()
|
|
|
|
|
|
CSimpleStringA CCustMngrAuthFSM::GetMaxTime(CSimpleStringA maxTime, CSimpleStringA tempTime)
|
|
|
{
|
|
|
- if (tempTime.GetLength() > 0){
|
|
|
- if (maxTime.GetLength() <= 0){
|
|
|
+ if (tempTime.GetLength() <= 0)
|
|
|
+ return maxTime;
|
|
|
+
|
|
|
+ if (maxTime.GetLength() <= 0)
|
|
|
+ {
|
|
|
+ maxTime = tempTime;
|
|
|
+ }else {
|
|
|
+ int compareResult = CompareUpdateTime((const char*)maxTime, (const char*)tempTime);
|
|
|
+ if (compareResult == 0)
|
|
|
+ {
|
|
|
maxTime = tempTime;
|
|
|
- }else{
|
|
|
- int compareResult = CompareUpdateTime((const char*)maxTime, (const char*)tempTime);
|
|
|
- if (compareResult == 0){
|
|
|
- maxTime = tempTime;
|
|
|
- }
|
|
|
}
|
|
|
}
|
|
|
return maxTime;
|