|
Example
|
sample_process_events (CTAHD ctahd)
{
CTA_EVENT event;
ISDN_MESSAGE *imsg;
ISDN_PACKET *ipkt;
BYTE *data;
DWORD ret;
char errortext[40];
#define EVENT_CODE(from, code) ((from<<8)|code)
...
/*
** Protocol already started...
** Application may have sent messages to stack
*/
...
/*
** Application waiting for events
*/
myWaitForEvent( ctahd, &event);
/*
** Got event ISDN_RCV_MESSAGE
** If the event value field is not SUCCESS, then
** the event was not received successfully.
*/
if( event.value != SUCCESS )
{
ctaGetText(ctahd, event.value, errortext, 40);
printf("RCV_FAIL: %s\n", errortext);
return MY_ERROR_RCV_FAILED;
}
/*
** NOTE: all asynchnous events have the
** msg->userid field is ISDN_USERID_ASYNC
*/
ipkt = (ISDN_PACKET *) event->buffer;
imsg = &ipkt->message;
data = ipkt->data;
printf("from: %c code=%c to=%c id=%d len=%d\n",
imsg->from_ent,
imsg->code,
imsg->to_ent,
imsg->add.conn_id,
ipkt->data_len);
switch(EVENT_CODE(imsg->from_ent, imsg->code) )
{
case EVENT_CODE(ENT_ACU, CONN_CO):
/*
** call is now connected
*/
printf("Connected on conn_id: %d\n",imsg->add.conn_id);
break;
case EVENT_CODE(ENT_ACU,ACU_CLEAR_CO):
/*
** call is now cleared
*/
printf("Cleared on conn_id: %d\n", imsg->add.conn_id);
break;
...
default:
printf("Unprocessed message: %c %c\n", imsg->from_ent,
imsg->code);
break;
}
/*
** Processing is done, release the buffer as soon as possible
*/
ret = isdnReleaseBuffer( ctahd, event.buffer );
if( ret != SUCCESS )
{
ctaGetText(ctahd, event.value, errortext, 40);
printf("RELEASE_FAIL: %s\n", errortext);
return MY_ERROR_RELEASE_FAILED;
}
...
}
|