xref: /AOO41X/main/cppuhelper/source/implbase_ex.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_cppuhelper.hxx"
30*cdf0e10cSrcweir #include <sal/alloca.h>
31*cdf0e10cSrcweir 
32*cdf0e10cSrcweir #include <string.h>
33*cdf0e10cSrcweir #include <osl/diagnose.h>
34*cdf0e10cSrcweir #include <rtl/byteseq.hxx>
35*cdf0e10cSrcweir #include <rtl/ustrbuf.hxx>
36*cdf0e10cSrcweir #include <rtl/uuid.h>
37*cdf0e10cSrcweir #include <cppuhelper/compbase_ex.hxx>
38*cdf0e10cSrcweir 
39*cdf0e10cSrcweir #include "com/sun/star/uno/RuntimeException.hpp"
40*cdf0e10cSrcweir 
41*cdf0e10cSrcweir using namespace ::cppu;
42*cdf0e10cSrcweir using namespace ::osl;
43*cdf0e10cSrcweir using namespace ::rtl;
44*cdf0e10cSrcweir using namespace ::com::sun::star;
45*cdf0e10cSrcweir using namespace ::com::sun::star::uno;
46*cdf0e10cSrcweir 
47*cdf0e10cSrcweir namespace cppu
48*cdf0e10cSrcweir {
49*cdf0e10cSrcweir 
50*cdf0e10cSrcweir /** Shared mutex for implementation helper initialization.
51*cdf0e10cSrcweir     Not for public use.
52*cdf0e10cSrcweir */
53*cdf0e10cSrcweir ::osl::Mutex & SAL_CALL getImplHelperInitMutex(void) SAL_THROW( () );
54*cdf0e10cSrcweir 
55*cdf0e10cSrcweir //--------------------------------------------------------------------------------------------------
56*cdf0e10cSrcweir static inline void checkInterface( Type const & rType )
57*cdf0e10cSrcweir     SAL_THROW( (RuntimeException) )
58*cdf0e10cSrcweir {
59*cdf0e10cSrcweir     if (TypeClass_INTERFACE != rType.getTypeClass())
60*cdf0e10cSrcweir     {
61*cdf0e10cSrcweir         OUStringBuffer buf( 64 );
62*cdf0e10cSrcweir         buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("querying for interface \"") );
63*cdf0e10cSrcweir         buf.append( rType.getTypeName() );
64*cdf0e10cSrcweir         buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("\": no interface type!") );
65*cdf0e10cSrcweir         OUString msg( buf.makeStringAndClear() );
66*cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 0
67*cdf0e10cSrcweir         OString str( OUStringToOString( msg, RTL_TEXTENCODING_ASCII_US ) );
68*cdf0e10cSrcweir         OSL_ENSURE( 0, str.getStr() );
69*cdf0e10cSrcweir #endif
70*cdf0e10cSrcweir         throw RuntimeException( msg, Reference< XInterface >() );
71*cdf0e10cSrcweir     }
72*cdf0e10cSrcweir }
73*cdf0e10cSrcweir //--------------------------------------------------------------------------------------------------
74*cdf0e10cSrcweir static inline bool isXInterface( rtl_uString * pStr ) SAL_THROW( () )
75*cdf0e10cSrcweir {
76*cdf0e10cSrcweir     return (((OUString const *)&pStr)->equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("com.sun.star.uno.XInterface") ) != sal_False);
77*cdf0e10cSrcweir }
78*cdf0e10cSrcweir //--------------------------------------------------------------------------------------------------
79*cdf0e10cSrcweir static inline void * makeInterface( sal_IntPtr nOffset, void * that ) SAL_THROW( () )
80*cdf0e10cSrcweir {
81*cdf0e10cSrcweir     return (((char *)that) + nOffset);
82*cdf0e10cSrcweir }
83*cdf0e10cSrcweir //--------------------------------------------------------------------------------------------------
84*cdf0e10cSrcweir static inline bool __td_equals(
85*cdf0e10cSrcweir 	typelib_TypeDescriptionReference const * pTDR1,
86*cdf0e10cSrcweir     typelib_TypeDescriptionReference const * pTDR2 )
87*cdf0e10cSrcweir 	SAL_THROW( () )
88*cdf0e10cSrcweir {
89*cdf0e10cSrcweir 	return ((pTDR1 == pTDR2) ||
90*cdf0e10cSrcweir             ((OUString const *)&pTDR1->pTypeName)->equals( *(OUString const *)&pTDR2->pTypeName ) != sal_False);
91*cdf0e10cSrcweir }
92*cdf0e10cSrcweir //--------------------------------------------------------------------------------------------------
93*cdf0e10cSrcweir static inline type_entry * __getTypeEntries( class_data * cd )
94*cdf0e10cSrcweir     SAL_THROW( (RuntimeException) )
95*cdf0e10cSrcweir {
96*cdf0e10cSrcweir     type_entry * pEntries = cd->m_typeEntries;
97*cdf0e10cSrcweir     if (! cd->m_storedTypeRefs) // not inited?
98*cdf0e10cSrcweir     {
99*cdf0e10cSrcweir         MutexGuard guard( getImplHelperInitMutex() );
100*cdf0e10cSrcweir         if (! cd->m_storedTypeRefs) // not inited?
101*cdf0e10cSrcweir         {
102*cdf0e10cSrcweir             // get all types
103*cdf0e10cSrcweir             for ( sal_Int32 n = cd->m_nTypes; n--; )
104*cdf0e10cSrcweir             {
105*cdf0e10cSrcweir                 type_entry * pEntry = &pEntries[ n ];
106*cdf0e10cSrcweir                 Type const & rType = (*pEntry->m_type.getCppuType)( 0 );
107*cdf0e10cSrcweir                 OSL_ENSURE( rType.getTypeClass() == TypeClass_INTERFACE, "### wrong helper init: expected interface!" );
108*cdf0e10cSrcweir                 OSL_ENSURE( ! isXInterface( rType.getTypeLibType()->pTypeName ), "### want to implement XInterface: template argument is XInterface?!?!?!" );
109*cdf0e10cSrcweir                 if (rType.getTypeClass() != TypeClass_INTERFACE)
110*cdf0e10cSrcweir                 {
111*cdf0e10cSrcweir                     OUStringBuffer buf( 48 );
112*cdf0e10cSrcweir                     buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("type \"") );
113*cdf0e10cSrcweir                     buf.append( rType.getTypeName() );
114*cdf0e10cSrcweir                     buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("\" is no interface type!") );
115*cdf0e10cSrcweir                     OUString msg( buf.makeStringAndClear() );
116*cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 0
117*cdf0e10cSrcweir                     OString str( OUStringToOString( msg, RTL_TEXTENCODING_ASCII_US ) );
118*cdf0e10cSrcweir                     OSL_ENSURE( 0, str.getStr() );
119*cdf0e10cSrcweir #endif
120*cdf0e10cSrcweir                     throw RuntimeException( msg, Reference< XInterface >() );
121*cdf0e10cSrcweir                 }
122*cdf0e10cSrcweir                 // ref is statically held by getCppuType()
123*cdf0e10cSrcweir                 pEntry->m_type.typeRef = rType.getTypeLibType();
124*cdf0e10cSrcweir             }
125*cdf0e10cSrcweir             cd->m_storedTypeRefs = sal_True;
126*cdf0e10cSrcweir         }
127*cdf0e10cSrcweir     }
128*cdf0e10cSrcweir     return pEntries;
129*cdf0e10cSrcweir }
130*cdf0e10cSrcweir //--------------------------------------------------------------------------------------------------
131*cdf0e10cSrcweir static inline void __fillTypes( Type * types, class_data * cd )
132*cdf0e10cSrcweir     SAL_THROW( (RuntimeException) )
133*cdf0e10cSrcweir {
134*cdf0e10cSrcweir     type_entry * pEntries = __getTypeEntries( cd );
135*cdf0e10cSrcweir     for ( sal_Int32 n = cd->m_nTypes; n--; )
136*cdf0e10cSrcweir     {
137*cdf0e10cSrcweir         types[ n ] = pEntries[ n ].m_type.typeRef;
138*cdf0e10cSrcweir     }
139*cdf0e10cSrcweir }
140*cdf0e10cSrcweir //--------------------------------------------------------------------------------------------------
141*cdf0e10cSrcweir namespace {
142*cdf0e10cSrcweir 
143*cdf0e10cSrcweir bool recursivelyFindType(
144*cdf0e10cSrcweir     typelib_TypeDescriptionReference const * demandedType,
145*cdf0e10cSrcweir     typelib_InterfaceTypeDescription const * type, sal_IntPtr * offset)
146*cdf0e10cSrcweir {
147*cdf0e10cSrcweir     // This code assumes that the vtables of a multiple-inheritance class (the
148*cdf0e10cSrcweir     // offset amount by which to adjust the this pointer) follow one another in
149*cdf0e10cSrcweir     // the object layout, and that they contain slots for the inherited classes
150*cdf0e10cSrcweir     // in a specifc order.  In theory, that need not hold for any given
151*cdf0e10cSrcweir     // platform; in practice, it seems to work well on all supported platforms:
152*cdf0e10cSrcweir  next:
153*cdf0e10cSrcweir     for (sal_Int32 i = 0; i < type->nBaseTypes; ++i) {
154*cdf0e10cSrcweir         if (i > 0) {
155*cdf0e10cSrcweir             *offset += sizeof (void *);
156*cdf0e10cSrcweir         }
157*cdf0e10cSrcweir         typelib_InterfaceTypeDescription const * base = type->ppBaseTypes[i];
158*cdf0e10cSrcweir         // ignore XInterface:
159*cdf0e10cSrcweir         if (base->nBaseTypes > 0) {
160*cdf0e10cSrcweir             if (__td_equals(
161*cdf0e10cSrcweir                     reinterpret_cast<
162*cdf0e10cSrcweir                         typelib_TypeDescriptionReference const * >(base),
163*cdf0e10cSrcweir                     demandedType))
164*cdf0e10cSrcweir             {
165*cdf0e10cSrcweir                 return true;
166*cdf0e10cSrcweir             }
167*cdf0e10cSrcweir             // Profiling showed that it is important to speed up the common case
168*cdf0e10cSrcweir             // of only one base:
169*cdf0e10cSrcweir             if (type->nBaseTypes == 1) {
170*cdf0e10cSrcweir                 type = base;
171*cdf0e10cSrcweir                 goto next;
172*cdf0e10cSrcweir             }
173*cdf0e10cSrcweir             if (recursivelyFindType(demandedType, base, offset)) {
174*cdf0e10cSrcweir                 return true;
175*cdf0e10cSrcweir             }
176*cdf0e10cSrcweir         }
177*cdf0e10cSrcweir     }
178*cdf0e10cSrcweir     return false;
179*cdf0e10cSrcweir }
180*cdf0e10cSrcweir 
181*cdf0e10cSrcweir }
182*cdf0e10cSrcweir 
183*cdf0e10cSrcweir static inline void * __queryDeepNoXInterface(
184*cdf0e10cSrcweir     typelib_TypeDescriptionReference * pDemandedTDR, class_data * cd, void * that )
185*cdf0e10cSrcweir     SAL_THROW( (RuntimeException) )
186*cdf0e10cSrcweir {
187*cdf0e10cSrcweir     type_entry * pEntries = __getTypeEntries( cd );
188*cdf0e10cSrcweir     sal_Int32 nTypes = cd->m_nTypes;
189*cdf0e10cSrcweir     sal_Int32 n;
190*cdf0e10cSrcweir 
191*cdf0e10cSrcweir     // try top interfaces without getting td
192*cdf0e10cSrcweir     for ( n = 0; n < nTypes; ++n )
193*cdf0e10cSrcweir     {
194*cdf0e10cSrcweir         if (__td_equals( pEntries[ n ].m_type.typeRef, pDemandedTDR ))
195*cdf0e10cSrcweir         {
196*cdf0e10cSrcweir             return makeInterface( pEntries[ n ].m_offset, that );
197*cdf0e10cSrcweir         }
198*cdf0e10cSrcweir     }
199*cdf0e10cSrcweir     // query deep getting td
200*cdf0e10cSrcweir     for ( n = 0; n < nTypes; ++n )
201*cdf0e10cSrcweir     {
202*cdf0e10cSrcweir         typelib_TypeDescription * pTD = 0;
203*cdf0e10cSrcweir         TYPELIB_DANGER_GET( &pTD, pEntries[ n ].m_type.typeRef );
204*cdf0e10cSrcweir         if (pTD)
205*cdf0e10cSrcweir         {
206*cdf0e10cSrcweir             // exclude top (already tested) and bottom (XInterface) interface
207*cdf0e10cSrcweir             OSL_ENSURE(
208*cdf0e10cSrcweir                 reinterpret_cast< typelib_InterfaceTypeDescription * >(pTD)->
209*cdf0e10cSrcweir                     nBaseTypes > 0,
210*cdf0e10cSrcweir                 "### want to implement XInterface:"
211*cdf0e10cSrcweir                     " template argument is XInterface?!?!?!" );
212*cdf0e10cSrcweir             sal_IntPtr offset = pEntries[n].m_offset;
213*cdf0e10cSrcweir             bool found = recursivelyFindType(
214*cdf0e10cSrcweir                 pDemandedTDR,
215*cdf0e10cSrcweir                 reinterpret_cast< typelib_InterfaceTypeDescription * >(pTD),
216*cdf0e10cSrcweir                 &offset);
217*cdf0e10cSrcweir             TYPELIB_DANGER_RELEASE( pTD );
218*cdf0e10cSrcweir             if (found) {
219*cdf0e10cSrcweir                 return makeInterface( offset, that );
220*cdf0e10cSrcweir             }
221*cdf0e10cSrcweir         }
222*cdf0e10cSrcweir         else
223*cdf0e10cSrcweir         {
224*cdf0e10cSrcweir             OUStringBuffer buf( 64 );
225*cdf0e10cSrcweir             buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("cannot get type description for type \"") );
226*cdf0e10cSrcweir             buf.append( pEntries[ n ].m_type.typeRef->pTypeName );
227*cdf0e10cSrcweir             buf.appendAscii( RTL_CONSTASCII_STRINGPARAM("\"!") );
228*cdf0e10cSrcweir             OUString msg( buf.makeStringAndClear() );
229*cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 0
230*cdf0e10cSrcweir             OString str( OUStringToOString( msg, RTL_TEXTENCODING_ASCII_US ) );
231*cdf0e10cSrcweir             OSL_ENSURE( 0, str.getStr() );
232*cdf0e10cSrcweir #endif
233*cdf0e10cSrcweir             throw RuntimeException( msg, Reference< XInterface >() );
234*cdf0e10cSrcweir         }
235*cdf0e10cSrcweir     }
236*cdf0e10cSrcweir     return 0;
237*cdf0e10cSrcweir }
238*cdf0e10cSrcweir 
239*cdf0e10cSrcweir // ImplHelper
240*cdf0e10cSrcweir //==================================================================================================
241*cdf0e10cSrcweir Any SAL_CALL ImplHelper_query(
242*cdf0e10cSrcweir     Type const & rType, class_data * cd, void * that )
243*cdf0e10cSrcweir     SAL_THROW( (RuntimeException) )
244*cdf0e10cSrcweir {
245*cdf0e10cSrcweir     checkInterface( rType );
246*cdf0e10cSrcweir     typelib_TypeDescriptionReference * pTDR = rType.getTypeLibType();
247*cdf0e10cSrcweir 
248*cdf0e10cSrcweir     void * p;
249*cdf0e10cSrcweir     // shortcut for XInterface
250*cdf0e10cSrcweir     if (isXInterface( pTDR->pTypeName ))
251*cdf0e10cSrcweir     {
252*cdf0e10cSrcweir         // take first one
253*cdf0e10cSrcweir         p = makeInterface( cd->m_typeEntries[ 0 ].m_offset, that );
254*cdf0e10cSrcweir     }
255*cdf0e10cSrcweir     else
256*cdf0e10cSrcweir     {
257*cdf0e10cSrcweir         p = __queryDeepNoXInterface( pTDR, cd, that );
258*cdf0e10cSrcweir         if (! p)
259*cdf0e10cSrcweir         {
260*cdf0e10cSrcweir             return Any();
261*cdf0e10cSrcweir         }
262*cdf0e10cSrcweir     }
263*cdf0e10cSrcweir     return Any( &p, pTDR );
264*cdf0e10cSrcweir }
265*cdf0e10cSrcweir //==================================================================================================
266*cdf0e10cSrcweir Any SAL_CALL ImplHelper_queryNoXInterface(
267*cdf0e10cSrcweir     Type const & rType, class_data * cd, void * that )
268*cdf0e10cSrcweir     SAL_THROW( (RuntimeException) )
269*cdf0e10cSrcweir {
270*cdf0e10cSrcweir     checkInterface( rType );
271*cdf0e10cSrcweir     typelib_TypeDescriptionReference * pTDR = rType.getTypeLibType();
272*cdf0e10cSrcweir 
273*cdf0e10cSrcweir     void * p = __queryDeepNoXInterface( pTDR, cd, that );
274*cdf0e10cSrcweir     if (p)
275*cdf0e10cSrcweir     {
276*cdf0e10cSrcweir         return Any( &p, pTDR );
277*cdf0e10cSrcweir     }
278*cdf0e10cSrcweir     else
279*cdf0e10cSrcweir     {
280*cdf0e10cSrcweir         return Any();
281*cdf0e10cSrcweir     }
282*cdf0e10cSrcweir }
283*cdf0e10cSrcweir //==================================================================================================
284*cdf0e10cSrcweir Sequence< sal_Int8 > SAL_CALL ImplHelper_getImplementationId( class_data * cd )
285*cdf0e10cSrcweir     SAL_THROW( (RuntimeException) )
286*cdf0e10cSrcweir {
287*cdf0e10cSrcweir     if (! cd->m_createdId)
288*cdf0e10cSrcweir     {
289*cdf0e10cSrcweir         sal_uInt8 * id = (sal_uInt8 *)alloca( 16 );
290*cdf0e10cSrcweir 		::rtl_createUuid( (sal_uInt8 *)id, 0, sal_True );
291*cdf0e10cSrcweir 
292*cdf0e10cSrcweir         MutexGuard guard( getImplHelperInitMutex() );
293*cdf0e10cSrcweir         if (! cd->m_createdId)
294*cdf0e10cSrcweir         {
295*cdf0e10cSrcweir             memcpy( cd->m_id, id, 16 );
296*cdf0e10cSrcweir             cd->m_createdId = sal_True;
297*cdf0e10cSrcweir         }
298*cdf0e10cSrcweir     }
299*cdf0e10cSrcweir 
300*cdf0e10cSrcweir     sal_Sequence * seq = 0;
301*cdf0e10cSrcweir     ::rtl_byte_sequence_constructFromArray( &seq, cd->m_id, 16 );
302*cdf0e10cSrcweir     return Sequence< sal_Int8 >( seq, SAL_NO_ACQUIRE );
303*cdf0e10cSrcweir }
304*cdf0e10cSrcweir //==================================================================================================
305*cdf0e10cSrcweir Sequence< Type > SAL_CALL ImplHelper_getTypes(
306*cdf0e10cSrcweir     class_data * cd )
307*cdf0e10cSrcweir     SAL_THROW( (RuntimeException) )
308*cdf0e10cSrcweir {
309*cdf0e10cSrcweir     Sequence< Type > types( cd->m_nTypes );
310*cdf0e10cSrcweir     Type * pTypes = types.getArray();
311*cdf0e10cSrcweir     __fillTypes( pTypes, cd );
312*cdf0e10cSrcweir     return types;
313*cdf0e10cSrcweir }
314*cdf0e10cSrcweir //==================================================================================================
315*cdf0e10cSrcweir Sequence< Type >  SAL_CALL ImplInhHelper_getTypes(
316*cdf0e10cSrcweir     class_data * cd, Sequence< Type > const & rAddTypes )
317*cdf0e10cSrcweir     SAL_THROW( (RuntimeException) )
318*cdf0e10cSrcweir {
319*cdf0e10cSrcweir     sal_Int32 nImplTypes = cd->m_nTypes;
320*cdf0e10cSrcweir     sal_Int32 nAddTypes = rAddTypes.getLength();
321*cdf0e10cSrcweir     Sequence< Type > types( nImplTypes + nAddTypes );
322*cdf0e10cSrcweir     Type * pTypes = types.getArray();
323*cdf0e10cSrcweir     __fillTypes( pTypes, cd );
324*cdf0e10cSrcweir     // append base types
325*cdf0e10cSrcweir     Type const * pAddTypes = rAddTypes.getConstArray();
326*cdf0e10cSrcweir     while (nAddTypes--)
327*cdf0e10cSrcweir     {
328*cdf0e10cSrcweir         pTypes[ nImplTypes + nAddTypes ] = pAddTypes[ nAddTypes ];
329*cdf0e10cSrcweir     }
330*cdf0e10cSrcweir     return types;
331*cdf0e10cSrcweir }
332*cdf0e10cSrcweir 
333*cdf0e10cSrcweir // WeakImplHelper
334*cdf0e10cSrcweir //==================================================================================================
335*cdf0e10cSrcweir Any SAL_CALL WeakImplHelper_query(
336*cdf0e10cSrcweir     Type const & rType, class_data * cd, void * that, OWeakObject * pBase )
337*cdf0e10cSrcweir     SAL_THROW( (RuntimeException) )
338*cdf0e10cSrcweir {
339*cdf0e10cSrcweir     checkInterface( rType );
340*cdf0e10cSrcweir     typelib_TypeDescriptionReference * pTDR = rType.getTypeLibType();
341*cdf0e10cSrcweir 
342*cdf0e10cSrcweir     // shortcut XInterface to OWeakObject
343*cdf0e10cSrcweir     if (! isXInterface( pTDR->pTypeName ))
344*cdf0e10cSrcweir     {
345*cdf0e10cSrcweir         void * p = __queryDeepNoXInterface( pTDR, cd, that );
346*cdf0e10cSrcweir         if (p)
347*cdf0e10cSrcweir         {
348*cdf0e10cSrcweir             return Any( &p, pTDR );
349*cdf0e10cSrcweir         }
350*cdf0e10cSrcweir     }
351*cdf0e10cSrcweir     return pBase->OWeakObject::queryInterface( rType );
352*cdf0e10cSrcweir }
353*cdf0e10cSrcweir //==================================================================================================
354*cdf0e10cSrcweir Sequence< Type > SAL_CALL WeakImplHelper_getTypes(
355*cdf0e10cSrcweir     class_data * cd )
356*cdf0e10cSrcweir     SAL_THROW( (RuntimeException) )
357*cdf0e10cSrcweir {
358*cdf0e10cSrcweir     sal_Int32 nTypes = cd->m_nTypes;
359*cdf0e10cSrcweir     Sequence< Type > types( nTypes +1 );
360*cdf0e10cSrcweir     Type * pTypes = types.getArray();
361*cdf0e10cSrcweir     __fillTypes( pTypes, cd );
362*cdf0e10cSrcweir     pTypes[ nTypes ] = ::getCppuType( (Reference< XWeak > const *)0 );
363*cdf0e10cSrcweir     return types;
364*cdf0e10cSrcweir }
365*cdf0e10cSrcweir 
366*cdf0e10cSrcweir // WeakAggImplHelper
367*cdf0e10cSrcweir //==================================================================================================
368*cdf0e10cSrcweir Any SAL_CALL WeakAggImplHelper_queryAgg(
369*cdf0e10cSrcweir     Type const & rType, class_data * cd, void * that, OWeakAggObject * pBase )
370*cdf0e10cSrcweir     SAL_THROW( (RuntimeException) )
371*cdf0e10cSrcweir {
372*cdf0e10cSrcweir     checkInterface( rType );
373*cdf0e10cSrcweir     typelib_TypeDescriptionReference * pTDR = rType.getTypeLibType();
374*cdf0e10cSrcweir 
375*cdf0e10cSrcweir     // shortcut XInterface to OWeakAggObject
376*cdf0e10cSrcweir     if (! isXInterface( pTDR->pTypeName ))
377*cdf0e10cSrcweir     {
378*cdf0e10cSrcweir         void * p = __queryDeepNoXInterface( pTDR, cd, that );
379*cdf0e10cSrcweir         if (p)
380*cdf0e10cSrcweir         {
381*cdf0e10cSrcweir             return Any( &p, pTDR );
382*cdf0e10cSrcweir         }
383*cdf0e10cSrcweir     }
384*cdf0e10cSrcweir     return pBase->OWeakAggObject::queryAggregation( rType );
385*cdf0e10cSrcweir }
386*cdf0e10cSrcweir //==================================================================================================
387*cdf0e10cSrcweir Sequence< Type > SAL_CALL WeakAggImplHelper_getTypes(
388*cdf0e10cSrcweir     class_data * cd )
389*cdf0e10cSrcweir     SAL_THROW( (RuntimeException) )
390*cdf0e10cSrcweir {
391*cdf0e10cSrcweir     sal_Int32 nTypes = cd->m_nTypes;
392*cdf0e10cSrcweir     Sequence< Type > types( nTypes +2 );
393*cdf0e10cSrcweir     Type * pTypes = types.getArray();
394*cdf0e10cSrcweir     __fillTypes( pTypes, cd );
395*cdf0e10cSrcweir     pTypes[ nTypes++ ] = ::getCppuType( (Reference< XWeak > const *)0 );
396*cdf0e10cSrcweir     pTypes[ nTypes ] = ::getCppuType( (const Reference< XAggregation > *)0 );
397*cdf0e10cSrcweir     return types;
398*cdf0e10cSrcweir }
399*cdf0e10cSrcweir 
400*cdf0e10cSrcweir // WeakComponentImplHelper
401*cdf0e10cSrcweir //==================================================================================================
402*cdf0e10cSrcweir Any SAL_CALL WeakComponentImplHelper_query(
403*cdf0e10cSrcweir     Type const & rType, class_data * cd, void * that, WeakComponentImplHelperBase * pBase )
404*cdf0e10cSrcweir     SAL_THROW( (RuntimeException) )
405*cdf0e10cSrcweir {
406*cdf0e10cSrcweir     checkInterface( rType );
407*cdf0e10cSrcweir     typelib_TypeDescriptionReference * pTDR = rType.getTypeLibType();
408*cdf0e10cSrcweir 
409*cdf0e10cSrcweir     // shortcut XInterface to WeakComponentImplHelperBase
410*cdf0e10cSrcweir     if (! isXInterface( pTDR->pTypeName ))
411*cdf0e10cSrcweir     {
412*cdf0e10cSrcweir         void * p = __queryDeepNoXInterface( pTDR, cd, that );
413*cdf0e10cSrcweir         if (p)
414*cdf0e10cSrcweir         {
415*cdf0e10cSrcweir             return Any( &p, pTDR );
416*cdf0e10cSrcweir         }
417*cdf0e10cSrcweir     }
418*cdf0e10cSrcweir     return pBase->WeakComponentImplHelperBase::queryInterface( rType );
419*cdf0e10cSrcweir }
420*cdf0e10cSrcweir //==================================================================================================
421*cdf0e10cSrcweir Sequence< Type > SAL_CALL WeakComponentImplHelper_getTypes(
422*cdf0e10cSrcweir     class_data * cd )
423*cdf0e10cSrcweir     SAL_THROW( (RuntimeException) )
424*cdf0e10cSrcweir {
425*cdf0e10cSrcweir     sal_Int32 nTypes = cd->m_nTypes;
426*cdf0e10cSrcweir     Sequence< Type > types( nTypes +2 );
427*cdf0e10cSrcweir     Type * pTypes = types.getArray();
428*cdf0e10cSrcweir     __fillTypes( pTypes, cd );
429*cdf0e10cSrcweir     pTypes[ nTypes++ ] = ::getCppuType( (Reference< XWeak > const *)0 );
430*cdf0e10cSrcweir     pTypes[ nTypes ] = ::getCppuType( (Reference< lang::XComponent > const *)0 );
431*cdf0e10cSrcweir     return types;
432*cdf0e10cSrcweir }
433*cdf0e10cSrcweir 
434*cdf0e10cSrcweir // WeakAggComponentImplHelper
435*cdf0e10cSrcweir //==================================================================================================
436*cdf0e10cSrcweir Any SAL_CALL WeakAggComponentImplHelper_queryAgg(
437*cdf0e10cSrcweir     Type const & rType, class_data * cd, void * that, WeakAggComponentImplHelperBase * pBase )
438*cdf0e10cSrcweir     SAL_THROW( (RuntimeException) )
439*cdf0e10cSrcweir {
440*cdf0e10cSrcweir     checkInterface( rType );
441*cdf0e10cSrcweir     typelib_TypeDescriptionReference * pTDR = rType.getTypeLibType();
442*cdf0e10cSrcweir 
443*cdf0e10cSrcweir     // shortcut XInterface to WeakAggComponentImplHelperBase
444*cdf0e10cSrcweir     if (! isXInterface( pTDR->pTypeName ))
445*cdf0e10cSrcweir     {
446*cdf0e10cSrcweir         void * p = __queryDeepNoXInterface( pTDR, cd, that );
447*cdf0e10cSrcweir         if (p)
448*cdf0e10cSrcweir         {
449*cdf0e10cSrcweir             return Any( &p, pTDR );
450*cdf0e10cSrcweir         }
451*cdf0e10cSrcweir     }
452*cdf0e10cSrcweir     return pBase->WeakAggComponentImplHelperBase::queryAggregation( rType );
453*cdf0e10cSrcweir }
454*cdf0e10cSrcweir //==================================================================================================
455*cdf0e10cSrcweir Sequence< Type > SAL_CALL WeakAggComponentImplHelper_getTypes(
456*cdf0e10cSrcweir     class_data * cd )
457*cdf0e10cSrcweir     SAL_THROW( (RuntimeException) )
458*cdf0e10cSrcweir {
459*cdf0e10cSrcweir     sal_Int32 nTypes = cd->m_nTypes;
460*cdf0e10cSrcweir     Sequence< Type > types( nTypes +3 );
461*cdf0e10cSrcweir     Type * pTypes = types.getArray();
462*cdf0e10cSrcweir     __fillTypes( pTypes, cd );
463*cdf0e10cSrcweir     pTypes[ nTypes++ ] = ::getCppuType( (Reference< XWeak > const *)0 );
464*cdf0e10cSrcweir     pTypes[ nTypes++ ] = ::getCppuType( (const Reference< XAggregation > *)0 );
465*cdf0e10cSrcweir     pTypes[ nTypes ] = ::getCppuType( (const Reference< lang::XComponent > *)0 );
466*cdf0e10cSrcweir     return types;
467*cdf0e10cSrcweir }
468*cdf0e10cSrcweir 
469*cdf0e10cSrcweir }
470