diff --git a/upnp/inc/upnpdebug.h b/upnp/inc/upnpdebug.h index 8e54a89..295038b 100644 --- a/upnp/inc/upnpdebug.h +++ b/upnp/inc/upnpdebug.h @@ -31,7 +31,7 @@ ******************************************************************************/ #ifndef UPNP_DEBUG_H -#define UPNP_DEBUG_H +#define UPNP_DEBUG_H /*! * \file @@ -39,7 +39,7 @@ #include "ThreadPool.h" #include "upnpconfig.h" -#include "UpnpGlobal.h" /* for UPNP_INLINE */ +#include "UpnpGlobal.h" /* for UPNP_INLINE */ #include @@ -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,11 +196,10 @@ 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. - */ + */ #ifdef DEBUG void UpnpPrintf( /*! [in] The level of the debug logging. It will decide whether debug @@ -212,27 +208,22 @@ void UpnpPrintf( /*! [in] debug will go in the name of this module. */ Dbg_Module Module, /*! [in] Name of the file from where debug statement is coming. */ - const char* DbgFileName, + const char *DbgFileName, /*! [in] Line number of the file from where debug statement is coming. */ int DbgLineNo, /*! [in] Printf like format specification. */ - const char* FmtStr, - /*! [in] Printf like Variable number of arguments that will go in the debug - * statement. */ + const char *FmtStr, + /*! [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 */ - __attribute__((format (__printf__, 5, 6))) + /* 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. */ - FILE *fd, + /*! [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,14 +258,13 @@ static UPNP_INLINE void UpnpDisplayFileAndLine( } #endif - /*! * \brief Writes the buffer in the file as per the requested banner */ #ifdef DEBUG void UpnpDisplayBanner( /*! [in] file descriptor where the banner will be written. */ - FILE *fd, + FILE * fd, /*! [in] The buffer that will be written. */ const char **lines, /*! [in] Size of the buffer. */ @@ -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,26 +283,24 @@ static UPNP_INLINE void UpnpDisplayBanner( } #endif - /*! * \brief Prints thread pool statistics. */ #ifdef DEBUG void PrintThreadPoolStats( /*! [in] The thread pool. */ - ThreadPool *tp, - /*! [in] The file name that called this function, use the macro __FILE__. */ + ThreadPool * tp, + /*! [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 */ - diff --git a/upnp/src/api/upnpdebug.c b/upnp/src/api/upnpdebug.c index e288979..04cc254 100644 --- a/upnp/src/api/upnpdebug.c +++ b/upnp/src/api/upnpdebug.c @@ -29,22 +29,22 @@ * ******************************************************************************/ -#include "config.h" +/*! + * \file + */ +#include "config.h" #include "ithread.h" #include "ixml.h" #include "upnp.h" #include "upnpdebug.h" - #include #include #include #include - - /*! Mutex to synchronize all the log file opeartions in the debug mode */ static ithread_mutex_t GlobalDebugMutex; @@ -63,31 +63,27 @@ 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); - if(DEBUG_TARGET == 1) { - if((ErrFileHnd = fopen( errFileName, "a")) == NULL) { + if (DEBUG_TARGET == 1) { + if ((ErrFileHnd = fopen(errFileName, "a")) == NULL) { return -1; } - if((InfoFileHnd = fopen( infoFileName, "a")) == NULL) { + if ((InfoFileHnd = fopen(infoFileName, "a")) == NULL) { return -1; } } return UPNP_E_SUCCESS; } - void UpnpSetLogLevel(Upnp_LogLevel log_level) { g_log_level = log_level; } - void UpnpCloseLog(void) { if (DEBUG_TARGET == 1) { @@ -99,71 +95,56 @@ 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; - } - if (InfoFileName) { - infoFileName = InfoFileName; - } + if (ErrFileName) { + errFileName = ErrFileName; + } + if (InfoFileName) { + infoFileName = InfoFileName; + } } - -int DebugAtThisLevel( - Upnp_LogLevel DLevel, - Dbg_Module Module) +int DebugAtThisLevel(Upnp_LogLevel DLevel, Dbg_Module Module) { int ret = DLevel <= g_log_level; ret &= - DEBUG_ALL || - (Module == SSDP && DEBUG_SSDP ) || - (Module == SOAP && DEBUG_SOAP ) || - (Module == GENA && DEBUG_GENA ) || - (Module == TPOOL && DEBUG_TPOOL) || - (Module == MSERV && DEBUG_MSERV) || - (Module == DOM && DEBUG_DOM ) || - (Module == HTTP && DEBUG_HTTP ); - + DEBUG_ALL || + (Module == SSDP && DEBUG_SSDP) || + (Module == SOAP && DEBUG_SOAP) || + (Module == GENA && DEBUG_GENA) || + (Module == TPOOL && DEBUG_TPOOL) || + (Module == MSERV && DEBUG_MSERV) || + (Module == DOM && DEBUG_DOM) || (Module == HTTP && DEBUG_HTTP); + return ret; } - -void UpnpPrintf( - Upnp_LogLevel DLevel, - Dbg_Module Module, - const char *DbgFileName, - int DbgLineNo, - const char *FmtStr, - ...) +void UpnpPrintf(Upnp_LogLevel DLevel, + Dbg_Module Module, + 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 @@ -216,24 +187,16 @@ void UpnpDisplayFileAndLine( #else (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,15 +244,13 @@ void UpnpDisplayBanner( free(leftMargin); } -void PrintThreadPoolStats( - ThreadPool *tp, - const char *DbgFileName, - int DbgLineNo, - const char *msg) +void PrintThreadPoolStats(ThreadPool *tp, + const char *DbgFileName, + int DbgLineNo, const char *msg) { ThreadPoolStats stats; ThreadPoolGetStats(tp, &stats); - UpnpPrintf(UPNP_INFO, API, DbgFileName, DbgLineNo, + UpnpPrintf(UPNP_INFO, API, DbgFileName, DbgLineNo, "%s\n" "High Jobs pending: %d\n" "Med Jobs Pending: %d\n" @@ -321,6 +281,4 @@ void PrintThreadPoolStats( stats.totalIdleTime); } - #endif /* DEBUG */ -