XnLog.h
Go to the documentation of this file.
00001 /*****************************************************************************
00002 *                                                                            *
00003 *  OpenNI 1.0 Alpha                                                          *
00004 *  Copyright (C) 2010 PrimeSense Ltd.                                        *
00005 *                                                                            *
00006 *  This file is part of OpenNI.                                              *
00007 *                                                                            *
00008 *  OpenNI is free software: you can redistribute it and/or modify            *
00009 *  it under the terms of the GNU Lesser General Public License as published  *
00010 *  by the Free Software Foundation, either version 3 of the License, or      *
00011 *  (at your option) any later version.                                       *
00012 *                                                                            *
00013 *  OpenNI is distributed in the hope that it will be useful,                 *
00014 *  but WITHOUT ANY WARRANTY; without even the implied warranty of            *
00015 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the              *
00016 *  GNU Lesser General Public License for more details.                       *
00017 *                                                                            *
00018 *  You should have received a copy of the GNU Lesser General Public License  *
00019 *  along with OpenNI. If not, see <http://www.gnu.org/licenses/>.            *
00020 *                                                                            *
00021 *****************************************************************************/
00022 
00023 
00024 
00025 
00026 #ifndef _XN_LOG_H_
00027 #define _XN_LOG_H_
00028 
00029 //---------------------------------------------------------------------------
00030 // Includes
00031 //---------------------------------------------------------------------------
00032 #include "XnOS.h"
00033 
00034 //---------------------------------------------------------------------------
00035 // Defines
00036 //---------------------------------------------------------------------------
00037 #define XN_LOG_DIR_NAME                 "Log"
00038 #define XN_LOG_MASKS_STRING_LEN 600
00039 #define XN_MASK_LOG                             "Log"
00040 #define XN_LOG_MASK_ALL                 "ALL"
00041 
00042 //---------------------------------------------------------------------------
00043 // Enums
00044 //---------------------------------------------------------------------------
00045 typedef enum XnLogSeverity
00046 {
00047         XN_LOG_VERBOSE,
00048         XN_LOG_INFO,
00049         XN_LOG_WARNING,
00050         XN_LOG_ERROR
00051 } XnLogSeverity;
00052 
00053 typedef enum
00054 {
00055         XN_LOG_WRITE_NONE,
00056         XN_LOG_WRITE_ALL,
00057         XN_LOG_WRITE_MASKS
00058 } XnLogFilteringType;
00059 
00060 //---------------------------------------------------------------------------
00061 // Types
00062 //---------------------------------------------------------------------------
00063 
00064 typedef struct XnDump 
00065 {
00066         XN_FILE_HANDLE hFile;
00067 } XnDump;
00068 
00069 const XnDump XN_DUMP_CLOSED = { XN_INVALID_FILE_HANDLE };
00070  
00071 //---------------------------------------------------------------------------
00072 // Exported Function Declaration
00073 //---------------------------------------------------------------------------
00074 
00078 XN_C_API XnStatus xnLogInitSystem();
00079 
00086 XN_C_API XnStatus xnLogInitFromINIFile(const XnChar* csINIFile, const XnChar* csSectionName);
00087 
00093 XN_C_API XnStatus xnLogInitFromXmlFile(const XnChar* strFileName);
00094 
00098 XN_C_API XnStatus xnLogStartNewFile();
00099 
00103 XN_C_API XnStatus xnLogClose();
00104 
00111 XN_C_API XnStatus xnLogSetMaskState(const XnChar* csMask, XnBool bEnabled);
00112 
00119 XN_C_API XnStatus xnDumpSetMaskState(const XnChar* csMask, XnBool bEnabled);
00120 
00126 XN_C_API XnStatus xnLogSetSeverityFilter(XnLogSeverity nMinSeverity);
00127 
00133 XN_C_API XnStatus xnLogSetConsoleOutput(XnBool bConsoleOutput);
00134 
00140 XN_C_API XnStatus xnLogSetFileOutput(XnBool bFileOutput);
00141 
00147 XN_C_API XnStatus xnLogSetLineInfo(XnBool bLineInfo);
00148 
00154 XN_C_API XnStatus xnLogSetOutputFolder(const XnChar* strOutputFolder);
00155 
00162 XN_C_API XnBool xnLogIsEnabled(const XnChar* csLogMask, XnLogSeverity nSeverity);
00163 
00173 XN_C_API void xnLogWrite(const XnChar* csLogMask, XnLogSeverity nSeverity, const XnChar* csFile, XnUInt32 nLine, const XnChar* csFormat, ...);
00174 
00184 XN_C_API void xnLogWriteNoEntry(const XnChar* csLogMask, XnLogSeverity nSeverity, const XnChar* csFormat, ...);
00185 
00197 XN_C_API void xnLogWriteBinaryData(const XnChar* csLogMask, XnLogSeverity nSeverity, const XnChar* csFile, XnUInt32 nLine, XnUChar* pBinData, XnUInt32 nDataSize, const XnChar* csFormat, ...);
00198 
00204 XN_C_API XnBool xnLogIsDumpMaskEnabled(const XnChar* csDumpMask);
00205 
00218 XN_C_API void xnDumpInit(XnDump* pDump, const XnChar* csDumpMask, const XnChar* csHeader, const XnChar* csFileNameFormat, ...);
00219 
00231 XN_C_API void xnDumpForceInit(XnDump* pDump, const XnChar* csHeader, const XnChar* csFileNameFormat, ...);
00232 
00239 XN_C_API void xnDumpClose(XnDump* pDump);
00240 
00248 XN_C_API void xnDumpWriteBufferImpl(XnDump dump, const void* pBuffer, XnUInt32 nBufferSize);
00249 
00250 inline void xnDumpWriteBuffer(XnDump dump, const void* pBuffer, XnUInt32 nBufferSize)
00251 {
00252         if (dump.hFile != XN_INVALID_FILE_HANDLE)
00253         {
00254                 xnDumpWriteBufferImpl(dump, pBuffer, nBufferSize);
00255         }
00256 }
00257 
00265 XN_C_API void xnDumpWriteStringImpl(XnDump dump, const XnChar* csFormat, ...);
00266 
00267 #if XN_PLATFORM_VAARGS_TYPE == XN_PLATFORM_USE_WIN32_VAARGS_STYLE
00268         #define xnDumpWriteString(dump, csFormat, ...)                                  \
00269                 if ((dump).hFile != XN_INVALID_FILE_HANDLE) {                                   \
00270                         xnDumpWriteStringImpl((dump), csFormat, __VA_ARGS__);           \
00271                 }
00272 #elif XN_PLATFORM_VAARGS_TYPE == XN_PLATFORM_USE_GCC_VAARGS_STYLE
00273         #define xnDumpWriteString(dump, csFormat, ...)                                  \
00274                 if ((dump).hFile != XN_INVALID_FILE_HANDLE) {                                   \
00275                         xnDumpWriteStringImpl((dump), csFormat, ##__VA_ARGS__); \
00276                 }
00277 #elif XN_PLATFORM_VAARGS_TYPE == XN_PLATFORM_USE_ARC_VAARGS_STYLE
00278         #define xnDumpWriteString(dump, csFormat, args...)                              \
00279                 if ((dump).hFile != XN_INVALID_FILE_HANDLE) {                                   \
00280                         xnDumpWriteStringImpl((dump), csFormat, args);                  \
00281                 }
00282 #elif XN_PLATFORM_VAARGS_TYPE == XN_PLATFORM_USE_NO_VAARGS
00283         #define xnDumpWriteString(dump, csFormat, arg)                                  \
00284                 if ((dump).hFile != XN_INVALID_FILE_HANDLE) {                                   \
00285                         xnDumpWriteStringImpl((dump), csFormat, arg);                           \
00286                 }
00287 #else
00288         #error Xiron Log - Unknown VAARGS type!
00289 #endif
00290 
00296 XN_C_API void xnDumpFlush(XnDump dump);
00297 
00298 
00299 #if XN_PLATFORM_VAARGS_TYPE == XN_PLATFORM_USE_WIN32_VAARGS_STYLE
00300         #define xnLogVerbose(csLogMask, csFormat, ...)  xnLogWrite(csLogMask, XN_LOG_VERBOSE, __FILE__, __LINE__, csFormat, __VA_ARGS__)
00301         #define xnLogInfo(csLogMask, csFormat, ...)             xnLogWrite(csLogMask, XN_LOG_INFO, __FILE__, __LINE__, csFormat, __VA_ARGS__)
00302         #define xnLogWarning(csLogMask, csFormat, ...)  xnLogWrite(csLogMask, XN_LOG_WARNING, __FILE__, __LINE__, csFormat, __VA_ARGS__)
00303         #define xnLogError(csLogMask, csFormat, ...)    xnLogWrite(csLogMask, XN_LOG_ERROR, __FILE__, __LINE__, csFormat, __VA_ARGS__)
00304 
00305         /* Writes to the log and returns nRetVal */
00306         #define XN_LOG_RETURN(nRetVal, nSeverity, csLogMask, csFormat, ...)                                                     \
00307                 {                                                                                                                                                                               \
00308                         xnLogWrite(csLogMask, nSeverity, __FILE__, __LINE__, csFormat, __VA_ARGS__);            \
00309                         return (nRetVal);                                                                                                                                       \
00310                 }
00311 
00312         /* Logs a warning and returns nRetVal */
00313         #define XN_LOG_WARNING_RETURN(nRetVal, csLogMask, csFormat, ...)                                                \
00314                 XN_LOG_RETURN(nRetVal, XN_LOG_WARNING, csLogMask, csFormat, __VA_ARGS__)
00315 
00316         /* Logs a warning and returns nRetVal */
00317         #define XN_LOG_ERROR_RETURN(nRetVal, csLogMask, csFormat, ...)                                                  \
00318                 XN_LOG_RETURN(nRetVal, XN_LOG_ERROR, csLogMask, csFormat, __VA_ARGS__)
00319 
00320         /* If nRetVal is not ok, writes to the log and returns nRetVal */
00321         #define XN_IS_STATUS_OK_LOG(nRetVal, nSeverity, csLogMask, csFormat, ...)                                       \
00322                 if (nRetVal != XN_STATUS_OK)                                                                                                                    \
00323                 {                                                                                                                                                                               \
00324                         XN_LOG_RETURN(nRetVal, nSeverity, csLogMask, csFormat, __VA_ARGS__)                                     \
00325                 }                                                                                                                                                                               
00326 
00327         /* If nRetVal is not ok, logs a warning and returns nRetVal */
00328         #define XN_IS_STATUS_OK_WARNING(nRetVal, csLogMask, csFormat, ...) \
00329                 XN_IS_STATUS_OK_LOG(nRetVal, XN_LOG_WARNING, csLogMask, csFormat, __VA_ARGS__)
00330 
00331         /* If nRetVal is not ok, logs an error and returns nRetVal */
00332         #define XN_IS_STATUS_OK_ERROR(nRetVal, csLogMask, csFormat, ...) \
00333                 XN_IS_STATUS_OK_LOG(nRetVal, XN_LOG_ERROR, csLogMask, csFormat, __VA_ARGS__)
00334 
00335 #elif XN_PLATFORM_VAARGS_TYPE == XN_PLATFORM_USE_GCC_VAARGS_STYLE
00336         #define xnLogVerbose(csLogMask, csFormat, ...)  xnLogWrite(csLogMask, XN_LOG_VERBOSE, __FILE__, __LINE__, csFormat, ##__VA_ARGS__)
00337         #define xnLogInfo(csLogMask, csFormat, ...)             xnLogWrite(csLogMask, XN_LOG_INFO, __FILE__, __LINE__, csFormat, ##__VA_ARGS__)
00338         #define xnLogWarning(csLogMask, csFormat, ...)  xnLogWrite(csLogMask, XN_LOG_WARNING, __FILE__, __LINE__, csFormat, ##__VA_ARGS__)
00339         #define xnLogError(csLogMask, csFormat, ...)    xnLogWrite(csLogMask, XN_LOG_ERROR, __FILE__, __LINE__, csFormat, ##__VA_ARGS__)
00340 
00341         /* Writes to the log and returns nRetVal */
00342         #define XN_LOG_RETURN(nRetVal, nSeverity, csLogMask, csFormat, ...)                                             \
00343         {                                                                                                                                                                               \
00344                 xnLogWrite(csLogMask, nSeverity, __FILE__, __LINE__, csFormat, ##__VA_ARGS__);          \
00345                 return (nRetVal);                                                                                                                                       \
00346         }
00347 
00348         /* Logs a warning and returns nRetVal */
00349         #define XN_LOG_WARNING_RETURN(nRetVal, csLogMask, csFormat, ...)                                                \
00350                 XN_LOG_RETURN(nRetVal, XN_LOG_WARNING, csLogMask, csFormat, ##__VA_ARGS__)
00351 
00352         /* Logs a warning and returns nRetVal */
00353         #define XN_LOG_ERROR_RETURN(nRetVal, csLogMask, csFormat, ...)                                                  \
00354                 XN_LOG_RETURN(nRetVal, XN_LOG_ERROR, csLogMask, csFormat, ##__VA_ARGS__)
00355 
00356         /* If nRetVal is not ok, writes to the log and returns nRetVal */
00357         #define XN_IS_STATUS_OK_LOG(nRetVal, nSeverity, csLogMask, csFormat, ...)                                       \
00358                 if (nRetVal != XN_STATUS_OK)                                                                                                                    \
00359         {                                                                                                                                                                               \
00360                 XN_LOG_RETURN(nRetVal, nSeverity, csLogMask, csFormat, ##__VA_ARGS__)                                   \
00361         }                                                                                                                                                                               
00362 
00363         /* If nRetVal is not ok, logs a warning and returns nRetVal */
00364         #define XN_IS_STATUS_OK_WARNING(nRetVal, csLogMask, csFormat, ...) \
00365                 XN_IS_STATUS_OK_LOG(nRetVal, XN_LOG_WARNING, csLogMask, csFormat, ##__VA_ARGS__)
00366 
00367         /* If nRetVal is not ok, logs an error and returns nRetVal */
00368         #define XN_IS_STATUS_OK_ERROR(nRetVal, csLogMask, csFormat, ...) \
00369                 XN_IS_STATUS_OK_LOG(nRetVal, XN_LOG_ERROR, csLogMask, csFormat, ##__VA_ARGS__)
00370 
00371 #elif XN_PLATFORM_VAARGS_TYPE == XN_PLATFORM_USE_ARC_VAARGS_STYLE
00372         #define xnLogVerbose(csLogMask, csFormat, args...)      xnLogWrite(csLogMask, XN_LOG_VERBOSE, __FILE__, __LINE__, csFormat, args)
00373         #define xnLogInfo(csLogMask, csFormat, args...)         xnLogWrite(csLogMask, XN_LOG_INFO, __FILE__, __LINE__, csFormat, args)
00374         #define xnLogWarning(csLogMask, csFormat, args...)      xnLogWrite(csLogMask, XN_LOG_WARNING, __FILE__, __LINE__, csFormat, args)
00375         #define xnLogError(csLogMask, csFormat, args...)        xnLogWrite(csLogMask, XN_LOG_ERROR, __FILE__, __LINE__, csFormat, args)
00376 
00377         /* Writes to the log and returns nRetVal */
00378         #define XN_LOG_RETURN(nRetVal, nSeverity, csLogMask, csFormat, args...)                                 \
00379         {                                                                                                                                                                               \
00380                 xnLogWrite(csLogMask, nSeverity, __FILE__, __LINE__, csFormat, args);                           \
00381                 return (nRetVal);                                                                                                                                       \
00382         }
00383 
00384         /* Logs a warning and returns nRetVal */
00385         #define XN_LOG_WARNING_RETURN(nRetVal, csLogMask, csFormat, args...)                                    \
00386                 XN_LOG_RETURN(nRetVal, XN_LOG_WARNING, csLogMask, csFormat, args)
00387 
00388         /* Logs a warning and returns nRetVal */
00389         #define XN_LOG_ERROR_RETURN(nRetVal, csLogMask, csFormat, args...)                                              \
00390                 XN_LOG_RETURN(nRetVal, XN_LOG_ERROR, csLogMask, csFormat, args)
00391 
00392         /* If nRetVal is not ok, writes to the log and returns nRetVal */
00393         #define XN_IS_STATUS_OK_LOG(nRetVal, nSeverity, csLogMask, csFormat, args...)                   \
00394                 if (nRetVal != XN_STATUS_OK)                                                                                                            \
00395         {                                                                                                                                                                               \
00396                 XN_LOG_RETURN(nRetVal, nSeverity, csLogMask, csFormat, args)                                            \
00397         }                                                                                                                                                                               
00398 
00399         /* If nRetVal is not ok, logs a warning and returns nRetVal */
00400         #define XN_IS_STATUS_OK_WARNING(nRetVal, csLogMask, csFormat, args...) \
00401                 XN_IS_STATUS_OK_LOG(nRetVal, XN_LOG_WARNING, csLogMask, csFormat, args)
00402 
00403         /* If nRetVal is not ok, logs an error and returns nRetVal */
00404         #define XN_IS_STATUS_OK_ERROR(nRetVal, csLogMask, csFormat, args...) \
00405                 XN_IS_STATUS_OK_LOG(nRetVal, XN_LOG_ERROR, csLogMask, csFormat, args)
00406 
00407 #elif XN_PLATFORM_VAARGS_TYPE == XN_PLATFORM_USE_NO_VAARGS
00408         #define xnLogVerbose(csLogMask, csFormat, args) xnLogWrite(csLogMask, XN_LOG_VERBOSE, __FILE__, __LINE__, csFormat, args)
00409         #define xnLogInfo(csLogMask, csFormat, args)    xnLogWrite(csLogMask, XN_LOG_INFO, __FILE__, __LINE__, csFormat, args)
00410         #define xnLogWarning(csLogMask, csFormat, args) xnLogWrite(csLogMask, XN_LOG_WARNING, __FILE__, __LINE__, csFormat, args)
00411         #define xnLogError(csLogMask, csFormat, args)   xnLogWrite(csLogMask, XN_LOG_ERROR, __FILE__, __LINE__, csFormat, args)
00412 
00413         /* Writes to the log and returns nRetVal */
00414         #define XN_LOG_RETURN(nRetVal, nSeverity csLogMask, csFormat, args)                                             \
00415         {                                                                                                                                                                               \
00416                 xnLogWrite(csLogMask, nSeverity, __FILE__, __LINE__, csFormat, args);                           \
00417                 return (nRetVal);                                                                                                                                       \
00418         }
00419 
00420         /* Logs a warning and returns nRetVal */
00421         #define XN_LOG_WARNING_RETURN(nRetVal, csLogMask, csFormat, args)                                               \
00422                 XN_LOG_RETURN(nRetVal, XN_LOG_WARNING, csLogMask, csFormat, args)
00423 
00424         /* Logs a warning and returns nRetVal */
00425         #define XN_LOG_ERROR_RETURN(nRetVal, csLogMask, csFormat, args)                                                 \
00426                 XN_LOG_RETURN(nRetVal, XN_LOG_ERROR, csLogMask, csFormat, args)
00427 
00428         /* If nRetVal is not ok, writes to the log and returns nRetVal */
00429         #define XN_IS_STATUS_OK_LOG(nRetVal, nSeverity, csLogMask, csFormat, args)                              \
00430                 if (nRetVal != XN_STATUS_OK)                                                                                                            \
00431                 {                                                                                                                                                                       \
00432                         XN_LOG_RETURN(nRetVal, nSeverity, csLogMask, csFormat, args)                                    \
00433                 }                                                                                                                                                                               
00434 
00435         /* If nRetVal is not ok, logs a warning and returns nRetVal */
00436         #define XN_IS_STATUS_OK_WARNING(nRetVal, csLogMask, csFormat, args) \
00437                 XN_IS_STATUS_OK_LOG(nRetVal, XN_LOG_WARNING, csLogMask, csFormat, args)
00438 
00439         /* If nRetVal is not ok, logs an error and returns nRetVal */
00440         #define XN_IS_STATUS_OK_ERROR(nRetVal, csLogMask, csFormat, args) \
00441                 XN_IS_STATUS_OK_LOG(nRetVal, XN_LOG_ERROR, csLogMask, csFormat, args)
00442 
00443 #else
00444         #error Xiron Log - Unknown VAARGS type!
00445 #endif
00446 
00447 //#define XN_NO_LOGS
00448 
00449 #if (defined(XN_NO_LOGS) && !defined(XN_LOG_IMPL))
00450         #define xnLogWrite
00451         #define xnLogWriteBinaryData
00452         #define xnLogIsDumpMaskEnabled(mask) FALSE
00453         #define xnDumpInit(dump,mask,header,format,...) NULL
00454         #define xnDumpForceInit(dump,header,format,...) NULL
00455         #define xnDumpClose
00456         #define xnDumpWriteBufferImpl
00457         #define xnDumpWriteStringImpl
00458         #undef xnDumpWriteBuffer
00459         #define xnDumpWriteBuffer
00460         #undef xnDumpWriteString
00461         #define xnDumpWriteString
00462         #undef xnLogVerbose
00463         #define xnLogVerbose
00464         #undef xnLogInfo
00465         #define xnLogInfo
00466         #undef xnLogWarning
00467         #define xnLogWarning
00468         #undef xnLogError
00469         #define xnLogError
00470 #endif
00471 
00472 #endif //_XN_LOG_H_
00473 


nao_openni
Author(s): Bener SUAY
autogenerated on Mon Jan 6 2014 11:27:51