IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Aug 20, 2010, 11:04:39 AM (16 years ago)
Author:
eugene
Message:

updates from trunk

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ipp-20100621/Ohana/src/opihi/dvo/LoadImages.c

    r28723 r28989  
    11# include "dvoshell.h"
     2
     3// XXX: Maybe make this a command line option
     4int dvoUseImageCache = 1;
     5
     6static char *lastFilename = NULL;
     7static time_t lastModified = 0;
     8static Image *imageCache = NULL;
     9static off_t cacheNimage = 0;
     10
     11static time_t getLastModified(char *filename);
    212
    313Image *LoadImages (off_t *Nimage) {
     
    1222  catdir = GetCATDIR ();
    1323  sprintf (filename, "%s/Images.dat", catdir);
     24
     25  if (lastFilename) {
     26    if (dvoUseImageCache && !strcmp(lastFilename, filename)) {
     27      // Make sure the file hasn't changed since we loaded it
     28      if (getLastModified(filename) == lastModified) {
     29        *Nimage = cacheNimage;
     30        return  imageCache;
     31      }
     32    }
     33    free(lastFilename);
     34    lastFilename = NULL;
     35    free(imageCache);
     36    imageCache = NULL;
     37    cacheNimage = 0;
     38    lastModified = 0;
     39  }
     40
    1441
    1542  gfits_db_init (&db);
     
    4067  if (!image) {
    4168    fprintf (stderr, "ERROR: failed to read images\n");
    42     exit (2);
     69    return (NULL);
     70  }
     71  if (dvoUseImageCache && image) {
     72    cacheNimage = *Nimage;
     73    imageCache = image;
     74    lastFilename = strdup(filename);
     75    lastModified = getLastModified(filename);
    4376  }
    4477  return (image);
    4578}
     79
     80static time_t getLastModified(char *filename) {
     81  struct stat statbuf;
     82  if (!stat(filename, &statbuf)) {
     83    return statbuf.st_mtime;
     84  } else {
     85    return 0;
     86  }
     87}
     88
     89void FreeImages(Image *images) {
     90  if (!dvoUseImageCache && (images != NULL)) {
     91    free(images);
     92  } else {
     93    // defer free until next LoadImages with a different or modified Images.dat
     94  }
     95}
     96
Note: See TracChangeset for help on using the changeset viewer.