LCOV - code coverage report
Current view: top level - svtools/source/control - asynclink.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 46 51 90.2 %
Date: 2012-08-25 Functions: 6 6 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 34 50 68.0 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : 
      30                 :            : #include <svtools/asynclink.hxx>
      31                 :            : #include <osl/mutex.hxx>
      32                 :            : #include <tools/debug.hxx>
      33                 :            : #include <vcl/timer.hxx>
      34                 :            : #include <vcl/svapp.hxx>
      35                 :            : 
      36                 :            : //--------------------------------------------------------------------
      37                 :            : namespace svtools {
      38                 :            : 
      39                 :       5288 : void AsynchronLink::CreateMutex()
      40                 :            : {
      41 [ +  - ][ +  - ]:       5288 :     if( !_pMutex ) _pMutex = new osl::Mutex;
      42                 :       5288 : }
      43                 :            : 
      44                 :       4105 : void AsynchronLink::Call( void* pObj, sal_Bool
      45                 :            : #ifdef DBG_UTIL
      46                 :            : bAllowDoubles
      47                 :            : #endif
      48                 :            : , sal_Bool bUseTimer )
      49                 :            : {
      50                 :            : #ifdef DBG_UTIL
      51                 :            :     if ( bUseTimer || !_bInCall )
      52                 :            :         DBG_WARNING( "Recursives Call. Eher ueber Timer. TLX Fragen" );
      53                 :            : #endif
      54         [ +  + ]:       4105 :     if( _aLink.IsSet() )
      55                 :            :     {
      56                 :       1578 :         _pArg = pObj;
      57                 :            :         DBG_ASSERT( bAllowDoubles ||
      58                 :            :                     ( !_nEventId && ( !_pTimer || !_pTimer->IsActive() ) ),
      59                 :            :                     "Schon ein Call unterwegs" );
      60         [ +  + ]:       1578 :         if( _nEventId )
      61                 :            :         {
      62         [ -  + ]:          2 :             if( _pMutex ) _pMutex->acquire();
      63                 :          2 :             Application::RemoveUserEvent( _nEventId );
      64         [ -  + ]:          2 :             if( _pMutex ) _pMutex->release();
      65                 :            :         }
      66         [ -  + ]:       1578 :         if( _pTimer )_pTimer->Stop();
      67         [ -  + ]:       1578 :         if( bUseTimer )
      68                 :            :         {
      69         [ #  # ]:          0 :             if( !_pTimer )
      70                 :            :             {
      71         [ #  # ]:          0 :                 _pTimer = new Timer;
      72                 :          0 :                 _pTimer->SetTimeout( 0 );
      73                 :            :                 _pTimer->SetTimeoutHdl( STATIC_LINK(
      74                 :          0 :                     this, AsynchronLink, HandleCall) );
      75                 :            :             }
      76                 :          0 :             _pTimer->Start();
      77                 :            :         }
      78                 :            :         else
      79                 :            :         {
      80         [ +  + ]:       1578 :             if( _pMutex ) _pMutex->acquire();
      81         [ +  - ]:       1578 :             Application::PostUserEvent( _nEventId, STATIC_LINK( this, AsynchronLink, HandleCall), 0 );
      82         [ +  + ]:       1578 :             if( _pMutex ) _pMutex->release();
      83                 :            :         }
      84                 :            :     }
      85                 :       4105 : }
      86                 :            : 
      87                 :       6321 : AsynchronLink::~AsynchronLink()
      88                 :            : {
      89         [ +  + ]:       6321 :     if( _nEventId )
      90                 :            :     {
      91                 :        446 :         Application::RemoveUserEvent( _nEventId );
      92                 :            :     }
      93         [ -  + ]:       6321 :     delete _pTimer;
      94         [ +  + ]:       6321 :     if( _pDeleted ) *_pDeleted = sal_True;
      95         [ +  + ]:       6321 :     delete _pMutex;
      96                 :       6321 : }
      97                 :            : 
      98                 :       1117 : IMPL_STATIC_LINK( AsynchronLink, HandleCall, void*, EMPTYARG )
      99                 :            : {
     100         [ +  + ]:       1117 :     if( pThis->_pMutex ) pThis->_pMutex->acquire();
     101                 :       1117 :     pThis->_nEventId = 0;
     102         [ +  + ]:       1117 :     if( pThis->_pMutex ) pThis->_pMutex->release();
     103                 :       1117 :     pThis->Call_Impl( pThis->_pArg );
     104                 :       1117 :     return 0;
     105                 :            : }
     106                 :            : 
     107                 :       7655 : void AsynchronLink::ClearPendingCall()
     108                 :            : {
     109         [ +  - ]:       7655 :     if( _pMutex ) _pMutex->acquire();
     110         [ +  + ]:       7655 :     if( _nEventId )
     111                 :            :     {
     112                 :         13 :         Application::RemoveUserEvent( _nEventId );
     113                 :         13 :         _nEventId = 0;
     114                 :            :     }
     115         [ +  - ]:       7655 :     if( _pMutex ) _pMutex->release();
     116         [ -  + ]:       7655 :     if( _pTimer ) _pTimer->Stop();
     117                 :       7655 : }
     118                 :            : 
     119                 :       1117 : void AsynchronLink::Call_Impl( void* pArg )
     120                 :            : {
     121                 :       1117 :     _bInCall = sal_True;
     122                 :       1117 :     sal_Bool bDeleted = sal_False;
     123                 :       1117 :     _pDeleted = &bDeleted;
     124         [ +  - ]:       1117 :     _aLink.Call( pArg );
     125         [ +  + ]:       1117 :     if( !bDeleted )
     126                 :            :     {
     127                 :       1109 :         _bInCall = sal_False;
     128                 :       1109 :         _pDeleted = 0;
     129                 :            :     }
     130                 :       1117 : }
     131                 :            : 
     132                 :            : }
     133                 :            : 
     134                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10