Beispiel #1
0
XnStatus XnFileDevice::SetInitialState(XnPropertySet* pSet)
{
    XnStatus nRetVal = XN_STATUS_OK;

    // Fix state (remove some properties that we don't wish to reflect in reader device)
    XnActualPropertiesHash* pDeviceModule = NULL;
    if (XN_STATUS_OK == pSet->pData->Get(XN_MODULE_NAME_DEVICE, pDeviceModule))
    {
        pDeviceModule->Remove(XN_MODULE_PROPERTY_READ_WRITE_MODE);
        pDeviceModule->Remove(XN_MODULE_PROPERTY_PRIMARY_STREAM);

        // check for timestamps resolution
        XnActualIntProperty* pIntProp = NULL;
        if (XN_STATUS_OK == pDeviceModule->Get(XN_MODULE_PROPERTY_HIGH_RES_TIMESTAMPS, (XnProperty*&)pIntProp))
        {
            m_bHighresTimestamps = (pIntProp->GetValue() == TRUE);
        }
    }

    // TODO: create DEVICE node

    // now create the rest of the modules and streams (DEVICE was already created)
    XnPropertySetData* pPropSetData = pSet->pData;
    for (XnPropertySetData::ConstIterator it = pPropSetData->Begin(); it != pPropSetData->End(); ++it)
    {
        // ignore module DEVICE
        if (strcmp(XN_MODULE_NAME_DEVICE, it->Key()) == 0)
        {
            continue;
        }

        // check if this is a stream
        XnActualPropertiesHash::ConstIterator itProp = it->Value()->End();
        if (XN_STATUS_OK == it->Value()->Find(XN_STREAM_PROPERTY_TYPE, itProp))
        {
            XnActualStringProperty* pTypeProp = (XnActualStringProperty*)itProp->Value();
            nRetVal = HandleNewStream(pTypeProp->GetValue(), it->Key(), it->Value());
            XN_IS_STATUS_OK(nRetVal);
        }
    } // modules loop

    return (XN_STATUS_OK);
}
XnStatus XnStreamReaderDevice::SetInitialState(const XnDeviceConfig* pDeviceConfig, XnPropertySet* pSet)
{
	XnStatus nRetVal = XN_STATUS_OK;
	
	// Fix state (remove some properties that we don't wish to reflect in reader device)
	XnActualPropertiesHash* pDeviceModule = NULL;
	if (XN_STATUS_OK == pSet->pData->Get(XN_MODULE_NAME_DEVICE, pDeviceModule))
	{
		pDeviceModule->Remove(XN_MODULE_PROPERTY_READ_WRITE_MODE);
		pDeviceModule->Remove(XN_MODULE_PROPERTY_PRIMARY_STREAM);
	}

	// now init base using this state (this will also create module DEVICE)
	XnDeviceConfig initConfig;
	initConfig.cpConnectionString = pDeviceConfig->cpConnectionString;
	initConfig.DeviceMode = pDeviceConfig->DeviceMode;
	initConfig.pInitialValues = pSet;
	initConfig.SharingMode = pDeviceConfig->SharingMode;

	nRetVal = XnStreamDevice::InitImpl(&initConfig);
	XN_IS_STATUS_OK(nRetVal);

	// now create the rest of the modules and streams (DEVICE was already created)
	XnPropertySetData* pPropSetData = pSet->pData;
	for (XnPropertySetData::ConstIterator it = pPropSetData->begin(); it != pPropSetData->end(); ++it)
	{
		// ignore module DEVICE
		if (strcmp(XN_MODULE_NAME_DEVICE, it.Key()) == 0)
		{
			continue;
		}

		// check if this is a stream
		XnActualPropertiesHash::ConstIterator itProp = it.Value()->end();
		if (XN_STATUS_OK == it.Value()->Find(XN_STREAM_PROPERTY_TYPE, itProp))
		{
			XnActualStringProperty* pTypeProp = (XnActualStringProperty*)itProp.Value();
			nRetVal = HandleNewStream(pTypeProp->GetValue(), it.Key(), it.Value());
			XN_IS_STATUS_OK(nRetVal);
		}
		else
		{
			// this is module. create it
			XnDeviceModuleHolder* pHolder = NULL;
			nRetVal = CreateModule(it.Key(), &pHolder);
			XN_IS_STATUS_OK(nRetVal);

			// set its props
			nRetVal = pHolder->Init(it.Value());
			if (nRetVal != XN_STATUS_OK)
			{
				DestroyModule(pHolder);
				return (nRetVal);
			}

			// and add it
			nRetVal = AddModule(pHolder);
			if (nRetVal != XN_STATUS_OK)
			{
				DestroyModule(pHolder);
				return (nRetVal);
			}
		}
	} // modules loop
	
	return (XN_STATUS_OK);
}