Home | History | Annotate | Download | only in include
      1 /* Copyright (c) 2011-2014 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 #ifndef __PLATFORM_LIB_LOG_UTIL_H__
     30 #define __PLATFORM_LIB_LOG_UTIL_H__
     31 
     32 #include "platform_lib_macros.h"
     33 
     34 #ifndef USE_GLIB
     35 #include <log_util.h>
     36 #else
     37 
     38 #include <stdio.h>
     39 #include <stdlib.h>
     40 #include <string.h>
     41 #include <sys/types.h>
     42 #include <time.h>
     43 #include <unistd.h>
     44 
     45 #ifndef LOG_TAG
     46 #define LOG_TAG "GPS_UTILS"
     47 #endif /* LOG_TAG */
     48 
     49 #ifdef __cplusplus
     50 extern "C"
     51 {
     52 #endif
     53 /*=============================================================================
     54  *
     55  *                         LOC LOGGER TYPE DECLARATION
     56  *
     57  *============================================================================*/
     58 /* LOC LOGGER */
     59 typedef struct loc_logger_s
     60 {
     61   unsigned long  DEBUG_LEVEL;
     62   unsigned long  TIMESTAMP;
     63 } loc_logger_s_type;
     64 
     65 /*=============================================================================
     66  *
     67  *                               EXTERNAL DATA
     68  *
     69  *============================================================================*/
     70 extern loc_logger_s_type loc_logger;
     71 
     72 // Logging Improvements
     73 extern const char *loc_logger_boolStr[];
     74 
     75 extern const char *boolStr[];
     76 extern const char VOID_RET[];
     77 extern const char FROM_AFW[];
     78 extern const char TO_MODEM[];
     79 extern const char FROM_MODEM[];
     80 extern const char TO_AFW[];
     81 extern const char EXIT_TAG[];
     82 extern const char ENTRY_TAG[];
     83 extern const char EXIT_ERROR_TAG[];
     84 
     85 /*=============================================================================
     86  *
     87  *                        MODULE EXPORTED FUNCTIONS
     88  *
     89  *============================================================================*/
     90 void loc_logger_init(unsigned long debug, unsigned long timestamp);
     91 char* get_timestamp(char* str, unsigned long buf_size);
     92 
     93 #ifndef DEBUG_DMN_LOC_API
     94 
     95 /* LOGGING MACROS */
     96 /*loc_logger.DEBUG_LEVEL is initialized to 0xff in loc_cfg.cpp
     97   if that value remains unchanged, it means gps.conf did not
     98   provide a value and we default to the initial value to use
     99   Android's logging levels*/
    100 #define IF_LOC_LOGE if((loc_logger.DEBUG_LEVEL >= 1) && (loc_logger.DEBUG_LEVEL <= 5))
    101 
    102 #define IF_LOC_LOGW if((loc_logger.DEBUG_LEVEL >= 2) && (loc_logger.DEBUG_LEVEL <= 5))
    103 
    104 #define IF_LOC_LOGI if((loc_logger.DEBUG_LEVEL >= 3) && (loc_logger.DEBUG_LEVEL <= 5))
    105 
    106 #define IF_LOC_LOGD if((loc_logger.DEBUG_LEVEL >= 4) && (loc_logger.DEBUG_LEVEL <= 5))
    107 
    108 #define IF_LOC_LOGV if((loc_logger.DEBUG_LEVEL >= 5) && (loc_logger.DEBUG_LEVEL <= 5))
    109 
    110 #define LOC_LOGE(...) \
    111 IF_LOC_LOGE { ALOGE("E/" __VA_ARGS__); } \
    112 else if (loc_logger.DEBUG_LEVEL == 0xff) { ALOGE("E/" __VA_ARGS__); }
    113 
    114 #define LOC_LOGW(...) \
    115 IF_LOC_LOGW { ALOGE("W/" __VA_ARGS__); }  \
    116 else if (loc_logger.DEBUG_LEVEL == 0xff) { ALOGW("W/" __VA_ARGS__); }
    117 
    118 #define LOC_LOGI(...) \
    119 IF_LOC_LOGI { ALOGE("I/" __VA_ARGS__); }   \
    120 else if (loc_logger.DEBUG_LEVEL == 0xff) { ALOGI("I/" __VA_ARGS__); }
    121 
    122 #define LOC_LOGD(...) \
    123 IF_LOC_LOGD { ALOGE("D/" __VA_ARGS__); }   \
    124 else if (loc_logger.DEBUG_LEVEL == 0xff) { ALOGD("D/" __VA_ARGS__); }
    125 
    126 #define LOC_LOGV(...) \
    127 IF_LOC_LOGV { ALOGE("V/" __VA_ARGS__); }   \
    128 else if (loc_logger.DEBUG_LEVEL == 0xff) { ALOGV("V/" __VA_ARGS__); }
    129 
    130 #else /* DEBUG_DMN_LOC_API */
    131 
    132 #define LOC_LOGE(...) ALOGE("E/" __VA_ARGS__)
    133 
    134 #define LOC_LOGW(...) ALOGW("W/" __VA_ARGS__)
    135 
    136 #define LOC_LOGI(...) ALOGI("I/" __VA_ARGS__)
    137 
    138 #define LOC_LOGD(...) ALOGD("D/" __VA_ARGS__)
    139 
    140 #define LOC_LOGV(...) ALOGV("V/" __VA_ARGS__)
    141 
    142 #endif /* DEBUG_DMN_LOC_API */
    143 
    144 /*=============================================================================
    145  *
    146  *                          LOGGING IMPROVEMENT MACROS
    147  *
    148  *============================================================================*/
    149 #define LOG_(LOC_LOG, ID, WHAT, SPEC, VAL)                                    \
    150     do {                                                                      \
    151         if (loc_logger.TIMESTAMP) {                                           \
    152             char ts[32];                                                      \
    153             LOC_LOG("[%s] %s %s line %d " #SPEC,                              \
    154                      get_timestamp(ts, sizeof(ts)), ID, WHAT, __LINE__, VAL); \
    155         } else {                                                              \
    156             LOC_LOG("%s %s line %d " #SPEC,                                   \
    157                      ID, WHAT, __LINE__, VAL);                                \
    158         }                                                                     \
    159     } while(0)
    160 
    161 #define LOC_LOG_HEAD(tag,fmt) "%s:%d][" tag "] " fmt "\n"
    162 #define LOC_LOGv(tag,fmt,...) LOC_LOGV(LOC_LOG_HEAD(tag,fmt), __func__, __LINE__, ##__VA_ARGS__)
    163 #define LOC_LOGw(tag,fmt,...) LOC_LOGW(LOC_LOG_HEAD(tag,fmt), __func__, __LINE__, ##__VA_ARGS__)
    164 #define LOC_LOGd(tag,fmt,...) LOC_LOGD(LOC_LOG_HEAD(tag,fmt), __func__, __LINE__, ##__VA_ARGS__)
    165 #define LOC_LOGe(tag,fmt,...) LOC_LOGE(LOC_LOG_HEAD(tag,fmt), __func__, __LINE__, ##__VA_ARGS__)
    166 
    167 #define LOG_I(ID, WHAT, SPEC, VAL) LOG_(LOC_LOGI, ID, WHAT, SPEC, VAL)
    168 #define LOG_V(ID, WHAT, SPEC, VAL) LOG_(LOC_LOGV, ID, WHAT, SPEC, VAL)
    169 #define LOG_E(ID, WHAT, SPEC, VAL) LOG_(LOC_LOGE, ID, WHAT, SPEC, VAL)
    170 
    171 #define ENTRY_LOG() LOG_V(ENTRY_TAG, __func__, %s, "")
    172 #define EXIT_LOG(SPEC, VAL) LOG_V(EXIT_TAG, __func__, SPEC, VAL)
    173 #define EXIT_LOG_WITH_ERROR(SPEC, VAL)                       \
    174     if (VAL != 0) {                                          \
    175         LOG_E(EXIT_ERROR_TAG, __func__, SPEC, VAL);          \
    176     } else {                                                 \
    177         LOG_V(EXIT_TAG, __func__, SPEC, VAL);                \
    178     }
    179 
    180 
    181 // Used for logging callflow from Android Framework
    182 #define ENTRY_LOG_CALLFLOW() LOG_I(FROM_AFW, __func__, %s, "")
    183 // Used for logging callflow to Modem
    184 #define EXIT_LOG_CALLFLOW(SPEC, VAL) LOG_I(TO_MODEM, __func__, SPEC, VAL)
    185 // Used for logging callflow from Modem(TO_MODEM, __func__, %s, "")
    186 #define MODEM_LOG_CALLFLOW(SPEC, VAL) LOG_I(FROM_MODEM, __func__, SPEC, VAL)
    187 // Used for logging callflow to Android Framework
    188 #define CALLBACK_LOG_CALLFLOW(CB, SPEC, VAL) LOG_I(TO_AFW, CB, SPEC, VAL)
    189 
    190 #ifdef __cplusplus
    191 }
    192 #endif
    193 
    194 #endif /* USE_GLIB */
    195 
    196 #endif /* __PLATFORM_LIB_LOG_UTIL_H__ */
    197