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 #ifndef _LIBS_LOG_LOG_RADIO_H
18 #define _LIBS_LOG_LOG_RADIO_H
19 
20 #include <android/log.h>
21 #include <log/log_id.h>
22 
23 /*
24  * Normally we strip the effects of ALOGV (VERBOSE messages),
25  * LOG_FATAL and LOG_FATAL_IF (FATAL assert messages) from the
26  * release builds be defining NDEBUG.  You can modify this (for
27  * example with "#define LOG_NDEBUG 0" at the top of your source
28  * file) to change that behavior.
29  */
30 
31 #ifndef LOG_NDEBUG
32 #ifdef NDEBUG
33 #define LOG_NDEBUG 1
34 #else
35 #define LOG_NDEBUG 0
36 #endif
37 #endif
38 
39 /* --------------------------------------------------------------------- */
40 
41 #ifndef __predict_false
42 #define __predict_false(exp) __builtin_expect((exp) != 0, 0)
43 #endif
44 
45 /*
46  * Simplified macro to send a verbose radio log message using current LOG_TAG.
47  */
48 #ifndef RLOGV
49 #define __RLOGV(...)                                                         \
50   ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_VERBOSE, LOG_TAG, \
51                                  __VA_ARGS__))
52 #if LOG_NDEBUG
53 #define RLOGV(...)          \
54   do {                      \
55     if (0) {                \
56       __RLOGV(__VA_ARGS__); \
57     }                       \
58   } while (0)
59 #else
60 #define RLOGV(...) __RLOGV(__VA_ARGS__)
61 #endif
62 #endif
63 
64 #ifndef RLOGV_IF
65 #if LOG_NDEBUG
66 #define RLOGV_IF(cond, ...) ((void)0)
67 #else
68 #define RLOGV_IF(cond, ...)                                                \
69   ((__predict_false(cond))                                                 \
70        ? ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_VERBOSE, \
71                                         LOG_TAG, __VA_ARGS__))             \
72        : (void)0)
73 #endif
74 #endif
75 
76 /*
77  * Simplified macro to send a debug radio log message using  current LOG_TAG.
78  */
79 #ifndef RLOGD
80 #define RLOGD(...)                                                         \
81   ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_DEBUG, LOG_TAG, \
82                                  __VA_ARGS__))
83 #endif
84 
85 #ifndef RLOGD_IF
86 #define RLOGD_IF(cond, ...)                                              \
87   ((__predict_false(cond))                                               \
88        ? ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_DEBUG, \
89                                         LOG_TAG, __VA_ARGS__))           \
90        : (void)0)
91 #endif
92 
93 /*
94  * Simplified macro to send an info radio log message using  current LOG_TAG.
95  */
96 #ifndef RLOGI
97 #define RLOGI(...)                                                        \
98   ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_INFO, LOG_TAG, \
99                                  __VA_ARGS__))
100 #endif
101 
102 #ifndef RLOGI_IF
103 #define RLOGI_IF(cond, ...)                                             \
104   ((__predict_false(cond))                                              \
105        ? ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_INFO, \
106                                         LOG_TAG, __VA_ARGS__))          \
107        : (void)0)
108 #endif
109 
110 /*
111  * Simplified macro to send a warning radio log message using current LOG_TAG.
112  */
113 #ifndef RLOGW
114 #define RLOGW(...)                                                        \
115   ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_WARN, LOG_TAG, \
116                                  __VA_ARGS__))
117 #endif
118 
119 #ifndef RLOGW_IF
120 #define RLOGW_IF(cond, ...)                                             \
121   ((__predict_false(cond))                                              \
122        ? ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_WARN, \
123                                         LOG_TAG, __VA_ARGS__))          \
124        : (void)0)
125 #endif
126 
127 /*
128  * Simplified macro to send an error radio log message using current LOG_TAG.
129  */
130 #ifndef RLOGE
131 #define RLOGE(...)                                                         \
132   ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_ERROR, LOG_TAG, \
133                                  __VA_ARGS__))
134 #endif
135 
136 #ifndef RLOGE_IF
137 #define RLOGE_IF(cond, ...)                                              \
138   ((__predict_false(cond))                                               \
139        ? ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_ERROR, \
140                                         LOG_TAG, __VA_ARGS__))           \
141        : (void)0)
142 #endif
143 
144 #endif /* _LIBS_LOG_LOG_RADIO_H */
145