LCOV - code coverage report
Current view: top level - sc/source/core/tool - refreshtimer.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 54 67 80.6 %
Date: 2014-11-03 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      156680 : void ScRefreshTimerControl::SetAllowRefresh( bool b )
      24             : {
      25      156680 :     if ( b && nBlockRefresh )
      26       77234 :         --nBlockRefresh;
      27       79446 :     else if ( !b && nBlockRefresh < (sal_uInt16)(~0) )
      28       79446 :         ++nBlockRefresh;
      29      156680 : }
      30             : 
      31       79446 : ScRefreshTimerProtector::ScRefreshTimerProtector( ScRefreshTimerControl * const & rp )
      32             :         :
      33       79446 :         m_rpControl( rp )
      34             : {
      35       79446 :     if ( m_rpControl )
      36             :     {
      37       79446 :         m_rpControl->SetAllowRefresh( false );
      38             :         // wait for any running refresh in another thread to finnish
      39       79446 :         ::osl::MutexGuard aGuard( m_rpControl->GetMutex() );
      40             :     }
      41       79446 : }
      42             : 
      43       79446 : ScRefreshTimerProtector::~ScRefreshTimerProtector()
      44             : {
      45       79446 :     if ( m_rpControl )
      46       77234 :         m_rpControl->SetAllowRefresh( true );
      47       79446 : }
      48             : 
      49         116 : ScRefreshTimer::ScRefreshTimer() : ppControl(0)
      50             : {
      51         116 :     SetTimeout( 0 );
      52         116 : }
      53             : 
      54          36 : ScRefreshTimer::ScRefreshTimer( sal_uLong nSeconds ) : ppControl(0)
      55             : {
      56          36 :     SetTimeout( nSeconds * 1000 );
      57          36 :     Start();
      58          36 : }
      59             : 
      60         842 : ScRefreshTimer::ScRefreshTimer( const ScRefreshTimer& r ) : AutoTimer( r ), ppControl(0)
      61             : {
      62         842 : }
      63             : 
      64        1988 : ScRefreshTimer::~ScRefreshTimer()
      65             : {
      66         994 :     if ( IsActive() )
      67           0 :         Stop();
      68         994 : }
      69             : 
      70          98 : ScRefreshTimer& ScRefreshTimer::operator=( const ScRefreshTimer& r )
      71             : {
      72          98 :     SetRefreshControl(0);
      73          98 :     AutoTimer::operator=( r );
      74          98 :     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         140 : void ScRefreshTimer::SetRefreshControl( ScRefreshTimerControl * const * pp )
      88             : {
      89         140 :     ppControl = pp;
      90         140 : }
      91             : 
      92          42 : void ScRefreshTimer::SetRefreshHandler( const Link& rLink )
      93             : {
      94          42 :     SetTimeoutHdl( rLink );
      95          42 : }
      96             : 
      97         128 : sal_uLong ScRefreshTimer::GetRefreshDelay() const
      98             : {
      99         128 :     return GetTimeout() / 1000;
     100             : }
     101             : 
     102         994 : void ScRefreshTimer::StopRefreshTimer()
     103             : {
     104         994 :     Stop();
     105         994 : }
     106             : 
     107          20 : void ScRefreshTimer::SetRefreshDelay( sal_uLong nSeconds )
     108             : {
     109          20 :     bool bActive = IsActive();
     110          20 :     if ( bActive && !nSeconds )
     111           0 :         Stop();
     112          20 :     SetTimeout( nSeconds * 1000 );
     113          20 :     if ( !bActive && nSeconds )
     114           6 :         Start();
     115          20 : }
     116             : 
     117           0 : void ScRefreshTimer::Timeout()
     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 :             Start();
     128             :     }
     129           0 : }
     130             : 
     131          42 : void ScRefreshTimer::Start()
     132             : {
     133          42 :     if ( GetTimeout() )
     134          26 :         AutoTimer::Start();
     135          42 : }
     136             : 
     137             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10