xref: /aoo42x/main/sal/inc/osl/diagnose.h (revision cdf0e10c)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir 
29*cdf0e10cSrcweir #ifndef _OSL_DIAGNOSE_H_
30*cdf0e10cSrcweir #define _OSL_DIAGNOSE_H_
31*cdf0e10cSrcweir 
32*cdf0e10cSrcweir #include <sal/types.h>
33*cdf0e10cSrcweir 
34*cdf0e10cSrcweir #ifdef __cplusplus
35*cdf0e10cSrcweir extern "C" {
36*cdf0e10cSrcweir #endif  /* __cplusplus */
37*cdf0e10cSrcweir 
38*cdf0e10cSrcweir /* //////////////////////////////////////////////////////////////////////////
39*cdf0e10cSrcweir 	Diagnostic support
40*cdf0e10cSrcweir */
41*cdf0e10cSrcweir 
42*cdf0e10cSrcweir void    	SAL_CALL osl_breakDebug(void);
43*cdf0e10cSrcweir sal_Bool 	SAL_CALL osl_assertFailedLine(const sal_Char* pszFileName, sal_Int32 nLine, const sal_Char* pszMessage);
44*cdf0e10cSrcweir void    	SAL_CALL osl_trace(const sal_Char* pszFormat, ...);
45*cdf0e10cSrcweir sal_Int32	SAL_CALL osl_reportError(sal_uInt32 nType, const sal_Char* pszErrorMessage);
46*cdf0e10cSrcweir 
47*cdf0e10cSrcweir /*
48*cdf0e10cSrcweir 	For message delivery
49*cdf0e10cSrcweir */
50*cdf0e10cSrcweir 
51*cdf0e10cSrcweir /** a message delivery function which receives a pre-formatted message string
52*cdf0e10cSrcweir */
53*cdf0e10cSrcweir typedef void (SAL_CALL *pfunc_osl_printDebugMessage)( const sal_Char * pszMessage );
54*cdf0e10cSrcweir 
55*cdf0e10cSrcweir /** a message delivery function which receives detailed information about where the message was triggered
56*cdf0e10cSrcweir */
57*cdf0e10cSrcweir typedef void (SAL_CALL *pfunc_osl_printDetailedDebugMessage)( const sal_Char * pszFileName, sal_Int32 nLine, const sal_Char* pszMessage );
58*cdf0e10cSrcweir 
59*cdf0e10cSrcweir /** sets a message delivery function
60*cdf0e10cSrcweir 
61*cdf0e10cSrcweir     The function set here is ignored if a function for detailed message information
62*cdf0e10cSrcweir     (pfunc_osl_printDetailedDebugMessage) has been set.
63*cdf0e10cSrcweir 
64*cdf0e10cSrcweir     The given message handler must be able to cope with a <NULL/> message.
65*cdf0e10cSrcweir */
66*cdf0e10cSrcweir pfunc_osl_printDebugMessage SAL_CALL osl_setDebugMessageFunc( pfunc_osl_printDebugMessage pNewFunc );
67*cdf0e10cSrcweir 
68*cdf0e10cSrcweir /** sets a delivery function for detailed message information.
69*cdf0e10cSrcweir 
70*cdf0e10cSrcweir     The given message handler must be able to cope with a <NULL/> message.
71*cdf0e10cSrcweir */
72*cdf0e10cSrcweir pfunc_osl_printDetailedDebugMessage SAL_CALL osl_setDetailedDebugMessageFunc( pfunc_osl_printDetailedDebugMessage pNewFunc );
73*cdf0e10cSrcweir 
74*cdf0e10cSrcweir #ifdef __cplusplus
75*cdf0e10cSrcweir }
76*cdf0e10cSrcweir #endif
77*cdf0e10cSrcweir 
78*cdf0e10cSrcweir #define OSL_THIS_FILE       __FILE__
79*cdf0e10cSrcweir 
80*cdf0e10cSrcweir /* the macro OSL_THIS_FUNC is intended to be an office internal macro for now */
81*cdf0e10cSrcweir #define OSL_THIS_FUNC "<unknown>"
82*cdf0e10cSrcweir 
83*cdf0e10cSrcweir /* the macro OSL_TO_STRING is intended to be an office internal macro for now */
84*cdf0e10cSrcweir #define OSL_TO_STRING( x ) #x
85*cdf0e10cSrcweir 
86*cdf0e10cSrcweir /* the macro OSL_MACRO_VALUE_TO_STRING is intended to be an office internal macro for now */
87*cdf0e10cSrcweir #define OSL_MACRO_VALUE_TO_STRING( x ) OSL_TO_STRING( x )
88*cdf0e10cSrcweir 
89*cdf0e10cSrcweir /* the macro OSL_LOG_PREFIX is intended to be an office internal macro for now */
90*cdf0e10cSrcweir #define OSL_LOG_PREFIX OSL_THIS_FILE ":" OSL_THIS_FUNC ":" OSL_MACRO_VALUE_TO_STRING( __LINE__ ) "; "
91*cdf0e10cSrcweir 
92*cdf0e10cSrcweir #define OSL_DEBUG_ONLY(s)	_OSL_DEBUG_ONLY(s)
93*cdf0e10cSrcweir #define OSL_TRACE           _OSL_TRACE
94*cdf0e10cSrcweir #define OSL_ASSERT(c) 	    _OSL_ASSERT(c, OSL_THIS_FILE, __LINE__)
95*cdf0e10cSrcweir #define OSL_ENSURE(c, m)   _OSL_ENSURE(c, OSL_THIS_FILE, __LINE__, m)
96*cdf0e10cSrcweir 
97*cdf0e10cSrcweir #define OSL_VERIFY(c) do { if (!(c)) OSL_ASSERT(0); } while (0)
98*cdf0e10cSrcweir #define OSL_PRECOND(c, m)  	OSL_ENSURE(c, m)
99*cdf0e10cSrcweir #define OSL_POSTCOND(c, m) 	OSL_ENSURE(c, m)
100*cdf0e10cSrcweir 
101*cdf0e10cSrcweir 
102*cdf0e10cSrcweir #ifdef __cplusplus
103*cdf0e10cSrcweir #define _OSL_GLOBAL	::
104*cdf0e10cSrcweir #else
105*cdf0e10cSrcweir #define _OSL_GLOBAL
106*cdf0e10cSrcweir #endif  /* __cplusplus */
107*cdf0e10cSrcweir 
108*cdf0e10cSrcweir #ifdef _WIN16
109*cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 0
110*cdf0e10cSrcweir #undef OSL_DEBUG_LEVEL
111*cdf0e10cSrcweir #define OSL_DEBUG_LEVEL 0
112*cdf0e10cSrcweir #endif
113*cdf0e10cSrcweir #endif
114*cdf0e10cSrcweir 
115*cdf0e10cSrcweir 
116*cdf0e10cSrcweir 
117*cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 0
118*cdf0e10cSrcweir 
119*cdf0e10cSrcweir #define _OSL_DEBUG_ONLY(f)	(f)
120*cdf0e10cSrcweir #define _OSL_ASSERT(c, f, l) \
121*cdf0e10cSrcweir 	do \
122*cdf0e10cSrcweir 	{  \
123*cdf0e10cSrcweir 	    if (!(c) && _OSL_GLOBAL osl_assertFailedLine(f, l, 0)) \
124*cdf0e10cSrcweir 		    _OSL_GLOBAL osl_breakDebug(); \
125*cdf0e10cSrcweir 	} while (0)
126*cdf0e10cSrcweir 
127*cdf0e10cSrcweir #define _OSL_ENSURE(c, f, l, m) \
128*cdf0e10cSrcweir 	do \
129*cdf0e10cSrcweir 	{  \
130*cdf0e10cSrcweir 	    if (!(c) && _OSL_GLOBAL osl_assertFailedLine(f, l, m)) \
131*cdf0e10cSrcweir 		    _OSL_GLOBAL osl_breakDebug(); \
132*cdf0e10cSrcweir 	} while (0)
133*cdf0e10cSrcweir 
134*cdf0e10cSrcweir #else
135*cdf0e10cSrcweir 
136*cdf0e10cSrcweir #define _OSL_DEBUG_ONLY(f)			((void)0)
137*cdf0e10cSrcweir #define _OSL_ASSERT(c, f, l)		((void)0)
138*cdf0e10cSrcweir #define _OSL_ENSURE(c, f, l, m)	    ((void)0)
139*cdf0e10cSrcweir 
140*cdf0e10cSrcweir #endif /* OSL_DEBUG_LEVEL */
141*cdf0e10cSrcweir 
142*cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 1
143*cdf0e10cSrcweir 
144*cdf0e10cSrcweir #define _OSL_TRACE                  _OSL_GLOBAL osl_trace
145*cdf0e10cSrcweir 
146*cdf0e10cSrcweir #else
147*cdf0e10cSrcweir 
148*cdf0e10cSrcweir #define _OSL_TRACE                  1 ? ((void)0) : _OSL_GLOBAL osl_trace
149*cdf0e10cSrcweir 
150*cdf0e10cSrcweir #endif /* OSL_DEBUG_LEVEL */
151*cdf0e10cSrcweir 
152*cdf0e10cSrcweir #endif /* _OSL_DIAGNOSE_H_ */
153