The following tasks should be performed by an IRAPI program when execution starts:
For example, the chantest.c application uses the irRegister(3IRAPI) function as follows:
if ((qid=irRegister("chantest")) < 0) {
irPError ("Error on irRegister");
exit (1);
}
As chantest.c is a multi-channel application, it uses irNumChans(3IRAPI) to obtain the number of channels in the system and allocates a CHLDATA data structure for each channel. By allocating one data structure for every channel in the system, it can be assigned to handle any or all channels simultaneously:
if (initData(irNumChans(IRD_REAL)) < 0) {
printf("Initialization failed\\\n");
exit(1);
}
The following code shows the chantest's initData() routine:
/* Global variables */
struct CHLDATA {
int State;
int RetryCount;
int PlayDone;
ir_event_t InputDoneEvent;
} *Chl;
int initData(int nchans)
{
if(nchans <= 0) return(-1);
if((Chl = (struct CHLDATA *)calloc(nchans,
sizeof(struct CHLDATA))) == 0)
{
return(-1);
}
return(0);
}