XnStatus Enumerate(XnUInt16 nVendor, XnUInt16 nProduct, XnStringsHash& devicesSet) { XnStatus nRetVal = XN_STATUS_OK; const XnUSBConnectionString* astrDevicePaths; XnUInt32 nCount; nRetVal = xnUSBEnumerateDevices(nVendor, nProduct, &astrDevicePaths, &nCount); XN_IS_STATUS_OK(nRetVal); for (XnUInt32 i = 0; i < nCount; ++i) { nRetVal = devicesSet.Set(astrDevicePaths[i], NULL); XN_IS_STATUS_OK(nRetVal); } xnUSBFreeDevicesList(astrDevicePaths); return (XN_STATUS_OK); }
XnStatus XnFileDevice::HandleStreamRemoved(const XnChar* strName) { XnStatus nRetVal = XN_STATUS_OK; // check for specific case: all streams are removed and then end-of-file is reached. // in this case, we don't really want to destroy streams, just wrap around. XnStringsHash StreamsToRemove; nRetVal = StreamsToRemove.Set(strName, NULL); XN_IS_STATUS_OK(nRetVal); XnPackedDataType nType = XN_PACKED_STREAM_REMOVED; XnUInt32 nPositionBefore; while (TRUE) { nRetVal = m_pInputStream->Tell(&nPositionBefore); XN_IS_STATUS_OK(nRetVal); nRetVal = m_pDataPacker->ReadNextObject(&nType); XN_IS_STATUS_OK(nRetVal); if (nType == XN_PACKED_STREAM_REMOVED) { XnChar strTempName[XN_DEVICE_MAX_STRING_LENGTH]; nRetVal = m_pDataPacker->ReadStreamRemoved(strTempName); XN_IS_STATUS_OK(nRetVal); nRetVal = StreamsToRemove.Set(strTempName, NULL); XN_IS_STATUS_OK(nRetVal); } else { break; } } if (nType != XN_PACKED_END) { // Not the case we were looking for. Remove those streams. for (XnStringsHash::Iterator it = StreamsToRemove.begin(); it != StreamsToRemove.end(); ++it) { nRetVal = m_pNotifications->OnNodeRemoved(m_pNotificationsCookie, it.Key()); XN_IS_STATUS_OK(nRetVal); XnNodeInfo* pNodeInfo; m_nodeInfoMap.Get(it.Key(), pNodeInfo); XN_DELETE(pNodeInfo->pXnCodec); m_nodeInfoMap.Remove(it.Key()); m_ignoreNewNodes.Remove(it.Key()); } m_bNodeCollectionChanged = TRUE; } // in any case, the last object we read wasn't handled yet (end-of-stream or another event), so // seek back, so it will be handled. nRetVal = m_pInputStream->Seek(nPositionBefore); XN_IS_STATUS_OK(nRetVal); return (XN_STATUS_OK); }