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