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" 33 #define LOG_DOMAIN 0xD001400 34 35 #define __DISP_FILENAME__ (strrchr(__FILE__, '/') ? (strrchr(__FILE__, '/') + 1) : __FILE__) 36 37 #ifndef DISPLAY_DEBUG_ENABLE 38 #define DISPLAY_DEBUG_ENABLE 0 39 #endif 40 41 #ifndef DISPLAY_LOGD 42 #define DISPLAY_LOGD(format, ...) \ 43 do { \ 44 if (DISPLAY_DEBUG_ENABLE) { \ 45 HILOG_INFO(LOG_CORE, "[%{public}s@%{public}s:%{public}d] " format "\n", \ 46 __FUNCTION__, __DISP_FILENAME__, __LINE__, \ 47 ##__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}s:%{public}d] " format "\n", \ 56 __FUNCTION__, __DISP_FILENAME__, __LINE__, ##__VA_ARGS__); \ 57 } while (0) 58 #endif 59 60 #ifndef DISPLAY_LOGW 61 #define DISPLAY_LOGW(format, ...) \ 62 do { \ 63 HILOG_WARN(LOG_CORE, "[%{public}s@%{public}s:%{public}d] " format "\n", \ 64 __FUNCTION__, __DISP_FILENAME__, __LINE__, \ 65 ##__VA_ARGS__); \ 66 } while (0) 67 #endif 68 69 #ifndef DISPLAY_LOGE 70 #define DISPLAY_LOGE(format, ...) \ 71 do { \ 72 HILOG_ERROR(LOG_CORE, \ 73 "\033[0;32;31m" \ 74 "[%{public}s@%{public}s:%{public}d] " format "\033[m" \ 75 "\n", \ 76 __FUNCTION__, __DISP_FILENAME__, __LINE__, ##__VA_ARGS__); \ 77 } while (0) 78 #endif 79 80 #ifndef CHECK_NULLPOINTER_RETURN_VALUE 81 #define CHECK_NULLPOINTER_RETURN_VALUE(pointer, ret) \ 82 do { \ 83 if ((pointer) == NULL) { \ 84 DISPLAY_LOGE("pointer is null and return ret\n"); \ 85 return (ret); \ 86 } \ 87 } while (0) 88 #endif 89 90 #ifndef CHECK_NULLPOINTER_RETURN 91 #define CHECK_NULLPOINTER_RETURN(pointer) \ 92 do { \ 93 if ((pointer) == NULL) { \ 94 DISPLAY_LOGE("pointer is null and return\n"); \ 95 return; \ 96 } \ 97 } while (0) 98 #endif 99 100 #ifndef DISPLAY_CHK_RETURN 101 #define DISPLAY_CHK_RETURN(val, ret, ...) \ 102 do { \ 103 if (val) { \ 104 __VA_ARGS__; \ 105 return (ret); \ 106 } \ 107 } while (0) 108 #endif 109 110 #ifndef DISPLAY_CHK_RETURN_NOT_VALUE 111 #define DISPLAY_CHK_RETURN_NOT_VALUE(val, ...) \ 112 do { \ 113 if (val) { \ 114 __VA_ARGS__; \ 115 return; \ 116 } \ 117 } while (0) 118 #endif 119 120 #ifdef __cplusplus 121 } 122 #endif 123 124 #endif /* DISP_COMMON_H */ 125