
Description | Cautions | Example | Errors | See Also
Name: |
long sr_setparm(dev, parmno, parmval) | |
Inputs: |
long dev |
|
|
long parmno |
|
|
void *parmval |
|
Returns: |
0 if successful | |
|
-1 if failure | |
Includes: |
srllib.h | |
Type: |
SRL Parameter function | |
The sr_setparm( ) function allows the application to set the value of an SRL parameter. Usually, this function's parameters govern the mode of operation for eventing and synchronization. The function parameters are described as follows:
Parameter |
Description | |
dev |
Device handle. Generally, you should set this parameter to SRL_DEVICE, which is the predefined SRL device handle. However, if the parameter being set is SR_USERCONTEXT, then dev should be set to the handle returned by the technology-specific xx_open( ). | |
parmno |
Value for the SRL parameter to be changed. Possible values are as follows: | |
|
|
Set the model type to turn off creation of internal thread used to service event handler action |
|
|
Set the polling granularity parameter (the time between device polls expressed in milliseconds). |
|
|
Set user-specific context. This lets you quickly set application-specific context on a given Dialogic device handle. |
|
|
Set the Win32 integration mode. (See below.) |
parmval |
A pointer to an area of memory that contains the value for the specified parameter. | |
|
|
The value is expected to point to an integer that contains SR_STASYNC or SR_MTASYNC. |
|
|
The value is expected to point to an integer that contains the polling granularity expressed in millisecond (ms) units. |
|
|
The value is expected to point to arbitrary user-supplied data. |
|
|
The value is expected to point to either an SRLWIN32INFO structure that indicates the Win32 synchronization method or to NULL to disable Win32 notification. |
For more information on Win32 integration and on use of the SR_WIN32INFO parameter, see section 5.5. Asynchronous with Win32 Synchronization Model.
Normally, when setting SRL parameters, you must set the dev parameter to SRL_DEVICE. However, if you set the parmno parameter to SR_USERCONTEXT, you must set the dev parameter to the device on which context is being retrieved.
#include <windows.h>
#include <srllib.h>
main()
{
int mode = SR_STASYNC;
if( sr_setparm( SRL_DEVICE, SR_MODELTYPE, &mode ) == -1 ){
printf( "Error: cannot set srl mode\n" );
exit( 1 );
}
}
The following example calls the sr_setparm( ) function with its parmno parameter set to SR_USERCONTEXT:
#include <windows.h>
#include <srllib.h>
#include <dxxxlib.h>
//
// 4 devices maximum
//
#define MAXDEVICECOUNT 4
//
// Per device structure, one for each device
//
APPDEVICESTRUCT AppDeviceStruct[MAXDEVICECOUNT];
BOOL OpenAllDevices()
{
ULONG DeviceIndex;
CHAR DeviceName[16];
INT hDevice;
for (DeviceIndex = 0; DeviceIndex < MAXDEVICECOUNT; DeviceIndex++) {
//
// Build the device name and open it
//
sprintf(DeviceName,"dxxxB1C%d", DeviceIndex+1);
hDevice = dx_open(DeviceName, 0);
if (hDevice == -1) {
return(FALSE);
}
//
// Now store away device handle and save device index on device
// handles user context
// This way given the device handle I get back to the device structure
// and vice versa
AppDeviceStruct[DeviceIndex].hDevice = hDevice;
if (sr_setparm(hDevice, SR_USERCONTEXT, (void *)&DeviceIndex) == -1) {
//
// perform clean up and return
//
return(FALSE);
}
} // End of for loop
return(TRUE);
}
//
// Main loop processing showing how to retrieve SR_USERCONTEXT
//
APPDEVICESTRUCT * WaitEvent()
{
ULONG DeviceIndex;
//
// Wait for any event
//
sr_waitevt(-1);
//
// got event so get device structure and return. Sr_getevtdev()
// returns the Dialogic device handle. DeviceIndex retrieves the
// the applications Index for this device. Of course the pointer
// to the AppDeviceStruct could have been stored directly as well
//
sr_getparm(sr_getevtdev(), SR_USERCONTEXT, (void *)&DeviceIndex);
return(&AppDeviceStruct[DeviceIndex]);
}
The following example uses Win32 notification through an I/O Completion Port:
#include <windows.h>
#include <srllib.h>
#include <dxxxlib.h>
#define DIALOGIC_KEY 1
SRLWIN32INFO AppWin32Info;
HANDLE hCompletionPort;
BOOL CreateAndRegisterEventNotification()
{
hCompletionPort = CreateIoCompletionPort( (HANDLE)NULL, // no handle
(HANDLE)NULL, // it's new
0, // no key
0); // scaling
// set up the information for SRL
AppWin32Info.dwTotalSize = sizeof(SRLWIN32INFO);
AppWin32Info.ObjectHandle = hCompletionPort;
AppWin32Info.UserKey = DIALOGIC_KEY;
AppWin32Info.dwHandleType = SR_IOCOMPLETIONPORT;
AppWin32Info.lpOverlapped = (LPOVERLAPPED)NULL;
sr_setparm(SRL_DEVICE, SR_WIN32INFO, (void *)&AppWin32Info);
//
// now add all the Win32 devices to the Completion Port assigning each
// one a unique key
//
return(TRUE);
}
BOOL WaitForCompletion()
{
DWORD UserKey;
DWORD NumberOfBytesTransferred;
LPOVERLAPPED lpOverlapped;
BOOL bStatus;
// block waiting for the event
bStatus = GetQueueCompletionStatus ( hCompletionPort,
&NumberOfBytesTransferred,
&UserKey,
&lpOverlapped,
INFINITE );
if (bStatus == FALSE) {
return(bStatus);
}
switch (UserKey) {
case DIALOGIC_KEY:
// get the event of the SRL event queue
sr_waitevt(0);
//
// use the sr_getevtxxx()functions now to get event information
//
break;
default:
// notification on some other win32 device, process accordingly
break;
}
return(TRUE)
}
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