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

📄 transport.c

📁 基于h323协议的软phone
💻 C
📖 第 1 页 / 共 5 页
字号:

        /* release the sessions hash table */
        if (transGlobals->hHashSessions)
            hashDestruct(transGlobals->hHashSessions);

        /* release the hosts hash table */
        if (transGlobals->hHashHosts)
            hashDestruct(transGlobals->hHashHosts);

        /* release the resvoir of hosts */
        if (transGlobals->hEmaHosts)
            emaDestruct(transGlobals->hEmaHosts);

        /* release the reservoir of sessions */
        if (transGlobals->hEmaSessions)
            emaDestruct(transGlobals->hEmaSessions);

        /* destroy timers pool */
        if (transGlobals->hTimers)
            RvH323TimerDestruct( transGlobals->hTimers );

        /* destruct the syntax trees */
        pstDestruct(transGlobals->synProtH450);
        pstDestruct(transGlobals->synProtH245);
        pstDestruct(transGlobals->synProtQ931);

        /* unlock the module */
        RvMutexUnlock(&transGlobals->lockSessionsList);

        /* release the global locks */
        RvLockDestruct(&transGlobals->lockHash);
        RvMutexDestruct(&transGlobals->lockSessionsList);

        RvLogInfo(&transGlobals->hLog,
            (&transGlobals->hLog, "Transport layer was shutdown"));

        RvLogSourceDestruct(RvLogGet(), &transGlobals->hLog);
        RvLogSourceDestruct(RvLogGet(), &transGlobals->hTPKTCHAN);

        /* deallocate the global element of the module */
        RvMemoryFree((void *)hAppTrans);
    }

    return cmTransOK;
}

/**************************************************************************************
 * cmTransCreateSession
 *
 * Purpose: Creates a new session element according to its parameters.
 *
 * Input:   hAppTrans       - A handle to the entire transport module
 *          haTranSession   - An application handle to be set to the session, ususally
 *                            would be the call handle that is associated with this session.
 *
 * Output:  hsTranSession   - An handle to the created session element
 *
 **************************************************************************************/
TRANSERR cmTransCreateSession(  IN  HAPPTRANS       hAppTrans,
                                IN  HATRANSSESSION  haTransSession,
                                OUT HSTRANSSESSION  *hsTransSession)
{
    cmTransGlobals  *transGlobals = (cmTransGlobals *)hAppTrans;
    EMAElement      newSession;
    emaStatistics stat;
    /* if the module was initialized */
    if (hAppTrans)
    {
        /* allocate a new session element */
        newSession = emaAdd(transGlobals->hEmaSessions, (void*)haTransSession);

        emaGetStatistics(transGlobals->hEmaSessions, &stat);

        /* set the output parameter to the allocated element (maybe NULL) */
        if (hsTransSession)
            *hsTransSession = (HSTRANSSESSION)newSession;

        /* if an element was indeed allocated return OK */
        if (newSession)
        {
            cmTransSession *session = (cmTransSession *)newSession;
            memset(session, 0, sizeof(cmTransSession));
            session->h245Stage                      = cmTransH245Stage_connect;
            session->tunnelingState                 = tunnNo;
            session->isTunnelingSupported           = RV_FALSE;
            session->faststartState                 = fsNo;
            session->firstMessageSent               = RV_FALSE;
            session->connectedToHost                = RV_FALSE;
            session->reportedH245Connect            = RV_FALSE;
            session->outgoing                       = RV_TRUE;
            session->closeOnNoSessions              = RV_TRUE;
            session->h450Element                    = -1;
            session->h450AlertElement               = -1;
            session->annexLElement                  = -1;
            session->annexMElement                  = -1;
            session->annexEUsageMode                = cmTransNoAnnexE;

            RvLogInfo(&transGlobals->hLog,
                (&transGlobals->hLog,
                    "cmTransCreateSession = %d(%p)", emaGetIndex((EMAElement)session), session));

            return cmTransOK;
        }
    }

    /* in cases that OK was NOT sent, return error indication */
    RvLogError(&transGlobals->hLog,
        (&transGlobals->hLog,
            "cmTransCreateSession [FAILURE](haSession=%p)", haTransSession));

    return cmTransErr;
}

/**************************************************************************************
 * cmTransCloseSession
 *
 * Purpose: Deletes a session element.
 *
 * Input:   hsTranSession   - An handle to the session element
 *
 * Output:  None.
 *
 **************************************************************************************/
TRANSERR cmTransCloseSession(IN HSTRANSSESSION hsTransSession)
{
    TRANSERR res = cmTransErr;
    /* check if an element exists */
    if (hsTransSession)
    {
#if (RV_LOGMASK_COMPILEMASK & RV_LOGLEVEL_INFO)
        /* retrieve the transport module global area */
        cmTransGlobals *transGlobals = (cmTransGlobals *)emaGetUserData((EMAElement)hsTransSession);

        RvLogInfo(&transGlobals->hLog,
            (&transGlobals->hLog,
                "cmTransCloseSession = %d(%p)", emaGetIndex((EMAElement)hsTransSession), hsTransSession));
#endif

        /* lock the whole module for this major change */
        if (emaLock((EMAElement)hsTransSession))
        {
            transSessionClose((cmTransSession *)hsTransSession);

            /* delete the host element */
            if (!emaWasDeleted((EMAElement)hsTransSession))
            {
                res = ((emaDelete( (EMAElement)hsTransSession )!= 0)?
                                cmTransErr:cmTransOK);
            }
            else
                res = cmTransOK;

            emaUnlock((EMAElement)hsTransSession);
        }
    }
    return res;
}


/**************************************************************************************
 * cmTransDrop
 *
 * Purpose: Drop a session (put its state in Idle).
 *
 * Input:   hsTranSession   - An handle to the session element
 *
 * Output:  None.
 *
 **************************************************************************************/
TRANSERR cmTransDrop(IN HSTRANSSESSION hsTransSession)
{
    cmTransSession *session=(cmTransSession *)hsTransSession;
    if (emaLock((EMAElement)hsTransSession))
    {
        if (session->Q931Connection != NULL)
        {
            if (session->Q931Connection->closeOnNoSessions || session->Q931Connection->remoteCloseOnNoSessions)
                session->Q931Connection->state = hostIdle;
        }
        emaUnlock((EMAElement)hsTransSession);
    }
    return cmTransOK;
}


/**************************************************************************************
 * cmTransCreateHost
 *
 * Purpose: Creates a new host element according to its parameters.
 *
 * Input:   hAppTrans   - A handle to the entire transport module
 *          haTranHost  - An application handle to be set to the host element.
 *
 * Output:  hsTranHost  - An handle to the created host element
 *
 **************************************************************************************/
TRANSERR cmTransCreateHost( IN  HAPPTRANS   hAppTrans,
                            IN  HATRANSHOST haTransHost,
                            OUT HSTRANSHOST *hsTransHost)
{
    cmTransGlobals  *transGlobals = (cmTransGlobals *)hAppTrans;
    EMAElement      newHost;

    /* if the module was initialized */
    if (hAppTrans)
    {
        /* allocate a new host element */
        newHost = emaAdd(transGlobals->hEmaHosts, (void*)haTransHost);

        /* set the output parameter to the allocated element (maybe NULL) */
        if (hsTransHost)
            *hsTransHost = (HSTRANSHOST)newHost;

        /* if an element was indeed allocated return OK */
        if (newHost)
        {
            cmTransHost *host = (cmTransHost *)newHost;

            memset(host, 0, sizeof(cmTransHost));

            RvLogInfo(&transGlobals->hLog,
                (&transGlobals->hLog,
                    "cmTransCreateHost created host=%d(%p)",emaGetIndex((EMAElement)host), host));

            return cmTransOK;
        }
    }

    /* in cases that OK was NOT sent, return error indication */
    return cmTransErr;
}

/**************************************************************************************
 * cmTransCloseHost
 *
 * Purpose: Deletes a host element. Will notify all its associates sessions.
 *
 * Input:   hsTranHost  - An handle to the host element
 *
 * Output:  None.
 *
 **************************************************************************************/
TRANSERR cmTransCloseHost(IN HSTRANSHOST hsTransHost)
{
    return closeHostInternal(hsTransHost, RV_FALSE);
}

/**************************************************************************************
 * cmTransSetSessionParam
 *
 * Purpose: Sets a specific parameter for the given session element.
 *
 * Input:   hsTranSession   - An handle to the session element
 *          param           - The name of the parameter to be set.
 *          value           - An integer or pointer to set as the new parameter.
 *
 * Output:  None.
 *
 **************************************************************************************/
TRANSERR cmTransSetSessionParam(IN HSTRANSSESSION       hsTransSession,
                                IN TRANSSESSIONPARAM    param,
                                IN void                 *value)
{
    cmTransSession *session = (cmTransSession *)hsTransSession;

    if (emaLock((EMAElement)session))
    {
        switch (param)
        {
            case cmTransParam_isTunnelingSupported:
                {
                    session->isTunnelingSupported = *(RvBool *)value;
                }
                break;

            case cmTransParam_notEstablishControl:
                {
                    session->notEstablishControl = *(RvBool *)value;
                }
                break;

            case cmTransParam_H245Stage:
                {
                    session->h245Stage = *(cmH245Stage *)value;
                }
                break;

            case cmTransParam_isParallelTunnelingSupported:
                {
                    session->isParallelTunnelingSupported = *(RvBool *)value;
                }
                break;

            case cmTransParam_shutdownEmptyConnection:
                {
                    session->closeOnNoSessions = *(RvBool *)value;
                    if (session->Q931Connection)
                        cmTransSetHostParam((HSTRANSHOST)session->Q931Connection,
                                             cmTransHostParam_shutdownEmptyConnection,
                                             value,
                                             RV_FALSE);
                }
                break;

            case cmTransParam_isMultiplexed:
                {
                    session->isMultiplexed = *(RvBool *)value;
                    if (session->Q931Connection)
                        cmTransSetHostParam((HSTRANSHOST)session->Q931Connection,
                                             cmTransHostParam_isMultiplexed,
                                             value,
                                             RV_FALSE);
                }
                break;

            case cmTransParam_isAnnexESupported:
                {
                    session->annexEUsageMode = *(cmAnnexEUsageMode *)value;
                }
                break;

            default:
                break;
        }

        /* unlock the session */
        emaUnlock((EMAElement)session);
        return cmTransOK;
    }

    return cmTransErr;
}

/**************************************************************************************
 * cmTransGetSessionParam
 *
 * Purpose: Gets a specific parameter from a given session element.
 *
 * Input:   hsTranSession   - An handle to the session element
 *          param           - The name of the parameter to get.
 *

⌨️ 快捷键说明

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