XnStatus xnConfigureCreateNodes(XnContext* pContext, const TiXmlElement* pRootElem, XnEnumerationErrors* pErrors) { XnStatus nRetVal = XN_STATUS_OK; const TiXmlElement* pProudctionNodes = pRootElem->FirstChildElement("ProductionNodes"); if (pProudctionNodes == NULL) { printf("XnXMLConfig::xnConfigureCreateNodes(): firstChildElement == ProductionNodes == NULL\n"); return (XN_STATUS_OK); } // global mirror printf("XnXMLConfig::xnConfigureCreateNodes(): Check GlobalMirror\n"); const TiXmlElement* pGlobalMirror = pProudctionNodes->FirstChildElement("GlobalMirror"); if (pGlobalMirror != NULL) { XnBool bOn; nRetVal = xnXmlReadBoolAttribute(pGlobalMirror, "on", &bOn); XN_IS_STATUS_OK(nRetVal); nRetVal = xnSetGlobalMirror(pContext, bOn); XN_IS_STATUS_OK(nRetVal); } // file recordings const TiXmlElement* pRecording = pProudctionNodes->FirstChildElement("Recording"); if (pRecording != NULL) { const XnChar* strFileName; nRetVal = xnXmlReadStringAttribute(pRecording, "file", &strFileName); XN_IS_STATUS_OK(nRetVal); xnLogVerbose(XN_MASK_OPEN_NI, "Opening file recording '%s'...", strFileName); nRetVal = xnContextOpenFileRecording(pContext, strFileName); XN_IS_STATUS_OK(nRetVal); } const XnChar* strNodeTagName = "Node"; const XnChar* strStartGeneratingAttr = "startGenerating"; XnBool bStartGeneratingAll = TRUE; if (NULL != pProudctionNodes->Attribute(strStartGeneratingAttr)) { nRetVal = xnXmlReadBoolAttribute(pProudctionNodes, strStartGeneratingAttr, &bStartGeneratingAll); XN_IS_STATUS_OK(nRetVal); } // new nodes printf("XnXMLConfig::xnConfigureCreateNodes(): Start iterating over production nodes.\n"); const TiXmlElement* pNode = pProudctionNodes->FirstChildElement(strNodeTagName); while (pNode != NULL) { // get type const XnChar* strType; nRetVal = xnXmlReadStringAttribute(pNode, "type", &strType); XN_IS_STATUS_OK(nRetVal); xnLogVerbose(XN_MASK_OPEN_NI, "Requested to create a node of type %s...", strType); XnProductionNodeType Type; printf("XnXMLConfig::xnConfigureCreateNodes(): call to xnProductionNodeTypeFromString()\n"); nRetVal = xnProductionNodeTypeFromString(strType, &Type); printf("ProductoniNodeType (see Include/XnTypes.h): %d\n", Type); XN_IS_STATUS_OK(nRetVal); // check if there is a query XnNodeQuery* pQuery = NULL; const TiXmlElement* pQueryElem = pNode->FirstChildElement("Query"); if (pQueryElem != NULL) { nRetVal = xnNodeQueryAllocate(&pQuery); XN_IS_STATUS_OK(nRetVal); nRetVal = xnXmlReadQuery(pQueryElem, pQuery); XN_IS_STATUS_OK(nRetVal); } // enumerate XnNodeInfoList* pTrees; printf("XnXMLConfig::xnConfigureCreateNodes(): call to xnEnumerateProductionTrees\n"); nRetVal = xnEnumerateProductionTrees(pContext, Type, pQuery, &pTrees, pErrors); // @todo Porting to Mac - this is where it goes wrong. XN_IS_STATUS_OK(nRetVal); if (pQuery != NULL) { xnNodeQueryFree(pQuery); pQuery = NULL; } // choose first one XnNodeInfoListIterator itChosen = xnNodeInfoListGetFirst(pTrees); XnNodeInfo* pChosenInfo = xnNodeInfoListGetCurrent(itChosen); // check if a name was requested if (NULL != pNode->Attribute("name")) { const XnChar* strName = NULL; nRetVal = xnXmlReadStringAttribute(pNode, "name", &strName); if (nRetVal != XN_STATUS_OK) { xnNodeInfoListFree(pTrees); return (nRetVal); } nRetVal = xnNodeInfoSetInstanceName(pChosenInfo, strName); if (nRetVal != XN_STATUS_OK) { xnNodeInfoListFree(pTrees); return (nRetVal); } } // create it printf("XnXMLConfig::xnConfigureCreateNodes(): call to xnCreateProductionTree()"); XnNodeHandle hNode; nRetVal = xnCreateProductionTree(pContext, pChosenInfo, &hNode); if (nRetVal != XN_STATUS_OK) { xnNodeInfoListFree(pTrees); return (nRetVal); } // free the list xnNodeInfoListFree(pTrees); // config it nRetVal = xnConfigureNodeFromXml(hNode, pNode); XN_IS_STATUS_OK(nRetVal); // check if we need to start it (if start generating all is on, it will be started at the end) XnBool bStart = FALSE; if (!bStartGeneratingAll) { if (NULL != pNode->Attribute(strStartGeneratingAttr)) { nRetVal = xnXmlReadBoolAttribute(pNode, strStartGeneratingAttr, &bStart); XN_IS_STATUS_OK(nRetVal); } if (bStart) { nRetVal = xnStartGenerating(hNode); XN_IS_STATUS_OK(nRetVal); } } pNode = pNode->NextSiblingElement(strNodeTagName); } // start generating all if (bStartGeneratingAll) { nRetVal = xnStartGeneratingAll(pContext); XN_IS_STATUS_OK(nRetVal); } return (XN_STATUS_OK); }
XnStatus xnConfigureCreateNodes(XnContext* pContext, const TiXmlElement* pRootElem, XnNodeInfoList* pCreatedNodes, XnEnumerationErrors* pErrors) { XnStatus nRetVal = XN_STATUS_OK; const TiXmlElement* pProudctionNodes = pRootElem->FirstChildElement("ProductionNodes"); if (pProudctionNodes == NULL) { return (XN_STATUS_OK); } // global mirror const TiXmlElement* pGlobalMirror = pProudctionNodes->FirstChildElement("GlobalMirror"); if (pGlobalMirror != NULL) { XnBool bOn; nRetVal = xnXmlReadBoolAttribute(pGlobalMirror, "on", &bOn); XN_IS_STATUS_OK(nRetVal); nRetVal = xnSetGlobalMirror(pContext, bOn); XN_IS_STATUS_OK(nRetVal); } // file recordings const TiXmlElement* pRecording = pProudctionNodes->FirstChildElement("Recording"); if (pRecording != NULL) { const XnChar* strFileName; nRetVal = xnXmlReadStringAttribute(pRecording, "file", &strFileName); XN_IS_STATUS_OK(nRetVal); xnLogVerbose(XN_MASK_OPEN_NI, "Opening file recording '%s'...", strFileName); XnNodeHandle hPlayer; nRetVal = xnContextOpenFileRecordingEx(pContext, strFileName, &hPlayer); XN_IS_STATUS_OK(nRetVal); nRetVal = xnNodeInfoListAddNode(pCreatedNodes, hPlayer->pNodeInfo); if (nRetVal != XN_STATUS_OK) { xnProductionNodeRelease(hPlayer); return (nRetVal); } XnDouble dSpeed = 1.0; if (NULL != pRecording->Attribute("playbackSpeed", &dSpeed)) { nRetVal = xnSetPlaybackSpeed(hPlayer, dSpeed); XN_IS_STATUS_OK(nRetVal); } const XnChar* REPEAT = "repeat"; if (NULL != pRecording->Attribute(REPEAT)) { XnBool bRepeat; nRetVal = xnXmlReadBoolAttribute(pRecording, REPEAT, &bRepeat); XN_IS_STATUS_OK(nRetVal); nRetVal = xnSetPlayerRepeat(hPlayer, bRepeat); XN_IS_STATUS_OK(nRetVal); } } const XnChar* strNodeTagName = "Node"; const XnChar* strStartGeneratingAttr = "startGenerating"; XnBool bStartGeneratingAll = TRUE; if (NULL != pProudctionNodes->Attribute(strStartGeneratingAttr)) { nRetVal = xnXmlReadBoolAttribute(pProudctionNodes, strStartGeneratingAttr, &bStartGeneratingAll); XN_IS_STATUS_OK(nRetVal); } // new nodes const TiXmlElement* pNode = pProudctionNodes->FirstChildElement(strNodeTagName); while (pNode != NULL) { // get type const XnChar* strType; nRetVal = xnXmlReadStringAttribute(pNode, "type", &strType); XN_IS_STATUS_OK(nRetVal); // check stopOnError status XnBool bStopOnError = TRUE; if (NULL != pNode->Attribute("stopOnError")) { nRetVal = xnXmlReadBoolAttribute(pNode, "stopOnError", &bStopOnError); XN_IS_STATUS_OK(nRetVal); } xnLogVerbose(XN_MASK_OPEN_NI, "Requested to create a node of type %s%s...", strType, bStopOnError ? "" : " (StopOnError=FALSE)"); XnProductionNodeType Type; nRetVal = xnProductionNodeTypeFromString(strType, &Type); XN_IS_STATUS_OK(nRetVal); // check if there is a query XnNodeQuery* pQuery = NULL; const TiXmlElement* pQueryElem = pNode->FirstChildElement("Query"); if (pQueryElem != NULL) { nRetVal = xnNodeQueryAllocate(&pQuery); XN_IS_STATUS_OK(nRetVal); nRetVal = xnXmlReadQuery(pQueryElem, pQuery); XN_IS_STATUS_OK(nRetVal); } // enumerate XnNodeInfoList* pTrees; nRetVal = xnEnumerateProductionTrees(pContext, Type, pQuery, &pTrees, pErrors); if (nRetVal == XN_STATUS_NO_NODE_PRESENT && !bStopOnError) { // go to next one pNode = pNode->NextSiblingElement(strNodeTagName); continue; } XN_IS_STATUS_OK(nRetVal); if (pQuery != NULL) { xnNodeQueryFree(pQuery); pQuery = NULL; } // choose first one XnNodeInfoListIterator itChosen = xnNodeInfoListGetFirst(pTrees); XnNodeInfo* pChosenInfo = xnNodeInfoListGetCurrent(itChosen); // check if a name was requested if (NULL != pNode->Attribute("name")) { const XnChar* strName = NULL; nRetVal = xnXmlReadStringAttribute(pNode, "name", &strName); if (nRetVal != XN_STATUS_OK) { xnNodeInfoListFree(pTrees); return (nRetVal); } nRetVal = xnNodeInfoSetInstanceName(pChosenInfo, strName); if (nRetVal != XN_STATUS_OK) { xnNodeInfoListFree(pTrees); return (nRetVal); } } // create it XnNodeHandle hNode; nRetVal = xnCreateProductionTree(pContext, pChosenInfo, &hNode); if (nRetVal != XN_STATUS_OK) { xnNodeInfoListFree(pTrees); return (nRetVal); } // free the list xnNodeInfoListFree(pTrees); // add it to the list of created nodes nRetVal = xnNodeInfoListAddNode(pCreatedNodes, pChosenInfo); if (nRetVal != XN_STATUS_OK) { xnProductionNodeRelease(hNode); return (nRetVal); } // config it nRetVal = xnConfigureNodeFromXml(hNode, pNode); if (nRetVal != XN_STATUS_OK) { xnProductionNodeRelease(hNode); return (nRetVal); } // check if we need to start it (if start generating all is on, it will be started at the end) XnBool bStart = FALSE; if (!bStartGeneratingAll) { if (NULL != pNode->Attribute(strStartGeneratingAttr)) { nRetVal = xnXmlReadBoolAttribute(pNode, strStartGeneratingAttr, &bStart); if (nRetVal != XN_STATUS_OK) { xnProductionNodeRelease(hNode); return (nRetVal); } } if (bStart) { nRetVal = xnStartGenerating(hNode); if (nRetVal != XN_STATUS_OK) { xnProductionNodeRelease(hNode); return (nRetVal); } } } pNode = pNode->NextSiblingElement(strNodeTagName); } // start generating all created nodes (by the order they were created in) if (bStartGeneratingAll) { XnBool bIsGenerator; for (XnNodeInfoListIterator it = xnNodeInfoListGetFirst(pCreatedNodes); xnNodeInfoListIteratorIsValid(it); it = xnNodeInfoListGetNext(it)) { XnNodeInfo* pNodeInfo = xnNodeInfoListGetCurrent(it); nRetVal = TypeManager::GetInstance().IsTypeDerivedFrom(pNodeInfo->Description.Type, XN_NODE_TYPE_GENERATOR, &bIsGenerator); XN_IS_STATUS_OK(nRetVal); if (bIsGenerator) { XN_ASSERT(pNodeInfo->hNode != NULL); nRetVal = xnStartGenerating(pNodeInfo->hNode); XN_IS_STATUS_OK(nRetVal); } } } return (XN_STATUS_OK); }
XnStatus xnConfigureCreateNodes(XnContext* pContext, const TiXmlElement* pRootElem, XnEnumerationErrors* pErrors) { XnStatus nRetVal = XN_STATUS_OK; const TiXmlElement* pProudctionNodes = pRootElem->FirstChildElement("ProductionNodes"); if (pProudctionNodes == NULL) { return (XN_STATUS_OK); } // global mirror const TiXmlElement* pGlobalMirror = pProudctionNodes->FirstChildElement("GlobalMirror"); if (pGlobalMirror != NULL) { XnBool bOn; nRetVal = xnXmlReadBoolAttribute(pGlobalMirror, "on", &bOn); XN_IS_STATUS_OK(nRetVal); nRetVal = xnSetGlobalMirror(pContext, bOn); XN_IS_STATUS_OK(nRetVal); } // file recordings const TiXmlElement* pRecording = pProudctionNodes->FirstChildElement("Recording"); if (pRecording != NULL) { const XnChar* strFileName; nRetVal = xnXmlReadStringAttribute(pRecording, "file", &strFileName); XN_IS_STATUS_OK(nRetVal); xnLogVerbose(XN_MASK_OPEN_NI, "Opening file recording '%s'...", strFileName); nRetVal = xnContextOpenFileRecording(pContext, strFileName); XN_IS_STATUS_OK(nRetVal); XnDouble dSpeed = 1.0; if (NULL != pRecording->Attribute("playbackSpeed", &dSpeed)) { XnNodeHandle hPlayer; nRetVal = xnFindExistingNodeByType(pContext, XN_NODE_TYPE_PLAYER, &hPlayer); XN_IS_STATUS_OK(nRetVal); nRetVal = xnSetPlaybackSpeed(hPlayer, dSpeed); XN_IS_STATUS_OK(nRetVal); } } const XnChar* strNodeTagName = "Node"; const XnChar* strStartGeneratingAttr = "startGenerating"; XnBool bStartGeneratingAll = TRUE; if (NULL != pProudctionNodes->Attribute(strStartGeneratingAttr)) { nRetVal = xnXmlReadBoolAttribute(pProudctionNodes, strStartGeneratingAttr, &bStartGeneratingAll); XN_IS_STATUS_OK(nRetVal); } // new nodes const TiXmlElement* pNode = pProudctionNodes->FirstChildElement(strNodeTagName); while (pNode != NULL) { // get type const XnChar* strType; nRetVal = xnXmlReadStringAttribute(pNode, "type", &strType); XN_IS_STATUS_OK(nRetVal); xnLogVerbose(XN_MASK_OPEN_NI, "Requested to create a node of type %s...", strType); XnProductionNodeType Type; nRetVal = xnProductionNodeTypeFromString(strType, &Type); XN_IS_STATUS_OK(nRetVal); // check if there is a query XnNodeQuery* pQuery = NULL; const TiXmlElement* pQueryElem = pNode->FirstChildElement("Query"); if (pQueryElem != NULL) { nRetVal = xnNodeQueryAllocate(&pQuery); XN_IS_STATUS_OK(nRetVal); nRetVal = xnXmlReadQuery(pQueryElem, pQuery); XN_IS_STATUS_OK(nRetVal); } // enumerate XnNodeInfoList* pTrees; nRetVal = xnEnumerateProductionTrees(pContext, Type, pQuery, &pTrees, pErrors); XN_IS_STATUS_OK(nRetVal); if (pQuery != NULL) { xnNodeQueryFree(pQuery); pQuery = NULL; } // choose first one XnNodeInfoListIterator itChosen = xnNodeInfoListGetFirst(pTrees); XnNodeInfo* pChosenInfo = xnNodeInfoListGetCurrent(itChosen); // check if a name was requested if (NULL != pNode->Attribute("name")) { const XnChar* strName = NULL; nRetVal = xnXmlReadStringAttribute(pNode, "name", &strName); if (nRetVal != XN_STATUS_OK) { xnNodeInfoListFree(pTrees); return (nRetVal); } nRetVal = xnNodeInfoSetInstanceName(pChosenInfo, strName); if (nRetVal != XN_STATUS_OK) { xnNodeInfoListFree(pTrees); return (nRetVal); } } // create it XnNodeHandle hNode; nRetVal = xnCreateProductionTree(pContext, pChosenInfo, &hNode); if (nRetVal != XN_STATUS_OK) { xnNodeInfoListFree(pTrees); return (nRetVal); } // free the list xnNodeInfoListFree(pTrees); // config it nRetVal = xnConfigureNodeFromXml(hNode, pNode); XN_IS_STATUS_OK(nRetVal); // check if we need to start it (if start generating all is on, it will be started at the end) XnBool bStart = FALSE; if (!bStartGeneratingAll) { if (NULL != pNode->Attribute(strStartGeneratingAttr)) { nRetVal = xnXmlReadBoolAttribute(pNode, strStartGeneratingAttr, &bStart); XN_IS_STATUS_OK(nRetVal); } if (bStart) { nRetVal = xnStartGenerating(hNode); XN_IS_STATUS_OK(nRetVal); } } pNode = pNode->NextSiblingElement(strNodeTagName); } // start generating all if (bStartGeneratingAll) { nRetVal = xnStartGeneratingAll(pContext); XN_IS_STATUS_OK(nRetVal); } return (XN_STATUS_OK); }