(cherry picked from commit e8106e4f05)
This commit is contained in:
Marcelo Roberto Jimenez 2010-12-13 09:33:49 -02:00
parent ad0584150f
commit 59c70e2a0e
2 changed files with 84 additions and 144 deletions

View File

@ -107,7 +107,6 @@ static UPNP_INLINE int UpnpInitLog(void)
return UPNP_E_SUCCESS;
}
#endif
/*!
* \brief Set the log level (see \c Upnp_LogLevel).
*/
@ -129,7 +128,9 @@ static UPNP_INLINE void UpnpSetLogLevel(Upnp_LogLevel log_level)
#ifdef DEBUG
void UpnpCloseLog(void);
#else
static UPNP_INLINE void UpnpCloseLog(void) {}
static UPNP_INLINE void UpnpCloseLog(void)
{
}
#endif
/*!
@ -142,8 +143,7 @@ void UpnpSetLogFileNames(
/*! [in] Name of the information file. */
const char *InfoFileName);
#else
static UPNP_INLINE void UpnpSetLogFileNames(
const char *ErrFileName,
static UPNP_INLINE void UpnpSetLogFileNames(const char *ErrFileName,
const char *InfoFileName)
{
return;
@ -175,7 +175,6 @@ static UPNP_INLINE FILE *UpnpGetDebugFile(Upnp_LogLevel level, Dbg_Module module
}
#endif
/*!
* \brief Returns true if debug output should be done in this module.
*
@ -189,9 +188,7 @@ int DebugAtThisLevel(
/*! [in] Debug will go in the name of this module. */
Dbg_Module Module);
#else
static UPNP_INLINE int DebugAtThisLevel(
Upnp_LogLevel DLevel,
Dbg_Module Module)
static UPNP_INLINE int DebugAtThisLevel(Upnp_LogLevel DLevel, Dbg_Module Module)
{
return 0;
DLevel = DLevel;
@ -199,7 +196,6 @@ static UPNP_INLINE int DebugAtThisLevel(
}
#endif
/*!
* \brief Prints the debug statement either on the standard output or log file
* along with the information from where this debug statement is coming.
@ -217,22 +213,17 @@ void UpnpPrintf(
int DbgLineNo,
/*! [in] Printf like format specification. */
const char *FmtStr,
/*! [in] Printf like Variable number of arguments that will go in the debug
* statement. */
/*! [in] Printf like Variable number of arguments that will go in the
* debug statement. */
...)
#if (__GNUC__ >= 3)
/* This enables printf like format checking by the compiler */
/* This enables printf like format checking by the compiler. */
__attribute__ ((format(__printf__, 5, 6)))
#endif
;
#else /* DEBUG */
static UPNP_INLINE void UpnpPrintf(
Upnp_LogLevel DLevel,
Dbg_Module Module,
const char* DbgFileName,
int DbgLineNo,
const char* FmtStr,
...)
static UPNP_INLINE void UpnpPrintf(Upnp_LogLevel DLevel, Dbg_Module Module,
const char *DbgFileName, int DbgLineNo, const char *FmtStr, ...)
{
return;
DLevel = DLevel;
@ -243,24 +234,22 @@ static UPNP_INLINE void UpnpPrintf(
}
#endif /* DEBUG */
/*!
* \brief Writes the file name and file number from where debug statement is
* coming to the log file.
*/
#ifdef DEBUG
void UpnpDisplayFileAndLine(
/*! [in] File descriptor where line number and file name will be written. */
/*! [in] File descriptor where line number and file name will be
* written. */
FILE * fd,
/*! [in] Name of the file. */
const char *DbgFileName,
/*! [in] Line number of the file. */
int DbgLineNo);
#else
static UPNP_INLINE void UpnpDisplayFileAndLine(
FILE *fd,
const char *DbgFileName,
int DbgLineNo)
static UPNP_INLINE void UpnpDisplayFileAndLine(FILE *fd,
const char *DbgFileName, int DbgLineNo)
{
return;
fd = fd;
@ -269,7 +258,6 @@ static UPNP_INLINE void UpnpDisplayFileAndLine(
}
#endif
/*!
* \brief Writes the buffer in the file as per the requested banner
*/
@ -284,11 +272,8 @@ void UpnpDisplayBanner(
/*! [in] This parameter provides the width of the banner. */
size_t starlength);
#else
static UPNP_INLINE void UpnpDisplayBanner(
FILE *fd,
const char **lines,
size_t size,
int starlength)
static UPNP_INLINE void UpnpDisplayBanner(FILE *fd, const char **lines,
size_t size, int starlength)
{
return;
fd = fd;
@ -298,7 +283,6 @@ static UPNP_INLINE void UpnpDisplayBanner(
}
#endif
/*!
* \brief Prints thread pool statistics.
*/
@ -306,18 +290,17 @@ static UPNP_INLINE void UpnpDisplayBanner(
void PrintThreadPoolStats(
/*! [in] The thread pool. */
ThreadPool * tp,
/*! [in] The file name that called this function, use the macro __FILE__. */
/*! [in] The file name that called this function, use the macro
* __FILE__. */
const char *DbgFileName,
/*! [in] The line number that the function was called, use the macro __LINE__. */
/*! [in] The line number that the function was called, use the macro
* __LINE__. */
int DbgLineNo,
/*! [in] The message. */
const char *msg);
#else
static UPNP_INLINE void PrintThreadPoolStats(
ThreadPool *tp,
const char *DbgFileName,
int DbgLineNo,
const char *msg)
static UPNP_INLINE void PrintThreadPoolStats(ThreadPool *tp,
const char *DbgFileName, int DbgLineNo, const char *msg)
{
return;
tp = tp;
@ -334,4 +317,3 @@ static UPNP_INLINE void PrintThreadPoolStats(
#endif
#endif /* UPNP_DEBUG_H */

View File

@ -29,22 +29,22 @@
*
******************************************************************************/
#include "config.h"
/*!
* \file
*/
#include "config.h"
#include "ithread.h"
#include "ixml.h"
#include "upnp.h"
#include "upnpdebug.h"
#include <stdarg.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
/*! Mutex to synchronize all the log file opeartions in the debug mode */
static ithread_mutex_t GlobalDebugMutex;
@ -63,10 +63,8 @@ static const char *errFileName = "IUpnpErrFile.txt";
/*! Name of the info file */
static const char *infoFileName = "IUpnpInfoFile.txt";
#ifdef DEBUG
int UpnpInitLog(void)
{
ithread_mutex_init(&GlobalDebugMutex, NULL);
@ -81,13 +79,11 @@ int UpnpInitLog(void)
return UPNP_E_SUCCESS;
}
void UpnpSetLogLevel(Upnp_LogLevel log_level)
{
g_log_level = log_level;
}
void UpnpCloseLog(void)
{
if (DEBUG_TARGET == 1) {
@ -99,10 +95,7 @@ void UpnpCloseLog(void)
ithread_mutex_destroy(&GlobalDebugMutex);
}
void UpnpSetLogFileNames(
const char *ErrFileName,
const char *InfoFileName)
void UpnpSetLogFileNames(const char *ErrFileName, const char *InfoFileName)
{
if (ErrFileName) {
errFileName = ErrFileName;
@ -112,10 +105,7 @@ void UpnpSetLogFileNames(
}
}
int DebugAtThisLevel(
Upnp_LogLevel DLevel,
Dbg_Module Module)
int DebugAtThisLevel(Upnp_LogLevel DLevel, Dbg_Module Module)
{
int ret = DLevel <= g_log_level;
ret &=
@ -125,45 +115,36 @@ int DebugAtThisLevel(
(Module == GENA && DEBUG_GENA) ||
(Module == TPOOL && DEBUG_TPOOL) ||
(Module == MSERV && DEBUG_MSERV) ||
(Module == DOM && DEBUG_DOM ) ||
(Module == HTTP && DEBUG_HTTP );
(Module == DOM && DEBUG_DOM) || (Module == HTTP && DEBUG_HTTP);
return ret;
}
void UpnpPrintf(
Upnp_LogLevel DLevel,
void UpnpPrintf(Upnp_LogLevel DLevel,
Dbg_Module Module,
const char *DbgFileName,
int DbgLineNo,
const char *FmtStr,
...)
const char *DbgFileName, int DbgLineNo, const char *FmtStr, ...)
{
va_list ArgList;
if (!DebugAtThisLevel(DLevel, Module)) {
if (!DebugAtThisLevel(DLevel, Module))
return;
}
ithread_mutex_lock(&GlobalDebugMutex);
va_start(ArgList, FmtStr);
if (!DEBUG_TARGET) {
if (DbgFileName) {
if (DbgFileName)
UpnpDisplayFileAndLine(stdout, DbgFileName, DbgLineNo);
}
vfprintf(stdout, FmtStr, ArgList);
fflush(stdout);
} else if (DLevel == 0) {
if (DbgFileName) {
UpnpDisplayFileAndLine(ErrFileHnd, DbgFileName, DbgLineNo);
}
if (DbgFileName)
UpnpDisplayFileAndLine(ErrFileHnd, DbgFileName,
DbgLineNo);
vfprintf(ErrFileHnd, FmtStr, ArgList);
fflush(ErrFileHnd);
} else {
if (DbgFileName) {
UpnpDisplayFileAndLine(InfoFileHnd, DbgFileName, DbgLineNo);
}
if (DbgFileName)
UpnpDisplayFileAndLine(InfoFileHnd, DbgFileName,
DbgLineNo);
vfprintf(InfoFileHnd, FmtStr, ArgList);
fflush(InfoFileHnd);
}
@ -171,31 +152,23 @@ void UpnpPrintf(
ithread_mutex_unlock(&GlobalDebugMutex);
}
FILE *GetDebugFile(Upnp_LogLevel DLevel, Dbg_Module Module)
{
FILE *ret;
if (!DebugAtThisLevel(DLevel, Module)) {
if (!DebugAtThisLevel(DLevel, Module))
ret = NULL;
}
if (!DEBUG_TARGET) {
if (!DEBUG_TARGET)
ret = stdout;
} else if (DLevel == 0) {
else if (DLevel == 0)
ret = ErrFileHnd;
} else {
else
ret = InfoFileHnd;
}
return ret;
}
void UpnpDisplayFileAndLine(
FILE *fd,
const char *DbgFileName,
int DbgLineNo)
void UpnpDisplayFileAndLine(FILE *fd, const char *DbgFileName, int DbgLineNo)
{
#define NLINES 2
#define MAX_LINE_SIZE 512
@ -205,10 +178,8 @@ void UpnpDisplayFileAndLine(
int i;
/* Initialize the pointer array */
for (i = 0; i < NLINES; i++) {
for (i = 0; i < NLINES; i++)
lines[i] = buf[i];
}
/* Put the debug lines in the buffer */
sprintf(buf[0], "DEBUG - THREAD ID: 0x%lX",
#ifdef WIN32
@ -217,23 +188,15 @@ void UpnpDisplayFileAndLine(
(unsigned long int)ithread_self()
#endif
);
if (DbgFileName) {
sprintf(buf[1],
"FILE: %s, LINE: %d",
DbgFileName,
DbgLineNo);
}
if (DbgFileName)
sprintf(buf[1], "FILE: %s, LINE: %d", DbgFileName, DbgLineNo);
/* Show the lines centered */
UpnpDisplayBanner(fd, lines, NLINES, NUMBER_OF_STARS);
fflush(fd);
}
void UpnpDisplayBanner(
FILE * fd,
const char **lines,
size_t size,
size_t starLength)
void UpnpDisplayBanner(FILE * fd,
const char **lines, size_t size, size_t starLength)
{
size_t leftMarginLength = starLength / 2 + 1;
size_t rightMarginLength = starLength / 2 + 1;
@ -263,11 +226,10 @@ void UpnpDisplayBanner(
line += starLengthMinus2;
}
leftMarginLength = (starLengthMinus2 - LineSize) / 2;
if (LineSize % 2 == 0) {
if (LineSize % 2 == 0)
rightMarginLength = leftMarginLength;
} else {
else
rightMarginLength = leftMarginLength + 1;
}
memset(leftMargin, ' ', leftMarginLength);
memset(rightMargin, ' ', rightMarginLength);
leftMargin[leftMarginLength] = 0;
@ -282,11 +244,9 @@ void UpnpDisplayBanner(
free(leftMargin);
}
void PrintThreadPoolStats(
ThreadPool *tp,
void PrintThreadPoolStats(ThreadPool *tp,
const char *DbgFileName,
int DbgLineNo,
const char *msg)
int DbgLineNo, const char *msg)
{
ThreadPoolStats stats;
ThreadPoolGetStats(tp, &stats);
@ -321,6 +281,4 @@ void PrintThreadPoolStats(
stats.totalIdleTime);
}
#endif /* DEBUG */