The Asynchronous with SRL Callback model lets your application execute event handers through either:
For details, see Section 4.1.4. SRL Callback Thread Behavior and Section
Choose the Asynchronous with SRL Callback model for an application that:
Asynchronous with SRL Callback Model Advantages
Asynchronous with SRL Callback Model Disadvantages
Asynchronous with SRL Callback Model Programming NotesSee Section 4.1.4. SRL Callback Thread Behavior.
Asynchronous with SRL Callback Model ExampleAn example of the Aynchronous with SRL Callback model, using the main thread, is shown below:
/********* Aynchronous with SRL Callback Model - Using the Main Thread **********/
/*
* Compiled using Visual C++ 5.0
*/
/* C includes */
#include <windows.h>
#include <stdio.h>
#include <StdLib.H>
#include <process.h>
#include <conio.h>
#include <ctype.h>
#include <String.H>
/* Dialogic includes */
#include <srllib.h>
#include <dxxxlib.h>
/* Defines */
#define MAXCHAN 4 /* maximun number of voice channels in system */
#define FOREVER 1
#define DIALSTRING "01234"
/* Globals */
int vxh[MAXCHAN];
int errflag = FALSE;
/* Prototypes */
int main();
long fallback_hdlr(unsigned long parm);
int voxinit(void);
int sysexit(int exitcode);
int process_events(void);
/****************************************************************
* NAME : int main(void)
* DESCRIPTION : The Entry Point into the application.
* INPUT : none
* OUTPUT : none
* RETURNS : 0 on success; 1 if a failure was encountered
* CAUTIONS : none
****************************************************************/
int main(void)
{
/* Show application's title */
printf("Asynchronous with Main-Thread Callback Model\n");
/* Start Dialogic Devices */
if (voxinit() == -1) {
sysexit(-1);
}
/* Process events , monitor keyboard input and other activities */
if (process_events() == -1) {
sysexit(-1);
}
sysexit(0);
return(0);
}
/****************************************************************
* NAME : int voxinit(void)
* DESCRIPTION : Initializes Dialogic Devices.
* INPUT : none
* OUTPUT : none
* RETURNS : 0 on success; -1 if a failure was encountered
* CAUTIONS : none
****************************************************************/
int voxinit(void)
{
int index;
int mode;
char devname[32];
/** Set to SR_STASYNC so another thread is not created by the SRL to
** monitor events to pass to the handler. We will use this thread
** to monitor events; creating another thread internally is not
** necessary.
**/
mode = SR_STASYNC;
if (sr_setparm(SRL_DEVICE, SR_MODELTYPE, &mode ) == -1 ) {
printf("ERROR:Unable to set SRL modeltype to SR_STASYNC \n" );
return(-1);
}
/*
* Set-up the fall-back handler
*/
if (sr_enbhdlr((long)EV_ANYDEV, (unsigned long)EV_ANYEVT, fallback_hdlr) == -1 ) {
printf("ERROR:Unable to set-up the fall back handler \n");
return(-1);
}
/* Open the voice chans now */
for (index = 0; index < MAXCHAN; index++) {
sprintf(devname, "dxxxB1C%d", (index+1));
if ((vxh[index] = dx_open(devname, 0)) == -1) {
/* Perform system error processing */
return(-1);
}
}
/* Issue the dial without call progres on all the voice chans */
for (index = 0; index < MAXCHAN; index++) {
if (dx_dial(vxh[index], DIALSTRING, NULL, EV_ASYNC) == -1) {
printf("ERROR: dx_dial(%s) failed, 0x%X(%s)\n",
ATDV_NAMEP(vxh[index]), ATDV_LASTERR(vxh[index]),
ATDV_ERRMSGP(vxh[index]));
return(-1);
}
}
}
/****************************************************************
* NAME : int process_events(void)
* DESCRIPTION : The processing loop.
* INPUT : none
* OUTPUT : none
* RETURNS : 0 on success; -1 if a failure was encountered
* CAUTIONS : none
****************************************************************/
int process_events(void)
{
while (FOREVER) {
if (kbhit() != (int)0) {
return(-1);
}
/* Wait for Dialogic events 1 second */
sr_waitevt(1000);
if (errflag == TRUE) {
return(-1);
}
/* Do other processing here */
printf("Press Any Key to Exit \n");
}
return(0);
}
/****************************************************************
* NAME : long fallback_hdlr(unsigned long parm)
* DESCRIPTION : The fallback handler for all Dialogic events
* INPUT : parm
* OUTPUT : return value
* RETURNS :
* CAUTIONS : none
****************************************************************/
long fallback_hdlr(unsigned long parm)
{
int index, devh, evttype;
/* Find out the event received */
devh = sr_getevtdev();
evttype = sr_getevttype();
for (index=0; index<MAXCHAN; index++) {
if (devh == vxh[index]) {
break;
}
}
switch(evttype) {
case TDX_DIAL :
printf("%s : Dialing again.\n", ATDV_NAMEP(vxh[index]));
if (dx_dial(vxh[index], DIALSTRING, NULL, EV_ASYNC) == -1) {
printf("ERROR: dx_dial(%s) failed, 0x%X(%s)\n",
ATDV_NAMEP(vxh[index]), ATDV_LASTERR(vxh[index]),
ATDV_ERRMSGP(vxh[index]));
errflag = TRUE;
}
break;
case TDX_ERROR :
printf("%s : TDX_ERROR!\n", ATDV_NAMEP(vxh[index]));
errflag = TRUE;
break;
default :
printf("%s : unknown event(0x%X)\n", ATDV_NAMEP(vxh[index]), evttype);
errflag = TRUE;
break;
}
/* Remove the events from the SRL queue */
return(1);
}
/****************************************************************
* NAME : void sysexit(exitcode)
* DESCRIPTION : Closes the devices and exits the application.
* INPUT : none
* OUTPUT : none
* RETURNS : exitcode
* CAUTIONS : Exit of the application!
****************************************************************/
int sysexit(int exitcode)
{
int index;
/* Close the voice chans now */
for (index = 0; index < MAXCHAN; index++) {
if (dx_close(vxh[index]) == -1) {
printf("ERROR: dx_close(%s) failed, 0x%X(%s)\n",
ATDV_NAMEP(vxh[index]), ATDV_LASTERR(vxh[index]),
ATDV_ERRMSGP(vxh[index]));
}
}
exit(exitcode);
return(exitcode);
}
Click here to contact Dialogic Customer Engineering
Copyright 2001, Dialogic Corporation