LCOV - code coverage report
Current view: top level - slideshow/source/engine - activitiesqueue.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 49 0.0 %
Date: 2014-04-14 Functions: 0 7 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             : // must be first
      22             : #include <canvas/debug.hxx>
      23             : #include <canvas/verbosetrace.hxx>
      24             : 
      25             : #include <comphelper/anytostring.hxx>
      26             : #include <cppuhelper/exc_hlp.hxx>
      27             : 
      28             : #include "slideshowexceptions.hxx"
      29             : #include "activity.hxx"
      30             : #include "activitiesqueue.hxx"
      31             : 
      32             : #include <boost/mem_fn.hpp>
      33             : #include <boost/shared_ptr.hpp>
      34             : #include <algorithm>
      35             : 
      36             : 
      37             : using namespace ::com::sun::star;
      38             : 
      39             : namespace slideshow
      40             : {
      41             :     namespace internal
      42             :     {
      43           0 :         ActivitiesQueue::ActivitiesQueue(
      44             :           const ::boost::shared_ptr< ::canvas::tools::ElapsedTime >& pPresTimer ) :
      45             :             mpTimer( pPresTimer ),
      46             :             maCurrentActivitiesWaiting(),
      47             :             maCurrentActivitiesReinsert(),
      48           0 :             maDequeuedActivities()
      49             :         {
      50           0 :         }
      51             : 
      52           0 :         ActivitiesQueue::~ActivitiesQueue()
      53             :         {
      54             :             // dispose all queue entries
      55             :             try
      56             :             {
      57             :                 std::for_each( maCurrentActivitiesWaiting.begin(),
      58             :                                maCurrentActivitiesWaiting.end(),
      59           0 :                                boost::mem_fn( &Disposable::dispose ) );
      60             :                 std::for_each( maCurrentActivitiesReinsert.begin(),
      61             :                                maCurrentActivitiesReinsert.end(),
      62           0 :                                boost::mem_fn( &Disposable::dispose ) );
      63             :             }
      64           0 :             catch (uno::Exception &)
      65             :             {
      66             :                 OSL_FAIL( OUStringToOString(
      67             :                                 comphelper::anyToString(
      68             :                                     cppu::getCaughtException() ),
      69             :                                 RTL_TEXTENCODING_UTF8 ).getStr() );
      70             :             }
      71           0 :         }
      72             : 
      73           0 :         bool ActivitiesQueue::addActivity( const ActivitySharedPtr& pActivity )
      74             :         {
      75             :             OSL_ENSURE( pActivity, "ActivitiesQueue::addActivity: activity ptr NULL" );
      76             : 
      77           0 :             if( !pActivity )
      78           0 :                 return false;
      79             : 
      80             :             // add entry to waiting list
      81           0 :             maCurrentActivitiesWaiting.push_back( pActivity );
      82             : 
      83           0 :             return true;
      84             :         }
      85             : 
      86           0 :         void ActivitiesQueue::process()
      87             :         {
      88             :             VERBOSE_TRACE( "ActivitiesQueue: outer loop heartbeat" );
      89             : 
      90             :             // accumulate time lag for all activities, and lag time
      91             :             // base if necessary:
      92             :             ActivityQueue::const_iterator iPos(
      93           0 :                 maCurrentActivitiesWaiting.begin() );
      94             :             const ActivityQueue::const_iterator iEnd(
      95           0 :                 maCurrentActivitiesWaiting.end() );
      96           0 :             double fLag = 0.0;
      97           0 :             for ( ; iPos != iEnd; ++iPos )
      98           0 :                 fLag = std::max<double>( fLag, (*iPos)->calcTimeLag() );
      99           0 :             if (fLag > 0.0)
     100             :             {
     101           0 :                 mpTimer->adjustTimer( -fLag );
     102             :             }
     103             : 
     104             :             // process list of activities
     105           0 :             while( !maCurrentActivitiesWaiting.empty() )
     106             :             {
     107             :                 // process topmost activity
     108           0 :                 ActivitySharedPtr pActivity( maCurrentActivitiesWaiting.front() );
     109           0 :                 maCurrentActivitiesWaiting.pop_front();
     110             : 
     111           0 :                 bool bReinsert( false );
     112             : 
     113             :                 try
     114             :                 {
     115             :                     // fire up activity
     116           0 :                     bReinsert = pActivity->perform();
     117             :                 }
     118           0 :                 catch( uno::RuntimeException& )
     119             :                 {
     120           0 :                     throw;
     121             :                 }
     122           0 :                 catch( uno::Exception& )
     123             :                 {
     124             :                     // catch anything here, we don't want
     125             :                     // to leave this scope under _any_
     126             :                     // circumstance. Although, do _not_
     127             :                     // reinsert an activity that threw
     128             :                     // once.
     129             : 
     130             :                     // NOTE: we explicitly don't catch(...) here,
     131             :                     // since this will also capture segmentation
     132             :                     // violations and the like. In such a case, we
     133             :                     // still better let our clients now...
     134             :                     OSL_FAIL( OUStringToOString(
     135             :                                     comphelper::anyToString( cppu::getCaughtException() ),
     136             :                                     RTL_TEXTENCODING_UTF8 ).getStr() );
     137             :                 }
     138           0 :                 catch( SlideShowException& )
     139             :                 {
     140             :                     // catch anything here, we don't want
     141             :                     // to leave this scope under _any_
     142             :                     // circumstance. Although, do _not_
     143             :                     // reinsert an activity that threw
     144             :                     // once.
     145             : 
     146             :                     // NOTE: we explicitly don't catch(...) here,
     147             :                     // since this will also capture segmentation
     148             :                     // violations and the like. In such a case, we
     149             :                     // still better let our clients now...
     150             :                     OSL_TRACE( "::presentation::internal::ActivitiesQueue: Activity threw a SlideShowException, removing from ring" );
     151             :                 }
     152             : 
     153           0 :                 if( bReinsert )
     154           0 :                     maCurrentActivitiesReinsert.push_back( pActivity );
     155             :                 else
     156           0 :                     maDequeuedActivities.push_back( pActivity );
     157             : 
     158             :                 VERBOSE_TRACE( "ActivitiesQueue: inner loop heartbeat" );
     159           0 :             }
     160             : 
     161           0 :             if( !maCurrentActivitiesReinsert.empty() )
     162             :             {
     163             :                 // reinsert all processed, but not finished
     164             :                 // activities back to waiting queue. With swap(),
     165             :                 // we kill two birds with one stone: we reuse the
     166             :                 // list nodes, and we clear the
     167             :                 // maCurrentActivitiesReinsert list
     168           0 :                 maCurrentActivitiesWaiting.swap( maCurrentActivitiesReinsert );
     169             :             }
     170           0 :         }
     171             : 
     172           0 :         void ActivitiesQueue::processDequeued()
     173             :         {
     174             :             // notify all dequeued activities from last round
     175             :             ::std::for_each( maDequeuedActivities.begin(),
     176             :                              maDequeuedActivities.end(),
     177           0 :                              ::boost::mem_fn( &Activity::dequeued ) );
     178           0 :             maDequeuedActivities.clear();
     179           0 :         }
     180             : 
     181           0 :         bool ActivitiesQueue::isEmpty() const
     182             :         {
     183           0 :             return maCurrentActivitiesWaiting.empty() && maCurrentActivitiesReinsert.empty();
     184             :         }
     185             : 
     186           0 :         void ActivitiesQueue::clear()
     187             :         {
     188             :             // dequeue all entries:
     189             :             std::for_each( maCurrentActivitiesWaiting.begin(),
     190             :                            maCurrentActivitiesWaiting.end(),
     191           0 :                            boost::mem_fn( &Activity::dequeued ) );
     192           0 :             ActivityQueue().swap( maCurrentActivitiesWaiting );
     193             : 
     194             :             std::for_each( maCurrentActivitiesReinsert.begin(),
     195             :                            maCurrentActivitiesReinsert.end(),
     196           0 :                            boost::mem_fn( &Activity::dequeued ) );
     197           0 :             ActivityQueue().swap( maCurrentActivitiesReinsert );
     198           0 :         }
     199             :     }
     200             : }
     201             : 
     202             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10