merge the formfield patch from ooo-build
[ooovba.git] / configmgr / source / inc / tracer.hxx
blobfe890d97f57f49a3e2e074eda4b0593d70422e8a
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: tracer.hxx,v $
10 * $Revision: 1.11 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef _CONFIGMGR_TRACER_HXX_
32 #define _CONFIGMGR_TRACER_HXX_
34 #if OSL_DEBUG_LEVEL > 0
35 #define CFG_ENABLE_TRACING
36 #endif
38 #ifdef CFG_ENABLE_TRACING
40 #include <sal/types.h>
41 #include <rtl/string.hxx>
42 #include <osl/mutex.hxx>
44 #include <stdarg.h>
45 #include <stdio.h>
47 #ifdef WNT
48 #include <sys/timeb.h>
49 #else
50 #include <sys/time.h>
51 #endif
53 #define OUSTRING2ASCII(rtlOUString) ::rtl::OString((rtlOUString).getStr(), (rtlOUString).getLength(), RTL_TEXTENCODING_ASCII_US).getStr()
55 #define CFG_TRACE_INFO OTraceIndent aIndent; OConfigTracer::traceInfo
56 // FIXME: do something more intelligent here
57 // the CFG_TRACE_INFO2 macro exists only to have a unique name of aIndent2
58 // so it does not hide aIndent in an outer scope (which would produce a
59 // a shadowing warning
60 #define CFG_TRACE_INFO2 OTraceIndent aIndent2; OConfigTracer::traceInfo
61 #define CFG_TRACE_WARNING OTraceIndent aIndent; OConfigTracer::traceWarning
62 #define CFG_TRACE_ERROR OTraceIndent aIndent; OConfigTracer::traceError
63 #define CFG_TRACE_INFO_NI OConfigTracer::traceInfo
64 #define CFG_TRACE_WARNING_NI OConfigTracer::traceWarning
65 #define CFG_TRACE_ERROR_NI OConfigTracer::traceError
67 namespace configmgr
70 struct OTracerSetup;
71 class OConfigTracer
73 friend class OTraceIndent;
75 protected:
76 static ::osl::Mutex & getMutex();
77 static OTracerSetup* s_pImpl;
78 #ifdef WNT
79 static timeb s_aStartTime;
80 #else
81 static timeval s_aStartTime;
82 #endif
84 private:
85 OConfigTracer(); // never implemented, no instantiation of this class allowed, only static members
87 public:
88 static void traceInfo(const sal_Char* _pFormat, ...);
89 #if OSL_DEBUG_LEVEL > 0
90 static void traceWarning(const sal_Char* _pFormat, ...);
91 static void traceError(const sal_Char* _pFormat, ...);
92 #endif
93 protected:
94 static void implTrace(const sal_Char* _pType, const sal_Char* _pFormat, va_list args);
95 static void startGlobalTimer();
96 static sal_uInt32 getGlobalTimer();
98 static void inc();
99 static void dec();
101 static void indent();
103 static void ensureData();
104 static void ensureInitalized();
107 class OTraceIndent
109 public:
110 OTraceIndent() { OConfigTracer::inc(); }
111 ~OTraceIndent() { OConfigTracer::dec(); }
114 } // namespace configmgr
116 #else // !CFG_ENABLE_TRACING
118 #include <stdio.h>
120 #define OUSTRING2ASCII(rtlOUString) "nothing"
122 namespace configmgr {
123 inline static void dont_trace(const char*,...) {}
126 #define CFG_TRACE_INFO dont_trace
127 #define CFG_TRACE_INFO2 dont_trace
128 #define CFG_TRACE_WARNING dont_trace
129 #define CFG_TRACE_ERROR dont_trace
130 #define CFG_TRACE_INFO_NI dont_trace
131 #define CFG_TRACE_WARNING_NI dont_trace
132 #define CFG_TRACE_ERROR_NI dont_trace
133 #define CFG_TRACE_TO_DEVICE dont_trace
135 #endif // CFG_ENABLE_TRACING
137 #endif // _CONFIGMGR_TRACER_HXX_