OpenNI 1.5.7
XnModuleCppRegistratration.h
Go to the documentation of this file.
1/*****************************************************************************
2* *
3* OpenNI 1.x Alpha *
4* Copyright (C) 2012 PrimeSense Ltd. *
5* *
6* This file is part of OpenNI. *
7* *
8* Licensed under the Apache License, Version 2.0 (the "License"); *
9* you may not use this file except in compliance with the License. *
10* You may obtain a copy of the License at *
11* *
12* http://www.apache.org/licenses/LICENSE-2.0 *
13* *
14* Unless required by applicable law or agreed to in writing, software *
15* distributed under the License is distributed on an "AS IS" BASIS, *
16* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
17* See the License for the specific language governing permissions and *
18* limitations under the License. *
19* *
20*****************************************************************************/
21#ifndef __XN_MODULE_CPP_REGISTRATION_H__
22#define __XN_MODULE_CPP_REGISTRATION_H__
23
24//---------------------------------------------------------------------------
25// Includes
26//---------------------------------------------------------------------------
28#include <XnUtils.h>
29
30using namespace xn;
31
32//---------------------------------------------------------------------------
33// Internal Macros
34//---------------------------------------------------------------------------
36#define _XN_MODULE_INST g_pTheModule
37
38#define _CONCAT(a,b) a##b
39
40inline XnModuleNodeHandle __ModuleNodeToHandle(xn::ModuleProductionNode* pNode)
41{
42 return ((XnModuleNodeHandle)pNode);
43}
44
45#define __XN_EXPORT_NODE_COMMON(ExportedClass, ExportedName, Type) \
46 \
47 static ExportedClass* ExportedName = new ExportedClass(); \
48 \
49 void XN_CALLBACK_TYPE _CONCAT(ExportedClass,GetDescription)(XnProductionNodeDescription* pDescription) \
50 { \
51 ExportedName->GetDescription(pDescription); \
52 } \
53 \
54 XnStatus XN_CALLBACK_TYPE _CONCAT(ExportedClass,EnumerateProductionTrees) \
55 (XnContext* pContext, XnNodeInfoList* pTreesList, XnEnumerationErrors* pErrors) \
56 { \
57 Context context(pContext); \
58 NodeInfoList list(pTreesList); \
59 EnumerationErrors errors(pErrors); \
60 return ExportedName->EnumerateProductionTrees(context, list, pErrors == NULL ? NULL : &errors); \
61 } \
62 \
63 XnStatus XN_CALLBACK_TYPE _CONCAT(ExportedClass,Create)(XnContext* pContext, \
64 const XnChar* strInstanceName, \
65 const XnChar* strCreationInfo, \
66 XnNodeInfoList* pNeededTrees, \
67 const XnChar* strConfigurationDir, \
68 XnModuleNodeHandle* phInstance) \
69 { \
70 xn::NodeInfoList* pNeeded = NULL; \
71 if (pNeededTrees != NULL) \
72 { \
73 pNeeded = XN_NEW(xn::NodeInfoList, pNeededTrees); \
74 } \
75 ModuleProductionNode* pNode; \
76 Context context(pContext); \
77 XnStatus nRetVal = ExportedName->Create(context, strInstanceName, strCreationInfo, \
78 pNeeded, strConfigurationDir, &pNode); \
79 if (nRetVal != XN_STATUS_OK) \
80 { \
81 XN_DELETE(pNeeded); \
82 return (nRetVal); \
83 } \
84 *phInstance = __ModuleNodeToHandle(pNode); \
85 XN_DELETE(pNeeded); \
86 return (XN_STATUS_OK); \
87 } \
88 \
89 void XN_CALLBACK_TYPE _CONCAT(ExportedClass,Destroy)(XnModuleNodeHandle hInstance) \
90 { \
91 ModuleProductionNode* pNode = (ModuleProductionNode*)hInstance; \
92 ExportedName->Destroy(pNode); \
93 } \
94 \
95 void XN_CALLBACK_TYPE _CONCAT(ExportedClass,GetExportedInterface)( \
96 XnModuleExportedProductionNodeInterface* pInterface) \
97 { \
98 pInterface->GetDescription = _CONCAT(ExportedClass,GetDescription); \
99 pInterface->EnumerateProductionTrees = _CONCAT(ExportedClass,EnumerateProductionTrees); \
100 pInterface->Create = _CONCAT(ExportedClass,Create); \
101 pInterface->Destroy = _CONCAT(ExportedClass,Destroy); \
102 pInterface->GetInterface.General = __ModuleGetGetInterfaceFunc(Type); \
103 } \
104 \
105 static XnStatus _CONCAT(ExportedClass,RegisterResult) = \
106 _XN_MODULE_INST->AddExportedNode(_CONCAT(ExportedClass,GetExportedInterface));
107
108#define _XN_EXPORT_NODE_COMMON(ExportedClass, Type) \
109 __XN_EXPORT_NODE_COMMON(ExportedClass, _g_##ExportedClass, Type)
110
111//---------------------------------------------------------------------------
112// Forward Declarations
113//---------------------------------------------------------------------------
114
115void XN_CALLBACK_TYPE __ModuleGetProductionNodeInterface(XnModuleProductionNodeInterface* pInterface);
116void XN_CALLBACK_TYPE __ModuleGetDeviceInterface(XnModuleDeviceInterface* pInterface);
117void XN_CALLBACK_TYPE __ModuleGetGeneratorInterface(XnModuleGeneratorInterface* pInterface);
118void XN_CALLBACK_TYPE __ModuleGetMapGeneratorInterface(XnModuleMapGeneratorInterface* pInterface);
119void XN_CALLBACK_TYPE __ModuleGetDepthGeneratorInterface(XnModuleDepthGeneratorInterface* pInterface);
120void XN_CALLBACK_TYPE __ModuleGetImageGeneratorInterface(XnModuleImageGeneratorInterface* pInterface);
121void XN_CALLBACK_TYPE __ModuleGetIRGeneratorInterface(XnModuleIRGeneratorInterface* pInterface);
122void XN_CALLBACK_TYPE __ModuleGetUserGeneratorInterface(XnModuleUserGeneratorInterface* pInterface);
123void XN_CALLBACK_TYPE __ModuleGetHandsGeneratorInterface(XnModuleHandsGeneratorInterface* pInterface);
124void XN_CALLBACK_TYPE __ModuleGetGestureGeneratorInterface(XnModuleGestureGeneratorInterface* pInterface);
125void XN_CALLBACK_TYPE __ModuleGetSceneAnalyzerInterface(XnModuleSceneAnalyzerInterface* pInterface);
126void XN_CALLBACK_TYPE __ModuleGetAudioGeneratorInterface(XnModuleAudioGeneratorInterface* pInterface);
127void XN_CALLBACK_TYPE __ModuleGetRecorderInterface(XnModuleRecorderInterface* pInterface);
128void XN_CALLBACK_TYPE __ModuleGetPlayerInterface(XnModulePlayerInterface* pInterface);
129void XN_CALLBACK_TYPE __ModuleGetCodecInterface(XnModuleCodecInterface* pInterface);
130void XN_CALLBACK_TYPE __ModuleGetScriptNodeInterface(XnModuleScriptNodeInterface* pInterface);
131
132//---------------------------------------------------------------------------
133// Utility Macros
134//---------------------------------------------------------------------------
135
136typedef void (XN_CALLBACK_TYPE *GetInterfaceFuncPtr)(void* pInterface);
137
138static GetInterfaceFuncPtr __ModuleGetGetInterfaceFunc(XnProductionNodeType type)
139{
140 // start with concrete type
142 return (GetInterfaceFuncPtr)__ModuleGetDeviceInterface;
144 return (GetInterfaceFuncPtr)__ModuleGetDepthGeneratorInterface;
146 return (GetInterfaceFuncPtr)__ModuleGetImageGeneratorInterface;
147 else if (xnIsTypeDerivedFrom(type, XN_NODE_TYPE_IR))
148 return (GetInterfaceFuncPtr)__ModuleGetIRGeneratorInterface;
150 return (GetInterfaceFuncPtr)__ModuleGetUserGeneratorInterface;
152 return (GetInterfaceFuncPtr)__ModuleGetGestureGeneratorInterface;
154 return (GetInterfaceFuncPtr)__ModuleGetSceneAnalyzerInterface;
156 return (GetInterfaceFuncPtr)__ModuleGetAudioGeneratorInterface;
158 return (GetInterfaceFuncPtr)__ModuleGetRecorderInterface;
160 return (GetInterfaceFuncPtr)__ModuleGetPlayerInterface;
162 return (GetInterfaceFuncPtr)__ModuleGetHandsGeneratorInterface;
164 return (GetInterfaceFuncPtr)__ModuleGetCodecInterface;
166 return (GetInterfaceFuncPtr)__ModuleGetScriptNodeInterface;
167 // and continue with abstract ones
169 return (GetInterfaceFuncPtr)__ModuleGetMapGeneratorInterface;
171 return (GetInterfaceFuncPtr)__ModuleGetGeneratorInterface;
173 return (GetInterfaceFuncPtr)__ModuleGetProductionNodeInterface;
174
175 // unknown
176 XN_ASSERT(FALSE);
177 return NULL;
178}
179
181#if XN_PLATFORM_SUPPORTS_DYNAMIC_LIBS
182 #define XN_EXPORT_MODULE(ModuleClass) \
183 \
184 ModuleClass __moduleInstance; \
185 Module* _XN_MODULE_INST = &__moduleInstance;
186#else
187 #define XN_EXPORT_MODULE(ModuleClass) \
188 \
189 static ModuleClass __moduleInstance; \
190 static Module* _XN_MODULE_INST = &__moduleInstance;
191#endif
192
194#define XN_EXPORT_NODE(ExportedClass, nodeType) \
195 _XN_EXPORT_NODE_COMMON(ExportedClass, nodeType)
196
198#define XN_EXPORT_DEVICE(ExportedClass) \
199 _XN_EXPORT_NODE_COMMON(ExportedClass, XN_NODE_TYPE_DEVICE)
200
202#define XN_EXPORT_DEPTH(ExportedClass) \
203 _XN_EXPORT_NODE_COMMON(ExportedClass, XN_NODE_TYPE_DEPTH)
204
206#define XN_EXPORT_IMAGE(ExportedClass) \
207 _XN_EXPORT_NODE_COMMON(ExportedClass, XN_NODE_TYPE_IMAGE)
208
210#define XN_EXPORT_IR(ExportedClass) \
211 _XN_EXPORT_NODE_COMMON(ExportedClass, XN_NODE_TYPE_IR)
212
213#define XN_EXPORT_USER(ExportedClass) \
214 _XN_EXPORT_NODE_COMMON(ExportedClass, XN_NODE_TYPE_USER)
215
216#define XN_EXPORT_HANDS(ExportedClass) \
217 _XN_EXPORT_NODE_COMMON(ExportedClass, XN_NODE_TYPE_HANDS)
218
219#define XN_EXPORT_GESTURE(ExportedClass) \
220 _XN_EXPORT_NODE_COMMON(ExportedClass, XN_NODE_TYPE_GESTURE)
221
222#define XN_EXPORT_SCENE(ExportedClass) \
223 _XN_EXPORT_NODE_COMMON(ExportedClass, XN_NODE_TYPE_SCENE)
224
226#define XN_EXPORT_AUDIO(ExportedClass) \
227 _XN_EXPORT_NODE_COMMON(ExportedClass, XN_NODE_TYPE_AUDIO)
228
230#define XN_EXPORT_RECORDER(ExportedClass) \
231 _XN_EXPORT_NODE_COMMON(ExportedClass, XN_NODE_TYPE_RECORDER)
232
234#define XN_EXPORT_PLAYER(ExportedClass) \
235 _XN_EXPORT_NODE_COMMON(ExportedClass, XN_NODE_TYPE_PLAYER)
236
237#define XN_EXPORT_CODEC(ExportedClass) \
238 _XN_EXPORT_NODE_COMMON(ExportedClass, XN_NODE_TYPE_CODEC)
239
240#define XN_EXPORT_SCRIPT(ExportedClass) \
241 _XN_EXPORT_NODE_COMMON(ExportedClass, XN_NODE_TYPE_SCRIPT)
242
243//---------------------------------------------------------------------------
244// Exported C functions
245//---------------------------------------------------------------------------
246#if XN_PLATFORM_SUPPORTS_DYNAMIC_LIBS
247 #include <XnModuleCFunctions.h>
248 #define XN_MODULE_FUNC_TYPE XN_C_API_EXPORT
249 extern Module* _XN_MODULE_INST;
250#else
251 #define XN_MODULE_FUNC_TYPE static
252 static Module* _XN_MODULE_INST;
253#endif
254
256{
257 XnStatus nRetVal = XN_STATUS_OK;
258
259 nRetVal = _XN_MODULE_INST->Load();
260 XN_IS_STATUS_OK(nRetVal);
261
262 return (XN_STATUS_OK);
263}
264
266{
267 _XN_MODULE_INST->Unload();
268}
269
271{
272 return _XN_MODULE_INST->GetExportedNodesCount();
273}
274
276{
277 return _XN_MODULE_INST->GetExportedNodes(aEntryPoints, nCount);
278}
279
281{
282 pVersion->nMajor = XN_MAJOR_VERSION;
283 pVersion->nMinor = XN_MINOR_VERSION;
285 pVersion->nBuild = XN_BUILD_VERSION;
286}
287
288#if !XN_PLATFORM_SUPPORTS_DYNAMIC_LIBS
289#include <XnUtils.h>
290
291static XnOpenNIModuleInterface moduleInterface =
292{
298};
299static XnStatus registerResult = xnRegisterModuleWithOpenNI(&moduleInterface, NULL, __FILE__);
300#endif
301
302#endif // __XN_MODULE_CPP_REGISTRATION_H__
#define XN_IS_STATUS_OK(x)
Definition: XnMacros.h:59
void(* GetInterfaceFuncPtr)(void *pInterface)
Definition: XnModuleCppRegistratration.h:136
XN_MODULE_FUNC_TYPE void XN_C_DECL XN_MODULE_UNLOAD()
Definition: XnModuleCppRegistratration.h:265
XN_MODULE_FUNC_TYPE XnStatus XN_C_DECL XN_MODULE_LOAD()
Definition: XnModuleCppRegistratration.h:255
XN_MODULE_FUNC_TYPE XnUInt32 XN_C_DECL XN_MODULE_GET_EXPORTED_NODES_COUNT()
Definition: XnModuleCppRegistratration.h:270
#define XN_MODULE_FUNC_TYPE
Definition: XnModuleCppRegistratration.h:251
#define XN_MODULE_GET_OPEN_NI_VERSION
Definition: XnModuleInterface.h:36
#define XN_MODULE_GET_EXPORTED_NODES_ENTRY_POINTS
Definition: XnModuleInterface.h:35
void(* XnModuleGetExportedInterfacePtr)(XnModuleExportedProductionNodeInterface *pInterface)
Definition: XnModuleInterface.h:62
#define FALSE
Definition: XnPlatform.h:89
XnUInt32 XnStatus
Definition: XnStatus.h:33
#define XN_STATUS_OK
Definition: XnStatus.h:36
void * XnModuleNodeHandle
Definition: XnTypes.h:221
XnInt32 XnProductionNodeType
Definition: XnTypes.h:94
@ XN_NODE_TYPE_PLAYER
Definition: XnTypes.h:126
@ XN_NODE_TYPE_DEPTH
Definition: XnTypes.h:108
@ XN_NODE_TYPE_HANDS
Definition: XnTypes.h:135
@ XN_NODE_TYPE_MAP_GENERATOR
Definition: XnTypes.h:143
@ XN_NODE_TYPE_SCRIPT
Definition: XnTypes.h:144
@ XN_NODE_TYPE_DEVICE
Definition: XnTypes.h:105
@ XN_NODE_TYPE_IR
Definition: XnTypes.h:117
@ XN_NODE_TYPE_IMAGE
Definition: XnTypes.h:111
@ XN_NODE_TYPE_AUDIO
Definition: XnTypes.h:114
@ XN_NODE_TYPE_CODEC
Definition: XnTypes.h:138
@ XN_NODE_TYPE_PRODUCTION_NODE
Definition: XnTypes.h:141
@ XN_NODE_TYPE_GENERATOR
Definition: XnTypes.h:142
@ XN_NODE_TYPE_GESTURE
Definition: XnTypes.h:129
@ XN_NODE_TYPE_RECORDER
Definition: XnTypes.h:123
@ XN_NODE_TYPE_USER
Definition: XnTypes.h:120
@ XN_NODE_TYPE_SCENE
Definition: XnTypes.h:132
#define XN_BUILD_VERSION
Definition: XnVersion.h:39
#define XN_MAJOR_VERSION
Definition: XnVersion.h:33
#define XN_MINOR_VERSION
Definition: XnVersion.h:35
#define XN_MAINTENANCE_VERSION
Definition: XnVersion.h:37
Definition: XnModuleCppInterface.h:47
Definition: XnModuleCppInterface.h:151
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:34
Definition: XnModuleInterface.h:1326
Definition: XnModuleInterface.h:1341
Definition: XnModuleInterface.h:1039
Definition: XnModuleInterface.h:412
Definition: XnModuleInterface.h:585
Definition: XnModuleInterface.h:1171
Definition: XnModuleInterface.h:1214
Definition: XnModuleInterface.h:1156
Definition: XnModuleInterface.h:1099
Definition: XnModuleInterface.h:897
Definition: XnModuleInterface.h:727
Definition: XnModuleInterface.h:325
Definition: XnModuleInterface.h:711
Definition: XnModuleInterface.h:1197
Definition: XnModuleInterface.h:1352
Definition: XnModuleInterface.h:1298
Definition: XnModuleInterface.h:70
Definition: XnTypes.h:154
XnUInt8 nMinor
Definition: XnTypes.h:156
XnUInt8 nMajor
Definition: XnTypes.h:155
XnUInt16 nMaintenance
Definition: XnTypes.h:157
XnUInt32 nBuild
Definition: XnTypes.h:158