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