LCOV - code coverage report
Current view: top level - libreoffice/sd/source/ui/slidesorter/cache - SlsQueueProcessor.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 80 0.0 %
Date: 2012-12-27 Functions: 0 14 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : 
      21             : #include "SlsQueueProcessor.hxx"
      22             : #include "SlsCacheConfiguration.hxx"
      23             : #include "SlsRequestQueue.hxx"
      24             : 
      25             : namespace sd { namespace slidesorter { namespace cache {
      26             : 
      27             : 
      28             : //=====  QueueProcessor  ======================================================
      29             : 
      30           0 : QueueProcessor::QueueProcessor (
      31             :     RequestQueue& rQueue,
      32             :     const ::boost::shared_ptr<BitmapCache>& rpCache,
      33             :     const Size& rPreviewSize,
      34             :     const bool bDoSuperSampling,
      35             :     const SharedCacheContext& rpCacheContext)
      36             :     : maMutex(),
      37             :       maTimer(),
      38             :       mnTimeBetweenHighPriorityRequests (10/*ms*/),
      39             :       mnTimeBetweenLowPriorityRequests (100/*ms*/),
      40             :       mnTimeBetweenRequestsWhenNotIdle (1000/*ms*/),
      41             :       maPreviewSize(rPreviewSize),
      42             :       mbDoSuperSampling(bDoSuperSampling),
      43             :       mpCacheContext(rpCacheContext),
      44             :       mrQueue(rQueue),
      45             :       mpCache(rpCache),
      46             :       maBitmapFactory(),
      47           0 :       mbIsPaused(false)
      48             : {
      49             :     // Look into the configuration if there for overriding values.
      50           0 :     ::com::sun::star::uno::Any aTimeBetweenReqeusts;
      51           0 :     aTimeBetweenReqeusts = CacheConfiguration::Instance()->GetValue("TimeBetweenHighPriorityRequests");
      52           0 :     if (aTimeBetweenReqeusts.has<sal_Int32>())
      53           0 :         aTimeBetweenReqeusts >>= mnTimeBetweenHighPriorityRequests;
      54             : 
      55           0 :     aTimeBetweenReqeusts = CacheConfiguration::Instance()->GetValue("TimeBetweenLowPriorityRequests");
      56           0 :     if (aTimeBetweenReqeusts.has<sal_Int32>())
      57           0 :         aTimeBetweenReqeusts >>= mnTimeBetweenLowPriorityRequests;
      58             : 
      59           0 :     aTimeBetweenReqeusts = CacheConfiguration::Instance()->GetValue("TimeBetweenRequestsDuringShow");
      60           0 :     if (aTimeBetweenReqeusts.has<sal_Int32>())
      61           0 :         aTimeBetweenReqeusts >>= mnTimeBetweenRequestsWhenNotIdle;
      62             : 
      63           0 :     maTimer.SetTimeoutHdl (LINK(this,QueueProcessor,ProcessRequestHdl));
      64           0 :     maTimer.SetTimeout (mnTimeBetweenHighPriorityRequests);
      65           0 : }
      66             : 
      67             : 
      68             : 
      69             : 
      70             : 
      71           0 : QueueProcessor::~QueueProcessor (void)
      72             : {
      73           0 : }
      74             : 
      75             : 
      76             : 
      77             : 
      78           0 : void QueueProcessor::Start (int nPriorityClass)
      79             : {
      80           0 :     if (mbIsPaused)
      81           0 :         return;
      82           0 :     if ( ! maTimer.IsActive())
      83             :     {
      84           0 :         if (nPriorityClass == 0)
      85           0 :             maTimer.SetTimeout (mnTimeBetweenHighPriorityRequests);
      86             :         else
      87           0 :             maTimer.SetTimeout (mnTimeBetweenLowPriorityRequests);
      88           0 :         maTimer.Start();
      89             :     }
      90             : }
      91             : 
      92             : 
      93             : 
      94             : 
      95           0 : void QueueProcessor::Stop (void)
      96             : {
      97           0 :     if (maTimer.IsActive())
      98           0 :         maTimer.Stop();
      99           0 : }
     100             : 
     101             : 
     102             : 
     103             : 
     104           0 : void QueueProcessor::Pause (void)
     105             : {
     106           0 :     mbIsPaused = true;
     107           0 : }
     108             : 
     109             : 
     110             : 
     111             : 
     112           0 : void QueueProcessor::Resume (void)
     113             : {
     114           0 :     mbIsPaused = false;
     115           0 :     if ( ! mrQueue.IsEmpty())
     116           0 :         Start(mrQueue.GetFrontPriorityClass());
     117           0 : }
     118             : 
     119             : 
     120             : 
     121             : 
     122           0 : void QueueProcessor::Terminate (void)
     123             : {
     124           0 : }
     125             : 
     126             : 
     127             : 
     128             : 
     129           0 : void QueueProcessor::SetPreviewSize (
     130             :     const Size& rPreviewSize,
     131             :     const bool bDoSuperSampling)
     132             : {
     133           0 :     maPreviewSize = rPreviewSize;
     134           0 :     mbDoSuperSampling = bDoSuperSampling;
     135           0 : }
     136             : 
     137             : 
     138             : 
     139             : 
     140           0 : IMPL_LINK_NOARG(QueueProcessor, ProcessRequestHdl)
     141             : {
     142           0 :     ProcessRequests();
     143           0 :     return 1;
     144             : }
     145             : 
     146             : 
     147             : 
     148             : 
     149           0 : void QueueProcessor::ProcessRequests (void)
     150             : {
     151             :     OSL_ASSERT(mpCacheContext.get()!=NULL);
     152             : 
     153             :     // Never process more than one request at a time in order to prevent the
     154             :     // lock up of the edit view.
     155           0 :     if ( ! mrQueue.IsEmpty()
     156           0 :         && ! mbIsPaused
     157           0 :         &&  mpCacheContext->IsIdle())
     158             :     {
     159           0 :         CacheKey aKey = NULL;
     160           0 :         RequestPriorityClass ePriorityClass (NOT_VISIBLE);
     161             :         {
     162           0 :             ::osl::MutexGuard aGuard (mrQueue.GetMutex());
     163             : 
     164           0 :             if ( ! mrQueue.IsEmpty())
     165             :             {
     166             :                 // Get the request with the highest priority from the queue.
     167           0 :                 ePriorityClass = mrQueue.GetFrontPriorityClass();
     168           0 :                 aKey = mrQueue.GetFront();
     169           0 :                 mrQueue.PopFront();
     170           0 :             }
     171             :         }
     172             : 
     173           0 :         if (aKey != NULL)
     174           0 :             ProcessOneRequest(aKey, ePriorityClass);
     175             :     }
     176             : 
     177             :     // Schedule the processing of the next element(s).
     178             :     {
     179           0 :         ::osl::MutexGuard aGuard (mrQueue.GetMutex());
     180           0 :         if ( ! mrQueue.IsEmpty())
     181           0 :             Start(mrQueue.GetFrontPriorityClass());
     182             :     }
     183           0 : }
     184             : 
     185             : 
     186             : 
     187             : 
     188           0 : void QueueProcessor::ProcessOneRequest (
     189             :     CacheKey aKey,
     190             :     const RequestPriorityClass ePriorityClass)
     191             : {
     192             :     try
     193             :     {
     194           0 :         ::osl::MutexGuard aGuard (maMutex);
     195             : 
     196             :         // Create a new preview bitmap and store it in the cache.
     197           0 :         if (mpCache.get() != NULL
     198           0 :             && mpCacheContext.get() != NULL)
     199             :         {
     200           0 :             const SdPage* pSdPage = dynamic_cast<const SdPage*>(mpCacheContext->GetPage(aKey));
     201           0 :             if (pSdPage != NULL)
     202             :             {
     203             :                 const Bitmap aPreview (
     204           0 :                     maBitmapFactory.CreateBitmap(*pSdPage, maPreviewSize, mbDoSuperSampling));
     205           0 :                 mpCache->SetBitmap (pSdPage, aPreview, ePriorityClass!=NOT_VISIBLE);
     206             : 
     207             :                 // Initiate a repaint of the new preview.
     208           0 :                 mpCacheContext->NotifyPreviewCreation(aKey, aPreview);
     209             :             }
     210           0 :         }
     211             :     }
     212           0 :     catch (::com::sun::star::uno::RuntimeException &)
     213             :     {
     214             :         OSL_FAIL("RuntimeException caught in QueueProcessor");
     215             :     }
     216           0 :     catch (::com::sun::star::uno::Exception &)
     217             :     {
     218             :         OSL_FAIL("Exception caught in QueueProcessor");
     219             :     }
     220           0 : }
     221             : 
     222           0 : void QueueProcessor::SetBitmapCache (
     223             :     const ::boost::shared_ptr<BitmapCache>& rpCache)
     224             : {
     225           0 :     mpCache = rpCache;
     226           0 : }
     227             : 
     228             : 
     229             : } } } // end of namespace ::sd::slidesorter::cache
     230             : 
     231             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10