/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file incorporates work covered by the following license notice: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed * with this work for additional information regarding copyright * ownership. The ASF licenses this file to you under the Apache * License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
void OInterfaceContainerHelper2::copyAndResetInUse()
{
OSL_ENSURE( bInUse, "OInterfaceContainerHelper2 not in use" ); if( bInUse )
{ // this should be the worst case. If an iterator is active // and a new Listener is added. if( bIsList )
aData.pAsVector = new std::vector< Reference< XInterface > >( *aData.pAsVector ); elseif( aData.pAsInterface )
aData.pAsInterface->acquire();
if( bIsList )
{ // It is not valid to compare the pointer directly, but it's faster. auto it = std::find_if(aData.pAsVector->begin(), aData.pAsVector->end(),
[&rListener](const css::uno::Reference<css::uno::XInterface>& rItem) { return rItem.get() == rListener.get(); });
// interface not found, use the correct compare method if (it == aData.pAsVector->end())
it = std::find(aData.pAsVector->begin(), aData.pAsVector->end(), rListener);
if (it != aData.pAsVector->end())
aData.pAsVector->erase(it);
void OInterfaceContainerHelper2::disposeAndClear( const EventObject & rEvt )
{
ClearableMutexGuard aGuard( rMutex );
OInterfaceIteratorHelper2 aIt( *this ); // Release container, in case new entries come while disposing
OSL_ENSURE( !bIsList || bInUse, "OInterfaceContainerHelper2 not in use" ); if( !bIsList && aData.pAsInterface )
aData.pAsInterface->release(); // set the member to null, use the iterator to delete the values
aData.pAsInterface = nullptr;
bIsList = false;
bInUse = false;
aGuard.clear(); while( aIt.hasMoreElements() )
{ try
{
Reference<XEventListener > xLst( aIt.next(), UNO_QUERY ); if( xLst.is() )
xLst->disposing( rEvt );
} catch ( RuntimeException & )
{ // be robust, if e.g. a remote bridge has disposed already. // there is no way to delegate the error to the caller :o(.
}
}
}
void OInterfaceContainerHelper2::clear()
{
MutexGuard aGuard( rMutex ); // Release container, in case new entries come while disposing
OSL_ENSURE( !bIsList || bInUse, "OInterfaceContainerHelper2 not in use" ); if (bInUse)
copyAndResetInUse(); if (bIsList) delete aData.pAsVector; elseif (aData.pAsInterface)
aData.pAsInterface->release();
aData.pAsInterface = nullptr;
bIsList = false;
}
std::vector< css::uno::Type > OMultiTypeInterfaceContainerHelper2::getContainedTypes() const
{
::osl::MutexGuard aGuard( rMutex );
std::vector< Type > aInterfaceTypes;
aInterfaceTypes.reserve( m_aMap.size() ); for (constauto& rItem : m_aMap)
{ // are interfaces added to this container? if( rItem.second->getLength() ) // yes, put the type in the array
aInterfaceTypes.push_back(rItem.first);
} return aInterfaceTypes;
}
// search container with id nUik auto iter = findType( rKey ); // container found? if( iter != m_aMap.end() ) return (*iter).second->removeInterface( rListener );
// no container with this id. Always return 0 return 0;
}
t_type2ptr::size_type i = 0; for (constauto& rItem : m_aMap)
{
ppListenerContainers[i++] = rItem.second.get();
}
}
}
// create a copy, because do not fire event in a guarded section for( t_type2ptr::size_type i = 0; i < nSize; i++ )
{ if( ppListenerContainers[i] )
ppListenerContainers[i]->disposeAndClear( rEvt );
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.