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 DISP_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__, DISP_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] " format "\n", __FUNCTION__, DISP_FILENAME, __LINE__, \ 60 ##__VA_ARGS__); \ 61 } while (0) 62 #endif 63 64 #ifndef DISPLAY_LOGW 65 #define DISPLAY_LOGW(format, ...) \ 66 do { \ 67 HILOG_WARN(LOG_CORE, "[%{public}s@%{public}s:%{public}d] " format "\n", __FUNCTION__, DISP_FILENAME, __LINE__, \ 68 ##__VA_ARGS__); \ 69 } while (0) 70 #endif 71 72 #ifndef DISPLAY_LOGE 73 #define DISPLAY_LOGE(format, ...) \ 74 do { \ 75 HILOG_ERROR(LOG_CORE, \ 76 "\033[0;32;31m" \ 77 "[%{public}s@%{public}s:%{public}d] " format "\033[m" \ 78 "\n", \ 79 __FUNCTION__, DISP_FILENAME, __LINE__, ##__VA_ARGS__); \ 80 } while (0) 81 #endif 82 83 #ifndef CHECK_NULLPOINTER_RETURN_VALUE 84 #define CHECK_NULLPOINTER_RETURN_VALUE(pointer, ret) \ 85 do { \ 86 if ((pointer) == NULL) { \ 87 DISPLAY_LOGE("pointer is null and return ret\n"); \ 88 return (ret); \ 89 } \ 90 } while (0) 91 #endif 92 93 #ifndef CHECK_NULLPOINTER_RETURN 94 #define CHECK_NULLPOINTER_RETURN(pointer) \ 95 do { \ 96 if ((pointer) == NULL) { \ 97 DISPLAY_LOGE("pointer is null and return\n"); \ 98 return; \ 99 } \ 100 } while (0) 101 #endif 102 103 #ifndef DISPLAY_CHK_RETURN 104 #define DISPLAY_CHK_RETURN(val, ret, ...) \ 105 do { \ 106 if (val) { \ 107 __VA_ARGS__; \ 108 return (ret); \ 109 } \ 110 } while (0) 111 #endif 112 113 #ifndef DISPLAY_CHK_RETURN_NOT_VALUE 114 #define DISPLAY_CHK_RETURN_NOT_VALUE(val, ...) \ 115 do { \ 116 if (val) { \ 117 __VA_ARGS__; \ 118 return; \ 119 } \ 120 } while (0) 121 #endif 122 123 #ifdef __cplusplus 124 } 125 #endif 126 127 #endif /* DISP_COMMON_H */ 128