Avaya Logo

Previous Topic

Next Topic

Book Contents

Book Index

Application execution

After application initialization, the application is ready to perform whatever IRAPI functions necessary to interact with the caller in the way defined by the application. Usually, the best way to implement this interaction is through an event switch inside a continuous loop on the irWCheck(3IRAPI) function. Each case in the switch should handle a unique event, perform the next event generating function, and return to the wait loop [irWCheck()]. Each time an application executes an event generating function, it should not execute another IRAPI function until it receives the event that terminates that function.

For example, an application might perform the following functions after application initialization:

  1. Answer the phone with irAnswer(3IRAPI) and wait for the IRE_ANSWER_DONE event.

    In the chantest.c application, after the IRE_EXEC event is received and chantest initializes the application, it answers the incoming call with irAnswer(3IRAPI). It then returns to the while loop to wait for the IRE_ANSWER_DONE event. The IRE_ANSWER_DONE event contains the result of the answer attempt.

    while ( irWCheck(&ev) != IRR_FAIL ) {
    switch(ev.event_id) {
    .
    .
    .
    case IRE_EXEC:
    .
    .
    .
    if (irAnswer(cid) == IRR_FAIL) {
    cleanup ("Error onirAnswer",cid);
    }
    break;

    case IRE_ANSWER_DONE:
    if ( ev.event_mod1 != IREM_COMPLETE ) {
    cleanup("Error in IRE_ANSWER_DONE", cid);
    break;
    }
    startChanTst(cid);
    break;

  2. Queue up voice files to play with irFPlay(3IRAPI), start play with irEnd(3IRAPI), and wait for the IRE_PLAY_DONE event.

    Chantest uses its startChanTst() subroutine when the IRE_ANSWER_DONE event is received to perform this step of the application. This subroutine plays the introductory announcement, ``Begin testing.''

    void startChanTst(channel_id cid)
    {
    int chan = irCid2Chan(cid);
    if ( chan == IRR_FAIL ) {
    cleanup("Can't get channel from cid", cid);
    return;
    }
    Chl[chan].PlayDone = IGNORE_WHEN_DONE;
    Chl[chan].RetryCount = 0;
    if (irFPlay(cid, 0, "/speech/begn.tst") < 0) {
    cleanup ("Error on irFPlay", cid);
    return;
    }
    playInstr(cid);
    }

    The startChanTst routine converts the cid to a channel number with irCid2Chan(3IRAPI). It uses the channel number to set application specific data for the channel. The PlayDone flag indicates what is to be done when the next IRE_PLAY_DONE event arrives. The RetryCount indicates the number of times the application has prompted the caller after getting no input. irFPlay(3IRAPI) is used to queue up the "begin testing'' introductory phrase stored in the file /speech/begn.tst for playing. The playInstr() subroutine then is called to play the instructions that are part of the initial chantest prompt.

    void playInstr(channel_id cid)
    {
    int chan = irCid2Chan(cid);
    if ( chan == IRR_FAIL ) {
    cleanup("Can't get channel from cid", cid);
    return;
    }
    Chl[chan].PlayDone = START_TIMER_WHEN_DONE;
    if(irFlushInput(cid) == IRR_FAIL ||
    irSetEvent(cid, IRE_INPUT, IRF_PLAYINTR | IRF_NOTIFY)
    == IRR_FAIL ||
    irSetEvent(cid, IRE_INPUT_DONE, IRF_NOTIFY) == IRR_FAIL ||
    irFPlay(cid, 0, "/speech/ent.4.tt") == IRR_FAIL ||
    irFPlay(cid, 0, "/speech/all.rptd") == IRR_FAIL ||
    irFPlay(cid, 0, "/speech/term.4.0") == IRR_FAIL ||
    irEnd(cid, 0, 0) < 0) {
    cleanup ("Error in playInstr", cid);
    }
    }

    Before the prompt is played, the PlayDone flag is set to indicate that the touch-tone input timer should be started when the next IRE_PLAY_DONE event is received. The irFlushInput(3IRAPI) function clears any caller input that has been given before the prompt. This synchronizes caller input with prompts. The irSetEvent(3IRAPI) function is used to set the IRE_INPUT event to interrupt speech play when the event is generated. This enables the talkoff feature, allowing the caller to interrupt a prompt with touch-tone input. Three separate phrases are queued up with irFPlay(3IRAPI) that make up instructions to the caller: "Enter 4 touch tone digits,'' "All digits except star and pound will be repeated,'' "Terminate your input with a pound sign.'' Speech play is started with the call to irEnd(3IRAPI) and the subroutine returns back to the main while loop to wait for the next event.

  3. Start the touch-tone input timer with irStartTTTimer(3IRAPI), collect input with irGetInput(3IRAPI), and wait for the IRE_INPUT_DONE event.

    Touch-tone input is always being collected and placed on the input queue. The IRE_INPUT event indicates that input has been placed on the input queue. The IRE_INPUT_DONE event indicates that the input on the input queue matches conditions specified by the input queue parameters.

  4. Disconnect with irDisconnect(3IRAPI), wait for the IRE_DISCONNECT_DONE event, and terminate the application.

© 2006 Avaya Inc. All Rights Reserved.