OpenNI 1.5.4
|
XnLog.h
Go to the documentation of this file.
00001 /**************************************************************************** 00002 * * 00003 * OpenNI 1.x Alpha * 00004 * Copyright (C) 2011 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 #ifndef _XN_LOG_H_ 00023 #define _XN_LOG_H_ 00024 00025 //--------------------------------------------------------------------------- 00026 // Includes 00027 //--------------------------------------------------------------------------- 00028 #include "XnOS.h" 00029 #include "XnLogTypes.h" 00030 #include "XnDump.h" 00031 00032 //--------------------------------------------------------------------------- 00033 // Exported Function Declaration 00034 //--------------------------------------------------------------------------- 00035 00045 XN_C_API XnStatus XN_C_DECL xnLogInitSystem(); 00046 00053 XN_C_API XnStatus XN_C_DECL xnLogInitFromINIFile(const XnChar* csINIFile, const XnChar* csSectionName); 00054 00060 XN_C_API XnStatus XN_C_DECL xnLogInitFromXmlFile(const XnChar* strFileName); 00061 00065 XN_C_API XnStatus XN_C_DECL xnLogClose(); 00066 00067 // @} 00068 00081 XN_C_API XnStatus XN_C_DECL xnLogSetMaskMinSeverity(const XnChar* strMask, XnLogSeverity minSeverity); 00082 00090 XN_C_API XnLogSeverity XN_C_DECL xnLogGetMaskMinSeverity(const XnChar* strMask); 00091 00092 // @} 00093 00106 XN_C_API XnStatus XN_C_DECL xnLogRegisterLogWriter(XnLogWriter* pWriter); 00107 00113 XN_C_API void XN_C_DECL xnLogUnregisterLogWriter(XnLogWriter* pWriter); 00114 00120 XN_C_API XnStatus XN_C_DECL xnLogSetConsoleOutput(XnBool bConsoleOutput); 00121 00127 XN_C_API XnStatus XN_C_DECL xnLogSetFileOutput(XnBool bFileOutput); 00128 00129 // @} 00130 00140 XN_C_API XnStatus XN_C_DECL xnLogStartNewFile(); 00141 00147 XN_C_API XnStatus XN_C_DECL xnLogSetLineInfo(XnBool bLineInfo); 00148 00154 XN_C_API XnStatus XN_C_DECL xnLogSetOutputFolder(const XnChar* strOutputFolder); 00155 00162 XN_C_API XnStatus XN_C_DECL xnLogGetFileName(XnChar* strFileName, XnUInt32 nBufferSize); 00163 00164 // @} 00165 00177 XN_C_API XnLogger* XN_C_DECL xnLoggerOpen(const XnChar* strMask); 00178 00191 XN_C_API void XN_C_DECL xnLoggerWrite(XnLogger* pLogger, XnLogSeverity severity, const XnChar* strFile, XnUInt32 nLine, const XnChar* strFormat, ...); 00192 00200 XN_C_API void XN_C_DECL xnLoggerWriteNoEntry(XnLogger* pLogger, XnLogSeverity severity, const XnChar* strFormat, ...); 00201 00213 XN_C_API void XN_C_DECL xnLoggerWriteBinaryData(XnLogger* pLogger, XnLogSeverity severity, const XnChar* strFile, XnUInt32 nLine, XnUChar* pBinData, XnUInt32 nDataSize, const XnChar* strFormat, ...); 00214 00221 XN_C_API XnBool XN_C_DECL xnLoggerIsEnabled(XnLogger* pLogger, XnLogSeverity severity); 00222 00228 XN_C_API void XN_C_DECL _xnLoggerClose(XnLogger* pLogger); 00229 00235 #define xnLoggerClose(pLogger) \ 00236 { \ 00237 _xnLoggerClose(pLogger); \ 00238 pLogger = NULL; \ 00239 } 00240 00241 #if XN_PLATFORM_VAARGS_TYPE == XN_PLATFORM_USE_WIN32_VAARGS_STYLE 00242 00245 #define xnLoggerWriteHelper(pLogger, severity, csFormat, ...) \ 00246 if (pLogger != NULL && severity >= pLogger->nMinSeverity) \ 00247 { \ 00248 xnLoggerWrite(pLogger, severity, __FILE__, __LINE__, csFormat, __VA_ARGS__); \ 00249 } 00250 00254 #define xnLoggerVerbose(pLogger, csFormat, ...) xnLoggerWriteHelper(pLogger, XN_LOG_VERBOSE, csFormat, __VA_ARGS__) 00255 00258 #define xnLoggerInfo(pLogger, csFormat, ...) xnLoggerWriteHelper(pLogger, XN_LOG_INFO, csFormat, __VA_ARGS__) 00259 00262 #define xnLoggerWarning(pLogger, csFormat, ...) xnLoggerWriteHelper(pLogger, XN_LOG_WARNING, csFormat, __VA_ARGS__) 00263 00266 #define xnLoggerError(pLogger, csFormat, ...) xnLoggerWriteHelper(pLogger, XN_LOG_ERROR, csFormat, __VA_ARGS__) 00267 00276 #define XN_RETURN_WITH_LOG(pLogger, nRetVal, severity, csFormat, ...) \ 00277 { \ 00278 xnLoggerWriteHelper(pLogger, severity, csFormat, __VA_ARGS__); \ 00279 return (nRetVal); \ 00280 } 00281 00289 #define XN_RETURN_WITH_WARNING_LOG(pLogger, nRetVal, csFormat, ...) \ 00290 XN_RETURN_WITH_LOG(pLogger, nRetVal, XN_LOG_WARNING, csFormat, __VA_ARGS__) 00291 00299 #define XN_RETURN_WITH_ERROR_LOG(pLogger, nRetVal, csFormat, ...) \ 00300 XN_RETURN_WITH_LOG(pLogger, nRetVal, XN_LOG_ERROR, csFormat, __VA_ARGS__) 00301 00302 #elif XN_PLATFORM_VAARGS_TYPE == XN_PLATFORM_USE_GCC_VAARGS_STYLE 00303 #define xnLoggerWriteHelper(pLogger, severity, csFormat, ...) \ 00304 if (pLogger != NULL && severity >= pLogger->nMinSeverity) \ 00305 { \ 00306 xnLoggerWrite(pLogger, severity, __FILE__, __LINE__, csFormat, ##__VA_ARGS__); \ 00307 } 00308 00309 #define xnLoggerVerbose(pLogger, csFormat, ...) xnLoggerWriteHelper(pLogger, XN_LOG_VERBOSE, csFormat,## __VA_ARGS__) 00310 #define xnLoggerInfo(pLogger, csFormat, ...) xnLoggerWriteHelper(pLogger, XN_LOG_INFO, csFormat, ##__VA_ARGS__) 00311 #define xnLoggerWarning(pLogger, csFormat, ...) xnLoggerWriteHelper(pLogger, XN_LOG_WARNING, csFormat, ##__VA_ARGS__) 00312 #define xnLoggerError(pLogger, csFormat, ...) xnLoggerWriteHelper(pLogger, XN_LOG_ERROR, csFormat, ##__VA_ARGS__) 00313 00314 /* Writes to the log and returns nRetVal */ 00315 #define XN_RETURN_WITH_LOG(pLogger, nRetVal, severity, csFormat, ...) \ 00316 { \ 00317 xnLoggerWriteHelper(pLogger, severity, csFormat, ##__VA_ARGS__); \ 00318 return (nRetVal); \ 00319 } 00320 00321 /* Logs a warning and returns nRetVal */ 00322 #define XN_RETURN_WITH_WARNING_LOG(pLogger, nRetVal, csFormat, ...) \ 00323 XN_RETURN_WITH_LOG(pLogger, nRetVal, XN_LOG_WARNING, csFormat, ##__VA_ARGS__) 00324 00325 /* Logs an error and returns nRetVal */ 00326 #define XN_RETURN_WITH_ERROR_LOG(pLogger, nRetVal, csFormat, ...) \ 00327 XN_RETURN_WITH_LOG(pLogger, nRetVal, XN_LOG_ERROR, csFormat, ##__VA_ARGS__) 00328 00329 #elif XN_PLATFORM_VAARGS_TYPE == XN_PLATFORM_USE_ARC_VAARGS_STYLE 00330 #define xnLoggerWriteHelper(pLogger, severity, csFormat...) \ 00331 if (pLogger != NULL && severity >= pLogger->nMinSeverity) \ 00332 { \ 00333 xnLoggerWrite(pLogger, severity, __FILE__, __LINE__, csFormat); \ 00334 } 00335 00336 #define xnLoggerVerbose(pLogger, csFormat...) xnLoggerWriteHelper(pLogger, XN_LOG_VERBOSE, csFormat) 00337 #define xnLoggerInfo(pLogger, csFormat...) xnLoggerWriteHelper(pLogger, XN_LOG_INFO, csFormat) 00338 #define xnLoggerWarning(pLogger, csFormat...) xnLoggerWriteHelper(pLogger, XN_LOG_WARNING, csFormat) 00339 #define xnLoggerError(pLogger, csFormat...) xnLoggerWriteHelper(pLogger, XN_LOG_ERROR, csFormat) 00340 00341 /* Writes to the log and returns nRetVal */ 00342 #define XN_RETURN_WITH_LOG(pLogger, nRetVal, severity, csFormat...) \ 00343 { \ 00344 xnLoggerWriteHelper(pLogger, severity, csFormat); \ 00345 return (nRetVal); \ 00346 } 00347 00348 /* Logs a warning and returns nRetVal */ 00349 #define XN_RETURN_WITH_WARNING_LOG(pLogger, nRetVal, csFormat...) \ 00350 XN_RETURN_WITH_LOG(pLogger, nRetVal, XN_LOG_WARNING, csFormat) 00351 00352 /* Logs an error and returns nRetVal */ 00353 #define XN_RETURN_WITH_ERROR_LOG(pLogger, nRetVal, csFormat...) \ 00354 XN_RETURN_WITH_LOG(pLogger, nRetVal, XN_LOG_ERROR, csFormat) 00355 00356 #elif XN_PLATFORM_VAARGS_TYPE == XN_PLATFORM_USE_NO_VAARGS 00357 #define xnLoggerWriteHelper(pLogger, severity, csFormat, arg) \ 00358 if (pLogger != NULL && severity >= pLogger->nMinSeverity) \ 00359 { \ 00360 xnLoggerWrite(pLogger, severity, __FILE__, __LINE__, csFormat, arg); \ 00361 } 00362 00363 #define xnLoggerVerbose(pLogger, csFormat, arg) xnLoggerWriteHelper(pLogger, XN_LOG_VERBOSE, csFormat, arg) 00364 #define xnLoggerInfo(pLogger, csFormat, arg) xnLoggerWriteHelper(pLogger, XN_LOG_INFO, csFormat, arg) 00365 #define xnLoggerWarning(pLogger, csFormat, arg) xnLoggerWriteHelper(pLogger, XN_LOG_WARNING, csFormat, arg) 00366 #define xnLoggerError(pLogger, csFormat, arg) xnLoggerWriteHelper(pLogger, XN_LOG_ERROR, csFormat, arg) 00367 00368 /* Writes to the log and returns nRetVal */ 00369 #define XN_RETURN_WITH_LOG(pLogger, nRetVal, severity, csFormat) \ 00370 { \ 00371 xnLoggerWriteHelper(pLogger, severity, csFormat); \ 00372 return (nRetVal); \ 00373 } 00374 00375 /* Logs a warning and returns nRetVal */ 00376 #define XN_RETURN_WITH_WARNING_LOG(pLogger, nRetVal, csFormat) \ 00377 XN_RETURN_WITH_LOG(pLogger, nRetVal, XN_LOG_WARNING, csFormat) 00378 00379 /* Logs an error and returns nRetVal */ 00380 #define XN_RETURN_WITH_ERROR_LOG(pLogger, nRetVal, csFormat) \ 00381 XN_RETURN_WITH_LOG(pLogger, nRetVal, XN_LOG_ERROR, csFormat) 00382 00383 #else 00384 #error Xiron Log - Unknown VAARGS type! 00385 #endif 00386 00387 // @} 00388 00406 XN_C_API XnStatus XN_C_DECL xnLogCreateNewFile(const XnChar* strName, XnBool bSessionBased, XnChar* csFullPath, XnUInt32 nPathBufferSize, XN_FILE_HANDLE* phFile); 00407 00408 // @} 00409 00410 #define XN_MASK_RETVAL_CHECKS "RetValChecks" 00411 00412 #if XN_PLATFORM == XN_PLATFORM_ARC 00413 extern "C" XnLogger* XN_LOGGER_RETVAL_CHECKS; 00414 #else 00415 XN_C_API XnLogger* XN_LOGGER_RETVAL_CHECKS; 00416 #endif 00417 00419 #define XN_IS_STATUS_OK_LOG_ERROR(what, nRetVal) \ 00420 if (nRetVal != XN_STATUS_OK) \ 00421 { \ 00422 xnLoggerError(XN_LOGGER_RETVAL_CHECKS, "Failed to " what ": %s", xnGetStatusString(nRetVal)); \ 00423 XN_ASSERT(FALSE); \ 00424 return (nRetVal); \ 00425 } 00426 00427 00428 #ifndef __XN_NO_BC__ 00429 00430 XN_C_API XnStatus XN_API_DEPRECATED("Please use xnLogSetMaskMinSeverity() instead") XN_C_DECL xnLogSetMaskState(const XnChar* csMask, XnBool bEnabled); 00431 XN_C_API XnStatus XN_API_DEPRECATED("Please use xnLogSetMaskMinSeverity() instead") XN_C_DECL xnLogSetSeverityFilter(XnLogSeverity nMinSeverity); 00432 XN_C_API XnBool XN_C_DECL xnLogIsEnabled(const XnChar* csLogMask, XnLogSeverity nSeverity); 00433 XN_C_API void XN_C_DECL xnLogWrite(const XnChar* csLogMask, XnLogSeverity nSeverity, const XnChar* csFile, XnUInt32 nLine, const XnChar* csFormat, ...); 00434 XN_C_API void XN_C_DECL xnLogWriteNoEntry(const XnChar* csLogMask, XnLogSeverity nSeverity, const XnChar* csFormat, ...); 00435 XN_C_API void XN_C_DECL xnLogWriteBinaryData(const XnChar* csLogMask, XnLogSeverity nSeverity, const XnChar* csFile, XnUInt32 nLine, XnUChar* pBinData, XnUInt32 nDataSize, const XnChar* csFormat, ...); 00436 XN_C_API XnStatus XN_API_DEPRECATED("Use xnLogCreateNewFile() instead") XN_C_DECL xnLogCreateFile(const XnChar* strFileName, XN_FILE_HANDLE* phFile); 00437 XN_C_API XnStatus XN_API_DEPRECATED("Use xnLogCreateNewFile() instead") XN_C_DECL xnLogCreateFileEx(const XnChar* strFileName, XnBool bSessionBased, XN_FILE_HANDLE* phFile); 00438 00439 #if XN_PLATFORM_VAARGS_TYPE == XN_PLATFORM_USE_WIN32_VAARGS_STYLE 00440 #define xnLogVerbose(csLogMask, csFormat, ...) xnLogWrite(csLogMask, XN_LOG_VERBOSE, __FILE__, __LINE__, csFormat, __VA_ARGS__) 00441 #define xnLogInfo(csLogMask, csFormat, ...) xnLogWrite(csLogMask, XN_LOG_INFO, __FILE__, __LINE__, csFormat, __VA_ARGS__) 00442 #define xnLogWarning(csLogMask, csFormat, ...) xnLogWrite(csLogMask, XN_LOG_WARNING, __FILE__, __LINE__, csFormat, __VA_ARGS__) 00443 #define xnLogError(csLogMask, csFormat, ...) xnLogWrite(csLogMask, XN_LOG_ERROR, __FILE__, __LINE__, csFormat, __VA_ARGS__) 00444 00445 /* Writes to the log and returns nRetVal */ 00446 #define XN_LOG_RETURN(nRetVal, nSeverity, csLogMask, csFormat, ...) \ 00447 { \ 00448 xnLogWrite(csLogMask, nSeverity, __FILE__, __LINE__, csFormat, __VA_ARGS__); \ 00449 return (nRetVal); \ 00450 } 00451 00452 /* Logs a warning and returns nRetVal */ 00453 #define XN_LOG_WARNING_RETURN(nRetVal, csLogMask, csFormat, ...) \ 00454 XN_LOG_RETURN(nRetVal, XN_LOG_WARNING, csLogMask, csFormat, __VA_ARGS__) 00455 00456 /* Logs a warning and returns nRetVal */ 00457 #define XN_LOG_ERROR_RETURN(nRetVal, csLogMask, csFormat, ...) \ 00458 XN_LOG_RETURN(nRetVal, XN_LOG_ERROR, csLogMask, csFormat, __VA_ARGS__) 00459 00460 #elif XN_PLATFORM_VAARGS_TYPE == XN_PLATFORM_USE_GCC_VAARGS_STYLE 00461 #define xnLogVerbose(csLogMask, csFormat, ...) xnLogWrite(csLogMask, XN_LOG_VERBOSE, __FILE__, __LINE__, csFormat, ##__VA_ARGS__) 00462 #define xnLogInfo(csLogMask, csFormat, ...) xnLogWrite(csLogMask, XN_LOG_INFO, __FILE__, __LINE__, csFormat, ##__VA_ARGS__) 00463 #define xnLogWarning(csLogMask, csFormat, ...) xnLogWrite(csLogMask, XN_LOG_WARNING, __FILE__, __LINE__, csFormat, ##__VA_ARGS__) 00464 #define xnLogError(csLogMask, csFormat, ...) xnLogWrite(csLogMask, XN_LOG_ERROR, __FILE__, __LINE__, csFormat, ##__VA_ARGS__) 00465 00466 /* Writes to the log and returns nRetVal */ 00467 #define XN_LOG_RETURN(nRetVal, nSeverity, csLogMask, csFormat, ...) \ 00468 { \ 00469 xnLogWrite(csLogMask, nSeverity, __FILE__, __LINE__, csFormat, ##__VA_ARGS__); \ 00470 return (nRetVal); \ 00471 } 00472 00473 /* Logs a warning and returns nRetVal */ 00474 #define XN_LOG_WARNING_RETURN(nRetVal, csLogMask, csFormat, ...) \ 00475 XN_LOG_RETURN(nRetVal, XN_LOG_WARNING, csLogMask, csFormat, ##__VA_ARGS__) 00476 00477 /* Logs a warning and returns nRetVal */ 00478 #define XN_LOG_ERROR_RETURN(nRetVal, csLogMask, csFormat, ...) \ 00479 XN_LOG_RETURN(nRetVal, XN_LOG_ERROR, csLogMask, csFormat, ##__VA_ARGS__) 00480 00481 #elif XN_PLATFORM_VAARGS_TYPE == XN_PLATFORM_USE_ARC_VAARGS_STYLE 00482 #define xnLogVerbose(csLogMask, csFormat...) xnLogWrite(csLogMask, XN_LOG_VERBOSE, __FILE__, __LINE__, csFormat) 00483 #define xnLogInfo(csLogMask, csFormat...) xnLogWrite(csLogMask, XN_LOG_INFO, __FILE__, __LINE__, csFormat) 00484 #define xnLogWarning(csLogMask, csFormat...) xnLogWrite(csLogMask, XN_LOG_WARNING, __FILE__, __LINE__, csFormat) 00485 #define xnLogError(csLogMask, csFormat...) xnLogWrite(csLogMask, XN_LOG_ERROR, __FILE__, __LINE__, csFormat) 00486 00487 /* Writes to the log and returns nRetVal */ 00488 #define XN_LOG_RETURN(nRetVal, nSeverity, csLogMask, csFormat...) \ 00489 { \ 00490 xnLogWrite(csLogMask, nSeverity, __FILE__, __LINE__, csFormat); \ 00491 return (nRetVal); \ 00492 } 00493 00494 /* Logs a warning and returns nRetVal */ 00495 #define XN_LOG_WARNING_RETURN(nRetVal, csLogMask, csFormat...) \ 00496 XN_LOG_RETURN(nRetVal, XN_LOG_WARNING, csLogMask, csFormat) 00497 00498 /* Logs a warning and returns nRetVal */ 00499 #define XN_LOG_ERROR_RETURN(nRetVal, csLogMask, csFormat...) \ 00500 XN_LOG_RETURN(nRetVal, XN_LOG_ERROR, csLogMask, csFormat) 00501 00502 /* If nRetVal is not ok, writes to the log and returns nRetVal */ 00503 #define XN_IS_STATUS_OK_LOG(nRetVal, nSeverity, csLogMask, csFormat...) \ 00504 if (nRetVal != XN_STATUS_OK) \ 00505 { \ 00506 XN_LOG_RETURN(nRetVal, nSeverity, csLogMask, csFormat) \ 00507 } 00508 00509 /* If nRetVal is not ok, logs a warning and returns nRetVal */ 00510 #define XN_IS_STATUS_OK_WARNING(nRetVal, csLogMask, csFormat...) \ 00511 XN_IS_STATUS_OK_LOG(nRetVal, XN_LOG_WARNING, csLogMask, csFormat) 00512 00513 /* If nRetVal is not ok, logs an error and returns nRetVal */ 00514 #define XN_IS_STATUS_OK_ERROR(nRetVal, csLogMask, csFormat...) \ 00515 XN_IS_STATUS_OK_LOG(nRetVal, XN_LOG_ERROR, csLogMask, csFormat) 00516 00517 #elif XN_PLATFORM_VAARGS_TYPE == XN_PLATFORM_USE_NO_VAARGS 00518 #define xnLogVerbose(csLogMask, csFormat, args) xnLogWrite(csLogMask, XN_LOG_VERBOSE, __FILE__, __LINE__, csFormat, args) 00519 #define xnLogInfo(csLogMask, csFormat, args) xnLogWrite(csLogMask, XN_LOG_INFO, __FILE__, __LINE__, csFormat, args) 00520 #define xnLogWarning(csLogMask, csFormat, args) xnLogWrite(csLogMask, XN_LOG_WARNING, __FILE__, __LINE__, csFormat, args) 00521 #define xnLogError(csLogMask, csFormat, args) xnLogWrite(csLogMask, XN_LOG_ERROR, __FILE__, __LINE__, csFormat, args) 00522 00523 /* Writes to the log and returns nRetVal */ 00524 #define XN_LOG_RETURN(nRetVal, nSeverity csLogMask, csFormat, args) \ 00525 { \ 00526 xnLogWrite(csLogMask, nSeverity, __FILE__, __LINE__, csFormat, args); \ 00527 return (nRetVal); \ 00528 } 00529 00530 /* Logs a warning and returns nRetVal */ 00531 #define XN_LOG_WARNING_RETURN(nRetVal, csLogMask, csFormat, args) \ 00532 XN_LOG_RETURN(nRetVal, XN_LOG_WARNING, csLogMask, csFormat, args) 00533 00534 /* Logs an error and returns nRetVal */ 00535 #define XN_LOG_ERROR_RETURN(nRetVal, csLogMask, csFormat, args) \ 00536 XN_LOG_RETURN(nRetVal, XN_LOG_ERROR, csLogMask, csFormat, args) 00537 00538 #else 00539 #error Xiron Log - Unknown VAARGS type! 00540 #endif 00541 00542 #endif // ifndef __XN_NO_BC__ 00543 00544 #endif //_XN_LOG_H_ 00545
Generated on Wed May 16 2012 10:16:05 for OpenNI 1.5.4 by 1.7.5.1