diff options
Diffstat (limited to 'chart2/source/controller/main/CommandDispatch.cxx')
-rw-r--r-- | chart2/source/controller/main/CommandDispatch.cxx | 74 |
1 files changed, 23 insertions, 51 deletions
diff --git a/chart2/source/controller/main/CommandDispatch.cxx b/chart2/source/controller/main/CommandDispatch.cxx index 22e0a52c204f..e4f8b1acebcf 100644 --- a/chart2/source/controller/main/CommandDispatch.cxx +++ b/chart2/source/controller/main/CommandDispatch.cxx @@ -17,40 +17,21 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ -#include "CommandDispatch.hxx" +#include <sal/config.h> + +#include <CommandDispatch.hxx> #include <com/sun/star/util/URLTransformer.hpp> -#include <tools/diagnose_ex.h> using namespace ::com::sun::star; using ::com::sun::star::uno::Reference; using ::com::sun::star::uno::Sequence; -namespace -{ -template< class Map > - void lcl_DisposeAndClearAndDeleteAllMapElements( - Map & rMap, - const Reference< uno::XInterface > & xEventSource ) -{ - for( const auto& rElement : rMap ) - { - if( rElement.second ) - { - rElement.second->disposeAndClear( xEventSource ); - delete rElement.second; - } - } -} - -} // anonymous namespace - namespace chart { CommandDispatch::CommandDispatch( const Reference< uno::XComponentContext > & xContext ) : - impl::CommandDispatch_Base( m_aMutex ), m_xContext( xContext ) { } @@ -63,9 +44,11 @@ void CommandDispatch::initialize() // ____ WeakComponentImplHelperBase ____ /// is called when this is disposed -void SAL_CALL CommandDispatch::disposing() +void CommandDispatch::disposing(std::unique_lock<std::mutex>& rGuard) { - lcl_DisposeAndClearAndDeleteAllMapElements( m_aListeners, static_cast< cppu::OWeakObject* >( this )); + Reference< uno::XInterface > xEventSource(static_cast< cppu::OWeakObject* >( this )); + for( auto& rElement : m_aListeners ) + rElement.second.disposeAndClear( rGuard, xEventSource ); m_aListeners.clear(); } @@ -75,24 +58,29 @@ void SAL_CALL CommandDispatch::dispatch( const util::URL& /* URL */, const Seque void SAL_CALL CommandDispatch::addStatusListener( const Reference< frame::XStatusListener >& Control, const util::URL& URL ) { - tListenerMap::iterator aIt( m_aListeners.find( URL.Complete )); - if( aIt == m_aListeners.end()) { - aIt = m_aListeners.insert( - m_aListeners.begin(), - tListenerMap::value_type( URL.Complete, new ::comphelper::OInterfaceContainerHelper2( m_aMutex ))); - } - OSL_ASSERT( aIt != m_aListeners.end()); + std::unique_lock g(m_aMutex); + tListenerMap::iterator aIt( m_aListeners.find( URL.Complete )); + if( aIt == m_aListeners.end()) + { + aIt = m_aListeners.emplace( + std::piecewise_construct, + std::forward_as_tuple(URL.Complete), + std::forward_as_tuple()).first; + } + assert( aIt != m_aListeners.end()); - aIt->second->addInterface( Control ); + aIt->second.addInterface( g, Control ); + } fireStatusEvent( URL.Complete, Control ); } void SAL_CALL CommandDispatch::removeStatusListener( const Reference< frame::XStatusListener >& Control, const util::URL& URL ) { + std::unique_lock g(m_aMutex); tListenerMap::iterator aIt( m_aListeners.find( URL.Complete )); if( aIt != m_aListeners.end()) - (*aIt).second->removeInterface( Control ); + (*aIt).second.removeInterface( g, Control ); } // ____ XModifyListener ____ @@ -143,24 +131,8 @@ void CommandDispatch::fireStatusEventForURL( tListenerMap::iterator aIt( m_aListeners.find( aURL.Complete )); if( aIt != m_aListeners.end()) { - if( aIt->second ) - { - ::comphelper::OInterfaceIteratorHelper2 aIntfIt( *((*aIt).second) ); - - while( aIntfIt.hasMoreElements()) - { - Reference< frame::XStatusListener > xListener( aIntfIt.next(), uno::UNO_QUERY ); - try - { - if( xListener.is()) - xListener->statusChanged( aEventToSend ); - } - catch( const uno::Exception & ) - { - DBG_UNHANDLED_EXCEPTION("chart2"); - } - } - } + std::unique_lock g(m_aMutex); + aIt->second.notifyEach(g, &css::frame::XStatusListener::statusChanged, aEventToSend); } } } |