1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/media/omx-plugin/include/ics/cutils/log.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,482 @@ 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 +#ifndef LOG_ALWAYS_FATAL_IF 1.296 +#define LOG_ALWAYS_FATAL_IF(cond, ...) \ 1.297 + ( (CONDITION(cond)) \ 1.298 + ? ((void)android_printAssert(#cond, LOG_TAG, ## __VA_ARGS__)) \ 1.299 + : (void)0 ) 1.300 +#endif 1.301 + 1.302 +#ifndef LOG_ALWAYS_FATAL 1.303 +#define LOG_ALWAYS_FATAL(...) \ 1.304 + ( ((void)android_printAssert(NULL, LOG_TAG, ## __VA_ARGS__)) ) 1.305 +#endif 1.306 + 1.307 +/* 1.308 + * Versions of LOG_ALWAYS_FATAL_IF and LOG_ALWAYS_FATAL that 1.309 + * are stripped out of release builds. 1.310 + */ 1.311 +#if LOG_NDEBUG 1.312 + 1.313 +#ifndef LOG_FATAL_IF 1.314 +#define LOG_FATAL_IF(cond, ...) ((void)0) 1.315 +#endif 1.316 +#ifndef LOG_FATAL 1.317 +#define LOG_FATAL(...) ((void)0) 1.318 +#endif 1.319 + 1.320 +#else 1.321 + 1.322 +#ifndef LOG_FATAL_IF 1.323 +#define LOG_FATAL_IF(cond, ...) LOG_ALWAYS_FATAL_IF(cond, ## __VA_ARGS__) 1.324 +#endif 1.325 +#ifndef LOG_FATAL 1.326 +#define LOG_FATAL(...) LOG_ALWAYS_FATAL(__VA_ARGS__) 1.327 +#endif 1.328 + 1.329 +#endif 1.330 + 1.331 +/* 1.332 + * Assertion that generates a log message when the assertion fails. 1.333 + * Stripped out of release builds. Uses the current LOG_TAG. 1.334 + */ 1.335 +#ifndef LOG_ASSERT 1.336 +#define LOG_ASSERT(cond, ...) LOG_FATAL_IF(!(cond), ## __VA_ARGS__) 1.337 +//#define LOG_ASSERT(cond) LOG_FATAL_IF(!(cond), "Assertion failed: " #cond) 1.338 +#endif 1.339 + 1.340 +// --------------------------------------------------------------------- 1.341 + 1.342 +/* 1.343 + * Basic log message macro. 1.344 + * 1.345 + * Example: 1.346 + * LOG(LOG_WARN, NULL, "Failed with error %d", errno); 1.347 + * 1.348 + * The second argument may be NULL or "" to indicate the "global" tag. 1.349 + */ 1.350 +#ifndef LOG 1.351 +#define LOG(priority, tag, ...) \ 1.352 + LOG_PRI(ANDROID_##priority, tag, __VA_ARGS__) 1.353 +#endif 1.354 + 1.355 +/* 1.356 + * Log macro that allows you to specify a number for the priority. 1.357 + */ 1.358 +#ifndef LOG_PRI 1.359 +#define LOG_PRI(priority, tag, ...) \ 1.360 + android_printLog(priority, tag, __VA_ARGS__) 1.361 +#endif 1.362 + 1.363 +/* 1.364 + * Log macro that allows you to pass in a varargs ("args" is a va_list). 1.365 + */ 1.366 +#ifndef LOG_PRI_VA 1.367 +#define LOG_PRI_VA(priority, tag, fmt, args) \ 1.368 + android_vprintLog(priority, NULL, tag, fmt, args) 1.369 +#endif 1.370 + 1.371 +/* 1.372 + * Conditional given a desired logging priority and tag. 1.373 + */ 1.374 +#ifndef IF_LOG 1.375 +#define IF_LOG(priority, tag) \ 1.376 + if (android_testLog(ANDROID_##priority, tag)) 1.377 +#endif 1.378 + 1.379 +// --------------------------------------------------------------------- 1.380 + 1.381 +/* 1.382 + * Event logging. 1.383 + */ 1.384 + 1.385 +/* 1.386 + * Event log entry types. These must match up with the declarations in 1.387 + * java/android/android/util/EventLog.java. 1.388 + */ 1.389 +typedef enum { 1.390 + EVENT_TYPE_INT = 0, 1.391 + EVENT_TYPE_LONG = 1, 1.392 + EVENT_TYPE_STRING = 2, 1.393 + EVENT_TYPE_LIST = 3, 1.394 +} AndroidEventLogType; 1.395 + 1.396 + 1.397 +#ifndef LOG_EVENT_INT 1.398 +#define LOG_EVENT_INT(_tag, _value) { \ 1.399 + int intBuf = _value; \ 1.400 + (void) android_btWriteLog(_tag, EVENT_TYPE_INT, &intBuf, \ 1.401 + sizeof(intBuf)); \ 1.402 + } 1.403 +#endif 1.404 +#ifndef LOG_EVENT_LONG 1.405 +#define LOG_EVENT_LONG(_tag, _value) { \ 1.406 + long long longBuf = _value; \ 1.407 + (void) android_btWriteLog(_tag, EVENT_TYPE_LONG, &longBuf, \ 1.408 + sizeof(longBuf)); \ 1.409 + } 1.410 +#endif 1.411 +#ifndef LOG_EVENT_STRING 1.412 +#define LOG_EVENT_STRING(_tag, _value) \ 1.413 + ((void) 0) /* not implemented -- must combine len with string */ 1.414 +#endif 1.415 +/* TODO: something for LIST */ 1.416 + 1.417 +/* 1.418 + * =========================================================================== 1.419 + * 1.420 + * The stuff in the rest of this file should not be used directly. 1.421 + */ 1.422 + 1.423 +#define android_printLog(prio, tag, fmt...) \ 1.424 + __android_log_print(prio, tag, fmt) 1.425 + 1.426 +#define android_vprintLog(prio, cond, tag, fmt...) \ 1.427 + __android_log_vprint(prio, tag, fmt) 1.428 + 1.429 +/* XXX Macros to work around syntax errors in places where format string 1.430 + * arg is not passed to LOG_ASSERT, LOG_ALWAYS_FATAL or LOG_ALWAYS_FATAL_IF 1.431 + * (happens only in debug builds). 1.432 + */ 1.433 + 1.434 +/* Returns 2nd arg. Used to substitute default value if caller's vararg list 1.435 + * is empty. 1.436 + */ 1.437 +#define __android_second(dummy, second, ...) second 1.438 + 1.439 +/* If passed multiple args, returns ',' followed by all but 1st arg, otherwise 1.440 + * returns nothing. 1.441 + */ 1.442 +#define __android_rest(first, ...) , ## __VA_ARGS__ 1.443 + 1.444 +#define android_printAssert(cond, tag, fmt...) \ 1.445 + __android_log_assert(cond, tag, \ 1.446 + __android_second(0, ## fmt, NULL) __android_rest(fmt)) 1.447 + 1.448 +#define android_writeLog(prio, tag, text) \ 1.449 + __android_log_write(prio, tag, text) 1.450 + 1.451 +#define android_bWriteLog(tag, payload, len) \ 1.452 + __android_log_bwrite(tag, payload, len) 1.453 +#define android_btWriteLog(tag, type, payload, len) \ 1.454 + __android_log_btwrite(tag, type, payload, len) 1.455 + 1.456 +// TODO: remove these prototypes and their users 1.457 +#define android_testLog(prio, tag) (1) 1.458 +#define android_writevLog(vec,num) do{}while(0) 1.459 +#define android_write1Log(str,len) do{}while (0) 1.460 +#define android_setMinPriority(tag, prio) do{}while(0) 1.461 +//#define android_logToCallback(func) do{}while(0) 1.462 +#define android_logToFile(tag, file) (0) 1.463 +#define android_logToFd(tag, fd) (0) 1.464 + 1.465 +typedef enum { 1.466 + LOG_ID_MAIN = 0, 1.467 + LOG_ID_RADIO = 1, 1.468 + LOG_ID_EVENTS = 2, 1.469 + LOG_ID_SYSTEM = 3, 1.470 + 1.471 + LOG_ID_MAX 1.472 +} log_id_t; 1.473 + 1.474 +/* 1.475 + * Send a simple string to the log. 1.476 + */ 1.477 +int __android_log_buf_write(int bufID, int prio, const char *tag, const char *text); 1.478 +int __android_log_buf_print(int bufID, int prio, const char *tag, const char *fmt, ...); 1.479 + 1.480 + 1.481 +#ifdef __cplusplus 1.482 +} 1.483 +#endif 1.484 + 1.485 +#endif // _LIBS_CUTILS_LOG_H