![]() |
OpenNI 1.5.7
|
00001 /***************************************************************************** 00002 * * 00003 * OpenNI 1.x Alpha * 00004 * Copyright (C) 2012 PrimeSense Ltd. * 00005 * * 00006 * This file is part of OpenNI. * 00007 * * 00008 * Licensed under the Apache License, Version 2.0 (the "License"); * 00009 * you may not use this file except in compliance with the License. * 00010 * You may obtain a copy of the License at * 00011 * * 00012 * http://www.apache.org/licenses/LICENSE-2.0 * 00013 * * 00014 * Unless required by applicable law or agreed to in writing, software * 00015 * distributed under the License is distributed on an "AS IS" BASIS, * 00016 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * 00017 * See the License for the specific language governing permissions and * 00018 * limitations under the License. * 00019 * * 00020 *****************************************************************************/ 00021 #ifndef __XN_DUMP_WRITERS_H__ 00022 #define __XN_DUMP_WRITERS_H__ 00023 00024 //--------------------------------------------------------------------------- 00025 // Includes 00026 //--------------------------------------------------------------------------- 00027 #include "XnDump.h" 00028 00029 //--------------------------------------------------------------------------- 00030 // Types 00031 //--------------------------------------------------------------------------- 00032 typedef struct XnDumpWriterFileHandle 00033 { 00034 void* pInternal; 00035 } XnDumpWriterFileHandle; 00036 00037 typedef struct XnDumpWriter 00038 { 00039 void* pCookie; 00040 XnDumpWriterFileHandle (XN_CALLBACK_TYPE* OpenFile)(void* pCookie, const XnChar* strDumpName, XnBool bSessionDump, const XnChar* strFileName); 00041 void (XN_CALLBACK_TYPE* Write)(void* pCookie, XnDumpWriterFileHandle hFile, const void* pBuffer, XnUInt32 nBufferSize); 00042 void (XN_CALLBACK_TYPE* CloseFile)(void* pCookie, XnDumpWriterFileHandle hFile); 00043 } XnDumpWriter; 00044 00045 //--------------------------------------------------------------------------- 00046 // Functions 00047 //--------------------------------------------------------------------------- 00048 XN_C_API XnStatus XN_C_DECL xnDumpRegisterWriter(XnDumpWriter* pWriter); 00049 00050 XN_C_API void XN_C_DECL xnDumpUnregisterWriter(XnDumpWriter* pWriter); 00051 00052 XN_C_API XnStatus XN_C_DECL xnDumpSetFilesOutput(XnBool bOn); 00053 00054 //--------------------------------------------------------------------------- 00055 // Helpers 00056 //--------------------------------------------------------------------------- 00057 #ifdef __cplusplus 00058 00059 class XnDumpWriterBase 00060 { 00061 public: 00062 XnDumpWriterBase() : m_bRegistered(FALSE) 00063 { 00064 m_cObject.pCookie = this; 00065 m_cObject.OpenFile = OpenFileCallback; 00066 m_cObject.Write = WriteCallback; 00067 m_cObject.CloseFile = CloseFileCallback; 00068 } 00069 00070 virtual ~XnDumpWriterBase() 00071 { 00072 Unregister(); 00073 } 00074 00075 XnStatus Register() 00076 { 00077 XnStatus nRetVal = XN_STATUS_OK; 00078 00079 if (!m_bRegistered) 00080 { 00081 OnRegister(); 00082 00083 nRetVal = xnDumpRegisterWriter(&m_cObject); 00084 if (nRetVal != XN_STATUS_OK) 00085 { 00086 OnUnregister(); 00087 return (nRetVal); 00088 } 00089 00090 m_bRegistered = TRUE; 00091 } 00092 00093 return (XN_STATUS_OK); 00094 } 00095 00096 void Unregister() 00097 { 00098 if (m_bRegistered) 00099 { 00100 xnDumpUnregisterWriter(&m_cObject); 00101 m_bRegistered = FALSE; 00102 00103 OnUnregister(); 00104 } 00105 } 00106 00107 inline XnBool IsRegistered() { return m_bRegistered; } 00108 00109 virtual XnDumpWriterFileHandle OpenFile(const XnChar* strDumpName, XnBool bSessionDump, const XnChar* strFileName) = 0; 00110 virtual void Write(XnDumpWriterFileHandle hFile, const void* pBuffer, XnUInt32 nBufferSize) = 0; 00111 virtual void CloseFile(XnDumpWriterFileHandle hFile) = 0; 00112 00113 operator const XnDumpWriter*() const 00114 { 00115 return &m_cObject; 00116 } 00117 00118 protected: 00119 virtual void OnRegister() {} 00120 virtual void OnUnregister() {} 00121 00122 private: 00123 static XnDumpWriterFileHandle XN_CALLBACK_TYPE OpenFileCallback(void* pCookie, const XnChar* strDumpName, XnBool bSessionDump, const XnChar* strFileName) 00124 { 00125 XnDumpWriterBase* pThis = (XnDumpWriterBase*)pCookie; 00126 return pThis->OpenFile(strDumpName, bSessionDump, strFileName); 00127 } 00128 00129 static void XN_CALLBACK_TYPE WriteCallback(void* pCookie, XnDumpWriterFileHandle hFile, const void* pBuffer, XnUInt32 nBufferSize) 00130 { 00131 XnDumpWriterBase* pThis = (XnDumpWriterBase*)pCookie; 00132 return pThis->Write(hFile, pBuffer, nBufferSize); 00133 } 00134 00135 static void XN_CALLBACK_TYPE CloseFileCallback(void* pCookie, XnDumpWriterFileHandle hFile) 00136 { 00137 XnDumpWriterBase* pThis = (XnDumpWriterBase*)pCookie; 00138 return pThis->CloseFile(hFile); 00139 } 00140 00141 XnDumpWriter m_cObject; 00142 XnBool m_bRegistered; 00143 }; 00144 00145 #endif 00146 00147 #endif // __XN_DUMP_WRITERS_H__