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 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 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 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 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 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 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); }