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

📄 cmq931.c

📁 基于h323协议的软phone
💻 C
📖 第 1 页 / 共 2 页
字号:
/***********************************************************************
        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 "rvh323timer.h"
#include "cm.h"
#include "cmintr.h"
#include "q931asn1.h"
#include "cmQ931.h"
#include "cmiQ931.h"
#include "cmCrossReference.h"
#include "cmCall.h"
#include "cmparam.h"

#ifdef __cplusplus
extern "C" {
#endif



/***************************/
/*  I  N  I  T  /  E  N  D */
/***************************/
int q931CallCreate(HQ931 call, int t301, int t302, int t303, int t304, int t310, int t322)
{
    q931Elem* callE=(q931Elem*)call;
    callE->t301=t301;
    callE->t302=t302;
    callE->t303=t303;
    callE->t304=t304;
    callE->t310=t310;
    callE->t322=t322;
    callE->callState=cs_Null;
    callE->timer=NULL;
    callE->timerSE=NULL;
    return RV_TRUE;
}

int q931CallClose(HQ931 call)
{
    q931Elem* callE=(q931Elem*)call;
    RvH323TimerCancel(cmGetTimersHandle(cmGetAHandle((HPROTOCOL)cmiGetByQ931(call))),&callE->timerSE);
    RvH323TimerCancel(cmGetTimersHandle(cmGetAHandle((HPROTOCOL)cmiGetByQ931(call))),&callE->timer);
    return 0;
}

callStateE q931GetCallState(HQ931 call)
{
    q931Elem* callE=(q931Elem*)call;
    return callE->callState;
}
/**********************/
/*  T  I  M  E  R  S  */
/**********************/

/* t301 - connectTimeOut (outgoing call, after alerting received) */
RvBool q931T301Timeout(void* context)
{
    HQ931 call=(HQ931)context;
    q931Elem* callE=(q931Elem*)call;

    if (emaLock((EMAElement)cmiGetByQ931(call)))
    {
        RvH323TimerClear(cmGetTimersHandle(cmGetAHandle((HPROTOCOL)cmiGetByQ931(call))), &callE->timer);
        q931CallDrop(call,-1);
        cmIndicate(cmiGetByQ931(call),-1, -1);
        if (!emaWasDeleted((EMAElement)cmiGetByQ931(call)))
            callE->callState=cs_Null;
        emaUnlock((EMAElement)cmiGetByQ931(call));
    }
    return RV_FALSE;
}

/* t302 - responseTimeOut or t302 (incoming call waiting for incomplete address to complete) */
RvBool q931T302Timeout(void* context)
{
    HQ931 call=(HQ931)context;
    q931Elem* callE=(q931Elem*)call;

    if (emaLock((EMAElement)cmiGetByQ931(call)))
    {
        RvH323TimerClear(cmGetTimersHandle(cmGetAHandle((HPROTOCOL)cmiGetByQ931(call))), &callE->timer);
        q931CallDrop(call,-1);
        cmIndicate(cmiGetByQ931(call),-1, -1);
        if (!emaWasDeleted((EMAElement)cmiGetByQ931(call)))
            callE->callState=cs_Null;
        emaUnlock((EMAElement)cmiGetByQ931(call));
    }
    return RV_FALSE;
}

/* t303 - responseTimeOut (outgoing call after dial) */
RvBool q931T303Timeout(void* context)
{
    HQ931 call=(HQ931)context;
    q931Elem* callE=(q931Elem*)call;

    if (emaLock((EMAElement)cmiGetByQ931(call)))
    {
        RvH323TimerClear(cmGetTimersHandle(cmGetAHandle((HPROTOCOL)cmiGetByQ931(call))), &callE->timer);
        q931CallDrop(call,-1);
        cmIndicate(cmiGetByQ931(call),-1, -1);
        if (!emaWasDeleted((EMAElement)cmiGetByQ931(call)))
            callE->callState=cs_Null;
        emaUnlock((EMAElement)cmiGetByQ931(call));
    }
    return RV_FALSE;
}

