• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef NAPI_BLUETOOTH_ERROR_H_
16 #define NAPI_BLUETOOTH_ERROR_H_
17 
18 
19 #include <cstdint>
20 #include "bluetooth_log.h"
21 #include "napi/native_api.h"
22 
23 namespace OHOS {
24 namespace Bluetooth {
25 
26 #ifdef ENABLE_NAPI_BLUETOOTH_MANAGER
27 #ifndef NAPI_BT_ASSERT_RETURN
28 #define NAPI_BT_ASSERT_RETURN(env, cond, errCode, retObj) \
29 do {                                                      \
30     if (!(cond)) {                                        \
31         HandleSyncErr((env), (errCode));                  \
32         HILOGE("bluetoothManager napi assert failed.");                    \
33         return (retObj);                                  \
34     }                                                     \
35 } while (0)
36 #endif
37 #else // ENABLE_NAPI_BLUETOOTH_MANAGER
38 #ifndef NAPI_BT_ASSERT_RETURN
39 #define NAPI_BT_ASSERT_RETURN(env, cond, errCode, retObj) \
40 do {                                                      \
41     if (!(cond)) {                                        \
42         HILOGE("bluetooth napi assert failed.");                    \
43         return (retObj);                                  \
44     }                                                     \
45 } while (0)
46 #endif
47 #endif
48 
49 #define NAPI_BT_ASSERT_RETURN_UNDEF(env, cond, errCode)  \
50 do {                                                     \
51     napi_value res = nullptr;                            \
52     napi_get_undefined((env), &res);                     \
53     NAPI_BT_ASSERT_RETURN((env), (cond), (errCode), res); \
54 } while (0)
55 
56 #define NAPI_BT_ASSERT_RETURN_FALSE(env, cond, errCode)  \
57 do {                                                     \
58     napi_value res = nullptr;                            \
59     napi_get_boolean((env), false, &res);                \
60     NAPI_BT_ASSERT_RETURN((env), (cond), (errCode), res); \
61 } while (0)
62 
63 void HandleSyncErr(const napi_env &env, int32_t errCode);
64 }
65 }
66 #endif