libUPnP  1.8.0
upnpdebug.h
Go to the documentation of this file.
1 /*******************************************************************************
2  *
3  * Copyright (c) 2000-2003 Intel Corporation
4  * Copyright (c) 2006 Rémi Turboult <r3mi@users.sourceforge.net>
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions are met:
9  *
10  * - Redistributions of source code must retain the above copyright notice,
11  * this list of conditions and the following disclaimer.
12  * - Redistributions in binary form must reproduce the above copyright notice,
13  * this list of conditions and the following disclaimer in the documentation
14  * and/or other materials provided with the distribution.
15  * - Neither name of Intel Corporation nor the names of its contributors
16  * may be used to endorse or promote products derived from this software
17  * without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR
23  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
24  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
25  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
26  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
27  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
28  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
29  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30  *
31  ******************************************************************************/
32 
33 #ifndef UPNP_DEBUG_H
34 #define UPNP_DEBUG_H
35 
36 
42 #include "ThreadPool.h"
43 #include "upnpconfig.h"
44 #include "UpnpGlobal.h" /* for UPNP_INLINE */
45 
46 
47 #include <stdio.h>
48 
49 
50 #ifdef __cplusplus
51 extern "C" {
52 #endif
53 
54 
60 
77 typedef enum Upnp_Module {
78  SSDP,
79  SOAP,
80  GENA,
81  TPOOL,
82  MSERV,
83  DOM,
84  API,
85  HTTP
86 } Dbg_Module;
87 
88 
90 typedef enum Upnp_LogLevel_e {
91  UPNP_CRITICAL,
92  UPNP_PACKET,
93  UPNP_INFO,
94  UPNP_ALL
95 } Upnp_LogLevel;
102 #define UPNP_DEFAULT_LOG_LEVEL UPNP_ALL
103 
104 
105 
111 #ifdef DEBUG
112 int UpnpInitLog(void);
113 #else
114 static UPNP_INLINE int UpnpInitLog(void)
115 {
116  return UPNP_E_SUCCESS;
117 }
118 #endif
119 
120 
124 #ifdef DEBUG
125 void UpnpSetLogLevel(
127  Upnp_LogLevel log_level);
128 #else
129 static UPNP_INLINE void UpnpSetLogLevel(Upnp_LogLevel log_level) {}
130 #endif
131 
132 
136 #ifdef DEBUG
137 void UpnpCloseLog(void);
138 #else
139 static UPNP_INLINE void UpnpCloseLog(void) {}
140 #endif
141 
142 
146 #ifdef DEBUG
149  const char *ErrFileName,
151  const char *InfoFileName);
152 #else
153 static UPNP_INLINE void UpnpSetLogFileNames(
154  const char *ErrFileName,
155  const char *InfoFileName) {}
156 #endif
157 
158 
166 #ifdef DEBUG
167 FILE *UpnpGetDebugFile(
170  Upnp_LogLevel level,
172  Dbg_Module module);
173 #else
174 static UPNP_INLINE FILE *UpnpGetDebugFile(Upnp_LogLevel level, Dbg_Module module)
175 {
176  return NULL;
177 }
178 #endif
179 
180 
186 #ifdef DEBUG
187 int DebugAtThisLevel(
190  Upnp_LogLevel DLevel,
192  Dbg_Module Module);
193 #else
194 static UPNP_INLINE int DebugAtThisLevel(
195  Upnp_LogLevel DLevel,
196  Dbg_Module Module)
197 {
198  return 0;
199 }
200 #endif
201 
202 
207 #ifdef DEBUG
208 void UpnpPrintf(
211  Upnp_LogLevel DLevel,
213  Dbg_Module Module,
215  const char* DbgFileName,
217  int DbgLineNo,
219  const char* FmtStr,
222  ...)
223 #if (__GNUC__ >= 3)
224  /* This enables printf like format checking by the compiler */
225  __attribute__((format (__printf__, 5, 6)))
226 #endif
227 ;
228 #else /* DEBUG */
229 static UPNP_INLINE void UpnpPrintf(
230  Upnp_LogLevel DLevel,
231  Dbg_Module Module,
232  const char* DbgFileName,
233  int DbgLineNo,
234  const char* FmtStr,
235  ...)
236 {
237 }
238 #endif /* DEBUG */
239 
240 
245 #ifdef DEBUG
248  FILE *fd,
250  const char *DbgFileName,
252  int DbgLineNo);
253 #else
255  FILE *fd,
256  const char *DbgFileName,
257  int DbgLineNo) {}
258 #endif
259 
260 
264 #ifdef DEBUG
265 void UpnpDisplayBanner(
267  FILE *fd,
269  const char **lines,
271  size_t size,
273  int starlength);
274 #else
275 static UPNP_INLINE void UpnpDisplayBanner(
276  FILE *fd,
277  const char **lines,
278  size_t size,
279  int starlength) {}
280 #endif
281 
282 
286 #ifdef DEBUG
289  ThreadPool *tp,
291  const char *DbgFileName,
293  int DbgLineNo,
295  const char *msg);
296 #else
298  ThreadPool *tp,
299  const char *DbgFileName,
300  int DbgLineNo,
301  const char *msg)
302 {
303 }
304 #endif
305 
306 
309 #ifdef __cplusplus
310 }
311 #endif
312 
313 #endif /* UPNP_DEBUG_H */
314 
void UpnpPrintf(Upnp_LogLevel DLevel, Dbg_Module Module, const char *DbgFileName, int DbgLineNo, const char *FmtStr,...)
Prints the debug statement either on the standard output or log file along with the information from ...
Definition: upnpdebug.c:148
int UpnpInitLog(void)
Initialize the log files.
Definition: upnpdebug.c:71
void PrintThreadPoolStats(ThreadPool *tp, const char *DbgFileName, int DbgLineNo, const char *msg)
Prints thread pool statistics.
Definition: upnpdebug.c:240
#define UPNP_E_SUCCESS
The operation completed successfully.
Definition: upnp.h:119
A thread pool similar to the thread pool in the UPnP SDK.
Definition: ThreadPool.h:266
void UpnpDisplayBanner(FILE *fd, const char **lines, size_t size, int starlength)
Writes the buffer in the file as per the requested banner.
void UpnpSetLogFileNames(const char *ErrFileName, const char *InfoFileName)
Set the name for error and information files, respectively.
Definition: upnpdebug.c:108
void UpnpSetLogLevel(Upnp_LogLevel log_level)
Set the log level (see Upnp_LogLevel).
Definition: upnpdebug.c:86
FILE * UpnpGetDebugFile(Upnp_LogLevel level, Dbg_Module module)
Check if the module is turned on for debug and returns the file descriptor corresponding to the debug...
Definition: upnpdebug.c:191
void UpnpDisplayFileAndLine(FILE *fd, const char *DbgFileName, int DbgLineNo)
Writes the file name and file number from where debug statement is coming to the log file...
Definition: upnpdebug.c:211
int DebugAtThisLevel(Upnp_LogLevel DLevel, Dbg_Module Module)
Returns true if debug output should be done in this module.
Definition: upnpdebug.c:129
void UpnpCloseLog(void)
Closes the log files.
Definition: upnpdebug.c:92
#define UPNP_INLINE
Declares an inline function.
Definition: UpnpGlobal.h:91
Defines constants that for some reason are not defined on some systems.