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  INTERFACES_PRIVACY_KITS_NAPI_COMMON_H
17 #define  INTERFACES_PRIVACY_KITS_NAPI_COMMON_H
18 
19 #include "access_token.h"
20 #include "napi/native_api.h"
21 #include "napi/native_node_api.h"
22 #include <thread>
23 
24 namespace OHOS {
25 namespace Security {
26 namespace AccessToken {
27 constexpr int32_t ASYNC_CALL_BACK_VALUES_NUM = 2;
28 constexpr int32_t ASYNC_CALL_BACK_PARAM_ERROR = 0;
29 constexpr int32_t ASYNC_CALL_BACK_PARAM_DATA = 1;
30 
31 bool IsCurrentThread(std::thread::id threadId);
32 bool CompareCallbackRef(const napi_env env, napi_ref subscriberRef, napi_ref unsubscriberRef, std::thread::id threadId);
33 bool ParseBool(const napi_env& env, const napi_value& value, bool& result);
34 bool ParseInt32(const napi_env& env, const napi_value& value, int32_t& result);
35 bool ParseInt64(const napi_env& env, const napi_value& value, int64_t& result);
36 bool ParseUint32(const napi_env& env, const napi_value& value, uint32_t& result);
37 bool ParseString(const napi_env& env, const napi_value& value, std::string& result);
38 bool ParseStringArray(const napi_env& env, const napi_value& value, std::vector<std::string>& result);
39 bool ParseAccessTokenIDArray(const napi_env& env, const napi_value& value, std::vector<AccessTokenID>& result);
40 bool ParseCallback(const napi_env& env, const napi_value& value, napi_ref& result);
41 bool IsArray(const napi_env& env, const napi_value& value);
42 bool CheckType(const napi_env& env, const napi_value& value, const napi_valuetype& type);
43 bool IsUndefinedOrNull(const napi_env& env, const napi_value& value);
44 bool IsNeedParseProperty(
45     const napi_env& env, const napi_value& value, const std::string& key, napi_value& property);
46 }  // namespace AccessToken
47 }  // namespace Security
48 }  // namespace OHOS
49 #endif /* INTERFACES_PRIVACY_KITS_NAPI_COMMON_H */
50 
51