• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "face_auth_driver_hdi.h"
17 
18 #include <memory>
19 #include <vector>
20 
21 #include "hdf_base.h"
22 #include "refbase.h"
23 
24 #include "iam_check.h"
25 #include "iam_logger.h"
26 #include "iam_ptr.h"
27 
28 #include "face_auth_defines.h"
29 #include "face_auth_executor_hdi.h"
30 #include "face_auth_interface_adapter.h"
31 #include "v1_0/face_auth_types.h"
32 #include "v1_0/iexecutor.h"
33 #include "v1_0/iface_auth_interface.h"
34 
35 #define LOG_LABEL UserIam::Common::LABEL_FACE_AUTH_SA
36 using namespace OHOS::HDI::FaceAuth::V1_0;
37 
38 namespace OHOS {
39 namespace UserIam {
40 namespace FaceAuth {
41 namespace UserAuth = OHOS::UserIam::UserAuth;
42 using namespace OHOS::UserIam;
43 
44 std::mutex FaceAuthDriverHdi::mutex_;
45 
FaceAuthDriverHdi(const std::shared_ptr<FaceAuthInterfaceAdapter> faceAuthInterfaceAdapter)46 FaceAuthDriverHdi::FaceAuthDriverHdi(const std::shared_ptr<FaceAuthInterfaceAdapter> faceAuthInterfaceAdapter)
47     : faceAuthInterfaceAdapter_(faceAuthInterfaceAdapter)
48 {
49 }
50 
GetExecutorList(std::vector<std::shared_ptr<UserAuth::IAuthExecutorHdi>> & executorList)51 void FaceAuthDriverHdi::GetExecutorList(std::vector<std::shared_ptr<UserAuth::IAuthExecutorHdi>> &executorList)
52 {
53     IF_FALSE_LOGE_AND_RETURN(faceAuthInterfaceAdapter_ != nullptr);
54     auto faceIf = faceAuthInterfaceAdapter_->Get();
55     if (faceIf == nullptr) {
56         IAM_LOGE("IFaceAuthInterface is null");
57         return;
58     }
59 
60     std::vector<sptr<IExecutor>> iExecutorList;
61     auto ret = faceIf->GetExecutorList(iExecutorList);
62     if (ret != HDF_SUCCESS) {
63         IAM_LOGE("GetExecutorList fail");
64         return;
65     }
66 
67     std::lock_guard<std::mutex> gurard(mutex_);
68     faceAuthExecutorList_.clear();
69     for (const auto &iExecutor : iExecutorList) {
70         if (iExecutor == nullptr) {
71             IAM_LOGE("iExecutor is nullptr");
72             continue;
73         }
74         auto executor = Common::MakeShared<FaceAuthExecutorHdi>(iExecutor);
75         if (executor == nullptr) {
76             IAM_LOGE("make share failed");
77             continue;
78         }
79         executorList.push_back(executor);
80         faceAuthExecutorList_.push_back(executor);
81     }
82 }
83 
SetBufferProducer(sptr<IBufferProducer> & producer)84 int32_t FaceAuthDriverHdi::SetBufferProducer(sptr<IBufferProducer> &producer)
85 {
86     if (faceAuthExecutorList_.size() == 0) {
87         IAM_LOGE("no executor to set buffer producer");
88         return FACE_AUTH_ERROR;
89     }
90 
91     std::lock_guard<std::mutex> gurard(mutex_);
92     for (auto executor : faceAuthExecutorList_) {
93         IF_FALSE_LOGE_AND_RETURN_VAL(executor != nullptr, FACE_AUTH_ERROR);
94         int32_t ret = executor->SetBufferProducer(producer);
95         if (ret != FACE_AUTH_SUCCESS) {
96             IAM_LOGE("executor SetBufferProducer fail %{public}d", ret);
97             return FACE_AUTH_ERROR;
98         }
99     }
100     return FACE_AUTH_SUCCESS;
101 }
102 } // namespace FaceAuth
103 } // namespace UserIam
104 } // namespace OHOS
105