• 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 #ifndef USER_AUTH_CALLBACK_V9_H
17 #define USER_AUTH_CALLBACK_V9_H
18 
19 #include <mutex>
20 
21 #include "nocopyable.h"
22 
23 #include "napi/native_api.h"
24 #include "auth_common.h"
25 #include "user_auth_napi_helper.h"
26 #include "user_auth_client.h"
27 
28 namespace OHOS {
29 namespace UserIam {
30 namespace UserAuth {
31 class UserAuthCallbackV9 : public std::enable_shared_from_this<UserAuthCallbackV9>,
32                            public NoCopyable,
33                            public AuthenticationCallback {
34 public:
35     explicit UserAuthCallbackV9(napi_env env);
36     ~UserAuthCallbackV9() override;
37     void OnAcquireInfo(int32_t module, uint32_t acquireInfo, const Attributes &extraInfo) override;
38     void OnResult(int32_t result, const Attributes &extraInfo) override;
39 
40     napi_status DoResultCallback(int32_t result, const std::vector<uint8_t> &token,
41         std::optional<int32_t> &remainTimes, std::optional<int32_t> &freezingTime);
42     napi_status DoAcquireCallback(int32_t module, uint32_t acquireInfo);
43 
44     void SetResultCallback(const std::shared_ptr<JsRefHolder> &resultCallback);
45     void ClearResultCallback();
46     void SetAcquireCallback(const std::shared_ptr<JsRefHolder> &acquireCallback);
47     void ClearAcquireCallback();
48 
49 private:
50     std::shared_ptr<JsRefHolder> GetResultCallback();
51     std::shared_ptr<JsRefHolder> GetAcquireCallback();
52 
53     napi_env env_ = nullptr;
54     std::mutex mutex_;
55     std::shared_ptr<JsRefHolder> resultCallback_ = nullptr;
56     std::shared_ptr<JsRefHolder> acquireCallback_ = nullptr;
57 };
58 } // namespace UserAuth
59 } // namespace UserIam
60 } // namespace OHOS
61 #endif // USER_AUTH_CALLBACK_V9_H
62