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