/* t304 - responseTimeOut or t304 (outgoing call in overlap sending process) */
RvBool q931T304Timeout(void* context)
{
    HQ931 call=(HQ931)context;
    q931Elem* callE=(q931Elem*)call;

    if (emaLock((EMAElement)cmiGetByQ931(call)))
    {
        RvH323TimerClear(cmGetTimersHandle(cmGetAHandle((HPROTOCOL)cmiGetByQ931(call))), &callE->timer);
        q931CallDrop(call,-1);
        cmIndicate(cmiGetByQ931(call),-1, -1);
        if (!emaWasDeleted((EMAElement)cmiGetByQ931(call)))
            callE->callState=cs_Null;
        emaUnlock((EMAElement)cmiGetByQ931(call));
    }
    return RV_FALSE;
}

/* t310 - connectTimeOut (outgoing call after callProceeding received) */
RvBool q931T310Timeout(void* context)
{
    HQ931 call=(HQ931)context;
    q931Elem* callE=(q931Elem*)call;

    if (emaLock((EMAElement)cmiGetByQ931(call)))
    {
        RvH323TimerClear(cmGetTimersHandle(cmGetAHandle((HPROTOCOL)cmiGetByQ931(call))), &callE->timer);
        q931CallDrop(call,-1);
        cmIndicate(cmiGetByQ931(call),-1, -1);
        if (!emaWasDeleted((EMAElement)cmiGetByQ931(call)))
            callE->callState=cs_Null;
        emaUnlock((EMAElement)cmiGetByQ931(call));
    }
    return RV_FALSE;
}

 /* t322 - 100 seconds (outgoing call waiting for reply to status inquiery) */
RvBool q931T322Timeout(void* context)
{
    q931Elem* callE=(q931Elem*)context;
    if (emaLock((EMAElement)cmiGetByQ931((HQ931)callE)))
    {
        RvH323TimerClear(cmGetTimersHandle(cmGetAHandle((HPROTOCOL)cmiGetByQ931((HQ931)callE))), &callE->timerSE);
        emaUnlock((EMAElement)cmiGetByQ931((HQ931)callE));
    }
    return RV_FALSE;
}

/*************************/
/*  A  C  T  I  O  N  S  */
/*************************/
int q931CallDial(HQ931 call, int message)
{
    q931Elem* callE=(q931Elem*)call;
    if (callE->callState==cs_Null)
    {
        RvH323TimerCancel(cmGetTimersHandle(cmGetAHandle((HPROTOCOL)cmiGetByQ931(call))), &callE->timer);
        callE->timer=RvH323TimerStart(cmGetTimersHandle(cmGetAHandle((HPROTOCOL)cmiGetByQ931((HQ931)callE))),q931T303Timeout,callE,callE->t303);
        sendCallMessage(cmiGetByQ931((HQ931)callE),message);
        callReleaseMessage(cmiGetByQ931((HQ931)callE),cmQ931setup);
        callE->callState=cs_Call_initiated;
    }
    return 0;
}
int q931CallInfo(HQ931 call, int message)
{
    q931Elem* callE=(q931Elem*)call;
    if (callE->callState==cs_Overlap_sending)
    {
        RvH323TimerCancel(cmGetTimersHandle(cmGetAHandle((HPROTOCOL)cmiGetByQ931(call))), &callE->timer);
        callE->timer=RvH323TimerStart(cmGetTimersHandle(cmGetAHandle((HPROTOCOL)cmiGetByQ931(call))),q931T304Timeout,callE,callE->t304);
        sendCallMessage(cmiGetByQ931(call),message);
        callReleaseMessage(cmiGetByQ931(call),cmQ931information);
    }
    else
    if (callE->callState!=cs_Null &&
        callE->callState!=cs_Call_initiated &&
        callE->callState!=cs_Call_present)
    {
        sendCallMessage(cmiGetByQ931(call),message);
        callReleaseMessage(cmiGetByQ931(call),cmQ931information);
    }
    return 0;
}
int q931CallMoreInfo(HQ931 call,int message)
{
    q931Elem* callE=(q931Elem*)call;
    if((callE->callState==cs_Call_present) || (callE->callState==cs_Overlap_receiving))
    {
        RvH323TimerCancel(cmGetTimersHandle(cmGetAHandle((HPROTOCOL)cmiGetByQ931(call))), &callE->timer);
        callE->timer=RvH323TimerStart(cmGetTimersHandle(cmGetAHandle((HPROTOCOL)cmiGetByQ931(call))),q931T302Timeout,callE,callE->t302);
        if (message<0)
            message=callGetMessage(cmiGetByQ931(call),cmQ931setupAcknowledge);
        sendCallMessage(cmiGetByQ931(call),message);
        callReleaseMessage(cmiGetByQ931(call),cmQ931setupAcknowledge);
        callE->callState=cs_Overlap_receiving;
    }
    return 0;
}


