From 79a7af4e4fef45807e166fde81f6a3be29758bc2 Mon Sep 17 00:00:00 2001 From: ChenHengming Date: Wed, 29 Jul 2015 07:13:02 +0000 Subject: [PATCH] [rk_log]: add os_log function on window separate os_log and platform log function git-svn-id: https://10.10.10.66:8443/svn/MediaProcessPlatform/trunk/mpp@10 6e48237b-75ef-9749-8fc9-41990f28c85a --- osal/CMakeLists.txt | 14 ++++++++++- osal/inc/rk_log.h | 51 ++++++++++++++++++++++++---------------- osal/os_log.h | 39 ++++++++++++++++++++++++++++++ osal/rk_log.cpp | 24 ++++++------------- osal/test/CMakeLists.txt | 2 +- osal/test/rk_log_test.c | 1 + osal/window/os_log.c | 35 +++++++++++++++++++++++++++ 7 files changed, 127 insertions(+), 39 deletions(-) create mode 100644 osal/os_log.h create mode 100644 osal/window/os_log.c diff --git a/osal/CMakeLists.txt b/osal/CMakeLists.txt index e3c2c185..0b1c1a7d 100644 --- a/osal/CMakeLists.txt +++ b/osal/CMakeLists.txt @@ -1,17 +1,29 @@ # vim: syntax=cmake +if(${ANDROID}) +set(OS_DIR android) +elseif(${UNIX}) +set(OS_DIR linux) +elseif(${WIN32}) +set(OS_DIR window) +else() +message(SEND_ERROR "Can not found platform definistion ${CMAKE_SYSTEM}") +endif() + set(OSAL_HDR inc/rk_list.h inc/rk_thread.h inc/rk_log.h + os_log.h ) set(OSAL_SRC rk_list.cpp rk_log.cpp + ${OS_DIR}/os_log.c ) add_library(osal STATIC - ${OSAL_SRC} + ${OSAL_SRC} ${OSAL_HDR} ) # ---------------------------------------------------------------------------- diff --git a/osal/inc/rk_log.h b/osal/inc/rk_log.h index 258b505d..4eabe433 100644 --- a/osal/inc/rk_log.h +++ b/osal/inc/rk_log.h @@ -19,31 +19,37 @@ #include "rk_type.h" +/* + * C log functions + */ #ifdef __cplusplus extern "C" { #endif -/* - * STATIC_LOG_LEVE is for - */ -#define STATIC_LOG_LEVE (0xffffffff) - -#ifdef STATIC_LOG_LEVE -#define rk_debug STATIC_LOG_LEVE -#else -extern RK_U32 rk_debug; +#ifndef LOG_TAG +#define LOG_TAG "rk_log" #endif void rk_set_log_flag(RK_U32 flag); RK_U32 rk_get_log_flag(); +#define rk_log(fmt, ...) _rk_log(LOG_TAG, fmt, ## __VA_ARGS__) +#define rk_err(fmt, ...) _rk_err(LOG_TAG, fmt, ## __VA_ARGS__) + +#define rk_dbg(debug, flag, fmt, ...) \ + do { \ + if (debug & flag) { \ + _rk_log(LOG_TAG, fmt, ## __VA_ARGS__); \ + } \ + } while(0) + /* * Send the specified message to the log - * rk_log : general log function - * rk_err : log function for error information + * _rk_log : general log function, send log to stdout + * _rk_err : log function for error information, send log to stderr */ -void rk_log(const char *fmt, ...); -void rk_err(const char *fmt, ...); +void _rk_log(const char *tag, const char *fmt, ...); +void _rk_err(const char *tag, const char *fmt, ...); /* * debug flag usage: @@ -55,14 +61,19 @@ void rk_err(const char *fmt, ...); * 24~31 bit: information print format */ /* - * 0~ 3 bit: + * dynamic debug function + * rk_dbg_add_flag : add a new debug flag associated with module name + * rk_dbg_set_flag : set a existing debug flag associated with module name + * rk_dbg_show_flag : show all existing debug flags + */ + +//void rk_dbg(RK_U32 debug, RK_U32 flag, const char *tag, const char *fmt, ...); + +/* + * submodules suggest to use macro as below: + * #define h264d_dbg(flag, const char *fmt, ...) \ + * rk_dbg(h264d_debug, flag, fmt, ## __VA_ARGS__) */ -#define rk_dbg(flag, debug, fmt, ...) \ - do { \ - if (debug & flag) { \ - rk_log(fmt, ## __VA_ARGS__); \ - } \ - } while(0) #ifdef __cplusplus } diff --git a/osal/os_log.h b/osal/os_log.h new file mode 100644 index 00000000..c552eda8 --- /dev/null +++ b/osal/os_log.h @@ -0,0 +1,39 @@ +/* + * Copyright 2010 Rockchip Electronics S.LSI Co. LTD + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/* + * all os log function will provide two interface + * os_log and os_err + * os_log for general message + * os_err for error message + */ + +#ifndef __OS_LOG_H__ +#define __OS_LOG_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +void os_log(const char* tag, const char* msg, va_list list); +void os_err(const char* tag, const char* msg, va_list list); + +#ifdef __cplusplus +} +#endif + +#endif /*__OS_LOG_H__*/ + diff --git a/osal/rk_log.cpp b/osal/rk_log.cpp index 2d545f78..806b33b3 100644 --- a/osal/rk_log.cpp +++ b/osal/rk_log.cpp @@ -17,40 +17,30 @@ #include #include #include "rk_log.h" - -#ifdef ANDROID -#include -#endif - +#include "os_log.h" #ifdef __cplusplus extern "C" { #endif static RK_U32 mpp_log_flag = 0; +static void (*rk_log_callback)(const char*, const char*, va_list) = os_log; +static void (*rk_err_callback)(const char*, const char*, va_list) = os_err; -void rk_log(const char *fmt, ...) +void _rk_log(const char *tag, const char *fmt, ...) { va_list args; va_start(args, fmt); -#ifdef ANDROID - ALOGI(fmt, args); -#else - vfprintf(stdout, fmt, args); -#endif + rk_log_callback(tag, fmt, args); va_end(args); return ; } -void rk_err(const char *fmt, ...) +void _rk_err(const char *tag, const char *fmt, ...) { va_list args; va_start(args, fmt); -#ifdef ANDROID - ALOGE(fmt, args); -#else - vfprintf(stderr, fmt, args); -#endif + rk_err_callback(tag, fmt, args); va_end(args); return ; } diff --git a/osal/test/CMakeLists.txt b/osal/test/CMakeLists.txt index 676b0324..ba150d22 100644 --- a/osal/test/CMakeLists.txt +++ b/osal/test/CMakeLists.txt @@ -13,6 +13,6 @@ endif() option(OSAL_THREAD_TEST "Build osal rk_thread unit test" ON) if(OSAL_THREAD_TEST) add_executable(rk_thread_test rk_thread_test.c) - target_link_libraries(rk_thread_test pthread osal) + target_link_libraries(rk_thread_test osal) endif() diff --git a/osal/test/rk_log_test.c b/osal/test/rk_log_test.c index 517c38cc..31d9b820 100644 --- a/osal/test/rk_log_test.c +++ b/osal/test/rk_log_test.c @@ -14,6 +14,7 @@ * limitations under the License. */ +#define LOG_TAG "rk_log_test" #include "rk_log.h" diff --git a/osal/window/os_log.c b/osal/window/os_log.c new file mode 100644 index 00000000..d6db74ca --- /dev/null +++ b/osal/window/os_log.c @@ -0,0 +1,35 @@ +/* + * Copyright 2010 Rockchip Electronics S.LSI Co. LTD + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include + +#define LINE_SZ 1024 + +void os_log(const char* tag, const char* msg, va_list list) +{ + char line[LINE_SZ] = {0}; + _snprintf(line, sizeof(line), "%s: %s", tag, msg); + vfprintf(stdout, line, list); +} + +void os_err(const char* tag, const char* msg, va_list list) +{ + char line[LINE_SZ] = {0}; + _snprintf(line, sizeof(line), "%s: %s", tag, msg); + vfprintf(stderr, line, list); +} +