OpenNI 1.5.7
XnCppWrapper.h
Go to the documentation of this file.
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_CPP_WRAPPER_H__
00022 #define __XN_CPP_WRAPPER_H__
00023 
00024 //---------------------------------------------------------------------------
00025 // Includes
00026 //---------------------------------------------------------------------------
00027 #include <XnOpenNI.h>
00028 #include <XnCodecIDs.h>
00029 
00030 //---------------------------------------------------------------------------
00031 // Types
00032 //---------------------------------------------------------------------------
00033 namespace xn
00034 {
00035     //---------------------------------------------------------------------------
00036     // Forward Declarations
00037     //---------------------------------------------------------------------------
00038     class ProductionNode;
00039     class EnumerationErrors;
00040     class NodeInfo;
00041     class NodeInfoList;
00042     class Context;
00043     class Query;
00044     class Generator;
00045 
00071     //---------------------------------------------------------------------------
00072     // Types
00073     //---------------------------------------------------------------------------
00074 
00100     typedef void (XN_CALLBACK_TYPE* StateChangedHandler)(ProductionNode& node, void* pCookie);
00101 
00102     //---------------------------------------------------------------------------
00103     // Internal stuff
00104     //---------------------------------------------------------------------------
00105     typedef XnStatus (*_XnRegisterStateChangeFuncPtr)(XnNodeHandle hNode, XnStateChangedHandler handler, void* pCookie, XnCallbackHandle* phCallback);
00106     typedef void (*_XnUnregisterStateChangeFuncPtr)(XnNodeHandle hNode, XnCallbackHandle hCallback);
00107 
00108     static XnStatus _RegisterToStateChange(_XnRegisterStateChangeFuncPtr xnFunc, XnNodeHandle hNode, StateChangedHandler handler, void* pCookie, XnCallbackHandle& hCallback);
00109     static void _UnregisterFromStateChange(_XnUnregisterStateChangeFuncPtr xnFunc, XnNodeHandle hNode, XnCallbackHandle hCallback);
00110 
00111     //---------------------------------------------------------------------------
00112     // Some Utilities
00113     //---------------------------------------------------------------------------
00118     class Version
00119     {
00120     public:
00121         Version(const XnVersion& version) : m_version(version) {}
00122         Version(XnUInt8 nMajor, XnUInt8 nMinor, XnUInt16 nMaintenance, XnUInt32 nBuild)
00123         {
00124             m_version.nMajor = nMajor;
00125             m_version.nMinor = nMinor;
00126             m_version.nMaintenance = nMaintenance;
00127             m_version.nBuild = nBuild;
00128         }
00129 
00130         bool operator==(const Version& other) const
00131         {
00132             return (xnVersionCompare(&m_version, &other.m_version) == 0);
00133         }
00134         bool operator!=(const Version& other) const
00135         {
00136             return (xnVersionCompare(&m_version, &other.m_version) != 0);
00137         }
00138         bool operator<(const Version& other) const
00139         {
00140             return (xnVersionCompare(&m_version, &other.m_version) < 0);
00141         }
00142         bool operator<=(const Version& other) const
00143         {
00144             return (xnVersionCompare(&m_version, &other.m_version) <= 0);
00145         }
00146         bool operator>(const Version& other) const
00147         {
00148             return (xnVersionCompare(&m_version, &other.m_version) > 0);
00149         }
00150         bool operator>=(const Version& other) const
00151         {
00152             return (xnVersionCompare(&m_version, &other.m_version) >= 0);
00153         }
00154 
00155         static Version Current()
00156         {
00157             XnVersion version;
00158             xnGetVersion(&version);
00159             return Version(version);
00160         }
00161 
00162         XnUInt8 Major() const { return m_version.nMajor; }
00163         XnUInt8 Minor() const { return m_version.nMinor; }
00164         XnUInt16 Maintenance() const { return m_version.nMaintenance; }
00165         XnUInt32 Build() const { return m_version.nBuild; }
00166 
00167         XnUInt8& Major() { return m_version.nMajor; }
00168         XnUInt8& Minor() { return m_version.nMinor; }
00169         XnUInt16& Maintenance() { return m_version.nMaintenance; }
00170         XnUInt32& Build() { return m_version.nBuild; }
00171 
00172         const XnVersion* GetUnderlying() const { return &m_version; }
00173         XnVersion* GetUnderlying() { return &m_version; }
00174 
00175     private:
00176         XnVersion m_version;
00177     };
00178 
00179     //---------------------------------------------------------------------------
00180     // Meta Data
00181     //---------------------------------------------------------------------------
00182 
00197     class OutputMetaData
00198     {
00199     public:
00205         inline OutputMetaData(const XnUInt8** ppData) : m_ppData(ppData), m_nAllocatedSize(0), m_pAllocatedData(NULL)
00206         {
00207             xnOSMemSet(&m_output, 0, sizeof(XnOutputMetaData));
00208         }
00209 
00213         virtual ~OutputMetaData() { Free(); }
00214 
00218         inline XnUInt64 Timestamp() const { return m_output.nTimestamp; }
00219 
00223         inline XnUInt64& Timestamp() { return m_output.nTimestamp; }
00224 
00229         inline XnUInt32 FrameID() const { return m_output.nFrameID; }
00230 
00235         inline XnUInt32& FrameID() { return m_output.nFrameID; }
00236 
00245         inline XnUInt32 DataSize() const { return m_output.nDataSize; }
00246 
00255         inline XnUInt32& DataSize() { return m_output.nDataSize; }
00256 
00261         inline XnBool IsDataNew() const { return m_output.bIsNew; }
00262 
00267         inline XnBool& IsDataNew() { return m_output.bIsNew; }
00268 
00272         inline const XnOutputMetaData* GetUnderlying() const { return &m_output; }
00276         inline XnOutputMetaData* GetUnderlying() { return &m_output; }
00277 
00282         inline const XnUInt8* Data() const { return *m_ppData; }
00287         inline const XnUInt8*& Data() { return *m_ppData; }
00288 
00292         inline XnUInt8* WritableData()
00293         {
00294             MakeDataWritable();
00295             return m_pAllocatedData;
00296         }
00297 
00306         XnStatus AllocateData(XnUInt32 nBytes)
00307         {
00308             if (nBytes > m_nAllocatedSize)
00309             {
00310                 // reallocate
00311                 XnUInt8* pData = (XnUInt8*)xnOSMallocAligned(nBytes, XN_DEFAULT_MEM_ALIGN);
00312                 XN_VALIDATE_ALLOC_PTR(pData);
00313 
00314                 // allocation succeeded, replace
00315                 Free();
00316                 m_pAllocatedData = pData;
00317                 m_nAllocatedSize = nBytes;
00318             }
00319 
00320             DataSize() = nBytes;
00321             *m_ppData = m_pAllocatedData;
00322 
00323             return XN_STATUS_OK;
00324         }
00325 
00329         void Free()
00330         {
00331             if (m_nAllocatedSize != 0)
00332             {
00333                 xnOSFreeAligned(m_pAllocatedData);
00334                 m_pAllocatedData = NULL;
00335                 m_nAllocatedSize = 0;
00336             }
00337         }
00338 
00343         XnStatus MakeDataWritable()
00344         {
00345             XnStatus nRetVal = XN_STATUS_OK;
00346 
00347             // check data isn't already writable
00348             if (Data() != m_pAllocatedData || DataSize() > m_nAllocatedSize)
00349             {
00350                 const XnUInt8* pOrigData = *m_ppData;
00351 
00352                 nRetVal = AllocateData(DataSize());
00353                 XN_IS_STATUS_OK(nRetVal);
00354 
00355                 if (pOrigData != NULL)
00356                 {
00357                     xnOSMemCopy(m_pAllocatedData, pOrigData, DataSize());
00358                 }
00359                 else
00360                 {
00361                     xnOSMemSet(m_pAllocatedData, 0, DataSize());
00362                 }
00363             }
00364 
00365             return (XN_STATUS_OK);
00366         }
00367 
00368     protected:
00369         XnUInt8* m_pAllocatedData;
00370 
00371     private:
00372         XnOutputMetaData m_output;
00373 
00374         const XnUInt8** m_ppData;
00375         XnUInt32 m_nAllocatedSize;
00376     };
00377 
00390     class MapMetaData : public OutputMetaData
00391     {
00392     public:
00399         inline MapMetaData(XnPixelFormat format, const XnUInt8** ppData) : OutputMetaData(ppData)
00400         {
00401             xnOSMemSet(&m_map, 0, sizeof(XnMapMetaData));
00402             m_map.pOutput = OutputMetaData::GetUnderlying();
00403             m_map.PixelFormat = format;
00404         }
00405 
00411         inline XnUInt32 XRes() const { return m_map.Res.X; }
00417         inline XnUInt32& XRes() { return m_map.Res.X; }
00418 
00424         inline XnUInt32 YRes() const { return m_map.Res.Y; }
00430         inline XnUInt32& YRes() { return m_map.Res.Y; }
00431 
00440         inline XnUInt32 XOffset() const { return m_map.Offset.X; }
00449         inline XnUInt32& XOffset() { return m_map.Offset.X; }
00450 
00459         inline XnUInt32 YOffset() const { return m_map.Offset.Y; }
00468         inline XnUInt32& YOffset() { return m_map.Offset.Y; }
00469 
00474         inline XnUInt32 FullXRes() const { return m_map.FullRes.X; }
00475 
00476 
00481         inline XnUInt32& FullXRes() { return m_map.FullRes.X; }
00482 
00486         inline XnUInt32 FullYRes() const { return m_map.FullRes.Y; }
00490         inline XnUInt32& FullYRes() { return m_map.FullRes.Y; }
00491 
00495         inline XnUInt32 FPS() const { return m_map.nFPS; }
00499         inline XnUInt32& FPS() { return m_map.nFPS; }
00500 
00504         inline XnPixelFormat PixelFormat() const { return m_map.PixelFormat; }
00505 
00509         inline const XnMapMetaData* GetUnderlying() const { return &m_map; }
00513         inline XnMapMetaData* GetUnderlying() { return &m_map; }
00514 
00518         inline XnUInt32 BytesPerPixel() const
00519         {
00520             switch (PixelFormat())
00521             {
00522                 case XN_PIXEL_FORMAT_RGB24:
00523                     return sizeof(XnRGB24Pixel);
00524                 case XN_PIXEL_FORMAT_YUV422:
00525                     return sizeof(XnYUV422DoublePixel)/2;
00526                 case XN_PIXEL_FORMAT_GRAYSCALE_8_BIT:
00527                     return sizeof(XnGrayscale8Pixel);
00528                 case XN_PIXEL_FORMAT_GRAYSCALE_16_BIT:
00529                     return sizeof(XnGrayscale16Pixel);
00530                 case XN_PIXEL_FORMAT_MJPEG:
00531                     return 2;
00532                 default:
00533                     XN_ASSERT(FALSE);
00534                     return 0;
00535             }
00536         }
00537 
00544         XnStatus AllocateData(XnUInt32 nXRes, XnUInt32 nYRes)
00545         {
00546             XnStatus nRetVal = XN_STATUS_OK;
00547 
00548             XnUInt32 nSize = nXRes * nYRes * BytesPerPixel();
00549             nRetVal = OutputMetaData::AllocateData(nSize);
00550             XN_IS_STATUS_OK(nRetVal);
00551 
00552             FullXRes() = XRes() = nXRes;
00553             FullYRes() = YRes() = nYRes;
00554             XOffset() = YOffset() = 0;
00555 
00556             return (XN_STATUS_OK);
00557         }
00558 
00567         XnStatus ReAdjust(XnUInt32 nXRes, XnUInt32 nYRes, const XnUInt8* pExternalBuffer)
00568         {
00569             XnStatus nRetVal = XN_STATUS_OK;
00570 
00571             if (pExternalBuffer == NULL)
00572             {
00573                 nRetVal = AllocateData(nXRes, nYRes);
00574                 XN_IS_STATUS_OK(nRetVal);
00575             }
00576             else
00577             {
00578                 FullXRes() = XRes() = nXRes;
00579                 FullYRes() = YRes() = nYRes;
00580                 XOffset() = YOffset() = 0;
00581                 Data() = pExternalBuffer;
00582                 DataSize() = nXRes * nYRes * BytesPerPixel();
00583             }
00584 
00585             return (XN_STATUS_OK);
00586         }
00587 
00588     protected:
00589         XnPixelFormat& PixelFormatImpl() { return m_map.PixelFormat; }
00590 
00591     private:
00592         // block copy ctor and assignment operator
00593         MapMetaData& operator=(const MapMetaData&);
00594         inline MapMetaData(const MapMetaData& other);
00595 
00596         // Members
00597         XnMapMetaData m_map;
00598     };
00599 
00607     template<class _pixelType>
00608     class Map
00609     {
00610     public:
00611         inline Map(_pixelType*& pData, XnUInt32& nXRes, XnUInt32 &nYRes) :
00612             m_pData(pData), m_nXRes(nXRes), m_nYRes(nYRes)
00613         {}
00614 
00622         inline XnUInt32 XRes() const { return m_nXRes; }
00630         inline XnUInt32 YRes() const { return m_nYRes; }
00631 
00643         inline const _pixelType& operator[](XnUInt32 nIndex) const
00644         {
00645             XN_ASSERT(nIndex < (m_nXRes * m_nYRes));
00646             return m_pData[nIndex];
00647         }
00659         inline _pixelType& operator[](XnUInt32 nIndex)
00660         {
00661             XN_ASSERT(nIndex < (m_nXRes *m_nYRes));
00662             return m_pData[nIndex];
00663         }
00664 
00673         inline const _pixelType& operator()(XnUInt32 x, XnUInt32 y) const
00674         {
00675             XN_ASSERT(x < m_nXRes && y < m_nYRes);
00676             return m_pData[y*m_nXRes + x];
00677         }
00686         inline _pixelType& operator()(XnUInt32 x, XnUInt32 y)
00687         {
00688             XN_ASSERT(x < m_nXRes && y < m_nYRes);
00689             return m_pData[y*m_nXRes + x];
00690         }
00691 
00692     private:
00693         /* block copy ctor and assignment operator */
00694         Map(const Map& other);
00695         Map& operator=(const Map&);
00696 
00697         _pixelType*& m_pData;
00698         XnUInt32& m_nXRes;
00699         XnUInt32& m_nYRes;
00700     };
00701 
00706     typedef Map<XnDepthPixel> DepthMap;
00708     typedef Map<XnUInt8> ImageMap;
00710     typedef Map<XnRGB24Pixel> RGB24Map;
00712     typedef Map<XnGrayscale16Pixel> Grayscale16Map;
00714     typedef Map<XnGrayscale8Pixel> Grayscale8Map;
00716     typedef Map<XnIRPixel> IRMap;
00718     typedef Map<XnLabel> LabelMap;
00753     class DepthMetaData : public MapMetaData
00754     {
00755     public:
00759         inline DepthMetaData() :
00760             MapMetaData(XN_PIXEL_FORMAT_GRAYSCALE_16_BIT, (const XnUInt8**)&m_depth.pData),
00761             m_depthMap(const_cast<XnDepthPixel*&>(m_depth.pData), MapMetaData::GetUnderlying()->Res.X, MapMetaData::GetUnderlying()->Res.Y),
00762             m_writableDepthMap((XnDepthPixel*&)m_pAllocatedData, MapMetaData::GetUnderlying()->Res.X, MapMetaData::GetUnderlying()->Res.Y)
00763         {
00764             xnOSMemSet(&m_depth, 0, sizeof(XnDepthMetaData));
00765             m_depth.pMap = MapMetaData::GetUnderlying();
00766         }
00767 
00775         inline void InitFrom(const DepthMetaData& other)
00776         {
00777             xnCopyDepthMetaData(&m_depth, &other.m_depth);
00778         }
00779 
00790         inline XnStatus InitFrom(const DepthMetaData& other, XnUInt32 nXRes, XnUInt32 nYRes, const XnDepthPixel* pExternalBuffer)
00791         {
00792             InitFrom(other);
00793             return ReAdjust(nXRes, nYRes, pExternalBuffer);
00794         }
00795 
00802         XnStatus CopyFrom(const DepthMetaData& other)
00803         {
00804             // copy props
00805             InitFrom(other);
00806             // and make a copy of the data (this will allocate and copy data)
00807             return MakeDataWritable();
00808         }
00809 
00813         XnStatus ReAdjust(XnUInt32 nXRes, XnUInt32 nYRes, const XnDepthPixel* pExternalBuffer = NULL)
00814         {
00815             return MapMetaData::ReAdjust(nXRes, nYRes, (const XnUInt8*)pExternalBuffer);
00816         }
00817 
00823         inline XnDepthPixel ZRes() const { return m_depth.nZRes; }
00829         inline XnDepthPixel& ZRes() { return m_depth.nZRes; }
00830 
00843         inline const XnDepthPixel* Data() const { return (const XnDepthPixel*)MapMetaData::Data(); }
00856         inline const XnDepthPixel*& Data() { return (const XnDepthPixel*&)MapMetaData::Data(); }
00857 
00858 
00862         inline XnDepthPixel* WritableData() { return (XnDepthPixel*)MapMetaData::WritableData(); }
00863 
00867         inline const xn::DepthMap& DepthMap() const { return m_depthMap; }
00871         inline xn::DepthMap& WritableDepthMap()
00872         {
00873             MakeDataWritable();
00874             return m_writableDepthMap;
00875         }
00876 
00882         inline const XnDepthPixel& operator[](XnUInt32 nIndex) const
00883         {
00884             XN_ASSERT(nIndex < (XRes()*YRes()));
00885             return Data()[nIndex];
00886         }
00887 
00894         inline const XnDepthPixel& operator()(XnUInt32 x, XnUInt32 y) const
00895         {
00896             XN_ASSERT(x < XRes() && y < YRes());
00897             return Data()[y*XRes() + x];
00898         }
00899 
00903         inline const XnDepthMetaData* GetUnderlying() const { return &m_depth; }
00907         inline XnDepthMetaData* GetUnderlying() { return &m_depth; }
00908 
00909     private:
00910         // block copy ctor and assignment operator (because we can't return errors in those)
00911         DepthMetaData(const DepthMetaData& other);
00912         DepthMetaData& operator=(const DepthMetaData&);
00913 
00914         XnDepthMetaData m_depth;
00915         const xn::DepthMap m_depthMap;
00916         xn::DepthMap m_writableDepthMap;
00917     };
00918 
00945     class ImageMetaData : public MapMetaData
00946     {
00947     public:
00948         inline ImageMetaData() :
00949             MapMetaData(XN_PIXEL_FORMAT_RGB24, &m_image.pData),
00950             m_imageMap(const_cast<XnUInt8*&>(m_image.pData), MapMetaData::GetUnderlying()->Res.X, MapMetaData::GetUnderlying()->Res.Y),
00951             m_writableImageMap((XnUInt8*&)m_pAllocatedData, MapMetaData::GetUnderlying()->Res.X, MapMetaData::GetUnderlying()->Res.Y),
00952             m_rgb24Map((XnRGB24Pixel*&)m_image.pData, MapMetaData::GetUnderlying()->Res.X, MapMetaData::GetUnderlying()->Res.Y),
00953             m_writableRgb24Map((XnRGB24Pixel*&)m_pAllocatedData, MapMetaData::GetUnderlying()->Res.X, MapMetaData::GetUnderlying()->Res.Y),
00954             m_gray16Map((XnGrayscale16Pixel*&)m_image.pData, MapMetaData::GetUnderlying()->Res.X, MapMetaData::GetUnderlying()->Res.Y),
00955             m_writableGray16Map((XnGrayscale16Pixel*&)m_pAllocatedData, MapMetaData::GetUnderlying()->Res.X, MapMetaData::GetUnderlying()->Res.Y),
00956             m_gray8Map((XnGrayscale8Pixel*&)m_image.pData, MapMetaData::GetUnderlying()->Res.X, MapMetaData::GetUnderlying()->Res.Y),
00957             m_writableGray8Map((XnGrayscale8Pixel*&)m_pAllocatedData, MapMetaData::GetUnderlying()->Res.X, MapMetaData::GetUnderlying()->Res.Y)
00958         {
00959             xnOSMemSet(&m_image, 0, sizeof(XnImageMetaData));
00960             m_image.pMap = MapMetaData::GetUnderlying();
00961         }
00962 
00970         inline void InitFrom(const ImageMetaData& other)
00971         {
00972             xnCopyImageMetaData(&m_image, &other.m_image);
00973         }
00974 
00986         inline XnStatus InitFrom(const ImageMetaData& other, XnUInt32 nXRes, XnUInt32 nYRes, XnPixelFormat format, const XnUInt8* pExternalBuffer)
00987         {
00988             InitFrom(other);
00989             XnStatus nRetVal = ReAdjust(nXRes, nYRes, format, pExternalBuffer);
00990             XN_IS_STATUS_OK(nRetVal);
00991             PixelFormat() = format;
00992             return XN_STATUS_OK;
00993         }
00994 
01002         inline XnStatus AllocateData(XnUInt32 nXRes, XnUInt32 nYRes, XnPixelFormat format)
01003         {
01004             XnPixelFormat origFormat = PixelFormat();
01005             PixelFormat() = format;
01006             XnStatus nRetVal = MapMetaData::AllocateData(nXRes, nYRes);
01007             if (nRetVal != XN_STATUS_OK)
01008             {
01009                 PixelFormat() = origFormat;
01010                 return (nRetVal);
01011             }
01012 
01013             return XN_STATUS_OK;
01014         }
01015 
01021         inline XnStatus CopyFrom(const ImageMetaData& other)
01022         {
01023             // copy props
01024             xnCopyImageMetaData(&m_image, &other.m_image);
01025             // and make a copy of the data (this will allocate and copy data)
01026             return MakeDataWritable();
01027         }
01028 
01038         XnStatus ReAdjust(XnUInt32 nXRes, XnUInt32 nYRes, XnPixelFormat format, const XnUInt8* pExternalBuffer = NULL)
01039         {
01040             XnPixelFormat origFormat = PixelFormat();
01041             PixelFormat() = format;
01042             XnStatus nRetVal = MapMetaData::ReAdjust(nXRes, nYRes, pExternalBuffer);
01043             if (nRetVal != XN_STATUS_OK)
01044             {
01045                 PixelFormat() = origFormat;
01046                 return (nRetVal);
01047             }
01048 
01049             return XN_STATUS_OK;
01050         }
01051 
01063         inline XnPixelFormat PixelFormat() const { return MapMetaData::PixelFormat(); }
01073         inline XnPixelFormat& PixelFormat() { return MapMetaData::PixelFormatImpl(); }
01074 
01078         inline XnUInt8* WritableData() { return MapMetaData::WritableData(); }
01079 
01084         inline const XnRGB24Pixel* RGB24Data() const { return (const XnRGB24Pixel*)MapMetaData::Data(); }
01089         inline const XnRGB24Pixel*& RGB24Data() { return (const XnRGB24Pixel*&)MapMetaData::Data(); }
01093         inline XnRGB24Pixel* WritableRGB24Data() { return (XnRGB24Pixel*)MapMetaData::WritableData(); }
01094 
01100         inline const XnYUV422DoublePixel* YUV422Data() const { return (const XnYUV422DoublePixel*)MapMetaData::Data(); }
01106         inline const XnYUV422DoublePixel*& YUV422Data() { return (const XnYUV422DoublePixel*&)MapMetaData::Data(); }
01110         inline XnYUV422DoublePixel* WritableYUV422Data() { return (XnYUV422DoublePixel*)MapMetaData::WritableData(); }
01111 
01116         inline const XnGrayscale8Pixel* Grayscale8Data() const { return (const XnGrayscale8Pixel*)MapMetaData::Data(); }
01121         inline const XnGrayscale8Pixel*& Grayscale8Data() { return (const XnGrayscale8Pixel*&)MapMetaData::Data(); }
01125         inline XnGrayscale8Pixel* WritableGrayscale8Data() { return (XnGrayscale8Pixel*)MapMetaData::WritableData(); }
01126 
01131         inline const XnGrayscale16Pixel* Grayscale16Data() const { return (const XnGrayscale16Pixel*)MapMetaData::Data(); }
01136         inline const XnGrayscale16Pixel*& Grayscale16Data() { return (const XnGrayscale16Pixel*&)MapMetaData::Data(); }
01140         inline XnGrayscale16Pixel* WritableGrayscale16Data() { return (XnGrayscale16Pixel*)MapMetaData::WritableData(); }
01141 
01145         inline const xn::ImageMap& ImageMap() const { return m_imageMap; }
01149         inline xn::ImageMap& WritableImageMap() { MakeDataWritable(); return m_writableImageMap; }
01150 
01156         inline const xn::RGB24Map& RGB24Map() const { return m_rgb24Map; }
01160         inline xn::RGB24Map& WritableRGB24Map() { MakeDataWritable(); return m_writableRgb24Map; }
01161 
01165         inline const xn::Grayscale8Map& Grayscale8Map() const { return m_gray8Map; }
01169         inline xn::Grayscale8Map& WritableGrayscale8Map() { MakeDataWritable(); return m_writableGray8Map; }
01170 
01175         inline const xn::Grayscale16Map& Grayscale16Map() const { return m_gray16Map; }
01179         inline xn::Grayscale16Map& WritableGrayscale16Map() { MakeDataWritable(); return m_writableGray16Map; }
01180 
01184         inline const XnImageMetaData* GetUnderlying() const { return &m_image; }
01188         inline XnImageMetaData* GetUnderlying() { return &m_image; }
01189 
01190     private:
01191         // block copy ctor and assignment operator
01192         ImageMetaData(const ImageMetaData& other);
01193         ImageMetaData& operator=(const ImageMetaData&);
01194 
01195         XnImageMetaData m_image;
01196         const xn::ImageMap m_imageMap;
01197         xn::ImageMap m_writableImageMap;
01198         const xn::RGB24Map m_rgb24Map;
01199         xn::RGB24Map m_writableRgb24Map;
01200         const xn::Grayscale16Map m_gray16Map;
01201         xn::Grayscale16Map m_writableGray16Map;
01202         const xn::Grayscale8Map m_gray8Map;
01203         xn::Grayscale8Map m_writableGray8Map;
01204     };
01205 
01215     class IRMetaData : public MapMetaData
01216     {
01217     public:
01218         inline IRMetaData() :
01219             MapMetaData(XN_PIXEL_FORMAT_GRAYSCALE_16_BIT, (const XnUInt8**)&m_ir.pData),
01220             m_irMap(const_cast<XnIRPixel*&>(m_ir.pData), MapMetaData::GetUnderlying()->Res.X, MapMetaData::GetUnderlying()->Res.Y),
01221             m_writableIRMap((XnIRPixel*&)m_pAllocatedData, MapMetaData::GetUnderlying()->Res.X, MapMetaData::GetUnderlying()->Res.Y)
01222         {
01223             xnOSMemSet(&m_ir, 0, sizeof(XnIRMetaData));
01224             m_ir.pMap = MapMetaData::GetUnderlying();
01225         }
01226 
01234         inline void InitFrom(const IRMetaData& other)
01235         {
01236             xnCopyIRMetaData(&m_ir, &other.m_ir);
01237         }
01238 
01248         inline XnStatus InitFrom(const IRMetaData& other, XnUInt32 nXRes, XnUInt32 nYRes, const XnIRPixel* pExternalBuffer)
01249         {
01250             InitFrom(other);
01251             return ReAdjust(nXRes, nYRes, pExternalBuffer);
01252         }
01253 
01259         XnStatus CopyFrom(const IRMetaData& other)
01260         {
01261             // copy props
01262             xnCopyIRMetaData(&m_ir, &other.m_ir);
01263             // and make a copy of the data (this will allocate and copy data)
01264             return MakeDataWritable();
01265         }
01266 
01270         XnStatus ReAdjust(XnUInt32 nXRes, XnUInt32 nYRes, const XnIRPixel* pExternalBuffer = NULL)
01271         {
01272             return MapMetaData::ReAdjust(nXRes, nYRes, (const XnUInt8*)pExternalBuffer);
01273         }
01274 
01287         inline const XnIRPixel* Data() const { return (const XnIRPixel*)MapMetaData::Data(); }
01300         inline const XnIRPixel*& Data() { return (const XnIRPixel*&)MapMetaData::Data(); }
01304         inline XnIRPixel* WritableData() { return (XnIRPixel*)MapMetaData::WritableData(); }
01305 
01311         inline const XnIRPixel& operator[](XnUInt32 nIndex) const
01312         {
01313             XN_ASSERT(nIndex < (XRes()*YRes()));
01314             return Data()[nIndex];
01315         }
01316 
01323         inline const XnIRPixel& operator()(XnUInt32 x, XnUInt32 y) const
01324         {
01325             XN_ASSERT(x < XRes() && y < YRes());
01326             return Data()[y*XRes() + x];
01327         }
01328 
01337         inline const xn::IRMap& IRMap() const { return m_irMap; }
01346         inline xn::IRMap& WritableIRMap() { MakeDataWritable(); return m_writableIRMap; }
01347 
01351         inline const XnIRMetaData* GetUnderlying() const { return &m_ir; }
01355         inline XnIRMetaData* GetUnderlying() { return &m_ir; }
01356 
01357     private:
01358         // block copy ctor and assignment operator
01359         IRMetaData(const IRMetaData& other);
01360         IRMetaData& operator=(const IRMetaData&);
01361 
01362         XnIRMetaData m_ir;
01363         const xn::IRMap m_irMap;
01364         xn::IRMap m_writableIRMap;
01365     };
01366 
01373     class AudioMetaData : public OutputMetaData
01374     {
01375     public:
01376         XN_PRAGMA_START_DISABLED_WARNING_SECTION(XN_UNALIGNED_ADDRESS_WARNING_ID);
01377         inline AudioMetaData() : OutputMetaData(&m_audio.pData)
01378         {
01379             xnOSMemSet(&m_audio, 0, sizeof(XnAudioMetaData));
01380             m_audio.pOutput = OutputMetaData::GetUnderlying();
01381         }
01382 
01383         XN_PRAGMA_STOP_DISABLED_WARNING_SECTION;
01384 
01392         inline void InitFrom(const AudioMetaData& other)
01393         {
01394             xnCopyAudioMetaData(&m_audio, &other.m_audio);
01395         }
01396 
01400         inline XnUInt8 NumberOfChannels() const { return m_audio.Wave.nChannels; }
01404         inline XnUInt8& NumberOfChannels() { return m_audio.Wave.nChannels; }
01405 
01409         inline XnUInt32 SampleRate() const { return m_audio.Wave.nSampleRate; }
01413         inline XnUInt32& SampleRate() { return m_audio.Wave.nSampleRate; }
01414 
01418         inline XnUInt16 BitsPerSample() const { return m_audio.Wave.nBitsPerSample; }
01422         inline XnUInt16& BitsPerSample() { return m_audio.Wave.nBitsPerSample; }
01423 
01427         inline const XnAudioMetaData* GetUnderlying() const { return &m_audio; }
01431         inline XnAudioMetaData* GetUnderlying() { return &m_audio; }
01432 
01433     private:
01434         // block copy ctor and assignment operator
01435         AudioMetaData(const AudioMetaData& other);
01436         AudioMetaData& operator=(const AudioMetaData&);
01437 
01438         XnAudioMetaData m_audio;
01439     };
01440 
01449     class SceneMetaData : public MapMetaData
01450     {
01451     public:
01452         inline SceneMetaData() :
01453             MapMetaData(XN_PIXEL_FORMAT_GRAYSCALE_16_BIT, (const XnUInt8**)&m_scene.pData),
01454             m_labelMap(const_cast<XnLabel*&>(m_scene.pData), MapMetaData::GetUnderlying()->Res.X, MapMetaData::GetUnderlying()->Res.Y),
01455             m_writableLabelMap((XnLabel*&)m_pAllocatedData, MapMetaData::GetUnderlying()->Res.X, MapMetaData::GetUnderlying()->Res.Y)
01456         {
01457             xnOSMemSet(&m_scene, 0, sizeof(XnSceneMetaData));
01458             m_scene.pMap = MapMetaData::GetUnderlying();
01459         }
01460 
01468         inline void InitFrom(const SceneMetaData& other)
01469         {
01470             xnCopySceneMetaData(&m_scene, &other.m_scene);
01471         }
01472 
01482         inline XnStatus InitFrom(const SceneMetaData& other, XnUInt32 nXRes, XnUInt32 nYRes, const XnLabel* pExternalBuffer)
01483         {
01484             InitFrom(other);
01485             return ReAdjust(nXRes, nYRes, pExternalBuffer);
01486         }
01487 
01493         XnStatus CopyFrom(const SceneMetaData& other)
01494         {
01495             // copy props
01496             xnCopySceneMetaData(&m_scene, &other.m_scene);
01497             // and make a copy of the data (this will allocate and copy data)
01498             return MakeDataWritable();
01499         }
01500 
01504         XnStatus ReAdjust(XnUInt32 nXRes, XnUInt32 nYRes, const XnLabel* pExternalBuffer = NULL)
01505         {
01506             return MapMetaData::ReAdjust(nXRes, nYRes, (const XnUInt8*)pExternalBuffer);
01507         }
01508 
01522         inline const XnLabel* Data() const { return (const XnLabel*)MapMetaData::Data(); }
01536         inline const XnLabel*& Data() { return (const XnLabel*&)MapMetaData::Data(); }
01537 
01541         inline XnLabel* WritableData() { return (XnLabel*)MapMetaData::WritableData(); }
01542 
01546         inline const xn::LabelMap& LabelMap() const { return m_labelMap; }
01550         inline xn::LabelMap& WritableLabelMap() { MakeDataWritable(); return m_writableLabelMap; }
01551 
01562         inline const XnLabel& operator[](XnUInt32 nIndex) const
01563         {
01564             XN_ASSERT(nIndex < (XRes()*YRes()));
01565             return Data()[nIndex];
01566         }
01567 
01579         inline const XnLabel& operator()(XnUInt32 x, XnUInt32 y) const
01580         {
01581             XN_ASSERT(x < XRes() && y < YRes());
01582             return (*this)[y*XRes() + x];
01583         }
01584 
01588         inline const XnSceneMetaData* GetUnderlying() const { return &m_scene; }
01592         inline XnSceneMetaData* GetUnderlying() { return &m_scene; }
01593 
01594     private:
01595         // block copy ctor and assignment operator
01596         SceneMetaData(const SceneMetaData& other);
01597         SceneMetaData& operator=(const SceneMetaData&);
01598 
01599         XnSceneMetaData m_scene;
01600         const xn::LabelMap m_labelMap;
01601         xn::LabelMap m_writableLabelMap;
01602     };
01603 
01604     //---------------------------------------------------------------------------
01605     // NodeWrapper
01606     //---------------------------------------------------------------------------
01607 
01627     class NodeWrapper
01628     {
01629     public:
01630         friend class Context;
01631 
01637         inline NodeWrapper(XnNodeHandle hNode) : m_hNode(NULL), m_hShuttingDownCallback(NULL)
01638         {
01639             SetHandle(hNode);
01640         }
01641 
01642         inline NodeWrapper(const NodeWrapper& other) : m_hNode(NULL), m_hShuttingDownCallback(NULL)
01643         {
01644             SetHandle(other.GetHandle());
01645         }
01646 
01647         inline NodeWrapper& operator=(const NodeWrapper& other)
01648         {
01649             SetHandle(other.GetHandle());
01650             return *this;
01651         }
01652 
01653         inline ~NodeWrapper()
01654         {
01655             SetHandle(NULL);
01656         }
01657 
01658         inline operator XnNodeHandle() const { return GetHandle(); }
01659 
01663         inline XnNodeHandle GetHandle() const { return m_hNode; }
01664 
01670         inline XnBool operator==(const NodeWrapper& other)
01671         {
01672             return (GetHandle() == other.GetHandle());
01673         }
01674 
01680         inline XnBool operator!=(const NodeWrapper& other)
01681         {
01682             return (GetHandle() != other.GetHandle());
01683         }
01684 
01698         inline XnBool IsValid() const { return (GetHandle() != NULL); }
01699 
01700         /*
01701          * @brief Gets the instance name of a node. Unless the application made a specific
01702          * request for a specific name, the name will be of the form: "Depth1", "Image2", etc.
01703          */
01704         const XnChar* GetName() const {return xnGetNodeName(GetHandle()); }
01705 
01710         inline XnStatus AddRef() { return xnProductionNodeAddRef(GetHandle()); }
01711 
01716         inline void Release()
01717         {
01718             SetHandle(NULL);
01719         }
01720 
01721 
01725         inline void SetHandle(XnNodeHandle hNode)
01726         {
01727             if (m_hNode == hNode)
01728             {
01729                 // Optimization: do nothing
01730                 return;
01731             }
01732 
01733             // check currently held node. If we're holding a node, release it
01734             if (m_hNode != NULL)
01735             {
01736                 XnContext* pContext = xnGetRefContextFromNodeHandle(m_hNode);
01737                 xnContextUnregisterFromShutdown(pContext, m_hShuttingDownCallback);
01738                 xnContextRelease(pContext);
01739                 xnProductionNodeRelease(m_hNode);
01740             }
01741 
01742             // check new node handle, if it points to a node, add ref to it
01743             if (hNode != NULL)
01744             {
01745                 XnStatus nRetVal = xnProductionNodeAddRef(hNode);
01746                 XN_ASSERT(nRetVal == XN_STATUS_OK);
01747                 XN_REFERENCE_VARIABLE(nRetVal);
01748 
01749                 XnContext* pContext = xnGetRefContextFromNodeHandle(hNode);
01750 
01751                 nRetVal = xnContextRegisterForShutdown(pContext, ContextShuttingDownCallback, this, &m_hShuttingDownCallback);
01752                 XN_ASSERT(nRetVal == XN_STATUS_OK);
01753 
01754                 xnContextRelease(pContext);
01755             }
01756 
01757             m_hNode = hNode;
01758         }
01759 
01760         inline void TakeOwnership(XnNodeHandle hNode)
01761         {
01762             SetHandle(hNode);
01763 
01764             if (hNode != NULL)
01765             {
01766                 xnProductionNodeRelease(hNode);
01767             }
01768         }
01769 
01771         inline XnStatus XN_API_DEPRECATED("Please use AddRef() instead.") Ref() { return AddRef(); }
01772         inline void XN_API_DEPRECATED("Please use Release() instead.") Unref() { Release(); }
01775     private:
01776         XnNodeHandle m_hNode;
01777         XnCallbackHandle m_hShuttingDownCallback;
01778 
01779         static void XN_CALLBACK_TYPE ContextShuttingDownCallback(XnContext* /*pContext*/, void* pCookie)
01780         {
01781             NodeWrapper* pThis = (NodeWrapper*)pCookie;
01782             pThis->m_hNode = NULL;
01783         }
01784     };
01785 
01786     //---------------------------------------------------------------------------
01787     // Node Info
01788     //---------------------------------------------------------------------------
01789 
01801     class NodeInfo
01802     {
01803     public:
01809         NodeInfo(XnNodeInfo* pInfo) : m_pNeededNodes(NULL), m_bOwnerOfNode(FALSE)
01810         {
01811             SetUnderlyingObject(pInfo);
01812         }
01813 
01819         NodeInfo(const NodeInfo& other) : m_pNeededNodes(NULL), m_bOwnerOfNode(FALSE)
01820         {
01821             SetUnderlyingObject(other.m_pInfo);
01822         }
01823 
01827         ~NodeInfo()
01828         {
01829             SetUnderlyingObject(NULL);
01830         }
01831 
01837         inline NodeInfo& operator=(const NodeInfo& other)
01838         {
01839             SetUnderlyingObject(other.m_pInfo);
01840             return *this;
01841         }
01842 
01846         inline operator XnNodeInfo*()
01847         {
01848             return m_pInfo;
01849         }
01850 
01856         inline XnStatus SetInstanceName(const XnChar* strName)
01857         {
01858             return xnNodeInfoSetInstanceName(m_pInfo, strName);
01859         }
01860 
01874         inline const XnProductionNodeDescription& GetDescription() const
01875         {
01876             return *xnNodeInfoGetDescription(m_pInfo);
01877         }
01878 
01890         inline const XnChar* GetInstanceName() const
01891         {
01892             return xnNodeInfoGetInstanceName(m_pInfo);
01893         }
01894 
01906         inline const XnChar* GetCreationInfo() const
01907         {
01908             return xnNodeInfoGetCreationInfo(m_pInfo);
01909         }
01910 
01911         /*
01912          * @brief Gets the list of dependant nodes for this node alternative.
01913          * These are any other node alternatives that the node is dependant on.
01914          */
01915         inline NodeInfoList& GetNeededNodes() const;
01916 
01924         inline XnStatus GetInstance(ProductionNode& node) const;
01925 
01930         inline const void* GetAdditionalData() const
01931         {
01932             return xnNodeInfoGetAdditionalData(m_pInfo);
01933         }
01934 
01939         inline XnStatus GetTreeStringRepresentation(XnChar* csResultBuffer, XnUInt32 nBufferSize) const
01940         {
01941             return xnNodeInfoGetTreeStringRepresentation(m_pInfo, csResultBuffer, nBufferSize);
01942         }
01943 
01944     private:
01945         inline void SetUnderlyingObject(XnNodeInfo* pInfo);
01946 
01947         XnNodeInfo* m_pInfo;
01948         mutable NodeInfoList* m_pNeededNodes;
01949         XnBool m_bOwnerOfNode; // backwards compatibility
01950         friend class Context;
01951     };
01952 
01953     //---------------------------------------------------------------------------
01954     // Query
01955     //---------------------------------------------------------------------------
01956 
01975     class Query
01976     {
01977     public:
01978         inline Query() : m_bAllocated(TRUE)
01979         {
01980             xnNodeQueryAllocate(&m_pQuery);
01981         }
01982 
01983         inline Query(XnNodeQuery* pNodeQuery) : m_bAllocated(FALSE), m_pQuery(pNodeQuery)
01984         {
01985         }
01986 
01987         ~Query()
01988         {
01989             if (m_bAllocated)
01990             {
01991                 xnNodeQueryFree(m_pQuery);
01992             }
01993         }
01994 
01998         inline const XnNodeQuery* GetUnderlyingObject() const { return m_pQuery; }
01999         inline XnNodeQuery* GetUnderlyingObject() { return m_pQuery; }
02000 
02005         inline XnStatus SetVendor(const XnChar* strVendor)
02006         {
02007             return xnNodeQuerySetVendor(m_pQuery, strVendor);
02008         }
02009 
02018         inline XnStatus SetName(const XnChar* strName)
02019         {
02020             return xnNodeQuerySetName(m_pQuery, strName);
02021         }
02022 
02026         inline XnStatus SetMinVersion(const XnVersion& minVersion)
02027         {
02028             return xnNodeQuerySetMinVersion(m_pQuery, &minVersion);
02029         }
02030 
02034         inline XnStatus SetMinVersion(const Version& minVersion)
02035         {
02036             return xnNodeQuerySetMinVersion(m_pQuery, minVersion.GetUnderlying());
02037         }
02038 
02042         inline XnStatus SetMaxVersion(const XnVersion& maxVersion)
02043         {
02044             return xnNodeQuerySetMaxVersion(m_pQuery, &maxVersion);
02045         }
02046 
02050         inline XnStatus SetMaxVersion(const Version& maxVersion)
02051         {
02052             return xnNodeQuerySetMaxVersion(m_pQuery, maxVersion.GetUnderlying());
02053         }
02054 
02067         inline XnStatus AddSupportedCapability(const XnChar* strNeededCapability)
02068         {
02069             return xnNodeQueryAddSupportedCapability(m_pQuery, strNeededCapability);
02070         }
02071 
02082         inline XnStatus AddSupportedMapOutputMode(const XnMapOutputMode& MapOutputMode)
02083         {
02084             return xnNodeQueryAddSupportedMapOutputMode(m_pQuery, &MapOutputMode);
02085         }
02086 
02091         inline XnStatus SetSupportedMinUserPositions(const XnUInt32 nCount)
02092         {
02093             return xnNodeQuerySetSupportedMinUserPositions(m_pQuery, nCount);
02094         }
02095 
02107         inline XnStatus SetExistingNodeOnly(XnBool bExistingNode)
02108         {
02109             return xnNodeQuerySetExistingNodeOnly(m_pQuery, bExistingNode);
02110         }
02111 
02116         inline XnStatus AddNeededNode(const XnChar* strInstanceName)
02117         {
02118             return xnNodeQueryAddNeededNode(m_pQuery, strInstanceName);
02119         }
02120 
02125         inline XnStatus SetCreationInfo(const XnChar* strCreationInfo)
02126         {
02127             return xnNodeQuerySetCreationInfo(m_pQuery, strCreationInfo);
02128         }
02129 
02130     private:
02131         XnNodeQuery* m_pQuery;
02132         XnBool m_bAllocated;
02133     };
02134 
02135     //---------------------------------------------------------------------------
02136     // Node Info List
02137     //---------------------------------------------------------------------------
02138 
02143     class NodeInfoList
02144     {
02145     public:
02149         class Iterator
02150         {
02151         public:
02152             friend class NodeInfoList;
02153 
02166             XnBool operator==(const Iterator& other) const
02167             {
02168                 return m_it.pCurrent == other.m_it.pCurrent;
02169             }
02170 
02177             XnBool operator!=(const Iterator& other) const
02178             {
02179                 return m_it.pCurrent != other.m_it.pCurrent;
02180             }
02181 
02186             inline Iterator& operator++()
02187             {
02188                 UpdateInternalObject(xnNodeInfoListGetNext(m_it));
02189                 return *this;
02190             }
02191 
02196             inline Iterator operator++(int)
02197             {
02198                 XnNodeInfoListIterator curr = m_it;
02199                 UpdateInternalObject(xnNodeInfoListGetNext(m_it));
02200                 return Iterator(curr);
02201             }
02202 
02206             inline Iterator& operator--()
02207             {
02208                 UpdateInternalObject(xnNodeInfoListGetPrevious(m_it));
02209                 return *this;
02210             }
02211 
02215             inline Iterator operator--(int)
02216             {
02217                 XnNodeInfoListIterator curr = m_it;
02218                 UpdateInternalObject(xnNodeInfoListGetPrevious(m_it));
02219                 return Iterator(curr);
02220             }
02221 
02225             inline NodeInfo operator*()
02226             {
02227                 return m_Info;
02228             }
02229 
02230         private:
02231             inline Iterator(XnNodeInfoListIterator it) : m_Info(NULL)
02232             {
02233                 UpdateInternalObject(it);
02234             }
02235 
02236             inline void UpdateInternalObject(XnNodeInfoListIterator it)
02237             {
02238                 m_it = it;
02239                 if (xnNodeInfoListIteratorIsValid(it))
02240                 {
02241                     XnNodeInfo* pInfo = xnNodeInfoListGetCurrent(it);
02242                     m_Info = NodeInfo(pInfo);
02243                 }
02244                 else
02245                 {
02246                     m_Info = NodeInfo(NULL);
02247                 }
02248             }
02249 
02250             NodeInfo m_Info;
02251             XnNodeInfoListIterator m_it;
02252         };
02253 
02257         inline NodeInfoList()
02258         {
02259             xnNodeInfoListAllocate(&m_pList);
02260             m_bAllocated = TRUE;
02261         }
02262 
02269         inline NodeInfoList(XnNodeInfoList* pList) : m_pList(pList), m_bAllocated(FALSE) {}
02270 
02271         inline ~NodeInfoList()
02272         {
02273             FreeImpl();
02274         }
02275 
02279         inline XnNodeInfoList* GetUnderlyingObject() const { return m_pList; }
02280 
02287         inline void ReplaceUnderlyingObject(XnNodeInfoList* pList)
02288         {
02289             FreeImpl();
02290             m_pList = pList;
02291             m_bAllocated = TRUE;
02292         }
02293 
02298         inline XnStatus Add(XnProductionNodeDescription& description, const XnChar* strCreationInfo, NodeInfoList* pNeededNodes)
02299         {
02300             XnNodeInfoList* pList = (pNeededNodes == NULL) ? NULL : pNeededNodes->GetUnderlyingObject();
02301             return xnNodeInfoListAdd(m_pList, &description, strCreationInfo, pList);
02302         }
02303 
02308         inline XnStatus AddEx(XnProductionNodeDescription& description, const XnChar* strCreationInfo, NodeInfoList* pNeededNodes, const void* pAdditionalData, XnFreeHandler pFreeHandler)
02309         {
02310             XnNodeInfoList* pList = (pNeededNodes == NULL) ? NULL : pNeededNodes->GetUnderlyingObject();
02311             return xnNodeInfoListAddEx(m_pList, &description, strCreationInfo, pList, pAdditionalData, pFreeHandler);
02312         }
02313 
02318         inline XnStatus AddNode(NodeInfo& info)
02319         {
02320             return xnNodeInfoListAddNode(m_pList, info);
02321         }
02322 
02327         inline XnStatus AddNodeFromAnotherList(Iterator& it)
02328         {
02329             return xnNodeInfoListAddNodeFromList(m_pList, it.m_it);
02330         }
02331 
02336         inline Iterator Begin() const
02337         {
02338             return Iterator(xnNodeInfoListGetFirst(m_pList));
02339         }
02340 
02345         inline Iterator End() const
02346         {
02347             XnNodeInfoListIterator it = { NULL };
02348             return Iterator(it);
02349         }
02350 
02355         inline Iterator RBegin() const
02356         {
02357             return Iterator(xnNodeInfoListGetLast(m_pList));
02358         }
02359 
02364         inline Iterator REnd() const
02365         {
02366             XnNodeInfoListIterator it = { NULL };
02367             return Iterator(it);
02368         }
02369 
02374         inline XnStatus Remove(Iterator& it)
02375         {
02376             return xnNodeInfoListRemove(m_pList, it.m_it);
02377         }
02378 
02383         inline XnStatus Clear()
02384         {
02385             return xnNodeInfoListClear(m_pList);
02386         }
02387 
02392         inline XnStatus Append(NodeInfoList& other)
02393         {
02394             return xnNodeInfoListAppend(m_pList, other.GetUnderlyingObject());
02395         }
02396 
02400         inline XnBool IsEmpty()
02401         {
02402             return xnNodeInfoListIsEmpty(m_pList);
02403         }
02404 
02409         inline XnStatus FilterList(Context& context, Query& query);
02410 
02411     private:
02412         inline void FreeImpl()
02413         {
02414             if (m_bAllocated)
02415             {
02416                 xnNodeInfoListFree(m_pList);
02417                 m_bAllocated = FALSE;
02418                 m_pList = NULL;
02419             }
02420         }
02421 
02422         XnNodeInfoList* m_pList;
02423         XnBool m_bAllocated;
02424     };
02425 
02426     //---------------------------------------------------------------------------
02427     // Production Nodes Functionality
02428     //---------------------------------------------------------------------------
02429 
02434     class Capability : public NodeWrapper
02435     {
02436     public:
02442         Capability(XnNodeHandle hNode) : NodeWrapper(hNode) {}
02443         Capability(const NodeWrapper& node) : NodeWrapper(node) {}
02444     };
02445 
02479     class ErrorStateCapability : public Capability
02480     {
02481     public:
02487         ErrorStateCapability(XnNodeHandle hNode) : Capability(hNode) {}
02488         ErrorStateCapability(const NodeWrapper& node) : Capability(node) {}
02489 
02493         inline XnStatus GetErrorState() const
02494         {
02495             return xnGetNodeErrorState(GetHandle());
02496         }
02497 
02507         inline XnStatus RegisterToErrorStateChange(StateChangedHandler handler, void* pCookie, XnCallbackHandle& hCallback)
02508         {
02509             return _RegisterToStateChange(xnRegisterToNodeErrorStateChange, GetHandle(), handler, pCookie, hCallback);
02510         }
02511 
02519         inline void UnregisterFromErrorStateChange(XnCallbackHandle hCallback)
02520         {
02521             _UnregisterFromStateChange(xnUnregisterFromNodeErrorStateChange, GetHandle(), hCallback);
02522         }
02523     };
02524 
02530     class GeneralIntCapability : public Capability
02531     {
02532     public:
02539         GeneralIntCapability(XnNodeHandle hNode, const XnChar* strCap) : Capability(hNode), m_strCap(strCap) {}
02540         GeneralIntCapability(const NodeWrapper& node, const XnChar* strCap) : Capability(node), m_strCap(strCap) {}
02541 
02546         inline void GetRange(XnInt32& nMin, XnInt32& nMax, XnInt32& nStep, XnInt32& nDefault, XnBool& bIsAutoSupported) const
02547         {
02548             xnGetGeneralIntRange(GetHandle(), m_strCap, &nMin, &nMax, &nStep, &nDefault, &bIsAutoSupported);
02549         }
02550 
02555         inline XnInt32 Get()
02556         {
02557             XnInt32 nValue;
02558             xnGetGeneralIntValue(GetHandle(), m_strCap, &nValue);
02559             return nValue;
02560         }
02561 
02566         inline XnStatus Set(XnInt32 nValue)
02567         {
02568             return xnSetGeneralIntValue(GetHandle(), m_strCap, nValue);
02569         }
02570 
02580         XnStatus RegisterToValueChange(StateChangedHandler handler, void* pCookie, XnCallbackHandle& hCallback);
02581 
02589         void UnregisterFromValueChange(XnCallbackHandle hCallback);
02590 
02591     private:
02592         const XnChar* m_strCap;
02593     };
02594 
02630     class ProductionNode : public NodeWrapper
02631     {
02632     public:
02638         inline ProductionNode(XnNodeHandle hNode = NULL) : NodeWrapper(hNode) {}
02639         inline ProductionNode(const NodeWrapper& other) : NodeWrapper(other) {}
02640 
02649         inline NodeInfo GetInfo() const { return NodeInfo(xnGetNodeInfo(GetHandle())); }
02650 
02655         inline XnStatus AddNeededNode(ProductionNode& needed)
02656         {
02657             return xnAddNeededNode(GetHandle(), needed.GetHandle());
02658         }
02659 
02664         inline XnStatus RemoveNeededNode(ProductionNode& needed)
02665         {
02666             return xnRemoveNeededNode(GetHandle(), needed.GetHandle());
02667         }
02668 
02680         inline void GetContext(Context& context) const;
02681 
02691         inline Context GetContext() const;
02692 
02704         inline XnBool IsCapabilitySupported(const XnChar* strCapabilityName) const
02705         {
02706             return xnIsCapabilitySupported(GetHandle(), strCapabilityName);
02707         }
02708 
02713         inline XnStatus SetIntProperty(const XnChar* strName, XnUInt64 nValue)
02714         {
02715             return xnSetIntProperty(GetHandle(), strName, nValue);
02716         }
02717 
02722         inline XnStatus SetRealProperty(const XnChar* strName, XnDouble dValue)
02723         {
02724             return xnSetRealProperty(GetHandle(), strName, dValue);
02725         }
02726 
02731         inline XnStatus SetStringProperty(const XnChar* strName, const XnChar* strValue)
02732         {
02733             return xnSetStringProperty(GetHandle(), strName, strValue);
02734         }
02735 
02740         inline XnStatus SetGeneralProperty(const XnChar* strName, XnUInt32 nBufferSize, const void* pBuffer)
02741         {
02742             return xnSetGeneralProperty(GetHandle(), strName, nBufferSize, pBuffer);
02743         }
02744 
02749         inline XnStatus GetIntProperty(const XnChar* strName, XnUInt64& nValue) const
02750         {
02751             return xnGetIntProperty(GetHandle(), strName, &nValue);
02752         }
02753 
02758         inline XnStatus GetRealProperty(const XnChar* strName, XnDouble &dValue) const
02759         {
02760             return xnGetRealProperty(GetHandle(), strName, &dValue);
02761         }
02762 
02767         inline XnStatus GetStringProperty(const XnChar* strName, XnChar* csValue, XnUInt32 nBufSize) const
02768         {
02769             return xnGetStringProperty(GetHandle(), strName, csValue, nBufSize);
02770         }
02771 
02776         inline XnStatus GetGeneralProperty(const XnChar* strName, XnUInt32 nBufferSize, void* pBuffer) const
02777         {
02778             return xnGetGeneralProperty(GetHandle(), strName, nBufferSize, pBuffer);
02779         }
02780 
02785         inline XnStatus LockForChanges(XnLockHandle* phLock)
02786         {
02787             return xnLockNodeForChanges(GetHandle(), phLock);
02788         }
02789 
02794         inline void UnlockForChanges(XnLockHandle hLock)
02795         {
02796             xnUnlockNodeForChanges(GetHandle(), hLock);
02797         }
02798 
02803         inline XnStatus LockedNodeStartChanges(XnLockHandle hLock)
02804         {
02805             return xnLockedNodeStartChanges(GetHandle(), hLock);
02806         }
02807 
02812         inline void LockedNodeEndChanges(XnLockHandle hLock)
02813         {
02814             xnLockedNodeEndChanges(GetHandle(), hLock);
02815         }
02816 
02825         inline const ErrorStateCapability GetErrorStateCap() const
02826         {
02827             return ErrorStateCapability(GetHandle());
02828         }
02829 
02838         inline ErrorStateCapability GetErrorStateCap()
02839         {
02840             return ErrorStateCapability(GetHandle());
02841         }
02842 
02854         inline GeneralIntCapability GetGeneralIntCap(const XnChar* strCapability)
02855         {
02856             return GeneralIntCapability(GetHandle(), strCapability);
02857         }
02858     };
02859 
02869     class DeviceIdentificationCapability : public Capability
02870     {
02871     public:
02877         DeviceIdentificationCapability(XnNodeHandle hNode) : Capability(hNode) {}
02878         DeviceIdentificationCapability(const NodeWrapper& node) : Capability(node) {}
02879 
02889         inline XnStatus GetDeviceName(XnChar* strBuffer, XnUInt32 nBufferSize)
02890         {
02891             return xnGetDeviceName(GetHandle(), strBuffer, &nBufferSize);
02892         }
02893 
02903         inline XnStatus GetVendorSpecificData(XnChar* strBuffer, XnUInt32 nBufferSize)
02904         {
02905             return xnGetVendorSpecificData(GetHandle(), strBuffer, &nBufferSize);
02906         }
02907 
02917         inline XnStatus GetSerialNumber(XnChar* strBuffer, XnUInt32 nBufferSize)
02918         {
02919             return xnGetSerialNumber(GetHandle(), strBuffer, &nBufferSize);
02920         }
02921     };
02922 
02936     class Device : public ProductionNode
02937     {
02938     public:
02939         inline Device(XnNodeHandle hNode = NULL) : ProductionNode(hNode) {}
02940         inline Device(const NodeWrapper& other) : ProductionNode(other) {}
02941 
02950         inline XnStatus Create(Context& context, Query* pQuery = NULL, EnumerationErrors* pErrors = NULL);
02951 
02965         inline DeviceIdentificationCapability GetIdentificationCap()
02966         {
02967             return DeviceIdentificationCapability(GetHandle());
02968         }
02969     };
02970 
03018     class MirrorCapability : public Capability
03019     {
03020     public:
03021         inline MirrorCapability(XnNodeHandle hNode) : Capability(hNode) {}
03022         MirrorCapability(const NodeWrapper& node) : Capability(node) {}
03023 
03030         inline XnStatus SetMirror(XnBool bMirror)
03031         {
03032             return xnSetMirror(GetHandle(), bMirror);
03033         }
03034 
03038         inline XnBool IsMirrored() const
03039         {
03040             return xnIsMirrored(GetHandle());
03041         }
03042 
03052         inline XnStatus RegisterToMirrorChange(StateChangedHandler handler, void* pCookie, XnCallbackHandle& hCallback)
03053         {
03054             return _RegisterToStateChange(xnRegisterToMirrorChange, GetHandle(), handler, pCookie, hCallback);
03055         }
03056 
03064         inline void UnregisterFromMirrorChange(XnCallbackHandle hCallback)
03065         {
03066             _UnregisterFromStateChange(xnUnregisterFromMirrorChange, GetHandle(), hCallback);
03067         }
03068     };
03069 
03102     class AlternativeViewPointCapability : public Capability
03103     {
03104     public:
03105         inline AlternativeViewPointCapability(XnNodeHandle hNode) : Capability(hNode) {}
03106         AlternativeViewPointCapability(const NodeWrapper& node) : Capability(node) {}
03107 
03122         inline XnBool IsViewPointSupported(ProductionNode& otherNode) const
03123         {
03124             return xnIsViewPointSupported(GetHandle(), otherNode.GetHandle());
03125         }
03126 
03134         inline XnStatus SetViewPoint(ProductionNode& otherNode)
03135         {
03136             return xnSetViewPoint(GetHandle(), otherNode.GetHandle());
03137         }
03138 
03142         inline XnStatus ResetViewPoint()
03143         {
03144             return xnResetViewPoint(GetHandle());
03145         }
03146 
03154         inline XnBool IsViewPointAs(ProductionNode& otherNode) const
03155         {
03156             return xnIsViewPointAs(GetHandle(), otherNode.GetHandle());
03157         }
03158 
03168         inline XnStatus RegisterToViewPointChange(StateChangedHandler handler, void* pCookie, XnCallbackHandle& hCallback)
03169         {
03170             return _RegisterToStateChange(xnRegisterToViewPointChange, GetHandle(), handler, pCookie, hCallback);
03171         }
03172 
03180         inline void UnregisterFromViewPointChange(XnCallbackHandle hCallback)
03181         {
03182             _UnregisterFromStateChange(xnUnregisterFromViewPointChange, GetHandle(), hCallback);
03183         }
03184 
03196         XnStatus GetPixelCoordinatesInViewPoint(ProductionNode& other, XnUInt32 x, XnUInt32 y, XnUInt32& altX, XnUInt32& altY)
03197         {
03198             return xnGetPixelCoordinatesInViewPoint(GetHandle(), other.GetHandle(), x, y, &altX, &altY);
03199         }
03200     };
03201 
03223     class FrameSyncCapability : public Capability
03224     {
03225     public:
03226         inline FrameSyncCapability(XnNodeHandle hNode) : Capability(hNode) {}
03227         FrameSyncCapability(const NodeWrapper& node) : Capability(node) {}
03228 
03237         inline XnBool CanFrameSyncWith(Generator& other) const;
03238 
03245         inline XnStatus FrameSyncWith(Generator& other);
03246 
03251         inline XnStatus StopFrameSyncWith(Generator& other);
03252 
03259         inline XnBool IsFrameSyncedWith(Generator& other) const;
03260 
03270         inline XnStatus RegisterToFrameSyncChange(StateChangedHandler handler, void* pCookie, XnCallbackHandle& hCallback)
03271         {
03272             return _RegisterToStateChange(xnRegisterToFrameSyncChange, GetHandle(), handler, pCookie, hCallback);
03273         }
03274 
03282         inline void UnregisterFromFrameSyncChange(XnCallbackHandle hCallback)
03283         {
03284             _UnregisterFromStateChange(xnUnregisterFromFrameSyncChange, GetHandle(), hCallback);
03285         }
03286     };
03287 
03340     class Generator : public ProductionNode
03341     {
03342     public:
03348         inline Generator(XnNodeHandle hNode = NULL) : ProductionNode(hNode) {}
03349         inline Generator(const NodeWrapper& other) : ProductionNode(other) {}
03350 
03370         inline XnStatus StartGenerating()
03371         {
03372             return xnStartGenerating(GetHandle());
03373         }
03374 
03378         inline XnBool IsGenerating() const
03379         {
03380             return xnIsGenerating(GetHandle());
03381         }
03382 
03391         inline XnStatus StopGenerating()
03392         {
03393             return xnStopGenerating(GetHandle());
03394         }
03395 
03409         inline XnStatus RegisterToGenerationRunningChange(StateChangedHandler handler, void* pCookie, XnCallbackHandle &hCallback)
03410         {
03411             return _RegisterToStateChange(xnRegisterToGenerationRunningChange, GetHandle(), handler, pCookie, hCallback);
03412         }
03413 
03421         inline void UnregisterFromGenerationRunningChange(XnCallbackHandle hCallback)
03422         {
03423             _UnregisterFromStateChange(xnUnregisterFromGenerationRunningChange, GetHandle(), hCallback);
03424         }
03425 
03439         inline XnStatus RegisterToNewDataAvailable(StateChangedHandler handler, void* pCookie, XnCallbackHandle &hCallback)
03440         {
03441             return _RegisterToStateChange(xnRegisterToNewDataAvailable, GetHandle(), handler, pCookie, hCallback);
03442         }
03443 
03451         inline void UnregisterFromNewDataAvailable(XnCallbackHandle hCallback)
03452         {
03453             _UnregisterFromStateChange(xnUnregisterFromNewDataAvailable, GetHandle(), hCallback);
03454         }
03455 
03464         inline XnBool IsNewDataAvailable(XnUInt64* pnTimestamp = NULL) const
03465         {
03466             return xnIsNewDataAvailable(GetHandle(), pnTimestamp);
03467         }
03468 
03487         inline XnStatus WaitAndUpdateData()
03488         {
03489             return xnWaitAndUpdateData(GetHandle());
03490         }
03491 
03496         inline XnBool IsDataNew() const
03497         {
03498             return xnIsDataNew(GetHandle());
03499         }
03500 
03518         inline const void* GetData()
03519         {
03520             return xnGetData(GetHandle());
03521         }
03522 
03536         inline XnUInt32 GetDataSize() const
03537         {
03538             return xnGetDataSize(GetHandle());
03539         }
03540 
03554         inline XnUInt64 GetTimestamp() const
03555         {
03556             return xnGetTimestamp(GetHandle());
03557         }
03558 
03571         inline XnUInt32 GetFrameID() const
03572         {
03573             return xnGetFrameID(GetHandle());
03574         }
03575 
03584         inline const MirrorCapability GetMirrorCap() const
03585         {
03586             return MirrorCapability(GetHandle());
03587         }
03588 
03597         inline MirrorCapability GetMirrorCap()
03598         {
03599             return MirrorCapability(GetHandle());
03600         }
03601 
03612         inline const AlternativeViewPointCapability GetAlternativeViewPointCap() const
03613         {
03614             return AlternativeViewPointCapability(GetHandle());
03615         }
03616 
03627         inline AlternativeViewPointCapability GetAlternativeViewPointCap()
03628         {
03629             return AlternativeViewPointCapability(GetHandle());
03630         }
03631 
03641         inline const FrameSyncCapability GetFrameSyncCap() const
03642         {
03643             return FrameSyncCapability(GetHandle());
03644         }
03645 
03655         inline FrameSyncCapability GetFrameSyncCap()
03656         {
03657             return FrameSyncCapability(GetHandle());
03658         }
03659     };
03660 
03705     class Recorder : public ProductionNode
03706     {
03707     public:
03713         inline Recorder(XnNodeHandle hNode = NULL) : ProductionNode(hNode) {}
03714         inline Recorder(const NodeWrapper& other) : ProductionNode(other) {}
03715 
03723         inline XnStatus Create(Context& context, const XnChar* strFormatName = NULL);
03724 
03733         inline XnStatus SetDestination(XnRecordMedium destType, const XnChar* strDest)
03734         {
03735             return xnSetRecorderDestination(GetHandle(), destType, strDest);
03736         }
03737 
03747         inline XnStatus GetDestination(XnRecordMedium& destType, XnChar* strDest, XnUInt32 nBufSize)
03748         {
03749             return xnGetRecorderDestination(GetHandle(), &destType, strDest, nBufSize);
03750         }
03751 
03761         inline XnStatus AddNodeToRecording(ProductionNode& Node, XnCodecID compression = XN_CODEC_NULL)
03762         {
03763             return xnAddNodeToRecording(GetHandle(), Node.GetHandle(), compression);
03764         }
03765 
03772         inline XnStatus RemoveNodeFromRecording(ProductionNode& Node)
03773         {
03774             return xnRemoveNodeFromRecording(GetHandle(), Node.GetHandle());
03775         }
03776 
03789         inline XnStatus Record()
03790         {
03791             return xnRecord(GetHandle());
03792         }
03793     };
03794 
03822     class Player : public ProductionNode
03823     {
03824     public:
03830         inline Player(XnNodeHandle hNode = NULL) : ProductionNode(hNode) {}
03831         inline Player(const NodeWrapper& other) : ProductionNode(other) {}
03832 
03841         inline XnStatus Create(Context& context, const XnChar* strFormatName);
03842 
03843 
03858         inline XnStatus SetRepeat(XnBool bRepeat)
03859         {
03860             return xnSetPlayerRepeat(GetHandle(), bRepeat);
03861         }
03862 
03867         inline XnStatus SetSource(XnRecordMedium sourceType, const XnChar* strSource)
03868         {
03869             return xnSetPlayerSource(GetHandle(), sourceType, strSource);
03870         }
03871 
03880         inline XnStatus GetSource(XnRecordMedium &sourceType, XnChar* strSource, XnUInt32 nBufSize) const
03881         {
03882             return xnGetPlayerSource(GetHandle(), &sourceType, strSource, nBufSize);
03883         }
03884 
03889         inline XnStatus ReadNext()
03890         {
03891             return xnPlayerReadNext(GetHandle());
03892         }
03893 
03918         inline XnStatus SeekToTimeStamp(XnInt64 nTimeOffset, XnPlayerSeekOrigin origin)
03919         {
03920             return xnSeekPlayerToTimeStamp(GetHandle(), nTimeOffset, origin);
03921         }
03922 
03947         inline XnStatus SeekToFrame(const XnChar* strNodeName, XnInt32 nFrameOffset, XnPlayerSeekOrigin origin)
03948         {
03949             return xnSeekPlayerToFrame(GetHandle(), strNodeName, nFrameOffset, origin);
03950         }
03951 
03957         inline XnStatus TellTimestamp(XnUInt64& nTimestamp) const
03958         {
03959             return xnTellPlayerTimestamp(GetHandle(), &nTimestamp);
03960         }
03961 
03974         inline XnStatus TellFrame(const XnChar* strNodeName, XnUInt32& nFrame) const
03975         {
03976             return xnTellPlayerFrame(GetHandle(), strNodeName, &nFrame);
03977         }
03978 
03986         inline XnStatus GetNumFrames(const XnChar* strNodeName, XnUInt32& nFrames) const
03987         {
03988             return xnGetPlayerNumFrames(GetHandle(), strNodeName, &nFrames);
03989         }
03990 
03995         inline const XnChar* GetSupportedFormat() const
03996         {
03997             return xnGetPlayerSupportedFormat(GetHandle());
03998         }
03999 
04004         inline XnStatus EnumerateNodes(NodeInfoList& list) const
04005         {
04006             XnNodeInfoList* pList;
04007             XnStatus nRetVal = xnEnumeratePlayerNodes(GetHandle(), &pList);
04008             XN_IS_STATUS_OK(nRetVal);
04009 
04010             list.ReplaceUnderlyingObject(pList);
04011 
04012             return (XN_STATUS_OK);
04013         }
04014 
04023         inline XnBool IsEOF() const
04024         {
04025             return xnIsPlayerAtEOF(GetHandle());
04026         }
04027 
04037         inline XnStatus RegisterToEndOfFileReached(StateChangedHandler handler, void* pCookie, XnCallbackHandle& hCallback)
04038         {
04039             return _RegisterToStateChange(xnRegisterToEndOfFileReached, GetHandle(), handler, pCookie, hCallback);
04040         }
04041 
04049         inline void UnregisterFromEndOfFileReached(XnCallbackHandle hCallback)
04050         {
04051             _UnregisterFromStateChange(xnUnregisterFromEndOfFileReached, GetHandle(), hCallback);
04052         }
04053 
04072         inline XnStatus SetPlaybackSpeed(XnDouble dSpeed)
04073         {
04074             return xnSetPlaybackSpeed(GetHandle(), dSpeed);
04075         }
04076 
04081         inline XnDouble GetPlaybackSpeed() const
04082         {
04083             return xnGetPlaybackSpeed(GetHandle());
04084         }
04085     };
04086 
04114     class CroppingCapability : public Capability
04115     {
04116     public:
04122         inline CroppingCapability(XnNodeHandle hNode) : Capability(hNode) {}
04123         CroppingCapability(const NodeWrapper& node) : Capability(node) {}
04124 
04134         inline XnStatus SetCropping(const XnCropping& Cropping)
04135         {
04136             return xnSetCropping(GetHandle(), &Cropping);
04137         }
04138 
04149         inline XnStatus GetCropping(XnCropping& Cropping) const
04150         {
04151             return xnGetCropping(GetHandle(), &Cropping);
04152         }
04153 
04163         inline XnStatus RegisterToCroppingChange(StateChangedHandler handler, void* pCookie, XnCallbackHandle& hCallback)
04164         {
04165             return _RegisterToStateChange(xnRegisterToCroppingChange, GetHandle(), handler, pCookie, hCallback);
04166         }
04167 
04175         inline void UnregisterFromCroppingChange(XnCallbackHandle hCallback)
04176         {
04177             _UnregisterFromStateChange(xnUnregisterFromCroppingChange, GetHandle(), hCallback);
04178         }
04179     };
04180 
04189     class AntiFlickerCapability : public Capability
04190     {
04191     public:
04197         inline AntiFlickerCapability(XnNodeHandle hNode) : Capability(hNode) {}
04198         AntiFlickerCapability(const NodeWrapper& node) : Capability(node) {}
04199 
04204         inline XnStatus SetPowerLineFrequency(XnPowerLineFrequency nFrequency)
04205         {
04206             return xnSetPowerLineFrequency(GetHandle(), nFrequency);
04207         }
04208 
04213         inline XnPowerLineFrequency GetPowerLineFrequency()
04214         {
04215             return xnGetPowerLineFrequency(GetHandle());
04216         }
04217 
04227         inline XnStatus RegisterToPowerLineFrequencyChange(StateChangedHandler handler, void* pCookie, XnCallbackHandle& hCallback)
04228         {
04229             return _RegisterToStateChange(xnRegisterToPowerLineFrequencyChange, GetHandle(), handler, pCookie, hCallback);
04230         }
04231 
04239         inline void UnregisterFromPowerLineFrequencyChange(XnCallbackHandle hCallback)
04240         {
04241             _UnregisterFromStateChange(xnUnregisterFromPowerLineFrequencyChange, GetHandle(), hCallback);
04242         }
04243     };
04244 
04268     class MapGenerator : public Generator
04269     {
04270     public:
04276         inline MapGenerator(XnNodeHandle hNode = NULL) : Generator(hNode) {}
04277         inline MapGenerator(const NodeWrapper& other) : Generator(other) {}
04278 
04286         inline XnUInt32 GetSupportedMapOutputModesCount() const
04287         {
04288             return xnGetSupportedMapOutputModesCount(GetHandle());
04289         }
04290 
04301         inline XnStatus GetSupportedMapOutputModes(XnMapOutputMode* aModes, XnUInt32& nCount) const
04302         {
04303             return xnGetSupportedMapOutputModes(GetHandle(), aModes, &nCount);
04304         }
04305 
04319         inline XnStatus SetMapOutputMode(const XnMapOutputMode& OutputMode)
04320         {
04321             return xnSetMapOutputMode(GetHandle(), &OutputMode);
04322         }
04323 
04341         inline XnStatus GetMapOutputMode(XnMapOutputMode &OutputMode) const
04342         {
04343             return xnGetMapOutputMode(GetHandle(), &OutputMode);
04344         }
04345 
04354         inline XnUInt32 GetBytesPerPixel() const
04355         {
04356             return xnGetBytesPerPixel(GetHandle());
04357         }
04358 
04368         inline XnStatus RegisterToMapOutputModeChange(StateChangedHandler handler, void* pCookie, XnCallbackHandle& hCallback)
04369         {
04370             return _RegisterToStateChange(xnRegisterToMapOutputModeChange, GetHandle(), handler, pCookie, hCallback);
04371         }
04372 
04380         inline void UnregisterFromMapOutputModeChange(XnCallbackHandle hCallback)
04381         {
04382             _UnregisterFromStateChange(xnUnregisterFromMapOutputModeChange, GetHandle(), hCallback);
04383         }
04384 
04393         inline const CroppingCapability GetCroppingCap() const
04394         {
04395             return CroppingCapability(GetHandle());
04396         }
04397 
04406         inline CroppingCapability GetCroppingCap()
04407         {
04408             return CroppingCapability(GetHandle());
04409         }
04410 
04416         inline GeneralIntCapability GetBrightnessCap()
04417         {
04418             return GeneralIntCapability(GetHandle(), XN_CAPABILITY_BRIGHTNESS);
04419         }
04420 
04426         inline GeneralIntCapability GetContrastCap()
04427         {
04428             return GeneralIntCapability(GetHandle(), XN_CAPABILITY_CONTRAST);
04429         }
04430 
04436         inline GeneralIntCapability GetHueCap()
04437         {
04438             return GeneralIntCapability(GetHandle(), XN_CAPABILITY_HUE);
04439         }
04440 
04446         inline GeneralIntCapability GetSaturationCap()
04447         {
04448             return GeneralIntCapability(GetHandle(), XN_CAPABILITY_SATURATION);
04449         }
04450 
04456         inline GeneralIntCapability GetSharpnessCap()
04457         {
04458             return GeneralIntCapability(GetHandle(), XN_CAPABILITY_SHARPNESS);
04459         }
04460 
04466         inline GeneralIntCapability GetGammaCap()
04467         {
04468             return GeneralIntCapability(GetHandle(), XN_CAPABILITY_GAMMA);
04469         }
04470 
04476         inline GeneralIntCapability GetWhiteBalanceCap()
04477         {
04478             return GeneralIntCapability(GetHandle(), XN_CAPABILITY_COLOR_TEMPERATURE);
04479         }
04480 
04486         inline GeneralIntCapability GetBacklightCompensationCap()
04487         {
04488             return GeneralIntCapability(GetHandle(), XN_CAPABILITY_BACKLIGHT_COMPENSATION);
04489         }
04490 
04496         inline GeneralIntCapability GetGainCap()
04497         {
04498             return GeneralIntCapability(GetHandle(), XN_CAPABILITY_GAIN);
04499         }
04500 
04506         inline GeneralIntCapability GetPanCap()
04507         {
04508             return GeneralIntCapability(GetHandle(), XN_CAPABILITY_PAN);
04509         }
04510 
04516         inline GeneralIntCapability GetTiltCap()
04517         {
04518             return GeneralIntCapability(GetHandle(), XN_CAPABILITY_TILT);
04519         }
04520 
04526         inline GeneralIntCapability GetRollCap()
04527         {
04528             return GeneralIntCapability(GetHandle(), XN_CAPABILITY_ROLL);
04529         }
04530 
04536         inline GeneralIntCapability GetZoomCap()
04537         {
04538             return GeneralIntCapability(GetHandle(), XN_CAPABILITY_ZOOM);
04539         }
04540 
04546         inline GeneralIntCapability GetExposureCap()
04547         {
04548             return GeneralIntCapability(GetHandle(), XN_CAPABILITY_EXPOSURE);
04549         }
04550 
04556         inline GeneralIntCapability GetAutoExposureCap()
04557         {
04558             return GeneralIntCapability(GetHandle(), XN_CAPABILITY_AUTO_EXPOSURE);
04559         }
04560         
04561         
04567         inline GeneralIntCapability GetIrisCap()
04568         {
04569             return GeneralIntCapability(GetHandle(), XN_CAPABILITY_IRIS);
04570         }
04571 
04577         inline GeneralIntCapability GetFocusCap()
04578         {
04579             return GeneralIntCapability(GetHandle(), XN_CAPABILITY_FOCUS);
04580         }
04581 
04587         inline GeneralIntCapability GetLowLightCompensationCap()
04588         {
04589             return GeneralIntCapability(GetHandle(), XN_CAPABILITY_LOW_LIGHT_COMPENSATION);
04590         }
04591 
04597         inline AntiFlickerCapability GetAntiFlickerCap()
04598         {
04599             return AntiFlickerCapability(GetHandle());
04600         }
04601     };
04602 
04611     class UserPositionCapability : public Capability
04612     {
04613     public:
04619         inline UserPositionCapability(XnNodeHandle hNode = NULL) : Capability(hNode) {}
04620         UserPositionCapability(const NodeWrapper& node) : Capability(node) {}
04621 
04626         inline XnUInt32 GetSupportedUserPositionsCount() const
04627         {
04628             return xnGetSupportedUserPositionsCount(GetHandle());
04629         }
04630 
04635         inline XnStatus SetUserPosition(XnUInt32 nIndex, const XnBoundingBox3D& Position)
04636         {
04637             return xnSetUserPosition(GetHandle(), nIndex, &Position);
04638         }
04639 
04644         inline XnStatus GetUserPosition(XnUInt32 nIndex, XnBoundingBox3D& Position) const
04645         {
04646             return xnGetUserPosition(GetHandle(), nIndex, &Position);
04647         }
04648 
04658         inline XnStatus RegisterToUserPositionChange(StateChangedHandler handler, void* pCookie, XnCallbackHandle& hCallback)
04659         {
04660             return _RegisterToStateChange(xnRegisterToUserPositionChange, GetHandle(), handler, pCookie, hCallback);
04661         }
04662 
04670         inline void UnregisterFromUserPositionChange(XnCallbackHandle hCallback)
04671         {
04672             _UnregisterFromStateChange(xnUnregisterFromUserPositionChange, GetHandle(), hCallback);
04673         }
04674     };
04675 
04720     class DepthGenerator : public MapGenerator
04721     {
04722     public:
04728         inline DepthGenerator(XnNodeHandle hNode = NULL) : MapGenerator(hNode) {}
04729         inline DepthGenerator(const NodeWrapper& other) : MapGenerator(other) {}
04730 
04738         inline XnStatus Create(Context& context, Query* pQuery = NULL, EnumerationErrors* pErrors = NULL);
04739 
04756         inline void GetMetaData(DepthMetaData& metaData) const
04757         {
04758             xnGetDepthMetaData(GetHandle(), metaData.GetUnderlying());
04759         }
04760 
04765         inline const XnDepthPixel* GetDepthMap() const
04766         {
04767             return xnGetDepthMap(GetHandle());
04768         }
04769 
04779         inline XnDepthPixel GetDeviceMaxDepth() const
04780         {
04781             return xnGetDeviceMaxDepth(GetHandle());
04782         }
04783 
04802         inline XnStatus GetFieldOfView(XnFieldOfView& FOV) const
04803         {
04804             return xnGetDepthFieldOfView(GetHandle(), &FOV);
04805         }
04806 
04816         inline XnStatus RegisterToFieldOfViewChange(StateChangedHandler handler, void* pCookie, XnCallbackHandle& hCallback)
04817         {
04818             return _RegisterToStateChange(xnRegisterToDepthFieldOfViewChange, GetHandle(), handler, pCookie, hCallback);
04819         }
04820 
04828         inline void UnregisterFromFieldOfViewChange(XnCallbackHandle hCallback)
04829         {
04830             _UnregisterFromStateChange(xnUnregisterFromDepthFieldOfViewChange, GetHandle(), hCallback);
04831         }
04832 
04842         inline XnStatus ConvertProjectiveToRealWorld(XnUInt32 nCount, const XnPoint3D aProjective[], XnPoint3D aRealWorld[]) const
04843         {
04844             return xnConvertProjectiveToRealWorld(GetHandle(), nCount, aProjective, aRealWorld);
04845         }
04846 
04856         inline XnStatus ConvertRealWorldToProjective(XnUInt32 nCount, const XnPoint3D aRealWorld[], XnPoint3D aProjective[]) const
04857         {
04858             return xnConvertRealWorldToProjective(GetHandle(), nCount, aRealWorld, aProjective);
04859         }
04860 
04866         inline const UserPositionCapability GetUserPositionCap() const
04867         {
04868             return UserPositionCapability(GetHandle());
04869         }
04870 
04876         inline UserPositionCapability GetUserPositionCap()
04877         {
04878             return UserPositionCapability(GetHandle());
04879         }
04880     };
04881 
04886     class MockDepthGenerator : public DepthGenerator
04887     {
04888     public:
04894         inline MockDepthGenerator(XnNodeHandle hNode = NULL) : DepthGenerator(hNode) {}
04895         inline MockDepthGenerator(const NodeWrapper& other) : DepthGenerator(other) {}
04896 
04903         XnStatus Create(Context& context, const XnChar* strName = NULL);
04904 
04912         XnStatus CreateBasedOn(DepthGenerator& other, const XnChar* strName = NULL);
04913 
04918         inline XnStatus SetData(XnUInt32 nFrameID, XnUInt64 nTimestamp, XnUInt32 nDataSize, const XnDepthPixel* pDepthMap)
04919         {
04920             return xnMockDepthSetData(GetHandle(), nFrameID, nTimestamp, nDataSize, pDepthMap);
04921         }
04922 
04931         inline XnStatus SetData(const DepthMetaData& depthMD, XnUInt32 nFrameID, XnUInt64 nTimestamp)
04932         {
04933             return SetData(nFrameID, nTimestamp, depthMD.DataSize(), depthMD.Data());
04934         }
04935 
04941         inline XnStatus SetData(const DepthMetaData& depthMD)
04942         {
04943             return SetData(depthMD, depthMD.FrameID(), depthMD.Timestamp());
04944         }
04945     };
04946 
04965     class ImageGenerator : public MapGenerator
04966     {
04967     public:
04973         inline ImageGenerator(XnNodeHandle hNode = NULL) : MapGenerator(hNode) {}
04974         inline ImageGenerator(const NodeWrapper& other) : MapGenerator(other) {}
04975 
04981         inline XnStatus Create(Context& context, Query* pQuery = NULL, EnumerationErrors* pErrors = NULL);
04982 
04999         inline void GetMetaData(ImageMetaData& metaData) const
05000         {
05001             xnGetImageMetaData(GetHandle(), metaData.GetUnderlying());
05002         }
05003 
05008         inline const XnRGB24Pixel* GetRGB24ImageMap() const
05009         {
05010             return xnGetRGB24ImageMap(GetHandle());
05011         }
05012 
05017         inline const XnYUV422DoublePixel* GetYUV422ImageMap() const
05018         {
05019             return xnGetYUV422ImageMap(GetHandle());
05020         }
05021 
05026         inline const XnGrayscale8Pixel* GetGrayscale8ImageMap() const
05027         {
05028             return xnGetGrayscale8ImageMap(GetHandle());
05029         }
05030 
05035         inline const XnGrayscale16Pixel* GetGrayscale16ImageMap() const
05036         {
05037             return xnGetGrayscale16ImageMap(GetHandle());
05038         }
05039 
05044         inline const XnUInt8* GetImageMap() const
05045         {
05046             return xnGetImageMap(GetHandle());
05047         }
05048 
05059         inline XnBool IsPixelFormatSupported(XnPixelFormat Format) const
05060         {
05061             return xnIsPixelFormatSupported(GetHandle(), Format);
05062         }
05063 
05081         inline XnStatus SetPixelFormat(XnPixelFormat Format)
05082         {
05083             return xnSetPixelFormat(GetHandle(), Format);
05084         }
05085 
05096         inline XnPixelFormat GetPixelFormat() const
05097         {
05098             return xnGetPixelFormat(GetHandle());
05099         }
05100 
05110         inline XnStatus RegisterToPixelFormatChange(StateChangedHandler handler, void* pCookie, XnCallbackHandle& hCallback)
05111         {
05112             return _RegisterToStateChange(xnRegisterToPixelFormatChange, GetHandle(), handler, pCookie, hCallback);
05113         }
05114 
05122         inline void UnregisterFromPixelFormatChange(XnCallbackHandle hCallback)
05123         {
05124             _UnregisterFromStateChange(xnUnregisterFromPixelFormatChange, GetHandle(), hCallback);
05125         }
05126     };
05127 
05132     class MockImageGenerator : public ImageGenerator
05133     {
05134     public:
05140         inline MockImageGenerator(XnNodeHandle hNode = NULL) : ImageGenerator(hNode) {}
05141         inline MockImageGenerator(const NodeWrapper& other) : ImageGenerator(other) {}
05142 
05149         XnStatus Create(Context& context, const XnChar* strName = NULL);
05150 
05158         XnStatus CreateBasedOn(ImageGenerator& other, const XnChar* strName = NULL);
05159 
05164         inline XnStatus SetData(XnUInt32 nFrameID, XnUInt64 nTimestamp, XnUInt32 nDataSize, const XnUInt8* pImageMap)
05165         {
05166             return xnMockImageSetData(GetHandle(), nFrameID, nTimestamp, nDataSize, pImageMap);
05167         }
05168 
05177         inline XnStatus SetData(const ImageMetaData& imageMD, XnUInt32 nFrameID, XnUInt64 nTimestamp)
05178         {
05179             return SetData(nFrameID, nTimestamp, imageMD.DataSize(), imageMD.Data());
05180         }
05181 
05187         inline XnStatus SetData(const ImageMetaData& imageMD)
05188         {
05189             return SetData(imageMD, imageMD.FrameID(), imageMD.Timestamp());
05190         }
05191     };
05192 
05201     class IRGenerator : public MapGenerator
05202     {
05203     public:
05209         inline IRGenerator(XnNodeHandle hNode = NULL) : MapGenerator(hNode) {}
05210         inline IRGenerator(const NodeWrapper& other) : MapGenerator(other) {}
05211 
05218         inline XnStatus Create(Context& context, Query* pQuery = NULL, EnumerationErrors* pErrors = NULL);
05219 
05236         inline void GetMetaData(IRMetaData& metaData) const
05237         {
05238             xnGetIRMetaData(GetHandle(), metaData.GetUnderlying());
05239         }
05240 
05244         inline const XnIRPixel* GetIRMap() const
05245         {
05246             return xnGetIRMap(GetHandle());
05247         }
05248     };
05249 
05254     class MockIRGenerator : public IRGenerator
05255     {
05256     public:
05262         inline MockIRGenerator(XnNodeHandle hNode = NULL) : IRGenerator(hNode) {}
05263         inline MockIRGenerator(const NodeWrapper& other) : IRGenerator(other) {}
05264 
05271         XnStatus Create(Context& context, const XnChar* strName = NULL);
05278         XnStatus CreateBasedOn(IRGenerator& other, const XnChar* strName = NULL);
05279 
05284         inline XnStatus SetData(XnUInt32 nFrameID, XnUInt64 nTimestamp, XnUInt32 nDataSize, const XnIRPixel* pIRMap)
05285         {
05286             return xnMockIRSetData(GetHandle(), nFrameID, nTimestamp, nDataSize, pIRMap);
05287         }
05288 
05297         inline XnStatus SetData(const IRMetaData& irMD, XnUInt32 nFrameID, XnUInt64 nTimestamp)
05298         {
05299             return SetData(nFrameID, nTimestamp, irMD.DataSize(), irMD.Data());
05300         }
05301 
05307         inline XnStatus SetData(const IRMetaData& irMD)
05308         {
05309             return SetData(irMD, irMD.FrameID(), irMD.Timestamp());
05310         }
05311     };
05312 
05380     class GestureGenerator : public Generator
05381     {
05382     public:
05388         inline GestureGenerator(XnNodeHandle hNode = NULL) : Generator(hNode) {}
05389         inline GestureGenerator(const NodeWrapper& other) : Generator(other) {}
05390 
05404         inline XnStatus Create(Context& context, Query* pQuery = NULL, EnumerationErrors* pErrors = NULL);
05405 
05419         inline XnStatus AddGesture(const XnChar* strGesture, XnBoundingBox3D* pArea)
05420         {
05421             return xnAddGesture(GetHandle(), strGesture, pArea);
05422         }
05423 
05431         inline XnStatus RemoveGesture(const XnChar* strGesture)
05432         {
05433             return xnRemoveGesture(GetHandle(), strGesture);
05434         }
05435 
05444         inline XnStatus GetAllActiveGestures(XnChar** astrGestures, XnUInt32 nNameLength, XnUInt16& nGestures) const
05445         {
05446             return xnGetAllActiveGestures(GetHandle(), astrGestures, nNameLength, &nGestures);
05447         }
05448 
05453         inline XnUInt16 GetNumberOfAvailableGestures() const
05454         {
05455             return xnGetNumberOfAvailableGestures(GetHandle());
05456         }
05457 
05466         inline XnStatus EnumerateAllGestures(XnChar** astrGestures, XnUInt32 nNameLength, XnUInt16& nGestures) const
05467         {
05468             return xnEnumerateAllGestures(GetHandle(), astrGestures, nNameLength, &nGestures);
05469         }
05470 
05476         inline XnBool IsGestureAvailable(const XnChar* strGesture) const
05477         {
05478             return xnIsGestureAvailable(GetHandle(), strGesture);
05479         }
05480 
05485         inline XnBool IsGestureProgressSupported(const XnChar* strGesture) const
05486         {
05487             return xnIsGestureProgressSupported(GetHandle(), strGesture);
05488         }
05489 
05511         typedef void (XN_CALLBACK_TYPE* GestureRecognized)(GestureGenerator& generator, const XnChar* strGesture, const XnPoint3D* pIDPosition, const XnPoint3D* pEndPosition, void* pCookie);
05512 
05539         typedef void (XN_CALLBACK_TYPE* GestureProgress)(GestureGenerator& generator, const XnChar* strGesture, const XnPoint3D* pPosition, XnFloat fProgress, void* pCookie);
05540 
05552         XnStatus RegisterGestureCallbacks(GestureRecognized RecognizedCB, GestureProgress ProgressCB, void* pCookie, XnCallbackHandle& hCallback)
05553         {
05554             XnStatus nRetVal = XN_STATUS_OK;
05555 
05556             GestureCookie* pGestureCookie;
05557             XN_VALIDATE_ALLOC(pGestureCookie, GestureCookie);
05558             pGestureCookie->recognizedHandler = RecognizedCB;
05559             pGestureCookie->progressHandler = ProgressCB;
05560             pGestureCookie->pUserCookie = pCookie;
05561 
05562             nRetVal = xnRegisterGestureCallbacks(GetHandle(), GestureRecognizedCallback, GestureProgressCallback, pGestureCookie, &pGestureCookie->hCallback);
05563             if (nRetVal != XN_STATUS_OK)
05564             {
05565                 xnOSFree(pGestureCookie);
05566                 return (nRetVal);
05567             }
05568 
05569             hCallback = pGestureCookie;
05570 
05571             return (XN_STATUS_OK);
05572         }
05573 
05581         inline void UnregisterGestureCallbacks(XnCallbackHandle hCallback)
05582         {
05583             GestureCookie* pGestureCookie = (GestureCookie*)hCallback;
05584             xnUnregisterGestureCallbacks(GetHandle(), pGestureCookie->hCallback);
05585             xnOSFree(pGestureCookie);
05586         }
05587 
05597         inline XnStatus RegisterToGestureChange(StateChangedHandler handler, void* pCookie, XnCallbackHandle& hCallback)
05598         {
05599             return _RegisterToStateChange(xnRegisterToGestureChange, GetHandle(), handler, pCookie, hCallback);
05600         }
05601 
05609         inline void UnregisterFromGestureChange(XnCallbackHandle hCallback)
05610         {
05611             _UnregisterFromStateChange(xnUnregisterFromGestureChange, GetHandle(), hCallback);
05612         }
05613 
05641         typedef void (XN_CALLBACK_TYPE* GestureIntermediateStageCompleted)(GestureGenerator& generator, const XnChar* strGesture, const XnPoint3D* pPosition, void* pCookie);
05642 
05652         XnStatus RegisterToGestureIntermediateStageCompleted(GestureIntermediateStageCompleted handler, void* pCookie, XnCallbackHandle& hCallback)
05653         {
05654             XnStatus nRetVal = XN_STATUS_OK;
05655 
05656             GestureIntermediateStageCompletedCookie* pGestureCookie;
05657             XN_VALIDATE_ALLOC(pGestureCookie, GestureIntermediateStageCompletedCookie);
05658             pGestureCookie->handler = handler;
05659             pGestureCookie->pUserCookie = pCookie;
05660 
05661             nRetVal = xnRegisterToGestureIntermediateStageCompleted(GetHandle(), GestureIntermediateStageCompletedCallback, pGestureCookie, &pGestureCookie->hCallback);
05662             if (nRetVal != XN_STATUS_OK)
05663             {
05664                 xnOSFree(pGestureCookie);
05665                 return (nRetVal);
05666             }
05667 
05668             hCallback = pGestureCookie;
05669 
05670             return (XN_STATUS_OK);
05671         }
05672 
05680         inline void UnregisterFromGestureIntermediateStageCompleted(XnCallbackHandle hCallback)
05681         {
05682             GestureIntermediateStageCompletedCookie* pGestureCookie = (GestureIntermediateStageCompletedCookie*)hCallback;
05683             xnUnregisterFromGestureIntermediateStageCompleted(GetHandle(), pGestureCookie->hCallback);
05684             xnOSFree(pGestureCookie);
05685         }
05686 
05705         typedef void (XN_CALLBACK_TYPE* GestureReadyForNextIntermediateStage)(GestureGenerator& generator, const XnChar* strGesture, const XnPoint3D* pPosition, void* pCookie);
05706 
05716         XnStatus RegisterToGestureReadyForNextIntermediateStage(GestureReadyForNextIntermediateStage handler, void* pCookie, XnCallbackHandle& hCallback)
05717         {
05718             XnStatus nRetVal = XN_STATUS_OK;
05719 
05720             GestureReadyForNextIntermediateStageCookie* pGestureCookie;
05721             XN_VALIDATE_ALLOC(pGestureCookie, GestureReadyForNextIntermediateStageCookie);
05722             pGestureCookie->handler = handler;
05723             pGestureCookie->pUserCookie = pCookie;
05724 
05725             nRetVal = xnRegisterToGestureReadyForNextIntermediateStage(GetHandle(), GestureReadyForNextIntermediateStageCallback, pGestureCookie, &pGestureCookie->hCallback);
05726             if (nRetVal != XN_STATUS_OK)
05727             {
05728                 xnOSFree(pGestureCookie);
05729                 return (nRetVal);
05730             }
05731 
05732             hCallback = pGestureCookie;
05733 
05734             return (XN_STATUS_OK);
05735         }
05736 
05744         inline void UnregisterFromGestureReadyForNextIntermediateStageCallbacks(XnCallbackHandle hCallback)
05745         {
05746             GestureReadyForNextIntermediateStageCookie* pGestureCookie = (GestureReadyForNextIntermediateStageCookie*)hCallback;
05747             xnUnregisterFromGestureReadyForNextIntermediateStage(GetHandle(), pGestureCookie->hCallback);
05748             xnOSFree(pGestureCookie);
05749         }
05750 
05752         inline XnStatus XN_API_DEPRECATED("Use GetAllActiveGestures() instead") GetActiveGestures(XnChar*& astrGestures, XnUInt16& nGestures) const
05753         {
05754             return xnGetActiveGestures(GetHandle(), &astrGestures, &nGestures);
05755         }
05756         inline XnStatus XN_API_DEPRECATED("Use EnumerateAllGestures() instead") EnumerateGestures(XnChar*& astrGestures, XnUInt16& nGestures) const
05757         {
05758             return xnEnumerateGestures(GetHandle(), &astrGestures, &nGestures);
05759         }
05762     private:
05763         typedef struct GestureCookie
05764         {
05765             GestureRecognized recognizedHandler;
05766             GestureProgress progressHandler;
05767             void* pUserCookie;
05768             XnCallbackHandle hCallback;
05769         } GestureCookie;
05770 
05771         static void XN_CALLBACK_TYPE GestureRecognizedCallback(XnNodeHandle hNode, const XnChar* strGesture, const XnPoint3D* pIDPosition, const XnPoint3D* pEndPosition, void* pCookie)
05772         {
05773             GestureCookie* pGestureCookie = (GestureCookie*)pCookie;
05774             GestureGenerator gen(hNode);
05775             if (pGestureCookie->recognizedHandler != NULL)
05776             {
05777                 pGestureCookie->recognizedHandler(gen, strGesture, pIDPosition, pEndPosition, pGestureCookie->pUserCookie);
05778             }
05779         }
05780 
05781         static void XN_CALLBACK_TYPE GestureProgressCallback(XnNodeHandle hNode, const XnChar* strGesture, const XnPoint3D* pPosition, XnFloat fProgress, void* pCookie)
05782         {
05783             GestureCookie* pGestureCookie = (GestureCookie*)pCookie;
05784             GestureGenerator gen(hNode);
05785             if (pGestureCookie->progressHandler != NULL)
05786             {
05787                 pGestureCookie->progressHandler(gen, strGesture, pPosition, fProgress, pGestureCookie->pUserCookie);
05788             }
05789         }
05790 
05791         typedef struct GestureIntermediateStageCompletedCookie
05792         {
05793             GestureIntermediateStageCompleted handler;
05794             void* pUserCookie;
05795             XnCallbackHandle hCallback;
05796         } GestureIntermediateStageCompletedCookie;
05797 
05798         static void XN_CALLBACK_TYPE GestureIntermediateStageCompletedCallback(XnNodeHandle hNode, const XnChar* strGesture, const XnPoint3D* pPosition, void* pCookie)
05799         {
05800             GestureIntermediateStageCompletedCookie* pGestureCookie = (GestureIntermediateStageCompletedCookie*)pCookie;
05801             GestureGenerator gen(hNode);
05802             if (pGestureCookie->handler != NULL)
05803             {
05804                 pGestureCookie->handler(gen, strGesture, pPosition, pGestureCookie->pUserCookie);
05805             }
05806         }
05807 
05808         typedef struct GestureReadyForNextIntermediateStageCookie
05809         {
05810             GestureReadyForNextIntermediateStage handler;
05811             void* pUserCookie;
05812             XnCallbackHandle hCallback;
05813         } GestureReadyForNextIntermediateStageCookie;
05814 
05815         static void XN_CALLBACK_TYPE GestureReadyForNextIntermediateStageCallback(XnNodeHandle hNode, const XnChar* strGesture, const XnPoint3D* pPosition, void* pCookie)
05816         {
05817             GestureReadyForNextIntermediateStageCookie* pGestureCookie = (GestureReadyForNextIntermediateStageCookie*)pCookie;
05818             GestureGenerator gen(hNode);
05819             if (pGestureCookie->handler != NULL)
05820             {
05821                 pGestureCookie->handler(gen, strGesture, pPosition, pGestureCookie->pUserCookie);
05822             }
05823         }
05824     };
05825 
05844     class SceneAnalyzer : public MapGenerator
05845     {
05846     public:
05852         inline SceneAnalyzer(XnNodeHandle hNode = NULL) : MapGenerator(hNode) {}
05853         inline SceneAnalyzer(const NodeWrapper& other) : MapGenerator(other) {}
05854 
05862         inline XnStatus Create(Context& context, Query* pQuery = NULL, EnumerationErrors* pErrors = NULL);
05863 
05864 
05884         inline void GetMetaData(SceneMetaData& metaData) const
05885         {
05886             xnGetSceneMetaData(GetHandle(), metaData.GetUnderlying());
05887         }
05888 
05893         inline const XnLabel* GetLabelMap() const
05894         {
05895             return xnGetLabelMap(GetHandle());
05896         }
05897 
05903         inline XnStatus GetFloor(XnPlane3D& Plane) const
05904         {
05905             return xnGetFloor(GetHandle(), &Plane);
05906         }
05907     };
05908 
05916     class HandTouchingFOVEdgeCapability : public Capability
05917     {
05918     public:
05924         inline HandTouchingFOVEdgeCapability(XnNodeHandle hNode) : Capability(hNode) {}
05925         HandTouchingFOVEdgeCapability(const NodeWrapper& node) : Capability(node) {}
05926 
05937         typedef void (XN_CALLBACK_TYPE* HandTouchingFOVEdge)(HandTouchingFOVEdgeCapability& touchingfov, XnUserID user, const XnPoint3D* pPosition, XnFloat fTime, XnDirection eDir, void* pCookie);
05938 
05948         inline XnStatus RegisterToHandTouchingFOVEdge(HandTouchingFOVEdge handler, void* pCookie, XnCallbackHandle& hCallback)
05949         {
05950             XnStatus nRetVal = XN_STATUS_OK;
05951 
05952             HandTouchingFOVEdgeCookie* pHandCookie;
05953             XN_VALIDATE_ALLOC(pHandCookie, HandTouchingFOVEdgeCookie);
05954             pHandCookie->handler = handler;
05955             pHandCookie->pUserCookie = pCookie;
05956 
05957             nRetVal = xnRegisterToHandTouchingFOVEdge(GetHandle(), HandTouchingFOVEdgeCB, pHandCookie, &pHandCookie->hCallback);
05958             if (nRetVal != XN_STATUS_OK)
05959             {
05960                 xnOSFree(pHandCookie);
05961                 return (nRetVal);
05962             }
05963 
05964             hCallback = pHandCookie;
05965 
05966             return (XN_STATUS_OK);
05967         }
05968 
05976         inline void UnregisterFromHandTouchingFOVEdge(XnCallbackHandle hCallback)
05977         {
05978             HandTouchingFOVEdgeCookie* pHandCookie = (HandTouchingFOVEdgeCookie*)hCallback;
05979             xnUnregisterFromHandTouchingFOVEdge(GetHandle(), pHandCookie->hCallback);
05980             xnOSFree(pHandCookie);
05981         }
05982     private:
05983         typedef struct HandTouchingFOVEdgeCookie
05984         {
05985             HandTouchingFOVEdge handler;
05986             void* pUserCookie;
05987             XnCallbackHandle hCallback;
05988         } HandTouchingFOVEdgeCookie;
05989 
05990         static void XN_CALLBACK_TYPE HandTouchingFOVEdgeCB(XnNodeHandle hNode, XnUserID user, const XnPoint3D* pPosition, XnFloat fTime, XnDirection eDir, void* pCookie)
05991         {
05992             HandTouchingFOVEdgeCookie* pHandCookie = (HandTouchingFOVEdgeCookie*)pCookie;
05993             HandTouchingFOVEdgeCapability cap(hNode);
05994             if (pHandCookie->handler != NULL)
05995             {
05996                 pHandCookie->handler(cap, user, pPosition, fTime, eDir, pHandCookie->pUserCookie);
05997             }
05998         }
05999 
06000     };
06001 
06089     class HandsGenerator : public Generator
06090     {
06091     public:
06097         inline HandsGenerator(XnNodeHandle hNode = NULL) : Generator(hNode) {}
06098         inline HandsGenerator(const NodeWrapper& other) : Generator(other) {}
06099 
06107         inline XnStatus Create(Context& context, Query* pQuery = NULL, EnumerationErrors* pErrors = NULL);
06108 
06124         typedef void (XN_CALLBACK_TYPE* HandCreate)(HandsGenerator& generator, XnUserID user, const XnPoint3D* pPosition, XnFloat fTime, void* pCookie);
06125 
06142         typedef void (XN_CALLBACK_TYPE* HandUpdate)(HandsGenerator& generator, XnUserID user, const XnPoint3D* pPosition, XnFloat fTime, void* pCookie);
06143 
06157         typedef void (XN_CALLBACK_TYPE* HandDestroy)(HandsGenerator& generator, XnUserID user, XnFloat fTime, void* pCookie);
06158 
06171         inline XnStatus RegisterHandCallbacks(HandCreate CreateCB, HandUpdate UpdateCB, HandDestroy DestroyCB, void* pCookie, XnCallbackHandle& hCallback)
06172         {
06173             XnStatus nRetVal = XN_STATUS_OK;
06174 
06175             HandCookie* pHandCookie;
06176             XN_VALIDATE_ALLOC(pHandCookie, HandCookie);
06177             pHandCookie->createHandler = CreateCB;
06178             pHandCookie->updateHandler = UpdateCB;
06179             pHandCookie->destroyHandler = DestroyCB;
06180             pHandCookie->pUserCookie = pCookie;
06181 
06182             nRetVal = xnRegisterHandCallbacks(GetHandle(), HandCreateCB, HandUpdateCB, HandDestroyCB, pHandCookie, &pHandCookie->hCallback);
06183             if (nRetVal != XN_STATUS_OK)
06184             {
06185                 xnOSFree(pHandCookie);
06186                 return (nRetVal);
06187             }
06188 
06189             hCallback = pHandCookie;
06190 
06191             return (XN_STATUS_OK);
06192         }
06193 
06201         inline void UnregisterHandCallbacks(XnCallbackHandle hCallback)
06202         {
06203             HandCookie* pHandCookie = (HandCookie*)hCallback;
06204             xnUnregisterHandCallbacks(GetHandle(), pHandCookie->hCallback);
06205             xnOSFree(pHandCookie);
06206         }
06207 
06221         inline XnStatus StopTracking(XnUserID user)
06222         {
06223             return xnStopTracking(GetHandle(), user);
06224         }
06225 
06234         inline XnStatus StopTrackingAll()
06235         {
06236             return xnStopTrackingAll(GetHandle());
06237         }
06238 
06255         inline XnStatus StartTracking(const XnPoint3D& ptPosition)
06256         {
06257             return xnStartTracking(GetHandle(), &ptPosition);
06258         }
06259 
06276         inline XnStatus SetSmoothing(XnFloat fSmoothingFactor)
06277         {
06278             return xnSetTrackingSmoothing(GetHandle(), fSmoothingFactor);
06279         }
06280 
06288         inline const HandTouchingFOVEdgeCapability GetHandTouchingFOVEdgeCap() const
06289         {
06290             return HandTouchingFOVEdgeCapability(GetHandle());
06291         }
06292 
06300         inline HandTouchingFOVEdgeCapability GetHandTouchingFOVEdgeCap()
06301         {
06302             return HandTouchingFOVEdgeCapability(GetHandle());
06303         }
06304 
06305     private:
06306         typedef struct HandCookie
06307         {
06308             HandCreate createHandler;
06309             HandUpdate updateHandler;
06310             HandDestroy destroyHandler;
06311             void* pUserCookie;
06312             XnCallbackHandle hCallback;
06313         } HandCookie;
06314 
06315         static void XN_CALLBACK_TYPE HandCreateCB(XnNodeHandle hNode, XnUserID user, const XnPoint3D* pPosition, XnFloat fTime, void* pCookie)
06316         {
06317             HandCookie* pHandCookie = (HandCookie*)pCookie;
06318             HandsGenerator gen(hNode);
06319             if (pHandCookie->createHandler != NULL)
06320             {
06321                 pHandCookie->createHandler(gen, user, pPosition, fTime, pHandCookie->pUserCookie);
06322             }
06323         }
06324         static void XN_CALLBACK_TYPE HandUpdateCB(XnNodeHandle hNode, XnUserID user, const XnPoint3D* pPosition, XnFloat fTime, void* pCookie)
06325         {
06326             HandCookie* pHandCookie = (HandCookie*)pCookie;
06327             HandsGenerator gen(hNode);
06328             if (pHandCookie->updateHandler != NULL)
06329             {
06330                 pHandCookie->updateHandler(gen, user, pPosition, fTime, pHandCookie->pUserCookie);
06331             }
06332         }
06333         static void XN_CALLBACK_TYPE HandDestroyCB(XnNodeHandle hNode, XnUserID user, XnFloat fTime, void* pCookie)
06334         {
06335             HandCookie* pHandCookie = (HandCookie*)pCookie;
06336             HandsGenerator gen(hNode);
06337             if (pHandCookie->destroyHandler != NULL)
06338             {
06339                 pHandCookie->destroyHandler(gen, user, fTime, pHandCookie->pUserCookie);
06340             }
06341         }
06342     };
06343 
06400     class SkeletonCapability : public Capability
06401     {
06402     public:
06408         inline SkeletonCapability(XnNodeHandle hNode) : Capability(hNode) {}
06409         SkeletonCapability(const NodeWrapper& node) : Capability(node) {}
06410 
06416         inline XnBool IsJointAvailable(XnSkeletonJoint eJoint) const
06417         {
06418             return xnIsJointAvailable(GetHandle(), eJoint);
06419         }
06420 
06426         inline XnBool IsProfileAvailable(XnSkeletonProfile eProfile) const
06427         {
06428             return xnIsProfileAvailable(GetHandle(), eProfile);
06429         }
06430 
06461         inline XnStatus SetSkeletonProfile(XnSkeletonProfile eProfile)
06462         {
06463             return xnSetSkeletonProfile(GetHandle(), eProfile);
06464         }
06465 
06489         inline XnStatus SetJointActive(XnSkeletonJoint eJoint, XnBool bState)
06490         {
06491             return xnSetJointActive(GetHandle(), eJoint, bState);
06492         }
06493 
06499         inline XnBool IsJointActive(XnSkeletonJoint eJoint) const
06500         {
06501             return xnIsJointActive(GetHandle(), eJoint);
06502         }
06503 
06513         inline XnStatus RegisterToJointConfigurationChange(StateChangedHandler handler, void* pCookie, XnCallbackHandle& hCallback)
06514         {
06515             return _RegisterToStateChange(xnRegisterToJointConfigurationChange, GetHandle(), handler, pCookie, hCallback);
06516         }
06517 
06525         inline void UnregisterFromJointConfigurationChange(XnCallbackHandle hCallback)
06526         {
06527             _UnregisterFromStateChange(xnUnregisterFromJointConfigurationChange, GetHandle(), hCallback);
06528         }
06529 
06534         inline XnStatus EnumerateActiveJoints(XnSkeletonJoint* pJoints, XnUInt16& nJoints) const
06535         {
06536             return xnEnumerateActiveJoints(GetHandle(), pJoints, &nJoints);
06537         }
06538 
06547         inline XnStatus GetSkeletonJoint(XnUserID user, XnSkeletonJoint eJoint, XnSkeletonJointTransformation& Joint) const
06548         {
06549             return xnGetSkeletonJoint(GetHandle(), user, eJoint, &Joint);
06550         }
06551 
06573         inline XnStatus GetSkeletonJointPosition(XnUserID user, XnSkeletonJoint eJoint, XnSkeletonJointPosition& Joint) const
06574         {
06575             return xnGetSkeletonJointPosition(GetHandle(), user, eJoint, &Joint);
06576         }
06577 
06585         inline XnStatus GetSkeletonJointOrientation(XnUserID user, XnSkeletonJoint eJoint, XnSkeletonJointOrientation& Joint) const
06586         {
06587             return xnGetSkeletonJointOrientation(GetHandle(), user, eJoint, &Joint);
06588         }
06589 
06600         inline XnBool IsTracking(XnUserID user) const
06601         {
06602             return xnIsSkeletonTracking(GetHandle(), user);
06603         }
06604 
06615         inline XnBool IsCalibrated(XnUserID user) const
06616         {
06617             return xnIsSkeletonCalibrated(GetHandle(), user);
06618         }
06619 
06630         inline XnBool IsCalibrating(XnUserID user) const
06631         {
06632             return xnIsSkeletonCalibrating(GetHandle(), user);
06633         }
06634 
06659         inline XnStatus RequestCalibration(XnUserID user, XnBool bForce)
06660         {
06661             return xnRequestSkeletonCalibration(GetHandle(), user, bForce);
06662         }
06663 
06673         inline XnStatus AbortCalibration(XnUserID user)
06674         {
06675             return xnAbortSkeletonCalibration(GetHandle(), user);
06676         }
06677 
06696         inline XnStatus SaveCalibrationDataToFile(XnUserID user, const XnChar* strFileName)
06697         {
06698             return xnSaveSkeletonCalibrationDataToFile(GetHandle(), user, strFileName);
06699         }
06700 
06707         inline XnStatus LoadCalibrationDataFromFile(XnUserID user, const XnChar* strFileName)
06708         {
06709             return xnLoadSkeletonCalibrationDataFromFile(GetHandle(), user, strFileName);
06710         }
06711 
06723         inline XnStatus SaveCalibrationData(XnUserID user, XnUInt32 nSlot)
06724         {
06725             return xnSaveSkeletonCalibrationData(GetHandle(), user, nSlot);
06726         }
06727 
06734         inline XnStatus LoadCalibrationData(XnUserID user, XnUInt32 nSlot)
06735         {
06736             return xnLoadSkeletonCalibrationData(GetHandle(), user, nSlot);
06737         }
06738 
06744         inline XnStatus ClearCalibrationData(XnUInt32 nSlot)
06745         {
06746             return xnClearSkeletonCalibrationData(GetHandle(), nSlot);
06747         }
06748 
06754         inline XnBool IsCalibrationData(XnUInt32 nSlot) const
06755         {
06756             return xnIsSkeletonCalibrationData(GetHandle(), nSlot);
06757         }
06758 
06773         inline XnStatus StartTracking(XnUserID user)
06774         {
06775             return xnStartSkeletonTracking(GetHandle(), user);
06776         }
06777 
06782         inline XnStatus StopTracking(XnUserID user)
06783         {
06784             return xnStopSkeletonTracking(GetHandle(), user);
06785         }
06786 
06795         inline XnStatus Reset(XnUserID user)
06796         {
06797             return xnResetSkeleton(GetHandle(), user);
06798         }
06799 
06808         inline XnBool NeedPoseForCalibration() const
06809         {
06810             return xnNeedPoseForSkeletonCalibration(GetHandle());
06811         }
06812 
06825         inline XnStatus GetCalibrationPose(XnChar* strPose) const
06826         {
06827             return xnGetSkeletonCalibrationPose(GetHandle(), strPose);
06828         }
06829 
06842         inline XnStatus SetSmoothing(XnFloat fSmoothingFactor)
06843         {
06844             return xnSetSkeletonSmoothing(GetHandle(), fSmoothingFactor);
06845         }
06846 
06868         typedef void (XN_CALLBACK_TYPE* CalibrationStart)(SkeletonCapability& skeleton, XnUserID user, void* pCookie);
06869 
06887         typedef void (XN_CALLBACK_TYPE* CalibrationEnd)(SkeletonCapability& skeleton, XnUserID user, XnBool bSuccess, void* pCookie);
06888 
06900         inline XnStatus RegisterToCalibrationStart(CalibrationStart handler, void* pCookie, XnCallbackHandle& hCallback)
06901         {
06902             XnStatus nRetVal = XN_STATUS_OK;
06903             CalibrationStartCookie* pCalibrationCookie;
06904             XN_VALIDATE_ALLOC(pCalibrationCookie, CalibrationStartCookie);
06905             pCalibrationCookie->handler = handler;
06906             pCalibrationCookie->pUserCookie = pCookie;
06907             nRetVal = xnRegisterToCalibrationStart(GetHandle(), CalibrationStartCallback, pCalibrationCookie, &pCalibrationCookie->hCallback);
06908             if (nRetVal != XN_STATUS_OK)
06909             {
06910                 xnOSFree(pCalibrationCookie);
06911                 return nRetVal;
06912             }
06913             hCallback = pCalibrationCookie;
06914             return XN_STATUS_OK;
06915         }
06916 
06927         inline XnStatus UnregisterFromCalibrationStart(XnCallbackHandle hCallback)
06928         {
06929             CalibrationStartCookie* pCalibrationCookie = (CalibrationStartCookie*)hCallback;
06930             xnUnregisterFromCalibrationStart(GetHandle(), pCalibrationCookie->hCallback);
06931             xnOSFree(pCalibrationCookie);
06932             return XN_STATUS_OK;
06933         }
06934 
06956         typedef void (XN_CALLBACK_TYPE* CalibrationInProgress)(SkeletonCapability& skeleton, XnUserID user, XnCalibrationStatus calibrationError, void* pCookie);
06957 
06967         inline XnStatus RegisterToCalibrationInProgress(CalibrationInProgress handler, void* pCookie, XnCallbackHandle& hCallback)
06968         {
06969             XnStatus nRetVal = XN_STATUS_OK;
06970 
06971             CalibrationInProgressCookie* pSkeletonCookie;
06972             XN_VALIDATE_ALLOC(pSkeletonCookie, CalibrationInProgressCookie);
06973             pSkeletonCookie->handler = handler;
06974             pSkeletonCookie->pUserCookie = pCookie;
06975 
06976             nRetVal = xnRegisterToCalibrationInProgress(GetHandle(), CalibrationInProgressCallback, pSkeletonCookie, &pSkeletonCookie->hCallback);
06977             if (nRetVal != XN_STATUS_OK)
06978             {
06979                 xnOSFree(pSkeletonCookie);
06980                 return (nRetVal);
06981             }
06982 
06983             hCallback = pSkeletonCookie;
06984 
06985             return (XN_STATUS_OK);
06986         }
06987 
06995         inline void UnregisterFromCalibrationInProgress(XnCallbackHandle hCallback)
06996         {
06997             CalibrationInProgressCookie* pSkeletonCookie = (CalibrationInProgressCookie*)hCallback;
06998             xnUnregisterFromCalibrationInProgress(GetHandle(), pSkeletonCookie->hCallback);
06999             xnOSFree(pSkeletonCookie);
07000         }
07001 
07019         typedef void (XN_CALLBACK_TYPE* CalibrationComplete)(SkeletonCapability& skeleton, XnUserID user, XnCalibrationStatus calibrationError, void* pCookie);
07020 
07030         inline XnStatus RegisterToCalibrationComplete(CalibrationComplete handler, void* pCookie, XnCallbackHandle& hCallback)
07031         {
07032             XnStatus nRetVal = XN_STATUS_OK;
07033 
07034             CalibrationCompleteCookie* pSkeletonCookie;
07035             XN_VALIDATE_ALLOC(pSkeletonCookie, CalibrationCompleteCookie);
07036             pSkeletonCookie->handler = handler;
07037             pSkeletonCookie->pUserCookie = pCookie;
07038 
07039             nRetVal = xnRegisterToCalibrationComplete(GetHandle(), CalibrationCompleteCallback, pSkeletonCookie, &pSkeletonCookie->hCallback);
07040             if (nRetVal != XN_STATUS_OK)
07041             {
07042                 xnOSFree(pSkeletonCookie);
07043                 return (nRetVal);
07044             }
07045 
07046             hCallback = pSkeletonCookie;
07047 
07048             return (XN_STATUS_OK);
07049         }
07050 
07058         inline void UnregisterFromCalibrationComplete(XnCallbackHandle hCallback)
07059         {
07060             CalibrationCompleteCookie* pSkeletonCookie = (CalibrationCompleteCookie*)hCallback;
07061             xnUnregisterFromCalibrationComplete(GetHandle(), pSkeletonCookie->hCallback);
07062             xnOSFree(pSkeletonCookie);
07063         }
07064 
07066         XN_API_DEPRECATED("Use the overload with one argument - the bState parameter is useless")
07067         inline XnBool IsJointActive(XnSkeletonJoint eJoint, XnBool /*bState*/) const
07068         {
07069             return xnIsJointActive(GetHandle(), eJoint);
07070         }
07071 
07072         inline XnStatus XN_API_DEPRECATED("Please use RegisterToCalibrationStart/Complete") RegisterCalibrationCallbacks(CalibrationStart CalibrationStartCB, CalibrationEnd CalibrationEndCB, void* pCookie, XnCallbackHandle& hCallback)
07073         {
07074             XnStatus nRetVal = XN_STATUS_OK;
07075 
07076             SkeletonCookie* pSkeletonCookie;
07077             XN_VALIDATE_ALLOC(pSkeletonCookie, SkeletonCookie);
07078             pSkeletonCookie->startHandler = CalibrationStartCB;
07079             pSkeletonCookie->endHandler = CalibrationEndCB;
07080             pSkeletonCookie->pUserCookie = pCookie;
07081 
07082 #pragma warning (push)
07083 #pragma warning (disable: XN_DEPRECATED_WARNING_IDS)
07084             nRetVal = xnRegisterCalibrationCallbacks(GetHandle(), CalibrationStartBundleCallback, CalibrationEndBundleCallback, pSkeletonCookie, &pSkeletonCookie->hCallback);
07085 #pragma warning (pop)
07086             if (nRetVal != XN_STATUS_OK)
07087             {
07088                 xnOSFree(pSkeletonCookie);
07089                 return (nRetVal);
07090             }
07091 
07092             hCallback = pSkeletonCookie;
07093 
07094             return (XN_STATUS_OK);
07095         }
07096 
07097         inline void XN_API_DEPRECATED("Please use UnregisterFromCalibrationStart/Complete") UnregisterCalibrationCallbacks(XnCallbackHandle hCallback)
07098         {
07099             SkeletonCookie* pSkeletonCookie = (SkeletonCookie*)hCallback;
07100 #pragma warning (push)
07101 #pragma warning (disable: XN_DEPRECATED_WARNING_IDS)
07102             xnUnregisterCalibrationCallbacks(GetHandle(), pSkeletonCookie->hCallback);
07103 #pragma warning (pop)
07104             xnOSFree(pSkeletonCookie);
07105         }
07108 private:
07109         typedef struct SkeletonCookie
07110         {
07111             CalibrationStart startHandler;
07112             CalibrationEnd endHandler;
07113             void* pUserCookie;
07114             XnCallbackHandle hCallback;
07115         } SkeletonCookie;
07116 
07117         static void XN_CALLBACK_TYPE CalibrationStartBundleCallback(XnNodeHandle hNode, XnUserID user, void* pCookie)
07118         {
07119             SkeletonCookie* pSkeletonCookie = (SkeletonCookie*)pCookie;
07120             SkeletonCapability cap(hNode);
07121             if (pSkeletonCookie->startHandler != NULL)
07122             {
07123                 pSkeletonCookie->startHandler(cap, user, pSkeletonCookie->pUserCookie);
07124             }
07125         }
07126 
07127         static void XN_CALLBACK_TYPE CalibrationEndBundleCallback(XnNodeHandle hNode, XnUserID user, XnBool bSuccess, void* pCookie)
07128         {
07129             SkeletonCookie* pSkeletonCookie = (SkeletonCookie*)pCookie;
07130             SkeletonCapability cap(hNode);
07131             if (pSkeletonCookie->endHandler != NULL)
07132             {
07133                 pSkeletonCookie->endHandler(cap, user, bSuccess, pSkeletonCookie->pUserCookie);
07134             }
07135         }
07136 
07137         typedef struct CalibrationStartCookie
07138         {
07139             CalibrationStart handler;
07140             void* pUserCookie;
07141             XnCallbackHandle hCallback;
07142         } CalibrationStartCookie;
07143 
07144         static void XN_CALLBACK_TYPE CalibrationStartCallback(XnNodeHandle hNode, XnUserID user, void* pCookie)
07145         {
07146             CalibrationStartCookie* pCalibrationCookie = (CalibrationStartCookie*)pCookie;
07147             SkeletonCapability cap(hNode);
07148             if (pCalibrationCookie->handler != NULL)
07149             {
07150                 pCalibrationCookie->handler(cap, user, pCalibrationCookie->pUserCookie);
07151             }
07152         }
07153 
07154         typedef struct CalibrationInProgressCookie
07155         {
07156             CalibrationInProgress handler;
07157             void* pUserCookie;
07158             XnCallbackHandle hCallback;
07159         } CalibrationInProgressCookie;
07160 
07161         static void XN_CALLBACK_TYPE CalibrationInProgressCallback(XnNodeHandle hNode, XnUserID user, XnCalibrationStatus calibrationError, void* pCookie)
07162         {
07163             CalibrationInProgressCookie* pSkeletonCookie = (CalibrationInProgressCookie*)pCookie;
07164             SkeletonCapability cap(hNode);
07165             if (pSkeletonCookie->handler != NULL)
07166             {
07167                 pSkeletonCookie->handler(cap, user, calibrationError, pSkeletonCookie->pUserCookie);
07168             }
07169         }
07170 
07171         typedef struct CalibrationCompleteCookie
07172         {
07173             CalibrationComplete handler;
07174             void* pUserCookie;
07175             XnCallbackHandle hCallback;
07176         } CalibrationCompleteCookie;
07177 
07178         static void XN_CALLBACK_TYPE CalibrationCompleteCallback(XnNodeHandle hNode, XnUserID user, XnCalibrationStatus calibrationError, void* pCookie)
07179         {
07180             CalibrationCompleteCookie* pSkeletonCookie = (CalibrationCompleteCookie*)pCookie;
07181             SkeletonCapability cap(hNode);
07182             if (pSkeletonCookie->handler != NULL)
07183             {
07184                 pSkeletonCookie->handler(cap, user, calibrationError, pSkeletonCookie->pUserCookie);
07185             }
07186         }
07187     };
07188 
07210     class PoseDetectionCapability : public Capability
07211     {
07212     public:
07218         inline PoseDetectionCapability(XnNodeHandle hNode) : Capability(hNode) {}
07219         PoseDetectionCapability(const NodeWrapper& node) : Capability(node) {}
07220 
07234         typedef void (XN_CALLBACK_TYPE* PoseDetection)(PoseDetectionCapability& pose, const XnChar* strPose, XnUserID user, void* pCookie);
07235 
07245         inline XnUInt32 GetNumberOfPoses() const
07246         {
07247             return xnGetNumberOfPoses(GetHandle());
07248         }
07249 
07262         inline XnStatus GetAllAvailablePoses(XnChar** pstrPoses, XnUInt32 nNameLength, XnUInt32& nPoses) const
07263         {
07264             return xnGetAllAvailablePoses(GetHandle(), pstrPoses, nNameLength, &nPoses);
07265         }
07266 
07267         inline XnBool IsPoseSupported(const XnChar* strPose)
07268         {
07269             return xnIsPoseSupported(GetHandle(), strPose);
07270         }
07271 
07272         inline XnStatus GetPoseStatus(XnUserID userID, const XnChar* poseName, XnUInt64& poseTime, XnPoseDetectionStatus& eStatus, XnPoseDetectionState& eState)
07273         {
07274             return xnGetPoseStatus(GetHandle(), userID, poseName, &poseTime, &eStatus, &eState);
07275         }
07276 
07292         inline XnStatus StartPoseDetection(const XnChar* strPose, XnUserID user)
07293         {
07294             return xnStartPoseDetection(GetHandle(), strPose, user);
07295         }
07296 
07308         inline XnStatus StopPoseDetection(XnUserID user)
07309         {
07310             return xnStopPoseDetection(GetHandle(), user);
07311         }
07312 
07316         inline XnStatus StopSinglePoseDetection(XnUserID user, const XnChar* strPose)
07317         {
07318             return xnStopSinglePoseDetection(GetHandle(), user, strPose);
07319         }
07320 
07330         inline XnStatus RegisterToPoseDetected(PoseDetection handler, void* pCookie, XnCallbackHandle& hCallback)
07331         {
07332             XnStatus nRetVal = XN_STATUS_OK;
07333             PoseDetectionCookie* pPoseCookie;
07334             XN_VALIDATE_ALLOC(pPoseCookie, PoseDetectionCookie);
07335             pPoseCookie->handler = handler;
07336             pPoseCookie->pPoseCookie = pCookie;
07337 
07338             nRetVal = xnRegisterToPoseDetected(GetHandle(), PoseDetectionCallback, pPoseCookie, &pPoseCookie->hCallback);
07339             if (nRetVal != XN_STATUS_OK)
07340             {
07341                 xnOSFree(pPoseCookie);
07342                 return nRetVal;
07343             }
07344             hCallback = pPoseCookie;
07345             return XN_STATUS_OK;
07346         }
07347 
07357         inline XnStatus RegisterToOutOfPose(PoseDetection handler, void* pCookie, XnCallbackHandle& hCallback)
07358         {
07359             XnStatus nRetVal = XN_STATUS_OK;
07360             PoseDetectionCookie* pPoseCookie;
07361             XN_VALIDATE_ALLOC(pPoseCookie, PoseDetectionCookie);
07362             pPoseCookie->handler = handler;
07363             pPoseCookie->pPoseCookie = pCookie;
07364 
07365             nRetVal = xnRegisterToOutOfPose(GetHandle(), PoseDetectionCallback, pPoseCookie, &pPoseCookie->hCallback);
07366             if (nRetVal != XN_STATUS_OK)
07367             {
07368                 xnOSFree(pPoseCookie);
07369                 return nRetVal;
07370             }
07371             hCallback = pPoseCookie;
07372             return XN_STATUS_OK;
07373         }
07381         inline void UnregisterFromPoseDetected(XnCallbackHandle hCallback)
07382         {
07383             PoseDetectionCookie* pPoseCookie = (PoseDetectionCookie*)hCallback;
07384             xnUnregisterFromPoseDetected(GetHandle(), pPoseCookie->hCallback);
07385             xnOSFree(pPoseCookie);
07386         }
07394         inline void UnregisterFromOutOfPose(XnCallbackHandle hCallback)
07395         {
07396             PoseDetectionCookie* pPoseCookie = (PoseDetectionCookie*)hCallback;
07397             xnUnregisterFromOutOfPose(GetHandle(), pPoseCookie->hCallback);
07398             xnOSFree(pPoseCookie);
07399         }
07400 
07423         typedef void (XN_CALLBACK_TYPE* PoseInProgress)(PoseDetectionCapability& pose, const XnChar* strPose, XnUserID user, XnPoseDetectionStatus poseError, void* pCookie);
07424 
07441         inline XnStatus RegisterToPoseInProgress(PoseInProgress handler, void* pCookie, XnCallbackHandle& hCallback)
07442         {
07443             XnStatus nRetVal = XN_STATUS_OK;
07444 
07445             PoseInProgressCookie* pPoseCookie;
07446             XN_VALIDATE_ALLOC(pPoseCookie, PoseInProgressCookie);
07447             pPoseCookie->handler = handler;
07448             pPoseCookie->pPoseCookie = pCookie;
07449 
07450             nRetVal = xnRegisterToPoseDetectionInProgress(GetHandle(), PoseDetectionInProgressCallback, pPoseCookie, &pPoseCookie->hCallback);
07451             if (nRetVal != XN_STATUS_OK)
07452             {
07453                 xnOSFree(pPoseCookie);
07454                 return (nRetVal);
07455             }
07456 
07457             hCallback = pPoseCookie;
07458 
07459             return (XN_STATUS_OK);
07460         }
07461 
07469         inline void UnregisterFromPoseInProgress(XnCallbackHandle hCallback)
07470         {
07471             PoseInProgressCookie* pPoseCookie = (PoseInProgressCookie*)hCallback;
07472             xnUnregisterFromPoseDetectionInProgress(GetHandle(), pPoseCookie->hCallback);
07473             xnOSFree(pPoseCookie);
07474         }
07475 
07477         inline XnStatus XN_API_DEPRECATED("Use GetAllAvailablePoses() instead") GetAvailablePoses(XnChar** pstrPoses, XnUInt32& nPoses) const
07478         {
07479             return xnGetAvailablePoses(GetHandle(), pstrPoses, &nPoses);
07480         }
07481 
07482         inline XnStatus XN_API_DEPRECATED("Please use RegisterToPoseDetected/RegisterToOutOfPose instead") RegisterToPoseCallbacks(PoseDetection PoseStartCB, PoseDetection PoseEndCB, void* pCookie, XnCallbackHandle& hCallback)
07483         {
07484             XnStatus nRetVal = XN_STATUS_OK;
07485 
07486             PoseCookie* pPoseCookie;
07487             XN_VALIDATE_ALLOC(pPoseCookie, PoseCookie);
07488             pPoseCookie->startHandler = PoseStartCB;
07489             pPoseCookie->endHandler = PoseEndCB;
07490             pPoseCookie->pPoseCookie = pCookie;
07491 
07492 #pragma warning (push)
07493 #pragma warning (disable: XN_DEPRECATED_WARNING_IDS)
07494             nRetVal = xnRegisterToPoseCallbacks(GetHandle(), PoseDetectionStartBundleCallback, PoseDetectionStartEndBundleCallback, pPoseCookie, &pPoseCookie->hCallback);
07495 #pragma warning (pop)
07496             if (nRetVal != XN_STATUS_OK)
07497             {
07498                 xnOSFree(pPoseCookie);
07499                 return (nRetVal);
07500             }
07501 
07502             hCallback = pPoseCookie;
07503 
07504             return (XN_STATUS_OK);
07505         }
07506 
07507         inline void XN_API_DEPRECATED("Please use UnregisterFromPoseDetected/UnregisterFromOutOfPose instead") UnregisterFromPoseCallbacks(XnCallbackHandle hCallback)
07508         {
07509             PoseCookie* pPoseCookie = (PoseCookie*)hCallback;
07510 #pragma warning (push)
07511 #pragma warning (disable: XN_DEPRECATED_WARNING_IDS)
07512             xnUnregisterFromPoseCallbacks(GetHandle(), pPoseCookie->hCallback);
07513 #pragma warning (pop)
07514             xnOSFree(pPoseCookie);
07515         }
07518 private:
07519         typedef struct PoseCookie
07520         {
07521             PoseDetection startHandler;
07522             PoseDetection endHandler;
07523             void* pPoseCookie;
07524             XnCallbackHandle hCallback;
07525         } PoseCookie;
07526 
07527         static void XN_CALLBACK_TYPE PoseDetectionStartBundleCallback(XnNodeHandle hNode, const XnChar* strPose, XnUserID user, void* pCookie)
07528         {
07529             PoseCookie* pPoseCookie = (PoseCookie*)pCookie;
07530             PoseDetectionCapability cap(hNode);
07531             if (pPoseCookie->startHandler != NULL)
07532             {
07533                 pPoseCookie->startHandler(cap, strPose, user, pPoseCookie->pPoseCookie);
07534             }
07535         }
07536 
07537         static void XN_CALLBACK_TYPE PoseDetectionStartEndBundleCallback(XnNodeHandle hNode, const XnChar* strPose, XnUserID user, void* pCookie)
07538         {
07539             PoseCookie* pPoseCookie = (PoseCookie*)pCookie;
07540             PoseDetectionCapability cap(hNode);
07541             if (pPoseCookie->endHandler != NULL)
07542             {
07543                 pPoseCookie->endHandler(cap, strPose, user, pPoseCookie->pPoseCookie);
07544             }
07545         }
07546         typedef struct PoseDetectionCookie
07547         {
07548             PoseDetection handler;
07549             void* pPoseCookie;
07550             XnCallbackHandle hCallback;
07551         } PoseDetectionCookie;
07552         static void XN_CALLBACK_TYPE PoseDetectionCallback(XnNodeHandle hNode, const XnChar* strPose, XnUserID user, void* pCookie)
07553         {
07554             PoseDetectionCookie* pPoseDetectionCookie = (PoseDetectionCookie*)pCookie;
07555             PoseDetectionCapability cap(hNode);
07556             if (pPoseDetectionCookie->handler != NULL)
07557             {
07558                 pPoseDetectionCookie->handler(cap, strPose, user, pPoseDetectionCookie->pPoseCookie);
07559             }
07560         }
07561 
07562         typedef struct PoseInProgressCookie
07563         {
07564             PoseInProgress handler;
07565             void* pPoseCookie;
07566             XnCallbackHandle hCallback;
07567         } PoseInProgressCookie;
07568 
07569         static void XN_CALLBACK_TYPE PoseDetectionInProgressCallback(XnNodeHandle hNode, const XnChar* strPose, XnUserID user, XnPoseDetectionStatus poseErrors, void* pCookie)
07570         {
07571             PoseInProgressCookie* pPoseCookie = (PoseInProgressCookie*)pCookie;
07572             PoseDetectionCapability cap(hNode);
07573             if (pPoseCookie->handler != NULL)
07574             {
07575                 pPoseCookie->handler(cap, strPose, user, poseErrors, pPoseCookie->pPoseCookie);
07576             }
07577         }
07578     };
07579 
07691     class UserGenerator : public Generator
07692     {
07693     public:
07699         inline UserGenerator(XnNodeHandle hNode = NULL) : Generator(hNode) {}
07700         inline UserGenerator(const NodeWrapper& other) : Generator(other) {}
07701 
07709         inline XnStatus Create(Context& context, Query* pQuery = NULL, EnumerationErrors* pErrors = NULL);
07710 
07723         typedef void (XN_CALLBACK_TYPE* UserHandler)(UserGenerator& generator, XnUserID user, void* pCookie);
07724 
07732         inline XnUInt16 GetNumberOfUsers() const
07733         {
07734             return xnGetNumberOfUsers(GetHandle());
07735         }
07736 
07759         inline XnStatus GetUsers(XnUserID aUsers[], XnUInt16& nUsers) const
07760         {
07761             return xnGetUsers(GetHandle(), aUsers, &nUsers);
07762         }
07763 
07783         inline XnStatus GetCoM(XnUserID user, XnPoint3D& com) const
07784         {
07785             return xnGetUserCoM(GetHandle(), user, &com);
07786         }
07787 
07803         inline XnStatus GetUserPixels(XnUserID user, SceneMetaData& smd) const
07804         {
07805             return xnGetUserPixels(GetHandle(), user, smd.GetUnderlying());
07806         }
07807 
07818         inline XnStatus RegisterUserCallbacks(UserHandler NewUserCB, UserHandler LostUserCB, void* pCookie, XnCallbackHandle& hCallback)
07819         {
07820             XnStatus nRetVal = XN_STATUS_OK;
07821 
07822             UserCookie* pUserCookie;
07823             XN_VALIDATE_ALLOC(pUserCookie, UserCookie);
07824             pUserCookie->newHandler = NewUserCB;
07825             pUserCookie->lostHandler = LostUserCB;
07826             pUserCookie->pUserCookie = pCookie;
07827 
07828             nRetVal = xnRegisterUserCallbacks(GetHandle(), NewUserCallback, LostUserCallback, pUserCookie, &pUserCookie->hCallback);
07829             if (nRetVal != XN_STATUS_OK)
07830             {
07831                 xnOSFree(pUserCookie);
07832                 return (nRetVal);
07833             }
07834 
07835             hCallback = pUserCookie;
07836 
07837             return (XN_STATUS_OK);
07838         }
07839 
07847         inline void UnregisterUserCallbacks(XnCallbackHandle hCallback)
07848         {
07849             UserCookie* pUserCookie = (UserCookie*)hCallback;
07850             xnUnregisterUserCallbacks(GetHandle(), pUserCookie->hCallback);
07851             xnOSFree(pUserCookie);
07852         }
07853 
07865         inline const SkeletonCapability GetSkeletonCap() const
07866         {
07867             return SkeletonCapability(GetHandle());
07868         }
07869 
07881         inline SkeletonCapability GetSkeletonCap()
07882         {
07883             return SkeletonCapability(GetHandle());
07884         }
07885 
07896         inline const PoseDetectionCapability GetPoseDetectionCap() const
07897         {
07898             return PoseDetectionCapability(GetHandle());
07899         }
07900 
07911         inline PoseDetectionCapability GetPoseDetectionCap()
07912         {
07913             return PoseDetectionCapability(GetHandle());
07914         }
07915 
07925         inline XnStatus RegisterToUserExit(UserHandler handler, void* pCookie, XnCallbackHandle& hCallback)
07926         {
07927             XnStatus nRetVal = XN_STATUS_OK;
07928 
07929             UserSingleCookie* pUserCookie;
07930             XN_VALIDATE_ALLOC(pUserCookie, UserSingleCookie);
07931             pUserCookie->handler = handler;
07932             pUserCookie->pUserCookie = pCookie;
07933 
07934             nRetVal = xnRegisterToUserExit(GetHandle(), UserSingleCallback, pUserCookie, &pUserCookie->hCallback);
07935             if (nRetVal != XN_STATUS_OK)
07936             {
07937                 xnOSFree(pUserCookie);
07938                 return (nRetVal);
07939             }
07940 
07941             hCallback = pUserCookie;
07942 
07943             return (XN_STATUS_OK);
07944         }
07945 
07953         inline void UnregisterFromUserExit(XnCallbackHandle hCallback)
07954         {
07955             UserSingleCookie* pUserCookie = (UserSingleCookie*)hCallback;
07956             xnUnregisterFromUserExit(GetHandle(), pUserCookie->hCallback);
07957             xnOSFree(pUserCookie);
07958         }
07959 
07969         inline XnStatus RegisterToUserReEnter(UserHandler handler, void* pCookie, XnCallbackHandle& hCallback)
07970         {
07971             XnStatus nRetVal = XN_STATUS_OK;
07972 
07973             UserSingleCookie* pUserCookie;
07974             XN_VALIDATE_ALLOC(pUserCookie, UserSingleCookie);
07975             pUserCookie->handler = handler;
07976             pUserCookie->pUserCookie = pCookie;
07977 
07978             nRetVal = xnRegisterToUserReEnter(GetHandle(), UserSingleCallback, pUserCookie, &pUserCookie->hCallback);
07979             if (nRetVal != XN_STATUS_OK)
07980             {
07981                 xnOSFree(pUserCookie);
07982                 return (nRetVal);
07983             }
07984 
07985             hCallback = pUserCookie;
07986 
07987             return (XN_STATUS_OK);
07988         }
07989 
07997         inline void UnregisterFromUserReEnter(XnCallbackHandle hCallback)
07998         {
07999             UserSingleCookie* pUserCookie = (UserSingleCookie*)hCallback;
08000             xnUnregisterFromUserReEnter(GetHandle(), pUserCookie->hCallback);
08001             xnOSFree(pUserCookie);
08002         }
08003 
08004     private:
08005         typedef struct UserCookie
08006         {
08007             UserHandler newHandler;
08008             UserHandler lostHandler;
08009             void* pUserCookie;
08010             XnCallbackHandle hCallback;
08011         } UserCookie;
08012 
08013         static void XN_CALLBACK_TYPE NewUserCallback(XnNodeHandle hNode, XnUserID user, void* pCookie)
08014         {
08015             UserCookie* pUserCookie = (UserCookie*)pCookie;
08016             UserGenerator gen(hNode);
08017             if (pUserCookie->newHandler != NULL)
08018             {
08019                 pUserCookie->newHandler(gen, user, pUserCookie->pUserCookie);
08020             }
08021         }
08022 
08023         static void XN_CALLBACK_TYPE LostUserCallback(XnNodeHandle hNode, XnUserID user, void* pCookie)
08024         {
08025             UserCookie* pUserCookie = (UserCookie*)pCookie;
08026             UserGenerator gen(hNode);
08027             if (pUserCookie->lostHandler != NULL)
08028             {
08029                 pUserCookie->lostHandler(gen, user, pUserCookie->pUserCookie);
08030             }
08031         }
08032 
08033         typedef struct UserSingleCookie
08034         {
08035             UserHandler handler;
08036             void* pUserCookie;
08037             XnCallbackHandle hCallback;
08038         } UserSingleCookie;
08039 
08040         static void XN_CALLBACK_TYPE UserSingleCallback(XnNodeHandle hNode, XnUserID user, void* pCookie)
08041         {
08042             UserSingleCookie* pUserCookie = (UserSingleCookie*)pCookie;
08043             UserGenerator gen(hNode);
08044             if (pUserCookie->handler != NULL)
08045             {
08046                 pUserCookie->handler(gen, user, pUserCookie->pUserCookie);
08047             }
08048         }
08049     };
08050 
08064     class AudioGenerator : public Generator
08065     {
08066     public:
08072         inline AudioGenerator(XnNodeHandle hNode = NULL) : Generator(hNode) {}
08073         inline AudioGenerator(const NodeWrapper& other) : Generator(other) {}
08074 
08082         inline XnStatus Create(Context& context, Query* pQuery = NULL, EnumerationErrors* pErrors = NULL);
08083 
08100         inline void GetMetaData(AudioMetaData& metaData) const
08101         {
08102             xnGetAudioMetaData(GetHandle(), metaData.GetUnderlying());
08103         }
08104 
08109         inline const XnUChar* GetAudioBuffer() const
08110         {
08111             return xnGetAudioBuffer(GetHandle());
08112         }
08113 
08117         inline XnUInt32 GetSupportedWaveOutputModesCount() const
08118         {
08119             return xnGetSupportedWaveOutputModesCount(GetHandle());
08120         }
08121 
08128         inline XnStatus GetSupportedWaveOutputModes(XnWaveOutputMode* aSupportedModes, XnUInt32& nCount) const
08129         {
08130             return xnGetSupportedWaveOutputModes(GetHandle(), aSupportedModes, &nCount);
08131         }
08132 
08144         inline XnStatus SetWaveOutputMode(const XnWaveOutputMode& OutputMode)
08145         {
08146             return xnSetWaveOutputMode(GetHandle(), &OutputMode);
08147         }
08148 
08160         inline XnStatus GetWaveOutputMode(XnWaveOutputMode& OutputMode) const
08161         {
08162             return xnGetWaveOutputMode(GetHandle(), &OutputMode);
08163         }
08164 
08174         inline XnStatus RegisterToWaveOutputModeChanges(StateChangedHandler handler, void* pCookie, XnCallbackHandle& hCallback)
08175         {
08176             return _RegisterToStateChange(xnRegisterToWaveOutputModeChanges, GetHandle(), handler, pCookie, hCallback);
08177         }
08178 
08186         inline void UnregisterFromWaveOutputModeChanges(XnCallbackHandle hCallback)
08187         {
08188             _UnregisterFromStateChange(xnUnregisterFromWaveOutputModeChanges, GetHandle(), hCallback);
08189         }
08190     };
08191 
08196     class MockAudioGenerator : public AudioGenerator
08197     {
08198     public:
08204         inline MockAudioGenerator(XnNodeHandle hNode = NULL) : AudioGenerator(hNode) {}
08205         inline MockAudioGenerator(const NodeWrapper& other) : AudioGenerator(other) {}
08206 
08213         XnStatus Create(Context& context, const XnChar* strName = NULL);
08214 
08222         XnStatus CreateBasedOn(AudioGenerator& other, const XnChar* strName = NULL);
08223 
08228         inline XnStatus SetData(XnUInt32 nFrameID, XnUInt64 nTimestamp, XnUInt32 nDataSize, const XnUInt8* pAudioBuffer)
08229         {
08230             return xnMockAudioSetData(GetHandle(), nFrameID, nTimestamp, nDataSize, pAudioBuffer);
08231         }
08232 
08241         inline XnStatus SetData(const AudioMetaData& audioMD, XnUInt32 nFrameID, XnUInt64 nTimestamp)
08242         {
08243             return SetData(nFrameID, nTimestamp, audioMD.DataSize(), audioMD.Data());
08244         }
08245 
08251         inline XnStatus SetData(const AudioMetaData& audioMD)
08252         {
08253             return SetData(audioMD, audioMD.FrameID(), audioMD.Timestamp());
08254         }
08255     };
08256 
08260     class MockRawGenerator : public Generator
08261     {
08262     public:
08263         MockRawGenerator(XnNodeHandle hNode = NULL) : Generator(hNode) {}
08264         MockRawGenerator(const NodeWrapper& other) : Generator(other) {}
08265 
08266         inline XnStatus Create(Context& context, const XnChar* strName = NULL);
08267 
08268         inline XnStatus SetData(XnUInt32 nFrameID, XnUInt64 nTimestamp, XnUInt32 nDataSize, const void* pData)
08269         {
08270             return xnMockRawSetData(GetHandle(), nFrameID, nTimestamp, nDataSize, pData);
08271         }
08272 
08273     };
08274 
08279     class Codec : public ProductionNode
08280     {
08281     public:
08287         inline Codec(XnNodeHandle hNode = NULL) : ProductionNode(hNode) {}
08288         inline Codec(const NodeWrapper& other) : ProductionNode(other) {}
08289 
08294         inline XnStatus Create(Context& context, XnCodecID codecID, ProductionNode& initializerNode);
08295 
08300         inline XnCodecID GetCodecID() const
08301         {
08302             return xnGetCodecID(GetHandle());
08303         }
08304 
08309         inline XnStatus EncodeData(const void* pSrc, XnUInt32 nSrcSize, void* pDst, XnUInt32 nDstSize, XnUInt* pnBytesWritten) const
08310         {
08311             return xnEncodeData(GetHandle(), pSrc, nSrcSize, pDst, nDstSize, pnBytesWritten);
08312         }
08313 
08318         inline XnStatus DecodeData(const void* pSrc, XnUInt32 nSrcSize, void* pDst, XnUInt32 nDstSize, XnUInt* pnBytesWritten) const
08319         {
08320             return xnDecodeData(GetHandle(), pSrc, nSrcSize, pDst, nDstSize, pnBytesWritten);
08321         }
08322     };
08323 
08357     class ScriptNode : public ProductionNode
08358     {
08359     public:
08365         inline ScriptNode(XnNodeHandle hNode = NULL) : ProductionNode(hNode) {}
08366         inline ScriptNode(const NodeWrapper& other) : ProductionNode(other) {}
08367 
08368         inline XnStatus Create(Context& context, const XnChar* strFormat);
08369 
08370         inline const XnChar* GetSupportedFormat()
08371         {
08372             return xnScriptNodeGetSupportedFormat(GetHandle());
08373         }
08374 
08380         inline XnStatus LoadScriptFromFile(const XnChar* strFileName)
08381         {
08382             return xnLoadScriptFromFile(GetHandle(), strFileName);
08383         }
08384 
08390         inline XnStatus LoadScriptFromString(const XnChar* strScript)
08391         {
08392             return xnLoadScriptFromString(GetHandle(), strScript);
08393         }
08394 
08406         inline XnStatus Run(EnumerationErrors* pErrors);
08407     };
08408 
08409     //---------------------------------------------------------------------------
08410     // EnumerationErrors
08411     //---------------------------------------------------------------------------
08432     class EnumerationErrors
08433     {
08434     public:
08438         inline EnumerationErrors() : m_bAllocated(TRUE), m_pErrors(NULL) { xnEnumerationErrorsAllocate(&m_pErrors); }
08439 
08447         inline EnumerationErrors(XnEnumerationErrors* pErrors, XnBool bOwn = FALSE) : m_bAllocated(bOwn), m_pErrors(pErrors) {}
08448 
08452         ~EnumerationErrors() { Free(); }
08453 
08457         class Iterator
08458         {
08459         public:
08460             friend class EnumerationErrors;
08461 
08467             XnBool operator==(const Iterator& other) const
08468             {
08469                 return m_it == other.m_it;
08470             }
08471 
08477             XnBool operator!=(const Iterator& other) const
08478             {
08479                 return m_it != other.m_it;
08480             }
08481 
08486             inline Iterator& operator++()
08487             {
08488                 m_it = xnEnumerationErrorsGetNext(m_it);
08489                 return *this;
08490             }
08491 
08496             inline Iterator operator++(int)
08497             {
08498                 return Iterator(xnEnumerationErrorsGetNext(m_it));
08499             }
08500 
08509             inline const XnProductionNodeDescription& Description() { return *xnEnumerationErrorsGetCurrentDescription(m_it); }
08510 
08515             inline XnStatus Error() { return xnEnumerationErrorsGetCurrentError(m_it); }
08516 
08517         private:
08518             inline Iterator(XnEnumerationErrorsIterator it) : m_it(it) {}
08519 
08520             XnEnumerationErrorsIterator m_it;
08521         };
08522 
08531         inline Iterator Begin() const { return Iterator(xnEnumerationErrorsGetFirst(m_pErrors)); }
08532 
08541         inline Iterator End() const { return Iterator(NULL); }
08542 
08551         inline XnStatus ToString(XnChar* csBuffer, XnUInt32 nSize)
08552         {
08553             return xnEnumerationErrorsToString(m_pErrors, csBuffer, nSize);
08554         }
08555 
08560         inline void Free()
08561         {
08562             if (m_bAllocated)
08563             {
08564                 xnEnumerationErrorsFree(m_pErrors);
08565                 m_pErrors = NULL;
08566                 m_bAllocated = FALSE;
08567             }
08568         }
08569 
08573         inline XnEnumerationErrors* GetUnderlying() { return m_pErrors; }
08574 
08575     private:
08576         XnEnumerationErrors* m_pErrors;
08577         XnBool m_bAllocated;
08578     };
08579 
08580     //---------------------------------------------------------------------------
08581     // Context
08582     //---------------------------------------------------------------------------
08583 
08619     class Context
08620     {
08621     public:
08636         typedef void (XN_CALLBACK_TYPE* NodeCreationHandler)(Context& context, ProductionNode& createdNode, void* pCookie);
08637 
08652         typedef void (XN_CALLBACK_TYPE* NodeDestructionHandler)(Context& context, const XnChar* strDestroyedNodeName, void* pCookie);
08653 
08657         inline Context() : m_pContext(NULL), m_bUsingDeprecatedAPI(FALSE), m_bAllocated(FALSE), m_hShuttingDownCallback(NULL) {}
08658 
08664         inline Context(XnContext* pContext) : m_pContext(NULL), m_bUsingDeprecatedAPI(FALSE), m_bAllocated(FALSE), m_hShuttingDownCallback(NULL)
08665         {
08666             SetHandle(pContext);
08667         }
08668 
08675         inline Context(const Context& other) : m_pContext(NULL), m_bUsingDeprecatedAPI(FALSE), m_bAllocated(FALSE), m_hShuttingDownCallback(NULL)
08676         {
08677             SetHandle(other.m_pContext);
08678         }
08679 
08683         ~Context()
08684         {
08685             SetHandle(NULL);
08686         }
08687 
08688         inline Context& operator=(const Context& other)
08689         {
08690             SetHandle(other.m_pContext);
08691             return *this;
08692         }
08693 
08697         inline XnContext* GetUnderlyingObject() const { return m_pContext; }
08698 
08704         inline XnBool operator==(const Context& other)
08705         {
08706             return (GetUnderlyingObject() == other.GetUnderlyingObject());
08707         }
08708 
08714         inline XnBool operator!=(const Context& other)
08715         {
08716             return (GetUnderlyingObject() != other.GetUnderlyingObject());
08717         }
08718 
08733         inline XnStatus Init()
08734         {
08735             XnContext* pContext = NULL;
08736             XnStatus nRetVal = xnInit(&pContext);
08737             XN_IS_STATUS_OK(nRetVal);
08738 
08739             TakeOwnership(pContext);
08740             m_bAllocated = TRUE;
08741 
08742             return (XN_STATUS_OK);
08743         }
08744 
08760         inline XnStatus RunXmlScript(const XnChar* strScript, ScriptNode& scriptNode, EnumerationErrors* pErrors = NULL)
08761         {
08762             XnStatus nRetVal = XN_STATUS_OK;
08763 
08764             XnNodeHandle hScriptNode;
08765             nRetVal = xnContextRunXmlScriptEx(m_pContext, strScript, pErrors == NULL ? NULL : pErrors->GetUnderlying(), &hScriptNode);
08766             XN_IS_STATUS_OK(nRetVal);
08767 
08768             scriptNode.TakeOwnership(hScriptNode);
08769 
08770             return (XN_STATUS_OK);
08771         }
08772 
08788         inline XnStatus RunXmlScriptFromFile(const XnChar* strFileName, ScriptNode& scriptNode, EnumerationErrors* pErrors = NULL)
08789         {
08790             XnStatus nRetVal = XN_STATUS_OK;
08791 
08792             XnNodeHandle hScriptNode;
08793             nRetVal = xnContextRunXmlScriptFromFileEx(m_pContext, strFileName, pErrors == NULL ? NULL : pErrors->GetUnderlying(), &hScriptNode);
08794             XN_IS_STATUS_OK(nRetVal);
08795 
08796             scriptNode.TakeOwnership(hScriptNode);
08797 
08798             return (XN_STATUS_OK);
08799         }
08800 
08816         inline XnStatus InitFromXmlFile(const XnChar* strFileName, ScriptNode& scriptNode, EnumerationErrors* pErrors = NULL)
08817         {
08818             XnContext* pContext = NULL;
08819 
08820             XnNodeHandle hScriptNode;
08821             XnStatus nRetVal = xnInitFromXmlFileEx(strFileName, &pContext, pErrors == NULL ? NULL : pErrors->GetUnderlying(), &hScriptNode);
08822             XN_IS_STATUS_OK(nRetVal);
08823 
08824             scriptNode.TakeOwnership(hScriptNode);
08825             TakeOwnership(pContext);
08826             m_bAllocated = TRUE;
08827 
08828             return (XN_STATUS_OK);
08829         }
08830 
08847         inline XnStatus OpenFileRecording(const XnChar* strFileName, ProductionNode& playerNode)
08848         {
08849             XnStatus nRetVal = XN_STATUS_OK;
08850 
08851             XnNodeHandle hPlayer;
08852             nRetVal = xnContextOpenFileRecordingEx(m_pContext, strFileName, &hPlayer);
08853             XN_IS_STATUS_OK(nRetVal);
08854 
08855             playerNode.TakeOwnership(hPlayer);
08856 
08857             return (XN_STATUS_OK);
08858         }
08859 
08864         inline XnStatus CreateMockNode(XnProductionNodeType type, const XnChar* strName, ProductionNode& mockNode)
08865         {
08866             XnStatus nRetVal = XN_STATUS_OK;
08867 
08868             XnNodeHandle hMockNode;
08869             nRetVal = xnCreateMockNode(m_pContext, type, strName, &hMockNode);
08870             XN_IS_STATUS_OK(nRetVal);
08871 
08872             mockNode.TakeOwnership(hMockNode);
08873 
08874             return (XN_STATUS_OK);
08875         }
08876 
08881         inline XnStatus CreateMockNodeBasedOn(ProductionNode& originalNode, const XnChar* strName, ProductionNode& mockNode)
08882         {
08883             XnStatus nRetVal = XN_STATUS_OK;
08884 
08885             XnNodeHandle hMockNode;
08886             nRetVal = xnCreateMockNodeBasedOn(m_pContext, originalNode, strName, &hMockNode);
08887             XN_IS_STATUS_OK(nRetVal);
08888 
08889             mockNode.TakeOwnership(hMockNode);
08890 
08891             return (XN_STATUS_OK);
08892         }
08893 
08898         inline XnStatus CreateCodec(XnCodecID codecID, ProductionNode& initializerNode, Codec& codec)
08899         {
08900             XnStatus nRetVal = XN_STATUS_OK;
08901 
08902             XnNodeHandle hCodec;
08903             nRetVal =  xnCreateCodec(m_pContext, codecID, initializerNode.GetHandle(), &hCodec);
08904             XN_IS_STATUS_OK(nRetVal);
08905 
08906             codec.TakeOwnership(hCodec);
08907 
08908             return (XN_STATUS_OK);
08909         }
08910 
08915         inline XnStatus AddRef()
08916         {
08917             return xnContextAddRef(m_pContext);
08918         }
08919 
08924         inline void Release()
08925         {
08926             SetHandle(NULL);
08927         }
08928 
08929 
08934         inline XnStatus AddLicense(const XnLicense& License)
08935         {
08936             return xnAddLicense(m_pContext, &License);
08937         }
08938 
08943         inline XnStatus EnumerateLicenses(XnLicense*& aLicenses, XnUInt32& nCount) const
08944         {
08945             return xnEnumerateLicenses(m_pContext, &aLicenses, &nCount);
08946         }
08947 
08952         inline static void FreeLicensesList(XnLicense aLicenses[])
08953         {
08954             xnFreeLicensesList(aLicenses);
08955         }
08956 
08977         XnStatus EnumerateProductionTrees(XnProductionNodeType Type, const Query* pQuery, NodeInfoList& TreesList, EnumerationErrors* pErrors = NULL) const
08978         {
08979             XnStatus nRetVal = XN_STATUS_OK;
08980 
08981             const XnNodeQuery* pInternalQuery = (pQuery != NULL) ? pQuery->GetUnderlyingObject() : NULL;
08982 
08983             XnNodeInfoList* pList = NULL;
08984             nRetVal = xnEnumerateProductionTrees(m_pContext, Type, pInternalQuery, &pList, pErrors == NULL ? NULL : pErrors->GetUnderlying());
08985             XN_IS_STATUS_OK(nRetVal);
08986 
08987             TreesList.ReplaceUnderlyingObject(pList);
08988 
08989             return (XN_STATUS_OK);
08990         }
08991 
09024         XnStatus CreateAnyProductionTree(XnProductionNodeType type, Query* pQuery, ProductionNode& node, EnumerationErrors* pErrors = NULL)
09025         {
09026             XnStatus nRetVal = XN_STATUS_OK;
09027 
09028             XnNodeQuery* pInternalQuery = (pQuery != NULL) ? pQuery->GetUnderlyingObject() : NULL;
09029 
09030             XnNodeHandle hNode;
09031             nRetVal = xnCreateAnyProductionTree(m_pContext, type, pInternalQuery, &hNode, pErrors == NULL ? NULL : pErrors->GetUnderlying());
09032             XN_IS_STATUS_OK(nRetVal);
09033 
09034             node.TakeOwnership(hNode);
09035 
09036             return (XN_STATUS_OK);
09037         }
09038 
09055         XnStatus CreateProductionTree(NodeInfo& Tree, ProductionNode& node)
09056         {
09057             XnStatus nRetVal = XN_STATUS_OK;
09058 
09059             XnNodeHandle hNode;
09060             nRetVal = xnCreateProductionTree(m_pContext, Tree, &hNode);
09061             XN_IS_STATUS_OK(nRetVal);
09062 
09063             node.TakeOwnership(hNode);
09064 
09065             return (XN_STATUS_OK);
09066         }
09067 
09076         XnStatus EnumerateExistingNodes(NodeInfoList& list) const
09077         {
09078             XnNodeInfoList* pList;
09079             XnStatus nRetVal = xnEnumerateExistingNodes(m_pContext, &pList);
09080             XN_IS_STATUS_OK(nRetVal);
09081 
09082             list.ReplaceUnderlyingObject(pList);
09083 
09084             return (XN_STATUS_OK);
09085         }
09086 
09105         XnStatus EnumerateExistingNodes(NodeInfoList& list, XnProductionNodeType type) const
09106         {
09107             XnNodeInfoList* pList;
09108             XnStatus nRetVal = xnEnumerateExistingNodesByType(m_pContext, type, &pList);
09109             XN_IS_STATUS_OK(nRetVal);
09110 
09111             list.ReplaceUnderlyingObject(pList);
09112 
09113             return (XN_STATUS_OK);
09114         }
09115 
09134         XnStatus FindExistingNode(XnProductionNodeType type, ProductionNode& node) const
09135         {
09136             XnStatus nRetVal = XN_STATUS_OK;
09137 
09138             XnNodeHandle hNode;
09139             nRetVal = xnFindExistingRefNodeByType(m_pContext, type, &hNode);
09140             XN_IS_STATUS_OK(nRetVal);
09141 
09142             node.TakeOwnership(hNode);
09143 
09144             return (XN_STATUS_OK);
09145         }
09146 
09151         XnStatus GetProductionNodeByName(const XnChar* strInstanceName, ProductionNode& node) const
09152         {
09153             XnStatus nRetVal = XN_STATUS_OK;
09154 
09155             XnNodeHandle hNode;
09156             nRetVal = xnGetRefNodeHandleByName(m_pContext, strInstanceName, &hNode);
09157             XN_IS_STATUS_OK(nRetVal);
09158 
09159             node.TakeOwnership(hNode);
09160 
09161             return (XN_STATUS_OK);
09162         }
09163 
09168         XnStatus GetProductionNodeInfoByName(const XnChar* strInstanceName, NodeInfo& nodeInfo) const
09169         {
09170             XnStatus nRetVal = XN_STATUS_OK;
09171 
09172             XnNodeHandle hNode;
09173             nRetVal = xnGetRefNodeHandleByName(m_pContext, strInstanceName, &hNode);
09174             XN_IS_STATUS_OK(nRetVal);
09175 
09176             xnProductionNodeRelease(hNode);
09177 
09178             nodeInfo = NodeInfo(xnGetNodeInfo(hNode));
09179 
09180             return (XN_STATUS_OK);
09181         }
09182 
09187         inline XnStatus StartGeneratingAll()
09188         {
09189             return xnStartGeneratingAll(m_pContext);
09190         }
09191 
09195         inline XnStatus StopGeneratingAll()
09196         {
09197             return xnStopGeneratingAll(m_pContext);
09198         }
09199 
09209         inline XnStatus SetGlobalMirror(XnBool bMirror)
09210         {
09211             return xnSetGlobalMirror(m_pContext, bMirror);
09212         }
09213 
09218         inline XnBool GetGlobalMirror()
09219         {
09220             return xnGetGlobalMirror(m_pContext);
09221         }
09222 
09227         inline XnStatus GetGlobalErrorState()
09228         {
09229             return xnGetGlobalErrorState(m_pContext);
09230         }
09231 
09241         inline XnStatus RegisterToErrorStateChange(XnErrorStateChangedHandler handler, void* pCookie, XnCallbackHandle& hCallback)
09242         {
09243             return xnRegisterToGlobalErrorStateChange(m_pContext, handler, pCookie, &hCallback);
09244         }
09245 
09253         inline void UnregisterFromErrorStateChange(XnCallbackHandle hCallback)
09254         {
09255             xnUnregisterFromGlobalErrorStateChange(m_pContext, hCallback);
09256         }
09257 
09267         inline XnStatus RegisterToNodeCreation(NodeCreationHandler handler, void* pCookie, XnCallbackHandle& hCallback)
09268         {
09269             XnStatus nRetVal = XN_STATUS_OK;
09270             
09271             NodeCreationCookie* pCreationCookie;
09272             XN_VALIDATE_ALLOC(pCreationCookie, NodeCreationCookie);
09273             pCreationCookie->pFunc = handler;
09274             pCreationCookie->pCookie = pCookie;
09275             
09276             nRetVal = xnRegisterToNodeCreation(m_pContext, NodeCreationCallback, pCreationCookie, &pCreationCookie->hUnderlyingCallback);
09277             XN_IS_STATUS_OK(nRetVal);
09278 
09279             hCallback = pCreationCookie;
09280 
09281             return XN_STATUS_OK;
09282         }
09283 
09291         inline void UnregisterFromNodeCreation(XnCallbackHandle hCallback)
09292         {
09293             NodeCreationCookie* pCreationCookie = (NodeCreationCookie*)hCallback;
09294             xnUnregisterFromNodeCreation(m_pContext, pCreationCookie->hUnderlyingCallback);
09295             xnOSFree(pCreationCookie);
09296         }
09297 
09307         inline XnStatus RegisterToNodeDestruction(NodeDestructionHandler handler, void* pCookie, XnCallbackHandle& hCallback)
09308         {
09309             XnStatus nRetVal = XN_STATUS_OK;
09310             
09311             NodeDestructionCookie* pDestructionCookie;
09312             XN_VALIDATE_ALLOC(pDestructionCookie, NodeDestructionCookie);
09313             pDestructionCookie->pFunc = handler;
09314             pDestructionCookie->pCookie = pCookie;
09315 
09316             nRetVal = xnRegisterToNodeDestruction(m_pContext, NodeDestructionCallback, pDestructionCookie, &pDestructionCookie->hUnderlyingCallback);
09317             XN_IS_STATUS_OK(nRetVal);
09318 
09319             hCallback = pDestructionCookie;
09320 
09321             return XN_STATUS_OK;
09322         }
09323 
09331         inline void UnregisterFromNodeDestruction(XnCallbackHandle hCallback)
09332         {
09333             NodeDestructionCookie* pDestructionCookie = (NodeDestructionCookie*)hCallback;
09334             xnUnregisterFromNodeDestruction(m_pContext, pDestructionCookie->hUnderlyingCallback);
09335             xnOSFree(pDestructionCookie);
09336         }
09337 
09371         inline XnStatus WaitAndUpdateAll()
09372         {
09373             return xnWaitAndUpdateAll(m_pContext);
09374         }
09375 
09410         inline XnStatus WaitAnyUpdateAll()
09411         {
09412             return xnWaitAnyUpdateAll(m_pContext);
09413         }
09414 
09445         inline XnStatus WaitOneUpdateAll(ProductionNode& node)
09446         {
09447             return xnWaitOneUpdateAll(m_pContext, node.GetHandle());
09448         }
09449 
09471         inline XnStatus WaitNoneUpdateAll()
09472         {
09473             return xnWaitNoneUpdateAll(m_pContext);
09474         }
09475 
09480         inline XnStatus AutoEnumerateOverSingleInput(NodeInfoList& List, XnProductionNodeDescription& description, const XnChar* strCreationInfo, XnProductionNodeType InputType, EnumerationErrors* pErrors, Query* pQuery = NULL) const
09481         {
09482             return xnAutoEnumerateOverSingleInput(m_pContext, List.GetUnderlyingObject(), &description, strCreationInfo, InputType, pErrors == NULL ? NULL : pErrors->GetUnderlying(), pQuery == NULL ? NULL : pQuery->GetUnderlyingObject());
09483         }
09484 
09488         inline void SetHandle(XnContext* pContext)
09489         {
09490             if (m_pContext == pContext)
09491             {
09492                 return;
09493             }
09494 
09495             if (m_pContext != NULL)
09496             {
09497                 if (m_bUsingDeprecatedAPI && m_bAllocated)
09498                 {
09499                     // Backwards compatibility: call shutdown instead of release, to make old programs get the
09500                     // exact same behavior they used to have.
09501                     xnForceShutdown(m_pContext);
09502                 }
09503                 else
09504                 {
09505                     xnContextUnregisterFromShutdown(m_pContext, m_hShuttingDownCallback);
09506                     xnContextRelease(m_pContext);
09507                 }
09508             }
09509 
09510             if (pContext != NULL)
09511             {
09512                 XnStatus nRetVal = xnContextAddRef(pContext);
09513                 XN_ASSERT(nRetVal == XN_STATUS_OK);
09514                 XN_REFERENCE_VARIABLE(nRetVal);
09515 
09516                 nRetVal = xnContextRegisterForShutdown(pContext, ContextShuttingDownCallback, this, &m_hShuttingDownCallback);
09517                 XN_ASSERT(nRetVal == XN_STATUS_OK);
09518             }
09519 
09520             m_pContext = pContext;
09521         }
09522 
09523         inline void TakeOwnership(XnContext* pContext)
09524         {
09525             SetHandle(pContext);
09526 
09527             if (pContext != NULL)
09528             {
09529                 xnContextRelease(pContext);
09530             }
09531         }
09532 
09534         inline XnStatus XN_API_DEPRECATED("Use other overload!") RunXmlScript(const XnChar* strScript, EnumerationErrors* pErrors = NULL)
09535         {
09536             m_bUsingDeprecatedAPI = TRUE;
09537             #pragma warning (push)
09538             #pragma warning (disable: XN_DEPRECATED_WARNING_IDS)
09539             return xnContextRunXmlScript(m_pContext, strScript, pErrors == NULL ? NULL : pErrors->GetUnderlying());
09540             #pragma warning (pop)
09541         }
09542 
09543         inline XnStatus XN_API_DEPRECATED("Use other overload!") RunXmlScriptFromFile(const XnChar* strFileName, EnumerationErrors* pErrors = NULL)
09544         {
09545             m_bUsingDeprecatedAPI = TRUE;
09546             #pragma warning (push)
09547             #pragma warning (disable: XN_DEPRECATED_WARNING_IDS)
09548             return xnContextRunXmlScriptFromFile(m_pContext, strFileName, pErrors == NULL ? NULL : pErrors->GetUnderlying());
09549             #pragma warning (pop)
09550         }
09551 
09552         inline XnStatus XN_API_DEPRECATED("Use other overload!") InitFromXmlFile(const XnChar* strFileName, EnumerationErrors* pErrors = NULL)
09553         {
09554             XnContext* pContext = NULL;
09555             m_bUsingDeprecatedAPI = TRUE;
09556 
09557             #pragma warning (push)
09558             #pragma warning (disable: XN_DEPRECATED_WARNING_IDS)
09559             XnStatus nRetVal = xnInitFromXmlFile(strFileName, &pContext, pErrors == NULL ? NULL : pErrors->GetUnderlying());
09560             #pragma warning (pop)
09561             XN_IS_STATUS_OK(nRetVal);
09562 
09563             TakeOwnership(pContext);
09564             m_bAllocated = TRUE;
09565 
09566             return (XN_STATUS_OK);
09567         }
09568 
09569         inline XnStatus XN_API_DEPRECATED("Use other overload!") OpenFileRecording(const XnChar* strFileName)
09570         {
09571             m_bUsingDeprecatedAPI = TRUE;
09572             #pragma warning (push)
09573             #pragma warning (disable: XN_DEPRECATED_WARNING_IDS)
09574             return xnContextOpenFileRecording(m_pContext, strFileName);
09575             #pragma warning (pop)
09576         }
09577 
09578         inline void XN_API_DEPRECATED("You may use Release() instead, or count on dtor") Shutdown()
09579         {
09580             if (m_pContext != NULL)
09581             {
09582                 #pragma warning (push)
09583                 #pragma warning (disable: XN_DEPRECATED_WARNING_IDS)
09584                 xnShutdown(m_pContext);
09585                 #pragma warning (pop)
09586                 m_pContext = NULL;
09587             }
09588         }
09589 
09590         XnStatus XN_API_DEPRECATED("Please use other overload") CreateProductionTree(NodeInfo& Tree)
09591         {
09592             XnStatus nRetVal = XN_STATUS_OK;
09593 
09594             XnNodeHandle hNode;
09595             nRetVal = xnCreateProductionTree(m_pContext, Tree, &hNode);
09596             XN_IS_STATUS_OK(nRetVal);
09597 
09598             Tree.m_bOwnerOfNode = TRUE;
09599 
09600             return (XN_STATUS_OK);
09601         }
09604     private:
09605         typedef struct NodeCreationCookie
09606         {
09607             NodeCreationHandler pFunc;
09608             void* pCookie;
09609             XnCallbackHandle hUnderlyingCallback;
09610         } NodeCreationCookie;
09611 
09612         typedef struct NodeDestructionCookie
09613         {
09614             NodeDestructionHandler pFunc;
09615             void* pCookie;
09616             XnCallbackHandle hUnderlyingCallback;
09617         } NodeDestructionCookie;
09618 
09619         static void XN_CALLBACK_TYPE NodeCreationCallback(XnContext* pContext, XnNodeHandle hCreatedNode, void* pCookie)
09620         {
09621             NodeCreationCookie* pNodeCreationCookie = (NodeCreationCookie*)pCookie;
09622             Context context(pContext);
09623             ProductionNode createdNode(hCreatedNode);
09624             pNodeCreationCookie->pFunc(context, createdNode, pNodeCreationCookie->pCookie);
09625         }
09626 
09627         static void XN_CALLBACK_TYPE NodeDestructionCallback(XnContext* pContext, const XnChar* strDestroyedNodeName, void* pCookie)
09628         {
09629             NodeDestructionCookie* pNodeCreationCookie = (NodeDestructionCookie*)pCookie;
09630             Context context(pContext);
09631             pNodeCreationCookie->pFunc(context, strDestroyedNodeName, pNodeCreationCookie->pCookie);
09632         }
09633 
09634         static void XN_CALLBACK_TYPE ContextShuttingDownCallback(XnContext* /*pContext*/, void* pCookie)
09635         {
09636             Context* pThis = (Context*)pCookie;
09637             pThis->m_pContext = NULL;
09638         }
09639 
09640         XnContext* m_pContext;
09641         XnBool m_bUsingDeprecatedAPI;
09642         XnBool m_bAllocated;
09643         XnCallbackHandle m_hShuttingDownCallback;
09644     };
09645 
09650     class Resolution
09651     {
09652     public:
09658         inline Resolution(XnResolution res) : m_Res(res)
09659         {
09660             m_nXRes = xnResolutionGetXRes(res);
09661             m_nYRes = xnResolutionGetYRes(res);
09662             m_strName = xnResolutionGetName(res);
09663         }
09664 
09671         inline Resolution(XnUInt32 xRes, XnUInt32 yRes) : m_nXRes(xRes), m_nYRes(yRes)
09672         {
09673             m_Res = xnResolutionGetFromXYRes(xRes, yRes);
09674             m_strName = xnResolutionGetName(m_Res);
09675         }
09676 
09682         inline Resolution(const XnChar* strName)
09683         {
09684             m_Res = xnResolutionGetFromName(strName);
09685             m_nXRes = xnResolutionGetXRes(m_Res);
09686             m_nYRes = xnResolutionGetYRes(m_Res);
09687             m_strName = xnResolutionGetName(m_Res);
09688         }
09689 
09693         inline XnResolution GetResolution() const { return m_Res; }
09697         inline XnUInt32 GetXResolution() const { return m_nXRes; }
09701         inline XnUInt32 GetYResolution() const { return m_nYRes; }
09705         inline const XnChar* GetName() const { return m_strName; }
09706 
09707     private:
09708         XnResolution m_Res;
09709         XnUInt32 m_nXRes;
09710         XnUInt32 m_nYRes;
09711         const XnChar* m_strName;
09712     };
09713 
09714     //---------------------------------------------------------------------------
09715     // Functions Implementation
09716     //---------------------------------------------------------------------------
09717     inline XnStatus NodeInfoList::FilterList(Context& context, Query& query)
09718     {
09719         return xnNodeQueryFilterList(context.GetUnderlyingObject(), query.GetUnderlyingObject(), m_pList);
09720     }
09721 
09722     inline void ProductionNode::GetContext(Context& context) const
09723     {
09724         context.TakeOwnership(xnGetRefContextFromNodeHandle(GetHandle()));
09725     }
09726 
09727     inline Context ProductionNode::GetContext() const
09728     {
09729         XnContext* pContext = xnGetRefContextFromNodeHandle(GetHandle());
09730         Context result(pContext);
09731         xnContextRelease(pContext);
09732         return result;
09733     }
09734 
09735     inline NodeInfoList& NodeInfo::GetNeededNodes() const
09736     {
09737         if (m_pNeededNodes == NULL)
09738         {
09739             XnNodeInfoList* pList = xnNodeInfoGetNeededNodes(m_pInfo);
09740             m_pNeededNodes = XN_NEW(NodeInfoList, pList);
09741         }
09742 
09743         return *m_pNeededNodes;
09744     }
09745 
09746     inline void NodeInfo::SetUnderlyingObject(XnNodeInfo* pInfo)
09747     {
09748         if (m_pNeededNodes != NULL)
09749         {
09750             XN_DELETE(m_pNeededNodes);
09751         }
09752 
09753         m_bOwnerOfNode = FALSE;
09754         m_pInfo = pInfo;
09755         m_pNeededNodes = NULL;
09756     }
09757 
09758     inline XnBool FrameSyncCapability::CanFrameSyncWith(Generator& other) const
09759     {
09760         return xnCanFrameSyncWith(GetHandle(), other.GetHandle());
09761     }
09762 
09763     inline XnStatus FrameSyncCapability::FrameSyncWith(Generator& other)
09764     {
09765         return xnFrameSyncWith(GetHandle(), other.GetHandle());
09766     }
09767 
09768     inline XnStatus FrameSyncCapability::StopFrameSyncWith(Generator& other)
09769     {
09770         return xnStopFrameSyncWith(GetHandle(), other.GetHandle());
09771     }
09772 
09773     inline XnBool FrameSyncCapability::IsFrameSyncedWith(Generator& other) const
09774     {
09775         return xnIsFrameSyncedWith(GetHandle(), other.GetHandle());
09776     }
09777 
09778     inline XnStatus NodeInfo::GetInstance(ProductionNode& node) const
09779     {
09780         if (m_pInfo == NULL)
09781         {
09782             return XN_STATUS_INVALID_OPERATION;
09783         }
09784 
09785         XnNodeHandle hNode = xnNodeInfoGetRefHandle(m_pInfo);
09786         node.TakeOwnership(hNode);
09787 
09788         if (m_bOwnerOfNode)
09789         {
09790             xnProductionNodeRelease(hNode);
09791         }
09792 
09793         return (XN_STATUS_OK);
09794     }
09795 
09796     //---------------------------------------------------------------------------
09797     // Node creation functions
09798     //---------------------------------------------------------------------------
09799 
09800     inline XnStatus Device::Create(Context& context, Query* pQuery/*=NULL*/, EnumerationErrors* pErrors/*=NULL*/)
09801     {
09802         XnNodeHandle hNode;
09803         XnStatus nRetVal = xnCreateDevice(context.GetUnderlyingObject(), &hNode, pQuery == NULL ? NULL : pQuery->GetUnderlyingObject(), pErrors == NULL ? NULL : pErrors->GetUnderlying());
09804         XN_IS_STATUS_OK(nRetVal);
09805         TakeOwnership(hNode);
09806         return (XN_STATUS_OK);
09807     }
09808 
09809     inline XnStatus Recorder::Create(Context& context, const XnChar* strFormatName /*= NULL*/)
09810     {
09811         XnNodeHandle hNode;
09812         XnStatus nRetVal = xnCreateRecorder(context.GetUnderlyingObject(), strFormatName, &hNode);
09813         XN_IS_STATUS_OK(nRetVal);
09814         TakeOwnership(hNode);
09815         return (XN_STATUS_OK);
09816     }
09817 
09818     inline XnStatus Player::Create(Context& context, const XnChar* strFormatName)
09819     {
09820         XnNodeHandle hNode;
09821         XnStatus nRetVal = xnCreatePlayer(context.GetUnderlyingObject(), strFormatName, &hNode);
09822         XN_IS_STATUS_OK(nRetVal);
09823         TakeOwnership(hNode);
09824         return (XN_STATUS_OK);
09825     }
09826 
09827     inline XnStatus DepthGenerator::Create(Context& context, Query* pQuery/*=NULL*/, EnumerationErrors* pErrors/*=NULL*/)
09828     {
09829         XnNodeHandle hNode;
09830         XnStatus nRetVal = xnCreateDepthGenerator(context.GetUnderlyingObject(), &hNode, pQuery == NULL ? NULL : pQuery->GetUnderlyingObject(), pErrors == NULL ? NULL : pErrors->GetUnderlying());
09831         XN_IS_STATUS_OK(nRetVal);
09832         TakeOwnership(hNode);
09833         return (XN_STATUS_OK);
09834     }
09835 
09836     inline XnStatus MockDepthGenerator::Create(Context& context, const XnChar* strName /* = NULL */)
09837     {
09838         XnNodeHandle hNode;
09839         XnStatus nRetVal = xnCreateMockNode(context.GetUnderlyingObject(), XN_NODE_TYPE_DEPTH, strName, &hNode);
09840         XN_IS_STATUS_OK(nRetVal);
09841         TakeOwnership(hNode);
09842         return (XN_STATUS_OK);
09843     }
09844 
09845     inline XnStatus MockDepthGenerator::CreateBasedOn(DepthGenerator& other, const XnChar* strName /* = NULL */)
09846     {
09847         Context context;
09848         other.GetContext(context);
09849         XnNodeHandle hNode;
09850         XnStatus nRetVal = xnCreateMockNodeBasedOn(context.GetUnderlyingObject(), other.GetHandle(), strName, &hNode);
09851         XN_IS_STATUS_OK(nRetVal);
09852         TakeOwnership(hNode);
09853         return (XN_STATUS_OK);
09854     }
09855 
09856     inline XnStatus ImageGenerator::Create(Context& context, Query* pQuery/*=NULL*/, EnumerationErrors* pErrors/*=NULL*/)
09857     {
09858         XnNodeHandle hNode;
09859         XnStatus nRetVal = xnCreateImageGenerator(context.GetUnderlyingObject(), &hNode, pQuery == NULL ? NULL : pQuery->GetUnderlyingObject(), pErrors == NULL ? NULL : pErrors->GetUnderlying());
09860         XN_IS_STATUS_OK(nRetVal);
09861         TakeOwnership(hNode);
09862         return (XN_STATUS_OK);
09863     }
09864 
09865     inline XnStatus MockImageGenerator::Create(Context& context, const XnChar* strName /* = NULL */)
09866     {
09867         XnNodeHandle hNode;
09868         XnStatus nRetVal = xnCreateMockNode(context.GetUnderlyingObject(), XN_NODE_TYPE_IMAGE, strName, &hNode);
09869         XN_IS_STATUS_OK(nRetVal);
09870         TakeOwnership(hNode);
09871         return (XN_STATUS_OK);
09872     }
09873 
09874     inline XnStatus MockImageGenerator::CreateBasedOn(ImageGenerator& other, const XnChar* strName /* = NULL */)
09875     {
09876         Context context;
09877         other.GetContext(context);
09878         XnNodeHandle hNode;
09879         XnStatus nRetVal = xnCreateMockNodeBasedOn(context.GetUnderlyingObject(), other.GetHandle(), strName, &hNode);
09880         XN_IS_STATUS_OK(nRetVal);
09881         TakeOwnership(hNode);
09882         return (XN_STATUS_OK);
09883     }
09884 
09885     inline XnStatus IRGenerator::Create(Context& context, Query* pQuery/*=NULL*/, EnumerationErrors* pErrors/*=NULL*/)
09886     {
09887         XnNodeHandle hNode;
09888         XnStatus nRetVal = xnCreateIRGenerator(context.GetUnderlyingObject(), &hNode, pQuery == NULL ? NULL : pQuery->GetUnderlyingObject(), pErrors == NULL ? NULL : pErrors->GetUnderlying());
09889         XN_IS_STATUS_OK(nRetVal);
09890         TakeOwnership(hNode);
09891         return (XN_STATUS_OK);
09892     }
09893 
09894     inline XnStatus MockIRGenerator::Create(Context& context, const XnChar* strName /* = NULL */)
09895     {
09896         XnNodeHandle hNode;
09897         XnStatus nRetVal = xnCreateMockNode(context.GetUnderlyingObject(), XN_NODE_TYPE_IR, strName, &hNode);
09898         XN_IS_STATUS_OK(nRetVal);
09899         TakeOwnership(hNode);
09900         return (XN_STATUS_OK);
09901     }
09902 
09903     inline XnStatus MockIRGenerator::CreateBasedOn(IRGenerator& other, const XnChar* strName /* = NULL */)
09904     {
09905         Context context;
09906         other.GetContext(context);
09907         XnNodeHandle hNode;
09908         XnStatus nRetVal = xnCreateMockNodeBasedOn(context.GetUnderlyingObject(), other.GetHandle(), strName, &hNode);
09909         XN_IS_STATUS_OK(nRetVal);
09910         TakeOwnership(hNode);
09911         return (XN_STATUS_OK);
09912     }
09913 
09914     inline XnStatus GestureGenerator::Create(Context& context, Query* pQuery/*=NULL*/, EnumerationErrors* pErrors/*=NULL*/)
09915     {
09916         XnNodeHandle hNode;
09917         XnStatus nRetVal = xnCreateGestureGenerator(context.GetUnderlyingObject(), &hNode, pQuery == NULL ? NULL : pQuery->GetUnderlyingObject(), pErrors == NULL ? NULL : pErrors->GetUnderlying());
09918         XN_IS_STATUS_OK(nRetVal);
09919         TakeOwnership(hNode);
09920         return (XN_STATUS_OK);
09921     }
09922 
09923     inline XnStatus SceneAnalyzer::Create(Context& context, Query* pQuery/*=NULL*/, EnumerationErrors* pErrors/*=NULL*/)
09924     {
09925         //You're creating a scene!
09926         XnNodeHandle hNode;
09927         XnStatus nRetVal = xnCreateSceneAnalyzer(context.GetUnderlyingObject(), &hNode, pQuery == NULL ? NULL : pQuery->GetUnderlyingObject(), pErrors == NULL ? NULL : pErrors->GetUnderlying());
09928         XN_IS_STATUS_OK(nRetVal);
09929         TakeOwnership(hNode);
09930         return (XN_STATUS_OK);
09931     }
09932 
09933     inline XnStatus HandsGenerator::Create(Context& context, Query* pQuery/*=NULL*/, EnumerationErrors* pErrors/*=NULL*/)
09934     {
09935         XnNodeHandle hNode;
09936         XnStatus nRetVal = xnCreateHandsGenerator(context.GetUnderlyingObject(), &hNode, pQuery == NULL ? NULL : pQuery->GetUnderlyingObject(), pErrors == NULL ? NULL : pErrors->GetUnderlying());
09937         XN_IS_STATUS_OK(nRetVal);
09938         TakeOwnership(hNode);
09939         return (XN_STATUS_OK);
09940     }
09941 
09942     inline XnStatus UserGenerator::Create(Context& context, Query* pQuery/*=NULL*/, EnumerationErrors* pErrors/*=NULL*/)
09943     {
09944         XnNodeHandle hNode;
09945         XnStatus nRetVal = xnCreateUserGenerator(context.GetUnderlyingObject(), &hNode, pQuery == NULL ? NULL : pQuery->GetUnderlyingObject(), pErrors == NULL ? NULL : pErrors->GetUnderlying());
09946         XN_IS_STATUS_OK(nRetVal);
09947         TakeOwnership(hNode);
09948         return (XN_STATUS_OK);
09949     }
09950 
09951     inline XnStatus AudioGenerator::Create(Context& context, Query* pQuery/*=NULL*/, EnumerationErrors* pErrors/*=NULL*/)
09952     {
09953         XnNodeHandle hNode;
09954         XnStatus nRetVal = xnCreateAudioGenerator(context.GetUnderlyingObject(), &hNode, pQuery == NULL ? NULL : pQuery->GetUnderlyingObject(), pErrors == NULL ? NULL : pErrors->GetUnderlying());
09955         XN_IS_STATUS_OK(nRetVal);
09956         TakeOwnership(hNode);
09957         return (XN_STATUS_OK);
09958     }
09959 
09960     inline XnStatus MockAudioGenerator::Create(Context& context, const XnChar* strName /* = NULL */)
09961     {
09962         XnNodeHandle hNode;
09963         XnStatus nRetVal = xnCreateMockNode(context.GetUnderlyingObject(), XN_NODE_TYPE_AUDIO, strName, &hNode);
09964         XN_IS_STATUS_OK(nRetVal);
09965         TakeOwnership(hNode);
09966         return (XN_STATUS_OK);
09967     }
09968 
09969     inline XnStatus MockAudioGenerator::CreateBasedOn(AudioGenerator& other, const XnChar* strName /* = NULL */)
09970     {
09971         Context context;
09972         other.GetContext(context);
09973         XnNodeHandle hNode;
09974         XnStatus nRetVal = xnCreateMockNodeBasedOn(context.GetUnderlyingObject(), other.GetHandle(), strName, &hNode);
09975         XN_IS_STATUS_OK(nRetVal);
09976         TakeOwnership(hNode);
09977         return (XN_STATUS_OK);
09978     }
09979 
09980     inline XnStatus MockRawGenerator::Create(Context& context, const XnChar* strName /*= NULL*/)
09981     {
09982         XnNodeHandle hNode;
09983         XnStatus nRetVal = xnCreateMockNode(context.GetUnderlyingObject(), XN_NODE_TYPE_GENERATOR, strName, &hNode);
09984         XN_IS_STATUS_OK(nRetVal);
09985         TakeOwnership(hNode);
09986         return (XN_STATUS_OK);
09987     }
09988 
09989     inline XnStatus Codec::Create(Context& context, XnCodecID codecID, ProductionNode& initializerNode)
09990     {
09991         XnNodeHandle hNode;
09992         XnStatus nRetVal = xnCreateCodec(context.GetUnderlyingObject(), codecID, initializerNode.GetHandle(), &hNode);
09993         XN_IS_STATUS_OK(nRetVal);
09994         TakeOwnership(hNode);
09995         return (XN_STATUS_OK);
09996     }
09997 
09998     inline XnStatus ScriptNode::Run(EnumerationErrors* pErrors)
09999     {
10000         return xnScriptNodeRun(GetHandle(), pErrors == NULL ? NULL : pErrors->GetUnderlying());
10001     }
10002 
10003     inline XnStatus ScriptNode::Create(Context& context, const XnChar* strFormat)
10004     {
10005         XnNodeHandle hNode;
10006         XnStatus nRetVal = xnCreateScriptNode(context.GetUnderlyingObject(), strFormat, &hNode);
10007         XN_IS_STATUS_OK(nRetVal);
10008         TakeOwnership(hNode);
10009         return (XN_STATUS_OK);
10010     }
10011 
10012     //---------------------------------------------------------------------------
10013     // Global Helper Functions
10014     //---------------------------------------------------------------------------
10015 
10016     inline void XN_API_DEPRECATED("Use xn::Version::Current() instead") GetVersion(XnVersion& Version)
10017     {
10018         xnGetVersion(&Version);
10019     }
10020 
10021     //---------------------------------------------------------------------------
10022     // Internal Helper Classes and Functions
10023     //---------------------------------------------------------------------------
10024 
10025     class StateChangedCallbackTranslator
10026     {
10027     public:
10028         StateChangedCallbackTranslator(StateChangedHandler handler, void* pCookie) : m_UserHandler(handler), m_pUserCookie(pCookie), m_hCallback(NULL) {}
10029 
10030         XnStatus Register(_XnRegisterStateChangeFuncPtr xnFunc, XnNodeHandle hNode)
10031         {
10032             return xnFunc(hNode, StateChangedCallback, this, &m_hCallback);
10033         }
10034 
10035         void Unregister(_XnUnregisterStateChangeFuncPtr xnFunc, XnNodeHandle hNode)
10036         {
10037             xnFunc(hNode, m_hCallback);
10038         }
10039 
10040         static XnStatus RegisterToUnderlying(_XnRegisterStateChangeFuncPtr xnFunc, XnNodeHandle hNode, StateChangedHandler handler, void* pCookie, XnCallbackHandle& hCallback)
10041         {
10042             XnStatus nRetVal = XN_STATUS_OK;
10043 
10044             StateChangedCallbackTranslator* pTrans;
10045             XN_VALIDATE_NEW(pTrans, StateChangedCallbackTranslator, handler, pCookie);
10046 
10047             nRetVal = pTrans->Register(xnFunc, hNode);
10048             if (nRetVal != XN_STATUS_OK)
10049             {
10050                 XN_DELETE(pTrans);
10051                 return (nRetVal);
10052             }
10053 
10054             hCallback = pTrans;
10055 
10056             return (XN_STATUS_OK);
10057         }
10058 
10059         static XnStatus UnregisterFromUnderlying(_XnUnregisterStateChangeFuncPtr xnFunc, XnNodeHandle hNode, XnCallbackHandle hCallback)
10060         {
10061             StateChangedCallbackTranslator* pTrans = (StateChangedCallbackTranslator*)hCallback;
10062             pTrans->Unregister(xnFunc, hNode);
10063             XN_DELETE(pTrans);
10064             return XN_STATUS_OK;
10065         }
10066 
10067     private:
10068         friend class GeneralIntCapability;
10069 
10070         typedef struct StateChangeCookie
10071         {
10072             StateChangedHandler userHandler;
10073             void* pUserCookie;
10074             XnCallbackHandle hCallback;
10075         } StateChangeCookie;
10076 
10077         static void XN_CALLBACK_TYPE StateChangedCallback(XnNodeHandle hNode, void* pCookie)
10078         {
10079             StateChangedCallbackTranslator* pTrans = (StateChangedCallbackTranslator*)pCookie;
10080             ProductionNode node(hNode);
10081             pTrans->m_UserHandler(node, pTrans->m_pUserCookie);
10082         }
10083 
10084         StateChangedHandler m_UserHandler;
10085         void* m_pUserCookie;
10086         XnCallbackHandle m_hCallback;
10087     };
10088 
10089     static XnStatus _RegisterToStateChange(_XnRegisterStateChangeFuncPtr xnFunc, XnNodeHandle hNode, StateChangedHandler handler, void* pCookie, XnCallbackHandle& hCallback)
10090     {
10091         return StateChangedCallbackTranslator::RegisterToUnderlying(xnFunc, hNode, handler, pCookie, hCallback);
10092     }
10093 
10094     static void _UnregisterFromStateChange(_XnUnregisterStateChangeFuncPtr xnFunc, XnNodeHandle hNode, XnCallbackHandle hCallback)
10095     {
10096         StateChangedCallbackTranslator::UnregisterFromUnderlying(xnFunc, hNode, hCallback);
10097     }
10098 
10099     inline XnStatus GeneralIntCapability::RegisterToValueChange(StateChangedHandler handler, void* pCookie, XnCallbackHandle& hCallback)
10100     {
10101         XnStatus nRetVal = XN_STATUS_OK;
10102 
10103         StateChangedCallbackTranslator* pTrans;
10104         XN_VALIDATE_NEW(pTrans, StateChangedCallbackTranslator, handler, pCookie);
10105 
10106         nRetVal = xnRegisterToGeneralIntValueChange(GetHandle(), m_strCap, pTrans->StateChangedCallback, pTrans, &pTrans->m_hCallback);
10107         if (nRetVal != XN_STATUS_OK)
10108         {
10109             XN_DELETE(pTrans);
10110             return (nRetVal);
10111         }
10112 
10113         hCallback = pTrans;
10114 
10115         return (XN_STATUS_OK);
10116     }
10117 
10118     inline void GeneralIntCapability::UnregisterFromValueChange(XnCallbackHandle hCallback)
10119     {
10120         StateChangedCallbackTranslator* pTrans = (StateChangedCallbackTranslator*)hCallback;
10121         xnUnregisterFromGeneralIntValueChange(GetHandle(), m_strCap, pTrans->m_hCallback);
10122         XN_DELETE(pTrans);
10123     }
10124 };
10125 
10126 #endif // __XN_CPP_WRAPPER_H__