OpenNI 1.5.4
XnModuleCppRegistratration.h
Go to the documentation of this file.
1/****************************************************************************
2* *
3* OpenNI 1.x Alpha *
4* Copyright (C) 2011 PrimeSense Ltd. *
5* *
6* This file is part of OpenNI. *
7* *
8* OpenNI is free software: you can redistribute it and/or modify *
9* it under the terms of the GNU Lesser General Public License as published *
10* by the Free Software Foundation, either version 3 of the License, or *
11* (at your option) any later version. *
12* *
13* OpenNI is distributed in the hope that it will be useful, *
14* but WITHOUT ANY WARRANTY; without even the implied warranty of *
15* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16* GNU Lesser General Public License for more details. *
17* *
18* You should have received a copy of the GNU Lesser General Public License *
19* along with OpenNI. If not, see <http://www.gnu.org/licenses/>. *
20* *
21****************************************************************************/
22#ifndef __XN_MODULE_CPP_REGISTRATION_H__
23#define __XN_MODULE_CPP_REGISTRATION_H__
24
25//---------------------------------------------------------------------------
26// Includes
27//---------------------------------------------------------------------------
29#include <XnUtils.h>
30
31using namespace xn;
32
33//---------------------------------------------------------------------------
34// Internal Macros
35//---------------------------------------------------------------------------
37#define _XN_MODULE_INST g_pTheModule
38
39#define _CONCAT(a,b) a##b
40
41inline XnModuleNodeHandle __ModuleNodeToHandle(xn::ModuleProductionNode* pNode)
42{
43 return ((XnModuleNodeHandle)pNode);
44}
45
46#define __XN_EXPORT_NODE_COMMON(ExportedClass, ExportedName, Type) \
47 \
48 static ExportedClass* ExportedName = new ExportedClass(); \
49 \
50 void XN_CALLBACK_TYPE _CONCAT(ExportedClass,GetDescription)(XnProductionNodeDescription* pDescription) \
51 { \
52 ExportedName->GetDescription(pDescription); \
53 } \
54 \
55 XnStatus XN_CALLBACK_TYPE _CONCAT(ExportedClass,EnumerateProductionTrees) \
56 (XnContext* pContext, XnNodeInfoList* pTreesList, XnEnumerationErrors* pErrors) \
57 { \
58 Context context(pContext); \
59 NodeInfoList list(pTreesList); \
60 EnumerationErrors errors(pErrors); \
61 return ExportedName->EnumerateProductionTrees(context, list, pErrors == NULL ? NULL : &errors); \
62 } \
63 \
64 XnStatus XN_CALLBACK_TYPE _CONCAT(ExportedClass,Create)(XnContext* pContext, \
65 const XnChar* strInstanceName, \
66 const XnChar* strCreationInfo, \
67 XnNodeInfoList* pNeededTrees, \
68 const XnChar* strConfigurationDir, \
69 XnModuleNodeHandle* phInstance) \
70 { \
71 xn::NodeInfoList* pNeeded = NULL; \
72 if (pNeededTrees != NULL) \
73 { \
74 pNeeded = XN_NEW(xn::NodeInfoList, pNeededTrees); \
75 } \
76 ModuleProductionNode* pNode; \
77 Context context(pContext); \
78 XnStatus nRetVal = ExportedName->Create(context, strInstanceName, strCreationInfo, \
79 pNeeded, strConfigurationDir, &pNode); \
80 if (nRetVal != XN_STATUS_OK) \
81 { \
82 XN_DELETE(pNeeded); \
83 return (nRetVal); \
84 } \
85 *phInstance = __ModuleNodeToHandle(pNode); \
86 XN_DELETE(pNeeded); \
87 return (XN_STATUS_OK); \
88 } \
89 \
90 void XN_CALLBACK_TYPE _CONCAT(ExportedClass,Destroy)(XnModuleNodeHandle hInstance) \
91 { \
92 ModuleProductionNode* pNode = (ModuleProductionNode*)hInstance; \
93 ExportedName->Destroy(pNode); \
94 } \
95 \
96 void XN_CALLBACK_TYPE _CONCAT(ExportedClass,GetExportedInterface)( \
97 XnModuleExportedProductionNodeInterface* pInterface) \
98 { \
99 pInterface->GetDescription = _CONCAT(ExportedClass,GetDescription); \
100 pInterface->EnumerateProductionTrees = _CONCAT(ExportedClass,EnumerateProductionTrees); \
101 pInterface->Create = _CONCAT(ExportedClass,Create); \
102 pInterface->Destroy = _CONCAT(ExportedClass,Destroy); \
103 pInterface->GetInterface.General = __ModuleGetGetInterfaceFunc(Type); \
104 } \
105 \
106 static XnStatus _CONCAT(ExportedClass,RegisterResult) = \
107 _XN_MODULE_INST->AddExportedNode(_CONCAT(ExportedClass,GetExportedInterface));
108
109#define _XN_EXPORT_NODE_COMMON(ExportedClass, Type) \
110 __XN_EXPORT_NODE_COMMON(ExportedClass, _g_##ExportedClass, Type)
111
112//---------------------------------------------------------------------------
113// Forward Declarations
114//---------------------------------------------------------------------------
115
116void XN_CALLBACK_TYPE __ModuleGetProductionNodeInterface(XnModuleProductionNodeInterface* pInterface);
117void XN_CALLBACK_TYPE __ModuleGetDeviceInterface(XnModuleDeviceInterface* pInterface);
118void XN_CALLBACK_TYPE __ModuleGetGeneratorInterface(XnModuleGeneratorInterface* pInterface);
119void XN_CALLBACK_TYPE __ModuleGetMapGeneratorInterface(XnModuleMapGeneratorInterface* pInterface);
120void XN_CALLBACK_TYPE __ModuleGetDepthGeneratorInterface(XnModuleDepthGeneratorInterface* pInterface);
121void XN_CALLBACK_TYPE __ModuleGetImageGeneratorInterface(XnModuleImageGeneratorInterface* pInterface);
122void XN_CALLBACK_TYPE __ModuleGetIRGeneratorInterface(XnModuleIRGeneratorInterface* pInterface);
123void XN_CALLBACK_TYPE __ModuleGetUserGeneratorInterface(XnModuleUserGeneratorInterface* pInterface);
124void XN_CALLBACK_TYPE __ModuleGetHandsGeneratorInterface(XnModuleHandsGeneratorInterface* pInterface);
125void XN_CALLBACK_TYPE __ModuleGetGestureGeneratorInterface(XnModuleGestureGeneratorInterface* pInterface);
126void XN_CALLBACK_TYPE __ModuleGetSceneAnalyzerInterface(XnModuleSceneAnalyzerInterface* pInterface);
127void XN_CALLBACK_TYPE __ModuleGetAudioGeneratorInterface(XnModuleAudioGeneratorInterface* pInterface);
128void XN_CALLBACK_TYPE __ModuleGetRecorderInterface(XnModuleRecorderInterface* pInterface);
129void XN_CALLBACK_TYPE __ModuleGetPlayerInterface(XnModulePlayerInterface* pInterface);
130void XN_CALLBACK_TYPE __ModuleGetCodecInterface(XnModuleCodecInterface* pInterface);
131void XN_CALLBACK_TYPE __ModuleGetScriptNodeInterface(XnModuleScriptNodeInterface* pInterface);
132
133//---------------------------------------------------------------------------
134// Utility Macros
135//---------------------------------------------------------------------------
136
137typedef void (XN_CALLBACK_TYPE *GetInterfaceFuncPtr)(void* pInterface);
138
139static GetInterfaceFuncPtr __ModuleGetGetInterfaceFunc(XnProductionNodeType type)
140{
141 // start with concrete type
143 return (GetInterfaceFuncPtr)__ModuleGetDeviceInterface;
145 return (GetInterfaceFuncPtr)__ModuleGetDepthGeneratorInterface;
147 return (GetInterfaceFuncPtr)__ModuleGetImageGeneratorInterface;
148 else if (xnIsTypeDerivedFrom(type, XN_NODE_TYPE_IR))
149 return (GetInterfaceFuncPtr)__ModuleGetIRGeneratorInterface;
151 return (GetInterfaceFuncPtr)__ModuleGetUserGeneratorInterface;
153 return (GetInterfaceFuncPtr)__ModuleGetGestureGeneratorInterface;
155 return (GetInterfaceFuncPtr)__ModuleGetSceneAnalyzerInterface;
157 return (GetInterfaceFuncPtr)__ModuleGetAudioGeneratorInterface;
159 return (GetInterfaceFuncPtr)__ModuleGetRecorderInterface;
161 return (GetInterfaceFuncPtr)__ModuleGetPlayerInterface;
163 return (GetInterfaceFuncPtr)__ModuleGetHandsGeneratorInterface;
165 return (GetInterfaceFuncPtr)__ModuleGetCodecInterface;
167 return (GetInterfaceFuncPtr)__ModuleGetScriptNodeInterface;
168 // and continue with abstract ones
170 return (GetInterfaceFuncPtr)__ModuleGetMapGeneratorInterface;
172 return (GetInterfaceFuncPtr)__ModuleGetGeneratorInterface;
174 return (GetInterfaceFuncPtr)__ModuleGetProductionNodeInterface;
175
176 // unknown
177 XN_ASSERT(FALSE);
178 return NULL;
179}
180
182#if XN_PLATFORM_SUPPORTS_DYNAMIC_LIBS
183 #define XN_EXPORT_MODULE(ModuleClass) \
184 \
185 ModuleClass __moduleInstance; \
186 Module* _XN_MODULE_INST = &__moduleInstance;
187#else
188 #define XN_EXPORT_MODULE(ModuleClass) \
189 \
190 static ModuleClass __moduleInstance; \
191 static Module* _XN_MODULE_INST = &__moduleInstance;
192#endif
193
195#define XN_EXPORT_NODE(ExportedClass, nodeType) \
196 _XN_EXPORT_NODE_COMMON(ExportedClass, nodeType)
197
199#define XN_EXPORT_DEVICE(ExportedClass) \
200 _XN_EXPORT_NODE_COMMON(ExportedClass, XN_NODE_TYPE_DEVICE)
201
203#define XN_EXPORT_DEPTH(ExportedClass) \
204 _XN_EXPORT_NODE_COMMON(ExportedClass, XN_NODE_TYPE_DEPTH)
205
207#define XN_EXPORT_IMAGE(ExportedClass) \
208 _XN_EXPORT_NODE_COMMON(ExportedClass, XN_NODE_TYPE_IMAGE)
209
211#define XN_EXPORT_IR(ExportedClass) \
212 _XN_EXPORT_NODE_COMMON(ExportedClass, XN_NODE_TYPE_IR)
213
214#define XN_EXPORT_USER(ExportedClass) \
215 _XN_EXPORT_NODE_COMMON(ExportedClass, XN_NODE_TYPE_USER)
216
217#define XN_EXPORT_HANDS(ExportedClass) \
218 _XN_EXPORT_NODE_COMMON(ExportedClass, XN_NODE_TYPE_HANDS)
219
220#define XN_EXPORT_GESTURE(ExportedClass) \
221 _XN_EXPORT_NODE_COMMON(ExportedClass, XN_NODE_TYPE_GESTURE)
222
223#define XN_EXPORT_SCENE(ExportedClass) \
224 _XN_EXPORT_NODE_COMMON(ExportedClass, XN_NODE_TYPE_SCENE)
225
227#define XN_EXPORT_AUDIO(ExportedClass) \
228 _XN_EXPORT_NODE_COMMON(ExportedClass, XN_NODE_TYPE_AUDIO)
229
231#define XN_EXPORT_RECORDER(ExportedClass) \
232 _XN_EXPORT_NODE_COMMON(ExportedClass, XN_NODE_TYPE_RECORDER)
233
235#define XN_EXPORT_PLAYER(ExportedClass) \
236 _XN_EXPORT_NODE_COMMON(ExportedClass, XN_NODE_TYPE_PLAYER)
237
238#define XN_EXPORT_CODEC(ExportedClass) \
239 _XN_EXPORT_NODE_COMMON(ExportedClass, XN_NODE_TYPE_CODEC)
240
241#define XN_EXPORT_SCRIPT(ExportedClass) \
242 _XN_EXPORT_NODE_COMMON(ExportedClass, XN_NODE_TYPE_SCRIPT)
243
244//---------------------------------------------------------------------------
245// Exported C functions
246//---------------------------------------------------------------------------
247#if XN_PLATFORM_SUPPORTS_DYNAMIC_LIBS
248 #include <XnModuleCFunctions.h>
249 #define XN_MODULE_FUNC_TYPE XN_C_API_EXPORT
250 extern Module* _XN_MODULE_INST;
251#else
252 #define XN_MODULE_FUNC_TYPE static
253 static Module* _XN_MODULE_INST;
254#endif
255
257{
258 XnStatus nRetVal = XN_STATUS_OK;
259
260 nRetVal = _XN_MODULE_INST->Load();
261 XN_IS_STATUS_OK(nRetVal);
262
263 return (XN_STATUS_OK);
264}
265
267{
268 _XN_MODULE_INST->Unload();
269}
270
272{
273 return _XN_MODULE_INST->GetExportedNodesCount();
274}
275
277{
278 return _XN_MODULE_INST->GetExportedNodes(aEntryPoints, nCount);
279}
280
282{
283 pVersion->nMajor = XN_MAJOR_VERSION;
284 pVersion->nMinor = XN_MINOR_VERSION;
286 pVersion->nBuild = XN_BUILD_VERSION;
287}
288
289#if !XN_PLATFORM_SUPPORTS_DYNAMIC_LIBS
290#include <XnUtils.h>
291
292static XnOpenNIModuleInterface moduleInterface =
293{
299};
300static XnStatus registerResult = xnRegisterModuleWithOpenNI(&moduleInterface, NULL, __FILE__);
301#endif
302
303#endif // __XN_MODULE_CPP_REGISTRATION_H__
#define XN_IS_STATUS_OK(x)
Definition: XnMacros.h:60
void(* GetInterfaceFuncPtr)(void *pInterface)
Definition: XnModuleCppRegistratration.h:137
XN_MODULE_FUNC_TYPE void XN_C_DECL XN_MODULE_UNLOAD()
Definition: XnModuleCppRegistratration.h:266
XN_MODULE_FUNC_TYPE XnStatus XN_C_DECL XN_MODULE_GET_EXPORTED_NODES_ENTRY_POINTS(XnModuleGetExportedInterfacePtr *aEntryPoints, XnUInt32 nCount)
Definition: XnModuleCppRegistratration.h:276
XN_MODULE_FUNC_TYPE XnStatus XN_C_DECL XN_MODULE_LOAD()
Definition: XnModuleCppRegistratration.h:256
XN_MODULE_FUNC_TYPE void XN_C_DECL XN_MODULE_GET_OPEN_NI_VERSION(XnVersion *pVersion)
Definition: XnModuleCppRegistratration.h:281
XN_MODULE_FUNC_TYPE XnUInt32 XN_C_DECL XN_MODULE_GET_EXPORTED_NODES_COUNT()
Definition: XnModuleCppRegistratration.h:271
#define XN_MODULE_FUNC_TYPE
Definition: XnModuleCppRegistratration.h:252
void(* XnModuleGetExportedInterfacePtr)(XnModuleExportedProductionNodeInterface *pInterface)
Definition: XnModuleInterface.h:63
#define FALSE
Definition: XnPlatform.h:97
XnUInt32 XnStatus
Definition: XnStatus.h:34
#define XN_STATUS_OK
Definition: XnStatus.h:37
void * XnModuleNodeHandle
Definition: XnTypes.h:219
XnInt32 XnProductionNodeType
Definition: XnTypes.h:92
@ XN_NODE_TYPE_PLAYER
Definition: XnTypes.h:124
@ XN_NODE_TYPE_DEPTH
Definition: XnTypes.h:106
@ XN_NODE_TYPE_HANDS
Definition: XnTypes.h:133
@ XN_NODE_TYPE_MAP_GENERATOR
Definition: XnTypes.h:141
@ XN_NODE_TYPE_SCRIPT
Definition: XnTypes.h:142
@ XN_NODE_TYPE_DEVICE
Definition: XnTypes.h:103
@ XN_NODE_TYPE_IR
Definition: XnTypes.h:115
@ XN_NODE_TYPE_IMAGE
Definition: XnTypes.h:109
@ XN_NODE_TYPE_AUDIO
Definition: XnTypes.h:112
@ XN_NODE_TYPE_CODEC
Definition: XnTypes.h:136
@ XN_NODE_TYPE_PRODUCTION_NODE
Definition: XnTypes.h:139
@ XN_NODE_TYPE_GENERATOR
Definition: XnTypes.h:140
@ XN_NODE_TYPE_GESTURE
Definition: XnTypes.h:127
@ XN_NODE_TYPE_RECORDER
Definition: XnTypes.h:121
@ XN_NODE_TYPE_USER
Definition: XnTypes.h:118
@ XN_NODE_TYPE_SCENE
Definition: XnTypes.h:130
#define XN_BUILD_VERSION
Definition: XnVersion.h:40
#define XN_MAJOR_VERSION
Definition: XnVersion.h:34
#define XN_MINOR_VERSION
Definition: XnVersion.h:36
#define XN_MAINTENANCE_VERSION
Definition: XnVersion.h:38
Definition: XnModuleCppInterface.h:48
Definition: XnModuleCppInterface.h:152
XN_C_API XnStatus XN_C_DECL xnRegisterModuleWithOpenNI(XnOpenNIModuleInterface *pInterface, const XnChar *strConfigDir, const XnChar *strName)
XN_C_API XnBool XN_C_DECL xnIsTypeDerivedFrom(XnProductionNodeType type, XnProductionNodeType base)
Checks if a certain production node type is a derived of another type.
Definition: XnCppWrapper.h:35
Definition: XnModuleInterface.h:1315
Definition: XnModuleInterface.h:1330
Definition: XnModuleInterface.h:1028
Definition: XnModuleInterface.h:413
Definition: XnModuleInterface.h:574
Definition: XnModuleInterface.h:1160
Definition: XnModuleInterface.h:1203
Definition: XnModuleInterface.h:1145
Definition: XnModuleInterface.h:1088
Definition: XnModuleInterface.h:886
Definition: XnModuleInterface.h:716
Definition: XnModuleInterface.h:326
Definition: XnModuleInterface.h:700
Definition: XnModuleInterface.h:1186
Definition: XnModuleInterface.h:1341
Definition: XnModuleInterface.h:1287
Definition: XnModuleInterface.h:71
Definition: XnTypes.h:152
XnUInt8 nMinor
Definition: XnTypes.h:154
XnUInt8 nMajor
Definition: XnTypes.h:153
XnUInt16 nMaintenance
Definition: XnTypes.h:155
XnUInt32 nBuild
Definition: XnTypes.h:156