/* * Copyright 2010, Axel Dörfler, axeld@pinc-software.de. * Distributed under the terms of the MIT License. */ #ifndef IMAGE_CACHE_H #define IMAGE_CACHE_H #include #include #include #include #include #include #include #include class BBitmap; class BMessage; class BMessenger; struct QueueEntry; enum { kMsgImageCacheImageLoaded = 'icIL', kMsgImageCacheProgressUpdate = 'icPU' }; class BitmapOwner : public BReferenceable { public: BitmapOwner(BBitmap* bitmap); virtual ~BitmapOwner(); private: BBitmap* fBitmap; }; struct CacheEntry : DoublyLinkedListLinkImpl { entry_ref ref; int32 page; int32 pageCount; BBitmap* bitmap; BitmapOwner* bitmapOwner; BString type; BString mimeType; }; class ImageCache { public: ImageCache(); virtual ~ImageCache(); status_t RetrieveImage(const entry_ref& ref, int32 page = 1, const BMessenger* target = NULL); void Stop(); private: static status_t _QueueWorkerThread(void* self); status_t _RetrieveImage(QueueEntry* entry, CacheEntry** _entry); void _NotifyListeners(CacheEntry* entry, QueueEntry* queueEntry); void _NotifyTarget(CacheEntry* entry, const BMessenger* target); void _BuildNotification(CacheEntry* entry, BMessage& message); private: typedef std::pair ImageSelector; typedef std::map CacheMap; typedef std::map QueueMap; typedef std::deque QueueDeque; typedef DoublyLinkedList CacheList; BLocker fLocker; CacheMap fCacheMap; CacheList fCacheEntriesByAge; QueueMap fQueueMap; QueueDeque fQueue; int32 fThreadCount; int32 fMaxThreadCount; uint64 fBytes; uint64 fMaxBytes; size_t fMaxEntries; }; #endif // IMAGE_CACHE_H