24 Voice API for Linux Demo Guide — June 2005
Demo Details
Since d40demo is also a working order entry system, the source code contains nonsystem routines
that are specific to the order entry application. The d40demo.c module contains the routines that
manage a simple database, which are called the application specific routines.
The d40demo program uses three system routines:
Initialization
Menu System Routine
Messaging System Routine
5.5.2 Global Variables
Global variables are used by the functions in d4xtools.c. These variables are defined in d4xtools.c:
cur_menu
Current Menu. A pointer to the current active menu.
pre_menu
Previous Menu. A pointer to the previous menu.
idlestate
Idle State Reentry Environment. The reentry point to the process. Using the longjmp( ) and
setjmp( ) Linux functions, idlestate is the point where the process sets the hookstate to onhook
and waits for the phone to ring.
devhandle
Device handle. The variable that holds the descriptor for the channel.
Two default DV_TPT arrays are defined in d40demo.c and are used by the d4xtools.c system
routines:
def_rp_tpt
Default Record and Play. The default DV_TPT array for recording and playing using dx_rec( )
and dx_play( ).
def_dg_tpt
Default Get Digit. The default DV_TPT array for getting digit responses using the
dx_getdig( ) function.
5.5.3 Initialization Routine
When d40demo is started, the application is initialized by a call in main( ) to init_sys( ). The
init_sys( ) function is located in the d4xtools.c module. It performs system initialization by
spawning a child process for each channel, configuring the signal handler, opening the channel,
initializing the message table, and ending the parent process.
For every argument supplied at the command line, the init_sys( ) function uses the Linux system
call fork( ) to spawn a child copy of the d40demo process. Any code following the call to fork( ) is
executing in both the child and the parent process. The following code fragment checks if the
process is a child process, and if it is, closes file descriptor 0, the standard input: