OpenNI 1.5.4
XnLogWriterBase.h
Go to the documentation of this file.
1/****************************************************************************
2* *
3* OpenNI 1.x 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_WRITER_BASE_H__
23#define __XN_LOG_WRITER_BASE_H__
24
25//---------------------------------------------------------------------------
26// Includes
27//---------------------------------------------------------------------------
28#include <XnLogTypes.h>
29#include <XnLog.h>
30
31//---------------------------------------------------------------------------
32// Types
33//---------------------------------------------------------------------------
35{
36public:
37 XnLogWriterBase() : m_bRegistered(FALSE)
38 {
39 m_cObject.pCookie = this;
40 m_cObject.WriteEntry = WriteEntryCallback;
41 m_cObject.WriteUnformatted = WriteUnformattedCallback;
42 m_cObject.OnConfigurationChanged = OnConfigurationChangedCallback;
43 m_cObject.OnClosing = OnClosingCallback;
44 }
45
47 {
48 Unregister();
49 }
50
52 {
53 XnStatus nRetVal = XN_STATUS_OK;
54
55 if (!m_bRegistered)
56 {
57 OnRegister();
58
59 nRetVal = xnLogRegisterLogWriter(&m_cObject);
60 if (nRetVal != XN_STATUS_OK)
61 {
63 return (nRetVal);
64 }
65
66 m_bRegistered = TRUE;
67 }
68
69 return (XN_STATUS_OK);
70 }
71
73 {
74 if (m_bRegistered)
75 {
76 xnLogUnregisterLogWriter(&m_cObject);
77 m_bRegistered = FALSE;
78
80 }
81 }
82
83 inline XnBool IsRegistered() { return m_bRegistered; }
84
85 virtual void WriteEntry(const XnLogEntry* pEntry) = 0;
86 virtual void WriteUnformatted(const XnChar* strMessage) = 0;
87 virtual void OnConfigurationChanged() {};
88 virtual void OnClosing()
89 {
90 Unregister();
91 };
92
93 operator const XnLogWriter*() const
94 {
95 return &m_cObject;
96 }
97
98protected:
99 virtual void OnRegister() {}
100 virtual void OnUnregister() {}
101
102private:
103 static void XN_CALLBACK_TYPE WriteEntryCallback(const XnLogEntry* pEntry, void* pCookie)
104 {
105 XnLogWriterBase* pThis = (XnLogWriterBase*)pCookie;
106 pThis->WriteEntry(pEntry);
107 }
108 static void XN_CALLBACK_TYPE WriteUnformattedCallback(const XnChar* strMessage, void* pCookie)
109 {
110 XnLogWriterBase* pThis = (XnLogWriterBase*)pCookie;
111 pThis->WriteUnformatted(strMessage);
112 }
113 static void XN_CALLBACK_TYPE OnConfigurationChangedCallback(void* pCookie)
114 {
115 XnLogWriterBase* pThis = (XnLogWriterBase*)pCookie;
116 pThis->OnConfigurationChanged();
117 }
118 static void XN_CALLBACK_TYPE OnClosingCallback(void* pCookie)
119 {
120 XnLogWriterBase* pThis = (XnLogWriterBase*)pCookie;
121 pThis->OnClosing();
122 }
123
124 XnLogWriter m_cObject;
125 XnBool m_bRegistered;
126};
127
128#endif // __XN_LOG_WRITER_BASE_H__
XN_C_API void XN_C_DECL xnLogUnregisterLogWriter(XnLogWriter *pWriter)
XN_C_API XnStatus XN_C_DECL xnLogRegisterLogWriter(XnLogWriter *pWriter)
#define TRUE
Definition: XnPlatform.h:93
#define FALSE
Definition: XnPlatform.h:97
XnUInt32 XnStatus
Definition: XnStatus.h:34
#define XN_STATUS_OK
Definition: XnStatus.h:37
Definition: XnLogWriterBase.h:35
virtual void OnConfigurationChanged()
Definition: XnLogWriterBase.h:87
XnLogWriterBase()
Definition: XnLogWriterBase.h:37
virtual void WriteUnformatted(const XnChar *strMessage)=0
virtual ~XnLogWriterBase()
Definition: XnLogWriterBase.h:46
virtual void OnClosing()
Definition: XnLogWriterBase.h:88
virtual void OnUnregister()
Definition: XnLogWriterBase.h:100
void Unregister()
Definition: XnLogWriterBase.h:72
virtual void WriteEntry(const XnLogEntry *pEntry)=0
XnBool IsRegistered()
Definition: XnLogWriterBase.h:83
XnStatus Register()
Definition: XnLogWriterBase.h:51
virtual void OnRegister()
Definition: XnLogWriterBase.h:99
Definition: XnLogTypes.h:61
Definition: XnLogTypes.h:72
void(* WriteUnformatted)(const XnChar *strMessage, void *pCookie)
Definition: XnLogTypes.h:75
void(* OnClosing)(void *pCookie)
Definition: XnLogTypes.h:77
void(* OnConfigurationChanged)(void *pCookie)
Definition: XnLogTypes.h:76
void * pCookie
Definition: XnLogTypes.h:73
void(* WriteEntry)(const XnLogEntry *pEntry, void *pCookie)
Definition: XnLogTypes.h:74