LCOV - code coverage report
Current view: top level - sc/source/core/tool - refreshtimer.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 54 67 80.6 %
Date: 2015-06-13 12:38:46 Functions: 14 18 77.8 %
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             : #include "refreshtimer.hxx"
      21             : #include "refreshtimerprotector.hxx"
      22             : 
      23       94404 : void ScRefreshTimerControl::SetAllowRefresh( bool b )
      24             : {
      25       94404 :     if ( b && nBlockRefresh )
      26       46555 :         --nBlockRefresh;
      27       47849 :     else if ( !b && nBlockRefresh < (sal_uInt16)(~0) )
      28       47849 :         ++nBlockRefresh;
      29       94404 : }
      30             : 
      31       47849 : ScRefreshTimerProtector::ScRefreshTimerProtector( ScRefreshTimerControl * const & rp )
      32             :         :
      33       47849 :         m_rpControl( rp )
      34             : {
      35       47849 :     if ( m_rpControl )
      36             :     {
      37       47849 :         m_rpControl->SetAllowRefresh( false );
      38             :         // wait for any running refresh in another thread to finnish
      39       47849 :         ::osl::MutexGuard aGuard( m_rpControl->GetMutex() );
      40             :     }
      41       47849 : }
      42             : 
      43       47849 : ScRefreshTimerProtector::~ScRefreshTimerProtector()
      44             : {
      45       47849 :     if ( m_rpControl )
      46       46555 :         m_rpControl->SetAllowRefresh( true );
      47       47849 : }
      48             : 
      49          67 : ScRefreshTimer::ScRefreshTimer() : ppControl(0)
      50             : {
      51          67 :     SetTimeout( 0 );
      52          67 : }
      53             : 
      54          18 : ScRefreshTimer::ScRefreshTimer( sal_uLong nSeconds ) : ppControl(0)
      55             : {
      56          18 :     SetTimeout( nSeconds * 1000 );
      57          18 :     Launch();
      58          18 : }
      59             : 
      60         421 : ScRefreshTimer::ScRefreshTimer( const ScRefreshTimer& r ) : AutoTimer( r ), ppControl(0)
      61             : {
      62         421 : }
      63             : 
      64        1006 : ScRefreshTimer::~ScRefreshTimer()
      65             : {
      66         503 :     if ( IsActive() )
      67           0 :         Stop();
      68         503 : }
      69             : 
      70          51 : ScRefreshTimer& ScRefreshTimer::operator=( const ScRefreshTimer& r )
      71             : {
      72          51 :     SetRefreshControl(0);
      73          51 :     AutoTimer::operator=( r );
      74          51 :     return *this;
      75             : }
      76             : 
      77           0 : bool ScRefreshTimer::operator==( const ScRefreshTimer& r ) const
      78             : {
      79           0 :     return GetTimeout() == r.GetTimeout();
      80             : }
      81             : 
      82           0 : bool ScRefreshTimer::operator!=( const ScRefreshTimer& r ) const
      83             : {
      84           0 :     return !ScRefreshTimer::operator==( r );
      85             : }
      86             : 
      87          72 : void ScRefreshTimer::SetRefreshControl( ScRefreshTimerControl * const * pp )
      88             : {
      89          72 :     ppControl = pp;
      90          72 : }
      91             : 
      92          21 : void ScRefreshTimer::SetRefreshHandler( const Link<Timer *, void>& rLink )
      93             : {
      94          21 :     SetTimeoutHdl( rLink );
      95          21 : }
      96             : 
      97          64 : sal_uLong ScRefreshTimer::GetRefreshDelay() const
      98             : {
      99          64 :     return GetTimeout() / 1000;
     100             : }
     101             : 
     102         503 : void ScRefreshTimer::StopRefreshTimer()
     103             : {
     104         503 :     Stop();
     105         503 : }
     106             : 
     107          10 : void ScRefreshTimer::SetRefreshDelay( sal_uLong nSeconds )
     108             : {
     109          10 :     bool bActive = IsActive();
     110          10 :     if ( bActive && !nSeconds )
     111           0 :         Stop();
     112          10 :     SetTimeout( nSeconds * 1000 );
     113          10 :     if ( !bActive && nSeconds )
     114           3 :         Launch();
     115          10 : }
     116             : 
     117           0 : void ScRefreshTimer::Invoke()
     118             : {
     119           0 :     if ( ppControl && *ppControl && (*ppControl)->IsRefreshAllowed() )
     120             :     {
     121             :         // now we COULD make the call in another thread ...
     122           0 :         ::osl::MutexGuard aGuard( (*ppControl)->GetMutex() );
     123           0 :         maTimeoutHdl.Call( this );
     124             :         // restart from now on, don't execute immediately again if timed out
     125             :         // a second time during refresh
     126           0 :         if ( IsActive() )
     127           0 :             Launch();
     128             :     }
     129           0 : }
     130             : 
     131          21 : void ScRefreshTimer::Launch()
     132             : {
     133          21 :     if ( GetTimeout() )
     134          13 :         AutoTimer::Start();
     135          21 : }
     136             : 
     137             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11