diff options
author | Ingrid Halama <iha@openoffice.org> | 2010-05-28 16:13:48 +0200 |
---|---|---|
committer | Ingrid Halama <iha@openoffice.org> | 2010-05-28 16:13:48 +0200 |
commit | 5347bfcf72ac68be94b565f760210463308a0cb4 (patch) | |
tree | 3644855d35f18c8634e8254dc2a4fa84ac6cfac5 /chart2/source/model/main/Diagram.cxx | |
parent | d6616fb95ac01bd8767935ac7a5adcb489666936 (diff) |
chart47: #i79087# prevent deadlock + prevent null pointer access
Diffstat (limited to 'chart2/source/model/main/Diagram.cxx')
-rw-r--r-- | chart2/source/model/main/Diagram.cxx | 171 |
1 files changed, 98 insertions, 73 deletions
diff --git a/chart2/source/model/main/Diagram.cxx b/chart2/source/model/main/Diagram.cxx index f74764c398ef..467e0feba5b4 100644 --- a/chart2/source/model/main/Diagram.cxx +++ b/chart2/source/model/main/Diagram.cxx @@ -300,72 +300,91 @@ Diagram::~Diagram() uno::Reference< beans::XPropertySet > SAL_CALL Diagram::getWall() throw (uno::RuntimeException) { - // /-- - MutexGuard aGuard( GetMutex() ); - if( ! m_xWall.is()) + uno::Reference< beans::XPropertySet > xRet; + bool bAddListener = false; { - m_xWall.set( new Wall()); - ModifyListenerHelper::addListener( m_xWall, m_xModifyEventForwarder ); + MutexGuard aGuard( GetMutex() ); + if( !m_xWall.is() ) + { + m_xWall.set( new Wall() ); + bAddListener = true; + } + xRet = m_xWall; } - return m_xWall; - // \-- + if(bAddListener) + ModifyListenerHelper::addListener( xRet, m_xModifyEventForwarder ); + return xRet; } uno::Reference< beans::XPropertySet > SAL_CALL Diagram::getFloor() throw (uno::RuntimeException) { - // /-- - MutexGuard aGuard( GetMutex() ); - if( ! m_xFloor.is()) + uno::Reference< beans::XPropertySet > xRet; + bool bAddListener = false; { - m_xFloor.set( new Wall()); - ModifyListenerHelper::addListener( m_xFloor, m_xModifyEventForwarder ); + MutexGuard aGuard( GetMutex() ); + if( !m_xFloor.is() ) + { + m_xFloor.set( new Wall() ); + bAddListener = true; + } + xRet = m_xFloor; } - return m_xFloor; - // \-- + if(bAddListener) + ModifyListenerHelper::addListener( xRet, m_xModifyEventForwarder ); + return xRet; } uno::Reference< chart2::XLegend > SAL_CALL Diagram::getLegend() throw (uno::RuntimeException) { - // /-- MutexGuard aGuard( GetMutex() ); return m_xLegend; - // \-- } -void SAL_CALL Diagram::setLegend( const uno::Reference< chart2::XLegend >& xLegend ) +void SAL_CALL Diagram::setLegend( const uno::Reference< chart2::XLegend >& xNewLegend ) throw (uno::RuntimeException) { - // /-- - ::osl::ClearableMutexGuard aGuard( GetMutex() ); - if( xLegend != m_xLegend ) + Reference< chart2::XLegend > xOldLegend; { - if( m_xLegend.is()) - ModifyListenerHelper::removeListener( m_xLegend, m_xModifyEventForwarder ); - m_xLegend = xLegend; - if( m_xLegend.is()) - ModifyListenerHelper::addListener( m_xLegend, m_xModifyEventForwarder ); - aGuard.clear(); - // \-- - fireModifyEvent(); + MutexGuard aGuard( GetMutex() ); + if( m_xLegend == xNewLegend ) + return; + xOldLegend = m_xLegend; + m_xLegend = xNewLegend; } + if( xOldLegend.is()) + ModifyListenerHelper::removeListener( xOldLegend, m_xModifyEventForwarder ); + if( xNewLegend.is()) + ModifyListenerHelper::addListener( xNewLegend, m_xModifyEventForwarder ); + fireModifyEvent(); } Reference< chart2::XColorScheme > SAL_CALL Diagram::getDefaultColorScheme() throw (uno::RuntimeException) { - if( ! m_xColorScheme.is()) + Reference< chart2::XColorScheme > xRet; + { + MutexGuard aGuard( GetMutex() ); + xRet = m_xColorScheme; + } + + if( !xRet.is()) { - m_xColorScheme.set( createConfigColorScheme( m_xContext )); + xRet.set( createConfigColorScheme( m_xContext )); + MutexGuard aGuard( GetMutex() ); + m_xColorScheme = xRet; } - return m_xColorScheme; + return xRet; } void SAL_CALL Diagram::setDefaultColorScheme( const Reference< chart2::XColorScheme >& xColorScheme ) throw (uno::RuntimeException) { - m_xColorScheme.set( xColorScheme ); + { + MutexGuard aGuard( GetMutex() ); + m_xColorScheme.set( xColorScheme ); + } fireModifyEvent(); } @@ -373,27 +392,26 @@ void SAL_CALL Diagram::setDefaultColorScheme( const Reference< chart2::XColorSch uno::Reference< chart2::XTitle > SAL_CALL Diagram::getTitleObject() throw (uno::RuntimeException) { - // /-- MutexGuard aGuard( GetMutex() ); return m_xTitle; - // \-- } -void SAL_CALL Diagram::setTitleObject( const uno::Reference< chart2::XTitle >& Title ) +void SAL_CALL Diagram::setTitleObject( const uno::Reference< chart2::XTitle >& xNewTitle ) throw (uno::RuntimeException) { - // /-- - ::osl::ClearableMutexGuard aGuard( GetMutex() ); - - if( m_xTitle != Title ) + Reference< chart2::XTitle > xOldTitle; { - ModifyListenerHelper::removeListener( m_xTitle, m_xModifyEventForwarder ); - m_xTitle = Title; - ModifyListenerHelper::addListener( m_xTitle, m_xModifyEventForwarder ); - // \-- - aGuard.clear(); - fireModifyEvent(); + MutexGuard aGuard( GetMutex() ); + if( m_xTitle == xNewTitle ) + return; + xOldTitle = m_xTitle; + m_xTitle = xNewTitle; } + if( xOldTitle.is()) + ModifyListenerHelper::removeListener( xOldTitle, m_xModifyEventForwarder ); + if( xNewTitle.is()) + ModifyListenerHelper::addListener( xNewTitle, m_xModifyEventForwarder ); + fireModifyEvent(); } // ____ X3DDefaultSetter ____ @@ -421,18 +439,19 @@ void SAL_CALL Diagram::addCoordinateSystem( throw (lang::IllegalArgumentException, uno::RuntimeException) { - if( ::std::find( m_aCoordSystems.begin(), m_aCoordSystems.end(), aCoordSys ) - != m_aCoordSystems.end()) - throw lang::IllegalArgumentException(); - - if( m_aCoordSystems.size()>=1 ) { - OSL_ENSURE( false, "more than one coordinatesystem is not supported yet by the fileformat" ); - return; - } - - m_aCoordSystems.push_back( aCoordSys ); + MutexGuard aGuard( GetMutex() ); + if( ::std::find( m_aCoordSystems.begin(), m_aCoordSystems.end(), aCoordSys ) + != m_aCoordSystems.end()) + throw lang::IllegalArgumentException(); + if( m_aCoordSystems.size()>=1 ) + { + OSL_ENSURE( false, "more than one coordinatesystem is not supported yet by the fileformat" ); + return; + } + m_aCoordSystems.push_back( aCoordSys ); + } ModifyListenerHelper::addListener( aCoordSys, m_xModifyEventForwarder ); fireModifyEvent(); } @@ -442,15 +461,16 @@ void SAL_CALL Diagram::removeCoordinateSystem( throw (container::NoSuchElementException, uno::RuntimeException) { - ::std::vector< uno::Reference< chart2::XCoordinateSystem > >::iterator - aIt( ::std::find( m_aCoordSystems.begin(), m_aCoordSystems.end(), aCoordSys )); - if( aIt == m_aCoordSystems.end()) - throw container::NoSuchElementException( - C2U( "The given coordinate-system is no element of the container" ), - static_cast< uno::XWeak * >( this )); - - m_aCoordSystems.erase( aIt ); - + { + MutexGuard aGuard( GetMutex() ); + ::std::vector< uno::Reference< chart2::XCoordinateSystem > >::iterator + aIt( ::std::find( m_aCoordSystems.begin(), m_aCoordSystems.end(), aCoordSys )); + if( aIt == m_aCoordSystems.end()) + throw container::NoSuchElementException( + C2U( "The given coordinate-system is no element of the container" ), + static_cast< uno::XWeak * >( this )); + m_aCoordSystems.erase( aIt ); + } ModifyListenerHelper::removeListener( aCoordSys, m_xModifyEventForwarder ); fireModifyEvent(); } @@ -458,6 +478,7 @@ void SAL_CALL Diagram::removeCoordinateSystem( uno::Sequence< uno::Reference< chart2::XCoordinateSystem > > SAL_CALL Diagram::getCoordinateSystems() throw (uno::RuntimeException) { + MutexGuard aGuard( GetMutex() ); return ContainerHelper::ContainerToSequence( m_aCoordSystems ); } @@ -466,17 +487,20 @@ void SAL_CALL Diagram::setCoordinateSystems( throw (lang::IllegalArgumentException, uno::RuntimeException) { - Sequence< Reference< chart2::XCoordinateSystem > > aNew(aCoordinateSystems); - - if( aNew.getLength()>1 ) + tCoordinateSystemContainerType aNew; + tCoordinateSystemContainerType aOld; + if( aCoordinateSystems.getLength()>0 ) { - OSL_ENSURE( false, "more than one coordinatesystem is not supported yet by the fileformat" ); - aNew.realloc(1); + OSL_ENSURE( aCoordinateSystems.getLength()<=1, "more than one coordinatesystem is not supported yet by the fileformat" ); + aNew.push_back( aCoordinateSystems[0] ); } - - ModifyListenerHelper::removeListenerFromAllElements( m_aCoordSystems, m_xModifyEventForwarder ); - m_aCoordSystems = ContainerHelper::SequenceToVector( aNew ); - ModifyListenerHelper::addListenerToAllElements( m_aCoordSystems, m_xModifyEventForwarder ); + { + MutexGuard aGuard( GetMutex() ); + std::swap( aOld, m_aCoordSystems ); + m_aCoordSystems = aNew; + } + ModifyListenerHelper::removeListenerFromAllElements( aOld, m_xModifyEventForwarder ); + ModifyListenerHelper::addListenerToAllElements( aNew, m_xModifyEventForwarder ); fireModifyEvent(); } @@ -484,6 +508,7 @@ void SAL_CALL Diagram::setCoordinateSystems( Reference< util::XCloneable > SAL_CALL Diagram::createClone() throw (uno::RuntimeException) { + MutexGuard aGuard( GetMutex() ); return Reference< util::XCloneable >( new Diagram( *this )); } |