1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
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>
27 //--------------------------------------------------------------------
30 void AsynchronLink::CreateMutex()
32 if( !_pMutex
) _pMutex
= new osl::Mutex
;
35 void AsynchronLink::Call( void* pObj
, sal_Bool
39 , sal_Bool bUseTimer
)
42 if ( bUseTimer
|| !_bInCall
)
43 DBG_WARNING( "Recursives Call. Eher ueber Timer. TLX Fragen" );
48 DBG_ASSERT( bAllowDoubles
||
49 ( !_nEventId
&& ( !_pTimer
|| !_pTimer
->IsActive() ) ),
50 "Schon ein Call unterwegs" );
53 if( _pMutex
) _pMutex
->acquire();
54 Application::RemoveUserEvent( _nEventId
);
55 if( _pMutex
) _pMutex
->release();
57 if( _pTimer
)_pTimer
->Stop();
63 _pTimer
->SetTimeout( 0 );
64 _pTimer
->SetTimeoutHdl( STATIC_LINK(
65 this, AsynchronLink
, HandleCall
) );
71 if( _pMutex
) _pMutex
->acquire();
72 Application::PostUserEvent( _nEventId
, STATIC_LINK( this, AsynchronLink
, HandleCall
), 0 );
73 if( _pMutex
) _pMutex
->release();
78 AsynchronLink::~AsynchronLink()
82 Application::RemoveUserEvent( _nEventId
);
85 if( _pDeleted
) *_pDeleted
= sal_True
;
89 IMPL_STATIC_LINK( AsynchronLink
, HandleCall
, void*, EMPTYARG
)
91 if( pThis
->_pMutex
) pThis
->_pMutex
->acquire();
93 if( pThis
->_pMutex
) pThis
->_pMutex
->release();
94 pThis
->Call_Impl( pThis
->_pArg
);
98 void AsynchronLink::ClearPendingCall()
100 if( _pMutex
) _pMutex
->acquire();
103 Application::RemoveUserEvent( _nEventId
);
106 if( _pMutex
) _pMutex
->release();
107 if( _pTimer
) _pTimer
->Stop();
110 void AsynchronLink::Call_Impl( void* pArg
)
113 sal_Bool bDeleted
= sal_False
;
114 _pDeleted
= &bDeleted
;
118 _bInCall
= sal_False
;
125 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */