• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-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 DEFINE_MULTIMODAL_H
16 #define DEFINE_MULTIMODAL_H
17 
18 #include "mmi_log.h"
19 
20 namespace OHOS {
21 namespace MMI {
22 #ifndef RET_OK
23     #define RET_OK (0)
24 #endif
25 
26 #ifndef RET_ERR
27     #define RET_ERR (-1)
28 #endif
29 
30 inline constexpr int32_t INVALID_FD { -1 };
31 inline constexpr int32_t INVALID_PID { -1 };
32 
33 #ifndef LINEINFO
34 #define LINEINFO __FILE__, __LINE__
35 #endif
36 
37 #ifdef DEBUG_CODE_TEST
38 #define CHKPL(cond, ...) \
39     do { \
40         if ((cond) == nullptr) { \
41             MMI_HILOGW("%{public}s, (%{public}d), CHKPL(%{public}s) is null, do nothing", \
42                 __FILE__, __LINE__, #cond); \
43         } \
44     } while (0)
45 
46 #define CHKPV(cond) \
47     do { \
48         if ((cond) == nullptr) { \
49             MMI_HILOGE("%{public}s, (%{public}d), CHKPV(%{public}s) is null", \
50                 __FILE__, __LINE__, #cond); \
51             return; \
52         } \
53     } while (0)
54 
55 #define CHKPF(cond) \
56     do { \
57         if ((cond) == nullptr) { \
58             MMI_HILOGE("%{public}s, (%{public}d), CHKPF(%{public}s) is null", \
59                 __FILE__, __LINE__, #cond); \
60             return false; \
61         } \
62     } while (0)
63 
64 #define CHKPS(cond) \
65     do { \
66         if ((cond) == nullptr) { \
67             MMI_HILOGE("%{public}s, (%{public}d), CHKPS(%{public}s) is null", \
68                 __FILE__, __LINE__, #cond); \
69             return ""; \
70         } \
71     } while (0)
72 
73 #define CHKPC(cond) \
74     { \
75         if ((cond) == nullptr) { \
76             MMI_HILOGW("%{public}s, (%{public}d), CHKPC(%{public}s) is null, skip then continue", \
77                 __FILE__, __LINE__, #cond); \
78             continue; \
79         } \
80     }
81 
82 #define CHKPB(cond) \
83     { \
84         if ((cond) == nullptr) { \
85             MMI_HILOGW("%{public}s, (%{public}d), CHKPB(%{public}s) is null, skip then break", \
86                 __FILE__, __LINE__, #cond); \
87             break; \
88         } \
89     }
90 
91 #define CHKPR(cond, r) \
92     do { \
93         if ((cond) == nullptr) { \
94             MMI_HILOGE("%{public}s, (%{public}d), CHKPR(%{public}s) is null, return value is %{public}d", \
95                 __FILE__, __LINE__, #cond, r); \
96             return r; \
97         } \
98     } while (0)
99 
100 #define CHKPP(cond) \
101     do { \
102         if ((cond) == nullptr) { \
103             MMI_HILOGE("%{public}s, (%{public}d), CHKPP(%{public}s) is null, return value is null", \
104                 __FILE__, __LINE__, #cond); \
105             return nullptr; \
106         } \
107     } while (0)
108 
109 #define CHKPO(cond) \
110     do { \
111         if ((cond) == nullptr) { \
112             MMI_HILOGW("%{public}s, (%{public}d), CHKPO(%{public}s) is null, skip then continue", \
113                 __FILE__, __LINE__, #cond); \
114             return {}; \
115         } \
116     } while (0)
117 
118 #define CK(cond, ec) \
119     do { \
120         if (!(cond)) { \
121             MMI_HILOGE("%{public}s, (%{public}d), CK(%{public}s), errCode:%{public}d", \
122                 __FILE__, __LINE__, #cond, ec); \
123         } \
124     } while (0)
125 
126 #define CHK_PID_AND_TID() \
127     do { \
128         MMI_HILOGD("%{public}s, (%{public}d), pid:%{public}d threadId:%{public}" PRIu64, \
129             __FILE__, __LINE__, GetPid(), GetThisThreadId()); \
130     } while (0)
131 
132 #else // DEBUG_CODE_TEST
133 #define CHKPL(cond) \
134     do { \
135         if ((cond) == nullptr) { \
136             MMI_HILOGW("CHKPL(%{public}s) is null, do nothing", #cond); \
137         } \
138     } while (0)
139 
140 #define CHKPV(cond) \
141     do { \
142         if ((cond) == nullptr) { \
143             MMI_HILOGE("CHKPV(%{public}s) is null", #cond); \
144             return; \
145         } \
146     } while (0)
147 
148 #define CHKPF(cond) \
149     do { \
150         if ((cond) == nullptr) { \
151             MMI_HILOGE("CHKPF(%{public}s) is null", #cond); \
152             return false; \
153         } \
154     } while (0)
155 
156 #define CHKPS(cond) \
157     do { \
158         if ((cond) == nullptr) { \
159             MMI_HILOGE("CHKPS(%{public}s) is null", #cond); \
160             return ""; \
161         } \
162     } while (0)
163 
164 #define CHKPC(cond) \
165     { \
166         if ((cond) == nullptr) { \
167             MMI_HILOGW("CHKPC(%{public}s) is null, skip then continue", #cond); \
168             continue; \
169         } \
170     }
171 
172 #define CHKPB(cond) \
173     { \
174         if ((cond) == nullptr) { \
175             MMI_HILOGW("CHKPB(%{public}s) is null, skip then break", #cond); \
176             break; \
177         } \
178     }
179 
180 #define CHKPR(cond, r) \
181     do { \
182         if ((cond) == nullptr) { \
183             MMI_HILOGE("CHKPR(%{public}s) is null, return value is %{public}d", #cond, r); \
184             return r; \
185         } \
186     } while (0)
187 
188 #define CHKPP(cond) \
189     do { \
190         if ((cond) == nullptr) { \
191             MMI_HILOGE("CHKPP(%{public}s) is null, return value is null", #cond); \
192             return nullptr; \
193         } \
194     } while (0)
195 
196 #define CHKPO(cond) \
197     do { \
198         if ((cond) == nullptr) { \
199             MMI_HILOGW("%{public}s, (%{public}d), CHKPO(%{public}s) is null, return object is null", \
200                 __FILE__, __LINE__, #cond); \
201             return {}; \
202         } \
203     } while (0)
204 
205 #define CK(cond, ec) \
206     do { \
207         if (!(cond)) { \
208             MMI_HILOGE("CK(%{public}s), errCode:%{public}d", #cond, ec); \
209         } \
210     } while (0)
211 
212 #define CHK_PID_AND_TID() \
213     do { \
214         MMI_HILOGD("pid:%{public}d threadId:%{public}" PRIu64, GetPid(), GetThisThreadId()); \
215     } while (0)
216 
217 #endif
218 
219 #define DEFRET_1(data, value, ...) (value)
220 #define DEFRET(...) DEFRET_1(__VA_ARGS__, false)
221 
222 #define WRITEBOOL(parcel, data, ...) \
223     do { \
224         if (!(parcel).WriteBool(data)) { \
225             MMI_HILOGE("WriteBool "#data" failed"); \
226             return DEFRET(false, ##__VA_ARGS__); \
227         } \
228     } while (0)
229 
230 #define WRITEINT32(parcel, data, ...) \
231     do { \
232         if (!(parcel).WriteInt32(data)) { \
233             MMI_HILOGE("WriteInt32 "#data" failed"); \
234             return DEFRET(false, ##__VA_ARGS__); \
235         } \
236     } while (0)
237 
238 #define WRITEINT64(parcel, data, ...) \
239     do { \
240         if (!(parcel).WriteInt64(data)) { \
241             MMI_HILOGE("WriteInt64 "#data" failed"); \
242             return DEFRET(false, ##__VA_ARGS__); \
243         } \
244     } while (0)
245 
246 #define WRITEUINT32(parcel, data, ...) \
247     do { \
248         if (!(parcel).WriteUint32(data)) { \
249             MMI_HILOGE("WriteUint32 "#data" failed"); \
250             return DEFRET(false, ##__VA_ARGS__); \
251         } \
252     } while (0)
253 
254 #define WRITEDOUBLE(parcel, data, ...) \
255     do { \
256         if (!(parcel).WriteDouble(data)) { \
257             MMI_HILOGE("WriteDouble "#data" failed"); \
258             return DEFRET(false, ##__VA_ARGS__); \
259         } \
260     } while (0)
261 
262 #define WRITESTRING(parcel, data, ...) \
263     do { \
264         if (!(parcel).WriteString(data)) { \
265             MMI_HILOGE("WriteString "#data" failed"); \
266             return DEFRET(false, ##__VA_ARGS__); \
267         } \
268     } while (0)
269 
270 #define READBOOL(parcel, data, ...) \
271     do { \
272         if (!(parcel).ReadBool(data)) { \
273             MMI_HILOGE("ReadBool "#data" failed"); \
274             return DEFRET(false, ##__VA_ARGS__); \
275         } \
276     } while (0)
277 
278 #define READINT32(parcel, data, ...) \
279     do { \
280         if (!(parcel).ReadInt32(data)) { \
281             MMI_HILOGE("ReadInt32 "#data" failed"); \
282             return DEFRET(false, ##__VA_ARGS__); \
283         } \
284     } while (0)
285 
286 #define READINT64(parcel, data, ...) \
287     do { \
288         if (!(parcel).ReadInt64(data)) { \
289             MMI_HILOGE("ReadInt64 "#data" failed"); \
290             return DEFRET(false, ##__VA_ARGS__); \
291         } \
292     } while (0)
293 
294 #define READUINT32(parcel, data, ...) \
295     do { \
296         if (!(parcel).ReadUint32(data)) { \
297             MMI_HILOGE("ReadUint32 "#data" failed"); \
298             return DEFRET(false, ##__VA_ARGS__); \
299         } \
300     } while (0)
301 
302 #define READDOUBLE(parcel, data, ...) \
303     do { \
304         if (!(parcel).ReadDouble(data)) { \
305             MMI_HILOGE("ReadDouble "#data" failed"); \
306             return DEFRET(false, ##__VA_ARGS__); \
307         } \
308     } while (0)
309 
310 #define READSTRING(parcel, data, ...) \
311     do { \
312         if (!(parcel).ReadString(data)) { \
313             MMI_HILOGE("ReadString "#data" failed"); \
314             return DEFRET(false, ##__VA_ARGS__); \
315         } \
316     } while (0)
317 } // namespace MMI
318 } // namespace OHOS
319 #endif // DEFINE_MULTIMODAL_H