⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pvaltree.c

📁 基于h323协议的软phone
💻 C
📖 第 1 页 / 共 5 页
字号:
        lbrotherId = currId;
        currId = pvtBrother(hVal, currId);
    }

    RvMutexUnlock(&vt->mutex);
    return lbrotherId;
}


/************************************************************************
 * pvtChild
 * purpose: Returns the Node ID of the first (leftmost) child of a parent.
 * input  : valH        - The PVT handle
 *          parentId    - The ID of any node
 * output : none
 * return : The Node ID of the first (leftmost) child of a parent on success
 *          Negative value on failure
 ************************************************************************/
RVAPI RvPvtNodeId RVCALLCONV
pvtChild(
       IN  HPVT         hVal,
       IN  RvPvtNodeId  parentId)
{
    RvPvtNodeId result;
    vtStruct *vt = (vtStruct *)hVal;
    if (!vt)
        return RV_PVT_ERROR_UNKNOWN;

    RvMutexLock(&vt->mutex);
    result = (RvPvtNodeId)rtHead(vt->vTree, (int)parentId);
    RvMutexUnlock(&vt->mutex);

    return result;
}


/************************************************************************
 * pvtNext
 * purpose: Returns the ID of a node located after a specified node.
 * input  : valH    - The PVT handle
 *          rootId  - The ID of the root node of the current Value Tree
 *          location- A Node ID inside the given root
 * output : none
 * return : The Node ID of the next node in the tree on success - this
 *          value should be given as the location on the next call.
 *          Negative value on failure
 ************************************************************************/
RVAPI RvPvtNodeId RVCALLCONV
pvtNext(
    IN  HPVT            hVal,
    IN  RvPvtNodeId     rootId,
    IN  RvPvtNodeId     location)
{
    RvPvtNodeId result;
    vtStruct *vt = (vtStruct *)hVal;
    if (!vt)
        return RV_PVT_ERROR_UNKNOWN;

    RvMutexLock(&vt->mutex);
    result = (RvPvtNodeId)rtNext(vt->vTree, (int)rootId, (int)location);
    RvMutexUnlock(&vt->mutex);

    return result;
}


/************************************************************************
 * pvtAddRootFromInt
 * purpose: Add a new root to PVT. This function should not be used
 *          directly by user applications. It is called internally through
 *          macros or other stack functions.
 * input  : hVal    - PVT handle to use
 *          hSyn    - Syntax tree to use
 *                    Can be set to -1 if it will be supplied later (by pvtSetTree)
 *          nodePath- Syntax node Id to use for the root.
 *                    Can be set to -1 if it will be supplied later or if
 *                    it should be the root of the syntax tree created.
 *          value   - Value of the root node, or length of the value if
 *                    value is a string
 *          string  - String value of the node, or NULL if not a string
 *          fileName- Filename that called this function
 *                    NULL if unknown
 *          lineno  - Line number in the filename that called this function
 *                    0 if unknown
 * output : none
 * return : Node id of the added root on success
 *          Negative value on failure
 ************************************************************************/
RVAPI RvPvtNodeId RVCALLCONV
pvtAddRootFromInt(
           IN  HPVT         hVal,
           IN  HPST         hSyn,
           IN  RvPstNodeId  nodePath,
           IN  RvInt32      value,
           IN  const char*  string,
           IN  const char*  fileName,
           IN  int          lineno)
{
    vtStruct *vt = (vtStruct *)hVal;
    RvPvtNodeId path, result;
    if (lineno || fileName);

    if (!vt) return RV_PVT_ERROR_UNKNOWN;
    RvMutexLock(&vt->mutex);

    /* Try and add the new root */
    path = (RvPvtNodeId)rtAddRoot(vt->vTree, NULL);
    if (!RV_PVT_NODEID_IS_VALID(path))
    {
        RvLogError(&vt->log,
            (&vt->log, "pvtAddRootFromInt: (@%s:%d) Cannot add root [size=%d]",
                 nprn(fileName), lineno, rtCurSize(vt->vTree)));
        RvMutexUnlock(&vt->mutex);
        return RV_PVT_ERROR_OUTOFRESOURCES;
    }

    RvLogDebug(&vt->log,
        (&vt->log, "pvtAddRootFromInt: (@%s:%d) hVal=0x%p. Added root=%d",
             nprn(fileName), lineno, hVal, path));

    /* Make sure we know the syntax node Id of the added node */
    if (!RV_PST_NODEID_IS_VALID(nodePath))
        nodePath = pstGetRoot(hSyn);

    /* Set the value of the root node */
    result = pvtSetNode(hVal, hSyn, path, nodePath, RV_PVT_ERROR_UNKNOWN, RV_ERROR_UNKNOWN, value, string, NULL);

    RvMutexUnlock(&vt->mutex);
    return result;
}


