コード例 #1
0
ファイル: nodeIterator.c プロジェクト: hakanernam/legato-af
//--------------------------------------------------------------------------------------------------
le_result_t ni_GoToParent
(
    ni_IteratorRef_t iteratorRef  ///< The iterator object to access.
)
//--------------------------------------------------------------------------------------------------
{
    // Update our path.
    if (le_pathIter_Append(iteratorRef->pathIterRef, "..") == LE_UNDERFLOW)
    {
        // Looks like there are no more parents in the chain.
        return LE_NOT_FOUND;
    }

    // Now, if we have a current node, just get it's parent node.  Otherwise make an attempt to see
    // if the requested parent node exists.
    if (iteratorRef->currentNodeRef != NULL)
    {
        iteratorRef->currentNodeRef = tdb_GetNodeParent(iteratorRef->currentNodeRef);
        LE_ASSERT(iteratorRef->currentNodeRef != NULL);
    }
    else
    {
        // Make an attempt to get the new current node.
        iteratorRef->currentNodeRef = ni_GetNode(iteratorRef, "");
    }

    return LE_OK;
}
コード例 #2
0
ファイル: nodeIterator.c プロジェクト: hakanernam/legato-af
//--------------------------------------------------------------------------------------------------
le_result_t ni_GetNodeName
(
    ni_IteratorRef_t iteratorRef,  ///< The iterator object to access.
    const char* pathPtr,           ///< Optional path to another node in the tree.
    char* destBufferPtr,           ///< The buffer to copy string data into.
    size_t bufferMax               ///< The maximum size of the string buffer.
)
//--------------------------------------------------------------------------------------------------
{
    // Make sure we were given a buffer.
    if (bufferMax == 0)
    {
        return LE_OVERFLOW;
    }

    // If we have a current node, get it's name.  Otherwise we'll have to get the name from the
    // path.
    tdb_NodeRef_t nodeRef = ni_GetNode(iteratorRef, pathPtr);

    if (nodeRef != NULL)
    {
        return tdb_GetNodeName(nodeRef, destBufferPtr, bufferMax);
    }

    // Clear out the target buffer and attempt get the last named segment on our path string.  If
    // that fails then we're on the root node and just return an empty string.
    *destBufferPtr = 0;

    if (le_pathIter_GoToEnd(iteratorRef->pathIterRef) != LE_OK)
    {
        return le_pathIter_GetCurrentNode(iteratorRef->pathIterRef, destBufferPtr, bufferMax);
    }

    return LE_OK;
}
コード例 #3
0
ファイル: nodeIterator.c プロジェクト: hakanernam/legato-af
//--------------------------------------------------------------------------------------------------
void ni_DeleteNode
(
    ni_IteratorRef_t iteratorRef,  ///< The iterator object to access.
    const char* newPathPtr         ///< Optional, can be used to specify a node relative to the
                                   ///<   current one.
)
//--------------------------------------------------------------------------------------------------
{
    // Delete the requested node, and then see if we can find our way back to where we were.
    tdb_NodeRef_t nodeRef = ni_GetNode(iteratorRef, newPathPtr);

    if (nodeRef)
    {
        tdb_DeleteNode(nodeRef);
        iteratorRef->currentNodeRef = ni_GetNode(iteratorRef, "");
    }
}
コード例 #4
0
ファイル: nodeIterator.c プロジェクト: hakanernam/legato-af
//--------------------------------------------------------------------------------------------------
le_cfg_nodeType_t ni_GetNodeType
(
    ni_IteratorRef_t iteratorRef,  ///< The iterator object to access.
    const char* pathPtr            ///< Optional.  If specified, this path can refer to another node
                                   ///<   in the tree.
)
//--------------------------------------------------------------------------------------------------
{
    return tdb_GetNodeType(ni_GetNode(iteratorRef, pathPtr));
}
コード例 #5
0
ファイル: nodeIterator.c プロジェクト: H-H-bin/legato-af
//--------------------------------------------------------------------------------------------------
le_result_t ni_GetNodeName
(
    ni_IteratorRef_t iteratorRef,  ///< [IN]  The iterator object to access.
    const char* pathPtr,           ///< [IN]  Optional path to another node in the tree.
    char* destBufferPtr,           ///< [OUT] The buffer to copy string data into.
    size_t bufferMax               ///< [IN]  The maximum size of the string buffer.
)
//--------------------------------------------------------------------------------------------------
{
    // Make sure we were given a buffer.
    if (bufferMax == 0)
    {
        return LE_OVERFLOW;
    }

    // If we have a current node, get it's name.  Otherwise we'll have to get the name from the
    // path.
    tdb_NodeRef_t nodeRef = ni_GetNode(iteratorRef, pathPtr);

    // If the iterator was closed during the GetNode, then that means there was a fatal problem
    // encountered.
    if (iteratorRef->isTerminated)
    {
        // At this point we know the client has been disconnected.  So just return fault so that the
        // calling code can know this.
        return LE_FAULT;
    }

    if (nodeRef != NULL)
    {
        return tdb_GetNodeName(nodeRef, destBufferPtr, bufferMax);
    }

    // Looks like a node wasn't found.  So, try to get the name of the node from the sub-path.  Or
    // if a sub-path was not specified, get the name from the iterator's base path.
    *destBufferPtr = '\0';

    if (strcmp(pathPtr, "") != 0)
    {
        le_pathIter_Ref_t subPathIter = le_pathIter_CreateForUnix(pathPtr);
        le_result_t result = le_pathIter_GoToEnd(iteratorRef->pathIterRef);

        if (result == LE_OK)
        {
            result = le_pathIter_GetCurrentNode(subPathIter, destBufferPtr, bufferMax);
        }

        le_pathIter_Delete(subPathIter);
        return result;
    }

    LE_ASSERT(le_pathIter_GoToEnd(iteratorRef->pathIterRef) == LE_OK);
    return le_pathIter_GetCurrentNode(iteratorRef->pathIterRef, destBufferPtr, bufferMax);
}
コード例 #6
0
// -------------------------------------------------------------------------------------------------
void le_cfgAdmin_ExportTree
(
    le_cfgAdmin_ServerCmdRef_t commandRef,  ///< [IN] Reference used to generate a reply for this
                                            ///<      request.
    le_cfg_IteratorRef_t externalRef,       ///< [IN] Write iterator that is being used for the
                                            ///<      export.
    const char* filePathPtr,                ///< [IN] Export the tree data to the this file.
    const char* nodePathPtr                 ///< [IN] Where in the tree should this export happen?
                                            ///<      Leave as an empty string to use the iterator's
                                            ///<      current node.
)
// -------------------------------------------------------------------------------------------------
{
    LE_DEBUG("** Exporting a tree from node '%s' into file '%s', using iterator, '%p'.",
             nodePathPtr, filePathPtr, externalRef);

    ni_IteratorRef_t iteratorRef = GetIteratorFromRef(externalRef);

    if (iteratorRef == NULL)
    {
        le_cfgAdmin_ExportTreeRespond(commandRef, LE_OK);
        return;
    }

    LE_DEBUG("Opening file '%s'.", filePathPtr);

    FILE* filePtr = NULL;

    filePtr = fopen(filePathPtr, "w+");

    if (!filePtr)
    {
        LE_ERROR("File '%s' could not be opened.", filePathPtr);
        le_cfgAdmin_ExportTreeRespond(commandRef, LE_IO_ERROR);

        return;
    }


    LE_DEBUG("Exporting config data.");

    le_result_t result = LE_OK;

    if (tdb_WriteTreeNode(ni_GetNode(iteratorRef, nodePathPtr), filePtr) != LE_OK)
    {
        result = LE_FAULT;
    }

    fclose(filePtr);

    le_cfgAdmin_ExportTreeRespond(commandRef, result);
}
コード例 #7
0
ファイル: nodeIterator.c プロジェクト: hakanernam/legato-af
//--------------------------------------------------------------------------------------------------
void ni_SetNodeValueString
(
    ni_IteratorRef_t iteratorRef,  ///< The iterator object to access.
    const char* pathPtr,           ///< Optional path to another node in the tree.
    const char* valuePtr           ///< Write this value into the tree.
)
//--------------------------------------------------------------------------------------------------
{
    tdb_NodeRef_t nodeRef = ni_GetNode(iteratorRef, pathPtr);

    if (nodeRef)
    {
        tdb_SetValueAsString(nodeRef, valuePtr);
    }
}
コード例 #8
0
ファイル: nodeIterator.c プロジェクト: hakanernam/legato-af
//--------------------------------------------------------------------------------------------------
void ni_SetEmpty
(
    ni_IteratorRef_t iteratorRef,  ///< The iterator object to access.
    const char* newPathPtr         ///< Optional, can be used to specify a node relative to the
                                   ///<   current one.
)
//--------------------------------------------------------------------------------------------------
{
    tdb_NodeRef_t nodeRef = ni_GetNode(iteratorRef, newPathPtr);

    if (nodeRef)
    {
        tdb_SetEmpty(nodeRef);
    }
}
コード例 #9
0
ファイル: nodeIterator.c プロジェクト: hakanernam/legato-af
//--------------------------------------------------------------------------------------------------
void ni_SetNodeValueBool
(
    ni_IteratorRef_t iteratorRef,  ///< The iterator object to access.
    const char* pathPtr,           ///< Optional path to another node in the tree.
    bool value                     ///< The value to write.
)
//--------------------------------------------------------------------------------------------------
{
    tdb_NodeRef_t nodeRef = ni_GetNode(iteratorRef, pathPtr);

    if (nodeRef)
    {
        tdb_SetValueAsBool(nodeRef, value);
    }
}
コード例 #10
0
ファイル: nodeIterator.c プロジェクト: hakanernam/legato-af
//--------------------------------------------------------------------------------------------------
bool ni_NodeExists
(
    ni_IteratorRef_t iteratorRef,  ///< The iterator object to access.
    const char* newPathPtr         ///< Optional, can be used to specify a node relative to the
                                   ///<   current one.
)
//--------------------------------------------------------------------------------------------------
{
    tdb_NodeRef_t nodeRef = ni_GetNode(iteratorRef, newPathPtr);

    if (nodeRef == NULL)
    {
        return false;
    }

    return tdb_GetNodeType(nodeRef) != LE_CFG_TYPE_DOESNT_EXIST;
}
コード例 #11
0
ファイル: nodeIterator.c プロジェクト: hakanernam/legato-af
//--------------------------------------------------------------------------------------------------
bool ni_GetNodeValueBool
(
    ni_IteratorRef_t iteratorRef,  ///< The iterator object to access.
    const char* pathPtr,           ///< Optional path to another node in the tree.
    bool defaultValue              ///< If the value can not be found, use this one instead.
)
//--------------------------------------------------------------------------------------------------
{
    tdb_NodeRef_t nodeRef = ni_GetNode(iteratorRef, pathPtr);

    if (nodeRef == NULL)
    {
        return defaultValue;
    }

    return tdb_GetValueAsBool(nodeRef, defaultValue);
}
コード例 #12
0
ファイル: nodeIterator.c プロジェクト: H-H-bin/legato-af
//--------------------------------------------------------------------------------------------------
bool ni_IsEmpty
(
    ni_IteratorRef_t iteratorRef,  ///< [IN] The iterator object to access.
    const char* newPathPtr         ///< [IN] Optional, can be used to specify a node relative to the
                                   ///<      current one.
)
//--------------------------------------------------------------------------------------------------
{
    tdb_NodeRef_t nodeRef = ni_GetNode(iteratorRef, newPathPtr);

    if (nodeRef)
    {
        return tdb_IsNodeEmpty(nodeRef);
    }

    return true;
}
コード例 #13
0
ファイル: nodeIterator.c プロジェクト: hakanernam/legato-af
//--------------------------------------------------------------------------------------------------
le_result_t ni_GetNodeValueString
(
    ni_IteratorRef_t iteratorRef,  ///< The iterator object to access.
    const char* pathPtr,           ///< Optional path to another node in the tree.
    char* destBufferPtr,           ///< The buffer to copy string data into.
    size_t bufferMax,              ///< The maximum size of the string buffer.
    const char* defaultPtr         ///< If the value can not be found, use this one instead.
)
//--------------------------------------------------------------------------------------------------
{
    tdb_NodeRef_t nodeRef = ni_GetNode(iteratorRef, pathPtr);

    if (nodeRef == NULL)
    {
        return le_utf8_Copy(destBufferPtr, defaultPtr, bufferMax, NULL);
    }

    return tdb_GetValueAsString(nodeRef, destBufferPtr, bufferMax, defaultPtr);
}
コード例 #14
0
ファイル: nodeIterator.c プロジェクト: hakanernam/legato-af
//--------------------------------------------------------------------------------------------------
le_result_t ni_SetNodeName
(
    ni_IteratorRef_t iteratorRef,  ///< The iterator object to access.
    const char* pathPtr,           ///< Optional path to another node in the tree.
    const char* namePtr            ///< The new name to use.
)
//--------------------------------------------------------------------------------------------------
{
    // Try to get the node, and if found, set the value.
    tdb_NodeRef_t nodeRef = ni_GetNode(iteratorRef, pathPtr);
    if (nodeRef)
    {
        return tdb_SetNodeName(nodeRef, namePtr);
    }

    // Because this is a write operation, and if the node wasn't found at this point then that means
    // there was a problem with the supplied path and ternimiate client was called, so we just
    // return LE_OK.
    return LE_OK;
}