
Description | Cautions | Example | Errors | See Also
Name: |
cc_GetChanId(crn, chanId) | |
Inputs: |
CRN crn |
|
CHAN_ID *chanId |
| |
Returns: |
0 on success | |
Includes: |
cclib.h | |
Category: |
Optional call handling | |
Mode: |
synchronous | |
Technology: |
BRI/2; BRI/SC | |
The cc_GetChanId( ) function gets the last channel information received from messages for the specified CRN. This function is used after a call-related event is received for the board device (e.g., dtiB1)
Parameter |
Description |
crn: |
The call reference number. |
chanId: |
Pointer to the Channel ID structure that contains the last channel preference known for the specified CRN. |
The channel ID information associated with a specific CRN may change after an incoming call is connected or answered.
#include <windows.h> /* For Windows applications only */
#include <stdio.h>
#include <errno.h>
#include "srllib.h"
#include "dtilib.h"
#include "cclib.h"
/** Globals **/
CRN normal_crn = 0; /* crn of a normal call */
CRN waitingcall_crn = 0;
/** Function prototypes **/
long event_handler(unsigned long event_handle);
int callfail (CRN crn);
int procdevfail (LINEDEV handle);
void main( )
{
LINEDEV boarddev;
.
.
if ( cc_Open ( &boarddev, "dtiB1", 0 ) < 0 )
{
printf ("Error opening board device: errno = %d\n", errno);
exit (1);
}
.
.
sr_setparm ( SRL_DEVICE, SR_MODELTYPE, &sr_mode );
sr_enbhdlr ( EV_ANYDEV, EV_ANYEVT, event_handler );
if ( cc_WaitCall (boarddev, &normal_crn, NULL, -1, EV_ASYNC) < 0 )
procdevfail (linedev);
.
.
.
}
long event_handler(unsigned long event_handle)
{
CRN crn;
int event;
void *datap;
char ani_buf[CC_ADDRSIZE];
CHAN_ID chanId;
event = sr_getevttype(event_handle);
datap = sr_getevtdatap(event_handle);
cc_GetCRN(&crn, datap);
switch(event)
{
case CCEV_OFFERED:
cc_GetChanId(crn, &chanId);
switch(chanId.channel)
{
case NO_BCHAN: /* waiting call */
cc_GetANI (crn, ani_buf);
if (strcmp (ani_buf, "9933000") == 0)
{
waitingcall_crn = crn;
/* If no resource is available, then an active one must be freed */
if( cc_DropCall (active_crn, NORMAL_CLEARING, EV_ASYNC) < 0 )
callfail(crn);
/** Optionally, the active call can be put on Hold
if( cc_HoldCall (active_crn, EV_ASYNC) < 0 )
callfail(crn);
**/
}
else /* this call is not for us */
{
if( cc_DropCall (crn, NORMAL_CLEARING, EV_ASYNC) < 0 )
callfail(crn);
}
break;
case DCHAN_IND: /* non circuit switched calls */
/* Ignore this call */
break;
default: /* normal call */
normal_crn = crn;
switch(chanId.mode)
{
case PREFFERED:
if( cc_AcceptCall(crn, EV_ASYNC) < 0 )
callfail(crn);
break;
case EXCLUSIVE:
if( cc_AcceptCall (crn, 0, EV_ASYNC) < 0 )
callfail(crn);
break;
}
}
break;
case CCEV_ACCEPT:
if( cc_AnswerCall (crn, 0, EV_ASYNC) < 0 )
callfail(crn);
break;
case CCEV_ANSWERED:
if(crn == waitingcall_crn)
{
normal_crn = crn;
waitingcall_crn = 0;
}
break;
case CCEV_HOLDACK:
if( (crn == normal_crn) && (callwaiting_crn != 0) )
{
cc_GetChanId(crn, &chanId);
freed_device = chanId.channel;
if( cc_AcceptCall(callwaiting_crn, num_rings, EV_ASYNC) < 0 )
callfail(crn);
active_crn = 0;
}
break;
case CCEV_DROPCALL:
if( cc_ReleaseCallEx (crn) < 0 )
callfail(crn);
if( (crn == normal_crn) && (callwaiting_crn != 0) )
{
cc_GetChanId(crn, &chanId);
if( cc_AcceptCall(callwaiting_crn, num_rings, EV_ASYNC) < 0 )
callfail(crn);
}
break;
case CCEV_RELEASE:
if(active_crn == crn)
active_crn = 0;
else if(waitingcall_crn == crn)
waitingcall_crn = 0;
break;
.
.
.
}
}
int callfail (CRN crn)
{
LINEDEV ld;
cc_CRN2LineDev (crn,&ld);
procdevfail (ld);
}
int procdevfail (LINEDEV handle)
{
int reason;
char *msg;
reason = cc_CauseValue (handle);
cc_ResultMsg (handle,reason, &msg);
printf ("reason = %x - %s\n", reason, msg);
}
If the function returns < 0 to indicate failure, use the cc_CauseValue( ) function to retrieve the reason code for the failure. The cc_ResultMsg( ) function can be used to interpret the reason code. Error codes are defined in the files ccerr.h, isdnerr.h, and isdncmd.h.
Error codes from the cc_GetChanId( ) function include the following:
Error Code |
Description |
ERR_ISDN_LIB | E_ISBADIF |
Bad interface number |
ERR_ISDN_LIB | E_ISBADCALLID |
Bad call identifier |
ERR_ISDN_LIB | E_ISBADTS |
Bad time slot |
Click here to contact Dialogic Customer Engineering
Copyright 2001, Dialogic Corporation