update dev300-m58
[ooovba.git] / svtools / source / control / asynclink.cxx
blobeb4549b74cd9277d735314aee197f002068cd695
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: asynclink.cxx,v $
10 * $Revision: 1.6 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svtools.hxx"
34 #include <asynclink.hxx>
35 #include <vos/mutex.hxx>
36 #include <tools/debug.hxx>
37 #include <vcl/timer.hxx>
38 #include <vcl/svapp.hxx>
40 //--------------------------------------------------------------------
41 namespace svtools {
43 void AsynchronLink::CreateMutex()
45 if( !_pMutex ) _pMutex = new vos::OMutex;
48 void AsynchronLink::Call( void* pObj, BOOL
49 #ifdef DBG_UTIL
50 bAllowDoubles
51 #endif
52 , BOOL bUseTimer )
54 #ifdef DBG_UTIL
55 if ( bUseTimer || !_bInCall )
56 DBG_WARNING( "Recursives Call. Eher ueber Timer. TLX Fragen" );
57 #endif
58 if( _aLink.IsSet() )
60 _pArg = pObj;
61 DBG_ASSERT( bAllowDoubles ||
62 ( !_nEventId && ( !_pTimer || !_pTimer->IsActive() ) ),
63 "Schon ein Call unterwegs" );
64 if( _nEventId )
66 if( _pMutex ) _pMutex->acquire();
67 Application::RemoveUserEvent( _nEventId );
68 if( _pMutex ) _pMutex->release();
70 if( _pTimer )_pTimer->Stop();
71 if( bUseTimer )
73 if( !_pTimer )
75 _pTimer = new Timer;
76 _pTimer->SetTimeout( 0 );
77 _pTimer->SetTimeoutHdl( STATIC_LINK(
78 this, AsynchronLink, HandleCall) );
80 _pTimer->Start();
82 else
84 if( _pMutex ) _pMutex->acquire();
85 Application::PostUserEvent( _nEventId, STATIC_LINK( this, AsynchronLink, HandleCall), 0 );
86 if( _pMutex ) _pMutex->release();
91 AsynchronLink::~AsynchronLink()
93 if( _nEventId )
95 Application::RemoveUserEvent( _nEventId );
97 delete _pTimer;
98 if( _pDeleted ) *_pDeleted = TRUE;
99 delete _pMutex;
102 IMPL_STATIC_LINK( AsynchronLink, HandleCall, void*, EMPTYARG )
104 if( pThis->_pMutex ) pThis->_pMutex->acquire();
105 pThis->_nEventId = 0;
106 if( pThis->_pMutex ) pThis->_pMutex->release();
107 pThis->Call_Impl( pThis->_pArg );
108 return 0;
111 void AsynchronLink::ForcePendingCall()
113 ClearPendingCall();
114 Call_Impl( _pArg );
117 void AsynchronLink::ClearPendingCall()
119 if( _pMutex ) _pMutex->acquire();
120 if( _nEventId )
122 Application::RemoveUserEvent( _nEventId );
123 _nEventId = 0;
125 if( _pMutex ) _pMutex->release();
126 if( _pTimer ) _pTimer->Stop();
129 void AsynchronLink::Call_Impl( void* pArg )
131 _bInCall = TRUE;
132 BOOL bDeleted = FALSE;
133 _pDeleted = &bDeleted;
134 _aLink.Call( pArg );
135 if( !bDeleted )
137 _bInCall = FALSE;
138 _pDeleted = 0;