17ec681f3Smrg/*
27ec681f3Smrg * Copyright (C) 2005-2017 The Android Open Source Project
37ec681f3Smrg *
47ec681f3Smrg * Licensed under the Apache License, Version 2.0 (the "License");
57ec681f3Smrg * you may not use this file except in compliance with the License.
67ec681f3Smrg * You may obtain a copy of the License at
77ec681f3Smrg *
87ec681f3Smrg *      http://www.apache.org/licenses/LICENSE-2.0
97ec681f3Smrg *
107ec681f3Smrg * Unless required by applicable law or agreed to in writing, software
117ec681f3Smrg * distributed under the License is distributed on an "AS IS" BASIS,
127ec681f3Smrg * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
137ec681f3Smrg * See the License for the specific language governing permissions and
147ec681f3Smrg * limitations under the License.
157ec681f3Smrg */
167ec681f3Smrg
177ec681f3Smrg#pragma once
187ec681f3Smrg
197ec681f3Smrg#include <android/log.h>
207ec681f3Smrg
217ec681f3Smrg/*
227ec681f3Smrg * Normally we strip the effects of ALOGV (VERBOSE messages),
237ec681f3Smrg * LOG_FATAL and LOG_FATAL_IF (FATAL assert messages) from the
247ec681f3Smrg * release builds be defining NDEBUG.  You can modify this (for
257ec681f3Smrg * example with "#define LOG_NDEBUG 0" at the top of your source
267ec681f3Smrg * file) to change that behavior.
277ec681f3Smrg */
287ec681f3Smrg
297ec681f3Smrg#ifndef LOG_NDEBUG
307ec681f3Smrg#ifdef NDEBUG
317ec681f3Smrg#define LOG_NDEBUG 1
327ec681f3Smrg#else
337ec681f3Smrg#define LOG_NDEBUG 0
347ec681f3Smrg#endif
357ec681f3Smrg#endif
367ec681f3Smrg
377ec681f3Smrg/* --------------------------------------------------------------------- */
387ec681f3Smrg
397ec681f3Smrg#ifndef __predict_false
407ec681f3Smrg#define __predict_false(exp) __builtin_expect((exp) != 0, 0)
417ec681f3Smrg#endif
427ec681f3Smrg
437ec681f3Smrg/*
447ec681f3Smrg * Simplified macro to send a verbose radio log message using current LOG_TAG.
457ec681f3Smrg */
467ec681f3Smrg#ifndef RLOGV
477ec681f3Smrg#define __RLOGV(...)                                                         \
487ec681f3Smrg  ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_VERBOSE, LOG_TAG, \
497ec681f3Smrg                                 __VA_ARGS__))
507ec681f3Smrg#if LOG_NDEBUG
517ec681f3Smrg#define RLOGV(...)          \
527ec681f3Smrg  do {                      \
537ec681f3Smrg    if (0) {                \
547ec681f3Smrg      __RLOGV(__VA_ARGS__); \
557ec681f3Smrg    }                       \
567ec681f3Smrg  } while (0)
577ec681f3Smrg#else
587ec681f3Smrg#define RLOGV(...) __RLOGV(__VA_ARGS__)
597ec681f3Smrg#endif
607ec681f3Smrg#endif
617ec681f3Smrg
627ec681f3Smrg#ifndef RLOGV_IF
637ec681f3Smrg#if LOG_NDEBUG
647ec681f3Smrg#define RLOGV_IF(cond, ...) ((void)0)
657ec681f3Smrg#else
667ec681f3Smrg#define RLOGV_IF(cond, ...)                                                \
677ec681f3Smrg  ((__predict_false(cond))                                                 \
687ec681f3Smrg       ? ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_VERBOSE, \
697ec681f3Smrg                                        LOG_TAG, __VA_ARGS__))             \
707ec681f3Smrg       : (void)0)
717ec681f3Smrg#endif
727ec681f3Smrg#endif
737ec681f3Smrg
747ec681f3Smrg/*
757ec681f3Smrg * Simplified macro to send a debug radio log message using  current LOG_TAG.
767ec681f3Smrg */
777ec681f3Smrg#ifndef RLOGD
787ec681f3Smrg#define RLOGD(...)                                                         \
797ec681f3Smrg  ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_DEBUG, LOG_TAG, \
807ec681f3Smrg                                 __VA_ARGS__))
817ec681f3Smrg#endif
827ec681f3Smrg
837ec681f3Smrg#ifndef RLOGD_IF
847ec681f3Smrg#define RLOGD_IF(cond, ...)                                              \
857ec681f3Smrg  ((__predict_false(cond))                                               \
867ec681f3Smrg       ? ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_DEBUG, \
877ec681f3Smrg                                        LOG_TAG, __VA_ARGS__))           \
887ec681f3Smrg       : (void)0)
897ec681f3Smrg#endif
907ec681f3Smrg
917ec681f3Smrg/*
927ec681f3Smrg * Simplified macro to send an info radio log message using  current LOG_TAG.
937ec681f3Smrg */
947ec681f3Smrg#ifndef RLOGI
957ec681f3Smrg#define RLOGI(...)                                                        \
967ec681f3Smrg  ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_INFO, LOG_TAG, \
977ec681f3Smrg                                 __VA_ARGS__))
987ec681f3Smrg#endif
997ec681f3Smrg
1007ec681f3Smrg#ifndef RLOGI_IF
1017ec681f3Smrg#define RLOGI_IF(cond, ...)                                             \
1027ec681f3Smrg  ((__predict_false(cond))                                              \
1037ec681f3Smrg       ? ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_INFO, \
1047ec681f3Smrg                                        LOG_TAG, __VA_ARGS__))          \
1057ec681f3Smrg       : (void)0)
1067ec681f3Smrg#endif
1077ec681f3Smrg
1087ec681f3Smrg/*
1097ec681f3Smrg * Simplified macro to send a warning radio log message using current LOG_TAG.
1107ec681f3Smrg */
1117ec681f3Smrg#ifndef RLOGW
1127ec681f3Smrg#define RLOGW(...)                                                        \
1137ec681f3Smrg  ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_WARN, LOG_TAG, \
1147ec681f3Smrg                                 __VA_ARGS__))
1157ec681f3Smrg#endif
1167ec681f3Smrg
1177ec681f3Smrg#ifndef RLOGW_IF
1187ec681f3Smrg#define RLOGW_IF(cond, ...)                                             \
1197ec681f3Smrg  ((__predict_false(cond))                                              \
1207ec681f3Smrg       ? ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_WARN, \
1217ec681f3Smrg                                        LOG_TAG, __VA_ARGS__))          \
1227ec681f3Smrg       : (void)0)
1237ec681f3Smrg#endif
1247ec681f3Smrg
1257ec681f3Smrg/*
1267ec681f3Smrg * Simplified macro to send an error radio log message using current LOG_TAG.
1277ec681f3Smrg */
1287ec681f3Smrg#ifndef RLOGE
1297ec681f3Smrg#define RLOGE(...)                                                         \
1307ec681f3Smrg  ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_ERROR, LOG_TAG, \
1317ec681f3Smrg                                 __VA_ARGS__))
1327ec681f3Smrg#endif
1337ec681f3Smrg
1347ec681f3Smrg#ifndef RLOGE_IF
1357ec681f3Smrg#define RLOGE_IF(cond, ...)                                              \
1367ec681f3Smrg  ((__predict_false(cond))                                               \
1377ec681f3Smrg       ? ((void)__android_log_buf_print(LOG_ID_RADIO, ANDROID_LOG_ERROR, \
1387ec681f3Smrg                                        LOG_TAG, __VA_ARGS__))           \
1397ec681f3Smrg       : (void)0)
1407ec681f3Smrg#endif
141