1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/media/omx-plugin/include/froyo/cutils/log.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,446 @@ 1.4 +/* 1.5 + * Copyright (C) 2005 The Android Open Source Project 1.6 + * 1.7 + * Licensed under the Apache License, Version 2.0 (the "License"); 1.8 + * you may not use this file except in compliance with the License. 1.9 + * You may obtain a copy of the License at 1.10 + * 1.11 + * http://www.apache.org/licenses/LICENSE-2.0 1.12 + * 1.13 + * Unless required by applicable law or agreed to in writing, software 1.14 + * distributed under the License is distributed on an "AS IS" BASIS, 1.15 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1.16 + * See the License for the specific language governing permissions and 1.17 + * limitations under the License. 1.18 + */ 1.19 + 1.20 +// 1.21 +// C/C++ logging functions. See the logging documentation for API details. 1.22 +// 1.23 +// We'd like these to be available from C code (in case we import some from 1.24 +// somewhere), so this has a C interface. 1.25 +// 1.26 +// The output will be correct when the log file is shared between multiple 1.27 +// threads and/or multiple processes so long as the operating system 1.28 +// supports O_APPEND. These calls have mutex-protected data structures 1.29 +// and so are NOT reentrant. Do not use LOG in a signal handler. 1.30 +// 1.31 +#ifndef _LIBS_CUTILS_LOG_H 1.32 +#define _LIBS_CUTILS_LOG_H 1.33 + 1.34 +#include <stdio.h> 1.35 +#include <time.h> 1.36 +#include <sys/types.h> 1.37 +#include <unistd.h> 1.38 +#ifdef HAVE_PTHREADS 1.39 +#include <pthread.h> 1.40 +#endif 1.41 +#include <stdarg.h> 1.42 + 1.43 +#include <cutils/uio.h> 1.44 +#include <cutils/logd.h> 1.45 + 1.46 +#ifdef __cplusplus 1.47 +extern "C" { 1.48 +#endif 1.49 + 1.50 +// --------------------------------------------------------------------- 1.51 + 1.52 +/* 1.53 + * Normally we strip LOGV (VERBOSE messages) from release builds. 1.54 + * You can modify this (for example with "#define LOG_NDEBUG 0" 1.55 + * at the top of your source file) to change that behavior. 1.56 + */ 1.57 +#ifndef LOG_NDEBUG 1.58 +#ifdef NDEBUG 1.59 +#define LOG_NDEBUG 1 1.60 +#else 1.61 +#define LOG_NDEBUG 0 1.62 +#endif 1.63 +#endif 1.64 + 1.65 +/* 1.66 + * This is the local tag used for the following simplified 1.67 + * logging macros. You can change this preprocessor definition 1.68 + * before using the other macros to change the tag. 1.69 + */ 1.70 +#ifndef LOG_TAG 1.71 +#define LOG_TAG NULL 1.72 +#endif 1.73 + 1.74 +// --------------------------------------------------------------------- 1.75 + 1.76 +/* 1.77 + * Simplified macro to send a verbose log message using the current LOG_TAG. 1.78 + */ 1.79 +#ifndef LOGV 1.80 +#if LOG_NDEBUG 1.81 +#define LOGV(...) ((void)0) 1.82 +#else 1.83 +#define LOGV(...) ((void)LOG(LOG_VERBOSE, LOG_TAG, __VA_ARGS__)) 1.84 +#endif 1.85 +#endif 1.86 + 1.87 +#define CONDITION(cond) (__builtin_expect((cond)!=0, 0)) 1.88 + 1.89 +#ifndef LOGV_IF 1.90 +#if LOG_NDEBUG 1.91 +#define LOGV_IF(cond, ...) ((void)0) 1.92 +#else 1.93 +#define LOGV_IF(cond, ...) \ 1.94 + ( (CONDITION(cond)) \ 1.95 + ? ((void)LOG(LOG_VERBOSE, LOG_TAG, __VA_ARGS__)) \ 1.96 + : (void)0 ) 1.97 +#endif 1.98 +#endif 1.99 + 1.100 +/* 1.101 + * Simplified macro to send a debug log message using the current LOG_TAG. 1.102 + */ 1.103 +#ifndef LOGD 1.104 +#define LOGD(...) ((void)LOG(LOG_DEBUG, LOG_TAG, __VA_ARGS__)) 1.105 +#endif 1.106 + 1.107 +#ifndef LOGD_IF 1.108 +#define LOGD_IF(cond, ...) \ 1.109 + ( (CONDITION(cond)) \ 1.110 + ? ((void)LOG(LOG_DEBUG, LOG_TAG, __VA_ARGS__)) \ 1.111 + : (void)0 ) 1.112 +#endif 1.113 + 1.114 +/* 1.115 + * Simplified macro to send an info log message using the current LOG_TAG. 1.116 + */ 1.117 +#ifndef LOGI 1.118 +#define LOGI(...) ((void)LOG(LOG_INFO, LOG_TAG, __VA_ARGS__)) 1.119 +#endif 1.120 + 1.121 +#ifndef LOGI_IF 1.122 +#define LOGI_IF(cond, ...) \ 1.123 + ( (CONDITION(cond)) \ 1.124 + ? ((void)LOG(LOG_INFO, LOG_TAG, __VA_ARGS__)) \ 1.125 + : (void)0 ) 1.126 +#endif 1.127 + 1.128 +/* 1.129 + * Simplified macro to send a warning log message using the current LOG_TAG. 1.130 + */ 1.131 +#ifndef LOGW 1.132 +#define LOGW(...) ((void)LOG(LOG_WARN, LOG_TAG, __VA_ARGS__)) 1.133 +#endif 1.134 + 1.135 +#ifndef LOGW_IF 1.136 +#define LOGW_IF(cond, ...) \ 1.137 + ( (CONDITION(cond)) \ 1.138 + ? ((void)LOG(LOG_WARN, LOG_TAG, __VA_ARGS__)) \ 1.139 + : (void)0 ) 1.140 +#endif 1.141 + 1.142 +/* 1.143 + * Simplified macro to send an error log message using the current LOG_TAG. 1.144 + */ 1.145 +#ifndef LOGE 1.146 +#define LOGE(...) ((void)LOG(LOG_ERROR, LOG_TAG, __VA_ARGS__)) 1.147 +#endif 1.148 + 1.149 +#ifndef LOGE_IF 1.150 +#define LOGE_IF(cond, ...) \ 1.151 + ( (CONDITION(cond)) \ 1.152 + ? ((void)LOG(LOG_ERROR, LOG_TAG, __VA_ARGS__)) \ 1.153 + : (void)0 ) 1.154 +#endif 1.155 + 1.156 +// --------------------------------------------------------------------- 1.157 + 1.158 +/* 1.159 + * Conditional based on whether the current LOG_TAG is enabled at 1.160 + * verbose priority. 1.161 + */ 1.162 +#ifndef IF_LOGV 1.163 +#if LOG_NDEBUG 1.164 +#define IF_LOGV() if (false) 1.165 +#else 1.166 +#define IF_LOGV() IF_LOG(LOG_VERBOSE, LOG_TAG) 1.167 +#endif 1.168 +#endif 1.169 + 1.170 +/* 1.171 + * Conditional based on whether the current LOG_TAG is enabled at 1.172 + * debug priority. 1.173 + */ 1.174 +#ifndef IF_LOGD 1.175 +#define IF_LOGD() IF_LOG(LOG_DEBUG, LOG_TAG) 1.176 +#endif 1.177 + 1.178 +/* 1.179 + * Conditional based on whether the current LOG_TAG is enabled at 1.180 + * info priority. 1.181 + */ 1.182 +#ifndef IF_LOGI 1.183 +#define IF_LOGI() IF_LOG(LOG_INFO, LOG_TAG) 1.184 +#endif 1.185 + 1.186 +/* 1.187 + * Conditional based on whether the current LOG_TAG is enabled at 1.188 + * warn priority. 1.189 + */ 1.190 +#ifndef IF_LOGW 1.191 +#define IF_LOGW() IF_LOG(LOG_WARN, LOG_TAG) 1.192 +#endif 1.193 + 1.194 +/* 1.195 + * Conditional based on whether the current LOG_TAG is enabled at 1.196 + * error priority. 1.197 + */ 1.198 +#ifndef IF_LOGE 1.199 +#define IF_LOGE() IF_LOG(LOG_ERROR, LOG_TAG) 1.200 +#endif 1.201 + 1.202 + 1.203 +// --------------------------------------------------------------------- 1.204 + 1.205 +/* 1.206 + * Simplified macro to send a verbose system log message using the current LOG_TAG. 1.207 + */ 1.208 +#ifndef SLOGV 1.209 +#if LOG_NDEBUG 1.210 +#define SLOGV(...) ((void)0) 1.211 +#else 1.212 +#define SLOGV(...) ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_VERBOSE, LOG_TAG, __VA_ARGS__)) 1.213 +#endif 1.214 +#endif 1.215 + 1.216 +#define CONDITION(cond) (__builtin_expect((cond)!=0, 0)) 1.217 + 1.218 +#ifndef SLOGV_IF 1.219 +#if LOG_NDEBUG 1.220 +#define SLOGV_IF(cond, ...) ((void)0) 1.221 +#else 1.222 +#define SLOGV_IF(cond, ...) \ 1.223 + ( (CONDITION(cond)) \ 1.224 + ? ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_VERBOSE, LOG_TAG, __VA_ARGS__)) \ 1.225 + : (void)0 ) 1.226 +#endif 1.227 +#endif 1.228 + 1.229 +/* 1.230 + * Simplified macro to send a debug system log message using the current LOG_TAG. 1.231 + */ 1.232 +#ifndef SLOGD 1.233 +#define SLOGD(...) ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__)) 1.234 +#endif 1.235 + 1.236 +#ifndef SLOGD_IF 1.237 +#define SLOGD_IF(cond, ...) \ 1.238 + ( (CONDITION(cond)) \ 1.239 + ? ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_DEBUG, LOG_TAG, __VA_ARGS__)) \ 1.240 + : (void)0 ) 1.241 +#endif 1.242 + 1.243 +/* 1.244 + * Simplified macro to send an info system log message using the current LOG_TAG. 1.245 + */ 1.246 +#ifndef SLOGI 1.247 +#define SLOGI(...) ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__)) 1.248 +#endif 1.249 + 1.250 +#ifndef SLOGI_IF 1.251 +#define SLOGI_IF(cond, ...) \ 1.252 + ( (CONDITION(cond)) \ 1.253 + ? ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_INFO, LOG_TAG, __VA_ARGS__)) \ 1.254 + : (void)0 ) 1.255 +#endif 1.256 + 1.257 +/* 1.258 + * Simplified macro to send a warning system log message using the current LOG_TAG. 1.259 + */ 1.260 +#ifndef SLOGW 1.261 +#define SLOGW(...) ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_WARN, LOG_TAG, __VA_ARGS__)) 1.262 +#endif 1.263 + 1.264 +#ifndef SLOGW_IF 1.265 +#define SLOGW_IF(cond, ...) \ 1.266 + ( (CONDITION(cond)) \ 1.267 + ? ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_WARN, LOG_TAG, __VA_ARGS__)) \ 1.268 + : (void)0 ) 1.269 +#endif 1.270 + 1.271 +/* 1.272 + * Simplified macro to send an error system log message using the current LOG_TAG. 1.273 + */ 1.274 +#ifndef SLOGE 1.275 +#define SLOGE(...) ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__)) 1.276 +#endif 1.277 + 1.278 +#ifndef SLOGE_IF 1.279 +#define SLOGE_IF(cond, ...) \ 1.280 + ( (CONDITION(cond)) \ 1.281 + ? ((void)__android_log_buf_print(LOG_ID_SYSTEM, ANDROID_LOG_ERROR, LOG_TAG, __VA_ARGS__)) \ 1.282 + : (void)0 ) 1.283 +#endif 1.284 + 1.285 + 1.286 + 1.287 +// --------------------------------------------------------------------- 1.288 + 1.289 +/* 1.290 + * Log a fatal error. If the given condition fails, this stops program 1.291 + * execution like a normal assertion, but also generating the given message. 1.292 + * It is NOT stripped from release builds. Note that the condition test 1.293 + * is -inverted- from the normal assert() semantics. 1.294 + */ 1.295 +#define LOG_ALWAYS_FATAL_IF(cond, ...) \ 1.296 + ( (CONDITION(cond)) \ 1.297 + ? ((void)android_printAssert(#cond, LOG_TAG, __VA_ARGS__)) \ 1.298 + : (void)0 ) 1.299 + 1.300 +#define LOG_ALWAYS_FATAL(...) \ 1.301 + ( ((void)android_printAssert(NULL, LOG_TAG, __VA_ARGS__)) ) 1.302 + 1.303 +/* 1.304 + * Versions of LOG_ALWAYS_FATAL_IF and LOG_ALWAYS_FATAL that 1.305 + * are stripped out of release builds. 1.306 + */ 1.307 +#if LOG_NDEBUG 1.308 + 1.309 +#define LOG_FATAL_IF(cond, ...) ((void)0) 1.310 +#define LOG_FATAL(...) ((void)0) 1.311 + 1.312 +#else 1.313 + 1.314 +#define LOG_FATAL_IF(cond, ...) LOG_ALWAYS_FATAL_IF(cond, __VA_ARGS__) 1.315 +#define LOG_FATAL(...) LOG_ALWAYS_FATAL(__VA_ARGS__) 1.316 + 1.317 +#endif 1.318 + 1.319 +/* 1.320 + * Assertion that generates a log message when the assertion fails. 1.321 + * Stripped out of release builds. Uses the current LOG_TAG. 1.322 + */ 1.323 +#define LOG_ASSERT(cond, ...) LOG_FATAL_IF(!(cond), __VA_ARGS__) 1.324 +//#define LOG_ASSERT(cond) LOG_FATAL_IF(!(cond), "Assertion failed: " #cond) 1.325 + 1.326 +// --------------------------------------------------------------------- 1.327 + 1.328 +/* 1.329 + * Basic log message macro. 1.330 + * 1.331 + * Example: 1.332 + * LOG(LOG_WARN, NULL, "Failed with error %d", errno); 1.333 + * 1.334 + * The second argument may be NULL or "" to indicate the "global" tag. 1.335 + */ 1.336 +#ifndef LOG 1.337 +#define LOG(priority, tag, ...) \ 1.338 + LOG_PRI(ANDROID_##priority, tag, __VA_ARGS__) 1.339 +#endif 1.340 + 1.341 +/* 1.342 + * Log macro that allows you to specify a number for the priority. 1.343 + */ 1.344 +#ifndef LOG_PRI 1.345 +#define LOG_PRI(priority, tag, ...) \ 1.346 + android_printLog(priority, tag, __VA_ARGS__) 1.347 +#endif 1.348 + 1.349 +/* 1.350 + * Log macro that allows you to pass in a varargs ("args" is a va_list). 1.351 + */ 1.352 +#ifndef LOG_PRI_VA 1.353 +#define LOG_PRI_VA(priority, tag, fmt, args) \ 1.354 + android_vprintLog(priority, NULL, tag, fmt, args) 1.355 +#endif 1.356 + 1.357 +/* 1.358 + * Conditional given a desired logging priority and tag. 1.359 + */ 1.360 +#ifndef IF_LOG 1.361 +#define IF_LOG(priority, tag) \ 1.362 + if (android_testLog(ANDROID_##priority, tag)) 1.363 +#endif 1.364 + 1.365 +// --------------------------------------------------------------------- 1.366 + 1.367 +/* 1.368 + * Event logging. 1.369 + */ 1.370 + 1.371 +/* 1.372 + * Event log entry types. These must match up with the declarations in 1.373 + * java/android/android/util/EventLog.java. 1.374 + */ 1.375 +typedef enum { 1.376 + EVENT_TYPE_INT = 0, 1.377 + EVENT_TYPE_LONG = 1, 1.378 + EVENT_TYPE_STRING = 2, 1.379 + EVENT_TYPE_LIST = 3, 1.380 +} AndroidEventLogType; 1.381 + 1.382 + 1.383 +#define LOG_EVENT_INT(_tag, _value) { \ 1.384 + int intBuf = _value; \ 1.385 + (void) android_btWriteLog(_tag, EVENT_TYPE_INT, &intBuf, \ 1.386 + sizeof(intBuf)); \ 1.387 + } 1.388 +#define LOG_EVENT_LONG(_tag, _value) { \ 1.389 + long long longBuf = _value; \ 1.390 + (void) android_btWriteLog(_tag, EVENT_TYPE_LONG, &longBuf, \ 1.391 + sizeof(longBuf)); \ 1.392 + } 1.393 +#define LOG_EVENT_STRING(_tag, _value) \ 1.394 + ((void) 0) /* not implemented -- must combine len with string */ 1.395 +/* TODO: something for LIST */ 1.396 + 1.397 +/* 1.398 + * =========================================================================== 1.399 + * 1.400 + * The stuff in the rest of this file should not be used directly. 1.401 + */ 1.402 + 1.403 +#define android_printLog(prio, tag, fmt...) \ 1.404 + __android_log_print(prio, tag, fmt) 1.405 + 1.406 +#define android_vprintLog(prio, cond, tag, fmt...) \ 1.407 + __android_log_vprint(prio, tag, fmt) 1.408 + 1.409 +#define android_printAssert(cond, tag, fmt...) \ 1.410 + __android_log_assert(cond, tag, fmt) 1.411 + 1.412 +#define android_writeLog(prio, tag, text) \ 1.413 + __android_log_write(prio, tag, text) 1.414 + 1.415 +#define android_bWriteLog(tag, payload, len) \ 1.416 + __android_log_bwrite(tag, payload, len) 1.417 +#define android_btWriteLog(tag, type, payload, len) \ 1.418 + __android_log_btwrite(tag, type, payload, len) 1.419 + 1.420 +// TODO: remove these prototypes and their users 1.421 +#define android_testLog(prio, tag) (1) 1.422 +#define android_writevLog(vec,num) do{}while(0) 1.423 +#define android_write1Log(str,len) do{}while (0) 1.424 +#define android_setMinPriority(tag, prio) do{}while(0) 1.425 +//#define android_logToCallback(func) do{}while(0) 1.426 +#define android_logToFile(tag, file) (0) 1.427 +#define android_logToFd(tag, fd) (0) 1.428 + 1.429 +typedef enum { 1.430 + LOG_ID_MAIN = 0, 1.431 + LOG_ID_RADIO = 1, 1.432 + LOG_ID_EVENTS = 2, 1.433 + LOG_ID_SYSTEM = 3, 1.434 + 1.435 + LOG_ID_MAX 1.436 +} log_id_t; 1.437 + 1.438 +/* 1.439 + * Send a simple string to the log. 1.440 + */ 1.441 +int __android_log_buf_write(int bufID, int prio, const char *tag, const char *text); 1.442 +int __android_log_buf_print(int bufID, int prio, const char *tag, const char *fmt, ...); 1.443 + 1.444 + 1.445 +#ifdef __cplusplus 1.446 +} 1.447 +#endif 1.448 + 1.449 +#endif // _LIBS_CUTILS_LOG_H