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