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: AsyncronousLink.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_dbaccess.hxx"
33 #ifndef DBAUI_ASYNCRONOUSLINK_HXX
34 #include "AsyncronousLink.hxx"
37 #include <vcl/svapp.hxx>
39 #ifndef _TOOLS_DEBUG_HXX
40 #include <tools/debug.hxx>
43 //==================================================================
45 //==================================================================
46 using namespace dbaui
;
47 DBG_NAME(OAsyncronousLink
)
48 //------------------------------------------------------------------
49 OAsyncronousLink::OAsyncronousLink( const Link
& _rHandler
)
50 :m_aHandler(_rHandler
)
52 ,m_aDestructionSafety()
55 DBG_CTOR(OAsyncronousLink
,NULL
);
58 //------------------------------------------------------------------
59 OAsyncronousLink::~OAsyncronousLink()
62 ::osl::MutexGuard
aEventGuard( m_aEventSafety
);
64 Application::RemoveUserEvent(m_nEventId
);
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
);
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
);
93 Application::RemoveUserEvent( m_nEventId
);
97 //------------------------------------------------------------------
98 IMPL_LINK(OAsyncronousLink
, OnAsyncCall
, void*, _pArg
)
101 ::osl::MutexGuard
aDestructionGuard( m_aDestructionSafety
);
103 ::osl::MutexGuard
aEventGuard( m_aEventSafety
);
105 // our destructor deleted the event just while we we're waiting for m_aEventSafety
111 if (m_aHandler
.IsSet())
112 return m_aHandler
.Call(_pArg
);