1 /* ------------------------------------------------------------------ 2 * Copyright (C) 2008 PacketVideo 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 13 * express or implied. 14 * See the License for the specific language governing permissions 15 * and limitations under the License. 16 * ------------------------------------------------------------------- 17 */ 18 19 #ifndef ANDROID_LOG_APPENDER_H_INCLUDED 20 #define ANDROID_LOG_APPENDER_H_INCLUDED 21 22 #ifndef PVLOGGERACCESSORIES_H_INCLUDED 23 #include "pvlogger_accessories.h" 24 #endif 25 26 #ifndef OSCLCONFIG_UTIL_H_INCLUDED 27 #include "osclconfig_util.h" 28 #endif 29 30 #ifndef OSCL_MEM_H_INCLUDED 31 #include "oscl_mem.h" 32 #endif 33 34 #include <utils/Log.h> 35 #undef LOG_TAG 36 #define LOG_TAG "PV" 37 38 /** 39 * Class: AndroidLogAppender 40 * 41 */ 42 template<class Layout, int32 LayoutBufferSize, class Lock = OsclNullLock> 43 class AndroidLogAppender : public PVLoggerAppender { 44 public: 45 typedef PVLoggerAppender::message_id_type message_id_type; 46 AndroidLogAppender()47 AndroidLogAppender() 48 { 49 stringbuf=NULL; 50 wstringbuf=NULL; 51 } ~AndroidLogAppender()52 virtual ~AndroidLogAppender() 53 { 54 if(stringbuf) 55 OSCL_DEFAULT_FREE(stringbuf); 56 if(wstringbuf) 57 OSCL_DEFAULT_FREE((OsclAny*)wstringbuf); 58 } 59 AppendString(message_id_type msgID,const char * fmt,va_list va)60 void AppendString(message_id_type msgID, const char *fmt, va_list va) 61 { 62 _lock.Lock(); 63 64 int32 size; 65 66 if(!stringbuf) 67 { 68 stringbuf=(char*)OSCL_DEFAULT_MALLOC(LayoutBufferSize); 69 if(!stringbuf) 70 return;//allocation failed-- just exit gracefully. 71 } 72 73 size = _layout.FormatString(stringbuf, LayoutBufferSize, msgID, fmt, va ); 74 75 LOGE(stringbuf); 76 77 _lock.Unlock(); 78 } AppendBuffers(message_id_type msgID,int32 numPairs,va_list va)79 void AppendBuffers(message_id_type msgID, int32 numPairs, va_list va) 80 { 81 OSCL_UNUSED_ARG(msgID); 82 83 for (int32 i = 0; i < numPairs; i++) 84 { 85 int32 length = va_arg (va, int32); 86 uint8* buffer = va_arg (va, uint8*); 87 88 int32 jj; 89 for( jj=10; jj<length; jj+=10 ) { 90 AppendStringA(0," %x %x %x %x %x %x %x %x %x %x", buffer[0], buffer[1], buffer[2], buffer[3], buffer[4], buffer[5], buffer[6], buffer[7], buffer[8], buffer[9]); 91 buffer += 10; 92 } 93 94 uint8 remainderbuf[10]; 95 uint32 remainder = length - (jj-10); 96 if( remainder > 0 && remainder <= 10 ) { 97 oscl_memcpy( remainderbuf, buffer, remainder ); 98 oscl_memset( remainderbuf+remainder, 0, 10-remainder ); 99 buffer = remainderbuf; 100 AppendStringA(0," %x %x %x %x %x %x %x %x %x %x", buffer[0], buffer[1], buffer[2], buffer[3], buffer[4], buffer[5], buffer[6], buffer[7], buffer[8], buffer[9]); 101 } 102 } 103 va_end(va); 104 } 105 106 private: AppendStringA(message_id_type msgID,const char * fmt,...)107 void AppendStringA(message_id_type msgID, const char *fmt, ...) { 108 va_list arguments; 109 va_start(arguments, fmt); 110 AppendString(msgID, fmt, arguments); 111 va_end(arguments); 112 } 113 114 Layout _layout; 115 Lock _lock; 116 char* stringbuf; 117 oscl_wchar* wstringbuf; 118 119 }; 120 121 #endif // ANDROID_LOG_APPENDER_H_INCLUDED 122 123