1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef SD_SLIDESORTER_QUEUE_PROCESSOR_HXX
25 #define SD_SLIDESORTER_QUEUE_PROCESSOR_HXX
26 
27 #include "cache/SlsPageCache.hxx"
28 #include "SlsRequestPriorityClass.hxx"
29 #include "SlsBitmapFactory.hxx"
30 #include "view/SlideSorterView.hxx"
31 #include "tools/IdleDetection.hxx"
32 #include "SlsBitmapCache.hxx"
33 #include "sdpage.hxx"
34 #include "Window.hxx"
35 
36 #include <svx/svdpagv.hxx>
37 #include <vcl/svapp.hxx>
38 #include <vcl/timer.hxx>
39 #include <boost/function.hpp>
40 
41 
42 namespace sd { namespace slidesorter { namespace view {
43 class SlideSorterView;
44 } } }
45 
46 
47 
48 namespace sd { namespace slidesorter { namespace cache {
49 
50 class BitmapCache;
51 class RequestQueue;
52 
53 
54 
55 /** This queue processor is timer based, i.e. when an entry is added to the
56     queue and the processor is started with Start() in the base class a
57     timer is started that eventually calls ProcessRequest().  This is
58     repeated until the queue is empty or Stop() is called.
59 */
60 class QueueProcessor
61 {
62 public:
63     typedef ::boost::function<bool()> IdleDetectionCallback;
64     QueueProcessor (
65         RequestQueue& rQueue,
66         const ::boost::shared_ptr<BitmapCache>& rpCache,
67         const Size& rPreviewSize,
68         const bool bDoSuperSampling,
69         const SharedCacheContext& rpCacheContext);
70 	virtual ~QueueProcessor();
71 
72     /** Start the processor.  This implementation is timer based and waits
73         an defined amount of time that depends on the given argument before
74         the next entry in the queue is processed.
75         @param nPriorityClass
76             A priority class of 0 tells the processor that a high priority
77             request is waiting in the queue.  The time to wait is thus
78             shorter then that for a low priority request (denoted by a value
79             of 1.)  When the timer is already running it is not modified.
80     */
81     void Start (int nPriorityClass = 0);
82     void Stop (void);
83     void Pause (void);
84     void Resume (void);
85 
86     void Terminate (void);
87 
88     void SetPreviewSize (
89         const Size& rSize,
90         const bool bDoSuperSampling);
91 
92     /** As we can not really terminate the rendering of a preview bitmap for
93         a request in midair this method acts more like a semaphor.  It
94         returns only when it is save for the caller to delete the request.
95         For this to work it is important to remove the request from the
96         queue before calling this method.
97     */
98     void RemoveRequest (CacheKey aKey);
99 
100     /** Use this method when the page cache is (maybe) using a different
101         BitmapCache.  This is usually necessary after calling
102         PageCacheManager::ChangeSize().
103     */
104     void SetBitmapCache (const ::boost::shared_ptr<BitmapCache>& rpCache);
105 
106 private:
107     /** This mutex is used to guard the queue processor.  Be careful not to
108         mix its use with that of the solar mutex.
109     */
110     ::osl::Mutex maMutex;
111 
112     Timer maTimer;
113     DECL_LINK(ProcessRequestHdl, Timer*);
114     sal_uInt32 mnTimeBetweenHighPriorityRequests;
115     sal_uInt32 mnTimeBetweenLowPriorityRequests;
116     sal_uInt32 mnTimeBetweenRequestsWhenNotIdle;
117     Size maPreviewSize;
118     bool mbDoSuperSampling;
119     SharedCacheContext mpCacheContext;
120     RequestQueue& mrQueue;
121     ::boost::shared_ptr<BitmapCache> mpCache;
122     BitmapFactory maBitmapFactory;
123     bool mbIsPaused;
124 
125     void ProcessRequests (void);
126     void ProcessOneRequest (
127         CacheKey aKey,
128         const RequestPriorityClass ePriorityClass);
129 };
130 
131 
132 
133 
134 } } } // end of namespace ::sd::slidesorter::cache
135 
136 #endif
137