1 /*
2  * Copyright (c) 2022 Shenzhen Kaihong Digital Industry Development 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 NFC_NAPI_CTRL_UTILS_H
17 #define NFC_NAPI_CTRL_UTILS_H
18 #include <chrono>
19 #include "napi/native_api.h"
20 #include "napi/native_node_api.h"
21 
22 namespace OHOS {
23 namespace NFC {
24 namespace KITS {
25 // business error code, throw these errors to applcation.
26 const static int BUSI_ERR_PERM = 201; // Permission denied.
27 const static int BUSI_ERR_PARAM = 401; // The parameter check failed.
28 const static int BUSI_ERR_CAPABILITY = 801; // Capability not supported.
29 const static int BUSI_ERR_NFC_STATE_INVALID = 3100101; // nfc state is abnormal.
30 
31 const std::string KEY_CODE = "code";
32 const std::string NFC_PERM_DESC = "ohos.permission.MANAGE_SECURE_SETTINGS";
33 
34 napi_value CreateUndefined(napi_env env);
35 
36 std::string BuildErrorMessage(int errCode, std::string funcName, std::string forbiddenPerm,
37     std::string paramName, std::string expertedType);
38 napi_value GenerateBusinessError(const napi_env &env, int errCode, const std::string &errMessage);
39 
40 bool CheckNfcStatusCodeAndThrow(const napi_env &env, int statusCode, const std::string funcName);
41 } // namespace KITS
42 } // namespace NFC
43 } // namespace OHOS
44 #endif