XnStatus XnDeviceFileReader::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. XnStringsSet StreamsToRemove; nRetVal = StreamsToRemove.Set(strName); XN_IS_STATUS_OK(nRetVal); XnPackedDataType nType = XN_PACKED_STREAM_REMOVED; XnUInt64 nPositionBefore; for (;;) { nRetVal = GetIOStream()->Tell(&nPositionBefore); XN_IS_STATUS_OK(nRetVal); nRetVal = GetDataPacker()->ReadNextObject(&nType); XN_IS_STATUS_OK(nRetVal); if (nType == XN_PACKED_STREAM_REMOVED) { XnChar strTempName[XN_DEVICE_MAX_STRING_LENGTH]; nRetVal = GetDataPacker()->ReadStreamRemoved(strTempName); XN_IS_STATUS_OK(nRetVal); nRetVal = StreamsToRemove.Set(strTempName); XN_IS_STATUS_OK(nRetVal); } else { break; } } if (nType != XN_PACKED_END) { // Not the case we were looking for. Remove those streams. for (XnStringsSet::Iterator it = StreamsToRemove.Begin(); it != StreamsToRemove.End(); ++it) { nRetVal = XnStreamReaderDevice::HandleStreamRemoved(it->Key()); XN_IS_STATUS_OK(nRetVal); } } // 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 = GetIOStream()->Seek(nPositionBefore); XN_IS_STATUS_OK(nRetVal); return (XN_STATUS_OK); }
XnStatus XnSensorIO::EnumerateSensors(XnConnectionString* aConnectionStrings, XnUInt32* pnCount) { XnStatus nRetVal = XN_STATUS_OK; nRetVal = xnUSBInit(); if (nRetVal != XN_STATUS_OK && nRetVal != XN_STATUS_USB_ALREADY_INIT) return nRetVal; // Temporary patch: "Cache" the devices since running USB enum on the MacOSX platform takes several seconds due to problems in libusb! #if (XN_PLATFORM == XN_PLATFORM_MACOSX) static XnStringsSet devicesSet; if (devicesSet.Size() == 0) { // search for supported devices for (XnUInt32 i = 0; i < ms_supportedProductsCount; ++i) { nRetVal = Enumerate(ms_supportedProducts[i], devicesSet); XN_IS_STATUS_OK(nRetVal); } } #else XnStringsSet devicesSet; // search for supported devices for (XnUInt32 i = 0; i < ms_supportedProductsCount; ++i) { nRetVal = Enumerate(ms_supportedProducts[i], devicesSet); XN_IS_STATUS_OK(nRetVal); } #endif // now copy back XnUInt32 nCount = 0; for (XnStringsSet::ConstIterator it = devicesSet.Begin(); it != devicesSet.End(); ++it, ++nCount) { if (nCount < *pnCount) { strcpy(aConnectionStrings[nCount], it->Key()); } } if (nCount > *pnCount) { *pnCount = nCount; return XN_STATUS_OUTPUT_BUFFER_OVERFLOW; } // All is good... *pnCount = nCount; return (XN_STATUS_OK); }
XnStatus Enumerate(XnUInt16 nProduct, XnStringsSet& devicesSet) { XnStatus nRetVal = XN_STATUS_OK; const XnUSBConnectionString* astrDevicePaths; XnUInt32 nCount; nRetVal = xnUSBEnumerateDevices(XN_SENSOR_VENDOR_ID, nProduct, &astrDevicePaths, &nCount); XN_IS_STATUS_OK(nRetVal); for (XnUInt32 i = 0; i < nCount; ++i) { nRetVal = devicesSet.Set(astrDevicePaths[i]); 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. XnStringsSet StreamsToRemove; nRetVal = StreamsToRemove.Set(strName); XN_IS_STATUS_OK(nRetVal); XnPackedDataType nType = XN_PACKED_STREAM_REMOVED; XnUInt32 nPositionBefore; for (;;) { 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); XN_IS_STATUS_OK(nRetVal); } else { break; } } if (nType != XN_PACKED_END) { // Not the case we were looking for. Remove those streams. for (XnStringsSet::Iterator it = StreamsToRemove.Begin(); it != StreamsToRemove.End(); ++it) { nRetVal = m_pNotifications->OnNodeRemoved(m_pNotificationsCookie, it->Key()); XN_IS_STATUS_OK(nRetVal); XnNodeInfo* pNodeInfo = NULL; 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); }