next up previous contents
Next: Notes Up: pil Previous: Notes   Contents


Calling PIL library functions from C/C++

Applications can use PIL services in one of 2 different modes. The first one ISDC_SINGLE_MODE is the simplest one. In this mode application simply includes pil.h header file, calls PILInit, plays with parameters by calling PILGetXxx/PILPutXxx functions and finally shuts down PIL library by calling PILClose. The skeleton code is given below.

/* this is skeleton code for simple PIL aware applications, this
   is not a working code.
*/

#include <stdio.h>
#include <pil.h>

int main(int argc, char **argv)
{ int r;
  float	fv[5];

r = PILInit(argc, argv);

if (r < 0)
  {
    printf("PILInit failed : %s\n", PIL_err_handler(r));
    return(10);
  }

r = PILGetBool("boolParName1", &intptr);
r = PILGetReal("RealParName34", &doubleptr);
r = PILGetReal4Vector("real4vecname", 5, &(fv[0]));

    /* .... application code follows .... */

PILClose(PIL_OK);
exit(0);
}

The second mode, called ISDC_SERVER_MODE allows for multiple rereads of parameter file. Using this method application can exchange data with other processes via parameter file (provided other processes use locks to assure exclusive access during read/write operation). One example of code is as follows :

/* this is skeleton code for PIL aware applications running in server mode,
   this is not a working code.
*/

#include <stdio.h>
#include <pil.h>

int main(int argc, char **argv)
{

PILInit(argc, argv);

if (ISDC_SERVER_MODE != PILRunMode)
  exit(-1);  /* error - not in server mode - check parameter file */

for (;;)
 {
   PILReloadParameters();
   PILGetInt("IntParName", &intvar);

   /* place for loop code here
        ...
   */

   PILPutReal("RealParName", 4.567);
   PILFlushParameters();
   if (exit_condition) break;
 }

PILClose(status);
return(PIL_OK);
}

After initial call to PILInit application jumps into main loop. In each iteration it rereads parameters from file (there is no need to call PILReloadParameters during first iteration), Based on new values of just read-in parameters (which might be modified by another process) application may decide to exit from loop or continue. If it decides to continue then after executing application specific loop code it calls PILFlushParameters to signal other process that it is done with current iteration. Algorithm described above is very simple, and the real applications are usually more complicated.

As mentioned earlier, applications written for ISDC should not use PILInit/PILClose directly. Instead they should use CommonInit/CommonExit functions from ISDC's Common Library.



Subsections
next up previous contents
Next: Notes Up: pil Previous: Notes   Contents
Bryan Irby 2004-10-05