2001-01-09 08:43:04 -06:00
|
|
|
/*************************************************************************
|
|
|
|
*
|
2008-04-10 08:03:39 -05:00
|
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
2001-01-09 08:43:04 -06:00
|
|
|
*
|
2010-02-12 08:01:35 -06:00
|
|
|
* Copyright 2000, 2010 Oracle and/or its affiliates.
|
2001-01-09 08:43:04 -06:00
|
|
|
*
|
2008-04-10 08:03:39 -05:00
|
|
|
* OpenOffice.org - a multi-platform office productivity suite
|
2001-01-09 08:43:04 -06:00
|
|
|
*
|
2008-04-10 08:03:39 -05:00
|
|
|
* This file is part of OpenOffice.org.
|
2001-01-09 08:43:04 -06:00
|
|
|
*
|
2008-04-10 08:03:39 -05:00
|
|
|
* OpenOffice.org is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Lesser General Public License version 3
|
|
|
|
* only, as published by the Free Software Foundation.
|
2001-01-09 08:43:04 -06:00
|
|
|
*
|
2008-04-10 08:03:39 -05:00
|
|
|
* OpenOffice.org is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Lesser General Public License version 3 for more details
|
|
|
|
* (a copy is included in the LICENSE file that accompanied this code).
|
2001-01-09 08:43:04 -06:00
|
|
|
*
|
2008-04-10 08:03:39 -05:00
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
* version 3 along with OpenOffice.org. If not, see
|
|
|
|
* <http://www.openoffice.org/license.html>
|
|
|
|
* for a copy of the LGPLv3 License.
|
2001-01-09 08:43:04 -06:00
|
|
|
*
|
|
|
|
************************************************************************/
|
2006-09-17 00:55:56 -05:00
|
|
|
|
|
|
|
// MARKER(update_precomp.py): autogen include statement, do not remove
|
|
|
|
#include "precompiled_dbaccess.hxx"
|
2001-01-09 08:43:04 -06:00
|
|
|
#ifndef DBAUI_ASYNCRONOUSLINK_HXX
|
|
|
|
#include "AsyncronousLink.hxx"
|
|
|
|
#endif
|
|
|
|
#ifndef _SV_SVAPP_HXX
|
|
|
|
#include <vcl/svapp.hxx>
|
|
|
|
#endif
|
2005-09-23 06:18:50 -05:00
|
|
|
#ifndef _TOOLS_DEBUG_HXX
|
|
|
|
#include <tools/debug.hxx>
|
|
|
|
#endif
|
|
|
|
|
2001-01-09 08:43:04 -06:00
|
|
|
//==================================================================
|
|
|
|
//= OAsyncronousLink
|
|
|
|
//==================================================================
|
|
|
|
using namespace dbaui;
|
2005-09-23 06:18:50 -05:00
|
|
|
DBG_NAME(OAsyncronousLink)
|
2001-01-09 08:43:04 -06:00
|
|
|
//------------------------------------------------------------------
|
2008-03-06 11:12:40 -06:00
|
|
|
OAsyncronousLink::OAsyncronousLink( const Link& _rHandler )
|
2001-01-09 08:43:04 -06:00
|
|
|
:m_aHandler(_rHandler)
|
2008-03-06 11:12:40 -06:00
|
|
|
,m_aEventSafety()
|
|
|
|
,m_aDestructionSafety()
|
2001-01-09 08:43:04 -06:00
|
|
|
,m_nEventId(0)
|
|
|
|
{
|
2005-09-23 06:18:50 -05:00
|
|
|
DBG_CTOR(OAsyncronousLink,NULL);
|
2001-01-09 08:43:04 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
OAsyncronousLink::~OAsyncronousLink()
|
|
|
|
{
|
|
|
|
{
|
2008-03-06 11:12:40 -06:00
|
|
|
::osl::MutexGuard aEventGuard( m_aEventSafety );
|
|
|
|
if ( m_nEventId )
|
2001-01-09 08:43:04 -06:00
|
|
|
Application::RemoveUserEvent(m_nEventId);
|
|
|
|
m_nEventId = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2008-03-06 11:12:40 -06:00
|
|
|
::osl::MutexGuard aDestructionGuard( m_aDestructionSafety );
|
2001-01-09 08:43:04 -06:00
|
|
|
// this is just for the case we're deleted while another thread just handled the event :
|
|
|
|
// if this other thread called our link while we were deleting the event here, the
|
|
|
|
// link handler blocked. With leaving the above block it continued, but now we are prevented
|
|
|
|
// to leave this destructor 'til the link handler recognizes that nEvent == 0 and leaves.
|
|
|
|
}
|
2005-09-23 06:18:50 -05:00
|
|
|
DBG_DTOR(OAsyncronousLink,NULL);
|
2001-01-09 08:43:04 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
2008-06-25 06:39:24 -05:00
|
|
|
void OAsyncronousLink::Call( void* _pArgument )
|
2001-01-09 08:43:04 -06:00
|
|
|
{
|
2008-03-06 11:12:40 -06:00
|
|
|
::osl::MutexGuard aEventGuard( m_aEventSafety );
|
2001-01-09 08:43:04 -06:00
|
|
|
if (m_nEventId)
|
|
|
|
Application::RemoveUserEvent(m_nEventId);
|
2008-06-25 06:39:24 -05:00
|
|
|
m_nEventId = Application::PostUserEvent( LINK( this, OAsyncronousLink, OnAsyncCall ), _pArgument );
|
2001-01-09 08:43:04 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
void OAsyncronousLink::CancelCall()
|
|
|
|
{
|
2008-03-06 11:12:40 -06:00
|
|
|
::osl::MutexGuard aEventGuard( m_aEventSafety );
|
|
|
|
if ( m_nEventId )
|
|
|
|
Application::RemoveUserEvent( m_nEventId );
|
2001-01-09 08:43:04 -06:00
|
|
|
m_nEventId = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
//------------------------------------------------------------------
|
|
|
|
IMPL_LINK(OAsyncronousLink, OnAsyncCall, void*, _pArg)
|
|
|
|
{
|
|
|
|
{
|
2008-03-06 11:12:40 -06:00
|
|
|
::osl::MutexGuard aDestructionGuard( m_aDestructionSafety );
|
2001-01-09 08:43:04 -06:00
|
|
|
{
|
2008-03-06 11:12:40 -06:00
|
|
|
::osl::MutexGuard aEventGuard( m_aEventSafety );
|
2001-01-09 08:43:04 -06:00
|
|
|
if (!m_nEventId)
|
2008-03-06 11:12:40 -06:00
|
|
|
// our destructor deleted the event just while we we're waiting for m_aEventSafety
|
2001-01-09 08:43:04 -06:00
|
|
|
// -> get outta here
|
|
|
|
return 0;
|
|
|
|
m_nEventId = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (m_aHandler.IsSet())
|
|
|
|
return m_aHandler.Call(_pArg);
|
|
|
|
|
|
|
|
return 0L;
|
|
|
|
}
|