OpenNI 1.5.7
XnLogWriterBase.h
Go to the documentation of this file.
1/*****************************************************************************
2* *
3* OpenNI 1.x Alpha *
4* Copyright (C) 2012 PrimeSense Ltd. *
5* *
6* This file is part of OpenNI. *
7* *
8* Licensed under the Apache License, Version 2.0 (the "License"); *
9* you may not use this file except in compliance with the License. *
10* You may obtain a copy of the License at *
11* *
12* http://www.apache.org/licenses/LICENSE-2.0 *
13* *
14* Unless required by applicable law or agreed to in writing, software *
15* distributed under the License is distributed on an "AS IS" BASIS, *
16* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
17* See the License for the specific language governing permissions and *
18* limitations under the License. *
19* *
20*****************************************************************************/
21#ifndef __XN_LOG_WRITER_BASE_H__
22#define __XN_LOG_WRITER_BASE_H__
23
24//---------------------------------------------------------------------------
25// Includes
26//---------------------------------------------------------------------------
27#include <XnLogTypes.h>
28#include <XnLog.h>
29
30//---------------------------------------------------------------------------
31// Types
32//---------------------------------------------------------------------------
34{
35public:
36 XnLogWriterBase() : m_bRegistered(FALSE)
37 {
38 m_cObject.pCookie = this;
39 m_cObject.WriteEntry = WriteEntryCallback;
40 m_cObject.WriteUnformatted = WriteUnformattedCallback;
41 m_cObject.OnConfigurationChanged = OnConfigurationChangedCallback;
42 m_cObject.OnClosing = OnClosingCallback;
43 }
44
46 {
47 Unregister();
48 }
49
51 {
52 XnStatus nRetVal = XN_STATUS_OK;
53
54 if (!m_bRegistered)
55 {
56 OnRegister();
57
58 nRetVal = xnLogRegisterLogWriter(&m_cObject);
59 if (nRetVal != XN_STATUS_OK)
60 {
62 return (nRetVal);
63 }
64
65 m_bRegistered = TRUE;
66 }
67
68 return (XN_STATUS_OK);
69 }
70
72 {
73 if (m_bRegistered)
74 {
75 xnLogUnregisterLogWriter(&m_cObject);
76 m_bRegistered = FALSE;
77
79 }
80 }
81
82 inline XnBool IsRegistered() { return m_bRegistered; }
83
84 virtual void WriteEntry(const XnLogEntry* pEntry) = 0;
85 virtual void WriteUnformatted(const XnChar* strMessage) = 0;
86 virtual void OnConfigurationChanged() {};
87 virtual void OnClosing()
88 {
89 Unregister();
90 };
91
92 operator const XnLogWriter*() const
93 {
94 return &m_cObject;
95 }
96
97protected:
98 virtual void OnRegister() {}
99 virtual void OnUnregister() {}
100
101private:
102 static void XN_CALLBACK_TYPE WriteEntryCallback(const XnLogEntry* pEntry, void* pCookie)
103 {
104 XnLogWriterBase* pThis = (XnLogWriterBase*)pCookie;
105 pThis->WriteEntry(pEntry);
106 }
107 static void XN_CALLBACK_TYPE WriteUnformattedCallback(const XnChar* strMessage, void* pCookie)
108 {
109 XnLogWriterBase* pThis = (XnLogWriterBase*)pCookie;
110 pThis->WriteUnformatted(strMessage);
111 }
112 static void XN_CALLBACK_TYPE OnConfigurationChangedCallback(void* pCookie)
113 {
114 XnLogWriterBase* pThis = (XnLogWriterBase*)pCookie;
115 pThis->OnConfigurationChanged();
116 }
117 static void XN_CALLBACK_TYPE OnClosingCallback(void* pCookie)
118 {
119 XnLogWriterBase* pThis = (XnLogWriterBase*)pCookie;
120 pThis->OnClosing();
121 }
122
123 XnLogWriter m_cObject;
124 XnBool m_bRegistered;
125};
126
127#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:85
#define FALSE
Definition XnPlatform.h:89
XnUInt32 XnStatus
Definition XnStatus.h:33
#define XN_STATUS_OK
Definition XnStatus.h:36
Definition XnLogWriterBase.h:34
virtual void OnConfigurationChanged()
Definition XnLogWriterBase.h:86
XnLogWriterBase()
Definition XnLogWriterBase.h:36
virtual void WriteUnformatted(const XnChar *strMessage)=0
virtual ~XnLogWriterBase()
Definition XnLogWriterBase.h:45
virtual void OnClosing()
Definition XnLogWriterBase.h:87
virtual void OnUnregister()
Definition XnLogWriterBase.h:99
void Unregister()
Definition XnLogWriterBase.h:71
virtual void WriteEntry(const XnLogEntry *pEntry)=0
XnBool IsRegistered()
Definition XnLogWriterBase.h:82
XnStatus Register()
Definition XnLogWriterBase.h:50
virtual void OnRegister()
Definition XnLogWriterBase.h:98
Definition XnLogTypes.h:60
Definition XnLogTypes.h:71
void(* WriteUnformatted)(const XnChar *strMessage, void *pCookie)
Definition XnLogTypes.h:74
void(* OnClosing)(void *pCookie)
Definition XnLogTypes.h:76
void(* OnConfigurationChanged)(void *pCookie)
Definition XnLogTypes.h:75
void * pCookie
Definition XnLogTypes.h:72
void(* WriteEntry)(const XnLogEntry *pEntry, void *pCookie)
Definition XnLogTypes.h:73