XnStatus XnDeviceModuleHolder::UnsafeSetProperties(const XnActualPropertiesHash& props) { XnStatus nRetVal = XN_STATUS_OK; for (XnActualPropertiesHash::ConstIterator it = props.Begin(); it != props.End(); ++it) { XnProperty* pRequestProp = it->Value(); XnProperty* pProp = NULL; // check if property already exist nRetVal = m_pModule->GetProperty(pRequestProp->GetName(), &pProp); if (nRetVal == XN_STATUS_DEVICE_PROPERTY_DONT_EXIST) { // property doesn't exist. create it now nRetVal = CreateProperty(pRequestProp); XN_IS_STATUS_OK(nRetVal); } else if (nRetVal == XN_STATUS_OK) { // property exists. Change its value nRetVal = UnsafeSetProperty(pRequestProp, pProp); XN_IS_STATUS_OK(nRetVal); } else { // error return (nRetVal); } } // props loop return (XN_STATUS_OK); }
XnStatus XnServerSensorInvoker::RegisterToProps(XnPropertySet* pProps) { XnStatus nRetVal = XN_STATUS_OK; XnCallbackHandle hDummy = NULL; for (XnPropertySetData::Iterator itMod = pProps->pData->Begin(); itMod != pProps->pData->End(); ++itMod) { XnActualPropertiesHash* pHash = itMod->Value(); XnDeviceModule* pModule; nRetVal = m_sensor.FindModule(itMod->Key(), &pModule); XN_IS_STATUS_OK(nRetVal); for (XnActualPropertiesHash::Iterator itProp = pHash->Begin(); itProp != pHash->End(); ++itProp) { XnProperty* pProp; nRetVal = pModule->GetProperty(itProp->Key(), &pProp); XN_IS_STATUS_OK(nRetVal); // no need to keep the handle. We only want to unregister when the stream is destroyed, and then // it happens anyway. nRetVal = pProp->OnChangeEvent().Register(PropertyChangedCallback, this, hDummy); XN_IS_STATUS_OK(nRetVal); } } return (XN_STATUS_OK); }
XN_DDK_API XnStatus XnPropertySetFindProperty(const XnPropertySet* pSet, const XnChar* strModule, const XnChar* strProp, XnPropertySetEnumerator** ppEnumerator) { XnStatus nRetVal = XN_STATUS_OK; XN_VALIDATE_INPUT_PTR(pSet); XN_VALIDATE_INPUT_PTR(strModule); XN_VALIDATE_INPUT_PTR(strProp); XN_VALIDATE_OUTPUT_PTR(ppEnumerator); // find module XnPropertySetData::Iterator itModule = pSet->pData->End(); nRetVal = pSet->pData->Find(strModule, itModule); XN_IS_STATUS_OK(nRetVal); XnActualPropertiesHash* pModule = itModule->Value(); // find property XnActualPropertiesHash::Iterator itProp = pModule->End(); nRetVal = pModule->Find(strProp, itProp); XN_IS_STATUS_OK(nRetVal); // create enumerator XnPropertySetEnumerator* pEnumer; XN_VALIDATE_NEW(pEnumer, XnPropertySetEnumerator); pEnumer->itModule = itModule; pEnumer->itProp = itProp; pEnumer->pModules = pSet->pData; pEnumer->strModule[0] = '\0'; pEnumer->bFirst = FALSE; *ppEnumerator = pEnumer; return XN_STATUS_OK; }
XnStatus XnDeviceBase::CreateStreams(const XnPropertySet* pSet) { XnStatus nRetVal = XN_STATUS_OK; for (XnPropertySetData::ConstIterator it = pSet->pData->Begin(); it != pSet->pData->End(); ++it) { // check if this module is a stream XnActualPropertiesHash* pModule = it->Value(); XnActualPropertiesHash::ConstIterator itProp = pModule->End(); if (XN_STATUS_OK == pModule->Find(XN_STREAM_PROPERTY_TYPE, itProp)) { // create a copy of the properties XnActualPropertiesHash streamProps(it->Key()); nRetVal = streamProps.CopyFrom(*pModule); XN_IS_STATUS_OK(nRetVal); // remove the type property nRetVal = streamProps.Remove(XN_STREAM_PROPERTY_TYPE); XN_IS_STATUS_OK(nRetVal); // and create the stream XnActualStringProperty* pActualProp = (XnActualStringProperty*)itProp->Value(); nRetVal = CreateStreamImpl(pActualProp->GetValue(), it->Key(), &streamProps); XN_IS_STATUS_OK(nRetVal); } } return (XN_STATUS_OK); }
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); }
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); }
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); }