
Description | Cautions | Examples | Errors | See Also
The sr_waitevtEx( ) function waits for events on certain devices. This function is an extended version of the standard sr_waitevt( ) function. It is used to asynchronously wait for any event to occur on any of the handles passed to the functions. It detects events from devices opened through any of the device-specific xx_open( ) function calls for that device.
Parameter |
Description |
handlep |
Points to an array of opened handles. |
handlecnt |
Indicates how many devices are contained in the array. |
timeout |
A timeout value of -1 instructs sr_waitevt( ) to wait indefinitely for the next event. Use timeout 0 when the SRL event must return imediately, regardlesss of whether or not an event is present in the SRL event queue. |
event_handlep |
When an event is reported, an event handle is passed backed to the application through the event_handlep argument. The value returned here should be passed to the sr_getevtdev( ) , sr_getevttype( ) , sr_getevtlen( ), and sr_getevtdatap( ) functions to retrieve the event information. |
The sr_waitevtEx( ) function can be used in a single-threaded or multithreaded application. Furthermore, functions initiated asynchronously from one thread can be completed and have the event returned by sr_waitevtEx( ) running in another thread. An application might also have multiple threads blocked in sr_waitevtEx( ) waiting for events on the same device, however it is indeterminate which thread picks up the event, so each thread should be running the same state machine.
The sr_waitevt( ) and sr_waitevtEx( ) functions should not be used in the same application.
The sr_waitevtEx( ) function can NOT be used in conjunction with handlers.
#include <srllib.h>
#include <windows.h>
#include <dxxxlib.h>
long chdev[MAXDEVS];
unsigned long evt_handle;
main( ... )
{
char channel_name[12];
int ch;
for (ch = 0; ch < MAXDEVS; ch++) {
/* Build the channel name for each channel */
if ( (chdev[ch] = dx_open(channel_name, 0) ) == -1 ) {
printf("dx_open failed\n");
exit(1);
}
}
/*
* Now initialize each device setting up the event masks and then issue
* the command asynchronously to start off the state machine.
*/
for (ch = 0; ch < MAXDEVS; ch++) {
/* Set up the event masks and other initialization */
/* set the channel onhook asynchronously */
if (dx_sethook( chdev[ch]. DX_ONHOOK, EV_ASYNC) == -1) {
/* sethook failed, handle the error */
}
}
/* This is the main loop to control the Voice hardware */
while (FOREVER) {
/* wait for the event */
sr_waitevtEx( chdev, MAXDEVS, -1, &evt_handle);
process_event( evt_handle);
}
int process_event( ehandle)
unsigned long ehandle;
{
int voxhandle = sr_getevtdev(ehandle);
switch(sr_getevttype(ehandle)) {
case TDX_CST:
.
break;
case TDX_PLAY:
.
break;
}
}
If this function returns -1 to indicate failure, obtain the reason for the error by calling the SRL standard attribute function ATDV_LASTERR(SRL_DEVICE) or ATDV_ERRMSGP(SRL_DEVICE) to retrieve either the error code or a pointer to the error description, respectively. One of the following errors may be returned:
ESR_SYS |
|
ESR_TMOUT |
|
Click here to contact Dialogic Customer Engineering
Copyright 2001, Dialogic Corporation