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/idle.hxx>
26 #include <vcl/svapp.hxx>
31 void AsynchronLink::CreateMutex()
33 if( !_pMutex
) _pMutex
= new osl::Mutex
;
36 void AsynchronLink::Call( void* pObj
, bool
43 if ( bUseTimer
|| !_bInCall
)
44 DBG_WARNING( "Recursives Call. Eher ueber Timer. TLX Fragen" );
49 DBG_ASSERT( bAllowDoubles
||
50 ( !_nEventId
&& ( !_pIdle
|| !_pIdle
->IsActive() ) ),
51 "Schon ein Call unterwegs" );
58 _pIdle
->SetPriority( SchedulerPriority::HIGHEST
);
59 _pIdle
->SetIdleHdl( LINK(
60 this, AsynchronLink
, HandleCall_Idle
) );
66 if( _pMutex
) _pMutex
->acquire();
67 _nEventId
= Application::PostUserEvent( LINK( this, AsynchronLink
, HandleCall_PostUserEvent
), 0 );
68 if( _pMutex
) _pMutex
->release();
73 AsynchronLink::~AsynchronLink()
77 Application::RemoveUserEvent( _nEventId
);
80 if( _pDeleted
) *_pDeleted
= true;
84 IMPL_LINK_NOARG_TYPED( AsynchronLink
, HandleCall_Idle
, Idle
*, void )
86 if( _pMutex
) _pMutex
->acquire();
88 if( _pMutex
) _pMutex
->release();
92 IMPL_LINK_NOARG( AsynchronLink
, HandleCall_PostUserEvent
)
94 HandleCall_Idle(nullptr);
98 void AsynchronLink::ClearPendingCall()
100 if( _pMutex
) _pMutex
->acquire();
103 Application::RemoveUserEvent( _nEventId
);
106 if( _pMutex
) _pMutex
->release();
107 if( _pIdle
) _pIdle
->Stop();
110 void AsynchronLink::Call_Impl( void* pArg
)
113 bool bDeleted
= false;
114 _pDeleted
= &bDeleted
;
125 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */