1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_svx.hxx" 30 #include "trace.hxx" 31 #include <tools/debug.hxx> 32 33 #if defined(DBG_UTIL) 34 35 //============================================================================== 36 37 //------------------------------------------------------------------------------ 38 ::vos::OMutex Tracer::s_aMapSafety; 39 ::std::map< ::vos::OThread::TThreadIdentifier, sal_Int32, ::std::less< ::vos::OThread::TThreadIdentifier > > 40 Tracer::s_aThreadIndents; 41 42 //------------------------------------------------------------------------------ 43 Tracer::Tracer(const char* _pBlockDescription) 44 :m_sBlockDescription(_pBlockDescription) 45 { 46 ::vos::OGuard aGuard(s_aMapSafety); 47 sal_Int32 nIndent = s_aThreadIndents[ ::vos::OThread::getCurrentIdentifier() ]++; 48 49 ByteString sIndent; 50 while (nIndent--) 51 sIndent += '\t'; 52 53 ByteString sThread( ByteString::CreateFromInt32( (sal_Int32)::vos::OThread::getCurrentIdentifier() ) ); 54 sThread += '\t'; 55 56 ByteString sMessage(sThread); 57 sMessage += sIndent; 58 sMessage += m_sBlockDescription; 59 sMessage += " {"; 60 DBG_TRACE(sMessage.GetBuffer()); 61 } 62 63 //------------------------------------------------------------------------------ 64 Tracer::~Tracer() 65 { 66 ::vos::OGuard aGuard(s_aMapSafety); 67 sal_Int32 nIndent = --s_aThreadIndents[ ::vos::OThread::getCurrentIdentifier() ]; 68 69 ByteString sIndent; 70 while (nIndent--) 71 sIndent += '\t'; 72 73 ByteString sThread( ByteString::CreateFromInt32( (sal_Int32)::vos::OThread::getCurrentIdentifier() ) ); 74 sThread += '\t'; 75 76 ByteString sMessage(sThread); 77 sMessage += sIndent; 78 sMessage += "} // "; 79 sMessage += m_sBlockDescription; 80 DBG_TRACE(sMessage.GetBuffer()); 81 } 82 83 //------------------------------------------------------------------------------ 84 void Tracer::TraceString(const char* _pMessage) 85 { 86 ::vos::OGuard aGuard(s_aMapSafety); 87 sal_Int32 nIndent = s_aThreadIndents[ ::vos::OThread::getCurrentIdentifier() ]; 88 89 ByteString sIndent; 90 while (nIndent--) 91 sIndent += '\t'; 92 93 ByteString sThread( ByteString::CreateFromInt32( (sal_Int32)::vos::OThread::getCurrentIdentifier() ) ); 94 sThread += '\t'; 95 96 ByteString sMessage(sThread); 97 sMessage += sIndent; 98 sMessage += m_sBlockDescription; 99 sMessage += ": "; 100 sMessage += _pMessage; 101 DBG_TRACE(sMessage.GetBuffer()); 102 } 103 104 //------------------------------------------------------------------------------ 105 void Tracer::TraceString1StringParam(const char* _pMessage, const char* _pParam) 106 { 107 ::vos::OGuard aGuard(s_aMapSafety); 108 sal_Int32 nIndent = s_aThreadIndents[ ::vos::OThread::getCurrentIdentifier() ]; 109 110 ByteString sIndent; 111 while (nIndent--) 112 sIndent += '\t'; 113 114 ByteString sThread( ByteString::CreateFromInt32( (sal_Int32)::vos::OThread::getCurrentIdentifier() ) ); 115 sThread += '\t'; 116 117 ByteString sMessage(sThread); 118 sMessage += sIndent; 119 sMessage += m_sBlockDescription; 120 sMessage += ": "; 121 sMessage += _pMessage; 122 DBG_TRACE1(sMessage.GetBuffer(), _pParam); 123 } 124 #endif 125