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