| 1591 | } |
| 1592 | |
| 1593 | static XnStatus xnCreateProductionNodeImpl(XnContext* pContext, XnNodeInfo* pTree, XnNodeHandle* phNode) |
| 1594 | { |
| 1595 | XnStatus nRetVal = XN_STATUS_OK; |
| 1596 | |
| 1597 | *phNode = NULL; |
| 1598 | |
| 1599 | // first of all, check if name is empty, if so - give it a default name |
| 1600 | if (pTree->strInstanceName[0] == '\0') |
| 1601 | { |
| 1602 | xnFindValidNameForType(pContext, pTree->Description.Type, pTree->strInstanceName); |
| 1603 | } |
| 1604 | |
| 1605 | XnChar strDescription[500]; |
| 1606 | xnProductionNodeDescriptionToString(&pTree->Description, strDescription, 500); |
| 1607 | xnLoggerInfo(g_logger, "Creating node '%s' of type %s...", pTree->strInstanceName, strDescription); |
| 1608 | |
| 1609 | XnModuleInstance* pModuleInstance; |
| 1610 | nRetVal = pContext->moduleLoader.CreateRootNode(pContext, pTree, &pModuleInstance); |
| 1611 | XN_IS_STATUS_OK(nRetVal); |
| 1612 | |
| 1613 | // create handle |
| 1614 | XnInternalNodeData* pNodeData; |
| 1615 | XN_VALIDATE_CALLOC(pNodeData, XnInternalNodeData, 1); |
| 1616 | |
| 1617 | pNodeData->pTypeHierarchy = XN_NEW(XnBitSet); |
| 1618 | if (pNodeData->pTypeHierarchy == NULL) |
| 1619 | { |
| 1620 | return xnFreeProductionNodeImpl(pNodeData, XN_STATUS_ALLOC_FAILED); |
| 1621 | } |
| 1622 | |
| 1623 | *pNodeData->pTypeHierarchy = pModuleInstance->pLoaded->pInterface->HierarchyType; |
| 1624 | pNodeData->pNodeInfo = pTree; |
| 1625 | pNodeData->nRefCount = 1; |
| 1626 | pNodeData->pModuleInstance = pModuleInstance; |
| 1627 | |
| 1628 | // reference context |
| 1629 | nRetVal = xnContextAddRef(pContext); |
| 1630 | if (nRetVal != XN_STATUS_OK) |
| 1631 | { |
| 1632 | return xnFreeProductionNodeImpl(pNodeData, nRetVal); |
| 1633 | } |
| 1634 | pNodeData->pContext = pContext; |
| 1635 | |
| 1636 | nRetVal = xnOSCreateCriticalSection(&pNodeData->hLock); |
| 1637 | if (nRetVal != XN_STATUS_OK) |
| 1638 | { |
| 1639 | return xnFreeProductionNodeImpl(pNodeData, nRetVal); |
| 1640 | } |
| 1641 | |
| 1642 | pNodeData->pNeededNodesDataHash = XN_NEW(XnNeededNodesDataHash); |
| 1643 | |
| 1644 | if (pNodeData->pNeededNodesDataHash == NULL) |
| 1645 | { |
| 1646 | return xnFreeProductionNodeImpl(pNodeData, XN_STATUS_ALLOC_FAILED); |
| 1647 | } |
| 1648 | |
| 1649 | pNodeData->pRegistrationCookiesHash = XN_NEW(XnModuleStateCookieHash); |
| 1650 |
no test coverage detected