Voice API for Linux Demo Guide — June 2005 25
Demo Details
if (rc == 0) {
close(0);
.
.
The code that follows the close( ) function call within the if statement is only executed in the child
process. The parent process fails the (rc == 0) comparison and loops back to the while statement.
When all the arguments are exhausted, the parent process eliminates itself by a call to the exit( )
function.
The signal( ) function calls redirect the signals from the outside world to call the sigcatch( )
function. The sigcatch( ) function, located in d4xtools.c, is the signal processing routine for each
channel. It stops I/O on the channel, sets the hook state to onhook, and exits the process. By
intercepting the signals and using sigcatch( ), the process exits cleanly if it receives an interrupt,
quit, terminate, or hang-up signal from the outside world.
The strcpy( ) function copies the channel device name to a global variable to give all functions
access to the device name.
The channel specified on the command line is opened by the dx_open( ) function with read and
write privileges. The descriptor for the channel is stored in the global variable devhandle.
The message structure is initialized in the for-loop. It scans every entry in the message structure,
opens the specified file with read-only privileges, and stores the file descriptor for the open file in
the message structure. This code allows an arbitrary number of playback files or devices to be
opened. You only need to specify a DL_MSGTBL structure for each playback file or device, and
the init_sys( ) function will open all the files and store the file descriptors.
The final action of a child process is to return the argument number as the return value. d40demo.c
uses this value when it initializes the order entry database.
5.5.4 Menu System Routine
d40demo is built around a menu system that controls the flow of the program. The menu system is
a general concept that is useful for any voice application. Understanding how the menu system
works is essential to understanding how d40demo works.

Model of the Menu System

In general, when a call is received by a voice application, all callers are presented with the same
initial voice menu. This menu is referred to as the root menu. For example, in a customer service
application, the initial prompt might introduce the company and ask the caller to press 1 for sales or
2 for support. The caller listens to the voice prompt and presses 1. The application prompts with
another menu, asking the caller to press 1 for Jane, 2 for John, or 3 to hang up. The caller presses 2
and is prompted to record a message to John. When the caller completes recording he is prompted
with the same menu asking him to press 1 for Jane, 2 for John, or 3 to hang-up. The caller presses 3
and is disconnected.
From the example above, it can be seen that all menus have the following characteristics. They play
voice prompts, require caller input, and transfer control based on caller input.