• 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 HKS_TEMPLATE_H
17 #define HKS_TEMPLATE_H
18 
19 #undef HKS_NULL_POINTER
20 
21 #ifdef __cplusplus
22 #define HKS_NULL_POINTER nullptr
23 #else
24 #define HKS_NULL_POINTER NULL
25 #endif
26 
27 #define HKS_IF_NOT_SUCC_LOGE_RETURN(RESULT, ERROR_CODE, LOG_MESSAGE, ...) \
28 if ((RESULT) != HKS_SUCCESS) { \
29     HKS_LOG_E(LOG_MESSAGE, ##__VA_ARGS__); \
30     return (ERROR_CODE); \
31 }
32 
33 #define HKS_IF_NOT_SUCC_LOGE_BREAK(RESULT, LOG_MESSAGE, ...) \
34 if ((RESULT) != HKS_SUCCESS) { \
35     HKS_LOG_E(LOG_MESSAGE, ##__VA_ARGS__); \
36     break; \
37 }
38 
39 #define HKS_IF_NOT_SUCC_BREAK(RESULT, ...) \
40 if ((RESULT) != HKS_SUCCESS) { \
41     break; \
42 }
43 
44 #define HKS_IF_NOT_SUCC_LOGE(RESULT, LOG_MESSAGE, ...) \
45 if ((RESULT) != HKS_SUCCESS) { \
46     HKS_LOG_E(LOG_MESSAGE, ##__VA_ARGS__); \
47 }
48 
49 #define HKS_IF_NOT_SUCC_RETURN(RESULT, ERROR_CODE) \
50 if ((RESULT) != HKS_SUCCESS) { \
51     return (ERROR_CODE); \
52 }
53 
54 #define HKS_IF_NULL_LOGE_RETURN(OBJECT, ERROR_CODE, LOG_MESSAGE, ...) \
55 if ((OBJECT) == HKS_NULL_POINTER) { \
56     HKS_LOG_E(LOG_MESSAGE, ##__VA_ARGS__); \
57     return (ERROR_CODE); \
58 }
59 
60 #define HKS_IF_NULL_LOGE_BREAK(OBJECT, LOG_MESSAGE, ...) \
61 if ((OBJECT) == HKS_NULL_POINTER) { \
62     HKS_LOG_E(LOG_MESSAGE, ##__VA_ARGS__); \
63     break; \
64 }
65 
66 #define HKS_IF_NULL_RETURN(OBJECT, ERROR_CODE) \
67 if ((OBJECT) == HKS_NULL_POINTER) { \
68     return (ERROR_CODE); \
69 }
70 
71 #define HKS_IF_NULL_BREAK(OBJECT) \
72 if ((OBJECT) == HKS_NULL_POINTER) { \
73     break; \
74 }
75 
76 #define HKS_IF_NOT_TRUE_LOGE_RETURN(BOOL_FUNC, ERROR_CODE) \
77 do { \
78     if (!(BOOL_FUNC)) { \
79         HKS_LOG_E("%{public}s failed!", #BOOL_FUNC); \
80         return ERROR_CODE; \
81     } \
82 } while (0)
83 
84 #define HKS_IF_NOT_TRUE_LOGE_RETURN_VOID(BOOL_FUNC) \
85 do { \
86     if (!(BOOL_FUNC)) { \
87         HKS_LOG_E("%{public}s failed!", #BOOL_FUNC); \
88         return; \
89     } \
90 } while (0)
91 #endif /* HKS_TEMPLATE_H */