MCPcopy Create free account
hub / github.com/OpenNI/OpenNI / openDeviceFromXmlWithChoice

Function openDeviceFromXmlWithChoice

Samples/NiViewer/Device.cpp:195–271  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

193}
194
195XnStatus openDeviceFromXmlWithChoice(const char* csXmlFile, EnumerationErrors& errors)
196{
197 XnStatus nRetVal = XN_STATUS_OK;
198
199 xnLogInitFromXmlFile(csXmlFile);
200
201 nRetVal = g_Context.Init();
202 XN_IS_STATUS_OK(nRetVal);
203
204 // find devices
205 NodeInfoList list;
206 nRetVal = g_Context.EnumerateProductionTrees(XN_NODE_TYPE_DEVICE, NULL, list, &errors);
207 XN_IS_STATUS_OK(nRetVal);
208
209 printf("The following devices were found:\n");
210 int i = 1;
211 for (NodeInfoList::Iterator it = list.Begin(); it != list.End(); ++it, ++i)
212 {
213 NodeInfo deviceNodeInfo = *it;
214
215 Device deviceNode;
216 deviceNodeInfo.GetInstance(deviceNode);
217 XnBool bExists = deviceNode.IsValid();
218 if (!bExists)
219 {
220 g_Context.CreateProductionTree(deviceNodeInfo, deviceNode);
221 // this might fail.
222 }
223
224 if (deviceNode.IsValid() && deviceNode.IsCapabilitySupported(XN_CAPABILITY_DEVICE_IDENTIFICATION))
225 {
226 const XnUInt32 nStringBufferSize = 200;
227 XnChar strDeviceName[nStringBufferSize];
228 XnChar strSerialNumber[nStringBufferSize];
229
230 XnUInt32 nLength = nStringBufferSize;
231 deviceNode.GetIdentificationCap().GetDeviceName(strDeviceName, nLength);
232 nLength = nStringBufferSize;
233 deviceNode.GetIdentificationCap().GetSerialNumber(strSerialNumber, nLength);
234 printf("[%d] %s (%s)\n", i, strDeviceName, strSerialNumber);
235 }
236 else
237 {
238 printf("[%d] %s\n", i, deviceNodeInfo.GetCreationInfo());
239 }
240
241 // release the device if we created it
242 if (!bExists && deviceNode.IsValid())
243 {
244 deviceNode.Release();
245 }
246 }
247 printf("\n");
248 printf("Choose device to open (1): ");
249
250 int chosen = 1;
251 scanf("%d", &chosen);
252

Callers 1

mainFunction · 0.85

Calls 15

xnLogInitFromXmlFileFunction · 0.85
openCommonFunction · 0.85
CreateProductionTreeMethod · 0.80
GetDeviceNameMethod · 0.80
GetIdentificationCapMethod · 0.80
GetSerialNumberMethod · 0.80
GetCreationInfoMethod · 0.80
RunXmlScriptFromFileMethod · 0.80
InitMethod · 0.45
BeginMethod · 0.45
EndMethod · 0.45

Tested by

no test coverage detected