1 /*
2  * Copyright (c) 2023 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 INTELL_VOICE_COMMON_NAPI_H
17 #define INTELL_VOICE_COMMON_NAPI_H
18 
19 #include "napi/native_api.h"
20 #include "napi/native_node_api.h"
21 
22 namespace OHOS {
23 namespace IntellVoiceNapi {
24 constexpr int ARGC_ONE = 1;
25 constexpr int ARGC_TWO = 2;
26 constexpr int ARG_INDEX_0 = 0;
27 constexpr int ARG_INDEX_1 = 1;
28 constexpr int ARG_INDEX_2 = 2;
29 
30 constexpr int32_t NAPI_INTELLIGENT_VOICE_SUCCESS = 0;
31 
32 constexpr int32_t  NAPI_INTELLIGENT_VOICE_PERMISSION_DENIED = 201;
33 constexpr int32_t  NAPI_INTELLIGENT_VOICE_NO_MEMORY = 22700101;
34 constexpr int32_t  NAPI_INTELLIGENT_VOICE_INVALID_PARAM = 22700102;
35 constexpr int32_t  NAPI_INTELLIGENT_VOICE_INIT_FAILED = 22700103;
36 constexpr int32_t  NAPI_INTELLIGENT_VOICE_COMMIT_ENROLL_FAILED = 22700104;
37 constexpr int32_t  NAPI_INTELLIGENT_VOICE_START_CAPTURER_FAILED = 22700105;
38 constexpr int32_t  NAPI_INTELLIGENT_VOICE_READ_FAILED = 22700106;
39 constexpr int32_t  NAPI_INTELLIGENT_VOICE_SYSTEM_ERROR = 22700107;
40 
41 class IntellVoiceCommonNapi {
42 public:
43     IntellVoiceCommonNapi() = default;
44     ~IntellVoiceCommonNapi() = default;
45     static std::string GetMessageByCode(const int32_t code);
46     static void ThrowError(napi_env env, int32_t code);
47     static bool IsSameCallback(napi_env env, napi_value callback, napi_ref callbackRef);
48 };
49 }
50 }
51 #endif