Martin Stjernholm | c15e7e4 | 2020-12-02 22:50:53 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2005-2017 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | #pragma once |
| 18 | |
| 19 | #include <android/log.h> |
| 20 | |
| 21 | /* |
| 22 | * Normally we strip the effects of ALOGV (VERBOSE messages), |
| 23 | * LOG_FATAL and LOG_FATAL_IF (FATAL assert messages) from the |
| 24 | * release builds be defining NDEBUG. You can modify this (for |
| 25 | * example with "#define LOG_NDEBUG 0" at the top of your source |
| 26 | * file) to change that behavior. |
| 27 | */ |
| 28 | |
| 29 | #ifndef LOG_NDEBUG |
| 30 | #ifdef NDEBUG |
| 31 | #define LOG_NDEBUG 1 |
| 32 | #else |
| 33 | #define LOG_NDEBUG 0 |
| 34 | #endif |
| 35 | #endif |
| 36 | |
| 37 | /* --------------------------------------------------------------------- */ |
| 38 | |
| 39 | #ifndef __predict_false |
| 40 | #define __predict_false(exp) __builtin_expect((exp) != 0, 0) |
| 41 | #endif |
| 42 | |
| 43 | /* |
| 44 | * Simplified macro to send a verbose radio log message using current LOG_TAG. |
| 45 | */ |
| 46 | #ifndef RLOGV |
| 47 | #define __RLOGV(...) \ |
| 48 | ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_VERBOSE, LOG_TAG, \ |
| 49 | __VA_ARGS__)) |
| 50 | #if LOG_NDEBUG |
| 51 | #define RLOGV(...) \ |
| 52 | do { \ |
| 53 | if (0) { \ |
| 54 | __RLOGV(__VA_ARGS__); \ |
| 55 | } \ |
| 56 | } while (0) |
| 57 | #else |
| 58 | #define RLOGV(...) __RLOGV(__VA_ARGS__) |
| 59 | #endif |
| 60 | #endif |
| 61 | |
| 62 | #ifndef RLOGV_IF |
| 63 | #if LOG_NDEBUG |
| 64 | #define RLOGV_IF(cond, ...) ((void)0) |
| 65 | #else |
| 66 | #define RLOGV_IF(cond, ...) \ |
| 67 | ((__predict_false(cond)) \ |
| 68 | ? ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_VERBOSE, \ |
| 69 | LOG_TAG, __VA_ARGS__)) \ |
| 70 | : (void)0) |
| 71 | #endif |
| 72 | #endif |
| 73 | |
| 74 | /* |
| 75 | * Simplified macro to send a debug radio log message using current LOG_TAG. |
| 76 | */ |
| 77 | #ifndef RLOGD |
| 78 | #define RLOGD(...) \ |
| 79 | ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_DEBUG, LOG_TAG, \ |
| 80 | __VA_ARGS__)) |
| 81 | #endif |
| 82 | |
| 83 | #ifndef RLOGD_IF |
| 84 | #define RLOGD_IF(cond, ...) \ |
| 85 | ((__predict_false(cond)) \ |
| 86 | ? ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_DEBUG, \ |
| 87 | LOG_TAG, __VA_ARGS__)) \ |
| 88 | : (void)0) |
| 89 | #endif |
| 90 | |
| 91 | /* |
| 92 | * Simplified macro to send an info radio log message using current LOG_TAG. |
| 93 | */ |
| 94 | #ifndef RLOGI |
| 95 | #define RLOGI(...) \ |
| 96 | ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_INFO, LOG_TAG, \ |
| 97 | __VA_ARGS__)) |
| 98 | #endif |
| 99 | |
| 100 | #ifndef RLOGI_IF |
| 101 | #define RLOGI_IF(cond, ...) \ |
| 102 | ((__predict_false(cond)) \ |
| 103 | ? ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_INFO, \ |
| 104 | LOG_TAG, __VA_ARGS__)) \ |
| 105 | : (void)0) |
| 106 | #endif |
| 107 | |
| 108 | /* |
| 109 | * Simplified macro to send a warning radio log message using current LOG_TAG. |
| 110 | */ |
| 111 | #ifndef RLOGW |
| 112 | #define RLOGW(...) \ |
| 113 | ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_WARN, LOG_TAG, \ |
| 114 | __VA_ARGS__)) |
| 115 | #endif |
| 116 | |
| 117 | #ifndef RLOGW_IF |
| 118 | #define RLOGW_IF(cond, ...) \ |
| 119 | ((__predict_false(cond)) \ |
| 120 | ? ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_WARN, \ |
| 121 | LOG_TAG, __VA_ARGS__)) \ |
| 122 | : (void)0) |
| 123 | #endif |
| 124 | |
| 125 | /* |
| 126 | * Simplified macro to send an error radio log message using current LOG_TAG. |
| 127 | */ |
| 128 | #ifndef RLOGE |
| 129 | #define RLOGE(...) \ |
| 130 | ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_ERROR, LOG_TAG, \ |
| 131 | __VA_ARGS__)) |
| 132 | #endif |
| 133 | |
| 134 | #ifndef RLOGE_IF |
| 135 | #define RLOGE_IF(cond, ...) \ |
| 136 | ((__predict_false(cond)) \ |
| 137 | ? ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_ERROR, \ |
| 138 | LOG_TAG, __VA_ARGS__)) \ |
| 139 | : (void)0) |
| 140 | #endif |