1 /*
2  * Copyright (c) 2023 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 DISPLAY_LOG_H
17 #define DISPLAY_LOG_H
18 #include <stdint.h>
19 #include <string.h>
20 #include "hilog/log.h"
21 
22 #ifdef HDF_LOG_TAG
23 #undef HDF_LOG_TAG
24 #endif
25 
26 #if defined(__cplusplus)
27 extern "C" {
28 #endif
29 
30 #undef LOG_TAG
31 #define LOG_TAG "DISP"
32 #undef LOG_DOMAIN
33 #define LOG_DOMAIN 0xD002515
34 
35 #ifndef DISPLAY_UNUSED
36 #define DISPLAY_UNUSED(x) (void)(x)
37 #endif
38 
39 #ifndef DISPLAY_DEBUG_ENABLE
40 #define DISPLAY_DEBUG_ENABLE 1
41 #endif
42 
43 #ifndef DISPLAY_LOGD
44 #define DISPLAY_LOGD(format, ...)                                                                                 \
45     do {                                                                                                          \
46         if (DISPLAY_DEBUG_ENABLE) {                                                                               \
47             HILOG_DEBUG(LOG_CORE, "[%{public}s:%{public}d] " format "\n", __FUNCTION__, __LINE__, ##__VA_ARGS__); \
48         }                                                                                                         \
49     } while (0)
50 #endif
51 
52 #ifndef DISPLAY_LOGI
53 #define DISPLAY_LOGI(format, ...)                                                                            \
54     do {                                                                                                     \
55         HILOG_INFO(LOG_CORE, "[%{public}s:%{public}d] " format "\n", __FUNCTION__, __LINE__, ##__VA_ARGS__); \
56     } while (0)
57 #endif
58 
59 #ifndef DISPLAY_LOGW
60 #define DISPLAY_LOGW(format, ...)                                                                            \
61     do {                                                                                                     \
62         HILOG_WARN(LOG_CORE, "[%{public}s:%{public}d] " format "\n", __FUNCTION__, __LINE__, ##__VA_ARGS__); \
63     } while (0)
64 #endif
65 
66 #ifndef DISPLAY_LOGE
67 #define DISPLAY_LOGE(format, ...)                      \
68     do {                                               \
69         HILOG_ERROR(LOG_CORE,                          \
70             "\033[0;32;31m"                            \
71             "[%{public}s:%{public}d] " format "\033[m" \
72             "\n",                                      \
73             __FUNCTION__, __LINE__, ##__VA_ARGS__);    \
74     } while (0)
75 #endif
76 
77 #ifndef CHECK_NULLPOINTER_RETURN_VALUE
78 #define CHECK_NULLPOINTER_RETURN_VALUE(pointer, ret)          \
79     do {                                                      \
80         if ((pointer) == NULL) {                              \
81             DISPLAY_LOGE("pointer is null and return ret\n"); \
82             return (ret);                                     \
83         }                                                     \
84     } while (0)
85 #endif
86 
87 #ifndef CHECK_NULLPOINTER_RETURN
88 #define CHECK_NULLPOINTER_RETURN(pointer)                 \
89     do {                                                  \
90         if ((pointer) == NULL) {                          \
91             DISPLAY_LOGE("pointer is null and return\n"); \
92             return;                                       \
93         }                                                 \
94     } while (0)
95 #endif
96 
97 #ifndef DISPLAY_CHK_RETURN
98 #define DISPLAY_CHK_RETURN(val, ret, ...) \
99     do {                                  \
100         if (val) {                        \
101             __VA_ARGS__;                  \
102             return (ret);                 \
103         }                                 \
104     } while (0)
105 #endif
106 
107 #ifndef DISPLAY_CHK_RETURN_NOT_VALUE
108 #define DISPLAY_CHK_RETURN_NOT_VALUE(val, ...) \
109     do {                                       \
110         if (val) {                             \
111             __VA_ARGS__;                       \
112             return;                            \
113         }                                      \
114     } while (0)
115 #endif
116 
117 #ifdef __cplusplus
118 }
119 #endif
120 
121 #endif // DISPLAY_LOG_H
122