/************************************************************************
 * q931CallCallProceeding
 * purpose: Send Q931 CallProceeding message on a call
 * input  : call    - Stack handle for the Q931 call
 *          message - CallProceeding message to send
 *                    if set to -1, then create the message from the call's
 *                    property database
 * output : none
 * return : Non-negative value on success
 *          Negative value on failure
 ************************************************************************/
int q931CallCallProceeding(IN HQ931 call, IN int message)
{
    int status = RV_ERROR_UNKNOWN;
    q931Elem* callE=(q931Elem*)call;
    if (callE->callState==cs_Call_present||
        callE->callState==cs_Overlap_receiving)
    {
        /* Get the message to send */
        if (message<0)
            message=callGetMessage(cmiGetByQ931(call),cmQ931callProceeding);

        /* Reset the call's Q931 timer */
        RvH323TimerCancel(cmGetTimersHandle(cmGetAHandle((HPROTOCOL)cmiGetByQ931(call))),&callE->timer);

        /* Send the Progress message */
        status = sendCallMessage(cmiGetByQ931(call),message);

        /* Release the message if not needed anymore */
        callReleaseMessage(cmiGetByQ931(call),cmQ931callProceeding);

        /* Change call's Q931 state to IncomingCallProceeding */
        callE->callState=cs_Incoming_call_proceeding;
    }
    return status;
}


/************************************************************************
 * q931CallProgress
 * purpose: Send Q931 Progress message on a call
 * input  : call    - Stack handle for the Q931 call
 *          message - Progress message to send
 * output : none
 * return : Non-negative value on success
 *          Negative value on failure
 ************************************************************************/
int q931CallProgress(IN HQ931 call, IN int message)
{
    int         status = RV_ERROR_UNKNOWN;
    q931Elem*   callE  = (q931Elem*)call;
    HAPP        hApp = cmGetAHandle((HPROTOCOL)cmiGetByQ931(call));
    HPVT        hVal;
    hVal = ((cmElem*)hApp)->hVal;


    if (callE->callState==cs_Call_present ||
        callE->callState==cs_Incoming_call_proceeding ||
        callE->callState==cs_Overlap_receiving ||
        callE->callState==cs_Call_received)
    {
        /* Send the Progress message */
        status = sendCallMessage(cmiGetByQ931(call),message);

        /* Release the message if not needed anymore */
        pvtDelete(hVal, message);
        callReleaseMessage(cmiGetByQ931(call),cmQ931progress);
    }
    return status;
}


/************************************************************************
 * q931CallNotify
 * purpose: Send Q931 Notify message on a call
 * input  : call    - Stack handle for the Q931 call
 *          message - Notify message to send
 * output : none
 * return : Non-negative value on success
 *          Negative value on failure
 ************************************************************************/
