office-gobmx/dbaccess/source/ui/browser/AsyncronousLink.cxx

113 lines
3.8 KiB
C++
Raw Normal View History

2001-01-09 08:43:04 -06:00
/*************************************************************************
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
2001-01-09 08:43:04 -06:00
*
* Copyright 2000, 2010 Oracle and/or its affiliates.
2001-01-09 08:43:04 -06:00
*
* OpenOffice.org - a multi-platform office productivity suite
2001-01-09 08:43:04 -06:00
*
* This file is part of OpenOffice.org.
2001-01-09 08:43:04 -06: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
*
* 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
*
* 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
*
************************************************************************/
// 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
#ifndef _TOOLS_DEBUG_HXX
#include <tools/debug.hxx>
#endif
2001-01-09 08:43:04 -06:00
//==================================================================
//= OAsyncronousLink
//==================================================================
using namespace dbaui;
DBG_NAME(OAsyncronousLink)
2001-01-09 08:43:04 -06:00
//------------------------------------------------------------------
OAsyncronousLink::OAsyncronousLink( const Link& _rHandler )
2001-01-09 08:43:04 -06:00
:m_aHandler(_rHandler)
,m_aEventSafety()
,m_aDestructionSafety()
2001-01-09 08:43:04 -06:00
,m_nEventId(0)
{
DBG_CTOR(OAsyncronousLink,NULL);
2001-01-09 08:43:04 -06:00
}
//------------------------------------------------------------------
OAsyncronousLink::~OAsyncronousLink()
{
{
::osl::MutexGuard aEventGuard( m_aEventSafety );
if ( m_nEventId )
2001-01-09 08:43:04 -06:00
Application::RemoveUserEvent(m_nEventId);
m_nEventId = 0;
}
{
::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.
}
DBG_DTOR(OAsyncronousLink,NULL);
2001-01-09 08:43:04 -06:00
}
//------------------------------------------------------------------
void OAsyncronousLink::Call( void* _pArgument )
2001-01-09 08:43:04 -06:00
{
::osl::MutexGuard aEventGuard( m_aEventSafety );
2001-01-09 08:43:04 -06:00
if (m_nEventId)
Application::RemoveUserEvent(m_nEventId);
m_nEventId = Application::PostUserEvent( LINK( this, OAsyncronousLink, OnAsyncCall ), _pArgument );
2001-01-09 08:43:04 -06:00
}
//------------------------------------------------------------------
void OAsyncronousLink::CancelCall()
{
::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)
{
{
::osl::MutexGuard aDestructionGuard( m_aDestructionSafety );
2001-01-09 08:43:04 -06:00
{
::osl::MutexGuard aEventGuard( m_aEventSafety );
2001-01-09 08:43:04 -06:00
if (!m_nEventId)
// 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;
}