|
@@ -1,7 +1,7 @@
|
|
|
#include "CustMngrAuthFSM.h"
|
|
|
#include "CustMngrAuth_UserErrorCode.h"
|
|
|
#include "SpHelper.h"
|
|
|
-#include "path.h"
|
|
|
+#include "fileutil.h"
|
|
|
|
|
|
#include <fstream>
|
|
|
#include <map>
|
|
@@ -330,8 +330,7 @@ ErrorCodeEnum CCustMngrAuthFSM::WaitForUkey(ErrorCodeEnum eErr)
|
|
|
BroadcastGetFinger(status);
|
|
|
while (1)
|
|
|
{
|
|
|
- std::this_thread::sleep_for(std::chrono::milliseconds(300));
|
|
|
- //Sleep(300);
|
|
|
+ SLEEP(300);
|
|
|
if (m_bCancelAuthorize)
|
|
|
{
|
|
|
m_bCancelAuthorize = false;
|
|
@@ -414,15 +413,9 @@ ErrorCodeEnum CCustMngrAuthFSM::OnInit()
|
|
|
|
|
|
int CCustMngrAuthFSM::Initial()
|
|
|
{
|
|
|
- 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");
|
|
|
+ ErrorCodeEnum errCode = OpenRunInfoFile();
|
|
|
+ if (errCode != Error_Succeed)
|
|
|
return 1;
|
|
|
- }
|
|
|
|
|
|
FeatureUpdateTask* pTask = new FeatureUpdateTask(this);
|
|
|
GetEntityBase()->GetFunction()->PostThreadPoolTask(pTask);
|
|
@@ -430,6 +423,22 @@ int CCustMngrAuthFSM::Initial()
|
|
|
return 0;
|
|
|
}
|
|
|
|
|
|
+ErrorCodeEnum CCustMngrAuthFSM::OpenRunInfoFile()
|
|
|
+{
|
|
|
+ ErrorCodeEnum errCode;
|
|
|
+ errCode = GetEntityBase()->GetFunction()->GetPath("RunInfo", m_RunInfoPath);
|
|
|
+ if (errCode != Error_Succeed)
|
|
|
+ {
|
|
|
+ LogError(Severity_High, Error_DevLoadFileFailed
|
|
|
+ , LOG_ERR_CUSTMNGRAUTH_GET_RUNINFO_PATH_FAILED_Init
|
|
|
+ , "get runinfo path failed while init");
|
|
|
+ errCode = Error_Unexpect;
|
|
|
+ }
|
|
|
+ Dbg("runinfo path: %s", m_RunInfoPath.GetData());
|
|
|
+
|
|
|
+ return errCode;
|
|
|
+}
|
|
|
+
|
|
|
#pragma endregion
|
|
|
|
|
|
#pragma region entity exit
|
|
@@ -500,7 +509,7 @@ void CCustMngrAuthFSM::FeatureUpdate()
|
|
|
}
|
|
|
waitInternal = CONNECT_INTERNAL;
|
|
|
}
|
|
|
- } while (0);
|
|
|
+ } while (false);
|
|
|
|
|
|
if (m_pConnection)
|
|
|
{
|
|
@@ -543,15 +552,15 @@ bool CCustMngrAuthFSM::ReadDataIntoMemory(bool& bHasData)
|
|
|
{
|
|
|
LOG_FUNCTION();
|
|
|
|
|
|
- CSimpleStringA runInfoFile = "";
|
|
|
+ CSimpleStringA runInfoFile(true);
|
|
|
runInfoFile = CSimpleStringA::Format("%s" SPLIT_SLASH_STR "runcfg" SPLIT_SLASH_STR RUNINFOFILE
|
|
|
, m_RunInfoPath.GetData());
|
|
|
std::ifstream inFile(runInfoFile.GetData());
|
|
|
string line;
|
|
|
int customerNum = 0;
|
|
|
|
|
|
- clock_t startReadFile = clock();
|
|
|
- clock_t endReadFile = clock();
|
|
|
+ ULLINT startReadFile = RVCGetTickCount();
|
|
|
+ ULLINT endReadFile = RVCGetTickCount();
|
|
|
|
|
|
while (getline(inFile, line))
|
|
|
{
|
|
@@ -607,8 +616,8 @@ bool CCustMngrAuthFSM::ReadDataIntoMemory(bool& bHasData)
|
|
|
|
|
|
Dbg("Total CustomerNum:%d in local file.", customerNum);
|
|
|
|
|
|
- endReadFile = clock();
|
|
|
- DWORD duration = (endReadFile - startReadFile) * 1000 / CLOCKS_PER_SEC;
|
|
|
+ endReadFile = RVCGetTickCount();
|
|
|
+ ULLINT duration = endReadFile - startReadFile;
|
|
|
LogWarn(Severity_High, Error_Debug
|
|
|
, LOG_ERR_CUSTMNGRAUTH_READ_INTO_MEMORY_TIME
|
|
|
, GenerateAlarmJson("CustMngrAuth", duration).GetData());
|
|
@@ -759,9 +768,10 @@ ErrorCodeEnum CCustMngrAuthFSM::ReceiveDataFromServer(CAutoArray<CSimpleStringA>
|
|
|
if (runInfoParam.IsFirstTimeQueryData)
|
|
|
m_pConnection->SendFeatReq(currAgent, branchID);
|
|
|
else
|
|
|
- m_pConnection->SendFeatReq(currAgent, branchID, (const char*)runInfoParam.LatestTime);
|
|
|
-
|
|
|
+ m_pConnection->SendFeatReq(currAgent, branchID, runInfoParam.LatestTime.GetData());
|
|
|
+
|
|
|
ResetEvent(m_pConnection->m_hPkgAnswer);
|
|
|
+
|
|
|
DWORD dw = WaitForSingleObject(m_pConnection->m_hPkgAnswer, 20000); //10->20 20200430@liuwentao
|
|
|
switch (dw)
|
|
|
{
|
|
@@ -822,12 +832,13 @@ ErrorCodeEnum CCustMngrAuthFSM::ReceiveDataFromServer(CAutoArray<CSimpleStringA>
|
|
|
/// <returns></returns>
|
|
|
ErrorCodeEnum CCustMngrAuthFSM::BackupBeforeWriteData(RunInfoParams& runInfoParam, CSmartPointer<IConfigInfo>& spConfig)
|
|
|
{
|
|
|
+ LOG_FUNCTION();
|
|
|
ErrorCodeEnum errCode = Error_Succeed;
|
|
|
|
|
|
runInfoParam.SrcFile = CSimpleStringA::Format("%s" SPLIT_SLASH_STR "runcfg" SPLIT_SLASH_STR RUNINFOFILE
|
|
|
- , (const char*)m_RunInfoPath);
|
|
|
+ , m_RunInfoPath.GetData());
|
|
|
runInfoParam.BackupFile = CSimpleStringA::Format("%s" SPLIT_SLASH_STR "runcfg" SPLIT_SLASH_STR RUNINFOFILE_BAK
|
|
|
- , (const char*)m_RunInfoPath);
|
|
|
+ , m_RunInfoPath.GetData());
|
|
|
|
|
|
EnterCriticalSection(&m_cs);
|
|
|
if (!BackupFile(runInfoParam.SrcFile, runInfoParam.BackupFile))
|
|
@@ -847,9 +858,9 @@ ErrorCodeEnum CCustMngrAuthFSM::BackupBeforeWriteData(RunInfoParams& runInfoPara
|
|
|
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("UpdateTime", "UpdateTime", runInfoParam.CurrentTime.GetData());
|
|
|
+ if (runInfoParam.IsFirstTimeQueryData)
|
|
|
{
|
|
|
spConfig->WriteConfigValue("LatestTime", "LatestTime", "");
|
|
|
}
|
|
@@ -859,17 +870,12 @@ ErrorCodeEnum CCustMngrAuthFSM::BackupBeforeWriteData(RunInfoParams& runInfoPara
|
|
|
bool CCustMngrAuthFSM::BackupFile(CSimpleStringA srcFile, CSimpleStringA dstFile)
|
|
|
{
|
|
|
bool backupResult = true;
|
|
|
- fstream fileExist;
|
|
|
ifstream inFile;
|
|
|
ofstream outFile;
|
|
|
- fileExist.open((const char*)srcFile, ios::in);
|
|
|
|
|
|
- if (!fileExist)
|
|
|
- {
|
|
|
- fileExist.close();
|
|
|
+ if (!ExistsFile(srcFile.GetData()))
|
|
|
return true;
|
|
|
- }
|
|
|
- fileExist.close();
|
|
|
+
|
|
|
inFile.open((const char*)srcFile);
|
|
|
if (inFile.fail())
|
|
|
{
|
|
@@ -923,7 +929,6 @@ ErrorCodeEnum CCustMngrAuthFSM::WriteData(RunInfoParams& runInfoParam
|
|
|
bool bExitLoop = false;
|
|
|
|
|
|
TempFeatureData tmpFeatureData;
|
|
|
- ZeroMemory(&tmpFeatureData, sizeof(tmpFeatureData));
|
|
|
tmpFeatureData.MaxUpdateTime = runInfoParam.LatestTime;
|
|
|
|
|
|
for (int transTime = 0; transTime < dataArray.GetCount(); ++transTime)
|
|
@@ -933,8 +938,7 @@ ErrorCodeEnum CCustMngrAuthFSM::WriteData(RunInfoParams& runInfoParam
|
|
|
|
|
|
//only 3-4 data, cause the limit of transfer amount
|
|
|
CSimpleStringA transBuffer = dataArray[transTime];
|
|
|
-
|
|
|
- if (reader.parse((const char*)transBuffer, root))
|
|
|
+ if (reader.parse(transBuffer.GetData(), root))
|
|
|
{
|
|
|
for (int i = 0; i < (int)root.size(); ++i)
|
|
|
{
|
|
@@ -1021,7 +1025,6 @@ ErrorCodeEnum CCustMngrAuthFSM::ProcessFeatureData(JsonParams& jsonParam, TempFe
|
|
|
tempFD = NULL;
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
CSimpleStringA tempMaxUpdateTime = CSimpleStringA(jsonParam.Root[jsonParam.Index]["updateTime"].asCString());
|
|
|
tmpFeatureData.MaxUpdateTime = GetMaxTime(tmpFeatureData.MaxUpdateTime, tempMaxUpdateTime);
|
|
|
|
|
@@ -1035,7 +1038,7 @@ ErrorCodeEnum CCustMngrAuthFSM::ProcessFeatureData(JsonParams& jsonParam, TempFe
|
|
|
memcpy(jstr, jsonFingerStr.GetData(), jlen);
|
|
|
jstr[jlen] = '\0'; //in case no \n in the end
|
|
|
|
|
|
- errCode = spConfig->WriteConfigValue((const char*)m_FingerSection, customerID.GetData(), jstr);
|
|
|
+ errCode = spConfig->WriteConfigValue(m_FingerSection.GetData(), customerID.GetData(), jstr);
|
|
|
delete[] jstr;
|
|
|
if (errCode != Error_Succeed)
|
|
|
{
|
|
@@ -1164,8 +1167,7 @@ ErrorCodeEnum CCustMngrAuthFSM::CollectProcess(SpReqAnsContext<CustMngrAuthServi
|
|
|
|
|
|
for (int i = 0; i < COLLECT_TIMES; ++i)
|
|
|
{
|
|
|
- if (i)
|
|
|
- std::this_thread::sleep_for(std::chrono::milliseconds(2000));
|
|
|
+ if (i) SLEEP(2000);
|
|
|
|
|
|
if (m_pFingerPrint == NULL || m_pFingerPrint->QuerySessionClosed())
|
|
|
{
|
|
@@ -1186,7 +1188,7 @@ ErrorCodeEnum CCustMngrAuthFSM::CollectProcess(SpReqAnsContext<CustMngrAuthServi
|
|
|
getImgNum += 1;
|
|
|
CBlob data;
|
|
|
imgFullPaths[i] = CSimpleStringA::Format("%s" SPLIT_SLASH_STR "%s"
|
|
|
- , (const char*)depPath, (const char*)collecetAns.imageName);
|
|
|
+ , depPath.GetData(), collecetAns.imageName.GetData());
|
|
|
errCode = GetImgBlob(data, imgFullPaths[i]);
|
|
|
|
|
|
if (errCode != Error_Succeed)
|
|
@@ -1224,10 +1226,8 @@ ErrorCodeEnum CCustMngrAuthFSM::CollectProcess(SpReqAnsContext<CustMngrAuthServi
|
|
|
//delete bmp files in dep
|
|
|
for (int j = 0; j < getImgNum; ++j)
|
|
|
{
|
|
|
- if (remove(imgFullPaths[j].GetData()) == 0)
|
|
|
- Dbg("finger image %s deleted!", imgFullPaths[j].GetData());
|
|
|
- else
|
|
|
- Dbg("fail to delete image %s!", imgFullPaths[j].GetData());
|
|
|
+ if (ExistsFileA(imgFullPaths[j]))
|
|
|
+ RemoveFileA(imgFullPaths[j]);
|
|
|
}
|
|
|
|
|
|
return errCode;
|
|
@@ -1269,7 +1269,7 @@ ErrorCodeEnum CCustMngrAuthFSM::GetImgBlob(CBlob& data, CSimpleStringA imgPath)
|
|
|
return Error_Succeed;
|
|
|
}
|
|
|
else {
|
|
|
- Dbg("fopen %s failed!", (const char*)imgPath);
|
|
|
+ Dbg("fopen %s failed!", imgPath.GetData());
|
|
|
return Error_IO;
|
|
|
}
|
|
|
}
|