int q931CallNotify(IN HQ931 call, IN int message)
{
    int       result = RV_ERROR_UNKNOWN;
    q931Elem* callE = (q931Elem*)call;
    HAPP      hApp = cmGetAHandle((HPROTOCOL)cmiGetByQ931(call));
    HPVT      hVal;
    hVal = ((cmElem*)hApp)->hVal;

    if (callE->callState==cs_Active)
    {
        /* Send the Notify message */
        result = sendCallMessage(cmiGetByQ931(call),message);

        /* Release the message if not needed anymore */
        pvtDelete(hVal, message);
        callReleaseMessage(cmiGetByQ931(call),cmQ931notify);
    }
    return result;
}


/************************************************************************
 * q931CallAccept
 * purpose: Send Q931 Alerting message on a call
 * input  : call    - Stack handle for the Q931 call to accept
 *          message - Alerting message to send
 *                    if set to -1, then create the message from the call's
 *                    property database
 * output : none
 * return : Non-negative value on success
 *          Negative value on failure
 ************************************************************************/
int q931CallAccept(IN HQ931 call, IN int message)
{
    int status = RV_ERROR_UNKNOWN;
    q931Elem* callE=(q931Elem*)call;
    if (callE->callState==cs_Call_present||
        callE->callState==cs_Incoming_call_proceeding||
        callE->callState==cs_Overlap_receiving)
    {
        /* Get the message to send */
        if (message<0)
            message=callGetMessage(cmiGetByQ931(call),cmQ931alerting);

        /* Reset the call's Q931 timer */
        RvH323TimerCancel(cmGetTimersHandle(cmGetAHandle((HPROTOCOL)cmiGetByQ931(call))),&callE->timer);

        /* Send the Alerting message */
        status = sendCallMessage(cmiGetByQ931(call),message);

        /* Release the message if not needed anymore */
        callReleaseMessage(cmiGetByQ931(call),cmQ931alerting);

        /* Change call's Q931 state to CallReceived */
        callE->callState=cs_Call_received;
    }
    return status;
}


/************************************************************************
 * q931CallAnswer
 * purpose: Send Q931 Connect message on a call
 * input  : call    - Stack handle for the Q931 call to connect
 *          message - Connect message to send
 *                    if set to -1, then create the message from the call's
 *                    property database
 * output : none
 * return : Non-negative value on success
 *          Negative value on failure
 ************************************************************************/
int q931CallAnswer(IN HQ931 call, IN int message)
{
    int status = RV_ERROR_UNKNOWN;
    q931Elem* callE=(q931Elem*)call;
    if (callE->callState==cs_Call_present||
        callE->callState==cs_Call_received||
        callE->callState==cs_Incoming_call_proceeding||
        callE->callState==cs_Overlap_receiving)
    {
        /* Get the message to send */
        if (message<0)
            message=callGetMessage(cmiGetByQ931(call),cmQ931connect);

        /* Reset the call's Q931 timer */
        RvH323TimerCancel(cmGetTimersHandle(cmGetAHandle((HPROTOCOL)cmiGetByQ931(call))),&callE->timer);

        /* Send the Connect message */
        status = sendCallMessage(cmiGetByQ931(call),message);

        /* Release the message if not needed anymore */
        callReleaseMessage(cmiGetByQ931(call),cmQ931connect);

        /* Change call's Q931 state to Active */
        callE->callState=cs_Active;
    }
    return status;
}


/************************************************************************
 * q931CallDrop
 * purpose: Drops a Q931 connection of a call
 * input  : call        - Stack handle for the Q931 call
 *          message     - Release message to send
 *                        If -1, then message will be created
 * output : none
 * return : Non-negative value on success
 *          Negative value on failure
 ************************************************************************/
int q931CallDrop(IN HQ931 call, IN int message)
{
    int status = 0;
    q931Elem* callE=(q931Elem*)call;

    /*Do this only if something already has happened on this call*/
    if (callE->callState!=cs_Null)
    {
        /* Get the message to send */
        if (message<0)
            message=callGetMessage(cmiGetByQ931(call),cmQ931releaseComplete);
        /* Reset the call's Q931 timer */
        RvH323TimerCancel(cmGetTimersHandle(cmGetAHandle((HPROTOCOL)cmiGetByQ931(call))),&callE->timer);

⌨️ 快捷键说明

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