/* Remove definitions of macros for these functions. The definitions are there to allow
   printing information about these functions */
#if defined(pvtAddRoot) || defined(pvtAddRootByPath)
#undef pvtAddRoot
#undef pvtAddRootByPath
#endif


/************************************************************************
 * pvtAddRoot
 * purpose: Adds a new node that constitutes the root of a new tree.
 * input  : valH    - PVT handle to use
 *          synH    - Syntax tree to use
 *                    Can be set to -1 if it will be supplied later (by pvtSetTree)
 *          value   - Value of the root node, or length of the value if
 *                    value is a string
 *          string  - String value of the node, or NULL if not a string
 * output : none
 * return : Node id of the added root on success
 *          Negative value on failure
 ************************************************************************/
RVAPI RvPvtNodeId RVCALLCONV
pvtAddRoot(
    IN  HPVT        valH,
    IN  HPST        synH,
    IN  RvInt32     value,
    IN  const char* string)
{
    return pvtAddRootFromInt(valH, synH, RV_PST_INVALID_NODEID, value,  string, __FILE__, __LINE__);
}



/************************************************************************
 * pvtAddRootByPath
 * purpose: Adds a new node that constitutes the root of a new tree.
 * input  : valH        - PVT handle to use
 *          synH        - Syntax tree to use
 *                        Can be set to -1 if it will be supplied later (by pvtSetTree)
 *          syntaxPath  - A path separated by periods (for example, "a.b.c") that
 *                        identifies the node of the Value Tree's syntax node.
 *                        The path starts from the syntax handle root node
 *          value       - Value of the root node, or length of the value if
 *                        value is a string
 *          string      - String value of the node, or NULL if not a string
 * output : none
 * return : Node id of the added root on success
 *          Negative value on failure
 ************************************************************************/
RVAPI RvPvtNodeId RVCALLCONV
pvtAddRootByPath(
    IN  HPVT    valH,
    IN  HPST    synH,
    IN  char*   syntaxPath,
    IN  RvInt32 value,
    IN  char*   string)
{
    return pvtAddRootFromInt(valH, synH, pstGetNodeIdByPath(synH, syntaxPath), value, string, __FILE__, __LINE__);
}




/************************************************************************
 * pvtAdd
 * purpose: Add child node under parentId.
 *          The new node is placed in its relative position according to syntax tree
 *          indexing of SEQUENCE fields of structure.
 * input  : valH        - PVT handle to use
 *          parentId    - The Node ID of the immediate parent of the new node.
 *          fieldId     - The field ID returned by pstGetFieldId().
 *                        If set to -1, it will be copied from the parent node.
 *          value       - Value of the root node, or length of the value if
 *                        value is a string
 *          string      - String value of the node, or NULL if not a string
 * output : index       - The index of the added child (1-based)
 * return : Node id of the added node on success
 *          Negative value on failure
 ************************************************************************/
RVAPI RvPvtNodeId RVCALLCONV
pvtAdd(
    IN  HPVT            hVal,
    IN  RvPvtNodeId     parentId,
    IN  RvPstFieldId    fieldId,
    IN  RvInt32         value,
    IN  const char*     string,
    OUT int*            index)
{
    RvPvtNodeId result;
    vtStruct* vt = (vtStruct *)hVal;

    RvMutexLock(&vt->mutex);
    result = pvtAddSyn(hVal, (HPST)-1, parentId, fieldId, value, string, NULL, index);
    RvMutexUnlock(&vt->mutex);

    return result;
}


/************************************************************************
 * pvtAddTree
 * purpose: Copies a sub-tree and places it under a specified parent in
 *          another sub-tree.
 * input  : destH       - The handle returned by cmGetValTree() for the
 *                        parent (destination).
 *          destNodeId  - The Node ID of the parent (destination).
 *                        The new sub-tree is placed under this node.
 *          srcH        - The handle returned by cmGetValTree() for the
 *                        source (copied sub-tree).
 *          srcNodeId   - The ID of the root node of the source sub-tree.
 * output : none
 * return : Node id of the added node on success
 *          Negative value on failure
 ************************************************************************/
