OpenNI 1.3.2
XnLog.h
Go to the documentation of this file.
1 /****************************************************************************
2 * *
3 * OpenNI 1.1 Alpha *
4 * Copyright (C) 2011 PrimeSense Ltd. *
5 * *
6 * This file is part of OpenNI. *
7 * *
8 * OpenNI is free software: you can redistribute it and/or modify *
9 * it under the terms of the GNU Lesser General Public License as published *
10 * by the Free Software Foundation, either version 3 of the License, or *
11 * (at your option) any later version. *
12 * *
13 * OpenNI is distributed in the hope that it will be useful, *
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16 * GNU Lesser General Public License for more details. *
17 * *
18 * You should have received a copy of the GNU Lesser General Public License *
19 * along with OpenNI. If not, see <http://www.gnu.org/licenses/>. *
20 * *
21 ****************************************************************************/
22 #ifndef _XN_LOG_H_
23 #define _XN_LOG_H_
24 
25 //---------------------------------------------------------------------------
26 // Includes
27 //---------------------------------------------------------------------------
28 #include "XnOS.h"
29 #include "XnLogTypes.h"
30 #include "XnDump.h"
31 
32 //---------------------------------------------------------------------------
33 // Exported Function Declaration
34 //---------------------------------------------------------------------------
35 
40 
47 XN_C_API XnStatus XN_C_DECL xnLogInitFromINIFile(const XnChar* csINIFile, const XnChar* csSectionName);
48 
54 XN_C_API XnStatus XN_C_DECL xnLogInitFromXmlFile(const XnChar* strFileName);
55 
61 XN_C_API XnStatus XN_C_DECL xnLogRegisterLogWriter(const XnLogWriter* pWriter);
62 
68 XN_C_API void XN_C_DECL xnLogUnregisterLogWriter(const XnLogWriter* pWriter);
69 
74 
78 XN_C_API XnStatus XN_C_DECL xnLogClose();
79 
86 XN_C_API XnStatus XN_C_DECL xnLogSetMaskState(const XnChar* csMask, XnBool bEnabled);
87 
94 
100 XN_C_API XnStatus XN_C_DECL xnLogSetConsoleOutput(XnBool bConsoleOutput);
101 
107 XN_C_API XnStatus XN_C_DECL xnLogSetFileOutput(XnBool bFileOutput);
108 
114 XN_C_API XnStatus XN_C_DECL xnLogSetLineInfo(XnBool bLineInfo);
115 
121 XN_C_API XnStatus XN_C_DECL xnLogSetOutputFolder(const XnChar* strOutputFolder);
122 
129 XN_C_API XnBool XN_C_DECL xnLogIsEnabled(const XnChar* csLogMask, XnLogSeverity nSeverity);
130 
140 XN_C_API void XN_C_DECL xnLogWrite(const XnChar* csLogMask, XnLogSeverity nSeverity, const XnChar* csFile, XnUInt32 nLine, const XnChar* csFormat, ...);
141 
151 XN_C_API void XN_C_DECL xnLogWriteNoEntry(const XnChar* csLogMask, XnLogSeverity nSeverity, const XnChar* csFormat, ...);
152 
164 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, ...);
165 
172 XN_C_API XnStatus XN_C_DECL xnLogCreateFile(const XnChar* csFileName, XN_FILE_HANDLE* phFile);
173 
174 #define XN_MASK_RETVAL_CHECKS "RetValChecks"
175 
177 #define XN_IS_STATUS_OK_LOG_ERROR(what, nRetVal) \
178  if (nRetVal != XN_STATUS_OK) \
179  { \
180  xnLogError(XN_MASK_RETVAL_CHECKS, "Failed to " what ": %s", xnGetStatusString(nRetVal)); \
181  XN_ASSERT(FALSE); \
182  return (nRetVal); \
183  }
184 
185 #if XN_PLATFORM_VAARGS_TYPE == XN_PLATFORM_USE_WIN32_VAARGS_STYLE
186  #define xnLogVerbose(csLogMask, csFormat, ...) xnLogWrite(csLogMask, XN_LOG_VERBOSE, __FILE__, __LINE__, csFormat, __VA_ARGS__)
187  #define xnLogInfo(csLogMask, csFormat, ...) xnLogWrite(csLogMask, XN_LOG_INFO, __FILE__, __LINE__, csFormat, __VA_ARGS__)
188  #define xnLogWarning(csLogMask, csFormat, ...) xnLogWrite(csLogMask, XN_LOG_WARNING, __FILE__, __LINE__, csFormat, __VA_ARGS__)
189  #define xnLogError(csLogMask, csFormat, ...) xnLogWrite(csLogMask, XN_LOG_ERROR, __FILE__, __LINE__, csFormat, __VA_ARGS__)
190 
191  /* Writes to the log and returns nRetVal */
192  #define XN_LOG_RETURN(nRetVal, nSeverity, csLogMask, csFormat, ...) \
193  { \
194  xnLogWrite(csLogMask, nSeverity, __FILE__, __LINE__, csFormat, __VA_ARGS__);\
195  return (nRetVal); \
196  }
197 
198  /* Logs a warning and returns nRetVal */
199  #define XN_LOG_WARNING_RETURN(nRetVal, csLogMask, csFormat, ...) \
200  XN_LOG_RETURN(nRetVal, XN_LOG_WARNING, csLogMask, csFormat, __VA_ARGS__)
201 
202  /* Logs an error and returns nRetVal */
203  #define XN_LOG_ERROR_RETURN(nRetVal, csLogMask, csFormat, ...) \
204  XN_LOG_RETURN(nRetVal, XN_LOG_ERROR, csLogMask, csFormat, __VA_ARGS__)
205 
206 #elif XN_PLATFORM_VAARGS_TYPE == XN_PLATFORM_USE_GCC_VAARGS_STYLE
207  #define xnLogVerbose(csLogMask, csFormat, ...) xnLogWrite(csLogMask, XN_LOG_VERBOSE, __FILE__, __LINE__, csFormat, ##__VA_ARGS__)
208  #define xnLogInfo(csLogMask, csFormat, ...) xnLogWrite(csLogMask, XN_LOG_INFO, __FILE__, __LINE__, csFormat, ##__VA_ARGS__)
209  #define xnLogWarning(csLogMask, csFormat, ...) xnLogWrite(csLogMask, XN_LOG_WARNING, __FILE__, __LINE__, csFormat, ##__VA_ARGS__)
210  #define xnLogError(csLogMask, csFormat, ...) xnLogWrite(csLogMask, XN_LOG_ERROR, __FILE__, __LINE__, csFormat, ##__VA_ARGS__)
211 
212  /* Writes to the log and returns nRetVal */
213  #define XN_LOG_RETURN(nRetVal, nSeverity, csLogMask, csFormat, ...) \
214  { \
215  xnLogWrite(csLogMask, nSeverity, __FILE__, __LINE__, csFormat, ##__VA_ARGS__); \
216  return (nRetVal); \
217  }
218 
219  /* Logs a warning and returns nRetVal */
220  #define XN_LOG_WARNING_RETURN(nRetVal, csLogMask, csFormat, ...) \
221  XN_LOG_RETURN(nRetVal, XN_LOG_WARNING, csLogMask, csFormat, ##__VA_ARGS__)
222 
223  /* Logs a warning and returns nRetVal */
224  #define XN_LOG_ERROR_RETURN(nRetVal, csLogMask, csFormat, ...) \
225  XN_LOG_RETURN(nRetVal, XN_LOG_ERROR, csLogMask, csFormat, ##__VA_ARGS__)
226 
227 #elif XN_PLATFORM_VAARGS_TYPE == XN_PLATFORM_USE_ARC_VAARGS_STYLE
228  #define xnLogVerbose(csLogMask, csFormat...) xnLogWrite(csLogMask, XN_LOG_VERBOSE, __FILE__, __LINE__, csFormat)
229  #define xnLogInfo(csLogMask, csFormat...) xnLogWrite(csLogMask, XN_LOG_INFO, __FILE__, __LINE__, csFormat)
230  #define xnLogWarning(csLogMask, csFormat...) xnLogWrite(csLogMask, XN_LOG_WARNING, __FILE__, __LINE__, csFormat)
231  #define xnLogError(csLogMask, csFormat...) xnLogWrite(csLogMask, XN_LOG_ERROR, __FILE__, __LINE__, csFormat)
232 
233  /* Writes to the log and returns nRetVal */
234  #define XN_LOG_RETURN(nRetVal, nSeverity, csLogMask, csFormat...) \
235  { \
236  xnLogWrite(csLogMask, nSeverity, __FILE__, __LINE__, csFormat); \
237  return (nRetVal); \
238  }
239 
240  /* Logs a warning and returns nRetVal */
241  #define XN_LOG_WARNING_RETURN(nRetVal, csLogMask, csFormat...) \
242  XN_LOG_RETURN(nRetVal, XN_LOG_WARNING, csLogMask, csFormat)
243 
244  /* Logs a warning and returns nRetVal */
245  #define XN_LOG_ERROR_RETURN(nRetVal, csLogMask, csFormat...) \
246  XN_LOG_RETURN(nRetVal, XN_LOG_ERROR, csLogMask, csFormat)
247 
248  /* If nRetVal is not ok, writes to the log and returns nRetVal */
249  #define XN_IS_STATUS_OK_LOG(nRetVal, nSeverity, csLogMask, csFormat...) \
250  if (nRetVal != XN_STATUS_OK) \
251  { \
252  XN_LOG_RETURN(nRetVal, nSeverity, csLogMask, csFormat) \
253  }
254 
255  /* If nRetVal is not ok, logs a warning and returns nRetVal */
256  #define XN_IS_STATUS_OK_WARNING(nRetVal, csLogMask, csFormat...) \
257  XN_IS_STATUS_OK_LOG(nRetVal, XN_LOG_WARNING, csLogMask, csFormat)
258 
259  /* If nRetVal is not ok, logs an error and returns nRetVal */
260  #define XN_IS_STATUS_OK_ERROR(nRetVal, csLogMask, csFormat...) \
261  XN_IS_STATUS_OK_LOG(nRetVal, XN_LOG_ERROR, csLogMask, csFormat)
262 
263 #elif XN_PLATFORM_VAARGS_TYPE == XN_PLATFORM_USE_NO_VAARGS
264  #define xnLogVerbose(csLogMask, csFormat, args) xnLogWrite(csLogMask, XN_LOG_VERBOSE, __FILE__, __LINE__, csFormat, args)
265  #define xnLogInfo(csLogMask, csFormat, args) xnLogWrite(csLogMask, XN_LOG_INFO, __FILE__, __LINE__, csFormat, args)
266  #define xnLogWarning(csLogMask, csFormat, args) xnLogWrite(csLogMask, XN_LOG_WARNING, __FILE__, __LINE__, csFormat, args)
267  #define xnLogError(csLogMask, csFormat, args) xnLogWrite(csLogMask, XN_LOG_ERROR, __FILE__, __LINE__, csFormat, args)
268 
269  /* Writes to the log and returns nRetVal */
270  #define XN_LOG_RETURN(nRetVal, nSeverity csLogMask, csFormat, args) \
271  { \
272  xnLogWrite(csLogMask, nSeverity, __FILE__, __LINE__, csFormat, args); \
273  return (nRetVal); \
274  }
275 
276  /* Logs a warning and returns nRetVal */
277  #define XN_LOG_WARNING_RETURN(nRetVal, csLogMask, csFormat, args) \
278  XN_LOG_RETURN(nRetVal, XN_LOG_WARNING, csLogMask, csFormat, args)
279 
280  /* Logs an error and returns nRetVal */
281  #define XN_LOG_ERROR_RETURN(nRetVal, csLogMask, csFormat, args) \
282  XN_LOG_RETURN(nRetVal, XN_LOG_ERROR, csLogMask, csFormat, args)
283 
284 #else
285  #error Xiron Log - Unknown VAARGS type!
286 #endif
287 
288 #endif //_XN_LOG_H_
289