Before an IRAPI application can start on a specific channel, it must perform the following tasks:
If the IRAPI application is assigned as a service to one or more channels, it should wait for an IRE_EXEC event from the IRAPI using the irWCheck(3IRAPI) function. This event is passed to an application when a new call arrives on a channel to which the application is assigned, or when another application uses irExec(3IRAPI) or irSubProg(3IRAPI) to run the application. When the IRE_EXEC event is received, call the irInit(3IRAPI) function to obtain ownership of the channel specified in the IRE_EXEC event data structure.
If the application is to run on a channel to which it is not assigned, it should first request ownership of the channel with irInit(3IRAPI) or irInitGroup(3IRAPI). It should then use irWCheck(3IRAPI) to wait for the IRE_CHAN_GRANT event before continuing with the application on that channel. See Channel management.
In each case, irInit(3IRAPI) or irInitGroup(3IRAPI) is used to obtain a valid channel ID (cid). This cid value is used as an argument to all other channel specific IRAPI functions and is included as part of the event data structure for all events that result from calling these functions.
After process initialization, chantest enters a while loop to wait for IRAPI events with irWCheck(3IRAPI). The chantest application is designed to be executed by the Application Dispatch (AD) process when a new call arrives on a channel to which chantest is assigned. Therefore, after process initialization, the chantest process does not start running the application until it receives an IRE_EXEC event. All events are handled by the switch statement within the while loop. The following code fragment shows how chantest initializes the application after receiving an IRE_EXEC event:
ir_event_t ev;
channel_id cid;
int chan;
.
.
.
while (irWCheck(&ev) != IRR_FAIL) {
switch (ev.event_id) {
case IRE_EXEC:
chan = ev.event_mod1;
if (irInit (chan, &cid, IRD_IMMEDIATE, 0) != IRR_OK) {
irPError ("Error on irInit");
break;
}
Chl[chan].State = BUSY;
if(setEvents(cid) < 0) {
cleanup("Error on setEvents", cid);
break;
}
if(setTTParams(cid) < 0) {
cleanup ("Error on setTTParams", cid);
break;
}
.
.
.
}
}
irPError("irWCheck Failed.");
exit(1);
After receiving an IRE_EXEC event, chantest gets the channel number from the event_mod1 modifier in the event data structure and attempts to obtain ownership of the channel and a valid channel identifier (cid) with irInit(3IRAPI).
The dispositions of the IRE_INPUT, IRE_INPUT_DONE, IRE_WINK and IRE_DISCONNECT events are set with chantest's setEvents() subroutine. The IRE_INPUT and IRE_INPUT_DONE events are simply set to notify chantest when they occur. These events indicate caller input. The IRE_WINK and IRE_DISCONNECT events indicate call termination. Chantest sets them to notify of their occurrence and to interrupt any voice play activity on the channel when they occur.
int setEvents(channel_id cid)
{
/* Enable events */
if ( irSetEvent(cid, IRE_CALL_PROG, IRF_NOTIFY) == IRR_FAIL ||
irSetEvent(cid, IRE_ENERGY, IRF_NOTIFY) == IRR_FAIL ||
irSetEvent(cid, IRE_INPUT, IRF_NOTIFY) == IRR_FAIL ||
irSetEvent(cid, IRE_INPUT_DONE, IRF_NOTIFY) == IRR_FAIL ||
irSetEvent(cid, IRE_WINK, IRF_NOTIFY | IRF_PLAYINTR | IRF_CALLINTR)
== IRR_FAIL ||
irSetEvent(cid, IRE_DISCONNECT, IRF_NOTIFY | IRF_PLAYINTR | IRF_CALLINTR)
== IRR_FAIL ) {
return(-1);
}
return(0);
}
Chantest uses its setTTParams() subroutine to set initial values of four IRAPI caller input parameters. The values of these parameters determine when an IRE_INPUT_DONE event is generated:
int setTTParams(channel_id cid)
{
/* Set up for reading INPUT_LEN digits from input queue */
if ( irSetParam(cid,IRP_INPUT_LEN,INPUT_LEN) == IRR_FAIL ||
irSetParam(cid, IRP_TT_PRETIME, 8000) == IRR_FAIL ||
irSetParam(cid, IRP_TT_INTERTIME, 5000) == IRR_FAIL ||
irSetParamStr(cid, IRP_INPUT_DELIM1, "#") == IRR_FAIL ) {
return(-1);
}
return(0);
}
The IRP_INPUT_LEN parameter specifies the maximum input length (INPUT_LEN is defined as 4 characters). The pre-digit and inter-digit timeout parameters are set to 8000 and 5000 milliseconds (8 and 5 seconds) respectively. The pound sign (#) is set as an input delineator for input shorter than IRP_INPUT_LEN.