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