libUPnP  1.14.22
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 "UpnpGlobal.h" /* for UPNP_INLINE */
41 #include "upnpconfig.h"
42 
43 #include <stdio.h>
44 
45 #ifdef __cplusplus
46 extern "C" {
47 #endif
48 
54 
70 typedef enum Upnp_Module
71 {
72  SSDP,
73  SOAP,
74  GENA,
75  TPOOL,
76  MSERV,
77  DOM,
78  API,
79  HTTP
80 } Dbg_Module;
81 
83 typedef enum Upnp_LogLevel_e
84 {
85  UPNP_CRITICAL,
86  UPNP_ERROR,
87  UPNP_INFO,
88  UPNP_ALL,
89  /* Always the last, please. */
90  UPNP_NEVER
91 } Upnp_LogLevel;
94 /* UPNP_PACKET probably resulted from a confusion between module and
95  level and was only used by a few messages in ssdp_device.c (they
96  have been moved to INFO). Kept for compatibility, don't use for new
97  messages.
98 */
99 #define UPNP_PACKET UPNP_ERROR
100 
104 #define UPNP_DEFAULT_LOG_LEVEL UPNP_ALL
105 
111 UPNP_EXPORT_SPEC int UpnpInitLog(void);
112 
113 #if defined NDEBUG && !defined UPNP_DEBUG_C
114  #define UpnpInitLog UpnpInitLog_Inlined
115 static UPNP_INLINE int UpnpInitLog_Inlined(void) { return UPNP_E_SUCCESS; }
116 #endif
117 
122  Upnp_LogLevel log_level);
123 
124 #if defined NDEBUG && !defined UPNP_DEBUG_C
125  #define UpnpSetLogLevel UpnpSetLogLevel_Inlined
126 static UPNP_INLINE void UpnpSetLogLevel_Inlined(Upnp_LogLevel log_level)
127 {
128  (void)log_level;
129  return;
130 }
131 #endif
132 
136 void UpnpCloseLog(void);
137 
138 #if defined NDEBUG && !defined UPNP_DEBUG_C
139  #define UpnpCloseLog UpnpCloseLog_Inlined
140 static UPNP_INLINE void UpnpCloseLog_Inlined(void) {}
141 #endif
142 
150  const char *fileName,
152  const char *Ignored);
153 
154 #if defined NDEBUG && !defined UPNP_DEBUG_C
155  #define UpnpSetLogFileNames UpnpSetLogFileNames_Inlined
156 static UPNP_INLINE void UpnpSetLogFileNames_Inlined(
157  const char *ErrFileName, const char *ignored)
158 {
159  (void)ErrFileName;
160  (void)ignored;
161  return;
162 }
163 #endif
164 
172 FILE *UpnpGetDebugFile(
175  Upnp_LogLevel level,
177  Dbg_Module module);
178 
179 #if defined NDEBUG && !defined UPNP_DEBUG_C
180  #define UpnpGetDebugFile UpnpGetDebugFile_Inlined
181 static UPNP_INLINE FILE *UpnpGetDebugFile_Inlined(
182  Upnp_LogLevel level, Dbg_Module module)
183 {
184  (void)level;
185  (void)module;
186  return NULL;
187 }
188 #endif
189 
194 void UpnpPrintf(
197  Upnp_LogLevel DLevel,
199  Dbg_Module Module,
201  const char *DbgFileName,
204  int DbgLineNo,
206  const char *FmtStr,
209  ...)
210 #if (__GNUC__ >= 3)
211  /* This enables printf like format checking by the compiler. */
212  __attribute__((format(__printf__, 5, 6)))
213 #endif
214  ;
215 
216 #if defined NDEBUG && !defined UPNP_DEBUG_C
217  #define UpnpPrintf UpnpPrintf_Inlined
218 // static UPNP_INLINE void UpnpPrintf_Inlined(Upnp_LogLevel DLevel,
219 // Dbg_Module Module,
220 // const char *DbgFileName,
221 // int DbgLineNo,
222 // const char *FmtStr,
223 // ...)
224 // #if (__GNUC__ >= 3)
225 // /* This enables printf like format checking by the compiler. */
226 // __attribute__((format(__printf__, 5, 6)))
227 // #endif
228 // ;
229 static UPNP_INLINE void UpnpPrintf_Inlined(Upnp_LogLevel DLevel,
230  Dbg_Module Module,
231  const char *DbgFileName,
232  int DbgLineNo,
233  const char *FmtStr,
234  ...)
235 {
236  (void)DLevel;
237  (void)Module;
238  (void)DbgFileName;
239  (void)DbgLineNo;
240  (void)FmtStr;
241  return;
242 }
243 #endif /* DEBUG */
244 
245 #ifdef __cplusplus
246 }
247 #endif
248 
249 #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:259
int UpnpInitLog(void)
Initialize the log files.
Definition: upnpdebug.c:71
#define UPNP_E_SUCCESS
The operation completed successfully.
Definition: upnp.h:97
void UpnpSetLogLevel(Upnp_LogLevel log_level)
Set the log level (see Upnp_LogLevel).
Definition: upnpdebug.c:114
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:295
#define UPNP_EXPORT_SPEC
Export functions on WIN32 DLLs.
Definition: UpnpGlobal.h:105
void UpnpCloseLog(void)
Closes the log files.
Definition: upnpdebug.c:120
void UpnpSetLogFileNames(const char *fileName, const char *Ignored)
Set the name for the log file. There used to be 2 separate files. The second parameter has been kept ...
Definition: upnpdebug.c:141
#define UPNP_INLINE
Declares an inline function.
Definition: UpnpGlobal.h:119
Defines constants that for some reason are not defined on some systems.