
Description | Cautions | Source Code | Example | Errors | See Also
|
Name: |
int li_attendant(pAtt) | |
|
Inputs: |
PDX_ATTENDANT *pAtt |
|
|
Returns: |
0 if success |
|
|
EDX_BADPARM |
||
|
EDX_BADPROD |
||
|
EDX_SYSTEM |
||
|
-1 if failure |
||
|
Includes: |
syntellect.h |
|
|
Category: |
Licenses and Technologies | |
|
Mode: |
Synchronous, multitasking | |
The li_attendant( ) function performs the actions of an automated attendant. It is an implementation of an automated attendant application and works as a created thread. Before the application can create the thread, it must initialize the DX_ATTENDANT data structure.
This function loops forever or until the named event specified in the szEventName field of the DX_ATTENDANT data structure becomes signaled. While waiting for the named event to be signaled, this function checks for an incoming call. By default, it assumes that an analog front end is present and uses dx_setevtmsk( ) and dx_getevt( ) to determine if an incoming call is present.
The application can override the default analog front end behavior by supplying a function in the pfnWaitForRings field of the data structure.
Once an incoming call is detected, the call is answered. A voice file intro.att is played back, and li_attendant( ) waits for digit input. By default, dx_sethook( ) is called unless pfnAnswerCall is not NULL. The application can override the default analog front end behavior by supplying a function in the pfnAnswerCall field.
The maximum number of DTMF digits is specified in the nExtensionLength field. If timeout occurs or the maximum number is reached, the translation function in the pfnExtensionMap field is called. The translated string, whose maximum length is nDialStringLength, is then dialed. The translation function should insert pauses and flash hook sequences where appropriate. The call is terminated using dx_sethook( ) unless pfnDisconnectCall is registered, and li_attendant( ) awaits the next incoming call. The application can override the default analog front end behavior by supplying a function in the pfnDisconnectCall field.
Parameter |
Description |
pAtt |
Points to the Automated Attendant data structure, DX_ATTENDANT, that specifies termination conditions for this function and more. For details, refer to the chapter on Data Structures. |
To view the source code for li_attendant( ), refer to the syntellect.c file in the samples\syntellect directory under the Dialogic home directory.
To view the source file for the example, refer to the attendant.c file in the samples\syntellect directory under the Dialogic home directory.
#include <windows.h>
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
#include <process.h>
#include <srllib.h>
#include <dxxxlib.h>
#include "syntellect.h"
#define EXTENSION_LENGTH 2
#define EVENT_NAME "ExitEvent"
// define functions used for the hook
static int att_onhook(int dev); // optional
static int att_offhook(int dev); // optional
static BOOL att_mapextension(char *, char *); // obligatory !!
static int att_waitforrings(int dev, BOOL *bWaiting); // optional
int main (int argc, char *argv[])
{
HANDLE hEvent;
HANDLE hThread[2];
DX_ATTENDANT Att[2];
BOOL ret;
ZeroMemory(&Att, sizeof(Att));
// initialize structure for two thread
// thread 1 uses custom call back functions
// for telephony control
Att[0].nSize = sizeof(DX_ATTENDANT);
strcpy(Att[0].szDevName, "dxxxB1C1");
Att[0].pfnDisconnectCall = (PFUNC) att_onhook;
Att[0].pfnAnswerCall = (PFUNC) att_offhook;
Att[0].pfnExtensionMap = (PMAPFUNC) att_mapextension;
Att[0].pfnWaitForRings = (PWAITFUNC) att_waitforrings;
strcpy(Att[0].szEventName, EVENT_NAME);
Att[0].nExtensionLength = EXTENSION_LENGTH;
Att[0].nDialStringLength = EXTENSION_LENGTH+10;
Att[0].nTimeOut = 5;
// thread 2 uses built-in functions
// for telephony control
Att[1].nSize = sizeof(DX_ATTENDANT);
strcpy(Att[1].szDevName , "dxxxB1C2");
Att[1].pfnDisconnectCall = (PFUNC) NULL;
Att[1].pfnAnswerCall = (PFUNC) NULL;
Att[1].pfnExtensionMap = (PMAPFUNC) att_mapextension;
Att[1].pfnWaitForRings = (PWAITFUNC) NULL;
strcpy(Att[1].szEventName , EVENT_NAME);
Att[1].nExtensionLength = EXTENSION_LENGTH;
Att[1].nDialStringLength = EXTENSION_LENGTH+10;
Att[1].nTimeOut = 5;
// create the named event
if ((hEvent = CreateEvent(
NULL, // no security attributes
TRUE, //FALSE, // not a manual-reset event
FALSE, // initial state is not signaled
EVENT_NAME // object name
)) == (HANDLE) NULL)
return (-1);
// start the first attendant thread
if ((hThread[0] = (HANDLE) _beginthread( li_attendant, 0, (void *) &Att[0] )) == (HANDLE) -1)
{
printf("Cannot create thread 1.\n");
exit(0);
}
// start the second attendant thread
if ((hThread[1] = (HANDLE) _beginthread( li_attendant, 0, (void *) &Att[1] )) == (HANDLE) -1)
{
printf("Cannot create thread 2.\n");
exit(0);
}
Sleep(30000); // Wait as long as you want to run the application
SetEvent(hEvent); // notify threads to exit
WaitForMultipleObjects(2, hThread, TRUE, INFINITE); // wait until the threads are done
CloseHandle(hEvent);
return(0);
}
int att_onhook(int dev)
{
printf("ONHOOK\n");
return (dx_sethook(dev, DX_ONHOOK, EV_SYNC));
}
int att_offhook(int dev)
{
printf("OFFHOOK\n");
return(dx_sethook(dev, DX_OFFHOOK, EV_SYNC));
}
int att_waitforrings(int dev, BOOL *bWaiting)
{
int ret;
DX_EBLK eblk;
ret = dx_getevt(dev, &eblk, 0);
if (ret == 0)
{
if (eblk.ev_event == DE_RINGS)
*bWaiting = FALSE;
}
return (0);
}
BOOL att_mapextension(char *szExtension, char *szMappedExtension)
{
int nExtId;
// for demo purposes use a dumb translation, increment extension by one...
nExtId = atoi(szExtension) + 1;
// prefix with flash hook and pause characters
sprintf(szMappedExtension, "&,,%*.d", EXTENSION_LENGTH, nExtId);
return(TRUE);
}
This function fails and returns the specified error under the following conditions:
Equate |
Returned When |
|
-1 |
|
|
EDX_BADPARM |
|
EDX_BADPROD |
The opened device is on a board that is not enabled with the Syntellect patent license (non-STC board). |
EDX_SYSTEM |
Error from operating system; use dx_fileerrno( ) to obtain error value. Unable to allocate nDialStringLength +1 characters. |
Click here to contact Dialogic Customer Engineering
Copyright 2002, Dialogic Corporation