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

📄 cmctrlcap.c

📁 基于h323协议的软phone
💻 C
📖 第 1 页 / 共 3 页
字号:
/***********************************************************************
        Copyright (c) 2002 RADVISION Ltd.
************************************************************************
NOTICE:
This document contains information that is confidential and proprietary
to RADVISION Ltd.. No part of this document may be reproduced in any
form whatsoever without written prior approval by RADVISION Ltd..

RADVISION Ltd. reserve the right to revise this publication and make
changes without obligation to notify any person of such revisions or
changes.
***********************************************************************/


#include "rvinternal.h"
#include "cmictrl.h"
#include "cmConf.h"
#include "caputils.h"
#include "strutils.h"
#include "cmchan.h"
#include "oidutils.h"
#include "stkutils.h"
#include "h245.h"
#include "cmChanGetByXXX.h"
#include "cmCtrlCap.h"
#include "cmdebprn.h"

#ifdef __cplusplus
extern "C" {
#endif

#define ifE(a) if(a)(a)


int cmcReadyEvent(H245Control* ctrl);
#define capSetSize 100
#define capDescSize 100

/*Out Capibility*/
static RvBool capTimeoutEventsHandler(void*hsCall);

void capInit(H245Control* ctrl)
{
    cmElem* app = (cmElem *)emaGetInstance((EMAElement)cmiGetByControl((HCONTROL)ctrl));
    OutgoingCapInfo* outcap=&ctrl->outCap;
    IncomingCapInfo* incap=&ctrl->inCap;

    outcap->seqNum = 0;
    outcap->waiting=RV_FALSE;
    outcap->termNodeId=RV_ERROR_UNKNOWN;
    incap->termNodeId=RV_ERROR_UNKNOWN;
    incap->manualResponse=(pvtGetChild2(app->hVal,app->h245Conf,__h245(capabilities),__h245(manualResponse))>=0);
    RvLogInfo(&app->log, (&app->log, "TCS manual response on %p = %d",ctrl,incap->manualResponse));

    outcap->timer = NULL;
    outcap->rejectCause = RV_ERROR_UNKNOWN;
}

/************************************************************************
 * capEnd
 * purpose: Finish with the capabilities exchange of a control object
 * input  : ctrl    - Control object
 * output : none
 * return : none
 ************************************************************************/
void capEnd(IN H245Control* ctrl)
{
    OutgoingCapInfo* outcap=&ctrl->outCap;
    HAPP hApp=(HAPP)emaGetInstance((EMAElement)cmiGetByControl((HCONTROL)ctrl));
    HPVT hVal;

    hVal = ((cmElem *)hApp)->hVal;

    /* Reset the outgoing capabilities timer is one exists */
    RvH323TimerCancel(cmGetTimersHandle(hApp),&outcap->timer);

    /* Delete PVT tree nodes of capabilities */
    if (ctrl->outCap.termNodeId>=0)
    {
        pvtDelete(hVal,  ctrl->outCap.termNodeId);
        ctrl->outCap.termNodeId = RV_ERROR_UNKNOWN;
    }
    if (ctrl->inCap.termNodeId>=0)
    {
        pvtDelete(hVal,  ctrl->inCap.termNodeId);
        ctrl->inCap.termNodeId = RV_ERROR_UNKNOWN;
    }
}


/************************************************************************
 * outCapTransferRequest
 * purpose: Request to send out a TCS message
 *          This function also handled the timer to set and adds additional
 *          information to the outgoing TCS
 * input  : ctrl    - Control object
 *          message - TCS message node ID to send
 * output : none
 * return : Non-negative value on success
 *          Negative value on failure
 ************************************************************************/
int outCapTransferRequest(IN H245Control* ctrl, IN int message)
{
    HAPP hApp=(HAPP)emaGetInstance((EMAElement)cmiGetByControl((HCONTROL)ctrl));
    HPVT hVal;
    cmElem* app;
    OutgoingCapInfo* outcap=&ctrl->outCap;
    int msgId;
    RvInt32 timeout=9;
    int res;
    int iSq;
    app = (cmElem *)hApp;
    hVal = app->hVal;
    
    /* Increment the sequence number for this TCS transaction */
    outcap->seqNum++;

    /* Set the sequenceNumber and protocolIdentifier in the TCS we're about to send */
    msgId = pvtGetChild2(hVal,message, __h245(request), __h245(terminalCapabilitySet));
    iSq = outcap->seqNum;
    pvtAdd(hVal, msgId, __h245(sequenceNumber) , iSq, NULL, NULL);
    pvtAdd(hVal, msgId, __h245(protocolIdentifier), app->h245protocolIDLen, app->h245protocolID, NULL);

    /* Send the TCS message */
    res = sendMessageH245((HCONTROL)ctrl, message);
    if (res >= 0)
    {
        /* Update the outgoing capabilities of this terminal */
        if (outcap->termNodeId < 0)
            outcap->termNodeId = pvtAddRoot(hVal, NULL, 0, NULL);
        pvtMoveTree(hVal, outcap->termNodeId, msgId);

        /* Set the timer for this transaction from the configuration */

	 /**
	  * 2004.09.24. modified by mxd. Not to start the timer.
	  */
/*     pvtGetChildValue2(hVal,((cmElem*)hApp)->h245Conf,__h245(capabilities),__h245(timeout),&timeout,NULL);
        RvH323TimerCancel(cmGetTimersHandle(hApp),&outcap->timer);
        outcap->timer = RvH323TimerStart(cmGetTimersHandle(hApp),capTimeoutEventsHandler,(void*)ctrl,timeout*1000);
*/
        /* Update control state because of this TCS */
        outcap->waiting = RV_TRUE;
        ctrl->eOutCapStatus = CapStatusSent;
    }

    return res;
}


/************************************************************************
 * terminalCapabilitySetAck
 * purpose: Handle an incoming TerminalCapabilitySetAck message
 * input  : ctrl    - Control object
 *          message - TCS.Ack message node
 * output : none
 * return : Non-negative value on success
 *          Negative value on failure
 ************************************************************************/
int terminalCapabilitySetAck(IN H245Control* ctrl, IN int message)
{
    HAPP hApp=(HAPP)emaGetInstance((EMAElement)cmiGetByControl((HCONTROL)ctrl));
    cmElem* app=(cmElem*)hApp;
    OutgoingCapInfo* outcap=&ctrl->outCap;

    if (outcap->waiting)
    {
        HPVT hVal = app->hVal;
        int sq;
        pvtGetChildValue(hVal, message, __h245(sequenceNumber), &sq, NULL);
        if (sq == outcap->seqNum)
        {
            RvH323TimerCancel(cmGetTimersHandle(hApp),&outcap->timer);
            ctrl->eOutCapStatus = CapStatusAcknowledged;
            outcap->waiting = RV_FALSE;

            emaMark((EMAElement)cmiGetByControl((HCONTROL)ctrl));

            if (app->cmMySessionEvent.cmEvCallCapabilitiesResponse != NULL)
            {
                /* Application's callback for TCS.Ack */
                int nesting;

                cmiCBEnter(hApp, "cmEvCallCapabilitiesResponse(haCall=0x%p, hsCall=0x%p, cmCapAccept)", (HAPPCALL)emaGetApplicationHandle((EMAElement)cmiGetByControl((HCONTROL)ctrl)), cmiGetByControl((HCONTROL)ctrl));
                nesting = emaPrepareForCallback((EMAElement)cmiGetByControl((HCONTROL)ctrl));
                app->cmMySessionEvent.cmEvCallCapabilitiesResponse((HAPPCALL)emaGetApplicationHandle((EMAElement)cmiGetByControl((HCONTROL)ctrl)), (HCALL)cmiGetByControl((HCONTROL)ctrl), cmCapAccept);
                emaReturnFromCallback((EMAElement)cmiGetByControl((HCONTROL)ctrl),nesting);
                cmiCBExit(hApp, "cmEvCallCapabilitiesResponse");
            }

            if (!emaWasDeleted((EMAElement)cmiGetByControl((HCONTROL)ctrl)))
            {
                cmcReadyEvent(ctrl);
            }
            emaRelease((EMAElement)cmiGetByControl((HCONTROL)ctrl));
        }
    }
    return RV_TRUE;
}


/************************************************************************
 * terminalCapabilitySetReject
 * purpose: Handle an incoming TerminalCapabilitySetReject message
 * input  : ctrl    - Control object
 *          message - TCS.Reject message node
 * output : none
 * return : Non-negative value on success
 *          Negative value on failure
 ************************************************************************/
int terminalCapabilitySetReject(IN H245Control* ctrl, IN int message)
{
    HAPP hApp=(HAPP)emaGetInstance((EMAElement)cmiGetByControl((HCONTROL)ctrl));
    OutgoingCapInfo* outcap=&ctrl->outCap;
    cmElem* app=(cmElem*)hApp;

    if (outcap->waiting)
    {
        HPVT hVal = app->hVal;
        int sq;
        pvtGetChildValue(hVal, message, __h245(sequenceNumber), &sq, NULL);
        if (sq == outcap->seqNum)
        {
            int tmpNodeId;
            int nesting;

            RvH323TimerCancel(cmGetTimersHandle(hApp),&outcap->timer);
            ctrl->eOutCapStatus = CapStatusRejected;

            /* Find out the cause */
            __pvtGetByFieldIds(tmpNodeId, hVal, message, {_h245(cause) _anyField LAST_TOKEN}, NULL, NULL, NULL);
            ctrl->outCap.rejectCause = pvtGetSyntaxIndex(hVal, tmpNodeId);

            cmiCBEnter(hApp, "cmEvCallCapabilitiesResponse: haCall=0x%p, hsCall=0x%p, cmCapReject.",(HAPPCALL)emaGetApplicationHandle((EMAElement)cmiGetByControl((HCONTROL)ctrl)),cmiGetByControl((HCONTROL)ctrl));
            emaMark((EMAElement)cmiGetByControl((HCONTROL)ctrl));
            nesting=emaPrepareForCallback((EMAElement)cmiGetByControl((HCONTROL)ctrl));
            ifE(app->cmMySessionEvent.cmEvCallCapabilitiesResponse) ((HAPPCALL)emaGetApplicationHandle((EMAElement)cmiGetByControl((HCONTROL)ctrl)), (HCALL)cmiGetByControl((HCONTROL)ctrl), cmCapReject);
            emaReturnFromCallback((EMAElement)cmiGetByControl((HCONTROL)ctrl),nesting);
            cmiCBExit(hApp, "cmEvCallCapabilitiesResponse.");
            outcap->waiting=RV_FALSE;
            emaRelease((EMAElement)cmiGetByControl((HCONTROL)ctrl));
        }
    }
    return RV_TRUE;
}

static RvBool capTimeoutEventsHandler(void*_ctrl)
{
    H245Control* ctrl=(H245Control*)_ctrl;

    if (emaLock((EMAElement)cmiGetByControl((HCONTROL)ctrl)))
    {
        OutgoingCapInfo* outcap=&ctrl->outCap;
        HAPP hApp;
        cmElem* app;
        HPVT hVal;
        int nesting;
        int nodeId;

        hApp =(HAPP)emaGetInstance((EMAElement)cmiGetByControl((HCONTROL)ctrl));
        app = (cmElem*)hApp;
        hVal = app->hVal;

        RvH323TimerClear(cmGetTimersHandle(hApp), &outcap->timer);
        ctrl->eOutCapStatus = CapStatusRejected;
        ctrl->outCap.rejectCause = RV_ERROR_UNKNOWN; /* No actual cause on timeout */

        nodeId=pvtAddRoot(hVal,app->synProtH245,0,NULL);
        pvtAddBranch2(hVal,nodeId,__h245(indication),__h245(terminalCapabilitySetRelease));
        sendMessageH245((HCONTROL)ctrl, nodeId);
        pvtDelete(hVal,nodeId);

        outcap->waiting = RV_FALSE;

        if (app->cmMySessionEvent.cmEvCallCapabilitiesResponse != NULL)
        {
            cmiCBEnter(hApp, "cmEvCallCapabilitiesResponse: haCall=0x%p, hsCall=0x%p, cmCapReject.",(HAPPCALL)emaGetApplicationHandle((EMAElement)cmiGetByControl((HCONTROL)ctrl)),cmiGetByControl((HCONTROL)ctrl));
            nesting=emaPrepareForCallback((EMAElement)cmiGetByControl((HCONTROL)ctrl));
            app->cmMySessionEvent.cmEvCallCapabilitiesResponse(
                (HAPPCALL)emaGetApplicationHandle((EMAElement)cmiGetByControl((HCONTROL)ctrl)),
                (HCALL)cmiGetByControl((HCONTROL)ctrl), cmCapReject);
            emaReturnFromCallback((EMAElement)cmiGetByControl((HCONTROL)ctrl),nesting);
            cmiCBExit(hApp, "cmEvCallCapabilitiesResponse.");
        }

        emaUnlock((EMAElement)cmiGetByControl((HCONTROL)ctrl));
    }
    return RV_FALSE;
}


/*In Capability*/

⌨️ 快捷键说明

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