1*9d7e27acSAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*9d7e27acSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*9d7e27acSAndrew Rist * or more contributor license agreements. See the NOTICE file
5*9d7e27acSAndrew Rist * distributed with this work for additional information
6*9d7e27acSAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*9d7e27acSAndrew Rist * to you under the Apache License, Version 2.0 (the
8*9d7e27acSAndrew Rist * "License"); you may not use this file except in compliance
9*9d7e27acSAndrew Rist * with the License. You may obtain a copy of the License at
10*9d7e27acSAndrew Rist *
11*9d7e27acSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*9d7e27acSAndrew Rist *
13*9d7e27acSAndrew Rist * Unless required by applicable law or agreed to in writing,
14*9d7e27acSAndrew Rist * software distributed under the License is distributed on an
15*9d7e27acSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*9d7e27acSAndrew Rist * KIND, either express or implied. See the License for the
17*9d7e27acSAndrew Rist * specific language governing permissions and limitations
18*9d7e27acSAndrew Rist * under the License.
19*9d7e27acSAndrew Rist *
20*9d7e27acSAndrew Rist *************************************************************/
21*9d7e27acSAndrew Rist
22*9d7e27acSAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_cppuhelper.hxx"
26cdf0e10cSrcweir #include <cppuhelper/implbase.hxx>
27cdf0e10cSrcweir #include <cppuhelper/compbase.hxx>
28cdf0e10cSrcweir #include <osl/diagnose.h>
29cdf0e10cSrcweir #include <rtl/uuid.h>
30cdf0e10cSrcweir
31cdf0e10cSrcweir #include <com/sun/star/lang/XComponent.hpp>
32cdf0e10cSrcweir #include "com/sun/star/uno/RuntimeException.hpp"
33cdf0e10cSrcweir
34cdf0e10cSrcweir using namespace ::osl;
35cdf0e10cSrcweir using namespace ::rtl;
36cdf0e10cSrcweir using namespace ::com::sun::star;
37cdf0e10cSrcweir using namespace ::com::sun::star::uno;
38cdf0e10cSrcweir
39cdf0e10cSrcweir namespace cppu
40cdf0e10cSrcweir {
41cdf0e10cSrcweir //==================================================================================================
getImplHelperInitMutex(void)42cdf0e10cSrcweir Mutex & SAL_CALL getImplHelperInitMutex(void) SAL_THROW( () )
43cdf0e10cSrcweir {
44cdf0e10cSrcweir static Mutex * s_pMutex = 0;
45cdf0e10cSrcweir if (! s_pMutex)
46cdf0e10cSrcweir {
47cdf0e10cSrcweir MutexGuard aGuard( Mutex::getGlobalMutex() );
48cdf0e10cSrcweir if (! s_pMutex)
49cdf0e10cSrcweir {
50cdf0e10cSrcweir static Mutex s_aMutex;
51cdf0e10cSrcweir s_pMutex = & s_aMutex;
52cdf0e10cSrcweir }
53cdf0e10cSrcweir }
54cdf0e10cSrcweir return * s_pMutex;
55cdf0e10cSrcweir }
56cdf0e10cSrcweir
57cdf0e10cSrcweir // ClassDataBase
58cdf0e10cSrcweir //__________________________________________________________________________________________________
ClassDataBase()59cdf0e10cSrcweir ClassDataBase::ClassDataBase() SAL_THROW( () )
60cdf0e10cSrcweir : bOffsetsInit( sal_False )
61cdf0e10cSrcweir , nType2Offset( 0 )
62cdf0e10cSrcweir , nClassCode( 0 )
63cdf0e10cSrcweir , pTypes( 0 )
64cdf0e10cSrcweir , pId( 0 )
65cdf0e10cSrcweir {
66cdf0e10cSrcweir }
67cdf0e10cSrcweir //__________________________________________________________________________________________________
ClassDataBase(sal_Int32 nClassCode_)68cdf0e10cSrcweir ClassDataBase::ClassDataBase( sal_Int32 nClassCode_ ) SAL_THROW( () )
69cdf0e10cSrcweir : bOffsetsInit( sal_False )
70cdf0e10cSrcweir , nType2Offset( 0 )
71cdf0e10cSrcweir , nClassCode( nClassCode_ )
72cdf0e10cSrcweir , pTypes( 0 )
73cdf0e10cSrcweir , pId( 0 )
74cdf0e10cSrcweir {
75cdf0e10cSrcweir }
76cdf0e10cSrcweir //__________________________________________________________________________________________________
~ClassDataBase()77cdf0e10cSrcweir ClassDataBase::~ClassDataBase() SAL_THROW( () )
78cdf0e10cSrcweir {
79cdf0e10cSrcweir delete pTypes;
80cdf0e10cSrcweir delete pId;
81cdf0e10cSrcweir
82cdf0e10cSrcweir for ( sal_Int32 nPos = nType2Offset; nPos--; )
83cdf0e10cSrcweir {
84cdf0e10cSrcweir typelib_typedescription_release(
85cdf0e10cSrcweir (typelib_TypeDescription *)((ClassData *)this)->arType2Offset[nPos].pTD );
86cdf0e10cSrcweir }
87cdf0e10cSrcweir }
88cdf0e10cSrcweir
89cdf0e10cSrcweir // ClassData
90cdf0e10cSrcweir //__________________________________________________________________________________________________
writeTypeOffset(const Type & rType,sal_Int32 nOffset)91cdf0e10cSrcweir void ClassData::writeTypeOffset( const Type & rType, sal_Int32 nOffset ) SAL_THROW( () )
92cdf0e10cSrcweir {
93cdf0e10cSrcweir arType2Offset[nType2Offset].nOffset = nOffset;
94cdf0e10cSrcweir
95cdf0e10cSrcweir arType2Offset[nType2Offset].pTD = 0;
96cdf0e10cSrcweir typelib_typedescriptionreference_getDescription(
97cdf0e10cSrcweir (typelib_TypeDescription **)&arType2Offset[nType2Offset].pTD, rType.getTypeLibType() );
98cdf0e10cSrcweir
99cdf0e10cSrcweir if (arType2Offset[nType2Offset].pTD)
100cdf0e10cSrcweir ++nType2Offset;
101cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 1
102cdf0e10cSrcweir else
103cdf0e10cSrcweir {
104cdf0e10cSrcweir OString msg( "### cannot get type description for " );
105cdf0e10cSrcweir msg += OUStringToOString( rType.getTypeName(), RTL_TEXTENCODING_ASCII_US );
106cdf0e10cSrcweir OSL_ENSURE( sal_False, msg.getStr() );
107cdf0e10cSrcweir }
108cdf0e10cSrcweir #endif
109cdf0e10cSrcweir }
110cdf0e10cSrcweir //__________________________________________________________________________________________________
initTypeProvider()111cdf0e10cSrcweir void ClassData::initTypeProvider() SAL_THROW( () )
112cdf0e10cSrcweir {
113cdf0e10cSrcweir ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
114cdf0e10cSrcweir if (! pTypes)
115cdf0e10cSrcweir {
116cdf0e10cSrcweir // create id
117cdf0e10cSrcweir pId = new Sequence< sal_Int8 >( 16 );
118cdf0e10cSrcweir rtl_createUuid( (sal_uInt8 *)pId->getArray(), 0, sal_True );
119cdf0e10cSrcweir
120cdf0e10cSrcweir // collect types
121cdf0e10cSrcweir Sequence< Type > * types = new Sequence< Type >(
122cdf0e10cSrcweir nType2Offset + 1 + (nClassCode == 4 ? 2 : nClassCode) );
123cdf0e10cSrcweir Type * pTypeAr = types->getArray();
124cdf0e10cSrcweir
125cdf0e10cSrcweir // given types
126cdf0e10cSrcweir sal_Int32 nPos = nType2Offset;
127cdf0e10cSrcweir while (nPos--)
128cdf0e10cSrcweir pTypeAr[nPos] = ((typelib_TypeDescription *)arType2Offset[nPos].pTD)->pWeakRef;
129cdf0e10cSrcweir
130cdf0e10cSrcweir // XTypeProvider
131cdf0e10cSrcweir pTypeAr[nType2Offset] = ::getCppuType( (const Reference< lang::XTypeProvider > *)0 );
132cdf0e10cSrcweir
133cdf0e10cSrcweir // class code extra types: [[XComponent,] XWeak[, XAggregation]]
134cdf0e10cSrcweir switch (nClassCode)
135cdf0e10cSrcweir {
136cdf0e10cSrcweir case 4:
137cdf0e10cSrcweir pTypeAr[nType2Offset +2] = ::getCppuType( (const Reference< lang::XComponent > *)0 );
138cdf0e10cSrcweir pTypeAr[nType2Offset +1] = ::getCppuType( (const Reference< XWeak > *)0 );
139cdf0e10cSrcweir break;
140cdf0e10cSrcweir case 3:
141cdf0e10cSrcweir pTypeAr[nType2Offset +3] = ::getCppuType( (const Reference< lang::XComponent > *)0 );
142cdf0e10cSrcweir case 2:
143cdf0e10cSrcweir pTypeAr[nType2Offset +2] = ::getCppuType( (const Reference< XAggregation > *)0 );
144cdf0e10cSrcweir case 1:
145cdf0e10cSrcweir pTypeAr[nType2Offset +1] = ::getCppuType( (const Reference< XWeak > *)0 );
146cdf0e10cSrcweir }
147cdf0e10cSrcweir
148cdf0e10cSrcweir pTypes = types;
149cdf0e10cSrcweir }
150cdf0e10cSrcweir }
151cdf0e10cSrcweir //__________________________________________________________________________________________________
getTypes()152cdf0e10cSrcweir Sequence< Type > ClassData::getTypes() SAL_THROW( () )
153cdf0e10cSrcweir {
154cdf0e10cSrcweir if (! pTypes)
155cdf0e10cSrcweir initTypeProvider();
156cdf0e10cSrcweir return *pTypes;
157cdf0e10cSrcweir }
158cdf0e10cSrcweir //__________________________________________________________________________________________________
getImplementationId()159cdf0e10cSrcweir Sequence< sal_Int8 > ClassData::getImplementationId() SAL_THROW( () )
160cdf0e10cSrcweir {
161cdf0e10cSrcweir if (! pTypes)
162cdf0e10cSrcweir initTypeProvider();
163cdf0e10cSrcweir return *pId;
164cdf0e10cSrcweir }
165cdf0e10cSrcweir
166cdf0e10cSrcweir //--------------------------------------------------------------------------------------------------
td_equals(typelib_TypeDescription * pTD,typelib_TypeDescriptionReference * pType)167cdf0e10cSrcweir static inline sal_Bool td_equals(
168cdf0e10cSrcweir typelib_TypeDescription * pTD, typelib_TypeDescriptionReference * pType )
169cdf0e10cSrcweir SAL_THROW( () )
170cdf0e10cSrcweir {
171cdf0e10cSrcweir return (pTD->pWeakRef == pType ||
172cdf0e10cSrcweir (pTD->pTypeName->length == pType->pTypeName->length &&
173cdf0e10cSrcweir rtl_ustr_compare( pTD->pTypeName->buffer, pType->pTypeName->buffer ) == 0));
174cdf0e10cSrcweir }
175cdf0e10cSrcweir //__________________________________________________________________________________________________
query(const Type & rType,lang::XTypeProvider * pBase)176cdf0e10cSrcweir Any ClassData::query( const Type & rType, lang::XTypeProvider * pBase ) SAL_THROW( () )
177cdf0e10cSrcweir {
178cdf0e10cSrcweir if (rType == ::getCppuType( (const Reference< XInterface > *)0 ))
179cdf0e10cSrcweir return Any( &pBase, ::getCppuType( (const Reference< XInterface > *)0 ) );
180cdf0e10cSrcweir for ( sal_Int32 nPos = 0; nPos < nType2Offset; ++nPos )
181cdf0e10cSrcweir {
182cdf0e10cSrcweir const Type_Offset & rTO = arType2Offset[nPos];
183cdf0e10cSrcweir typelib_InterfaceTypeDescription * pTD = rTO.pTD;
184cdf0e10cSrcweir while (pTD)
185cdf0e10cSrcweir {
186cdf0e10cSrcweir if (td_equals( (typelib_TypeDescription *)pTD,
187cdf0e10cSrcweir *(typelib_TypeDescriptionReference **)&rType ))
188cdf0e10cSrcweir {
189cdf0e10cSrcweir void * pInterface = (char *)pBase + rTO.nOffset;
190cdf0e10cSrcweir return Any( &pInterface, (typelib_TypeDescription *)pTD );
191cdf0e10cSrcweir }
192cdf0e10cSrcweir pTD = pTD->pBaseTypeDescription;
193cdf0e10cSrcweir }
194cdf0e10cSrcweir }
195cdf0e10cSrcweir if (rType == ::getCppuType( (const Reference< lang::XTypeProvider > *)0 ))
196cdf0e10cSrcweir return Any( &pBase, ::getCppuType( (const Reference< lang::XTypeProvider > *)0 ) );
197cdf0e10cSrcweir
198cdf0e10cSrcweir return Any();
199cdf0e10cSrcweir }
200cdf0e10cSrcweir
201cdf0e10cSrcweir //##################################################################################################
202cdf0e10cSrcweir //##################################################################################################
203cdf0e10cSrcweir //##################################################################################################
204cdf0e10cSrcweir
205cdf0e10cSrcweir // WeakComponentImplHelperBase
206cdf0e10cSrcweir //__________________________________________________________________________________________________
WeakComponentImplHelperBase(Mutex & rMutex)207cdf0e10cSrcweir WeakComponentImplHelperBase::WeakComponentImplHelperBase( Mutex & rMutex )
208cdf0e10cSrcweir SAL_THROW( () )
209cdf0e10cSrcweir : rBHelper( rMutex )
210cdf0e10cSrcweir {
211cdf0e10cSrcweir }
212cdf0e10cSrcweir //__________________________________________________________________________________________________
~WeakComponentImplHelperBase()213cdf0e10cSrcweir WeakComponentImplHelperBase::~WeakComponentImplHelperBase()
214cdf0e10cSrcweir SAL_THROW( () )
215cdf0e10cSrcweir {
216cdf0e10cSrcweir }
217cdf0e10cSrcweir //__________________________________________________________________________________________________
disposing()218cdf0e10cSrcweir void WeakComponentImplHelperBase::disposing()
219cdf0e10cSrcweir {
220cdf0e10cSrcweir }
221cdf0e10cSrcweir //__________________________________________________________________________________________________
queryInterface(Type const & rType)222cdf0e10cSrcweir Any WeakComponentImplHelperBase::queryInterface( Type const & rType )
223cdf0e10cSrcweir throw (RuntimeException)
224cdf0e10cSrcweir {
225cdf0e10cSrcweir if (rType == ::getCppuType( (Reference< lang::XComponent > const *)0 ))
226cdf0e10cSrcweir {
227cdf0e10cSrcweir void * p = static_cast< lang::XComponent * >( this );
228cdf0e10cSrcweir return Any( &p, rType );
229cdf0e10cSrcweir }
230cdf0e10cSrcweir return OWeakObject::queryInterface( rType );
231cdf0e10cSrcweir }
232cdf0e10cSrcweir //__________________________________________________________________________________________________
acquire()233cdf0e10cSrcweir void WeakComponentImplHelperBase::acquire()
234cdf0e10cSrcweir throw ()
235cdf0e10cSrcweir {
236cdf0e10cSrcweir OWeakObject::acquire();
237cdf0e10cSrcweir }
238cdf0e10cSrcweir //__________________________________________________________________________________________________
release()239cdf0e10cSrcweir void WeakComponentImplHelperBase::release()
240cdf0e10cSrcweir throw ()
241cdf0e10cSrcweir {
242cdf0e10cSrcweir if (osl_decrementInterlockedCount( &m_refCount ) == 0) {
243cdf0e10cSrcweir // ensure no other references are created, via the weak connection point, from now on
244cdf0e10cSrcweir disposeWeakConnectionPoint();
245cdf0e10cSrcweir // restore reference count:
246cdf0e10cSrcweir osl_incrementInterlockedCount( &m_refCount );
247cdf0e10cSrcweir if (! rBHelper.bDisposed) {
248cdf0e10cSrcweir try {
249cdf0e10cSrcweir dispose();
250cdf0e10cSrcweir }
251cdf0e10cSrcweir catch (RuntimeException const& exc) { // don't break throw ()
252cdf0e10cSrcweir OSL_ENSURE(
253cdf0e10cSrcweir false, OUStringToOString(
254cdf0e10cSrcweir exc.Message, RTL_TEXTENCODING_ASCII_US ).getStr() );
255cdf0e10cSrcweir static_cast<void>(exc);
256cdf0e10cSrcweir }
257cdf0e10cSrcweir OSL_ASSERT( rBHelper.bDisposed );
258cdf0e10cSrcweir }
259cdf0e10cSrcweir OWeakObject::release();
260cdf0e10cSrcweir }
261cdf0e10cSrcweir }
262cdf0e10cSrcweir //__________________________________________________________________________________________________
dispose()263cdf0e10cSrcweir void WeakComponentImplHelperBase::dispose()
264cdf0e10cSrcweir throw (RuntimeException)
265cdf0e10cSrcweir {
266cdf0e10cSrcweir ClearableMutexGuard aGuard( rBHelper.rMutex );
267cdf0e10cSrcweir if (!rBHelper.bDisposed && !rBHelper.bInDispose)
268cdf0e10cSrcweir {
269cdf0e10cSrcweir rBHelper.bInDispose = sal_True;
270cdf0e10cSrcweir aGuard.clear();
271cdf0e10cSrcweir try
272cdf0e10cSrcweir {
273cdf0e10cSrcweir // side effect: keeping a reference to this
274cdf0e10cSrcweir lang::EventObject aEvt( static_cast< OWeakObject * >( this ) );
275cdf0e10cSrcweir try
276cdf0e10cSrcweir {
277cdf0e10cSrcweir rBHelper.aLC.disposeAndClear( aEvt );
278cdf0e10cSrcweir disposing();
279cdf0e10cSrcweir }
280cdf0e10cSrcweir catch (...)
281cdf0e10cSrcweir {
282cdf0e10cSrcweir MutexGuard aGuard2( rBHelper.rMutex );
283cdf0e10cSrcweir // bDisposed and bInDispose must be set in this order:
284cdf0e10cSrcweir rBHelper.bDisposed = sal_True;
285cdf0e10cSrcweir rBHelper.bInDispose = sal_False;
286cdf0e10cSrcweir throw;
287cdf0e10cSrcweir }
288cdf0e10cSrcweir MutexGuard aGuard2( rBHelper.rMutex );
289cdf0e10cSrcweir // bDisposed and bInDispose must be set in this order:
290cdf0e10cSrcweir rBHelper.bDisposed = sal_True;
291cdf0e10cSrcweir rBHelper.bInDispose = sal_False;
292cdf0e10cSrcweir }
293cdf0e10cSrcweir catch (RuntimeException &)
294cdf0e10cSrcweir {
295cdf0e10cSrcweir throw;
296cdf0e10cSrcweir }
297cdf0e10cSrcweir catch (Exception & exc)
298cdf0e10cSrcweir {
299cdf0e10cSrcweir throw RuntimeException(
300cdf0e10cSrcweir OUString( RTL_CONSTASCII_USTRINGPARAM(
301cdf0e10cSrcweir "unexpected UNO exception caught: ") ) +
302cdf0e10cSrcweir exc.Message, Reference< XInterface >() );
303cdf0e10cSrcweir }
304cdf0e10cSrcweir }
305cdf0e10cSrcweir }
306cdf0e10cSrcweir //__________________________________________________________________________________________________
addEventListener(Reference<lang::XEventListener> const & xListener)307cdf0e10cSrcweir void WeakComponentImplHelperBase::addEventListener(
308cdf0e10cSrcweir Reference< lang::XEventListener > const & xListener )
309cdf0e10cSrcweir throw (RuntimeException)
310cdf0e10cSrcweir {
311cdf0e10cSrcweir ClearableMutexGuard aGuard( rBHelper.rMutex );
312cdf0e10cSrcweir if (rBHelper.bDisposed || rBHelper.bInDispose)
313cdf0e10cSrcweir {
314cdf0e10cSrcweir aGuard.clear();
315cdf0e10cSrcweir lang::EventObject aEvt( static_cast< OWeakObject * >( this ) );
316cdf0e10cSrcweir xListener->disposing( aEvt );
317cdf0e10cSrcweir }
318cdf0e10cSrcweir else
319cdf0e10cSrcweir {
320cdf0e10cSrcweir rBHelper.addListener( ::getCppuType( &xListener ), xListener );
321cdf0e10cSrcweir }
322cdf0e10cSrcweir }
323cdf0e10cSrcweir //__________________________________________________________________________________________________
removeEventListener(Reference<lang::XEventListener> const & xListener)324cdf0e10cSrcweir void WeakComponentImplHelperBase::removeEventListener(
325cdf0e10cSrcweir Reference< lang::XEventListener > const & xListener )
326cdf0e10cSrcweir throw (RuntimeException)
327cdf0e10cSrcweir {
328cdf0e10cSrcweir rBHelper.removeListener( ::getCppuType( &xListener ), xListener );
329cdf0e10cSrcweir }
330cdf0e10cSrcweir
331cdf0e10cSrcweir // WeakAggComponentImplHelperBase
332cdf0e10cSrcweir //__________________________________________________________________________________________________
WeakAggComponentImplHelperBase(Mutex & rMutex)333cdf0e10cSrcweir WeakAggComponentImplHelperBase::WeakAggComponentImplHelperBase( Mutex & rMutex )
334cdf0e10cSrcweir SAL_THROW( () )
335cdf0e10cSrcweir : rBHelper( rMutex )
336cdf0e10cSrcweir {
337cdf0e10cSrcweir }
338cdf0e10cSrcweir //__________________________________________________________________________________________________
~WeakAggComponentImplHelperBase()339cdf0e10cSrcweir WeakAggComponentImplHelperBase::~WeakAggComponentImplHelperBase()
340cdf0e10cSrcweir SAL_THROW( () )
341cdf0e10cSrcweir {
342cdf0e10cSrcweir }
343cdf0e10cSrcweir //__________________________________________________________________________________________________
disposing()344cdf0e10cSrcweir void WeakAggComponentImplHelperBase::disposing()
345cdf0e10cSrcweir {
346cdf0e10cSrcweir }
347cdf0e10cSrcweir //__________________________________________________________________________________________________
queryInterface(Type const & rType)348cdf0e10cSrcweir Any WeakAggComponentImplHelperBase::queryInterface( Type const & rType )
349cdf0e10cSrcweir throw (RuntimeException)
350cdf0e10cSrcweir {
351cdf0e10cSrcweir return OWeakAggObject::queryInterface( rType );
352cdf0e10cSrcweir }
353cdf0e10cSrcweir //__________________________________________________________________________________________________
queryAggregation(Type const & rType)354cdf0e10cSrcweir Any WeakAggComponentImplHelperBase::queryAggregation( Type const & rType )
355cdf0e10cSrcweir throw (RuntimeException)
356cdf0e10cSrcweir {
357cdf0e10cSrcweir if (rType == ::getCppuType( (Reference< lang::XComponent > const *)0 ))
358cdf0e10cSrcweir {
359cdf0e10cSrcweir void * p = static_cast< lang::XComponent * >( this );
360cdf0e10cSrcweir return Any( &p, rType );
361cdf0e10cSrcweir }
362cdf0e10cSrcweir return OWeakAggObject::queryAggregation( rType );
363cdf0e10cSrcweir }
364cdf0e10cSrcweir //__________________________________________________________________________________________________
acquire()365cdf0e10cSrcweir void WeakAggComponentImplHelperBase::acquire()
366cdf0e10cSrcweir throw ()
367cdf0e10cSrcweir {
368cdf0e10cSrcweir OWeakAggObject::acquire();
369cdf0e10cSrcweir }
370cdf0e10cSrcweir //__________________________________________________________________________________________________
release()371cdf0e10cSrcweir void WeakAggComponentImplHelperBase::release()
372cdf0e10cSrcweir throw ()
373cdf0e10cSrcweir {
374cdf0e10cSrcweir Reference<XInterface> const xDelegator_(xDelegator);
375cdf0e10cSrcweir if (xDelegator_.is()) {
376cdf0e10cSrcweir OWeakAggObject::release();
377cdf0e10cSrcweir }
378cdf0e10cSrcweir else if (osl_decrementInterlockedCount( &m_refCount ) == 0) {
379cdf0e10cSrcweir // ensure no other references are created, via the weak connection point, from now on
380cdf0e10cSrcweir disposeWeakConnectionPoint();
381cdf0e10cSrcweir // restore reference count:
382cdf0e10cSrcweir osl_incrementInterlockedCount( &m_refCount );
383cdf0e10cSrcweir if (! rBHelper.bDisposed) {
384cdf0e10cSrcweir try {
385cdf0e10cSrcweir dispose();
386cdf0e10cSrcweir }
387cdf0e10cSrcweir catch (RuntimeException const& exc) { // don't break throw ()
388cdf0e10cSrcweir OSL_ENSURE(
389cdf0e10cSrcweir false, OUStringToOString(
390cdf0e10cSrcweir exc.Message, RTL_TEXTENCODING_ASCII_US ).getStr() );
391cdf0e10cSrcweir static_cast<void>(exc);
392cdf0e10cSrcweir }
393cdf0e10cSrcweir OSL_ASSERT( rBHelper.bDisposed );
394cdf0e10cSrcweir }
395cdf0e10cSrcweir OWeakAggObject::release();
396cdf0e10cSrcweir }
397cdf0e10cSrcweir }
398cdf0e10cSrcweir //__________________________________________________________________________________________________
dispose()399cdf0e10cSrcweir void WeakAggComponentImplHelperBase::dispose()
400cdf0e10cSrcweir throw (RuntimeException)
401cdf0e10cSrcweir {
402cdf0e10cSrcweir ClearableMutexGuard aGuard( rBHelper.rMutex );
403cdf0e10cSrcweir if (!rBHelper.bDisposed && !rBHelper.bInDispose)
404cdf0e10cSrcweir {
405cdf0e10cSrcweir rBHelper.bInDispose = sal_True;
406cdf0e10cSrcweir aGuard.clear();
407cdf0e10cSrcweir try
408cdf0e10cSrcweir {
409cdf0e10cSrcweir // side effect: keeping a reference to this
410cdf0e10cSrcweir lang::EventObject aEvt( static_cast< OWeakObject * >( this ) );
411cdf0e10cSrcweir try
412cdf0e10cSrcweir {
413cdf0e10cSrcweir rBHelper.aLC.disposeAndClear( aEvt );
414cdf0e10cSrcweir disposing();
415cdf0e10cSrcweir }
416cdf0e10cSrcweir catch (...)
417cdf0e10cSrcweir {
418cdf0e10cSrcweir MutexGuard aGuard2( rBHelper.rMutex );
419cdf0e10cSrcweir // bDisposed and bInDispose must be set in this order:
420cdf0e10cSrcweir rBHelper.bDisposed = sal_True;
421cdf0e10cSrcweir rBHelper.bInDispose = sal_False;
422cdf0e10cSrcweir throw;
423cdf0e10cSrcweir }
424cdf0e10cSrcweir MutexGuard aGuard2( rBHelper.rMutex );
425cdf0e10cSrcweir // bDisposed and bInDispose must be set in this order:
426cdf0e10cSrcweir rBHelper.bDisposed = sal_True;
427cdf0e10cSrcweir rBHelper.bInDispose = sal_False;
428cdf0e10cSrcweir }
429cdf0e10cSrcweir catch (RuntimeException &)
430cdf0e10cSrcweir {
431cdf0e10cSrcweir throw;
432cdf0e10cSrcweir }
433cdf0e10cSrcweir catch (Exception & exc)
434cdf0e10cSrcweir {
435cdf0e10cSrcweir throw RuntimeException(
436cdf0e10cSrcweir OUString( RTL_CONSTASCII_USTRINGPARAM(
437cdf0e10cSrcweir "unexpected UNO exception caught: ") ) +
438cdf0e10cSrcweir exc.Message, Reference< XInterface >() );
439cdf0e10cSrcweir }
440cdf0e10cSrcweir }
441cdf0e10cSrcweir }
442cdf0e10cSrcweir //__________________________________________________________________________________________________
addEventListener(Reference<lang::XEventListener> const & xListener)443cdf0e10cSrcweir void WeakAggComponentImplHelperBase::addEventListener(
444cdf0e10cSrcweir Reference< lang::XEventListener > const & xListener )
445cdf0e10cSrcweir throw (RuntimeException)
446cdf0e10cSrcweir {
447cdf0e10cSrcweir ClearableMutexGuard aGuard( rBHelper.rMutex );
448cdf0e10cSrcweir if (rBHelper.bDisposed || rBHelper.bInDispose)
449cdf0e10cSrcweir {
450cdf0e10cSrcweir aGuard.clear();
451cdf0e10cSrcweir lang::EventObject aEvt( static_cast< OWeakObject * >( this ) );
452cdf0e10cSrcweir xListener->disposing( aEvt );
453cdf0e10cSrcweir }
454cdf0e10cSrcweir else
455cdf0e10cSrcweir {
456cdf0e10cSrcweir rBHelper.addListener( ::getCppuType( &xListener ), xListener );
457cdf0e10cSrcweir }
458cdf0e10cSrcweir }
459cdf0e10cSrcweir //__________________________________________________________________________________________________
removeEventListener(Reference<lang::XEventListener> const & xListener)460cdf0e10cSrcweir void WeakAggComponentImplHelperBase::removeEventListener(
461cdf0e10cSrcweir Reference< lang::XEventListener > const & xListener )
462cdf0e10cSrcweir throw (RuntimeException)
463cdf0e10cSrcweir {
464cdf0e10cSrcweir rBHelper.removeListener( ::getCppuType( &xListener ), xListener );
465cdf0e10cSrcweir }
466cdf0e10cSrcweir
467cdf0e10cSrcweir }
468