00001 #ifndef CACHE_H 00002 #define CACHE_H 00003 00004 // CICache for quickly reading data that is hard to decompress yet used 00005 // over and over. 00006 00007 // Actual caching is done in the File object 00008 // the CICache keeps files open while rendering. 00009 00010 // Since the CICache outlives EDLs it must copy every parameter given to it. 00011 00012 // Files given as arguments must outlive the cache. 00013 00014 #include "arraylist.h" 00015 #include "asset.inc" 00016 #include "cache.inc" 00017 #include "condition.inc" 00018 #include "edl.inc" 00019 #include "file.inc" 00020 #include "garbage.h" 00021 #include "linklist.h" 00022 #include "mutex.inc" 00023 #include "pluginserver.inc" 00024 #include "preferences.inc" 00025 00026 #include <stdint.h> 00027 00028 class CICacheItem : public ListItem<CICacheItem>, public GarbageObject 00029 { 00030 public: 00031 CICacheItem(CICache *cache, EDL *edl, Asset *asset); 00032 CICacheItem(); 00033 ~CICacheItem(); 00034 00035 File *file; 00036 // Number of last get or put operation involving this object. 00037 int age; 00038 Asset *asset; // Copy of asset. CICache should outlive EDLs. 00039 Condition *item_lock; 00040 int checked_out; 00041 private: 00042 CICache *cache; 00043 }; 00044 00045 class CICache : public List<CICacheItem> 00046 { 00047 public: 00048 CICache(Preferences *preferences, 00049 ArrayList<PluginServer*> *plugindb); 00050 ~CICache(); 00051 00052 friend class CICacheItem; 00053 00054 // Enter a new file into the cache which is already open. 00055 // If the file doesn't exist return the arguments. 00056 // If the file exists delete the arguments and return the file which exists. 00057 // void update(File* &file); 00058 // void set_edl(EDL *edl); 00059 00060 // open it, lock it and add it to the cache if it isn't here already 00061 // If it's already checked out, the value of block causes it to wait 00062 // until it's checked in. 00063 File* check_out(Asset *asset, EDL *edl, int block = 1); 00064 00065 // unlock a file from the cache 00066 int check_in(Asset *asset); 00067 00068 // delete an entry from the cache 00069 // before deleting an asset, starting a new project or something 00070 int delete_entry(Asset *asset); 00071 int delete_entry(char *path); 00072 // Remove all entries from the cache. 00073 void remove_all(); 00074 00075 // Get ID of oldest member. 00076 // Called by MWindow::age_caches. 00077 int get_oldest(); 00078 int64_t get_memory_usage(int use_lock); 00079 00080 // Called by age() and MWindow::age_caches 00081 // returns 1 if nothing was available to delete 00082 // 0 if successful 00083 int delete_oldest(); 00084 00085 // Called by check_in() and modules. 00086 // deletes oldest assets until under the memory limit 00087 int age(); 00088 00089 00090 int dump(); 00091 00092 ArrayList<PluginServer*> *plugindb; 00093 00094 private: 00095 00096 // for deleting items 00097 int lock_all(); 00098 int unlock_all(); 00099 00100 // to prevent one from checking the same asset out before it's checked in 00101 // yet without blocking the asset trying to get checked in 00102 // use a seperate mutex for checkouts and checkins 00103 Mutex *total_lock; 00104 Condition *check_out_lock; 00105 // Copy of EDL 00106 EDL *edl; 00107 Preferences *preferences; 00108 }; 00109 00110 00111 00112 00113 00114 00115 00116 00117 #endif
1.5.5