libUPnP  1.14.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 
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 } Upnp_LogLevel;
92 /* UPNP_PACKET probably resulted from a confusion between module and
93  level and was only used by a few messages in ssdp_device.c (they
94  have been moved to INFO). Kept for compatibility, don't use for new
95  messages.
96 */
97 #define UPNP_PACKET UPNP_ERROR
98 
102 #define UPNP_DEFAULT_LOG_LEVEL UPNP_ALL
103 
109 #ifdef DEBUG
110 int UpnpInitLog(void);
111 #else
112 static UPNP_INLINE int UpnpInitLog(void) { return UPNP_E_SUCCESS; }
113 #endif
114 
117 #ifdef DEBUG
118 void UpnpSetLogLevel(
120  Upnp_LogLevel log_level);
121 #else
122 static UPNP_INLINE void UpnpSetLogLevel(Upnp_LogLevel log_level)
123 {
124  (void)log_level;
125  return;
126 }
127 #endif
128 
132 #ifdef DEBUG
133 void UpnpCloseLog(void);
134 #else
135 static UPNP_INLINE void UpnpCloseLog(void) {}
136 #endif
137 
143 #ifdef DEBUG
146  const char *fileName,
148  const char *Ignored);
149 #else
150 static UPNP_INLINE void UpnpSetLogFileNames(
151  const char *ErrFileName, const char *ignored)
152 {
153  (void)ErrFileName;
154  (void)ignored;
155  return;
156 }
157 #endif
158 
166 #ifdef DEBUG
167 FILE *UpnpGetDebugFile(
170  Upnp_LogLevel level,
172  Dbg_Module module);
173 #else
174 static UPNP_INLINE FILE *UpnpGetDebugFile(
175  Upnp_LogLevel level, Dbg_Module module)
176 {
177  (void)level;
178  (void)module;
179  return NULL;
180 }
181 #endif
182 
187 #ifdef DEBUG
188 void UpnpPrintf(
191  Upnp_LogLevel DLevel,
193  Dbg_Module Module,
195  const char *DbgFileName,
198  int DbgLineNo,
200  const char *FmtStr,
203  ...)
204 #if (__GNUC__ >= 3)
205  /* This enables printf like format checking by the compiler. */
206  __attribute__((format(__printf__, 5, 6)))
207 #endif
208  ;
209 #else /* DEBUG */
210 static UPNP_INLINE void UpnpPrintf(Upnp_LogLevel DLevel,
211  Dbg_Module Module,
212  const char *DbgFileName,
213  int DbgLineNo,
214  const char *FmtStr,
215  ...)
216 #if (__GNUC__ >= 3)
217  /* This enables printf like format checking by the compiler. */
218  __attribute__((format(__printf__, 5, 6)))
219 #endif
220  ;
221 static UPNP_INLINE void UpnpPrintf(Upnp_LogLevel DLevel,
222  Dbg_Module Module,
223  const char *DbgFileName,
224  int DbgLineNo,
225  const char *FmtStr,
226  ...)
227 {
228  (void)DLevel;
229  (void)Module;
230  (void)DbgFileName;
231  (void)DbgLineNo;
232  (void)FmtStr;
233  return;
234 }
235 #endif /* DEBUG */
236 
237 #ifdef __cplusplus
238 }
239 #endif
240 
241 #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:230
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:104
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:262
void UpnpCloseLog(void)
Closes the log files.
Definition: upnpdebug.c:110
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:126
#define UPNP_INLINE
Declares an inline function.
Definition: UpnpGlobal.h:103
Defines constants that for some reason are not defined on some systems.