]> git.lyx.org Git - lyx.git/blob - src/graphics/LoaderQueue.h
Rename files in src/support, step one.
[lyx.git] / src / graphics / LoaderQueue.h
1 // -*- C++ -*-
2 /**
3  * \file LoaderQueue.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Alfredo Braunstein
8  *
9  * Full author contact details are available in file CREDITS.
10  *
11  * This implements a threaded service queue which loads images on background.
12  * In order to request an image loading you call touch() with the pointer to
13  * the cached image. Then it will try to satisfy the request as soon as
14  * posible (that's it: after finishing an eventual loading on progress)
15  * touch() returns inmediately, in order not tu disrupt the flow of the main
16  * thread.
17  * The service thread is the method loadNext(). It's actually not a thread,
18  * but implemented with a timer that comes back every x msec.
19  */
20
21 #ifndef LOADERQUEUE_H
22 #define LOADERQUEUE_H
23
24 #include "GraphicsCache.h"
25 #include "frontends/Timeout.h"
26
27 #include <set>
28 #include <queue>
29
30 namespace lyx {
31 namespace graphics {
32
33 class LoaderQueue {
34 public:
35         /// Use this to request that the item is loaded.
36         void touch(Cache::ItemPtr const & item);
37         /// Query whether the clock is ticking.
38         bool running() const;
39         ///get the and only instance of the class
40         static LoaderQueue & get();
41         /** Adjusts the queue priority:
42          *  numimages is the number of images loaded in a particular call
43          *  from the timer.
44          *  millisecs is the time interval between calls.
45          *  Higher numimages, lower millisecs means higher priority.
46          */
47         static void setPriority(int numimages , int millisecs);
48 private:
49         /// This class is a singleton class... use LoaderQueue::get() instead
50         LoaderQueue();
51         /// The in-progress loading queue (elements are unique here).
52         std::list<Cache::ItemPtr> cache_queue_;
53         /// Used to make the insertion of new elements faster.
54         std::set<Cache::ItemPtr> cache_set_;
55         /// Newly touched elements go here. loadNext moves them to cache_queue_
56         std::queue<Cache::ItemPtr> bucket_;
57         ///
58         Timeout timer;
59         ///
60         bool running_;
61         ///
62         static int s_numimages_ ;
63         ///
64         static int s_millisecs_ ;
65
66         /** This is the 'threaded' method, that does the loading in the
67          *  background.
68          */
69         void loadNext();
70         ///
71         void startLoader();
72         ///
73         void stopLoader();
74 };
75
76 } // namespace graphics
77 } // namespace lyx
78
79 #endif // LOADERQUEUE_H