1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: SlsQueueProcessor.cxx,v $
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 (
45 const ::boost::shared_ptr
<BitmapCache
>& rpCache
,
46 const Size
& rPreviewSize
,
47 const SharedCacheContext
& rpCacheContext
)
50 mnTimeBetweenHighPriorityRequests (10/*ms*/),
51 mnTimeBetweenLowPriorityRequests (100/*ms*/),
52 mnTimeBetweenRequestsWhenNotIdle (1000/*ms*/),
53 maPreviewSize(rPreviewSize
),
54 mpCacheContext(rpCacheContext
),
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
)
96 if ( ! maTimer
.IsActive())
98 if (nPriorityClass
== 0)
99 maTimer
.SetTimeout (mnTimeBetweenHighPriorityRequests
);
101 maTimer
.SetTimeout (mnTimeBetweenLowPriorityRequests
);
109 void QueueProcessor::Stop (void)
111 if (maTimer
.IsActive())
118 void QueueProcessor::Pause (void)
126 void QueueProcessor::Resume (void)
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
)
160 void QueueProcessor::ProcessRequests (void)
162 OSL_ASSERT(mpCacheContext
.get()!=NULL
);
164 while ( ! mrQueue
.IsEmpty() && ! mbIsPaused
)
166 if ( ! mpCacheContext
->IsIdle())
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();
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)
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);
204 Start(mrQueue
.GetFrontPriorityClass());
211 void QueueProcessor::ProcessOneRequest (
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
));
226 const ::boost::shared_ptr
<BitmapEx
> pPreview (
227 maBitmapFactory
.CreateBitmap(*pSdPage
, maPreviewSize
));
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
)
241 OSL_ASSERT("RuntimeException caught in QueueProcessor");
243 catch (::com::sun::star::uno::Exception aException
)
246 OSL_ASSERT("Exception caught in QueueProcessor");
253 void QueueProcessor::RemoveRequest (CacheKey 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
)
270 } } } // end of namespace ::sd::slidesorter::cache