RVAPI RvPvtNodeId RVCALLCONV
pvtAddTree(
    IN  HPVT        destH,
    IN  RvPvtNodeId destNodeId,
    IN  HPVT        srcH,
    IN  RvPvtNodeId srcNodeId)
{
    vtStructs   v;
    RvMutex *   mutex1, * mutex2;
    RvPvtNodeId result;

    if (!destH || !srcH) return RV_PVT_ERROR_UNKNOWN;

    v.dest = (vtStruct *)destH;
    v.src = (vtStruct *)srcH;

    /* Make sure we lock an an orderly fashion to diminish dead-locking possibilities */
    if (destH > srcH)
    {
        mutex1 = &v.src->mutex;
        mutex2 = &v.dest->mutex;
    }
    else
    {
        mutex1 = &v.dest->mutex;
        mutex2 = &v.src->mutex;
    }

    RvMutexLock(mutex1);
    RvMutexLock(mutex2);
    result = (RvPvtNodeId)rtAdd(v.dest->vTree, (int)destNodeId, v.src->vTree, (int)srcNodeId, pvtAddTreeFunc, (void *)&v);
    RvMutexUnlock(mutex2);
    RvMutexUnlock(mutex1);

    return result;
}


/************************************************************************
 * pvtAddChilds
 * purpose: Copies a sub-tree, excluding its root node, and places it under
 *          a specified parent.
 * input  : destH       - The handle returned by cmGetValTree() for the
 *                        parent (destination).
 *          destNodeId  - The Node ID of the parent (destination).
 *                        The new sub-tree is placed under this node.
 *          srcH        - The handle returned by cmGetValTree() for the
 *                        source (copied sub-tree).
 *          srcNodeId   - The ID of the root node of the source sub-tree.
 * output : none
 * return : Non-negative value on success
 *          Negative value on failure
 ************************************************************************/
RVAPI int RVCALLCONV
pvtAddChilds(
    IN  HPVT        destH,
    IN  RvPvtNodeId destNodeId,
    IN  HPVT        srcH,
    IN  RvPvtNodeId srcNodeId)
{
    vtStructs   v;
    RvMutex *   mutex1, * mutex2;
    int         result;

    if (!destH || !srcH) return RV_ERROR_UNKNOWN;

    v.dest = (vtStruct *)destH;
    v.src = (vtStruct *)srcH;

    /* Make sure we lock an an orderly fashion to diminish dead-locking possibilities */
    if (destH > srcH)
    {
        mutex1 = &v.src->mutex;
        mutex2 = &v.dest->mutex;
    }
    else
    {
        mutex1 = &v.dest->mutex;
        mutex2 = &v.src->mutex;
    }

    RvMutexLock(mutex1);
    RvMutexLock(mutex2);
    result = rtAddChilds(v.dest->vTree, (int)destNodeId, v.src->vTree, (int)srcNodeId, pvtAddTreeFunc, (void *)&v);
    RvMutexUnlock(mutex2);
    RvMutexUnlock(mutex1);

    return result;
}


/************************************************************************
 * pvtDelete
 * purpose: Deletes a sub-tree
 * input  : valH            - PVT handle to use
 *          subTreeRootId   - The ID of the root node to delete
 * output : none
 * return : Non-negative value on success
 *          Negative value on failure
 ************************************************************************/
RVAPI int RVCALLCONV
pvtDelete(
      IN  HPVT          hVal,
      IN  RvPvtNodeId   subTreeRootId)
{
    vtStruct *vt = (vtStruct *)hVal;
    int result;

    if ((int)subTreeRootId < 0)
        return RV_ERROR_UNKNOWN;

    RvMutexLock(&vt->mutex);

#if (RV_LOGMASK_COMPILEMASK & RV_LOGLEVEL_DEBUG)
    /* If it's a root node, we notify that it's being deleted */
    if (rtParent(vt->vTree, (int)subTreeRootId) < 0)
    {
        RvLogDebug(&vt->log,
            (&vt->log, "pvtDelete: hVal=0x%p. Deleted root=%d", hVal, subTreeRootId));
    }
#endif

    result = rtDelete(vt->vTree, (int)subTreeRootId, pvtDeleteFunc, (void *)&hVal);
    RvMutexUnlock(&vt->mutex);

    return result;
}


/************************************************************************
 * pvtDeleteChilds
 * purpose: Deletes the children of root node.
 * input  : valH            - PVT handle to use
 *          subTreeRootId   - The ID of the root node to delete
 * output : none
 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -