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

📄 ema.c

📁 基于h323协议的软phone
💻 C
📖 第 1 页 / 共 4 页
字号:
 * output : none
 * return : Negative value on failure
 ************************************************************************/
int emaSetApplicationHandle(IN EMAElement elem, IN void* appHandle)
{
    emaElem* rElem;

    if (elem == NULL) return RV_ERROR_UNKNOWN;

    /* Find out our element information */
    rElem = (emaElem *)((char*)elem - sizeof(emaElem));
    rElem->appHandle = appHandle;

#ifdef RV_EMA_DEBUG
    {
        /* Make sure element is not vacant */
        emaObject* ema;
        int location;

        ema = rElem->ema;
        location = raGetByPtr(ema->ra, rElem);

        if (raElemIsVacant(ema->ra, location))
        {
            RvLogExcep(&ema->log,
                (&ema->log, "emaSetApplicationHandle (%s): Element %d,0x%p is vacant",
                     raGetName(ema->ra), location, rElem));
        }
    }
#endif

    return 0;
}


/************************************************************************
 * emaGetApplicationHandle
 * purpose: Get the application's handle of an element in EMA
 * input  : elem        - Element in EMA
 * output : appHandle   - Application's handle for the element
 * return : Pointer to the application handle
 *          NULL on failure
 ************************************************************************/
void* emaGetApplicationHandle(IN EMAElement elem)
{
    emaElem* rElem;

    if (elem == NULL) return NULL;

    /* Find out our element information */
    rElem = (emaElem *)((char*)elem - sizeof(emaElem));

#ifdef RV_EMA_DEBUG
    {
        /* Make sure element is not vacant */
        emaObject* ema;
        int location;

        ema = rElem->ema;
        location = raGetByPtr(ema->ra, rElem);

        if (raElemIsVacant(ema->ra, location))
        {
            RvLogExcep(&ema->log,
                (&ema->log, "emaGetApplicationHandle (%s): Element %d,0x%p is vacant",
                     raGetName(ema->ra), location, rElem));
        }
    }
#endif

    return rElem->appHandle;
}


/************************************************************************
 * emaGetType
 * purpose: Return the type of the element inside the EMA object.
 *          This is the type given in emaConstruct().
 * input  : elem    - Element in EMA
 * output : none
 * return : The element's type on success
 *          0 on failure
 ************************************************************************/
RvUint32 emaGetType(IN EMAElement elem)
{
    emaObject* ema;
    emaElem* rElem;

    if (elem == NULL) return 0;

    /* Find out our element information */
    rElem = (emaElem *)((char*)elem - sizeof(emaElem));
    ema = rElem->ema;

    return ema->type;
}


/************************************************************************
 * emaGetUserData
 * purpose: Return the user related data of the element inside the EMA
 *          object. This is the userData given in emaConstruct().
 * input  : elem    - Element in EMA
 * output : none
 * return : The element's user data pointer on success
 *          NULL on failure
 ************************************************************************/
void* emaGetUserData(IN EMAElement elem)
{
    emaObject* ema;
    emaElem* rElem;

    if (elem == NULL) return NULL;

    /* Find out our element information */
    rElem = (emaElem *)((char*)elem - sizeof(emaElem));
    ema = rElem->ema;

    return ema->userData;
}

/************************************************************************
 * emaGetUserDataByInstance
 * purpose: Return the user related data inside the EMA object, by the
 *          EMA instance returned by emaConstruct().
 *          This is the userData given in emaConstruct().
 * input  : emaH   - handle to the EMA
 * output : none
 * return : The user data pointer on success
 *          NULL on failure
 ************************************************************************/
void* emaGetUserDataByInstance(IN HEMA emaH)
{
    emaObject* ema = (emaObject *)emaH;

    if (emaH == NULL) return NULL;

    /* Find out our information */
    return ema->userData;
}

/************************************************************************
 * emaGetInstance
 * purpose: Return the instance of this EMA element.
 *          This is the instance given in emaConstruct().
 * input  : elem    - Element in EMA
 * output : none
 * return : The element's instance on success
 *          NULL on failure
 ************************************************************************/
void const* emaGetInstance(IN EMAElement elem)
{
    emaObject* ema;
    emaElem* rElem;

    if (elem == NULL) return NULL;

    /* Find out our element information */
    rElem = (emaElem *)((char*)elem - sizeof(emaElem));
    ema = rElem->ema;

    if (ema)
        return ema->instance;
    else
        return NULL;
}


/************************************************************************
 * emaGetObject
 * purpose: Return the EMA object this element is in
 * input  : elem    - Element in EMA
 * output : none
 * return : The element's EMA object on success
 *          NULL on failure
 ************************************************************************/
HEMA emaGetObject(IN EMAElement elem)
{
    emaElem* rElem;

    if (elem == NULL) return NULL;

    /* Find out our element information */
    rElem = (emaElem *)((char*)elem - sizeof(emaElem));

    return (HEMA)rElem->ema;
}


/************************************************************************
 * emaDoAll
 * purpose: Call a function on all used elements in EMA
 * input  : emaH        - Handle of the EMA object
 *          func        - Function to execute on all elements
 *          param       - Context to use when executing the function
 * output : none
 * return : Non-negative value on success
 *          Negative value on failure
 ************************************************************************/
int emaDoAll(
    IN HEMA     emaH,
    IN EMAFunc  func,
    IN void*    param)
{
    emaObject* ema = (emaObject *)emaH;
    int        i;

    /* Pass through all the elements, executing the functions on those
       which are used */
    for (i = 0; i < raMaxSize(ema->ra); i++)
    if (!raElemIsVacant(ema->ra, i))
    {
        char *elem  = (char *)raGet(ema->ra, i);

        /* We change the context by the return value of the function */
        param = func(elem + sizeof(emaElem), param);
    }

    return 0;
}


/************************************************************************
 * emaGetNext
 * purpose: Get the next used element in EMA.
 *          This function can be used to implement search or "doall"
 *          functions on EMA.
 * input  : emaH        - Handle of the EMA object
 *          cur         - Current EMA element whose next we're looking for
 *                        If NULL, then emaGetNext() will return the first
 *                        used element.
 * output : none
 * return : Pointer to the next used element on success
 *          NULL when no more used elements are left
 ************************************************************************/
EMAElement emaGetNext(
    IN HEMA         emaH,
    IN EMAElement   cur)
{
    emaObject* ema = (emaObject *)emaH;
    emaElem* rElem;
    int location;

    /* Find out our element information */
    if (cur != NULL)
        rElem = (emaElem *)((char*)cur - sizeof(emaElem));
    else
        rElem = NULL;

    /* Find the location */
    location = raGetNext(ema->ra, raGetByPtr(ema->ra, rElem));

    if (location >= 0)
        return (EMAElement)((char*)raGet(ema->ra, location) + sizeof(emaElem));
    else
        return NULL;
}


/************************************************************************
 * emaGetIndex
 * purpose: Returns the index of the element in the ema
 * input  : elem    - Element in EMA
 * output : none
 * return : The element's index on success
 *          Negative value on failure
 ************************************************************************/
int emaGetIndex(IN EMAElement elem)
{
    emaObject* ema;
    emaElem* rElem;

    if (elem == NULL) return RV_ERROR_UNKNOWN;

    /* Find out our element information */
    rElem = (emaElem *)((char*)elem - sizeof(emaElem));
    ema = rElem->ema;

    /* Find the location */
    return raGetByPtr(ema->ra, rElem);
}


/************************************************************************
 * emaGetStatistics
 * purpose: Get statistics information about EMA.
 *          The number of used items also includes those deleted, but still
 *          marked.
 * input  : emaH        - Handle of the EMA object
 * output : stats       - Statistics information
 * return : Non-negative value on success
 *          Negative value on failure
 ************************************************************************/
int emaGetStatistics(IN HEMA emaH, OUT emaStatistics* stats)
{
    emaObject* ema = (emaObject *)emaH;
    if (ema == NULL) return RV_ERROR_UNKNOWN;

    stats->numMarked = ema->markCount;
    return raGetStatistics(ema->ra, &stats->elems);
}

/************************************************************************
 * emaIsVacant
 * purpose: Returns whether the given object is free for allocation
 * input  : elem    - Element in EMA
 * output : none
 * return : RV_TRUE  - if the elemnt is not allocated
 *          RV_FALSE - otherwise
 ************************************************************************/
int emaIsVacant(IN EMAElement elem)
{
    emaObject* ema;
    emaElem* rElem;

    if (elem == NULL) return RV_FALSE;

    /* Find out our element information */
    rElem = (emaElem *)((char*)elem - sizeof(emaElem));
    ema = rElem->ema;

    /* Find the location */
    return (!ema);
}


/******************************************************************************
 * emaAddWatchdogResource
 * ----------------------------------------------------------------------------
 * General: Add an EMA instance as a resource handled by the watchdog.
 *
 * Return Value: RV_OK  - if successful.
 *               Other on failure
 * ----------------------------------------------------------------------------
 * Arguments:
 * Input:  emaH         - EMA instance handle.
 *         watchdog     - The watchdog instance to add this EMA to.
 *         name         - Name of resource to use.
 *         group        - Group name for this resource.
 *         description  - Short description about this resource.
 *****************************************************************************/
RvStatus emaAddWatchdogResource(
    IN HEMA         emaH,
    IN RvWatchdog   *watchdog,
    IN const char   *name,
    IN const char   *group,
    IN const char   *description)
{
    RvStatus status;
    emaObject* ema = (emaObject *)emaH;

    /* Make sure we're not trying this more than once */
    if (ema->watchdog != NULL)
        return RV_ERROR_UNKNOWN;

    status = RvWatchdogAddResource(watchdog, name, group, description,
        EmaWatchdogResourceCallback, (void *)emaH, &ema->watchdogResource);
    if (status >= 0)
        ema->watchdog = watchdog; /* Got it */

    return status;
}


#ifdef __cplusplus
}
#endif

⌨️ 快捷键说明

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