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_V8_H
17 #define USER_AUTH_CALLBACK_V8_H
18 
19 #include "nocopyable.h"
20 
21 #include "auth_common.h"
22 #include "user_auth_napi_helper.h"
23 #include "user_auth_client.h"
24 
25 namespace OHOS {
26 namespace UserIam {
27 namespace UserAuth {
28 class UserAuthCallbackV8 : public std::enable_shared_from_this<UserAuthCallbackV8>,
29                            public NoCopyable,
30                            public AuthenticationCallback {
31 public:
32     UserAuthCallbackV8(napi_env env,
33         const std::shared_ptr<JsRefHolder> &resultCallback, const std::shared_ptr<JsRefHolder> &acquireCallback);
34     ~UserAuthCallbackV8() override;
35     void OnAcquireInfo(int32_t module, uint32_t acquireInfo, const Attributes &extraInfo) override;
36     void OnResult(int32_t result, const Attributes &extraInfo) override;
37 
38     napi_status DoResultCallback(int32_t result, const std::vector<uint8_t> &token,
39         std::optional<int32_t> &remainTimes, std::optional<int32_t> &freezingTime);
40     napi_status DoAcquireCallback(int32_t module, uint32_t acquireInfo);
41 
42 private:
43     napi_env env_ = nullptr;
44     std::shared_ptr<JsRefHolder> resultCallback_ = nullptr;
45     std::shared_ptr<JsRefHolder> acquireCallback_ = nullptr;
46 };
47 } // namespace UserAuth
48 } // namespace UserIam
49 } // namespace OHOS
50 #endif // USER_AUTH_CALLBACK_V8_H
51