merge the formfield patch from ooo-build
[ooovba.git] / sd / source / ui / slidesorter / cache / SlsQueueProcessor.cxx
blob8a5380913c1b056aac085c33bfa48abfc970bcd3
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: SlsQueueProcessor.cxx,v $
10 * $Revision: 1.10 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #include "precompiled_sd.hxx"
33 #include "SlsQueueProcessor.hxx"
34 #include "SlsCacheConfiguration.hxx"
35 #include "SlsRequestQueue.hxx"
36 #include "SlsIdleDetector.hxx"
38 namespace sd { namespace slidesorter { namespace cache {
41 //===== QueueProcessor ======================================================
43 QueueProcessor::QueueProcessor (
44 RequestQueue& rQueue,
45 const ::boost::shared_ptr<BitmapCache>& rpCache,
46 const Size& rPreviewSize,
47 const SharedCacheContext& rpCacheContext)
48 : maMutex(),
49 maTimer(),
50 mnTimeBetweenHighPriorityRequests (10/*ms*/),
51 mnTimeBetweenLowPriorityRequests (100/*ms*/),
52 mnTimeBetweenRequestsWhenNotIdle (1000/*ms*/),
53 maPreviewSize(rPreviewSize),
54 mpCacheContext(rpCacheContext),
55 mrQueue(rQueue),
56 mpCache(rpCache),
57 maBitmapFactory(),
58 mbIsPaused(false)
60 // Look into the configuration if there for overriding values.
61 ::com::sun::star::uno::Any aTimeBetweenReqeusts;
62 aTimeBetweenReqeusts = CacheConfiguration::Instance()->GetValue(
63 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("TimeBetweenHighPriorityRequests")));
64 if (aTimeBetweenReqeusts.has<sal_Int32>())
65 aTimeBetweenReqeusts >>= mnTimeBetweenHighPriorityRequests;
67 aTimeBetweenReqeusts = CacheConfiguration::Instance()->GetValue(
68 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("TimeBetweenLowPriorityRequests")));
69 if (aTimeBetweenReqeusts.has<sal_Int32>())
70 aTimeBetweenReqeusts >>= mnTimeBetweenLowPriorityRequests;
72 aTimeBetweenReqeusts = CacheConfiguration::Instance()->GetValue(
73 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("TimeBetweenRequestsDuringShow")));
74 if (aTimeBetweenReqeusts.has<sal_Int32>())
75 aTimeBetweenReqeusts >>= mnTimeBetweenRequestsWhenNotIdle;
77 maTimer.SetTimeoutHdl (LINK(this,QueueProcessor,ProcessRequestHdl));
78 maTimer.SetTimeout (mnTimeBetweenHighPriorityRequests);
85 QueueProcessor::~QueueProcessor (void)
92 void QueueProcessor::Start (int nPriorityClass)
94 if (mbIsPaused)
95 return;
96 if ( ! maTimer.IsActive())
98 if (nPriorityClass == 0)
99 maTimer.SetTimeout (mnTimeBetweenHighPriorityRequests);
100 else
101 maTimer.SetTimeout (mnTimeBetweenLowPriorityRequests);
102 maTimer.Start();
109 void QueueProcessor::Stop (void)
111 if (maTimer.IsActive())
112 maTimer.Stop();
118 void QueueProcessor::Pause (void)
120 mbIsPaused = true;
126 void QueueProcessor::Resume (void)
128 mbIsPaused = false;
129 if ( ! mrQueue.IsEmpty())
130 Start(mrQueue.GetFrontPriorityClass());
136 void QueueProcessor::Terminate (void)
143 void QueueProcessor::SetPreviewSize (const Size& rPreviewSize)
145 maPreviewSize = rPreviewSize;
151 IMPL_LINK(QueueProcessor, ProcessRequestHdl, Timer*, EMPTYARG)
153 ProcessRequests();
154 return 1;
160 void QueueProcessor::ProcessRequests (void)
162 OSL_ASSERT(mpCacheContext.get()!=NULL);
164 while ( ! mrQueue.IsEmpty() && ! mbIsPaused)
166 if ( ! mpCacheContext->IsIdle())
167 break;
169 CacheKey aKey = NULL;
170 RequestPriorityClass ePriorityClass (NOT_VISIBLE);
172 ::osl::MutexGuard aGuard (mrQueue.GetMutex());
174 if ( ! mrQueue.IsEmpty())
176 // Get the request with the highest priority from the queue.
177 ePriorityClass = mrQueue.GetFrontPriorityClass();
178 aKey = mrQueue.GetFront();
179 mrQueue.PopFront();
183 if (aKey != NULL)
184 ProcessOneRequest(aKey, ePriorityClass);
186 // Requests of lower priority are processed one at a time.
188 ::osl::MutexGuard aGuard (mrQueue.GetMutex());
189 if ( ! mrQueue.IsEmpty())
190 if (mrQueue.GetFrontPriorityClass() > 0)
191 break;
195 // Schedule the processing of the next element(s).
197 ::osl::MutexGuard aGuard (mrQueue.GetMutex());
198 if ( ! mrQueue.IsEmpty())
200 if (bIsShowingFullScreenShow)
201 Start(mnTimeBetweenRequestsWhenNotIdle);
202 else
204 Start(mrQueue.GetFrontPriorityClass());
211 void QueueProcessor::ProcessOneRequest (
212 CacheKey aKey,
213 const RequestPriorityClass ePriorityClass)
217 ::osl::MutexGuard aGuard (maMutex);
219 // Create a new preview bitmap and store it in the cache.
220 if (mpCache.get() != NULL
221 && mpCacheContext.get() != NULL)
223 const SdPage* pSdPage = dynamic_cast<const SdPage*>(mpCacheContext->GetPage(aKey));
224 if (pSdPage != NULL)
226 const ::boost::shared_ptr<BitmapEx> pPreview (
227 maBitmapFactory.CreateBitmap(*pSdPage, maPreviewSize));
228 mpCache->SetBitmap (
229 pSdPage,
230 pPreview,
231 ePriorityClass!=NOT_VISIBLE);
233 // Initiate a repaint of the new preview.
234 mpCacheContext->NotifyPreviewCreation(aKey, pPreview);
238 catch (::com::sun::star::uno::RuntimeException aException)
240 (void) aException;
241 OSL_ASSERT("RuntimeException caught in QueueProcessor");
243 catch (::com::sun::star::uno::Exception aException)
245 (void) aException;
246 OSL_ASSERT("Exception caught in QueueProcessor");
253 void QueueProcessor::RemoveRequest (CacheKey aKey)
255 (void)aKey;
256 // See the method declaration above for an explanation why this makes sense.
257 ::osl::MutexGuard aGuard (maMutex);
263 void QueueProcessor::SetBitmapCache (
264 const ::boost::shared_ptr<BitmapCache>& rpCache)
266 mpCache = rpCache;
270 } } } // end of namespace ::sd::slidesorter::cache