Kaydet (Commit) a5dbe5a8 authored tarafından Noel Grandin's avatar Noel Grandin

use rtl::Reference in svl,sfx2

instead of manual ref-counting

Change-Id: Icb6472ffadfb57c9723b26f6f247e78fff45e528
Reviewed-on: https://gerrit.libreoffice.org/43193Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarNoel Grandin <noel.grandin@collabora.co.uk>
üst 62fc2167
......@@ -1567,16 +1567,15 @@ SfxItemState SfxBindings::QueryState( sal_uInt16 nSlot, std::unique_ptr<SfxPoolI
}
SfxItemState eState = SfxItemState::SET;
BindDispatch_Impl *pBind = new BindDispatch_Impl( xDisp, aURL, pCache, pSlot );
pBind->acquire();
xDisp->addStatusListener( pBind, aURL );
if ( !pBind->GetStatus().IsEnabled )
rtl::Reference<BindDispatch_Impl> xBind(new BindDispatch_Impl( xDisp, aURL, pCache, pSlot ));
xDisp->addStatusListener( xBind.get(), aURL );
if ( !xBind->GetStatus().IsEnabled )
{
eState = SfxItemState::DISABLED;
}
else
{
css::uno::Any aAny = pBind->GetStatus().State;
css::uno::Any aAny = xBind->GetStatus().State;
css::uno::Type aType = aAny.getValueType();
if ( aType == cppu::UnoType<bool>::get() )
......@@ -1607,8 +1606,8 @@ SfxItemState SfxBindings::QueryState( sal_uInt16 nSlot, std::unique_ptr<SfxPoolI
rpState.reset(new SfxVoidItem( nSlot ));
}
xDisp->removeStatusListener( pBind, aURL );
pBind->Release();
xDisp->removeStatusListener( xBind.get(), aURL );
xBind.clear();
if ( bDeleteCache )
DELETEZ( pCache );
return eState;
......
......@@ -145,16 +145,13 @@ void SAL_CALL BindDispatch_Impl::statusChanged( const css::frame::FeatureStateE
}
}
void BindDispatch_Impl::Release()
BindDispatch_Impl::~BindDispatch_Impl()
{
if ( xDisp.is() )
{
xDisp->removeStatusListener( static_cast<css::frame::XStatusListener*>(this), aURL );
xDisp.clear();
}
pCache = nullptr;
release();
}
......@@ -180,7 +177,6 @@ sal_Int16 BindDispatch_Impl::Dispatch( const css::uno::Sequence < css::beans::Pr
// This constructor for an invalid cache that is updated in the first request.
SfxStateCache::SfxStateCache( sal_uInt16 nFuncId ):
pDispatch( nullptr ),
nId(nFuncId),
pInternalController(nullptr),
pController(nullptr),
......@@ -201,11 +197,6 @@ SfxStateCache::~SfxStateCache()
DBG_ASSERT( pController == nullptr && pInternalController == nullptr, "there are still Controllers registered" );
if ( !IsInvalidItem(pLastItem) )
delete pLastItem;
if ( pDispatch )
{
pDispatch->Release();
pDispatch = nullptr;
}
}
......@@ -217,11 +208,7 @@ void SfxStateCache::Invalidate( bool bWithMsg )
{
bSlotDirty = true;
aSlotServ.SetSlot( nullptr );
if ( pDispatch )
{
pDispatch->Release();
pDispatch = nullptr;
}
mxDispatch.clear();
}
}
......@@ -236,7 +223,7 @@ const SfxSlotServer* SfxStateCache::GetSlotServer( SfxDispatcher &rDispat , cons
// get the SlotServer; we need it for internal controllers anyway, but also in most cases
rDispat.FindServer_( nId, aSlotServ, false );
DBG_ASSERT( !pDispatch, "Old Dispatch not removed!" );
DBG_ASSERT( !mxDispatch.is(), "Old Dispatch not removed!" );
// we don't need to check the dispatch provider if we only have an internal controller
if ( xProv.is() )
......@@ -291,13 +278,12 @@ const SfxSlotServer* SfxStateCache::GetSlotServer( SfxDispatcher &rDispat , cons
}
// so the dispatch object isn't a SfxDispatcher wrapper or it is one, but it uses another dispatcher, but not rDispat
pDispatch = new BindDispatch_Impl( xDisp, aURL, this, pSlot );
pDispatch->acquire();
mxDispatch = new BindDispatch_Impl( xDisp, aURL, this, pSlot );
// flags must be set before adding StatusListener because the dispatch object will set the state
bSlotDirty = false;
bCtrlDirty = true;
xDisp->addStatusListener( pDispatch, aURL );
xDisp->addStatusListener( mxDispatch.get(), aURL );
}
else if ( rDispat.GetFrame() )
{
......@@ -367,7 +353,7 @@ void SfxStateCache::SetVisibleState( bool bShow )
}
// Update Controller
if ( !pDispatch && pController )
if ( !mxDispatch.is() && pController )
{
for ( SfxControllerItem *pCtrl = pController;
pCtrl;
......@@ -416,7 +402,7 @@ void SfxStateCache::SetState_Impl
if ( bNotify )
{
// Update Controller
if ( !pDispatch && pController )
if ( !mxDispatch.is() && pController )
{
for ( SfxControllerItem *pCtrl = pController;
pCtrl;
......@@ -454,7 +440,7 @@ void SfxStateCache::SetCachedState( bool bAlways )
if ( bAlways || ( !bItemDirty && !bSlotDirty ) )
{
// Update Controller
if ( !pDispatch && pController )
if ( !mxDispatch.is() && pController )
{
for ( SfxControllerItem *pCtrl = pController;
pCtrl;
......@@ -473,24 +459,24 @@ void SfxStateCache::SetCachedState( bool bAlways )
css::uno::Reference< css::frame::XDispatch > SfxStateCache::GetDispatch() const
{
if ( pDispatch )
return pDispatch->xDisp;
if ( mxDispatch.is() )
return mxDispatch->xDisp;
return css::uno::Reference< css::frame::XDispatch > ();
}
sal_Int16 SfxStateCache::Dispatch( const SfxItemSet* pSet, bool bForceSynchron )
{
// protect pDispatch against destruction in the call
css::uno::Reference < css::frame::XStatusListener > xKeepAlive( pDispatch );
rtl::Reference<BindDispatch_Impl> xKeepAlive( mxDispatch );
sal_Int16 eRet = css::frame::DispatchResultState::DONTKNOW;
if ( pDispatch )
if ( mxDispatch.is() )
{
uno::Sequence < beans::PropertyValue > aArgs;
if (pSet)
TransformItems( nId, *pSet, aArgs );
eRet = pDispatch->Dispatch( aArgs, bForceSynchron );
eRet = mxDispatch->Dispatch( aArgs, bForceSynchron );
}
return eRet;
......
......@@ -46,11 +46,11 @@ public:
const css::uno::Reference< css::frame::XDispatch > & rDisp,
const css::util::URL& rURL,
SfxStateCache* pStateCache, const SfxSlot* pSlot );
~BindDispatch_Impl() override;
virtual void SAL_CALL statusChanged( const css::frame::FeatureStateEvent& Event ) override;
virtual void SAL_CALL disposing( const css::lang::EventObject& Source ) override;
virtual void SAL_CALL statusChanged( const css::frame::FeatureStateEvent& Event ) override;
virtual void SAL_CALL disposing( const css::lang::EventObject& Source ) override;
void Release();
const css::frame::FeatureStateEvent& GetStatus() const { return aStatus;}
sal_Int16 Dispatch( const css::uno::Sequence < css::beans::PropertyValue >& aProps, bool bForceSynchron );
};
......@@ -58,7 +58,8 @@ public:
class SfxStateCache
{
friend class BindDispatch_Impl;
BindDispatch_Impl* pDispatch;
rtl::Reference<BindDispatch_Impl>
mxDispatch;
sal_uInt16 nId; // Slot-Id
SfxControllerItem* pInternalController;
css::uno::Reference < css::frame::XDispatch > xMyDispatch;
......
......@@ -346,15 +346,13 @@ uno::Sequence<OUString> SAL_CALL SvNumberFormatterServiceObj::getSupportedServic
}
SvNumberFormatsObj::SvNumberFormatsObj( SvNumberFormatsSupplierObj& _rParent, ::comphelper::SharedMutex const & _rMutex )
:rSupplier( _rParent )
:m_xSupplier( &_rParent )
,m_aMutex( _rMutex )
{
rSupplier.acquire();
}
SvNumberFormatsObj::~SvNumberFormatsObj()
{
rSupplier.release();
}
// XNumberFormats
......@@ -363,12 +361,12 @@ uno::Reference<beans::XPropertySet> SAL_CALL SvNumberFormatsObj::getByKey( sal_I
{
::osl::MutexGuard aGuard( m_aMutex );
SvNumberFormatter* pFormatter = rSupplier.GetNumberFormatter();
SvNumberFormatter* pFormatter = m_xSupplier->GetNumberFormatter();
const SvNumberformat* pFormat = pFormatter ? pFormatter->GetEntry(nKey) : nullptr;
if (!pFormat)
throw uno::RuntimeException();
return new SvNumberFormatObj( rSupplier, nKey, m_aMutex );
return new SvNumberFormatObj( *m_xSupplier, nKey, m_aMutex );
}
uno::Sequence<sal_Int32> SAL_CALL SvNumberFormatsObj::queryKeys( sal_Int16 nType,
......@@ -377,7 +375,7 @@ uno::Sequence<sal_Int32> SAL_CALL SvNumberFormatsObj::queryKeys( sal_Int16 nType
{
::osl::MutexGuard aGuard( m_aMutex );
SvNumberFormatter* pFormatter = rSupplier.GetNumberFormatter();
SvNumberFormatter* pFormatter = m_xSupplier->GetNumberFormatter();
if ( !pFormatter )
throw uno::RuntimeException();
......@@ -402,7 +400,7 @@ sal_Int32 SAL_CALL SvNumberFormatsObj::queryKey( const OUString& aFormat,
{
::osl::MutexGuard aGuard( m_aMutex );
SvNumberFormatter* pFormatter = rSupplier.GetNumberFormatter();
SvNumberFormatter* pFormatter = m_xSupplier->GetNumberFormatter();
if (!pFormatter)
throw uno::RuntimeException();
......@@ -421,7 +419,7 @@ sal_Int32 SAL_CALL SvNumberFormatsObj::addNew( const OUString& aFormat,
::osl::MutexGuard aGuard( m_aMutex );
sal_Int32 nRet = 0;
SvNumberFormatter* pFormatter = rSupplier.GetNumberFormatter();
SvNumberFormatter* pFormatter = m_xSupplier->GetNumberFormatter();
if (!pFormatter)
throw uno::RuntimeException();
......@@ -450,7 +448,7 @@ sal_Int32 SAL_CALL SvNumberFormatsObj::addNewConverted( const OUString& aFormat,
::osl::MutexGuard aGuard( m_aMutex );
sal_Int32 nRet = 0;
SvNumberFormatter* pFormatter = rSupplier.GetNumberFormatter();
SvNumberFormatter* pFormatter = m_xSupplier->GetNumberFormatter();
if (!pFormatter)
throw uno::RuntimeException();
......@@ -476,7 +474,7 @@ sal_Int32 SAL_CALL SvNumberFormatsObj::addNewConverted( const OUString& aFormat,
void SAL_CALL SvNumberFormatsObj::removeByKey( sal_Int32 nKey )
{
::osl::MutexGuard aGuard( m_aMutex );
SvNumberFormatter* pFormatter = rSupplier.GetNumberFormatter();
SvNumberFormatter* pFormatter = m_xSupplier->GetNumberFormatter();
if (pFormatter)
{
......@@ -492,7 +490,7 @@ OUString SAL_CALL SvNumberFormatsObj::generateFormat( sal_Int32 nBaseKey,
{
::osl::MutexGuard aGuard( m_aMutex );
SvNumberFormatter* pFormatter = rSupplier.GetNumberFormatter();
SvNumberFormatter* pFormatter = m_xSupplier->GetNumberFormatter();
if (!pFormatter)
throw uno::RuntimeException();
......@@ -507,7 +505,7 @@ sal_Int32 SAL_CALL SvNumberFormatsObj::getStandardIndex( const lang::Locale& nLo
{
::osl::MutexGuard aGuard( m_aMutex );
SvNumberFormatter* pFormatter = rSupplier.GetNumberFormatter();
SvNumberFormatter* pFormatter = m_xSupplier->GetNumberFormatter();
if (!pFormatter)
throw uno::RuntimeException();
......@@ -520,7 +518,7 @@ sal_Int32 SAL_CALL SvNumberFormatsObj::getStandardFormat( sal_Int16 nType, const
{
::osl::MutexGuard aGuard( m_aMutex );
SvNumberFormatter* pFormatter = rSupplier.GetNumberFormatter();
SvNumberFormatter* pFormatter = m_xSupplier->GetNumberFormatter();
if (!pFormatter)
throw uno::RuntimeException();
......@@ -536,7 +534,7 @@ sal_Int32 SAL_CALL SvNumberFormatsObj::getFormatIndex( sal_Int16 nIndex, const l
{
::osl::MutexGuard aGuard( m_aMutex );
SvNumberFormatter* pFormatter = rSupplier.GetNumberFormatter();
SvNumberFormatter* pFormatter = m_xSupplier->GetNumberFormatter();
if (!pFormatter)
throw uno::RuntimeException();
......@@ -556,7 +554,7 @@ sal_Int32 SAL_CALL SvNumberFormatsObj::getFormatForLocale( sal_Int32 nKey, const
{
::osl::MutexGuard aGuard( m_aMutex );
SvNumberFormatter* pFormatter = rSupplier.GetNumberFormatter();
SvNumberFormatter* pFormatter = m_xSupplier->GetNumberFormatter();
if (!pFormatter)
throw uno::RuntimeException();
......@@ -583,16 +581,14 @@ uno::Sequence<OUString> SAL_CALL SvNumberFormatsObj::getSupportedServiceNames()
}
SvNumberFormatObj::SvNumberFormatObj( SvNumberFormatsSupplierObj& rParent, sal_uLong nK, const ::comphelper::SharedMutex& _rMutex )
:rSupplier( rParent )
:m_xSupplier( &rParent )
,nKey( nK )
,m_aMutex( _rMutex )
{
rSupplier.acquire();
}
SvNumberFormatObj::~SvNumberFormatObj()
{
rSupplier.release();
}
// XPropertySet
......@@ -616,7 +612,7 @@ uno::Any SAL_CALL SvNumberFormatObj::getPropertyValue( const OUString& aProperty
::osl::MutexGuard aGuard( m_aMutex );
uno::Any aRet;
SvNumberFormatter* pFormatter = rSupplier.GetNumberFormatter();
SvNumberFormatter* pFormatter = m_xSupplier->GetNumberFormatter();
const SvNumberformat* pFormat = pFormatter ? pFormatter->GetEntry(nKey) : nullptr;
if (!pFormat)
throw uno::RuntimeException();
......@@ -730,7 +726,7 @@ uno::Sequence<beans::PropertyValue> SAL_CALL SvNumberFormatObj::getPropertyValue
{
::osl::MutexGuard aGuard( m_aMutex );
SvNumberFormatter* pFormatter = rSupplier.GetNumberFormatter();
SvNumberFormatter* pFormatter = m_xSupplier->GetNumberFormatter();
const SvNumberformat* pFormat = pFormatter ? pFormatter->GetEntry(nKey) : nullptr;
if (!pFormat)
throw uno::RuntimeException();
......@@ -796,15 +792,13 @@ uno::Sequence<OUString> SAL_CALL SvNumberFormatObj::getSupportedServiceNames()
}
SvNumberFormatSettingsObj::SvNumberFormatSettingsObj( SvNumberFormatsSupplierObj& rParent, const ::comphelper::SharedMutex& _rMutex )
:rSupplier( rParent )
:m_xSupplier( &rParent )
,m_aMutex( _rMutex )
{
rSupplier.acquire();
}
SvNumberFormatSettingsObj::~SvNumberFormatSettingsObj()
{
rSupplier.release();
}
// XPropertySet
......@@ -822,7 +816,7 @@ void SAL_CALL SvNumberFormatSettingsObj::setPropertyValue( const OUString& aProp
{
::osl::MutexGuard aGuard( m_aMutex );
SvNumberFormatter* pFormatter = rSupplier.GetNumberFormatter();
SvNumberFormatter* pFormatter = m_xSupplier->GetNumberFormatter();
if (!pFormatter)
throw uno::RuntimeException();
......@@ -860,7 +854,7 @@ uno::Any SAL_CALL SvNumberFormatSettingsObj::getPropertyValue( const OUString& a
::osl::MutexGuard aGuard( m_aMutex );
uno::Any aRet;
SvNumberFormatter* pFormatter = rSupplier.GetNumberFormatter();
SvNumberFormatter* pFormatter = m_xSupplier->GetNumberFormatter();
if (!pFormatter)
throw uno::RuntimeException();
......
......@@ -87,8 +87,8 @@ class SvNumberFormatsObj : public cppu::WeakImplHelper<
css::lang::XServiceInfo>
{
private:
SvNumberFormatsSupplierObj& rSupplier;
mutable ::comphelper::SharedMutex m_aMutex;
rtl::Reference<SvNumberFormatsSupplierObj> m_xSupplier;
mutable ::comphelper::SharedMutex m_aMutex;
public:
SvNumberFormatsObj(SvNumberFormatsSupplierObj& pParent, ::comphelper::SharedMutex const & _rMutex);
......@@ -135,8 +135,9 @@ class SvNumberFormatObj : public cppu::WeakImplHelper<
css::lang::XServiceInfo>
{
private:
SvNumberFormatsSupplierObj& rSupplier;
sal_uLong nKey;
rtl::Reference<SvNumberFormatsSupplierObj>
m_xSupplier;
sal_uLong nKey;
mutable ::comphelper::SharedMutex m_aMutex;
public:
......@@ -181,7 +182,8 @@ class SvNumberFormatSettingsObj : public cppu::WeakImplHelper<
css::lang::XServiceInfo>
{
private:
SvNumberFormatsSupplierObj& rSupplier;
rtl::Reference<SvNumberFormatsSupplierObj>
m_xSupplier;
mutable ::comphelper::SharedMutex m_aMutex;
public:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment