XnStatus XnServerSensorInvoker::OnPropertyChanged(const XnProperty* pProp)
{
	// some special handling
	if (strcmp(pProp->GetName(), XN_STREAM_PROPERTY_STATE) == 0)
	{
		// ignore STATE property (every client has its own value)
		return XN_STATUS_OK;
	}
	else if (strcmp(pProp->GetName(), XN_MODULE_PROPERTY_ERROR_STATE) == 0)
	{
		XnActualIntProperty* pActualIntProp = (XnActualIntProperty*)pProp;
		XnStatus nOldErrorState = m_errorState;
		m_errorState = (XnStatus)pActualIntProp->GetValue();
		switch (m_errorState)
		{
		case XN_STATUS_DEVICE_NOT_CONNECTED:
			//TODO: Handle disconnection
			break;
		case XN_STATUS_OK:
			if (nOldErrorState == XN_STATUS_DEVICE_NOT_CONNECTED)
			{
				//TODO: Handle re-connection
				break;
			}
		}
	}

	// raise event
	m_propChangedEvent.Raise(pProp);

	return (XN_STATUS_OK);
}
Ejemplo n.º 2
0
XN_DDK_API XnStatus XnPropertySetCloneModule(const XnPropertySet* pSource, XnPropertySet* pDest, const XnChar* strModule, const XnChar* strNewName)
{
	XnStatus nRetVal = XN_STATUS_OK;

	XnActualPropertiesHash* pModuleProps = NULL;
	nRetVal = pSource->pData->Get(strModule, pModuleProps);
	XN_IS_STATUS_OK(nRetVal);

	nRetVal = XnPropertySetAddModule(pDest, strNewName);
	XN_IS_STATUS_OK(nRetVal);

	for (XnActualPropertiesHash::ConstIterator it = pModuleProps->Begin(); it != pModuleProps->End(); ++it)
	{
		XnProperty* pProp = it->Value();
		switch (pProp->GetType())
		{
		case XN_PROPERTY_TYPE_INTEGER:
			{
				XnActualIntProperty* pIntProp = (XnActualIntProperty*)pProp;
				nRetVal = XnPropertySetAddIntProperty(pDest, strNewName, pIntProp->GetName(), pIntProp->GetValue());
				XN_IS_STATUS_OK(nRetVal);
				break;
			}
		case XN_PROPERTY_TYPE_REAL:
			{
				XnActualRealProperty* pRealProp = (XnActualRealProperty*)pProp;
				nRetVal = XnPropertySetAddRealProperty(pDest, strNewName, pRealProp->GetName(), pRealProp->GetValue());
				XN_IS_STATUS_OK(nRetVal);
				break;
			}
		case XN_PROPERTY_TYPE_STRING:
			{
				XnActualStringProperty* pStrProp = (XnActualStringProperty*)pProp;
				nRetVal = XnPropertySetAddStringProperty(pDest, strNewName, pStrProp->GetName(), pStrProp->GetValue());
				XN_IS_STATUS_OK(nRetVal);
				break;
			}
		case XN_PROPERTY_TYPE_GENERAL:
			{
				XnActualGeneralProperty* pGenProp = (XnActualGeneralProperty*)pProp;
				nRetVal = XnPropertySetAddGeneralProperty(pDest, strNewName, pGenProp->GetName(), &pGenProp->GetValue());
				XN_IS_STATUS_OK(nRetVal);
				break;
			}
		default:
			XN_LOG_WARNING_RETURN(XN_STATUS_ERROR, XN_MASK_DDK, "Unknown property type: %d", pProp->GetType());
		}
	}

	return (XN_STATUS_OK);
}
Ejemplo n.º 3
0
XnStatus XnDataPacker::WritePropertySetProperties(const XnPropertySet* pSet)
{
    XnStatus nRetVal = XN_STATUS_OK;

    for (XnPropertySetData::Iterator it = pSet->pData->Begin(); it != pSet->pData->End(); ++it)
    {
        XnActualPropertiesHash* pModule = it->Value();
        for (XnActualPropertiesHash::ConstIterator itProp = pModule->Begin(); itProp != pModule->End(); ++itProp)
        {
            switch (itProp->Value()->GetType())
            {
            case XN_PROPERTY_TYPE_INTEGER:
            {
                XnActualIntProperty* pProp = (XnActualIntProperty*)itProp->Value();
                nRetVal = WritePropertyImpl(pProp->GetModule(), pProp->GetName(), pProp->GetValue());
                XN_IS_STATUS_OK(nRetVal);
                break;
            }
            case XN_PROPERTY_TYPE_REAL:
            {
                XnActualRealProperty* pProp = (XnActualRealProperty*)itProp->Value();
                nRetVal = WritePropertyImpl(pProp->GetModule(), pProp->GetName(), pProp->GetValue());
                XN_IS_STATUS_OK(nRetVal);
                break;
            }
            case XN_PROPERTY_TYPE_STRING:
            {
                XnActualStringProperty* pProp = (XnActualStringProperty*)itProp->Value();
                nRetVal = WritePropertyImpl(pProp->GetModule(), pProp->GetName(), pProp->GetValue());
                XN_IS_STATUS_OK(nRetVal);
                break;
            }
            case XN_PROPERTY_TYPE_GENERAL:
            {
                XnActualGeneralProperty* pProp = (XnActualGeneralProperty*)itProp->Value();
                nRetVal = WritePropertyImpl(pProp->GetModule(), pProp->GetName(), pProp->GetValue());
                XN_IS_STATUS_OK(nRetVal);
                break;
            }
            default:
                XN_LOG_WARNING_RETURN(XN_STATUS_ERROR, XN_MASK_DDK, "Unknown property type: %d", itProp->Value()->GetType());
            }
        }
    }

    StartWritingIntenalObject(XN_PACKED_PROPERTY_SET_PROPERTIES_END_MARKER);
    EndWritingInternalObject();

    return (XN_STATUS_OK);
}
XnStatus XnDeviceModuleHolder::UnsafeSetProperty(const XnProperty* pRequest, XnProperty* pProp)
{
	XnStatus nRetVal = XN_STATUS_OK;
	
	if (pRequest->GetType() != pProp->GetType())
	{
		XN_LOG_WARNING_RETURN(XN_STATUS_DEVICE_PROPERTY_BAD_TYPE, XN_MASK_DDK, "Property '%s' has the wrong type!", pRequest->GetName());
	}

	switch (pRequest->GetType())
	{
	case XN_PROPERTY_TYPE_INTEGER:
		{
			XnActualIntProperty* pActualRequest = (XnActualIntProperty*)pRequest;
			XnActualIntProperty* pActualProp = (XnActualIntProperty*)pProp;
			nRetVal = pActualProp->UnsafeUpdateValue(pActualRequest->GetValue());
			XN_IS_STATUS_OK(nRetVal);
			break;
		}
	case XN_PROPERTY_TYPE_REAL:
		{
			XnActualRealProperty* pActualRequest = (XnActualRealProperty*)pRequest;
			XnActualRealProperty* pActualProp = (XnActualRealProperty*)pProp;
			nRetVal = pActualProp->UnsafeUpdateValue(pActualRequest->GetValue());
			XN_IS_STATUS_OK(nRetVal);
			break;
		}
	case XN_PROPERTY_TYPE_STRING:
		{
			XnActualStringProperty* pActualRequest = (XnActualStringProperty*)pRequest;
			XnActualStringProperty* pActualProp = (XnActualStringProperty*)pProp;
			nRetVal = pActualProp->UnsafeUpdateValue(pActualRequest->GetValue());
			XN_IS_STATUS_OK(nRetVal);
			break;
		}
	case XN_PROPERTY_TYPE_GENERAL:
		{
			XnActualGeneralProperty* pActualRequest = (XnActualGeneralProperty*)pRequest;
			XnActualGeneralProperty* pActualProp = (XnActualGeneralProperty*)pProp;
			nRetVal = pActualProp->UnsafeUpdateValue(pActualRequest->GetValue());
			XN_IS_STATUS_OK(nRetVal);
			break;
		}
	default:
		XN_LOG_WARNING_RETURN(XN_STATUS_ERROR, XN_MASK_DDK, "Unknown property type: %d\n", pRequest->GetType());
	} // switch
	
	return (XN_STATUS_OK);
}
Ejemplo n.º 5
0
XN_DDK_API XnStatus XnPropertySetEnumeratorGetIntValue(const XnPropertySetEnumerator* pEnumerator, XnUInt64* pnValue)
{
	XN_VALIDATE_INPUT_PTR(pEnumerator);
	XN_VALIDATE_OUTPUT_PTR(pnValue);

	XnProperty* pPropBase = pEnumerator->itProp->Value();
	if (pPropBase->GetType() != XN_PROPERTY_TYPE_INTEGER)
	{
		return XN_STATUS_DEVICE_PROPERTY_BAD_TYPE;
	}

	XnActualIntProperty* pProp = (XnActualIntProperty*)pPropBase;
	*pnValue = pProp->GetValue();

	return (XN_STATUS_OK);
}
Ejemplo n.º 6
0
XnStatus XnActualPropertiesHash::CopyFrom(const XnActualPropertiesHash& other)
{
	XnStatus nRetVal = XN_STATUS_OK;

	Clear();
	strncpy(m_strName, other.m_strName, XN_DEVICE_MAX_STRING_LENGTH);

	for (ConstIterator it = other.Begin(); it != other.End(); ++it)
	{
		switch (it->Value()->GetType())
		{
		case XN_PROPERTY_TYPE_INTEGER:
			{
				XnActualIntProperty* pProp = (XnActualIntProperty*)it->Value();
				nRetVal = Add(pProp->GetId(), pProp->GetName(), pProp->GetValue());
				XN_IS_STATUS_OK(nRetVal);
				break;
			}
		case XN_PROPERTY_TYPE_REAL:
			{
				XnActualRealProperty* pProp = (XnActualRealProperty*)it->Value();
				nRetVal = Add(pProp->GetId(), pProp->GetName(), pProp->GetValue());
				XN_IS_STATUS_OK(nRetVal);
				break;
			}
		case XN_PROPERTY_TYPE_STRING:
			{
				XnActualStringProperty* pProp = (XnActualStringProperty*)it->Value();
				nRetVal = Add(pProp->GetId(), pProp->GetName(), pProp->GetValue());
				XN_IS_STATUS_OK(nRetVal);
				break;
			}
		case XN_PROPERTY_TYPE_GENERAL:
			{
				XnActualGeneralProperty* pProp = (XnActualGeneralProperty*)it->Value();
				nRetVal = Add(pProp->GetId(), pProp->GetName(), pProp->GetValue());
				XN_IS_STATUS_OK(nRetVal);
				break;
			}
		default:
			XN_LOG_WARNING_RETURN(XN_STATUS_ERROR, XN_MASK_DDK, "Unknown property type: %d\n", it->Value()->GetType());
		}
	}

	return (XN_STATUS_OK);
}
XnStatus XnDeviceModule::UnsafeBatchConfig(const XnActualPropertiesHash& props)
{
	XnStatus nRetVal = XN_STATUS_OK;

	for (XnActualPropertiesHash::ConstIterator it = props.Begin(); it != props.End(); ++it)
	{
		XnProperty* pRequestProp = it->Value();
		switch (pRequestProp->GetType())
		{
		case XN_PROPERTY_TYPE_INTEGER:
			{
				XnActualIntProperty* pProp = (XnActualIntProperty*)pRequestProp;
				nRetVal = UnsafeUpdateProperty(pProp->GetName(), pProp->GetValue());
				XN_IS_STATUS_OK(nRetVal);
				break;
			}
		case XN_PROPERTY_TYPE_REAL:
			{
				XnActualRealProperty* pProp = (XnActualRealProperty*)pRequestProp;
				nRetVal = UnsafeUpdateProperty(pProp->GetName(), pProp->GetValue());
				XN_IS_STATUS_OK(nRetVal);
				break;
			}
		case XN_PROPERTY_TYPE_STRING:
			{
				XnActualStringProperty* pProp = (XnActualStringProperty*)pRequestProp;
				nRetVal = UnsafeUpdateProperty(pProp->GetName(), pProp->GetValue());
				XN_IS_STATUS_OK(nRetVal);
				break;
			}
		case XN_PROPERTY_TYPE_GENERAL:
			{
				XnActualGeneralProperty* pProp = (XnActualGeneralProperty*)pRequestProp;
				nRetVal = UnsafeUpdateProperty(pProp->GetName(), pProp->GetValue());
				XN_IS_STATUS_OK(nRetVal);
				break;
			}
		default:
			XN_LOG_WARNING_RETURN(XN_STATUS_ERROR, XN_MASK_DDK, "Unknown property type: %d\n", pRequestProp->GetType());
		} // type switch
	} // props loop

	return (XN_STATUS_OK);
}
Ejemplo n.º 8
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);
}
Ejemplo n.º 9
0
XnStatus XnSensorFirmwareParams::AddFirmwareAudioParam(XnActualIntProperty& Property, XnUInt16 nFirmwareParam, XnFWVer nMinVer /* = XN_SENSOR_FW_VER_3_0 */, XnFWVer nMaxVer /* = XN_SENSOR_FW_VER_UNKNOWN */, XnUInt16 nValueIfNotSupported /* = 0 */)
{
	XnStatus nRetVal = XN_STATUS_OK;
	
	nRetVal = AddFirmwareParam(Property, nFirmwareParam, nMinVer, nMaxVer, nValueIfNotSupported);
	XN_IS_STATUS_OK(nRetVal);

	Property.UpdateSetCallback(SetFirmwareAudioParamCallback, this);
	
	return (XN_STATUS_OK);
}
Ejemplo n.º 10
0
XnStatus XnSensorStreamHelper::ConfigureFirmware(XnActualIntProperty& Property)
{
	XnStatus nRetVal = XN_STATUS_OK;
	
	XnSensorStreamHelperCookie* pPropData = NULL;
	nRetVal = m_FirmwareProperties.Get(&Property, pPropData);
	XN_IS_STATUS_OK(nRetVal);

	XnUInt64 nFirmwareValue = Property.GetValue();

	if (pPropData->pStreamToFirmwareFunc != NULL)
	{
		nRetVal = pPropData->pStreamToFirmwareFunc(Property.GetValue(), &nFirmwareValue);
		XN_IS_STATUS_OK(nRetVal);
	}

	nRetVal = pPropData->pFirmwareProp->SetValue(nFirmwareValue);
	XN_IS_STATUS_OK(nRetVal);

	return (XN_STATUS_OK);
}
Ejemplo n.º 11
0
XnStatus XnServerSession::OnPropertyChanged(const XnProperty* pProp)
{
	XnStatus nRetVal = XN_STATUS_OK;
	
	XnAutoCSLocker streamLocker(m_hStreamsLock);

	SessionStream* pStream = NULL;
	nRetVal = FindStreamByServerName(pProp->GetModule(), &pStream);
	XN_IS_STATUS_OK(nRetVal);

	// send message
	m_pLogger->DumpMessage("PropChange", 0, m_nID, pProp->GetName());

	XnAutoCSLocker commLocker(m_hCommLock);
	switch (pProp->GetType())
	{
	case XN_PROPERTY_TYPE_INTEGER:
		{
			XnActualIntProperty* pActualProp = (XnActualIntProperty*)pProp;
			nRetVal = m_privateOutgoingPacker.WriteProperty(pStream->strClientStreamName, pProp->GetName(), pActualProp->GetValue());
			XN_IS_STATUS_OK(nRetVal);
			break;
		}
	case XN_PROPERTY_TYPE_REAL:
		{
			XnActualRealProperty* pActualProp = (XnActualRealProperty*)pProp;
			nRetVal = m_privateOutgoingPacker.WriteProperty(pStream->strClientStreamName, pProp->GetName(), pActualProp->GetValue());
			XN_IS_STATUS_OK(nRetVal);
			break;
		}
	case XN_PROPERTY_TYPE_STRING:
		{
			XnActualStringProperty* pActualProp = (XnActualStringProperty*)pProp;
			nRetVal = m_privateOutgoingPacker.WriteProperty(pStream->strClientStreamName, pProp->GetName(), pActualProp->GetValue());
			XN_IS_STATUS_OK(nRetVal);
			break;
		}
	case XN_PROPERTY_TYPE_GENERAL:
		{
			XnActualGeneralProperty* pActualProp = (XnActualGeneralProperty*)pProp;
			nRetVal = m_privateOutgoingPacker.WriteProperty(pStream->strClientStreamName, pProp->GetName(), pActualProp->GetValue());
			XN_IS_STATUS_OK(nRetVal);
			break;
		}
	default:
		XN_LOG_WARNING_RETURN(XN_STATUS_ERROR, XN_MASK_SENSOR_SERVER, "Unknown property type: %d", pProp->GetType());
	}

	return (XN_STATUS_OK);
}
Ejemplo n.º 12
0
XnStatus XnSensorFirmwareParams::AddFirmwareParam(XnActualIntProperty& Property, XnUInt16 nFirmwareParam, XnFWVer nMinVer /* = XN_SENSOR_FW_VER_UNKNOWN */, XnFWVer nMaxVer /* = XN_SENSOR_FW_VER_UNKNOWN */, XnUInt16 nValueIfNotSupported /* = 0 */)
{
	XnStatus nRetVal = XN_STATUS_OK;

	XnFirmwareParam param;
	param.pProperty = &Property;
	param.nFirmwareParam = nFirmwareParam;
	param.MinVer = nMinVer;
	param.MaxVer = nMaxVer;
	param.nValueIfNotSupported = nValueIfNotSupported;

	nRetVal = m_AllFirmwareParams.Set(&Property, param);
	XN_IS_STATUS_OK(nRetVal);

	XnChar csNewName[XN_DEVICE_MAX_STRING_LENGTH];
	sprintf(csNewName, "%s (%d)", Property.GetName(), nFirmwareParam);

	Property.UpdateName("Firmware", csNewName);
	Property.SetLogSeverity(XN_LOG_VERBOSE);
	Property.SetAlwaysSet(TRUE);
	Property.UpdateSetCallback(SetFirmwareParamCallback, this);

	return (XN_STATUS_OK);
}
Ejemplo n.º 13
0
XnStatus XnSensorStreamHelper::SimpleSetFirmwareParam(XnActualIntProperty& Property, XnUInt16 nValue)
{
	XnStatus nRetVal = XN_STATUS_OK;
	
	nRetVal = BeforeSettingFirmwareParam(Property, nValue);
	XN_IS_STATUS_OK(nRetVal);

	nRetVal = Property.UnsafeUpdateValue(nValue);
	XN_IS_STATUS_OK(nRetVal);

	nRetVal = AfterSettingFirmwareParam(Property);
	XN_IS_STATUS_OK(nRetVal);
	
	return (XN_STATUS_OK);
}
XnStatus XnDeviceModuleHolder::CreateProperty(XnProperty* pRequestProp)
{
	XnStatus nRetVal = XN_STATUS_OK;

	XnProperty* pNewProp = NULL;

	switch (pRequestProp->GetType())
	{
	case XN_PROPERTY_TYPE_INTEGER:
		{
			XnActualIntProperty* pProp = (XnActualIntProperty*)pRequestProp;
			XN_VALIDATE_NEW(pNewProp, XnActualIntProperty, pProp->GetName(), pProp->GetValue());
			break;
		}
	case XN_PROPERTY_TYPE_REAL:
		{
			XnActualRealProperty* pProp = (XnActualRealProperty*)pRequestProp;
			XN_VALIDATE_NEW(pNewProp, XnActualRealProperty, pProp->GetName(), pProp->GetValue());
			break;
		}
	case XN_PROPERTY_TYPE_STRING:
		{
			XnActualStringProperty* pProp = (XnActualStringProperty*)pRequestProp;
			XN_VALIDATE_NEW(pNewProp, XnActualStringProperty, pProp->GetName(), pProp->GetValue());
			break;
		}
	case XN_PROPERTY_TYPE_GENERAL:
		{
			XnActualGeneralProperty* pProp = (XnActualGeneralProperty*)pRequestProp;

			// create new buffer
			XnGeneralBuffer gbNew;
			nRetVal = XnGeneralBufferAlloc(&gbNew, pProp->GetValue().nDataSize);
			XN_IS_STATUS_OK(nRetVal);

			// copy content
			xnOSMemCopy(gbNew.pData, pProp->GetValue().pData, pProp->GetValue().nDataSize);

			XnActualGeneralProperty* pNewGeneralProp = NULL;
			XN_VALIDATE_NEW(pNewGeneralProp, XnActualGeneralProperty, pProp->GetName(), gbNew);
			pNewGeneralProp->SetAsBufferOwner(TRUE);
			pNewProp = pNewGeneralProp;
			break;
		}
	default:
		XN_LOG_WARNING_RETURN(XN_STATUS_ERROR, XN_MASK_DDK, "Unknown property type: %d\n", pRequestProp->GetType());
	} // switch

	// add the property to the module
	nRetVal = m_pModule->AddProperty(pNewProp);
	if (nRetVal != XN_STATUS_OK)
	{
		XN_DELETE(pNewProp);
		return (nRetVal);
	}

	// and add it to the list of allocated ones (so we'll delete it afterwards)
	m_Allocated.AddLast(pNewProp);

	return XN_STATUS_OK;
}
Ejemplo n.º 15
0
XnStatus XnFileDevice::HandleNewStream(const XnChar *strType, const XnChar *strName, const XnActualPropertiesHash *pInitialValues)
{
    XnStatus nRetVal = XN_STATUS_OK;

    // check if we need to ignore that (stream was not removed upon Rewind).
    XnNodeInfoMap::Iterator it = m_ignoreNewNodes.End();
    if (m_ignoreNewNodes.Find(strName, it) == XN_STATUS_OK)
    {
        // ignore
        return (XN_STATUS_OK);
    }

    XnProductionNodeType type = GetNodeType(strType);
    if (type == -1)
    {
        XN_LOG_WARNING_RETURN(XN_STATUS_CORRUPT_FILE, XN_MASK_FILE, "Invalid node type: %s", strType);
    }

    // find compression type
    XnActualIntProperty* pComp = NULL;
    nRetVal = pInitialValues->Get(XN_STREAM_PROPERTY_COMPRESSION, (XnProperty*&)pComp);
    XN_IS_STATUS_OK(nRetVal);

    XnCodecID codecID = XnCodec::GetCodecIDFromCompressionFormat((XnCompressionFormats)pComp->GetValue());
    if (codecID == XN_CODEC_NULL)
    {
        XN_LOG_WARNING_RETURN(XN_STATUS_CORRUPT_FILE, XN_MASK_FILE, "Invalid compression type: %llu", pComp->GetValue());
    }

    // notify we have a new node
    nRetVal = m_pNotifications->OnNodeAdded(m_pNotificationsCookie, strName, type, codecID);
    XN_IS_STATUS_OK(nRetVal);

    // we support the mirror capability
    nRetVal = m_pNotifications->OnNodeIntPropChanged(m_pNotificationsCookie, strName, XN_CAPABILITY_MIRROR, 1);
    XN_IS_STATUS_OK(nRetVal);

    // we support the extended serialization capability
    nRetVal = m_pNotifications->OnNodeIntPropChanged(m_pNotificationsCookie, strName, XN_CAPABILITY_EXTENDED_SERIALIZATION, 1);
    XN_IS_STATUS_OK(nRetVal);

    // now write state
    for (XnActualPropertiesHash::ConstIterator it = pInitialValues->Begin(); it != pInitialValues->End(); ++it)
    {
        XnProperty* pProp = it->Value();

        switch (pProp->GetType())
        {
        case XN_PROPERTY_TYPE_INTEGER:
        {
            XnActualIntProperty* pIntProp = (XnActualIntProperty*)pProp;
            nRetVal = HandleIntProperty(strName, pProp->GetName(), pIntProp->GetValue());
        }
        break;
        case XN_PROPERTY_TYPE_REAL:
        {
            XnActualRealProperty* pRealProp = (XnActualRealProperty*)pProp;
            nRetVal = HandleRealProperty(strName, pProp->GetName(), pRealProp->GetValue());
        }
        break;
        case XN_PROPERTY_TYPE_STRING:
        {
            XnActualStringProperty* pStrProp = (XnActualStringProperty*)pProp;
            nRetVal = HandleStringProperty(strName, pProp->GetName(), pStrProp->GetValue());
        }
        break;
        case XN_PROPERTY_TYPE_GENERAL:
        {
            XnActualGeneralProperty* pGenProp = (XnActualGeneralProperty*)pProp;
            nRetVal = HandleGeneralProperty(strName, pProp->GetName(), pGenProp->GetValue());
        }
        break;
        default:
            XN_LOG_WARNING_RETURN(XN_STATUS_ERROR, XN_MASK_FILE, "Unknown property type: %d", pProp->GetType());
        }

        XN_IS_STATUS_OK(nRetVal);
    }

    // at this stage, a node should exist with this name
    xn::ProductionNode node;
    nRetVal = m_context.GetProductionNodeByName(strName, node);
    XN_IS_STATUS_OK(nRetVal);

    // S2D & RW
    if (type == XN_NODE_TYPE_DEPTH)
    {
        nRetVal = UpdateS2DTables(xn::DepthGenerator(node));
        XN_IS_STATUS_OK(nRetVal);

        nRetVal = UpdateRWData(xn::DepthGenerator(node));
        XN_IS_STATUS_OK(nRetVal);
    }

    // notify end-of-state
    nRetVal = m_pNotifications->OnNodeStateReady(m_pNotificationsCookie, strName);
    XN_IS_STATUS_OK(nRetVal);

    // add it to the map
    XnNodeInfo nodeInfo = {0};
    nRetVal = m_nodeInfoMap.Set(strName, nodeInfo);
    XN_IS_STATUS_OK(nRetVal);

    // create codec
    nRetVal = CreateCodec(node);
    XN_IS_STATUS_OK(nRetVal);

    // check IR compatibility
    nRetVal = CheckIRCompatibility(node);
    XN_IS_STATUS_OK(nRetVal);

    return (XN_STATUS_OK);
}
XnStatus XnServerSensorInvoker::OnStreamAdded(const XnChar* StreamName)
{
	XnStatus nRetVal = XN_STATUS_OK;

	// get all props
	XN_PROPERTY_SET_CREATE_ON_STACK(props);
	nRetVal = m_sensor.GetAllProperties(&props, FALSE, StreamName);
	XN_IS_STATUS_OK(nRetVal);

	// register to all props
	nRetVal = RegisterToProps(&props);
	XN_IS_STATUS_OK(nRetVal);

	XnActualPropertiesHash* pStreamProps = props.pData->Begin()->Value();

	// create stream data
	SensorInvokerStream serverStream;
	xnOSMemSet(&serverStream, 0, sizeof(serverStream));
	strcpy(serverStream.strType, StreamName);

	XN_VALIDATE_NEW(serverStream.pNewDataEvent, NewStreamDataEvent);

	// check if this is a frame stream
	XnProperty* pIsFrameBased;
	nRetVal = pStreamProps->Get(XN_STREAM_PROPERTY_IS_FRAME_BASED, pIsFrameBased);
	if (nRetVal == XN_STATUS_OK)
	{
		XnActualIntProperty* pIntProp = (XnActualIntProperty*)pIsFrameBased;
		serverStream.bFrameStream = (pIntProp->GetValue() == TRUE);
	}

	if (serverStream.bFrameStream)
	{
		// create the "shared memory name" property
		XN_VALIDATE_NEW(serverStream.pSharedMemoryName, XnActualStringProperty, XN_STREAM_PROPERTY_SHARED_BUFFER_NAME);

		// and add it to the stream
		XnDeviceStream* pStream;
		nRetVal = m_sensor.GetStream(StreamName, &pStream);
		if (nRetVal != XN_STATUS_OK)
		{
			XN_DELETE(serverStream.pNewDataEvent);
			XN_DELETE(serverStream.pSharedMemoryName);
			return nRetVal;
		}

		nRetVal = pStream->AddProperty(serverStream.pSharedMemoryName);
		if (nRetVal != XN_STATUS_OK)
		{
			XN_DELETE(serverStream.pNewDataEvent);
			XN_DELETE(serverStream.pSharedMemoryName);
			return nRetVal;
		}

		// create a shared memory buffer pool for it
		nRetVal = SetStreamSharedMemory(&serverStream);
		if (nRetVal != XN_STATUS_OK)
		{
			XN_DELETE(serverStream.pNewDataEvent);
			XN_DELETE(serverStream.pSharedMemoryName);
			return nRetVal;
		}
	}

	// create a stream data object for the stream
	nRetVal = m_sensor.CreateStreamData(StreamName, &serverStream.pStreamData);
	if (nRetVal != XN_STATUS_OK)
	{
		XN_DELETE(serverStream.pNewDataEvent);
		XN_DELETE(serverStream.pSharedMemoryName);
		return (nRetVal);
	}

	// and add it to our list of streams
	nRetVal = m_streams.Set(StreamName, serverStream);
	if (nRetVal != XN_STATUS_OK)
	{
		XN_DELETE(serverStream.pNewDataEvent);
		XN_DELETE(serverStream.pSharedMemoryName);
		return (nRetVal);
	}

	return (XN_STATUS_OK);
}
Ejemplo n.º 17
0
XnStatus XnDeviceFileReader::ReadInitialState(XnPropertySet *pSet)
{
	XnStatus nRetVal = XN_STATUS_OK;

	if (m_nFileVersion < 4)
	{
		if (m_pBCData == NULL)
		{
			nRetVal = BCInit();
			XN_IS_STATUS_OK(nRetVal);
		}

		return BCReadInitialState(pSet);
	}

	// first read first object - modules properties - using base
	nRetVal = XnStreamReaderDevice::ReadInitialState(pSet);
	XN_IS_STATUS_OK(nRetVal);

	// now continue reading until we get to first data
	XnPackedDataType nType;
	XnBool bStateEnd = FALSE;
	XnUInt64 nPositionBefore;

	while (!bStateEnd)
	{
		nRetVal = GetIOStream()->Tell(&nPositionBefore);
		XN_IS_STATUS_OK(nRetVal);

		nRetVal = GetDataPacker()->ReadNextObject(&nType);
		XN_IS_STATUS_OK(nRetVal);

		switch (nType)
		{
		case XN_PACKED_NEW_STREAM:
			{
				XnChar strType[XN_DEVICE_MAX_STRING_LENGTH];
				XnChar strName[XN_DEVICE_MAX_STRING_LENGTH];
				XN_PROPERTY_SET_CREATE_ON_STACK(props);
				nRetVal = GetDataPacker()->ReadNewStream(strType, strName, &props);
				XN_IS_STATUS_OK(nRetVal);

				XnActualPropertiesHash* pStreamProps;
				nRetVal = XnPropertySetDataDetachModule(props.pData, strName, &pStreamProps);
				XN_IS_STATUS_OK(nRetVal);

				nRetVal = XnPropertySetDataAttachModule(pSet->pData, strName, pStreamProps);
				XN_IS_STATUS_OK(nRetVal);
				break;
			}
		case XN_PACKED_INT_PROPERTY:
			{
				XnChar strModule[XN_DEVICE_MAX_STRING_LENGTH];
				XnChar strProp[XN_DEVICE_MAX_STRING_LENGTH];
				XnUInt64 nValue;
				nRetVal = GetDataPacker()->ReadProperty(strModule, strProp, &nValue);
				XN_IS_STATUS_OK(nRetVal);

				XnActualPropertiesHash* pModule = NULL;
				nRetVal = pSet->pData->Get(strModule, pModule);
				XN_IS_STATUS_OK(nRetVal);

				XnProperty* pProp = NULL;
				nRetVal = pModule->Get(strProp, pProp);
				XN_IS_STATUS_OK(nRetVal);

				XnActualIntProperty* pIntProp = (XnActualIntProperty*)pProp;
				nRetVal = pIntProp->UnsafeUpdateValue(nValue);
				XN_IS_STATUS_OK(nRetVal);
				break;
			}
		case XN_PACKED_REAL_PROPERTY:
			{
				XnChar strModule[XN_DEVICE_MAX_STRING_LENGTH];
				XnChar strProp[XN_DEVICE_MAX_STRING_LENGTH];
				XnDouble dValue;
				nRetVal = GetDataPacker()->ReadProperty(strModule, strProp, &dValue);
				XN_IS_STATUS_OK(nRetVal);

				XnActualPropertiesHash* pModule;
				nRetVal = pSet->pData->Get(strModule, pModule);
				XN_IS_STATUS_OK(nRetVal);

				XnProperty* pProp;
				nRetVal = pModule->Get(strProp, pProp);
				XN_IS_STATUS_OK(nRetVal);

				XnActualRealProperty* pRealProp = (XnActualRealProperty*)pProp;
				nRetVal = pRealProp->UnsafeUpdateValue(dValue);
				XN_IS_STATUS_OK(nRetVal);
				break;
			}
		case XN_PACKED_STRING_PROPERTY:
			{
				XnChar strModule[XN_DEVICE_MAX_STRING_LENGTH];
				XnChar strProp[XN_DEVICE_MAX_STRING_LENGTH];
				XnChar strValue[XN_DEVICE_MAX_STRING_LENGTH];
				nRetVal = GetDataPacker()->ReadProperty(strModule, strProp, strValue);
				XN_IS_STATUS_OK(nRetVal);

				XnActualPropertiesHash* pModule;
				nRetVal = pSet->pData->Get(strModule, pModule);
				XN_IS_STATUS_OK(nRetVal);

				XnProperty* pProp;
				nRetVal = pModule->Get(strProp, pProp);
				XN_IS_STATUS_OK(nRetVal);

				XnActualStringProperty* pStringProp = (XnActualStringProperty*)pProp;
				nRetVal = pStringProp->UnsafeUpdateValue(strValue);
				XN_IS_STATUS_OK(nRetVal);
				break;
			}
		case XN_PACKED_GENERAL_PROPERTY:
			{
				XnChar strModule[XN_DEVICE_MAX_STRING_LENGTH];
				XnChar strProp[XN_DEVICE_MAX_STRING_LENGTH];
				XnGeneralBuffer gbValue;
				nRetVal = GetDataPacker()->ReadProperty(strModule, strProp, &gbValue);
				XN_IS_STATUS_OK(nRetVal);

				XnActualPropertiesHash* pModule;
				nRetVal = pSet->pData->Get(strModule, pModule);
				XN_IS_STATUS_OK(nRetVal);

				XnProperty* pProp;
				nRetVal = pModule->Get(strProp, pProp);
				XN_IS_STATUS_OK(nRetVal);

				XnActualGeneralProperty* pIntProp = (XnActualGeneralProperty*)pProp;
				nRetVal = pIntProp->UnsafeUpdateValue(gbValue);
				XN_IS_STATUS_OK(nRetVal);
				break;
			}
		default:
			// reached end of initial state. go back to beginning of this object
			nRetVal = GetIOStream()->Seek(nPositionBefore);
			XN_IS_STATUS_OK(nRetVal);

			// stop reading
			bStateEnd = TRUE;
		}
	} // objects loop
	
	return (XN_STATUS_OK);
}
XnStatus XnSensorProductionNode::NotifyExState(XnNodeNotifications* pNotifications, void* pCookie)
{
	XnStatus nRetVal = XN_STATUS_OK;
	
	// get all properties
	XN_PROPERTY_SET_CREATE_ON_STACK(props);
	nRetVal = m_pSensor->GetAllProperties(&props, FALSE, GetModuleName());
	XN_IS_STATUS_OK(nRetVal);

	XnActualPropertiesHash* pPropsHash = props.pData->begin().Value();

	// filter properties (remove the ones already exposed as OpenNI interfaces)
	FilterProperties(pPropsHash);

	const XnChar* astrIntProps[200] = {0};
	const XnChar* astrRealProps[200] = {0};
	const XnChar* astrStringProps[200] = {0};
	const XnChar* astrGeneralProps[200] = {0};

	XnUInt32 nIntProps = 0;
	XnUInt32 nRealProps = 0;
	XnUInt32 nStringProps = 0;
	XnUInt32 nGeneralProps = 0;

	// enumerate over properties
	for (XnActualPropertiesHash::Iterator it = pPropsHash->begin(); it != pPropsHash->end(); ++it)
	{
		XnProperty* pProp = it.Value();

		switch (pProp->GetType())
		{
		case XN_PROPERTY_TYPE_INTEGER:
			{
				XnActualIntProperty* pIntProp = (XnActualIntProperty*)pProp;
				pNotifications->OnNodeIntPropChanged(pCookie, GetInstanceName(), pProp->GetName(), pIntProp->GetValue());
				astrIntProps[nIntProps++] = pProp->GetName();
			}
			break;
		case XN_PROPERTY_TYPE_REAL:
			{
				XnActualRealProperty* pRealProp = (XnActualRealProperty*)pProp;
				pNotifications->OnNodeRealPropChanged(pCookie, GetInstanceName(), pProp->GetName(), pRealProp->GetValue());
				astrRealProps[nRealProps++] = pProp->GetName();
			}
			break;
		case XN_PROPERTY_TYPE_STRING:
			{
				XnActualStringProperty* pStrProp = (XnActualStringProperty*)pProp;
				pNotifications->OnNodeStringPropChanged(pCookie, GetInstanceName(), pProp->GetName(), pStrProp->GetValue());
				astrStringProps[nStringProps++] = pProp->GetName();
			}
			break;
		case XN_PROPERTY_TYPE_GENERAL:
			{
				XnActualGeneralProperty* pGenProp = (XnActualGeneralProperty*)pProp;
				pNotifications->OnNodeGeneralPropChanged(pCookie, GetInstanceName(), pProp->GetName(), pGenProp->GetValue().nDataSize, pGenProp->GetValue().pData);
				astrGeneralProps[nGeneralProps++] = pProp->GetName();
			}
			break;
		default:
			XN_LOG_WARNING_RETURN(XN_STATUS_ERROR, XN_MASK_DEVICE_SENSOR, "Unknown property type: %d", pProp->GetType());
		}
	}

	// TODO: also register to these properties, and if changed, notify.

	// store notifications object
	m_pNotifications = pNotifications;
	m_pCookie = pCookie;

	return (XN_STATUS_OK);
}
Ejemplo n.º 19
0
XnStatus XnSensorFirmwareParams::CommitTransactionAsBatch()
{
	XnStatus nRetVal = XN_STATUS_OK;

	if (!m_bInTransaction)
	{
		return XN_STATUS_ERROR;
	}

	// we are no longer in transaction, even if we fail to commit.
	m_bInTransaction = FALSE;

	if (m_TransactionOrder.Size() != 0)
	{
		XnUInt32 nMaxCount = m_TransactionOrder.Size();
		XnInnerParamData* pParams;
		XN_VALIDATE_CALLOC(pParams, XnInnerParamData, nMaxCount);

		XnChar strLogMessage[1024];
		XnUInt32 nMaxLength = 1024;
		XnUInt32 nLength = 0;
		XnUInt32 nChars;
		xnOSStrFormat(strLogMessage + nLength, nMaxLength - nLength, &nChars, "Setting firmware params:\n\t");
		nLength += nChars;

		XnUInt32 nCount = 0;

		for (XnActualIntPropertyList::Iterator it = m_TransactionOrder.begin(); it != m_TransactionOrder.end(); ++it)
		{
			XnActualIntProperty* pProp = *it;

			XnUInt32 nValue;
			nRetVal = m_Transaction.Get(pProp, nValue);
			if (nRetVal != XN_STATUS_OK)
			{
				xnOSFree(pParams);
				return (nRetVal);
			}

			XnFirmwareParam* pParam;
			nRetVal = CheckFirmwareParam(pProp, nValue, &pParam);
			if (nRetVal != XN_STATUS_OK)
			{
				xnOSFree(pParams);
				return (nRetVal);
			}

			if (pParam != NULL)
			{
				xnOSStrFormat(strLogMessage + nLength, nMaxLength - nLength, &nChars, "%s = %u\n\t", pProp->GetName(), nValue);
				nLength += nChars;

				pParams[nCount].nParam = pParam->nFirmwareParam;
				pParams[nCount].nValue = (XnUInt16)nValue;
				nCount++;
			}
		}

		xnLogVerbose(XN_MASK_SENSOR_PROTOCOL, "%s", strLogMessage);

		// set all params
		nRetVal = m_pCommands->SetMultipleFirmwareParams(pParams, nCount);
		xnOSFree(pParams);
		XN_IS_STATUS_OK(nRetVal);

		// and update their props
		for (XnActualIntPropertyList::Iterator it = m_TransactionOrder.begin(); it != m_TransactionOrder.end(); ++it)
		{
			XnActualIntProperty* pProp = *it;

			XnUInt32 nValue;
			nRetVal = m_Transaction.Get(pProp, nValue);
			XN_IS_STATUS_OK(nRetVal);

			nRetVal = pProp->UnsafeUpdateValue(nValue);
			XN_IS_STATUS_OK(nRetVal);
		}
	}

	m_Transaction.Clear();
	m_TransactionOrder.Clear();

	return (XN_STATUS_OK);
}