libUPnP  1.8.1
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 
40 #include "ThreadPool.h"
41 #include "upnpconfig.h"
42 #include "UpnpGlobal.h" /* for UPNP_INLINE */
43 
44 #include <stdio.h>
45 
46 #ifdef __cplusplus
47 extern "C" {
48 #endif
49 
55 
72 typedef enum Upnp_Module {
73  SSDP,
74  SOAP,
75  GENA,
76  TPOOL,
77  MSERV,
78  DOM,
79  API,
80  HTTP
81 } Dbg_Module;
82 
84 typedef enum Upnp_LogLevel_e {
85  UPNP_CRITICAL,
86  UPNP_PACKET,
87  UPNP_INFO,
88  UPNP_ALL
89 } Upnp_LogLevel;
95 #define UPNP_DEFAULT_LOG_LEVEL UPNP_ALL
96 
102 #ifdef DEBUG
103 int UpnpInitLog(void);
104 #else
105 static UPNP_INLINE int UpnpInitLog(void)
106 {
107  return UPNP_E_SUCCESS;
108 }
109 #endif
110 
113 #ifdef DEBUG
114 void UpnpSetLogLevel(
116  Upnp_LogLevel log_level);
117 #else
118 static UPNP_INLINE void UpnpSetLogLevel(Upnp_LogLevel log_level)
119 {
120  return;
121  log_level = log_level;
122 }
123 #endif
124 
128 #ifdef DEBUG
129 void UpnpCloseLog(void);
130 #else
131 static UPNP_INLINE void UpnpCloseLog(void)
132 {
133 }
134 #endif
135 
139 #ifdef DEBUG
142  const char *ErrFileName,
144  const char *InfoFileName);
145 #else
146 static UPNP_INLINE void UpnpSetLogFileNames(const char *ErrFileName,
147  const char *InfoFileName)
148 {
149  return;
150  ErrFileName = ErrFileName;
151  InfoFileName = InfoFileName;
152 }
153 #endif
154 
162 #ifdef DEBUG
163 FILE *UpnpGetDebugFile(
166  Upnp_LogLevel level,
168  Dbg_Module module);
169 #else
170 static UPNP_INLINE FILE *UpnpGetDebugFile(Upnp_LogLevel level, Dbg_Module module)
171 {
172  return NULL;
173  level = level;
174  module = module;
175 }
176 #endif
177 
183 #ifdef DEBUG
184 int DebugAtThisLevel(
187  Upnp_LogLevel DLevel,
189  Dbg_Module Module);
190 #else
191 static UPNP_INLINE int DebugAtThisLevel(Upnp_LogLevel DLevel, Dbg_Module Module)
192 {
193  return 0;
194  DLevel = DLevel;
195  Module = Module;
196 }
197 #endif
198 
203 #ifdef DEBUG
204 void UpnpPrintf(
207  Upnp_LogLevel DLevel,
209  Dbg_Module Module,
211  const char *DbgFileName,
213  int DbgLineNo,
215  const char *FmtStr,
218  ...)
219 #if (__GNUC__ >= 3)
220  /* This enables printf like format checking by the compiler. */
221  __attribute__ ((format(__printf__, 5, 6)))
222 #endif
223  ;
224 #else /* DEBUG */
225 static UPNP_INLINE void UpnpPrintf(Upnp_LogLevel DLevel, Dbg_Module Module,
226  const char *DbgFileName, int DbgLineNo, const char *FmtStr, ...)
227 {
228  return;
229  DLevel = DLevel;
230  Module = Module;
231  DbgFileName = DbgFileName;
232  DbgLineNo = DbgLineNo;
233  FmtStr = FmtStr;
234 }
235 #endif /* DEBUG */
236 
241 #ifdef DEBUG
245  FILE * fd,
247  const char *DbgFileName,
249  int DbgLineNo);
250 #else
251 static UPNP_INLINE void UpnpDisplayFileAndLine(FILE *fd,
252  const char *DbgFileName, int DbgLineNo)
253 {
254  return;
255  fd = fd;
256  DbgFileName = DbgFileName;
257  DbgLineNo = DbgLineNo;
258 }
259 #endif
260 
264 #ifdef DEBUG
265 void UpnpDisplayBanner(
267  FILE * fd,
269  const char **lines,
271  size_t size,
273  size_t starlength);
274 #else
275 static UPNP_INLINE void UpnpDisplayBanner(FILE *fd, const char **lines,
276  size_t size, int starlength)
277 {
278  return;
279  fd = fd;
280  lines = lines;
281  size = size;
282  starlength = starlength;
283 }
284 #endif
285 
288 #ifdef __cplusplus
289 }
290 #endif
291 
292 #endif /* UPNP_DEBUG_H */
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:126
int UpnpInitLog(void)
Initialize the log files.
Definition: upnpdebug.c:68
#define UPNP_E_SUCCESS
The operation completed successfully.
Definition: upnp.h:97
void UpnpSetLogFileNames(const char *ErrFileName, const char *InfoFileName)
Set the name for error and information files, respectively.
Definition: upnpdebug.c:100
void UpnpDisplayBanner(FILE *fd, const char **lines, size_t size, size_t starlength)
Writes the buffer in the file as per the requested banner.
Definition: upnpdebug.c:201
void UpnpSetLogLevel(Upnp_LogLevel log_level)
Set the log level (see Upnp_LogLevel).
Definition: upnpdebug.c:84
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...
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:174
int DebugAtThisLevel(Upnp_LogLevel DLevel, Dbg_Module Module)
Returns true if debug output should be done in this module.
Definition: upnpdebug.c:110
void UpnpCloseLog(void)
Closes the log files.
Definition: upnpdebug.c:89
#define UPNP_INLINE
Declares an inline function.
Definition: UpnpGlobal.h:93
Defines constants that for some reason are not defined on some systems.