From 9666ce027901b98f4d6d63ffb7d3b1cac5075ac5 Mon Sep 17 00:00:00 2001 From: tianshi25 Date: Sat, 29 Jan 2022 02:47:00 +0800 Subject: [PATCH] review Signed-off-by: tianshi25 --- services/faceauth/src/face_auth_executor_callback.cpp | 11 +++++++++++ services/faceauth/src/face_auth_manager.cpp | 10 ++++++++++ services/temp/src/face_auth_ca.cpp | 3 +++ 3 files changed, 24 insertions(+) diff --git a/services/faceauth/src/face_auth_executor_callback.cpp b/services/faceauth/src/face_auth_executor_callback.cpp index fe3dff4..11abceb 100644 --- a/services/faceauth/src/face_auth_executor_callback.cpp +++ b/services/faceauth/src/face_auth_executor_callback.cpp @@ -41,6 +41,7 @@ int32_t ExecutorCallback::OnBeginExecute(uint64_t scheduleId, std::vectorGetUint64Value(AUTH_TEMPLATE_ID, templateId); switch(command) { case FACE_COMMAND_ENROLL: { + // Tianshi: 数据结构 清零 EnrollParam data; data.scheduleID = scheduleId; data.templateID = templateId; @@ -48,6 +49,7 @@ int32_t ExecutorCallback::OnBeginExecute(uint64_t scheduleId, std::vectorCancelEnrollment(data); break; } case FACE_COMMAND_CANCEL_AUTH: { + // Tianshi: 数据结构 清零 AuthParam data; data.scheduleID = scheduleId; manager->CancelAuth(data); break; } default: + // Tianshi: 打印下错误Command的值 FACEAUTH_HILOGI(MODULE_SERVICE, "other command."); break; } @@ -86,10 +91,12 @@ void ExecutorCallback::OnMessengerReady(const sptrSetExecutorMessenger(messenger); } + // Tianshi: 异常流程日志 } int32_t ExecutorCallback::OnSetProperty(pAuthAttributes properties) { + // Tianshi: 下面一行删掉? (void)(properties); FACEAUTH_HILOGI(MODULE_SERVICE, "%{public}s run.", __PRETTY_FUNCTION__); std::shared_ptr manager = FaceAuthManager::GetInstance(); @@ -114,6 +121,7 @@ int32_t ExecutorCallback::OnSetProperty(pAuthAttributes properties) bundleName.assign(callerName.begin(),callerName.end()); switch(command) { case FACE_COMMAND_REMOVE: { + // Tianshi: 数据结构 清零 RemoveParam data; data.scheduleID = scheduleID; data.templateID = templateID; @@ -127,6 +135,7 @@ int32_t ExecutorCallback::OnSetProperty(pAuthAttributes properties) manager->ReleaseAlgorithm(bundleName); break; default: + // Tianshi: 打印下错误Command的值 FACEAUTH_HILOGI(MODULE_SERVICE, "other command."); break; } @@ -135,10 +144,12 @@ int32_t ExecutorCallback::OnSetProperty(pAuthAttributes properties) int32_t ExecutorCallback::OnGetProperty(std::shared_ptr conditions, std::shared_ptr values) { + // Tianshi: 下面两行删掉? (void)(conditions); (void)(values); std::shared_ptr faceAuthCA = FaceAuthCA::GetInstance(); if (faceAuthCA == nullptr) { + // Tianshi: 日志 return FA_RET_ERROR; } uint64_t templateID = 0; diff --git a/services/faceauth/src/face_auth_manager.cpp b/services/faceauth/src/face_auth_manager.cpp index be3f1c0..67c19e2 100755 --- a/services/faceauth/src/face_auth_manager.cpp +++ b/services/faceauth/src/face_auth_manager.cpp @@ -187,6 +187,7 @@ void FaceAuthManager::HandleCallAuthenticate(const AuthParam ¶m) FaceReqType reqType; reqType.reqId = param.scheduleID; reqType.operateType = FACE_OPERATE_TYPE_LOCAL_AUTH; + // Tianshi: 疑似有问题 FaceAuthReq::GetInstance()->RemoveRequireInfo(reqType); //check param if (param.templateID < 0) { @@ -224,6 +225,7 @@ void FaceAuthManager::HandleCallAuthenticate(const AuthParam ¶m) return; } // receive algorithm message and handle algorithm result + // Tianshi: 参考下一期的实现,这里起了thread,能挡住EventHandler调度下一个TASK么 pthread_t threadID; int ret = pthread_create(&threadID, nullptr, OperForAlgorithm, (void*)(&(param.scheduleID))); if (ret != FA_RET_OK) { @@ -306,6 +308,7 @@ void FaceAuthManager::HandleCallEnroll(const EnrollParam ¶m) return; } // receive algorithm message and handle algorithm result + // Tianshi: 参考下一期的实现,这里起了thread,能挡住EventHandler调度下一个TASK么 pthread_t threadID; int ret = pthread_create(&threadID, nullptr, OperForAlgorithm, (void*)(&(param.scheduleID))); if (ret != FA_RET_OK) { @@ -374,6 +377,7 @@ void* FaceAuthManager::OperForAlgorithm(void* arg) uint64_t scheduleID = *(static_cast(arg)); std::shared_ptr faceAuthCA = FaceAuthCA::GetInstance(); if (faceAuthCA == nullptr) { + // Tianshi: 异常流程日志 return nullptr; } int32_t retCode = 0; @@ -413,6 +417,7 @@ void FaceAuthManager::HandleAlgoResult(uint64_t scheduleID) { std::shared_ptr faceAuthCA = FaceAuthCA::GetInstance(); if (faceAuthCA == nullptr) { + // Tianshi: 异常流程日志 return; } AlgorithmResult retResult; @@ -557,6 +562,7 @@ FIRetCode FaceAuthManager::ReleaseAlgorithm(std::string bundleName) FACEAUTH_HILOGE(MODULE_SERVICE,"Release Fail %{public}d", result); return FI_RC_ERROR; } + bool FaceAuthManager::IsAlgorithmInited() { if (bundleNameList_.empty()) { @@ -566,6 +572,7 @@ bool FaceAuthManager::IsAlgorithmInited() FACEAUTH_HILOGI(MODULE_SERVICE,"FaceAuthAlgoDispatcher IsInited bundleNameList_ is not empty,no need init"); return false; } + AlgoResult FaceAuthManager::IsNeedAlgoLoad(std::string bundleName) { FACEAUTH_HILOGI(MODULE_SERVICE,"FaceAuthAlgoDispatcher IsNeedAlgoLoad start"); @@ -592,6 +599,7 @@ AlgoResult FaceAuthManager::IsNeedAlgoLoad(std::string bundleName) AlgoResult FaceAuthManager::IsNeedAlgoRelease(std::string bundleName) { AlgoResult result = AR_SUCCESS; + // Tianshi:一期实现错误?这里应该先-1,减到0erase? if (bundleNameList_.erase(bundleName) != 0) { if (bundleNameList_.empty()) { result = AR_EMPTY; @@ -606,11 +614,13 @@ AlgoResult FaceAuthManager::IsNeedAlgoRelease(std::string bundleName) uint32_t FaceAuthManager::GenerateEventId() { struct timespec t; + // Tianshi: 直接 = {0} ? t.tv_sec = 0; t.tv_nsec = 0; clock_gettime(CLOCK_REALTIME, &t); int64_t elapsedTime { ((t.tv_sec) * SEC_TO_NANOSEC + t.tv_nsec) }; size_t elapsedHash = std::hash()(std::to_string(elapsedTime)); + // Tianshi:安全随机数?明天确认下用途 uint32_t eventId = static_cast(elapsedHash); FACEAUTH_HILOGI(MODULE_SERVICE,"GenerateEventId generate eventId %{public}u", eventId); return eventId; diff --git a/services/temp/src/face_auth_ca.cpp b/services/temp/src/face_auth_ca.cpp index 61705c0..7c9e7ea 100644 --- a/services/temp/src/face_auth_ca.cpp +++ b/services/temp/src/face_auth_ca.cpp @@ -100,15 +100,18 @@ int32_t FaceAuthCA::CancelAlogrithmOperation() { //temp code start void GetAuthResult(int32_t &result) { FILE* pFile = nullptr; + // Tianshi: 只读就可以吧,要a+么 pFile = fopen("/data/useriam/auth_result.txt","a+"); if(pFile == nullptr) { printf("open file failed."); return; } + fseek(pFile,0,SEEK_END); if(0 < ftell(pFile)) { fseek(pFile,0,SEEK_SET); char str[128] = {0}; + // Tianshi: 要保证str以0结尾,读取长度不能和str一致 fread((void*)str,sizeof(char),128,pFile); result = atoi(str); } -- Gitee