1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23 #if !defined INCLUDED_JFW_PLUGIN_DIAGNOSTICS_HXX
24 #define INCLUDED_JFW_PLUGIN_DIAGNOSTICS_HXX
25 #include "osl/diagnose.h"
26 #include "rtl/ustring.hxx"
27 #include <stdio.h>
28
29 #if OSL_DEBUG_LEVEL >= 1
30 #define JFW_ENSURE(c, m) _JFW_ENSURE(c, OSL_THIS_FILE, __LINE__, m)
31 #else
32 #define JFW_ENSURE(c, m) ((void) 0)
33 #endif
34
35 #if OSL_DEBUG_LEVEL >= 2
36 #define JFW_WARNING2(c, m) _JFW_WARNING2(c, OSL_THIS_FILE, __LINE__, m)
37 #else
38 #define JFW_WARNING2(c, m) ((void) 0)
39 #endif
40
41
42 #if OSL_DEBUG_LEVEL >= 0
43 #define JFW_TRACE0(m) jfw_trace(m)
44 #else
45 #define JFW_TRACE0(m) ((void) 0)
46 #endif
47
48 #if OSL_DEBUG_LEVEL >= 1
49 #define JFW_TRACE1(m) jfw_trace(m)
50 #else
51 #define JFW_TRACE1(m) ((void) 0)
52 #endif
53
54 #if OSL_DEBUG_LEVEL >= 2
55 #define JFW_TRACE2(m) jfw_trace(m)
56 #else
57 #define JFW_TRACE2(m) ((void) 0)
58 #endif
59
60
61
62 #define _JFW_ENSURE(c, f, l, m) jfw_ensure(c, f, l, m)
63 #define _JFW_WARNING(c, f, l, m) jfw_warning2(c, f, l, m);
64
65
66 namespace jfw_plugin
67 {
68
jfw_ensure(bool condition,const sal_Char * pzFile,sal_Int32 line,const rtl::OUString & message)69 inline void jfw_ensure(bool
70 #if OSL_DEBUG_LEVEL > 0 /* prevent warning in pro version */
71 condition
72 #endif
73 , const sal_Char *
74 #if OSL_DEBUG_LEVEL > 0 /* prevent warning in pro version */
75 pzFile
76 #endif
77 , sal_Int32
78 #if OSL_DEBUG_LEVEL > 0 /* prevent warning in pro version */
79 line
80 #endif
81 , const rtl::OUString& message )
82 {
83 rtl::OString oMsg = rtl::OUStringToOString(message, osl_getThreadTextEncoding());
84 _OSL_ENSURE(condition, pzFile, line, oMsg.getStr());
85 }
86
jfw_warning2(bool condition,const sal_Char * pzFile,sal_Int32 line,sal_Char * pzMessage)87 inline void jfw_warning2(bool condition, const sal_Char * pzFile, sal_Int32 line,
88 sal_Char * pzMessage)
89 {
90 if (! condition)
91 fprintf(
92 stderr, "%s\n File: %s\n Line: %ld", pzMessage, pzFile,
93 sal::static_int_cast< unsigned long >(line));
94 }
95
jfw_trace(rtl::OUString message)96 inline void jfw_trace(rtl::OUString message)
97 {
98 rtl::OString oMsg = rtl::OUStringToOString(message, osl_getThreadTextEncoding());
99 fprintf(stderr,"%s", oMsg.getStr());
100 }
101
jfw_trace(const sal_Char * pzMessage)102 inline void jfw_trace(const sal_Char * pzMessage)
103 {
104 if (pzMessage)
105 fprintf(stderr,"%s", pzMessage);
106 }
107
jfw_trace(const rtl::OString & message)108 inline void jfw_trace(const rtl::OString& message)
109 {
110 if (message.getLength() > 0)
111 fprintf(stderr,"%s", message.getStr());
112 }
113
114 }
115
116 #endif
117