OpenNI 1.5.4
XnDumpWriters.h
Go to the documentation of this file.
1#ifndef __XN_DUMP_WRITERS_H__
2#define __XN_DUMP_WRITERS_H__
3
4//---------------------------------------------------------------------------
5// Includes
6//---------------------------------------------------------------------------
7#include "XnDump.h"
8
9//---------------------------------------------------------------------------
10// Types
11//---------------------------------------------------------------------------
16
17typedef struct XnDumpWriter
18{
19 void* pCookie;
20 XnDumpWriterFileHandle (XN_CALLBACK_TYPE* OpenFile)(void* pCookie, const XnChar* strDumpName, XnBool bSessionDump, const XnChar* strFileName);
21 void (XN_CALLBACK_TYPE* Write)(void* pCookie, XnDumpWriterFileHandle hFile, const void* pBuffer, XnUInt32 nBufferSize);
22 void (XN_CALLBACK_TYPE* CloseFile)(void* pCookie, XnDumpWriterFileHandle hFile);
24
25//---------------------------------------------------------------------------
26// Functions
27//---------------------------------------------------------------------------
29
31
33
34//---------------------------------------------------------------------------
35// Helpers
36//---------------------------------------------------------------------------
37#ifdef __cplusplus
38
39class XnDumpWriterBase
40{
41public:
42 XnDumpWriterBase() : m_bRegistered(FALSE)
43 {
44 m_cObject.pCookie = this;
45 m_cObject.OpenFile = OpenFileCallback;
46 m_cObject.Write = WriteCallback;
47 m_cObject.CloseFile = CloseFileCallback;
48 }
49
50 virtual ~XnDumpWriterBase()
51 {
52 Unregister();
53 }
54
55 XnStatus Register()
56 {
57 XnStatus nRetVal = XN_STATUS_OK;
58
59 if (!m_bRegistered)
60 {
61 OnRegister();
62
63 nRetVal = xnDumpRegisterWriter(&m_cObject);
64 if (nRetVal != XN_STATUS_OK)
65 {
66 OnUnregister();
67 return (nRetVal);
68 }
69
70 m_bRegistered = TRUE;
71 }
72
73 return (XN_STATUS_OK);
74 }
75
76 void Unregister()
77 {
78 if (m_bRegistered)
79 {
80 xnDumpUnregisterWriter(&m_cObject);
81 m_bRegistered = FALSE;
82
83 OnUnregister();
84 }
85 }
86
87 inline XnBool IsRegistered() { return m_bRegistered; }
88
89 virtual XnDumpWriterFileHandle OpenFile(const XnChar* strDumpName, XnBool bSessionDump, const XnChar* strFileName) = 0;
90 virtual void Write(XnDumpWriterFileHandle hFile, const void* pBuffer, XnUInt32 nBufferSize) = 0;
91 virtual void CloseFile(XnDumpWriterFileHandle hFile) = 0;
92
93 operator const XnDumpWriter*() const
94 {
95 return &m_cObject;
96 }
97
98protected:
99 virtual void OnRegister() {}
100 virtual void OnUnregister() {}
101
102private:
103 static XnDumpWriterFileHandle XN_CALLBACK_TYPE OpenFileCallback(void* pCookie, const XnChar* strDumpName, XnBool bSessionDump, const XnChar* strFileName)
104 {
105 XnDumpWriterBase* pThis = (XnDumpWriterBase*)pCookie;
106 return pThis->OpenFile(strDumpName, bSessionDump, strFileName);
107 }
108
109 static void XN_CALLBACK_TYPE WriteCallback(void* pCookie, XnDumpWriterFileHandle hFile, const void* pBuffer, XnUInt32 nBufferSize)
110 {
111 XnDumpWriterBase* pThis = (XnDumpWriterBase*)pCookie;
112 return pThis->Write(hFile, pBuffer, nBufferSize);
113 }
114
115 static void XN_CALLBACK_TYPE CloseFileCallback(void* pCookie, XnDumpWriterFileHandle hFile)
116 {
117 XnDumpWriterBase* pThis = (XnDumpWriterBase*)pCookie;
118 return pThis->CloseFile(hFile);
119 }
120
121 XnDumpWriter m_cObject;
122 XnBool m_bRegistered;
123};
124
125#endif
126
127#endif // __XN_DUMP_WRITERS_H__
XN_C_API void XN_C_DECL xnDumpUnregisterWriter(XnDumpWriter *pWriter)
struct XnDumpWriter XnDumpWriter
XN_C_API XnStatus XN_C_DECL xnDumpSetFilesOutput(XnBool bOn)
struct XnDumpWriterFileHandle XnDumpWriterFileHandle
XN_C_API XnStatus XN_C_DECL xnDumpRegisterWriter(XnDumpWriter *pWriter)
#define TRUE
Definition XnPlatform.h:96
#define FALSE
Definition XnPlatform.h:100
#define XN_C_API
Definition XnPlatform.h:132
XnUInt32 XnStatus
Definition XnStatus.h:34
#define XN_STATUS_OK
Definition XnStatus.h:37
Definition XnDumpWriters.h:13
void * pInternal
Definition XnDumpWriters.h:14
Definition XnDumpWriters.h:18
void(* CloseFile)(void *pCookie, XnDumpWriterFileHandle hFile)
Definition XnDumpWriters.h:22
XnDumpWriterFileHandle(* OpenFile)(void *pCookie, const XnChar *strDumpName, XnBool bSessionDump, const XnChar *strFileName)
Definition XnDumpWriters.h:20
void * pCookie
Definition XnDumpWriters.h:19
void(* Write)(void *pCookie, XnDumpWriterFileHandle hFile, const void *pBuffer, XnUInt32 nBufferSize)
Definition XnDumpWriters.h:21