• 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 
16 #ifndef DEFINE_MULTIMODAL_H
17 #define DEFINE_MULTIMODAL_H
18 
19 #include "mmi_log.h"
20 
21 namespace OHOS {
22 namespace MMI {
23 #ifndef RET_OK
24     #define RET_OK (0)
25 #endif
26 
27 #ifndef RET_ERR
28     #define RET_ERR (-1)
29 #endif
30 
31 inline constexpr int32_t INVALID_FD { -1 };
32 inline constexpr int32_t INVALID_PID { -1 };
33 
34 #ifndef LINEINFO
35 #define LINEINFO __FILE__, __LINE__
36 #endif
37 
38 #ifdef DEBUG_CODE_TEST
39 #define CHKPL(cond, ...) \
40     do { \
41         if ((cond) == nullptr) { \
42             MMI_HILOGW("%{public}s, (%{public}d), CHKPL(%{public}s) is null, do nothing", \
43                 __FILE__, __LINE__, #cond); \
44         } \
45     } while (0)
46 
47 #define CHKPV(cond) \
48     do { \
49         if ((cond) == nullptr) { \
50             MMI_HILOGE("%{public}s, (%{public}d), CHKPV(%{public}s) is null", \
51                 __FILE__, __LINE__, #cond); \
52             return; \
53         } \
54     } while (0)
55 
56 #define CHKPF(cond) \
57     do { \
58         if ((cond) == nullptr) { \
59             MMI_HILOGE("%{public}s, (%{public}d), CHKPF(%{public}s) is null", \
60                 __FILE__, __LINE__, #cond); \
61             return false; \
62         } \
63     } while (0)
64 
65 #define CHKPS(cond) \
66     do { \
67         if ((cond) == nullptr) { \
68             MMI_HILOGE("%{public}s, (%{public}d), CHKPS(%{public}s) is null", \
69                 __FILE__, __LINE__, #cond); \
70             return ""; \
71         } \
72     } while (0)
73 
74 #define CHKPC(cond) \
75     { \
76         if ((cond) == nullptr) { \
77             MMI_HILOGW("%{public}s, (%{public}d), CHKPC(%{public}s) is null, skip then continue", \
78                 __FILE__, __LINE__, #cond); \
79             continue; \
80         } \
81     }
82 
83 #define CHKPB(cond) \
84     { \
85         if ((cond) == nullptr) { \
86             MMI_HILOGW("%{public}s, (%{public}d), CHKPB(%{public}s) is null, skip then break", \
87                 __FILE__, __LINE__, #cond); \
88             break; \
89         } \
90     }
91 
92 #define CHKPR(cond, r) \
93     do { \
94         if ((cond) == nullptr) { \
95             MMI_HILOGE("%{public}s, (%{public}d), CHKPR(%{public}s) is null, return value is %{public}d", \
96                 __FILE__, __LINE__, #cond, r); \
97             return r; \
98         } \
99     } while (0)
100 
101 #define CHKPP(cond) \
102     do { \
103         if ((cond) == nullptr) { \
104             MMI_HILOGE("%{public}s, (%{public}d), CHKPP(%{public}s) is null, return value is null", \
105                 __FILE__, __LINE__, #cond); \
106             return nullptr; \
107         } \
108     } while (0)
109 
110 #define CHKPO(cond) \
111     do { \
112         if ((cond) == nullptr) { \
113             MMI_HILOGW("%{public}s, (%{public}d), CHKPO(%{public}s) is null, skip then continue", \
114                 __FILE__, __LINE__, #cond); \
115             return {}; \
116         } \
117     } while (0)
118 
119 #define CK(cond, ec) \
120     do { \
121         if (!(cond)) { \
122             MMI_HILOGE("%{public}s, (%{public}d), CK(%{public}s), errCode:%{public}d", \
123                 __FILE__, __LINE__, #cond, ec); \
124         } \
125     } while (0)
126 
127 #define CHKCC(cond) \
128     { \
129         if (!(cond)) { \
130             continue; \
131         } \
132     }
133 
134 #define CHK_PID_AND_TID() \
135     do { \
136         MMI_HILOGD("%{public}s, (%{public}d), pid:%{public}d threadId:%{public}" PRIu64, \
137             __FILE__, __LINE__, GetPid(), GetThisThreadId()); \
138     } while (0)
139 
140 #else // DEBUG_CODE_TEST
141 #define CHKPL(cond) \
142     do { \
143         if ((cond) == nullptr) { \
144             MMI_HILOGW("CHKPL(%{public}s) is null, do nothing", #cond); \
145         } \
146     } while (0)
147 
148 #define CHKPV(cond) \
149     do { \
150         if ((cond) == nullptr) { \
151             MMI_HILOGE("CHKPV(%{public}s) is null", #cond); \
152             return; \
153         } \
154     } while (0)
155 
156 #define CHK_INVALID_RV(cond, desc) \
157     do { \
158         if ((cond) < 0) { \
159             MMI_HILOGE("(%{public}s less than 0, desc:%{public}s)", #cond, std::string(desc).c_str()); \
160             return; \
161         } \
162     } while (0)
163 
164 #define CHKPF(cond) \
165     do { \
166         if ((cond) == nullptr) { \
167             MMI_HILOGE("CHKPF(%{public}s) is null", #cond); \
168             return false; \
169         } \
170     } while (0)
171 
172 #define CHECKSIZE(arg0, arg1) \
173     do { \
174         if ((arg0) > (arg1)) { \
175             MMI_HILOGE("arg0 value is out of arg1 size"); \
176             return false; \
177         } \
178     } while (0)
179 
180 #define CHKPS(cond) \
181     do { \
182         if ((cond) == nullptr) { \
183             MMI_HILOGE("CHKPS(%{public}s) is null", #cond); \
184             return ""; \
185         } \
186     } while (0)
187 
188 #define CHKPC(cond) \
189     { \
190         if ((cond) == nullptr) { \
191             MMI_HILOGW("CHKPC(%{public}s) is null, skip then continue", #cond); \
192             continue; \
193         } \
194     }
195 
196 #define CHKPB(cond) \
197     { \
198         if ((cond) == nullptr) { \
199             MMI_HILOGW("CHKPB(%{public}s) is null, skip then break", #cond); \
200             break; \
201         } \
202     }
203 
204 #define CHKPR(cond, r) \
205     do { \
206         if ((cond) == nullptr) { \
207             MMI_HILOGE("CHKPR(%{public}s) is null, return value is %{public}d", #cond, r); \
208             return r; \
209         } \
210     } while (0)
211 
212 #define CHKFR(cond, r, desc) \
213     do { \
214         if (!(cond)) { \
215             MMI_HILOGE("CHKFR(%{public}s) is false, hint is %{public}s", #cond, desc); \
216             return r; \
217         } \
218     } while (0)
219 
220 #define CHK_KEY_ITEM(keyItem) \
221     do { \
222         if (!(keyItem)) { \
223             MMI_HILOGE("The keyItem is nullopt"); \
224             return false; \
225         } \
226     } while (0)
227 
228 #define CHKPRV(cond, msg) \
229     do { \
230         if ((cond) == nullptr) { \
231             MMI_HILOGE("CHKPRV(%{public}s) is null, msg %{public}s", #cond, msg); \
232             return; \
233         } \
234     } while (0)
235 
236 #define CHKNOKRV(cond, msg) \
237     do { \
238         if ((cond) != RET_OK) { \
239             MMI_HILOGE("CHKNOKRV(%{public}s) is not RET_OK, hint is %{public}s", #cond, msg); \
240             return; \
241         } \
242     } while (0)
243 
244 #define CHKFRV(cond, msg) \
245     do { \
246         if (!(cond)) { \
247             MMI_HILOGE("CHKFRV(%{public}s) is null, hint is %{public}s", #cond, msg); \
248             return; \
249         } \
250     } while (0)
251 
252 #define CHKPP(cond) \
253     do { \
254         if ((cond) == nullptr) { \
255             MMI_HILOGE("CHKPP(%{public}s) is null, return value is null", #cond); \
256             return nullptr; \
257         } \
258     } while (0)
259 
260 #define CHKPO(cond) \
261     do { \
262         if ((cond) == nullptr) { \
263             MMI_HILOGW("%{public}s, (%{public}d), CHKPO(%{public}s) is null, return object is null", \
264                 __FILE__, __LINE__, #cond); \
265             return {}; \
266         } \
267     } while (0)
268 
269 #define CK(cond, ec) \
270     do { \
271         if (!(cond)) { \
272             MMI_HILOGE("CK(%{public}s), errCode:%{public}d", #cond, ec); \
273         } \
274     } while (0)
275 
276 #define CHKCC(cond) \
277     { \
278         if (!(cond)) { \
279             continue; \
280         } \
281     }
282 
283 #define CHK_PID_AND_TID() \
284     do { \
285         MMI_HILOGD("pid:%{public}d threadId:%{public}" PRIu64, GetPid(), GetThisThreadId()); \
286     } while (0)
287 
288 #endif
289 
290 #define DEFRET_1(data, value, ...) (value)
291 #define DEFRET(...) DEFRET_1(__VA_ARGS__, false)
292 
293 #define WRITEBOOL(parcel, data, ...) \
294     do { \
295         if (!(parcel).WriteBool(data)) { \
296             MMI_HILOGE("WriteBool "#data" failed"); \
297             return DEFRET(false, ##__VA_ARGS__); \
298         } \
299     } while (0)
300 
301 #define WRITEINT32(parcel, data, ...) \
302     do { \
303         if (!(parcel).WriteInt32(data)) { \
304             MMI_HILOGE("WriteInt32 "#data" failed"); \
305             return DEFRET(false, ##__VA_ARGS__); \
306         } \
307     } while (0)
308 
309 #define WRITEINT64(parcel, data, ...) \
310     do { \
311         if (!(parcel).WriteInt64(data)) { \
312             MMI_HILOGE("WriteInt64 "#data" failed"); \
313             return DEFRET(false, ##__VA_ARGS__); \
314         } \
315     } while (0)
316 
317 #define WRITEUINT8(parcel, data, ...) \
318     do { \
319         if (!(parcel).WriteUint8(data)) { \
320             MMI_HILOGE("WriteUint8 "#data" failed"); \
321             return DEFRET(false, ##__VA_ARGS__); \
322         } \
323     } while (0)
324 
325 #define WRITEUINT32(parcel, data, ...) \
326     do { \
327         if (!(parcel).WriteUint32(data)) { \
328             MMI_HILOGE("WriteUint32 "#data" failed"); \
329             return DEFRET(false, ##__VA_ARGS__); \
330         } \
331     } while (0)
332 
333 #define WRITEUINT64(parcel, data, ...) \
334     do { \
335         if (!(parcel).WriteUint64(data)) { \
336             MMI_HILOGE("WriteUint64 "#data" failed"); \
337             return DEFRET(false, ##__VA_ARGS__); \
338         } \
339     } while (0)
340 
341 #define WRITEDOUBLE(parcel, data, ...) \
342     do { \
343         if (!(parcel).WriteDouble(data)) { \
344             MMI_HILOGE("WriteDouble "#data" failed"); \
345             return DEFRET(false, ##__VA_ARGS__); \
346         } \
347     } while (0)
348 
349 #define WRITEFLOAT(parcel, data, ...) \
350     do { \
351         if (!(parcel).WriteFloat(data)) { \
352             MMI_HILOGE("WriteFloat "#data" failed"); \
353             return DEFRET(false, ##__VA_ARGS__); \
354         } \
355     } while (0)
356 
357 #define WRITESTRING(parcel, data, ...) \
358     do { \
359         if (!(parcel).WriteString(data)) { \
360             MMI_HILOGE("WriteString "#data" failed"); \
361             return DEFRET(false, ##__VA_ARGS__); \
362         } \
363     } while (0)
364 
365 #define WRITEBUFFER(parcel, data, length, ...) \
366     do { \
367         if (!(parcel).WriteBuffer((data), length)) { \
368             MMI_HILOGE("WriteBuffer "#data" failed"); \
369             return DEFRET(false, ##__VA_ARGS__); \
370         } \
371     } while (0)
372 
373 #define WRITEREMOTEOBJECT(parcel, data, ...) \
374     do { \
375         if (!(parcel).WriteRemoteObject(data)) { \
376             MMI_HILOGE("WriteRemoteObject "#data" failed"); \
377             return DEFRET(false, ##__VA_ARGS__); \
378         } \
379     } while (0)
380 
381 #define READBOOL(parcel, data, ...) \
382     do { \
383         if (!(parcel).ReadBool(data)) { \
384             MMI_HILOGE("ReadBool "#data" failed"); \
385             return DEFRET(false, ##__VA_ARGS__); \
386         } \
387     } while (0)
388 
389 #define READINT32(parcel, data, ...) \
390     do { \
391         if (!(parcel).ReadInt32(data)) { \
392             MMI_HILOGE("ReadInt32 "#data" failed"); \
393             return DEFRET(false, ##__VA_ARGS__); \
394         } \
395     } while (0)
396 
397 #define READINT64(parcel, data, ...) \
398     do { \
399         if (!(parcel).ReadInt64(data)) { \
400             MMI_HILOGE("ReadInt64 "#data" failed"); \
401             return DEFRET(false, ##__VA_ARGS__); \
402         } \
403     } while (0)
404 
405 #define READUINT8(parcel, data, ...) \
406     do { \
407         if (!(parcel).ReadUint8(data)) { \
408             MMI_HILOGE("ReadUint8 "#data" failed"); \
409             return DEFRET(false, ##__VA_ARGS__); \
410         } \
411     } while (0)
412 
413 #define READUINT32(parcel, data, ...) \
414     do { \
415         if (!(parcel).ReadUint32(data)) { \
416             MMI_HILOGE("ReadUint32 "#data" failed"); \
417             return DEFRET(false, ##__VA_ARGS__); \
418         } \
419     } while (0)
420 
421 #define READUINT64(parcel, data, ...) \
422     do { \
423         if (!(parcel).ReadUint64(data)) { \
424             MMI_HILOGE("ReadUint64 "#data" failed"); \
425             return DEFRET(false, ##__VA_ARGS__); \
426         } \
427     } while (0)
428 
429 #define READDOUBLE(parcel, data, ...) \
430     do { \
431         if (!(parcel).ReadDouble(data)) { \
432             MMI_HILOGE("ReadDouble "#data" failed"); \
433             return DEFRET(false, ##__VA_ARGS__); \
434         } \
435     } while (0)
436 
437 #define READFLOAT(parcel, data, ...) \
438     do { \
439         if (!(parcel).ReadFloat(data)) { \
440             MMI_HILOGE("ReadFloat "#data" failed"); \
441             return DEFRET(false, ##__VA_ARGS__); \
442         } \
443     } while (0)
444 
445 #define READSTRING(parcel, data, ...) \
446     do { \
447         if (!(parcel).ReadString(data)) { \
448             MMI_HILOGE("ReadString "#data" failed"); \
449             return DEFRET(false, ##__VA_ARGS__); \
450         } \
451     } while (0)
452 } // namespace MMI
453 } // namespace OHOS
454 #endif // DEFINE_MULTIMODAL_H
455