1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: asynclink.cxx,v $
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 //--------------------------------------------------------------------
43 void AsynchronLink::CreateMutex()
45 if( !_pMutex
) _pMutex
= new vos::OMutex
;
48 void AsynchronLink::Call( void* pObj
, BOOL
55 if ( bUseTimer
|| !_bInCall
)
56 DBG_WARNING( "Recursives Call. Eher ueber Timer. TLX Fragen" );
61 DBG_ASSERT( bAllowDoubles
||
62 ( !_nEventId
&& ( !_pTimer
|| !_pTimer
->IsActive() ) ),
63 "Schon ein Call unterwegs" );
66 if( _pMutex
) _pMutex
->acquire();
67 Application::RemoveUserEvent( _nEventId
);
68 if( _pMutex
) _pMutex
->release();
70 if( _pTimer
)_pTimer
->Stop();
76 _pTimer
->SetTimeout( 0 );
77 _pTimer
->SetTimeoutHdl( STATIC_LINK(
78 this, AsynchronLink
, HandleCall
) );
84 if( _pMutex
) _pMutex
->acquire();
85 Application::PostUserEvent( _nEventId
, STATIC_LINK( this, AsynchronLink
, HandleCall
), 0 );
86 if( _pMutex
) _pMutex
->release();
91 AsynchronLink::~AsynchronLink()
95 Application::RemoveUserEvent( _nEventId
);
98 if( _pDeleted
) *_pDeleted
= TRUE
;
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
);
111 void AsynchronLink::ForcePendingCall()
117 void AsynchronLink::ClearPendingCall()
119 if( _pMutex
) _pMutex
->acquire();
122 Application::RemoveUserEvent( _nEventId
);
125 if( _pMutex
) _pMutex
->release();
126 if( _pTimer
) _pTimer
->Stop();
129 void AsynchronLink::Call_Impl( void* pArg
)
132 BOOL bDeleted
= FALSE
;
133 _pDeleted
= &bDeleted
;