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 #if !defined INCLUDED_JFW_PLUGIN_DIAGNOSTICS_HXX
28 #define INCLUDED_JFW_PLUGIN_DIAGNOSTICS_HXX
29 #include "osl/diagnose.h"
30 #include "rtl/ustring.hxx"
31 #include <stdio.h>
32 
33 #if OSL_DEBUG_LEVEL >= 1
34 #define JFW_ENSURE(c, m)  _JFW_ENSURE(c, OSL_THIS_FILE, __LINE__,  m)
35 #else
36 #define JFW_ENSURE(c, m)  ((void) 0)
37 #endif
38 
39 #if OSL_DEBUG_LEVEL >= 2
40 #define JFW_WARNING2(c, m)  _JFW_WARNING2(c, OSL_THIS_FILE, __LINE__, m)
41 #else
42 #define JFW_WARNING2(c, m)  ((void) 0)
43 #endif
44 
45 
46 #if OSL_DEBUG_LEVEL >= 0
47 #define JFW_TRACE0(m)  jfw_trace(m)
48 #else
49 #define JFW_TRACE0(m)  ((void) 0)
50 #endif
51 
52 #if OSL_DEBUG_LEVEL >= 1
53 #define JFW_TRACE1(m)  jfw_trace(m)
54 #else
55 #define JFW_TRACE1(m)  ((void) 0)
56 #endif
57 
58 #if OSL_DEBUG_LEVEL >= 2
59 #define JFW_TRACE2(m)  jfw_trace(m)
60 #else
61 #define JFW_TRACE2(m)  ((void) 0)
62 #endif
63 
64 
65 
66 #define _JFW_ENSURE(c, f, l, m)  jfw_ensure(c, f, l, m)
67 #define _JFW_WARNING(c, f, l, m)  jfw_warning2(c, f, l, m);
68 
69 
70 namespace jfw_plugin
71 {
72 
73 inline void jfw_ensure(bool
74                        #if OSL_DEBUG_LEVEL > 0 /* prevent warning in pro version */
75                        condition
76                        #endif
77                        , const sal_Char *
78                        #if OSL_DEBUG_LEVEL > 0 /* prevent warning in pro version */
79                        pzFile
80                        #endif
81                        , sal_Int32
82                        #if OSL_DEBUG_LEVEL > 0 /* prevent warning in pro version */
83                        line
84                        #endif
85                        , const rtl::OUString& message )
86 {
87     rtl::OString oMsg = rtl::OUStringToOString(message, osl_getThreadTextEncoding());
88     _OSL_ENSURE(condition, pzFile, line, oMsg.getStr());
89 }
90 
91 inline void jfw_warning2(bool condition, const sal_Char * pzFile, sal_Int32 line,
92                          sal_Char * pzMessage)
93 {
94     if (! condition)
95         fprintf(
96             stderr, "%s\n File: %s\n Line: %ld", pzMessage, pzFile,
97             sal::static_int_cast< unsigned long >(line));
98 }
99 
100 inline void jfw_trace(rtl::OUString message)
101 {
102     rtl::OString oMsg = rtl::OUStringToOString(message, osl_getThreadTextEncoding());
103     fprintf(stderr,"%s", oMsg.getStr());
104 }
105 
106 inline void jfw_trace(const sal_Char * pzMessage)
107 {
108     if (pzMessage)
109         fprintf(stderr,"%s", pzMessage);
110 }
111 
112 inline void jfw_trace(const rtl::OString& message)
113 {
114     if (message.getLength() > 0)
115         fprintf(stderr,"%s", message.getStr());
116 }
117 
118 }
119 
120 #endif
121