- Timestamp:
- Aug 20, 2010, 11:04:39 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ipp-20100621/Ohana/src/opihi/dvo/LoadImages.c
r28723 r28989 1 1 # include "dvoshell.h" 2 3 // XXX: Maybe make this a command line option 4 int dvoUseImageCache = 1; 5 6 static char *lastFilename = NULL; 7 static time_t lastModified = 0; 8 static Image *imageCache = NULL; 9 static off_t cacheNimage = 0; 10 11 static time_t getLastModified(char *filename); 2 12 3 13 Image *LoadImages (off_t *Nimage) { … … 12 22 catdir = GetCATDIR (); 13 23 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 14 41 15 42 gfits_db_init (&db); … … 40 67 if (!image) { 41 68 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); 43 76 } 44 77 return (image); 45 78 } 79 80 static 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 89 void 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.
