Преглед изворни кода

Z991239-6201 #comment feat: 优化指纹文件清理

Signed-Off-By: commit-hook
刘文涛80174520 пре 4 месеци
родитељ
комит
3945fb9a33
2 измењених фајлова са 36 додато и 20 уклоњено
  1. 32 19
      Module/mod_FingerPrint/FingerPrintFSM.cpp
  2. 4 1
      Module/mod_FingerPrint/FingerPrintFSM.h

+ 32 - 19
Module/mod_FingerPrint/FingerPrintFSM.cpp

@@ -68,7 +68,7 @@ unsigned int CFingerPrintFSM::s0_on_event(FSMEvent* e)
 				CancelScanJSEvent* pCSE = dynamic_cast<CancelScanJSEvent*>(e);
 				//清理遗留的指纹文件
 				if (m_fingerPrintFileSet.size() > 0) {
-					DeleteRegisterFingerBmp(m_fingerPrintFileSet);
+					DeleteRegisterFingerBmp();
 				}
 				DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER)("扫描取消成功");
 				pCSE->ctx->Answer(Error_Succeed);
@@ -79,7 +79,7 @@ unsigned int CFingerPrintFSM::s0_on_event(FSMEvent* e)
 				e->SetHandled();
 				//清理遗留的指纹文件
 				if (m_fingerPrintFileSet.size() > 0) {
-					DeleteRegisterFingerBmp(m_fingerPrintFileSet);
+					DeleteRegisterFingerBmp();
 				}
 			}
 			break;
@@ -627,12 +627,12 @@ int CFingerPrintFSM::GetFingerPrintJS(SpReqAnsContext<FingerPrintService_GetFing
 	}
 	else {
 		//临时注册的文件进行缓存
-		m_fingerPrintFileSet.insert(strPath);
+		insertRegisterFingerBmp(strPath);
 	}
 
 	//主动和异常退出清理之前的缓存指纹文件
 	if (m_bCancelScan || bExit) {
-		DeleteRegisterFingerBmp(m_fingerPrintFileSet);
+		DeleteRegisterFingerBmp();
 	}
 
 	delete[] lpbFeature;
@@ -653,14 +653,14 @@ int CFingerPrintFSM::GenerateTemplateJS(SpReqAnsContext<FingerPrintService_Gener
 	if (m_bCancelScan || m_bExit) {		
 		DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_USER).setLogCode(FingerPrint_Generate_Template_ID).setResultCode(getRTACode(FingerPrint_UserErrorCode_CANCEL_GETTEMPLATE))("指纹模版生成失败,已取消");
 		ctx->Answer(Error_Unexpect, FingerPrint_UserErrorCode_CANCEL_GETTEMPLATE);//RTA2427
-		DeleteRegisterFingerBmp(m_fingerPrintFileSet);
+		DeleteRegisterFingerBmp();
 		return 0;
 	}
 
 	if (ctx->Req.fingerSNList.GetCount() != 3) {	
 		DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER).setLogCode(FingerPrint_Generate_Template_ID).setResultCode(getRTACode(FingerPrint_UserErrorCode_GETTEMPLATE_PARAM_FAIL))("指纹模版生成失败,输入参数错误");
 		ctx->Answer(Error_Unexpect, FingerPrint_UserErrorCode_GETTEMPLATE_PARAM_FAIL);//RTA242B
-		DeleteRegisterFingerBmp(m_fingerPrintFileSet);
+		DeleteRegisterFingerBmp();
 		return 0;
 	}
 
@@ -670,17 +670,20 @@ int CFingerPrintFSM::GenerateTemplateJS(SpReqAnsContext<FingerPrintService_Gener
 
 		UpdateAndWarnFileFindInDepBak(tempStr, CSimpleStringA::Format("finger%d.bmp", ctx->Req.fingerSNList[i]), FingerPrint_UserErrorCode_FindFile_in_DepBak);
 
-		imagePaths.push_back(tempStr);
-		DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("<GenerateTemplateJS>,imagePaths[%d]=%s", i, tempStr.GetData());
-		if (!ExistsFileA(imagePaths[i]))
+		if (!ExistsFileA(tempStr.GetData()))
 		{
-			CSimpleStringA errMsg = CSimpleStringA::Format("<GenerateTemplateJS>, image <%s> not exist.", imagePaths[i].GetData());
+			CSimpleStringA errMsg = CSimpleStringA::Format("<GenerateTemplateJS>, image <%s> not exist.", tempStr.GetData());
 			LogWarn(Severity_Middle, Error_Hardware, FingerPrint_UserErrorCode_GETTEMPLATE_NO_FILE, errMsg.GetData());
 			DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_USER).setLogCode(FingerPrint_Generate_Template_ID).setResultCode(getRTACode(FingerPrint_UserErrorCode_GETTEMPLATE_NO_FILE))("指纹模版生成失败,指纹图片不存在");
 			ctx->Answer(Error_Unexpect, FingerPrint_UserErrorCode_GETTEMPLATE_NO_FILE);//RTA242C
-			DeleteRegisterFingerBmp(m_fingerPrintFileSet);
+			DeleteRegisterFingerBmp();
 			return 0;
 		}
