add Autosave continuous backups by Andras Reuss and Andrew-R
[goodguy/cinelerra.git] / cinelerra-5.1 / cinelerra / cachebase.h
1
2 /*
3  * CINELERRA
4  * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  *
20  */
21
22 #ifndef CACHEBASE_H
23 #define CACHEBASE_H
24
25
26 #include "asset.inc"
27 #include "linklist.h"
28 #include "mutex.inc"
29 #include <stdint.h>
30
31 // Store rendered elements from files but not the files.
32 // Drawing caches must be separate from file caches to avoid
33 // delaying other file accesses for the drawing routines.
34
35
36 class CacheItemBase : public ListItem<CacheItemBase>
37 {
38 public:
39         CacheItemBase();
40         virtual ~CacheItemBase();
41
42         virtual int get_size();
43
44 // source_id - supplied by user if the cache is not part of a file.
45 // Used for fast accesses.
46         int source_id;
47 // path is needed since the item may need to be deleted based on file.
48 // Used for deletion.
49         char *path;
50 // Number of last get or put operation involving this object.
51         int age;
52 // Starting point of item in asset's native rate.
53         int64_t position;
54 };
55
56
57
58 class CacheBase : public List<CacheItemBase>
59 {
60 public:
61         CacheBase();
62         virtual ~CacheBase();
63
64         void age_cache(int64_t max_items);
65         int get_age();
66         int cache_items() { return total_items; }
67         void remove_all();
68
69 // Insert item in list in ascending position order.
70         void put_item(CacheItemBase *item);
71 // Get first item from list with matching position or 0 if none found.
72         CacheItemBase* get_item(int64_t position);
73 // Delete item.
74         void del_item(CacheItemBase *item);
75         int delete_item(CacheItemBase *item);
76 // Remove all items with the same source_id or matching path if set
77         void remove_item(int source_id, char *path);
78         void remove_item(Indexable *idxbl);
79         void remove_asset(Asset *asset);
80 // Called when done with the item returned by get_.
81 // Ignore if item was 0.
82         void unlock();
83 // Delete oldest item.  
84 // Return number of bytes freed if successful.  Return 0 if nothing to delete.
85         int delete_oldest();
86 // Calculate current size of cache in bytes
87         int64_t get_memory_usage();
88
89         int total_items;
90         Mutex *lock;
91 // Current position of search
92         CacheItemBase *current_item;
93 };
94
95
96
97 #endif