blob: 460d6e7e91724adee49da802dc2f27bde123df57 [file] [log] [blame]
Chris Fries2804ee12017-06-22 14:14:17 -05001/* 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
30#ifndef __LOG_UTIL_H__
31#define __LOG_UTIL_H__
32
Dante Russo07562132017-11-22 15:37:18 -080033#if defined (USE_ANDROID_LOGGING) || defined (ANDROID)
34// Android and LE targets with logcat support
Chris Fries2804ee12017-06-22 14:14:17 -050035#include <utils/Log.h>
Chris Fries2804ee12017-06-22 14:14:17 -050036
Dante Russo07562132017-11-22 15:37:18 -080037#elif defined (USE_GLIB)
38// LE targets with no logcat support
Chris Fries2804ee12017-06-22 14:14:17 -050039#include <stdio.h>
Dante Russo769e9ca2018-03-21 09:09:38 -070040#include <string.h>
Chris Fries2804ee12017-06-22 14:14:17 -050041#include <sys/types.h>
42#include <unistd.h>
Dante Russo769e9ca2018-03-21 09:09:38 -070043#include <cutils/log.h>
Chris Fries2804ee12017-06-22 14:14:17 -050044
45#ifndef LOG_TAG
46#define LOG_TAG "GPS_UTILS"
Dante Russo769e9ca2018-03-21 09:09:38 -070047#endif /* LOG_TAG */
Chris Fries2804ee12017-06-22 14:14:17 -050048
Dante Russo07562132017-11-22 15:37:18 -080049#endif /* #if defined (USE_ANDROID_LOGGING) || defined (ANDROID) */
Chris Fries2804ee12017-06-22 14:14:17 -050050
51#ifdef __cplusplus
52extern "C"
53{
54#endif
55/*=============================================================================
56 *
57 * LOC LOGGER TYPE DECLARATION
58 *
59 *============================================================================*/
60/* LOC LOGGER */
61typedef struct loc_logger_s
62{
63 unsigned long DEBUG_LEVEL;
64 unsigned long TIMESTAMP;
65} loc_logger_s_type;
66
67/*=============================================================================
68 *
69 * EXTERNAL DATA
70 *
71 *============================================================================*/
72extern loc_logger_s_type loc_logger;
73
74// Logging Improvements
75extern const char *loc_logger_boolStr[];
76
77extern const char *boolStr[];
78extern const char VOID_RET[];
79extern const char FROM_AFW[];
80extern const char TO_MODEM[];
81extern const char FROM_MODEM[];
82extern const char TO_AFW[];
83extern const char EXIT_TAG[];
84extern const char ENTRY_TAG[];
85extern const char EXIT_ERROR_TAG[];
86
87/*=============================================================================
88 *
89 * MODULE EXPORTED FUNCTIONS
90 *
91 *============================================================================*/
92extern void loc_logger_init(unsigned long debug, unsigned long timestamp);
93extern char* get_timestamp(char* str, unsigned long buf_size);
94
95#ifndef DEBUG_DMN_LOC_API
96
97/* LOGGING MACROS */
98/*loc_logger.DEBUG_LEVEL is initialized to 0xff in loc_cfg.cpp
99 if that value remains unchanged, it means gps.conf did not
100 provide a value and we default to the initial value to use
101 Android's logging levels*/
102#define IF_LOC_LOGE if((loc_logger.DEBUG_LEVEL >= 1) && (loc_logger.DEBUG_LEVEL <= 5))
103#define IF_LOC_LOGW if((loc_logger.DEBUG_LEVEL >= 2) && (loc_logger.DEBUG_LEVEL <= 5))
104#define IF_LOC_LOGI if((loc_logger.DEBUG_LEVEL >= 3) && (loc_logger.DEBUG_LEVEL <= 5))
105#define IF_LOC_LOGD if((loc_logger.DEBUG_LEVEL >= 4) && (loc_logger.DEBUG_LEVEL <= 5))
106#define IF_LOC_LOGV if((loc_logger.DEBUG_LEVEL >= 5) && (loc_logger.DEBUG_LEVEL <= 5))
107
108#define LOC_LOGE(...) IF_LOC_LOGE { ALOGE(__VA_ARGS__); }
109#define LOC_LOGW(...) IF_LOC_LOGW { ALOGW(__VA_ARGS__); }
110#define LOC_LOGI(...) IF_LOC_LOGI { ALOGI(__VA_ARGS__); }
111#define LOC_LOGD(...) IF_LOC_LOGD { ALOGD(__VA_ARGS__); }
112#define LOC_LOGV(...) IF_LOC_LOGV { ALOGV(__VA_ARGS__); }
113
114#else /* DEBUG_DMN_LOC_API */
115
116#define LOC_LOGE(...) ALOGE(__VA_ARGS__)
117#define LOC_LOGW(...) ALOGW(__VA_ARGS__)
118#define LOC_LOGI(...) ALOGI(__VA_ARGS__)
119#define LOC_LOGD(...) ALOGD(__VA_ARGS__)
120#define LOC_LOGV(...) ALOGV(__VA_ARGS__)
121
122#endif /* DEBUG_DMN_LOC_API */
123
124/*=============================================================================
125 *
126 * LOGGING IMPROVEMENT MACROS
127 *
128 *============================================================================*/
129#define LOG_(LOC_LOG, ID, WHAT, SPEC, VAL) \
130 do { \
131 if (loc_logger.TIMESTAMP) { \
132 char ts[32]; \
133 LOC_LOG("[%s] %s %s line %d " #SPEC, \
134 get_timestamp(ts, sizeof(ts)), ID, WHAT, __LINE__, VAL); \
135 } else { \
136 LOC_LOG("%s %s line %d " #SPEC, \
137 ID, WHAT, __LINE__, VAL); \
138 } \
139 } while(0)
140
141#define LOC_LOG_HEAD(fmt) "%s:%d] " fmt
142#define LOC_LOGv(fmt,...) LOC_LOGV(LOC_LOG_HEAD(fmt), __FUNCTION__, __LINE__, ##__VA_ARGS__)
143#define LOC_LOGw(fmt,...) LOC_LOGW(LOC_LOG_HEAD(fmt), __FUNCTION__, __LINE__, ##__VA_ARGS__)
144#define LOC_LOGd(fmt,...) LOC_LOGD(LOC_LOG_HEAD(fmt), __FUNCTION__, __LINE__, ##__VA_ARGS__)
145#define LOC_LOGe(fmt,...) LOC_LOGE(LOC_LOG_HEAD(fmt), __FUNCTION__, __LINE__, ##__VA_ARGS__)
146
147#define LOG_I(ID, WHAT, SPEC, VAL) LOG_(LOC_LOGI, ID, WHAT, SPEC, VAL)
148#define LOG_V(ID, WHAT, SPEC, VAL) LOG_(LOC_LOGV, ID, WHAT, SPEC, VAL)
149#define LOG_E(ID, WHAT, SPEC, VAL) LOG_(LOC_LOGE, ID, WHAT, SPEC, VAL)
150
151#define ENTRY_LOG() LOG_V(ENTRY_TAG, __FUNCTION__, %s, "")
152#define EXIT_LOG(SPEC, VAL) LOG_V(EXIT_TAG, __FUNCTION__, SPEC, VAL)
153#define EXIT_LOG_WITH_ERROR(SPEC, VAL) \
154 if (VAL != 0) { \
155 LOG_E(EXIT_ERROR_TAG, __FUNCTION__, SPEC, VAL); \
156 } else { \
157 LOG_V(EXIT_TAG, __FUNCTION__, SPEC, VAL); \
158 }
159
160
161// Used for logging callflow from Android Framework
162#define ENTRY_LOG_CALLFLOW() LOG_I(FROM_AFW, __FUNCTION__, %s, "")
163// Used for logging callflow to Modem
164#define EXIT_LOG_CALLFLOW(SPEC, VAL) LOG_I(TO_MODEM, __FUNCTION__, SPEC, VAL)
165// Used for logging callflow from Modem(TO_MODEM, __FUNCTION__, %s, "")
166#define MODEM_LOG_CALLFLOW(SPEC, VAL) LOG_I(FROM_MODEM, __FUNCTION__, SPEC, VAL)
167// Used for logging callflow to Android Framework
168#define CALLBACK_LOG_CALLFLOW(CB, SPEC, VAL) LOG_I(TO_AFW, CB, SPEC, VAL)
169
170#ifdef __cplusplus
171}
172#endif
173
174#endif // __LOG_UTIL_H__