LCOV - code coverage report
Current view: top level - svtools/source/control - asynclink.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 45 50 90.0 %
Date: 2015-06-13 12:38:46 Functions: 8 9 88.9 %
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 <svtools/asynclink.hxx>
      22             : #include <osl/mutex.hxx>
      23             : #include <tools/debug.hxx>
      24             : #include <vcl/timer.hxx>
      25             : #include <vcl/idle.hxx>
      26             : #include <vcl/svapp.hxx>
      27             : 
      28             : 
      29             : namespace svtools {
      30             : 
      31       12371 : void AsynchronLink::CreateMutex()
      32             : {
      33       12371 :     if( !_pMutex ) _pMutex = new osl::Mutex;
      34       12371 : }
      35             : 
      36       15029 : void AsynchronLink::Call( void* pObj, bool
      37             : #ifdef DBG_UTIL
      38             : bAllowDoubles
      39             : #endif
      40             : , bool bUseTimer )
      41             : {
      42             : #ifdef DBG_UTIL
      43             :     if ( bUseTimer || !_bInCall )
      44             :         DBG_WARNING( "Recursives Call. Eher ueber Timer. TLX Fragen" );
      45             : #endif
      46       15029 :     if( _aLink.IsSet() )
      47             :     {
      48        2754 :         _pArg = pObj;
      49             :         DBG_ASSERT( bAllowDoubles ||
      50             :                     ( !_nEventId && ( !_pIdle || !_pIdle->IsActive() ) ),
      51             :                     "Schon ein Call unterwegs" );
      52        2754 :         ClearPendingCall();
      53        2754 :         if( bUseTimer )
      54             :         {
      55           0 :             if( !_pIdle )
      56             :             {
      57           0 :                 _pIdle = new Idle;
      58           0 :                 _pIdle->SetPriority( SchedulerPriority::HIGHEST );
      59             :                 _pIdle->SetIdleHdl( LINK(
      60           0 :                     this, AsynchronLink, HandleCall_Idle) );
      61             :             }
      62           0 :             _pIdle->Start();
      63             :         }
      64             :         else
      65             :         {
      66        2754 :             if( _pMutex ) _pMutex->acquire();
      67        2754 :             _nEventId = Application::PostUserEvent( LINK( this, AsynchronLink, HandleCall_PostUserEvent), 0 );
      68        2754 :             if( _pMutex ) _pMutex->release();
      69             :         }
      70             :     }
      71       15029 : }
      72             : 
      73       14957 : AsynchronLink::~AsynchronLink()
      74             : {
      75       14957 :     if( _nEventId )
      76             :     {
      77        2248 :         Application::RemoveUserEvent( _nEventId );
      78             :     }
      79       14957 :     delete _pIdle;
      80       14957 :     if( _pDeleted ) *_pDeleted = true;
      81       14957 :     delete _pMutex;
      82       14957 : }
      83             : 
      84         476 : IMPL_LINK_NOARG_TYPED( AsynchronLink, HandleCall_Idle, Idle*, void )
      85             : {
      86         476 :     if( _pMutex ) _pMutex->acquire();
      87         476 :     _nEventId = 0;
      88         476 :     if( _pMutex ) _pMutex->release();
      89         476 :     Call_Impl( _pArg );
      90         476 : }
      91             : 
      92         952 : IMPL_LINK_NOARG( AsynchronLink, HandleCall_PostUserEvent )
      93             : {
      94         476 :     HandleCall_Idle(nullptr);
      95         476 :     return 0;
      96             : }
      97             : 
      98       27392 : void AsynchronLink::ClearPendingCall()
      99             : {
     100       27392 :     if( _pMutex ) _pMutex->acquire();
     101       27392 :     if( _nEventId )
     102             :     {
     103          29 :         Application::RemoveUserEvent( _nEventId );
     104          29 :         _nEventId = 0;
     105             :     }
     106       27392 :     if( _pMutex ) _pMutex->release();
     107       27392 :     if( _pIdle ) _pIdle->Stop();
     108       27392 : }
     109             : 
     110         476 : void AsynchronLink::Call_Impl( void* pArg )
     111             : {
     112         476 :     _bInCall = true;
     113         476 :     bool bDeleted = false;
     114         476 :     _pDeleted = &bDeleted;
     115         476 :     _aLink.Call( pArg );
     116         476 :     if( !bDeleted )
     117             :     {
     118         475 :         _bInCall = false;
     119         475 :         _pDeleted = 0;
     120             :     }
     121         476 : }
     122             : 
     123             : }
     124             : 
     125             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11