+		else {
+			imagePaths.push_back(tempStr);
+			insertRegisterFingerBmp(tempStr);
+			DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("<GenerateTemplateJS>,imagePaths[%d]=%s", i, tempStr.GetData());
+		}
 		
 	}
 	
@@ -715,7 +718,7 @@ int CFingerPrintFSM::GenerateTemplateJS(SpReqAnsContext<FingerPrintService_Gener
 		errCode = Error_Unexpect;
 	}
 
-	DeleteRegisterFingerBmp(m_fingerPrintFileSet);
+	DeleteRegisterFingerBmp();
 
 	if (errCode == Error_Succeed) {
 		ctx->Answer(Error_Succeed);
@@ -1159,34 +1162,44 @@ ErrorCodeEnum CFingerPrintFSM::DeleteFingerBmp(CSimpleStringA imgPath)
 	}
 }
 
-ErrorCodeEnum CFingerPrintFSM::DeleteRegisterFingerBmp(set<CSimpleStringA> imgPathSet)
+ErrorCodeEnum CFingerPrintFSM::DeleteRegisterFingerBmp()
 {
-	DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("execute DeleteRegisterFinger begin,imgPathSet count: %d", imgPathSet.size());
-	auto it = imgPathSet.begin();
-	while (it != imgPathSet.end()) {
+	m_fingerfileMtx.lock();
+	DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("execute DeleteRegisterFinger begin,imgPathSet count: %d", m_fingerPrintFileSet.size());
+	auto it = m_fingerPrintFileSet.begin();
+	while (it != m_fingerPrintFileSet.end()) {
 		CSimpleStringA imgPath = *it;
 		if (ExistsFileA(imgPath))
 		{
 			if (RemoveFileA(imgPath))
 			{
 				DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("DeleteFile(%s) success.", imgPath.GetData());
-				it = imgPathSet.erase(it);
+				it = m_fingerPrintFileSet.erase(it);
 			}
 			else
 			{
 				DbgWithLink(LOG_LEVEL_WARN, LOG_TYPE_SYSTEM)("DeleteFile(%s) failed LastError(%d).", imgPath.GetData(), errno);
+				m_fingerfileMtx.unlock();
 				return Error_Unexpect;
 			}
 		}
 		else {
 			//DbgWithLink(LOG_LEVEL_INFO, LOG_TYPE_SYSTEM)("file %s not exist.", imgPath);
-			it = imgPathSet.erase(it);
+			it = m_fingerPrintFileSet.erase(it);
 		}
 	}
-	DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("execute DeleteRegisterFinger after,imgPathSet count: %d", imgPathSet.size());
+	DbgWithLink(LOG_LEVEL_DEBUG, LOG_TYPE_SYSTEM)("execute DeleteRegisterFinger after,imgPathSet count: %d", m_fingerPrintFileSet.size());
+	m_fingerfileMtx.unlock();
 	return Error_Succeed;
 }
 
+void CFingerPrintFSM::insertRegisterFingerBmp(CSimpleStringA bmpPath)
+{
+	m_fingerfileMtx.lock();
+	m_fingerPrintFileSet.insert(bmpPath);
+	m_fingerfileMtx.unlock();
+}
+
 DWORD CFingerPrintFSM::GetFsmStateErrCode()
 {
 	CSimpleStringA currStateName = GetCurrStateName();

+ 4 - 1
Module/mod_FingerPrint/FingerPrintFSM.h

@@ -6,6 +6,7 @@
 #include "FingerPrintClass.h"
 #include "FingerPrint_UserErrorCode.h"
 #include <set>
+#include <mutex>
 
 #include "CommEntityUtil.hpp"
 
@@ -353,7 +354,8 @@ public:
 
 	ErrorCodeEnum GetImgBlob(CBlob& data, CSimpleStringA imgPath);
 	ErrorCodeEnum DeleteFingerBmp(CSimpleStringA imgPath);
-	ErrorCodeEnum DeleteRegisterFingerBmp(set<CSimpleStringA> imgPathSet);
+	ErrorCodeEnum DeleteRegisterFingerBmp();
+	void insertRegisterFingerBmp(CSimpleStringA bmpPath);
 
 	DWORD GetFsmStateErrCode();
 
@@ -361,6 +363,7 @@ private:
 	bool m_bCancelScan;
 	bool m_bExitMainPage;
 	set<CSimpleStringA> m_fingerPrintFileSet;
+	std::mutex m_fingerfileMtx;          
 };
 
 //废弃