• 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 
16 #ifndef WIFI_NAPI_ERRCODE_H_
17 #define WIFI_NAPI_ERRCODE_H_
18 
19 #include "wifi_napi_utils.h"
20 #include <string>
21 #include "wifi_napi_errcode.h"
22 
23 namespace OHOS {
24 namespace Wifi {
25 inline const std::string BUSINESS_ERROR_PROPERTY_CODE = "code";
26 inline const std::string BUSINESS_ERROR_PROPERTY_MESSAGE = "message";
27 inline const std::string BUSINESS_ERROR_PROPERTY_DATA = "data";
28 
29 enum WifiNapiErrCode {
30     WIFI_ERRCODE_SUCCESS = 0, /* successfully */
31     WIFI_ERRCODE_PERMISSION_DENIED = 201, /* permission denied */
32     WIFI_ERRCODE_NON_SYSTEMAPP = 202, /* not system app */
33     WIFI_ERRCODE_INVALID_PARAM = 401, /* invalid params */
34     WIFI_ERRCODE_NOT_SUPPORTED = 801, /* not supported */
35     WIFI_ERRCODE_OPERATION_FAILED = 1000, /* failed */
36     WIFI_ERRCODE_WIFI_NOT_OPENED  = 1001, /* sta service not opened */
37     WIFI_ERRCODE_OPEN_FAIL_WHEN_CLOSING = 1003, /* forbid when current airplane opened */
38     WIFI_ERRCODE_CLOSE_FAIL_WHEN_OPENING = 1004, /* forbid when current powersaving opened */
39     WIFI_ERRCODE_USER_DOES_NOT_RESPOND = 1005, /* user does not respond */
40     WIFI_ERRCODE_USER_REFUSE_THE_ACTION = 1006, /* user refuse the action */
41     WIFI_ERRCODE_PARAM_VALIDATION_FAILED = 1007, /* parameter validation failed */
42 };
43 
44 #ifdef ENABLE_NAPI_WIFI_MANAGER
45 #ifndef WIFI_NAPI_ASSERT
46 #define WIFI_NAPI_ASSERT(env, cond, errCode, sysCap) \
47 do { \
48     if (!(cond)) { \
49         napi_value res = nullptr; \
50         HandleSyncErrCode(env, errCode, sysCap); \
51         napi_get_undefined(env, &res); \
52         return res; \
53     } \
54 } while (0)
55 #endif
56 
57 #ifndef WIFI_NAPI_RETURN
58 #define WIFI_NAPI_RETURN(env, cond, errCode, sysCap) \
59 do { \
60     napi_value res = nullptr; \
61     if (!(cond)) { \
62         HandleSyncErrCode(env, errCode, sysCap); \
63     } \
64     napi_get_undefined(env, &res); \
65     return res; \
66 } while (0)
67 #endif
68 
69 #else /* #else ENABLE_NAPI_WIFI_MANAGER */
70 
71 #ifndef WIFI_NAPI_ASSERT
72 #define WIFI_NAPI_ASSERT(env, cond, errCode, sysCap) \
73 do { \
74     if (!(cond)) { \
75         napi_value res = nullptr; \
76         napi_get_boolean(env, cond, &res); \
77         return res; \
78     } \
79 } while (0)
80 #endif
81 
82 #ifndef WIFI_NAPI_RETURN
83 #define WIFI_NAPI_RETURN(env, cond, errCode, sysCap) \
84 do { \
85     napi_value res = nullptr; \
86     napi_get_boolean(env, cond, &res); \
87     return res; \
88 } while (0)
89 #endif
90 #endif /* #endif ENABLE_NAPI_WIFI_MANAGER */
91 
92 /**
93  * @brief Thow error code for async-callback function.
94  *
95  * @param env The env.
96  * @param info The input data.
97  */
98 void HandleCallbackErrCode(const napi_env &env, const AsyncContext &info);
99 
100 /**
101  * @brief Thow error code for async-promise function.
102  *
103  * @param env The env.
104  * @param info The input data.
105  */
106 void HandlePromiseErrCode(const napi_env &env, const AsyncContext &info);
107 
108 
109 #ifdef ENABLE_NAPI_WIFI_MANAGER
110 /**
111  * @brief Thow error code for async function.
112  *
113  * @param env The env.
114  * @param errCode The error code.
115  * @param sysCap System capability code.
116  */
117 void HandleSyncErrCode(const napi_env &env, int32_t errCode, int32_t sysCap);
118 #endif
119 }  // namespace Wifi
120 }  // namespace OHOS
121 #endif
122 
123