• 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 CHK_INVALID_RV(cond, desc) \
149     do { \
150         if ((cond) < 0) { \
151             MMI_HILOGE("(%{public}s less than 0, desc:%{public}s)", #cond, std::string(desc).c_str()); \
152             return; \
153         } \
154     } while (0)
155 
156 #define CHKPF(cond) \
157     do { \
158         if ((cond) == nullptr) { \
159             MMI_HILOGE("CHKPF(%{public}s) is null", #cond); \
160             return false; \
161         } \
162     } while (0)
163 
164 #define CHECKSIZE(arg0, arg1) \
165     do { \
166         if ((arg0) > (arg1)) { \
167             MMI_HILOGE("arg0 value is out of arg1 size"); \
168             return false; \
169         } \
170     } while (0)
171 
172 #define CHKPS(cond) \
173     do { \
174         if ((cond) == nullptr) { \
175             MMI_HILOGE("CHKPS(%{public}s) is null", #cond); \
176             return ""; \
177         } \
178     } while (0)
179 
180 #define CHKPC(cond) \
181     { \
182         if ((cond) == nullptr) { \
183             MMI_HILOGW("CHKPC(%{public}s) is null, skip then continue", #cond); \
184             continue; \
185         } \
186     }
187 
188 #define CHKPB(cond) \
189     { \
190         if ((cond) == nullptr) { \
191             MMI_HILOGW("CHKPB(%{public}s) is null, skip then break", #cond); \
192             break; \
193         } \
194     }
195 
196 #define CHKPR(cond, r) \
197     do { \
198         if ((cond) == nullptr) { \
199             MMI_HILOGE("CHKPR(%{public}s) is null, return value is %{public}d", #cond, r); \
200             return r; \
201         } \
202     } while (0)
203 
204 #define CHKPP(cond) \
205     do { \
206         if ((cond) == nullptr) { \
207             MMI_HILOGE("CHKPP(%{public}s) is null, return value is null", #cond); \
208             return nullptr; \
209         } \
210     } while (0)
211 
212 #define CHKPO(cond) \
213     do { \
214         if ((cond) == nullptr) { \
215             MMI_HILOGW("%{public}s, (%{public}d), CHKPO(%{public}s) is null, return object is null", \
216                 __FILE__, __LINE__, #cond); \
217             return {}; \
218         } \
219     } while (0)
220 
221 #define CK(cond, ec) \
222     do { \
223         if (!(cond)) { \
224             MMI_HILOGE("CK(%{public}s), errCode:%{public}d", #cond, ec); \
225         } \
226     } while (0)
227 
228 #define CHK_PID_AND_TID() \
229     do { \
230         MMI_HILOGD("pid:%{public}d threadId:%{public}" PRIu64, GetPid(), GetThisThreadId()); \
231     } while (0)
232 
233 #endif
234 
235 #define DEFRET_1(data, value, ...) (value)
236 #define DEFRET(...) DEFRET_1(__VA_ARGS__, false)
237 
238 #define WRITEBOOL(parcel, data, ...) \
239     do { \
240         if (!(parcel).WriteBool(data)) { \
241             MMI_HILOGE("WriteBool "#data" failed"); \
242             return DEFRET(false, ##__VA_ARGS__); \
243         } \
244     } while (0)
245 
246 #define WRITEINT32(parcel, data, ...) \
247     do { \
248         if (!(parcel).WriteInt32(data)) { \
249             MMI_HILOGE("WriteInt32 "#data" failed"); \
250             return DEFRET(false, ##__VA_ARGS__); \
251         } \
252     } while (0)
253 
254 #define WRITEINT64(parcel, data, ...) \
255     do { \
256         if (!(parcel).WriteInt64(data)) { \
257             MMI_HILOGE("WriteInt64 "#data" failed"); \
258             return DEFRET(false, ##__VA_ARGS__); \
259         } \
260     } while (0)
261 
262 #define WRITEUINT8(parcel, data, ...) \
263     do { \
264         if (!(parcel).WriteUint8(data)) { \
265             MMI_HILOGE("WriteUint8 "#data" failed"); \
266             return DEFRET(false, ##__VA_ARGS__); \
267         } \
268     } while (0)
269 
270 #define WRITEUINT32(parcel, data, ...) \
271     do { \
272         if (!(parcel).WriteUint32(data)) { \
273             MMI_HILOGE("WriteUint32 "#data" failed"); \
274             return DEFRET(false, ##__VA_ARGS__); \
275         } \
276     } while (0)
277 
278 #define WRITEUINT64(parcel, data, ...) \
279     do { \
280         if (!(parcel).WriteUint64(data)) { \
281             MMI_HILOGE("WriteUint64 "#data" failed"); \
282             return DEFRET(false, ##__VA_ARGS__); \
283         } \
284     } while (0)
285 
286 #define WRITEDOUBLE(parcel, data, ...) \
287     do { \
288         if (!(parcel).WriteDouble(data)) { \
289             MMI_HILOGE("WriteDouble "#data" failed"); \
290             return DEFRET(false, ##__VA_ARGS__); \
291         } \
292     } while (0)
293 
294 #define WRITESTRING(parcel, data, ...) \
295     do { \
296         if (!(parcel).WriteString(data)) { \
297             MMI_HILOGE("WriteString "#data" failed"); \
298             return DEFRET(false, ##__VA_ARGS__); \
299         } \
300     } while (0)
301 
302 #define READBOOL(parcel, data, ...) \
303     do { \
304         if (!(parcel).ReadBool(data)) { \
305             MMI_HILOGE("ReadBool "#data" failed"); \
306             return DEFRET(false, ##__VA_ARGS__); \
307         } \
308     } while (0)
309 
310 #define READINT32(parcel, data, ...) \
311     do { \
312         if (!(parcel).ReadInt32(data)) { \
313             MMI_HILOGE("ReadInt32 "#data" failed"); \
314             return DEFRET(false, ##__VA_ARGS__); \
315         } \
316     } while (0)
317 
318 #define READINT64(parcel, data, ...) \
319     do { \
320         if (!(parcel).ReadInt64(data)) { \
321             MMI_HILOGE("ReadInt64 "#data" failed"); \
322             return DEFRET(false, ##__VA_ARGS__); \
323         } \
324     } while (0)
325 
326 #define READUINT8(parcel, data, ...) \
327     do { \
328         if (!(parcel).ReadUint8(data)) { \
329             MMI_HILOGE("ReadUint8 "#data" failed"); \
330             return DEFRET(false, ##__VA_ARGS__); \
331         } \
332     } while (0)
333 
334 #define READUINT32(parcel, data, ...) \
335     do { \
336         if (!(parcel).ReadUint32(data)) { \
337             MMI_HILOGE("ReadUint32 "#data" failed"); \
338             return DEFRET(false, ##__VA_ARGS__); \
339         } \
340     } while (0)
341 
342 #define READUINT64(parcel, data, ...) \
343     do { \
344         if (!(parcel).ReadUint64(data)) { \
345             MMI_HILOGE("ReadUint64 "#data" failed"); \
346             return DEFRET(false, ##__VA_ARGS__); \
347         } \
348     } while (0)
349 
350 #define READDOUBLE(parcel, data, ...) \
351     do { \
352         if (!(parcel).ReadDouble(data)) { \
353             MMI_HILOGE("ReadDouble "#data" failed"); \
354             return DEFRET(false, ##__VA_ARGS__); \
355         } \
356     } while (0)
357 
358 #define READSTRING(parcel, data, ...) \
359     do { \
360         if (!(parcel).ReadString(data)) { \
361             MMI_HILOGE("ReadString "#data" failed"); \
362             return DEFRET(false, ##__VA_ARGS__); \
363         } \
364     } while (0)
365 } // namespace MMI
366 } // namespace OHOS
367 #endif // DEFINE_MULTIMODAL_H