23 #include <osl/diagnose.h>
28 #include <com/sun/star/lang/DisposedException.hpp>
64 void SAL_CALL acquire() noexcept override;
65 void SAL_CALL release() noexcept override;
69 void SAL_CALL addReference( const css::
uno::
Reference< css::
uno::XReference >& xRef ) override;
70 void SAL_CALL removeReference( const css::
uno::
Reference< css::
uno::XReference >& xRef ) override;
92 rType, static_cast< XAdapter * >(
this ), static_cast< XInterface * >(
this ) );
96 void SAL_CALL OWeakConnectionPoint::acquire() noexcept
100 assert(m_aRefCount != -1);
102 osl_atomic_increment( &m_aRefCount );
106 void SAL_CALL OWeakConnectionPoint::release() noexcept
108 if (! osl_atomic_decrement( &m_aRefCount ))
117 void OWeakConnectionPoint::dispose()
119 std::vector<Reference<XReference>> aCopy;
127 aCopy.swap(m_aReferences);
136 catch (css::lang::DisposedException &) {}
154 std::scoped_lock guard(*gpWeakMutex);
159 oslInterlockedCount
n = osl_atomic_increment( &m_pObject->m_refCount );
164 osl_atomic_decrement( &m_pObject->m_refCount );
174 osl_atomic_decrement( &m_pObject->m_refCount );
182 std::scoped_lock aGuard(*gpWeakMutex);
183 m_aReferences.push_back( rRef );
189 std::scoped_lock aGuard(*gpWeakMutex);
193 auto it = std::find_if(m_aReferences.rbegin(), m_aReferences.rend(),
195 if (it != m_aReferences.rend()) {
196 m_aReferences.erase( it.base()-1 );
200 it = std::find(m_aReferences.rbegin(), m_aReferences.rend(), rRef);
201 if ( it != m_aReferences.rend() )
202 m_aReferences.erase( it.base()-1 );
213 static_cast< XWeak * >(
this ), static_cast< XInterface * >(
this ) );
217 void SAL_CALL OWeakObject::acquire() noexcept
223 void SAL_CALL OWeakObject::release() noexcept
225 if (osl_atomic_decrement( &
m_refCount ) == 0) {
228 disposeWeakConnectionPoint();
234 void OWeakObject::disposeWeakConnectionPoint()
236 OSL_PRECOND(
m_refCount == 0,
"OWeakObject::disposeWeakConnectionPoint: only to be called with a ref count of 0!" );
237 if (m_pWeakConnectionPoint !=
nullptr) {
239 m_pWeakConnectionPoint =
nullptr;
250 OWeakObject::~OWeakObject() COVERITY_NOEXCEPT_FALSE
257 if (!m_pWeakConnectionPoint)
260 std::scoped_lock aGuard( *gpWeakMutex );
261 if( !m_pWeakConnectionPoint )
265 m_pWeakConnectionPoint = p;
269 return m_pWeakConnectionPoint;
275 OWeakAggObject::~OWeakAggObject()
280 void OWeakAggObject::acquire() noexcept
286 OWeakObject::acquire();
290 void OWeakAggObject::release() noexcept
296 OWeakObject::release();
303 return (x.is() ? x->queryInterface( rType ) : queryAggregation( rType ));
307 Any OWeakAggObject::queryAggregation(
const Type & rType )
311 static_cast< XInterface * >( static_cast< OWeakObject * >(
this ) ),
312 static_cast< XAggregation * >(
this ),
313 static_cast< XWeak * >(
this ) );
319 xDelegator = rDelegator;
343 void SAL_CALL acquire() noexcept
override;
344 void SAL_CALL release() noexcept
override;
347 void SAL_CALL
dispose()
override;
405 rType, static_cast< XReference * >(
this ), static_cast< XInterface * >(
this ) );
434 xAdp->removeReference(static_cast<XReference*>(
this));
487 if (
this == &rWeakRef)
499 std::swap(m_pImpl, other.m_pImpl);
545 xAdp =
m_pImpl->m_XWeakConnectionPoint;
549 return xAdp->queryAdapted();
static std::mutex * gpWeakMutex
void SAL_CALL throwException(Any const &exc)
void SAL_CALL dispose() override
Any SAL_CALL queryInterface(const Type &rType) override
void SAL_CALL release() noexcept override
WeakReferenceHelper()
Default ctor.
Reference< XAdapter > m_XWeakConnectionPoint
The connection point of the weak object, guarded by getWeakMutex()
void SAL_CALL acquire() noexcept override
std::vector< Reference< XReference > > m_aReferences
The container to hold the weak references.
Any SAL_CALL getCaughtException()
Use this function to get the dynamic type of a caught C++-UNO exception; completes the above function...
WeakReferenceHelper &SAL_CALL operator=(const WeakReferenceHelper &rWeakRef)
Releases this reference and takes over rWeakRef.
virtual ~OWeakRefListener()
The WeakReferenceHelper holds a weak reference to an object.
OWeakConnectionPoint(OWeakObject *pObj)
Hold the weak object without an acquire (only the pointer).
void dispose()
Called from the weak object if the reference count goes to zero.
Base class to implement a UNO object supporting weak references, i.e.
void SAL_CALL release() noexcept override
oslInterlockedCount m_aRefCount
The reference counter.
oslInterlockedCount m_aRefCount
The reference counter.
void SAL_CALL clear()
Releases this reference.
css::uno::Reference< css::uno::XInterface > SAL_CALL get() const
Gets a hard reference to the object.
OWeakObject * m_pObject
The weak object.
~WeakReferenceHelper()
Releases this reference.
#define SAL_WARN(area, stream)
OWeakRefListener(const Reference< XInterface > &xInt)
void SAL_CALL acquire() noexcept override
css::uno::Any SAL_CALL queryInterface(const css::uno::Type &rType, Interface1 *p1)
Compares demanded type to given template argument types.