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

Generated by: LCOV version 1.10