merge the formfield patch from ooo-build
[ooovba.git] / dbaccess / source / ui / browser / AsyncronousLink.cxx
blob92ee577f4266b7d381559d8e9767217caf3f4c21
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: AsyncronousLink.cxx,v $
10 * $Revision: 1.9 $
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_dbaccess.hxx"
33 #ifndef DBAUI_ASYNCRONOUSLINK_HXX
34 #include "AsyncronousLink.hxx"
35 #endif
36 #ifndef _SV_SVAPP_HXX
37 #include <vcl/svapp.hxx>
38 #endif
39 #ifndef _TOOLS_DEBUG_HXX
40 #include <tools/debug.hxx>
41 #endif
43 //==================================================================
44 //= OAsyncronousLink
45 //==================================================================
46 using namespace dbaui;
47 DBG_NAME(OAsyncronousLink)
48 //------------------------------------------------------------------
49 OAsyncronousLink::OAsyncronousLink( const Link& _rHandler )
50 :m_aHandler(_rHandler)
51 ,m_aEventSafety()
52 ,m_aDestructionSafety()
53 ,m_nEventId(0)
55 DBG_CTOR(OAsyncronousLink,NULL);
58 //------------------------------------------------------------------
59 OAsyncronousLink::~OAsyncronousLink()
62 ::osl::MutexGuard aEventGuard( m_aEventSafety );
63 if ( m_nEventId )
64 Application::RemoveUserEvent(m_nEventId);
65 m_nEventId = 0;
69 ::osl::MutexGuard aDestructionGuard( m_aDestructionSafety );
70 // this is just for the case we're deleted while another thread just handled the event :
71 // if this other thread called our link while we were deleting the event here, the
72 // link handler blocked. With leaving the above block it continued, but now we are prevented
73 // to leave this destructor 'til the link handler recognizes that nEvent == 0 and leaves.
75 DBG_DTOR(OAsyncronousLink,NULL);
79 //------------------------------------------------------------------
80 void OAsyncronousLink::Call( void* _pArgument )
82 ::osl::MutexGuard aEventGuard( m_aEventSafety );
83 if (m_nEventId)
84 Application::RemoveUserEvent(m_nEventId);
85 m_nEventId = Application::PostUserEvent( LINK( this, OAsyncronousLink, OnAsyncCall ), _pArgument );
88 //------------------------------------------------------------------
89 void OAsyncronousLink::CancelCall()
91 ::osl::MutexGuard aEventGuard( m_aEventSafety );
92 if ( m_nEventId )
93 Application::RemoveUserEvent( m_nEventId );
94 m_nEventId = 0;
97 //------------------------------------------------------------------
98 IMPL_LINK(OAsyncronousLink, OnAsyncCall, void*, _pArg)
101 ::osl::MutexGuard aDestructionGuard( m_aDestructionSafety );
103 ::osl::MutexGuard aEventGuard( m_aEventSafety );
104 if (!m_nEventId)
105 // our destructor deleted the event just while we we're waiting for m_aEventSafety
106 // -> get outta here
107 return 0;
108 m_nEventId = 0;
111 if (m_aHandler.IsSet())
112 return m_aHandler.Call(_pArg);
114 return 0L;