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