
Description | Cautions | Example | Errors
Name: |
long sr_waitevt(timeout) | |
Inputs: |
long timeout |
|
Returns: |
time left before timeout | |
|
-1 if timeout | |
Includes: |
srllib.h | |
Type: |
Event Control function | |
The function sr_waitevt( ), for a specified period of time, waits for any event to occur on any Dialogic device
Parameter |
Description |
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. |
The sr_waitevt( ) function returns a value when the next event occurs, or when a timeout is reached. If an event occurs, the value returned is the number of milliseconds before the timeout. If no event occurs before the timeout, the value returned is -1. If the function times out, a timeout event occurs on the SRL_DEVICE. The sr_getevtdev(0) function returns SRL_DEVICE, the Dialogic device handle associated with the current event. The sr_getevttype(0) function returns SR_TMOUTEVT, which is the current event type.
When an application receives an event, the event must be handled immediately and event-specific information should be retrieved before the next call to sr_waitevt( ) because sr_waitevt( ) automatically removes the current event before waiting for the next event; previous information is overwritten.
The sr_waitevt( ) function cannot be called from within a handler.
You cannot use sr_waitevt( ) and sr_waitevtEx( ) functions in the same thread.
If you use the sr_waitevt( ) function to retrieve events, pass 0 as a parameter when using the following functions:
#include <windows.h>
#include <srllib.h>
#include <dxxxlib.h>
int dx_handler(unsigned long evhandle)
{
printf( "Got event 0x%x on device %s, data length = %d, datap = 0x%x\n",
sr_getevttype(evhandle), ATDV_NAMEP( sr_getevtdev()), sr_getevtlen(evhandle),
sr_getevtdatap(evhandle));
/* Tell SRL to keep the event */
return( 1 );
}
main()
{
int dxxxdev;
int mode = SR_STASYNC;
/* Set SRL to turn off creation of internal thread */
if( sr_setparm( SRL_DEVICE, SR_MODELTYPE, &mode ) == -1 ){
printf( "Error: cannot set srl mode\n" );
exit( 1 );
}
/* Open a dxxx channel device */
if(( dxxxdev = dx_open( "dxxxB1C1", 0 )) == -1 ){
printf( "Error: cannot open device\n" );
exit( 1 );
}
/* enable a handler for all events on the device */
if( sr_enbhdlr( dxxxdev, EV_ANYEVT, dx_handler ) == -1 ){
printf( "Error: could not enable handler\n" );
exit( 1 );
}
/* Perform an async function on the device */
if( dx_sethook( dxxxdev, DL_ONHOOK, EV_ASYNC ) == -1 ){
printf( "dx_sethook failed: error = %s\n", ATDV_ERRMSGP( dxxxdev ));
exit( 1 );
}
/* Wait 10 seconds for an event */
if( sr_waitevt( 10000 ) == -1 ){
printf( "sr_waitevt, %s\n",
ATDV_ERRMSGP( SRL_DEVICE ));
exit( 1 );
}
/* Disable the handler */
if( sr_dishdlr( dxxxdev, EV_ANYEVT, dx_handler ) == -1 ){
printf( "Error: could not disable handler\n" );
exit( 1 );
}
if( dx_close( dxxxdev ) == -1 ){
printf( "Error: could not close dxxxdev\n" );
exit( 1 );
}
exit( 0 );
}
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 |
|
Click here to contact Dialogic Customer Engineering
Copyright 2001, Dialogic Corporation