1/* Copyright (c) 2011 The Linux Foundation. All rights reserved. 2 * 3 * Redistribution and use in source and binary forms, with or without 4 * modification, are permitted provided that the following conditions are 5 * met: 6 * * Redistributions of source code must retain the above copyright 7 * notice, this list of conditions and the following disclaimer. 8 * * Redistributions in binary form must reproduce the above 9 * copyright notice, this list of conditions and the following 10 * disclaimer in the documentation and/or other materials provided 11 * with the distribution. 12 * * Neither the name of The Linux Foundation nor the names of its 13 * contributors may be used to endorse or promote products derived 14 * from this software without specific prior written permission. 15 * 16 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED 17 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 18 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT 19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS 20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 23 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 24 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 25 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN 26 * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 * 28 */ 29 30#ifndef __LOG_UTIL_H__ 31#define __LOG_UTIL_H__ 32 33#ifndef USE_GLIB 34#include <utils/Log.h> 35#endif /* USE_GLIB */ 36 37#ifdef USE_GLIB 38 39#include <stdio.h> 40#include <sys/types.h> 41#include <unistd.h> 42 43#ifndef LOG_TAG 44#define LOG_TAG "GPS_UTILS" 45 46#endif // LOG_TAG 47 48#endif /* USE_GLIB */ 49 50#ifdef __cplusplus 51extern "C" 52{ 53#endif 54/*============================================================================= 55 * 56 * LOC LOGGER TYPE DECLARATION 57 * 58 *============================================================================*/ 59/* LOC LOGGER */ 60typedef struct loc_logger_s 61{ 62 unsigned long DEBUG_LEVEL; 63 unsigned long TIMESTAMP; 64} loc_logger_s_type; 65 66/*============================================================================= 67 * 68 * EXTERNAL DATA 69 * 70 *============================================================================*/ 71extern loc_logger_s_type loc_logger; 72 73// Logging Improvements 74extern const char *loc_logger_boolStr[]; 75 76extern const char *boolStr[]; 77extern const char VOID_RET[]; 78extern const char FROM_AFW[]; 79extern const char TO_MODEM[]; 80extern const char FROM_MODEM[]; 81extern const char TO_AFW[]; 82extern const char EXIT_TAG[]; 83extern const char ENTRY_TAG[]; 84/*============================================================================= 85 * 86 * MODULE EXPORTED FUNCTIONS 87 * 88 *============================================================================*/ 89extern void loc_logger_init(unsigned long debug, unsigned long timestamp); 90extern char* get_timestamp(char* str, unsigned long buf_size); 91 92#ifndef DEBUG_DMN_LOC_API 93 94/* LOGGING MACROS */ 95/*loc_logger.DEBUG_LEVEL is initialized to 0xff in loc_cfg.cpp 96 if that value remains unchanged, it means gps.conf did not 97 provide a value and we default to the initial value to use 98 Android's logging levels*/ 99#define LOC_LOGE(...) \ 100if ((loc_logger.DEBUG_LEVEL >= 1) && (loc_logger.DEBUG_LEVEL <= 5)) { ALOGE("W/"__VA_ARGS__); } \ 101else if (loc_logger.DEBUG_LEVEL == 0xff) { ALOGE("W/"__VA_ARGS__); } 102 103#define LOC_LOGW(...) \ 104if ((loc_logger.DEBUG_LEVEL >= 2) && (loc_logger.DEBUG_LEVEL <= 5)) { ALOGE("W/"__VA_ARGS__); } \ 105else if (loc_logger.DEBUG_LEVEL == 0xff) { ALOGW("W/"__VA_ARGS__); } 106 107#define LOC_LOGI(...) \ 108if ((loc_logger.DEBUG_LEVEL >= 3) && (loc_logger.DEBUG_LEVEL <= 5)) { ALOGE("I/"__VA_ARGS__); } \ 109else if (loc_logger.DEBUG_LEVEL == 0xff) { ALOGI("I/"__VA_ARGS__); } 110 111#define LOC_LOGD(...) \ 112if ((loc_logger.DEBUG_LEVEL >= 4) && (loc_logger.DEBUG_LEVEL <= 5)) { ALOGE("D/"__VA_ARGS__); } \ 113else if (loc_logger.DEBUG_LEVEL == 0xff) { ALOGD("D/"__VA_ARGS__); } 114 115#define LOC_LOGV(...) \ 116if ((loc_logger.DEBUG_LEVEL >= 5) && (loc_logger.DEBUG_LEVEL <= 5)) { ALOGE("V/"__VA_ARGS__); } \ 117else if (loc_logger.DEBUG_LEVEL == 0xff) { ALOGV("V/"__VA_ARGS__); } 118 119#else /* DEBUG_DMN_LOC_API */ 120 121#define LOC_LOGE(...) ALOGE("E/"__VA_ARGS__) 122 123#define LOC_LOGW(...) ALOGW("W/"__VA_ARGS__) 124 125#define LOC_LOGI(...) ALOGI("I/"__VA_ARGS__) 126 127#define LOC_LOGD(...) ALOGD("D/"__VA_ARGS__) 128 129#define LOC_LOGV(...) ALOGV("V/"__VA_ARGS__) 130 131#endif /* DEBUG_DMN_LOC_API */ 132 133/*============================================================================= 134 * 135 * LOGGING IMPROVEMENT MACROS 136 * 137 *============================================================================*/ 138#define LOG_(LOC_LOG, ID, WHAT, SPEC, VAL) \ 139 do { \ 140 if (loc_logger.TIMESTAMP) { \ 141 char ts[32]; \ 142 LOC_LOG("[%s] %s %s line %d " #SPEC, \ 143 get_timestamp(ts, sizeof(ts)), ID, WHAT, __LINE__, VAL); \ 144 } else { \ 145 LOC_LOG("%s %s line %d " #SPEC, \ 146 ID, WHAT, __LINE__, VAL); \ 147 } \ 148 } while(0) 149 150 151#define LOG_I(ID, WHAT, SPEC, VAL) LOG_(LOC_LOGI, ID, WHAT, SPEC, VAL) 152#define LOG_V(ID, WHAT, SPEC, VAL) LOG_(LOC_LOGV, ID, WHAT, SPEC, VAL) 153 154#define ENTRY_LOG() LOG_V(ENTRY_TAG, __func__, %s, "") 155#define EXIT_LOG(SPEC, VAL) LOG_V(EXIT_TAG, __func__, SPEC, VAL) 156 157 158// Used for logging callflow from Android Framework 159#define ENTRY_LOG_CALLFLOW() LOG_I(FROM_AFW, __func__, %s, "") 160// Used for logging callflow to Modem 161#define EXIT_LOG_CALLFLOW(SPEC, VAL) LOG_I(TO_MODEM, __func__, SPEC, VAL) 162// Used for logging callflow from Modem(TO_MODEM, __func__, %s, "") 163#define MODEM_LOG_CALLFLOW(SPEC, VAL) LOG_I(FROM_MODEM, __func__, SPEC, VAL) 164// Used for logging callflow to Android Framework 165#define CALLBACK_LOG_CALLFLOW(CB, SPEC, VAL) LOG_I(TO_AFW, CB, SPEC, VAL) 166 167#ifdef __cplusplus 168} 169#endif 170 171#endif // __LOG_UTIL_H__ 172