示例#1
0
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 XnStringsHash devicesSet;

    if (devicesSet.Size() == 0)
    {
        // search for a v6.0.1 device
        nRetVal = Enumerate(XN_SENSOR_6_0_1_PRODUCT_ID, devicesSet);
        XN_IS_STATUS_OK(nRetVal);

        // search for a v6.0 device
        nRetVal = Enumerate(XN_SENSOR_6_0_PRODUCT_ID, devicesSet);
        XN_IS_STATUS_OK(nRetVal);
    }
#else
    XnStringsHash devicesSet;

    // search for a v6.0.1 device
    nRetVal = Enumerate(XN_SENSOR_6_0_1_PRODUCT_ID, devicesSet);
    XN_IS_STATUS_OK(nRetVal);

    // search for a v6.0 device
    nRetVal = Enumerate(XN_SENSOR_6_0_PRODUCT_ID, devicesSet);
    XN_IS_STATUS_OK(nRetVal);

    // search for a v5.0 device
    nRetVal = Enumerate(XN_SENSOR_5_0_PRODUCT_ID, devicesSet);
    XN_IS_STATUS_OK(nRetVal);
#endif

    // now copy back
    XnUInt32 nCount = 0;
    for (XnStringsHash::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 XnSensorIO::EnumerateSensors(XnConnectionString* aConnectionStrings, XnUInt32* pnCount)
{
	XnStatus nRetVal = XN_STATUS_OK;
	XnBool bIsPresent = FALSE;

	nRetVal = xnUSBInit();
	if (nRetVal != XN_STATUS_OK && nRetVal != XN_STATUS_USB_ALREADY_INIT)
		return nRetVal;

	XnStringsHash devicesSet;

	// --avin mod--
	// search for a kinect device
	nRetVal = Enumerate(XN_SENSOR_PRODUCT_ID_KINECT, devicesSet);
	XN_IS_STATUS_OK(nRetVal);

	// now copy back
	XnUInt32 nCount = 0;
	for (XnStringsHash::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);
}
示例#3
0
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);
}
示例#4
0
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);
}