repository_infos: Enable automatic updates on the main Haiku repostiory.
[haiku.git] / src / apps / showimage / ImageCache.h
blob000cb32e4e6e7a7bd074bd66e2158a7e2b511180
1 /*
2 * Copyright 2010, Axel Dörfler, axeld@pinc-software.de.
3 * Distributed under the terms of the MIT License.
4 */
5 #ifndef IMAGE_CACHE_H
6 #define IMAGE_CACHE_H
9 #include <deque>
10 #include <map>
11 #include <set>
13 #include <Entry.h>
14 #include <Locker.h>
15 #include <String.h>
17 #include <kernel/util/DoublyLinkedList.h>
18 #include <Referenceable.h>
21 class BBitmap;
22 class BMessage;
23 class BMessenger;
24 struct QueueEntry;
27 enum {
28 kMsgImageCacheImageLoaded = 'icIL',
29 kMsgImageCacheProgressUpdate = 'icPU'
33 class BitmapOwner : public BReferenceable {
34 public:
35 BitmapOwner(BBitmap* bitmap);
36 virtual ~BitmapOwner();
38 private:
39 BBitmap* fBitmap;
43 struct CacheEntry : DoublyLinkedListLinkImpl<CacheEntry> {
44 entry_ref ref;
45 int32 page;
46 int32 pageCount;
47 BBitmap* bitmap;
48 BitmapOwner* bitmapOwner;
49 BString type;
50 BString mimeType;
54 class ImageCache {
55 public:
56 ImageCache();
57 virtual ~ImageCache();
58 status_t RetrieveImage(const entry_ref& ref,
59 int32 page = 1,
60 const BMessenger* target = NULL);
61 void Stop();
63 private:
65 static status_t _QueueWorkerThread(void* self);
67 status_t _RetrieveImage(QueueEntry* entry,
68 CacheEntry** _entry);
69 void _NotifyListeners(CacheEntry* entry,
70 QueueEntry* queueEntry);
71 void _NotifyTarget(CacheEntry* entry,
72 const BMessenger* target);
73 void _BuildNotification(CacheEntry* entry,
74 BMessage& message);
76 private:
77 typedef std::pair<entry_ref, int32> ImageSelector;
78 typedef std::map<ImageSelector, CacheEntry*> CacheMap;
79 typedef std::map<ImageSelector, QueueEntry*> QueueMap;
80 typedef std::deque<QueueEntry*> QueueDeque;
81 typedef DoublyLinkedList<CacheEntry> CacheList;
83 BLocker fLocker;
84 CacheMap fCacheMap;
85 CacheList fCacheEntriesByAge;
86 QueueMap fQueueMap;
87 QueueDeque fQueue;
88 int32 fThreadCount;
89 int32 fMaxThreadCount;
90 uint64 fBytes;
91 uint64 fMaxBytes;
92 size_t fMaxEntries;
96 #endif // IMAGE_CACHE_H