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 29 #ifndef _OSL_DIAGNOSE_H_ 30 #define _OSL_DIAGNOSE_H_ 31 32 #include <sal/types.h> 33 34 #ifdef __cplusplus 35 extern "C" { 36 #endif /* __cplusplus */ 37 38 /* ////////////////////////////////////////////////////////////////////////// 39 Diagnostic support 40 */ 41 42 void SAL_CALL osl_breakDebug(void); 43 sal_Bool SAL_CALL osl_assertFailedLine(const sal_Char* pszFileName, sal_Int32 nLine, const sal_Char* pszMessage); 44 void SAL_CALL osl_trace(const sal_Char* pszFormat, ...); 45 sal_Int32 SAL_CALL osl_reportError(sal_uInt32 nType, const sal_Char* pszErrorMessage); 46 47 /* 48 For message delivery 49 */ 50 51 /** a message delivery function which receives a pre-formatted message string 52 */ 53 typedef void (SAL_CALL *pfunc_osl_printDebugMessage)( const sal_Char * pszMessage ); 54 55 /** a message delivery function which receives detailed information about where the message was triggered 56 */ 57 typedef void (SAL_CALL *pfunc_osl_printDetailedDebugMessage)( const sal_Char * pszFileName, sal_Int32 nLine, const sal_Char* pszMessage ); 58 59 /** sets a message delivery function 60 61 The function set here is ignored if a function for detailed message information 62 (pfunc_osl_printDetailedDebugMessage) has been set. 63 64 The given message handler must be able to cope with a <NULL/> message. 65 */ 66 pfunc_osl_printDebugMessage SAL_CALL osl_setDebugMessageFunc( pfunc_osl_printDebugMessage pNewFunc ); 67 68 /** sets a delivery function for detailed message information. 69 70 The given message handler must be able to cope with a <NULL/> message. 71 */ 72 pfunc_osl_printDetailedDebugMessage SAL_CALL osl_setDetailedDebugMessageFunc( pfunc_osl_printDetailedDebugMessage pNewFunc ); 73 74 #ifdef __cplusplus 75 } 76 #endif 77 78 #define OSL_THIS_FILE __FILE__ 79 80 /* the macro OSL_THIS_FUNC is intended to be an office internal macro for now */ 81 #define OSL_THIS_FUNC "<unknown>" 82 83 /* the macro OSL_TO_STRING is intended to be an office internal macro for now */ 84 #define OSL_TO_STRING( x ) #x 85 86 /* the macro OSL_MACRO_VALUE_TO_STRING is intended to be an office internal macro for now */ 87 #define OSL_MACRO_VALUE_TO_STRING( x ) OSL_TO_STRING( x ) 88 89 /* the macro OSL_LOG_PREFIX is intended to be an office internal macro for now */ 90 #define OSL_LOG_PREFIX OSL_THIS_FILE ":" OSL_THIS_FUNC ":" OSL_MACRO_VALUE_TO_STRING( __LINE__ ) "; " 91 92 #define OSL_DEBUG_ONLY(s) _OSL_DEBUG_ONLY(s) 93 #define OSL_TRACE _OSL_TRACE 94 #define OSL_ASSERT(c) _OSL_ASSERT(c, OSL_THIS_FILE, __LINE__) 95 #define OSL_ENSURE(c, m) _OSL_ENSURE(c, OSL_THIS_FILE, __LINE__, m) 96 97 #define OSL_VERIFY(c) do { if (!(c)) OSL_ASSERT(0); } while (0) 98 #define OSL_PRECOND(c, m) OSL_ENSURE(c, m) 99 #define OSL_POSTCOND(c, m) OSL_ENSURE(c, m) 100 101 102 #ifdef __cplusplus 103 #define _OSL_GLOBAL :: 104 #else 105 #define _OSL_GLOBAL 106 #endif /* __cplusplus */ 107 108 #ifdef _WIN16 109 #if OSL_DEBUG_LEVEL > 0 110 #undef OSL_DEBUG_LEVEL 111 #define OSL_DEBUG_LEVEL 0 112 #endif 113 #endif 114 115 116 117 #if OSL_DEBUG_LEVEL > 0 118 119 #define _OSL_DEBUG_ONLY(f) (f) 120 #define _OSL_ASSERT(c, f, l) \ 121 do \ 122 { \ 123 if (!(c) && _OSL_GLOBAL osl_assertFailedLine(f, l, 0)) \ 124 _OSL_GLOBAL osl_breakDebug(); \ 125 } while (0) 126 127 #define _OSL_ENSURE(c, f, l, m) \ 128 do \ 129 { \ 130 if (!(c) && _OSL_GLOBAL osl_assertFailedLine(f, l, m)) \ 131 _OSL_GLOBAL osl_breakDebug(); \ 132 } while (0) 133 134 #else 135 136 #define _OSL_DEBUG_ONLY(f) ((void)0) 137 #define _OSL_ASSERT(c, f, l) ((void)0) 138 #define _OSL_ENSURE(c, f, l, m) ((void)0) 139 140 #endif /* OSL_DEBUG_LEVEL */ 141 142 #if OSL_DEBUG_LEVEL > 1 143 144 #define _OSL_TRACE _OSL_GLOBAL osl_trace 145 146 #else 147 148 #define _OSL_TRACE 1 ? ((void)0) : _OSL_GLOBAL osl_trace 149 150 #endif /* OSL_DEBUG_LEVEL */ 151 152 #endif /* _OSL_DIAGNOSE_H_ */ 153