Changeset 28958 for trunk/Ohana/src/opihi/dvo/LoadImages.c
- Timestamp:
- Aug 18, 2010, 7:38:20 PM (16 years ago)
- File:
-
- 1 edited
-
trunk/Ohana/src/opihi/dvo/LoadImages.c (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana/src/opihi/dvo/LoadImages.c
r27435 r28958 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); … … 38 65 39 66 image = gfits_table_get_Image (&db.ftable, Nimage, &db.swapped); 67 if (dvoUseImageCache && image) { 68 cacheNimage = *Nimage; 69 imageCache = image; 70 lastFilename = strdup(filename); 71 lastModified = getLastModified(filename); 72 } 73 40 74 return (image); 41 75 } 76 77 static time_t getLastModified(char *filename) { 78 struct stat statbuf; 79 if (!stat(filename, &statbuf)) { 80 return statbuf.st_mtime; 81 } else { 82 return 0; 83 } 84 } 85 86 void FreeImages(Image *images) { 87 if (!dvoUseImageCache && (images != NULL)) { 88 free(images); 89 } else { 90 // defer free until next LoadImages with a different or modified Images.dat 91 } 92 } 93
Note:
See TracChangeset
for help on using the changeset viewer.
