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 FACERECOGNITION_USER_AUTH_H 17 #define FACERECOGNITION_USER_AUTH_H 18 19 #include "napi/native_common.h" 20 #include "auth_build.h" 21 #include "auth_common.h" 22 23 namespace OHOS { 24 namespace UserIAM { 25 namespace UserAuth { 26 typedef struct AsyncHolder { AsyncHolderAsyncHolder27 AsyncHolder() : data(nullptr), asyncWork(nullptr) {}; 28 void *data; 29 napi_async_work asyncWork; 30 } AsyncHolder; 31 32 class UserAuthImpl { 33 public: 34 UserAuthImpl(); 35 ~UserAuthImpl(); 36 AuthBuild authBuild; 37 napi_value GetVersion(napi_env env, napi_callback_info info); 38 napi_value GetAvailableStatus(napi_env env, napi_callback_info info); 39 napi_value GetProperty(napi_env env, napi_callback_info info); 40 napi_value SetProperty(napi_env env, napi_callback_info info); 41 napi_value Auth(napi_env env, napi_callback_info info); 42 napi_value Execute(napi_env env, napi_callback_info info); 43 napi_value AuthUser(napi_env env, napi_callback_info info); 44 napi_value CancelAuth(napi_env env, napi_callback_info info); 45 46 private: 47 napi_value GetPropertyWrap(napi_env env, napi_callback_info info, AsyncHolder *asyncHolder); 48 napi_value GetPropertyAsync(napi_env env, AsyncHolder *asyncHolder); 49 napi_value GetPropertyPromise(napi_env env, AsyncHolder *asyncHolder); 50 51 napi_value SetPropertyWrap(napi_env env, napi_callback_info info, AsyncHolder *asyncHolder); 52 napi_value SetPropertyAsync(napi_env env, AsyncHolder *asyncHolder); 53 napi_value SetPropertyPromise(napi_env env, AsyncHolder *asyncHolder); 54 55 napi_value AuthWrap(napi_env env, AuthInfo *authInfo); 56 napi_value BuildAuthInfo(napi_env env, AuthInfo *authInfo); 57 napi_value AuthUserWrap(napi_env env, AuthUserInfo *userInfo); 58 napi_value BuildAuthUserInfo(napi_env env, AuthUserInfo *userInfo); 59 60 ResultCode ParseExecuteParametersOne(napi_env env, size_t argc, napi_value *argv, ExecuteInfo &executeInfo); 61 ResultCode ParseExecuteParametersZero(napi_env env, size_t argc, napi_value *argv, ExecuteInfo &executeInfo); 62 ResultCode ParseExecuteParameters(napi_env env, size_t argc, napi_value *argv, ExecuteInfo &executeInfo); 63 64 static void SetPropertyExecute(napi_env env, void *data); 65 static void SetPropertyPromiseExecuteDone(napi_env env, napi_status status, void *data); 66 static void SetPropertyAsyncExecuteDone(napi_env env, napi_status status, void *data); 67 static void GetPropertyExecute(napi_env env, void *data); 68 static void GetPropertyPromiseExecuteDone(napi_env env, napi_status status, void *data); 69 static void GetPropertyAsyncExecuteDone(napi_env env, napi_status status, void *data); 70 }; 71 } // namespace UserAuth 72 } // namespace UserIAM 73 } // namespace OHOS 74 #endif // FACERECOGNITION_USER_AUTH_H 75