Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #include "SlsQueueProcessor.hxx"
31 : : #include "SlsCacheConfiguration.hxx"
32 : : #include "SlsRequestQueue.hxx"
33 : :
34 : : namespace sd { namespace slidesorter { namespace cache {
35 : :
36 : :
37 : : //===== QueueProcessor ======================================================
38 : :
39 : 126 : QueueProcessor::QueueProcessor (
40 : : RequestQueue& rQueue,
41 : : const ::boost::shared_ptr<BitmapCache>& rpCache,
42 : : const Size& rPreviewSize,
43 : : const bool bDoSuperSampling,
44 : : const SharedCacheContext& rpCacheContext)
45 : : : maMutex(),
46 : : maTimer(),
47 : : mnTimeBetweenHighPriorityRequests (10/*ms*/),
48 : : mnTimeBetweenLowPriorityRequests (100/*ms*/),
49 : : mnTimeBetweenRequestsWhenNotIdle (1000/*ms*/),
50 : : maPreviewSize(rPreviewSize),
51 : : mbDoSuperSampling(bDoSuperSampling),
52 : : mpCacheContext(rpCacheContext),
53 : : mrQueue(rQueue),
54 : : mpCache(rpCache),
55 : : maBitmapFactory(),
56 [ + - ][ + - ]: 126 : mbIsPaused(false)
[ + - ][ + - ]
57 : : {
58 : : // Look into the configuration if there for overriding values.
59 : 126 : ::com::sun::star::uno::Any aTimeBetweenReqeusts;
60 [ + - ][ + - ]: 126 : aTimeBetweenReqeusts = CacheConfiguration::Instance()->GetValue("TimeBetweenHighPriorityRequests");
[ + - ]
61 [ - + ][ + - ]: 126 : if (aTimeBetweenReqeusts.has<sal_Int32>())
62 : 0 : aTimeBetweenReqeusts >>= mnTimeBetweenHighPriorityRequests;
63 : :
64 [ + - ][ + - ]: 126 : aTimeBetweenReqeusts = CacheConfiguration::Instance()->GetValue("TimeBetweenLowPriorityRequests");
[ + - ]
65 [ - + ][ + - ]: 126 : if (aTimeBetweenReqeusts.has<sal_Int32>())
66 : 0 : aTimeBetweenReqeusts >>= mnTimeBetweenLowPriorityRequests;
67 : :
68 [ + - ][ + - ]: 126 : aTimeBetweenReqeusts = CacheConfiguration::Instance()->GetValue("TimeBetweenRequestsDuringShow");
[ + - ]
69 [ - + ][ + - ]: 126 : if (aTimeBetweenReqeusts.has<sal_Int32>())
70 : 0 : aTimeBetweenReqeusts >>= mnTimeBetweenRequestsWhenNotIdle;
71 : :
72 [ + - ]: 126 : maTimer.SetTimeoutHdl (LINK(this,QueueProcessor,ProcessRequestHdl));
73 [ + - ]: 126 : maTimer.SetTimeout (mnTimeBetweenHighPriorityRequests);
74 : 126 : }
75 : :
76 : :
77 : :
78 : :
79 : :
80 [ + - ][ + - ]: 126 : QueueProcessor::~QueueProcessor (void)
[ + - ][ + - ]
81 : : {
82 [ - + ]: 252 : }
83 : :
84 : :
85 : :
86 : :
87 : 1285 : void QueueProcessor::Start (int nPriorityClass)
88 : : {
89 [ - + ]: 1285 : if (mbIsPaused)
90 : 1285 : return;
91 [ + + ]: 1285 : if ( ! maTimer.IsActive())
92 : : {
93 [ + + ]: 285 : if (nPriorityClass == 0)
94 : 133 : maTimer.SetTimeout (mnTimeBetweenHighPriorityRequests);
95 : : else
96 : 152 : maTimer.SetTimeout (mnTimeBetweenLowPriorityRequests);
97 : 285 : maTimer.Start();
98 : : }
99 : : }
100 : :
101 : :
102 : :
103 : :
104 : 126 : void QueueProcessor::Stop (void)
105 : : {
106 [ + + ]: 126 : if (maTimer.IsActive())
107 : 15 : maTimer.Stop();
108 : 126 : }
109 : :
110 : :
111 : :
112 : :
113 : 0 : void QueueProcessor::Pause (void)
114 : : {
115 : 0 : mbIsPaused = true;
116 : 0 : }
117 : :
118 : :
119 : :
120 : :
121 : 0 : void QueueProcessor::Resume (void)
122 : : {
123 : 0 : mbIsPaused = false;
124 [ # # ]: 0 : if ( ! mrQueue.IsEmpty())
125 : 0 : Start(mrQueue.GetFrontPriorityClass());
126 : 0 : }
127 : :
128 : :
129 : :
130 : :
131 : 126 : void QueueProcessor::Terminate (void)
132 : : {
133 : 126 : }
134 : :
135 : :
136 : :
137 : :
138 : 10 : void QueueProcessor::SetPreviewSize (
139 : : const Size& rPreviewSize,
140 : : const bool bDoSuperSampling)
141 : : {
142 : 10 : maPreviewSize = rPreviewSize;
143 : 10 : mbDoSuperSampling = bDoSuperSampling;
144 : 10 : }
145 : :
146 : :
147 : :
148 : :
149 : 270 : IMPL_LINK_NOARG(QueueProcessor, ProcessRequestHdl)
150 : : {
151 : 270 : ProcessRequests();
152 : 270 : return 1;
153 : : }
154 : :
155 : :
156 : :
157 : :
158 : 270 : void QueueProcessor::ProcessRequests (void)
159 : : {
160 : : OSL_ASSERT(mpCacheContext.get()!=NULL);
161 : :
162 : : // Never process more than one request at a time in order to prevent the
163 : : // lock up of the edit view.
164 [ + - ]: 540 : if ( ! mrQueue.IsEmpty()
[ + - + - ]
[ + - ]
165 : 270 : && ! mbIsPaused
166 : 270 : && mpCacheContext->IsIdle())
167 : : {
168 : 270 : CacheKey aKey = NULL;
169 : 270 : RequestPriorityClass ePriorityClass (NOT_VISIBLE);
170 : : {
171 [ + - ][ + - ]: 270 : ::osl::MutexGuard aGuard (mrQueue.GetMutex());
172 : :
173 [ + - ][ + - ]: 270 : if ( ! mrQueue.IsEmpty())
174 : : {
175 : : // Get the request with the highest priority from the queue.
176 [ + - ]: 270 : ePriorityClass = mrQueue.GetFrontPriorityClass();
177 [ + - ]: 270 : aKey = mrQueue.GetFront();
178 [ + - ]: 270 : mrQueue.PopFront();
179 [ + - ]: 270 : }
180 : : }
181 : :
182 [ + - ]: 270 : if (aKey != NULL)
183 : 270 : ProcessOneRequest(aKey, ePriorityClass);
184 : : }
185 : :
186 : : // Schedule the processing of the next element(s).
187 : : {
188 [ + - ][ + - ]: 270 : ::osl::MutexGuard aGuard (mrQueue.GetMutex());
189 [ + - ][ + + ]: 270 : if ( ! mrQueue.IsEmpty())
190 [ + - ][ + - ]: 270 : Start(mrQueue.GetFrontPriorityClass());
[ + - ]
191 : : }
192 : 270 : }
193 : :
194 : :
195 : :
196 : :
197 : 270 : void QueueProcessor::ProcessOneRequest (
198 : : CacheKey aKey,
199 : : const RequestPriorityClass ePriorityClass)
200 : : {
201 : : try
202 : : {
203 [ + - ]: 270 : ::osl::MutexGuard aGuard (maMutex);
204 : :
205 : : // Create a new preview bitmap and store it in the cache.
206 [ + - + - ]: 540 : if (mpCache.get() != NULL
[ + - ]
207 : 270 : && mpCacheContext.get() != NULL)
208 : : {
209 [ + - ][ - + ]: 270 : const SdPage* pSdPage = dynamic_cast<const SdPage*>(mpCacheContext->GetPage(aKey));
210 [ + - ]: 270 : if (pSdPage != NULL)
211 : : {
212 : : const Bitmap aPreview (
213 [ + - ]: 270 : maBitmapFactory.CreateBitmap(*pSdPage, maPreviewSize, mbDoSuperSampling));
214 [ + - ]: 270 : mpCache->SetBitmap (pSdPage, aPreview, ePriorityClass!=NOT_VISIBLE);
215 : :
216 : : // Initiate a repaint of the new preview.
217 [ + - ][ + - ]: 270 : mpCacheContext->NotifyPreviewCreation(aKey, aPreview);
218 : : }
219 [ + - ]: 270 : }
[ # # # ]
220 : : }
221 : 0 : catch (::com::sun::star::uno::RuntimeException &)
222 : : {
223 : : OSL_FAIL("RuntimeException caught in QueueProcessor");
224 : : }
225 : 0 : catch (::com::sun::star::uno::Exception &)
226 : : {
227 : : OSL_FAIL("Exception caught in QueueProcessor");
228 : : }
229 : 270 : }
230 : :
231 : 10 : void QueueProcessor::SetBitmapCache (
232 : : const ::boost::shared_ptr<BitmapCache>& rpCache)
233 : : {
234 : 10 : mpCache = rpCache;
235 : 10 : }
236 : :
237 : :
238 : : } } } // end of namespace ::sd::slidesorter::cache
239 : :
240 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|