Device* getDevice() { return g_Device.IsValid() ? &g_Device : NULL; }
XnStatus openDeviceFromXmlWithChoice(const char* csXmlFile, EnumerationErrors& errors) { XnStatus nRetVal = XN_STATUS_OK; xnLogInitFromXmlFile(csXmlFile); nRetVal = g_Context.Init(); XN_IS_STATUS_OK(nRetVal); // find devices NodeInfoList list; nRetVal = g_Context.EnumerateProductionTrees(XN_NODE_TYPE_DEVICE, NULL, list, &errors); XN_IS_STATUS_OK(nRetVal); printf("The following devices were found:\n"); int i = 1; for (NodeInfoList::Iterator it = list.Begin(); it != list.End(); ++it, ++i) { NodeInfo deviceNodeInfo = *it; Device deviceNode; deviceNodeInfo.GetInstance(deviceNode); XnBool bExists = deviceNode.IsValid(); if (!bExists) { g_Context.CreateProductionTree(deviceNodeInfo, deviceNode); // this might fail. } if (deviceNode.IsValid() && deviceNode.IsCapabilitySupported(XN_CAPABILITY_DEVICE_IDENTIFICATION)) { const XnUInt32 nStringBufferSize = 200; XnChar strDeviceName[nStringBufferSize]; XnChar strSerialNumber[nStringBufferSize]; XnUInt32 nLength = nStringBufferSize; deviceNode.GetIdentificationCap().GetDeviceName(strDeviceName, nLength); nLength = nStringBufferSize; deviceNode.GetIdentificationCap().GetSerialNumber(strSerialNumber, nLength); printf("[%d] %s (%s)\n", i, strDeviceName, strSerialNumber); } else { printf("[%d] %s\n", i, deviceNodeInfo.GetCreationInfo()); } // release the device if we created it if (!bExists && deviceNode.IsValid()) { deviceNode.Release(); } } printf("\n"); printf("Choose device to open (1): "); int chosen = 1; scanf("%d", &chosen); // create it NodeInfoList::Iterator it = list.Begin(); for (i = 1; i < chosen; ++i) { it++; } NodeInfo deviceNode = *it; nRetVal = g_Context.CreateProductionTree(deviceNode, g_Device); XN_IS_STATUS_OK(nRetVal); // now run the rest of the XML nRetVal = g_Context.RunXmlScriptFromFile(csXmlFile, g_scriptNode, &errors); XN_IS_STATUS_OK(nRetVal); openCommon(); return (XN_STATUS_OK); }