Пример #1
0
//--------------------------------------------------------------------------------------------------
tdb_NodeRef_t ni_GetNode
(
    ni_IteratorRef_t iteratorRef,  ///< The iterator object to access.
    const char* subPathPtr         ///< Optional, can be used to specify a node relative to the
                                   ///<   current one.
)
//--------------------------------------------------------------------------------------------------
{
    // Check to see if we have a current node.  If we do, then attempt to traverse from our current
    // node, to the requested sub-node.  If the new path is NULL or empty, then we'll just end up
    // getting our current node.
    if (iteratorRef->currentNodeRef != NULL)
    {
        le_pathIter_Ref_t newPathRef = le_pathIter_CreateForUnix(subPathPtr);
        tdb_NodeRef_t nodeRef = tdb_GetNode(iteratorRef->currentNodeRef, newPathRef);

        le_pathIter_Delete(newPathRef);

        return nodeRef;
    }

    // Ok, the iterator doesn't have a current node.  So, copy iterator's existing path, and append
    // the new sub path to the existing path.  Once that's done, attempt to find the requested node
    // in the tree.  If the node still can not be found, return NULL.
    le_pathIter_Ref_t newPathRef = le_pathIter_Clone(iteratorRef->pathIterRef);
    tdb_NodeRef_t nodeRef = NULL;
    le_result_t result = LE_OK;

    if (subPathPtr != NULL)
    {
        result = le_pathIter_Append(newPathRef, subPathPtr);
    }

    // Make sure that the append was successful.  If it is, get the node.
    if (result == LE_OVERFLOW)
    {
        tu_TerminateClient(iteratorRef->sessionRef, "Specified path too large.");
    }
    else if (result == LE_UNDERFLOW)
    {
        tu_TerminateClient(iteratorRef->sessionRef,
                           "Specified path attempts to iterate below root.");
    }
    else
    {
        nodeRef = tdb_GetNode(tdb_GetRootNode(iteratorRef->treeRef), newPathRef);
    }

    le_pathIter_Delete(newPathRef);

    return nodeRef;
}
Пример #2
0
//--------------------------------------------------------------------------------------------------
tdb_NodeRef_t ni_TryCreateNode
(
    ni_IteratorRef_t iteratorRef,  ///< [IN] The iterator object to access.
    const char* subPathPtr         ///< [IN] Optional, can be used to specify a node relative to the
                                   ///<      current one.
)
//--------------------------------------------------------------------------------------------------
{
    // Clone the iterator's original path and, if supplied, append the new sub path onto this new
    // path.
    le_pathIter_Ref_t newPathRef = NULL;

    if (CloneAndAppendPath(iteratorRef, subPathPtr, &newPathRef) != LE_OK)
    {
        return NULL;
    }

    // Attempt to find the node in the tree.  If not found attempt to create the new node in the
    // tree.
    tdb_NodeRef_t rootNodeRef = tdb_GetRootNode(iteratorRef->treeRef);
    tdb_NodeRef_t nodeRef = tdb_GetNode(rootNodeRef, newPathRef);

    if (nodeRef == NULL)
    {
        nodeRef = tdb_CreateNodePath(rootNodeRef, newPathRef);
    }

    le_pathIter_Delete(newPathRef);
    return nodeRef;
}
Пример #3
0
//--------------------------------------------------------------------------------------------------
le_result_t ni_GoToNode
(
    ni_IteratorRef_t iteratorRef,  ///< The iterator object to access.
    const char* newPathPtr         ///< Path to the new location in the tree to jump to.
)
//--------------------------------------------------------------------------------------------------
{
    LE_ASSERT(iteratorRef != NULL);
    LE_ASSERT(le_pathIter_IsAbsolute(iteratorRef->pathIterRef) == true);

    le_result_t result = le_pathIter_Append(iteratorRef->pathIterRef, newPathPtr);

    if (result == LE_OK)
    {
        tdb_TreeRef_t treeRef = iteratorRef->treeRef;

        iteratorRef->currentNodeRef = tdb_GetNode(tdb_GetRootNode(treeRef),
                                                  iteratorRef->pathIterRef);

    }

    return result;
}
Пример #4
0
//--------------------------------------------------------------------------------------------------
tdb_NodeRef_t ni_GetNode
(
    ni_IteratorRef_t iteratorRef,  ///< [IN] The iterator object to access.
    const char* subPathPtr         ///< [IN] Optional, can be used to specify a node relative to the
                                   ///<      current one.
)
//--------------------------------------------------------------------------------------------------
{
    // Copy iterator's existing path, and append the new sub path to the copied path.  Once
    // that's done, attempt to find the requested node in the tree.  If the node still can not be
    // found, return NULL.
    le_pathIter_Ref_t newPathRef = NULL;

    if (CloneAndAppendPath(iteratorRef, subPathPtr, &newPathRef) != LE_OK)
    {
        return NULL;
    }

    tdb_NodeRef_t nodeRef = tdb_GetNode(tdb_GetRootNode(iteratorRef->treeRef), newPathRef);

    le_pathIter_Delete(newPathRef);

    return nodeRef;
}