Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #include "sal/config.h"
31 : :
32 : : #include <vector>
33 : :
34 : : #include <sal/alloca.h>
35 : :
36 : : #include <osl/diagnose.h>
37 : : #include <rtl/alloc.h>
38 : : #include <rtl/ustring.hxx>
39 : :
40 : : #include <uno/mapping.hxx>
41 : :
42 : : #include <cppuhelper/bootstrap.hxx>
43 : : #include <cppuhelper/implbase1.hxx>
44 : : #include <typelib/typedescription.h>
45 : :
46 : : #include <com/sun/star/lang/XComponent.hpp>
47 : : #include <com/sun/star/container/XHierarchicalNameAccess.hpp>
48 : : #include <com/sun/star/reflection/XTypeDescription.hpp>
49 : : #include <com/sun/star/reflection/XEnumTypeDescription.hpp>
50 : : #include <com/sun/star/reflection/XIndirectTypeDescription.hpp>
51 : : #include <com/sun/star/reflection/XInterfaceMemberTypeDescription.hpp>
52 : : #include <com/sun/star/reflection/XInterfaceAttributeTypeDescription2.hpp>
53 : : #include <com/sun/star/reflection/XMethodParameter.hpp>
54 : : #include <com/sun/star/reflection/XInterfaceMethodTypeDescription.hpp>
55 : : #include <com/sun/star/reflection/XInterfaceTypeDescription2.hpp>
56 : : #include <com/sun/star/reflection/XCompoundTypeDescription.hpp>
57 : : #include <com/sun/star/reflection/XStructTypeDescription.hpp>
58 : : #include <com/sun/star/reflection/XUnionTypeDescription.hpp>
59 : : #include "com/sun/star/uno/RuntimeException.hpp"
60 : :
61 : : #include "boost/scoped_array.hpp"
62 : :
63 : : using namespace ::rtl;
64 : : using namespace ::com::sun::star;
65 : : using namespace ::com::sun::star::uno;
66 : : using namespace ::com::sun::star::reflection;
67 : :
68 : :
69 : : namespace cppu
70 : : {
71 : :
72 : : static typelib_TypeDescription * createCTD(
73 : : Reference< container::XHierarchicalNameAccess > const & access,
74 : : const Reference< XTypeDescription > & xType );
75 : :
76 : : //==================================================================================================
77 : 0 : inline static sal_Int64 coerceToInt64( const Any & rVal )
78 : : {
79 [ # # # # : 0 : switch (rVal.getValueTypeClass())
# # # # #
# # ]
80 : : {
81 : : case TypeClass_CHAR:
82 : 0 : return *(sal_Unicode *)rVal.getValue();
83 : : case TypeClass_BOOLEAN:
84 [ # # ]: 0 : return (*(sal_Bool *)rVal.getValue() ? 1 : 0);
85 : : case TypeClass_BYTE:
86 : 0 : return *(sal_Int8 *)rVal.getValue();
87 : : case TypeClass_SHORT:
88 : 0 : return *(sal_Int16 *)rVal.getValue();
89 : : case TypeClass_UNSIGNED_SHORT:
90 : 0 : return *(sal_uInt16 *)rVal.getValue();
91 : : case TypeClass_LONG:
92 : 0 : return *(sal_Int32 *)rVal.getValue();
93 : : case TypeClass_UNSIGNED_LONG:
94 : 0 : return *(sal_uInt32 *)rVal.getValue();
95 : : case TypeClass_HYPER:
96 : 0 : return *(sal_Int64 *)rVal.getValue();
97 : : case TypeClass_UNSIGNED_HYPER:
98 : 0 : return *(sal_uInt64 *)rVal.getValue();
99 : : case TypeClass_ENUM:
100 : 0 : return *(int *)rVal.getValue();
101 : : default:
102 : : OSL_ASSERT(false);
103 : 0 : return 0;
104 : : }
105 : : }
106 : : //==================================================================================================
107 : 0 : inline static typelib_TypeDescription * createCTD(
108 : : const Reference< XUnionTypeDescription > & xType )
109 : : {
110 : 0 : typelib_TypeDescription * pRet = 0;
111 [ # # ]: 0 : if (xType.is())
112 : : {
113 [ # # ][ # # ]: 0 : OUString aTypeName( xType->getName() );
114 : :
115 : : // discriminant type
116 [ # # ][ # # ]: 0 : Reference< XTypeDescription > xDiscrTD( xType->getDiscriminantType() );
117 [ # # ][ # # ]: 0 : OUString aDiscrTypeName( xDiscrTD->getName() );
118 : 0 : typelib_TypeDescriptionReference * pDiscrTypeRef = 0;
119 : : typelib_typedescriptionreference_new( &pDiscrTypeRef,
120 [ # # ][ # # ]: 0 : (typelib_TypeClass)xDiscrTD->getTypeClass(),
121 : 0 : aDiscrTypeName.pData );
122 : : // default member type
123 [ # # ][ # # ]: 0 : Reference< XTypeDescription > xDefaultMemberTD( xType->getDefaultMemberType() );
124 [ # # ][ # # ]: 0 : OUString aDefMemberTypeName( xDefaultMemberTD->getName() );
125 : 0 : typelib_TypeDescriptionReference * pDefMemberTypeRef = 0;
126 : : typelib_typedescriptionreference_new( &pDefMemberTypeRef,
127 [ # # ][ # # ]: 0 : (typelib_TypeClass)xDefaultMemberTD->getTypeClass(),
128 : 0 : aDefMemberTypeName.pData );
129 : : // init array
130 [ # # ][ # # ]: 0 : Sequence< Any > aDiscriminants( xType->getDiscriminants() );
131 [ # # ][ # # ]: 0 : Sequence< Reference< XTypeDescription > > aMemberTypes( xType->getMemberTypes() );
132 [ # # ][ # # ]: 0 : Sequence< OUString > aMemberNames( xType->getMemberNames() );
133 : 0 : sal_Int32 nMembers = aDiscriminants.getLength();
134 : : OSL_ASSERT( nMembers == aMemberNames.getLength() && nMembers == aMemberTypes.getLength() );
135 : :
136 : 0 : const Any * pDiscriminants = aDiscriminants.getConstArray();
137 : 0 : const Reference< XTypeDescription > * pMemberTypes = aMemberTypes.getConstArray();
138 : 0 : const OUString * pMemberNames = aMemberNames.getConstArray();
139 : :
140 : 0 : typelib_Union_Init * pMembers = (typelib_Union_Init *)alloca( nMembers * sizeof(typelib_Union_Init) );
141 : :
142 : : sal_Int32 nPos;
143 [ # # ]: 0 : for ( nPos = nMembers; nPos--; )
144 : : {
145 : 0 : typelib_Union_Init & rEntry = pMembers[nPos];
146 : : // member discriminant
147 : 0 : rEntry.nDiscriminant = coerceToInt64( pDiscriminants[nPos] );
148 : : // member type
149 [ # # ][ # # ]: 0 : OUString aMemberTypeName( pMemberTypes[nPos]->getName() );
150 : 0 : rEntry.pTypeRef = 0;
151 : : typelib_typedescriptionreference_new( &rEntry.pTypeRef,
152 [ # # ][ # # ]: 0 : (typelib_TypeClass)pMemberTypes[nPos]->getTypeClass(),
153 : 0 : aMemberTypeName.pData );
154 : : // member name
155 : 0 : rEntry.pMemberName = pMemberNames[nPos].pData;
156 : 0 : }
157 : :
158 : : typelib_typedescription_newUnion( &pRet, aTypeName.pData,
159 : : pDiscrTypeRef,
160 [ # # ]: 0 : coerceToInt64( xType->getDefaultDiscriminant() ),
161 : : pDefMemberTypeRef,
162 [ # # ]: 0 : nMembers, pMembers );
163 : :
164 [ # # ]: 0 : for ( nPos = nMembers; nPos--; )
165 : : {
166 : 0 : typelib_typedescriptionreference_release( pMembers[nPos].pTypeRef );
167 : : }
168 : :
169 : 0 : typelib_typedescriptionreference_release( pDiscrTypeRef );
170 [ # # ][ # # ]: 0 : typelib_typedescriptionreference_release( pDefMemberTypeRef );
[ # # ]
171 : : }
172 : 0 : return pRet;
173 : : }
174 : : //==================================================================================================
175 : 2853 : inline static typelib_TypeDescription * createCTD(
176 : : const Reference< XCompoundTypeDescription > & xType )
177 : : {
178 : 2853 : typelib_TypeDescription * pRet = 0;
179 [ + + ]: 2853 : if (xType.is())
180 : : {
181 : : typelib_TypeDescription * pBaseType = createCTD(
182 [ + - ][ + - ]: 2120 : Reference< XCompoundTypeDescription >::query( xType->getBaseType() ) );
[ + - ][ + - ]
183 [ + + ]: 2120 : if (pBaseType)
184 : 1387 : typelib_typedescription_register( &pBaseType );
185 : :
186 : : // construct member init array
187 [ + - ][ + - ]: 2120 : const Sequence<Reference< XTypeDescription > > & rMemberTypes = xType->getMemberTypes();
188 [ + - ][ + - ]: 2120 : const Sequence< OUString > & rMemberNames = xType->getMemberNames();
189 : :
190 : 2120 : const Reference< XTypeDescription > * pMemberTypes = rMemberTypes.getConstArray();
191 : 2120 : const OUString * pMemberNames = rMemberNames.getConstArray();
192 : :
193 : 2120 : sal_Int32 nMembers = rMemberTypes.getLength();
194 : : OSL_ENSURE( nMembers == rMemberNames.getLength(), "### lens differ!" );
195 : :
196 [ + - ][ + - ]: 2120 : OUString aTypeName( xType->getName() );
197 : :
198 : 2120 : typelib_CompoundMember_Init * pMemberInits = (typelib_CompoundMember_Init *)alloca(
199 : : sizeof(typelib_CompoundMember_Init) * nMembers );
200 : :
201 : : sal_Int32 nPos;
202 [ + + ]: 4815 : for ( nPos = nMembers; nPos--; )
203 : : {
204 : 2695 : typelib_CompoundMember_Init & rInit = pMemberInits[nPos];
205 [ + - ][ + - ]: 2695 : rInit.eTypeClass = (typelib_TypeClass)pMemberTypes[nPos]->getTypeClass();
206 : :
207 [ + - ][ + - ]: 2695 : OUString aMemberTypeName( pMemberTypes[nPos]->getName() );
208 : 2695 : rtl_uString_acquire( rInit.pTypeName = aMemberTypeName.pData );
209 : :
210 : : // string is held by rMemberNames
211 : 2695 : rInit.pMemberName = pMemberNames[nPos].pData;
212 : 2695 : }
213 : :
214 : : typelib_typedescription_new(
215 : : &pRet,
216 [ + - ][ + - ]: 2120 : (typelib_TypeClass)xType->getTypeClass(),
217 : : aTypeName.pData,
218 : : (pBaseType ? pBaseType->pWeakRef : 0),
219 [ + + ]: 4240 : nMembers, pMemberInits );
220 : :
221 : : // cleanup
222 [ + + ]: 4815 : for ( nPos = nMembers; nPos--; )
223 : : {
224 : 2695 : rtl_uString_release( pMemberInits[nPos].pTypeName );
225 : : }
226 [ + + ]: 2120 : if (pBaseType)
227 [ + - ][ + - ]: 2120 : typelib_typedescription_release( pBaseType );
228 : : }
229 : 2853 : return pRet;
230 : : }
231 : : //==================================================================================================
232 : 7184 : inline static typelib_TypeDescription * createCTD(
233 : : Reference< container::XHierarchicalNameAccess > const & access,
234 : : const Reference< XStructTypeDescription > & xType )
235 : : {
236 : 7184 : typelib_TypeDescription * pRet = 0;
237 [ + - ][ + - ]: 7184 : if (xType.is() && xType->getTypeParameters().getLength() == 0)
[ + - ][ + - ]
[ + - ][ + - ]
[ + - # # ]
238 : : {
239 : : typelib_TypeDescription * pBaseType = createCTD(
240 [ + - ][ + - ]: 7184 : access, xType->getBaseType() );
[ + - ]
241 [ + + ]: 7184 : if (pBaseType)
242 : 711 : typelib_typedescription_register( &pBaseType );
243 : :
244 : : // construct member init array
245 [ + - ][ + - ]: 7184 : const Sequence<Reference< XTypeDescription > > & rMemberTypes = xType->getMemberTypes();
246 [ + - ][ + - ]: 7184 : const Sequence< OUString > & rMemberNames = xType->getMemberNames();
247 : :
248 : 7184 : const Reference< XTypeDescription > * pMemberTypes = rMemberTypes.getConstArray();
249 : 7184 : const OUString * pMemberNames = rMemberNames.getConstArray();
250 : :
251 : 7184 : sal_Int32 nMembers = rMemberTypes.getLength();
252 : : OSL_ENSURE( nMembers == rMemberNames.getLength(), "### lens differ!" );
253 : :
254 [ + - ][ + - ]: 7184 : OUString aTypeName( xType->getName() );
255 : :
256 : 7184 : typelib_StructMember_Init * pMemberInits = (typelib_StructMember_Init *)alloca(
257 : : sizeof(typelib_StructMember_Init) * nMembers );
258 : :
259 [ + - ]: 7184 : Sequence< Reference< XTypeDescription > > templateMemberTypes;
260 : 7184 : sal_Int32 i = aTypeName.indexOf('<');
261 [ + + ]: 7184 : if (i >= 0) {
262 : : Reference< XStructTypeDescription > templateDesc(
263 [ + - ]: 421 : access->getByHierarchicalName(aTypeName.copy(0, i)),
264 [ + - ][ + - ]: 421 : UNO_QUERY_THROW);
265 : : OSL_ASSERT(
266 : : templateDesc->getTypeParameters().getLength()
267 : : == xType->getTypeArguments().getLength());
268 [ + - ][ + - ]: 421 : templateMemberTypes = templateDesc->getMemberTypes();
[ + - ][ + - ]
269 : 421 : OSL_ASSERT(templateMemberTypes.getLength() == nMembers);
270 : : }
271 : :
272 : : sal_Int32 nPos;
273 [ + + ]: 33938 : for ( nPos = nMembers; nPos--; )
274 : : {
275 : 26754 : typelib_StructMember_Init & rInit = pMemberInits[nPos];
276 : : rInit.aBase.eTypeClass
277 [ + - ][ + - ]: 26754 : = (typelib_TypeClass)pMemberTypes[nPos]->getTypeClass();
278 : :
279 [ + - ][ + - ]: 26754 : OUString aMemberTypeName( pMemberTypes[nPos]->getName() );
280 : : rtl_uString_acquire(
281 : 26754 : rInit.aBase.pTypeName = aMemberTypeName.pData );
282 : :
283 : : // string is held by rMemberNames
284 : 26754 : rInit.aBase.pMemberName = pMemberNames[nPos].pData;
285 : :
286 : 26754 : rInit.bParameterizedType = templateMemberTypes.getLength() != 0
287 [ + - ][ + - ]: 662 : && (templateMemberTypes[nPos]->getTypeClass()
[ + - ]
288 [ + + ][ + + ]: 27416 : == TypeClass_UNKNOWN);
289 : 26754 : }
290 : :
291 : : typelib_typedescription_newStruct(
292 : : &pRet,
293 : : aTypeName.pData,
294 : : (pBaseType ? pBaseType->pWeakRef : 0),
295 [ + + ]: 7184 : nMembers, pMemberInits );
296 : :
297 : : // cleanup
298 [ + + ]: 33938 : for ( nPos = nMembers; nPos--; )
299 : : {
300 : 26754 : rtl_uString_release( pMemberInits[nPos].aBase.pTypeName );
301 : : }
302 [ + + ]: 7184 : if (pBaseType)
303 [ + - ][ + - ]: 7184 : typelib_typedescription_release( pBaseType );
[ + - ]
304 : : }
305 : 7184 : return pRet;
306 : : }
307 : : //==================================================================================================
308 : 6050 : inline static typelib_TypeDescription * createCTD(
309 : : const Reference< XInterfaceAttributeTypeDescription2 > & xAttribute )
310 : : {
311 : 6050 : typelib_TypeDescription * pRet = 0;
312 [ + - ]: 6050 : if (xAttribute.is())
313 : : {
314 [ + - ][ + - ]: 6050 : OUString aMemberName( xAttribute->getName() );
315 [ + - ][ + - ]: 6050 : Reference< XTypeDescription > xType( xAttribute->getType() );
316 [ + - ][ + - ]: 6050 : OUString aMemberTypeName( xType->getName() );
317 [ + - ]: 6050 : std::vector< rtl_uString * > getExc;
318 : : Sequence< Reference< XCompoundTypeDescription > > getExcs(
319 [ + - ][ + - ]: 6050 : xAttribute->getGetExceptions() );
320 [ + + ]: 6055 : for (sal_Int32 i = 0; i != getExcs.getLength(); ++i)
321 : : {
322 : : OSL_ASSERT( getExcs[i].is() );
323 [ + - ][ + - ]: 5 : getExc.push_back( getExcs[i]->getName().pData );
[ + - ][ + - ]
324 : : }
325 [ + - ]: 6050 : std::vector< rtl_uString * > setExc;
326 : : Sequence< Reference< XCompoundTypeDescription > > setExcs(
327 [ + - ][ + - ]: 6050 : xAttribute->getSetExceptions() );
328 [ + + ]: 6616 : for (sal_Int32 i = 0; i != setExcs.getLength(); ++i)
329 : : {
330 : : OSL_ASSERT( setExcs[i].is() );
331 [ + - ][ + - ]: 566 : setExc.push_back( setExcs[i]->getName().pData );
[ + - ][ + - ]
332 : : }
333 : : typelib_typedescription_newExtendedInterfaceAttribute(
334 : : (typelib_InterfaceAttributeTypeDescription **)&pRet,
335 [ + - ]: 6050 : xAttribute->getPosition(),
336 : : aMemberName.pData, // name
337 [ + - ][ + - ]: 6050 : (typelib_TypeClass)xType->getTypeClass(),
338 : : aMemberTypeName.pData, // type name
339 [ + - ][ + - ]: 6050 : xAttribute->isReadOnly(),
340 : 12100 : getExc.size(), getExc.empty() ? 0 : &getExc[0],
341 [ + + ][ + + ]: 18150 : setExc.size(), setExc.empty() ? 0 : &setExc[0] );
[ + - ][ + - ]
[ + - ]
342 : : }
343 : 6050 : return pRet;
344 : : }
345 : : //==================================================================================================
346 : 30292 : static typelib_TypeDescription * createCTD(
347 : : const Reference< XInterfaceMethodTypeDescription > & xMethod )
348 : : {
349 : 30292 : typelib_TypeDescription * pRet = 0;
350 [ + - ]: 30292 : if (xMethod.is())
351 : : {
352 [ + - ][ + - ]: 30292 : Reference< XTypeDescription > xReturnType( xMethod->getReturnType() );
353 : :
354 : : // init all params
355 [ + - ][ + - ]: 30292 : const Sequence<Reference< XMethodParameter > > & rParams = xMethod->getParameters();
356 : 30292 : const Reference< XMethodParameter > * pParams = rParams.getConstArray();
357 : 30292 : sal_Int32 nParams = rParams.getLength();
358 : :
359 : 30292 : typelib_Parameter_Init * pParamInit = (typelib_Parameter_Init *)alloca(
360 : : sizeof(typelib_Parameter_Init) * nParams );
361 : :
362 : : sal_Int32 nPos;
363 [ + + ]: 57273 : for ( nPos = nParams; nPos--; )
364 : : {
365 : 26981 : const Reference< XMethodParameter > & xParam = pParams[nPos];
366 [ + - ][ + - ]: 26981 : const Reference< XTypeDescription > & xType = xParam->getType();
367 [ + - ][ + - ]: 26981 : typelib_Parameter_Init & rInit = pParamInit[xParam->getPosition()];
368 : :
369 [ + - ][ + - ]: 26981 : rInit.eTypeClass = (typelib_TypeClass)xType->getTypeClass();
370 [ + - ][ + - ]: 26981 : OUString aParamTypeName( xType->getName() );
371 : 26981 : rtl_uString_acquire( rInit.pTypeName = aParamTypeName.pData );
372 [ + - ][ + - ]: 26981 : OUString aParamName( xParam->getName() );
373 : 26981 : rtl_uString_acquire( rInit.pParamName = aParamName.pData );
374 [ + - ][ + - ]: 26981 : rInit.bIn = xParam->isIn();
375 [ + - ][ + - ]: 26981 : rInit.bOut = xParam->isOut();
376 : 26981 : }
377 : :
378 : : // init all exception strings
379 [ + - ][ + - ]: 30292 : const Sequence<Reference< XTypeDescription > > & rExceptions = xMethod->getExceptions();
380 : 30292 : const Reference< XTypeDescription > * pExceptions = rExceptions.getConstArray();
381 : 30292 : sal_Int32 nExceptions = rExceptions.getLength();
382 : 30292 : rtl_uString ** ppExceptionNames = (rtl_uString **)alloca(
383 : : sizeof(rtl_uString *) * nExceptions );
384 : :
385 [ + + ]: 48394 : for ( nPos = nExceptions; nPos--; )
386 : : {
387 [ + - ][ + - ]: 18102 : OUString aExceptionTypeName( pExceptions[nPos]->getName() );
388 : 18102 : rtl_uString_acquire( ppExceptionNames[nPos] = aExceptionTypeName.pData );
389 : 18102 : }
390 : :
391 [ + - ][ + - ]: 30292 : OUString aTypeName( xMethod->getName() );
392 [ + - ][ + - ]: 30292 : OUString aReturnTypeName( xReturnType->getName() );
393 : :
394 : : typelib_typedescription_newInterfaceMethod(
395 : : (typelib_InterfaceMethodTypeDescription **)&pRet,
396 [ + - ]: 30292 : xMethod->getPosition(),
397 [ + - ][ + - ]: 30292 : xMethod->isOneway(),
398 : : aTypeName.pData,
399 [ + - ][ + - ]: 30292 : (typelib_TypeClass)xReturnType->getTypeClass(),
400 : : aReturnTypeName.pData,
401 : : nParams, pParamInit,
402 [ + - ]: 30292 : nExceptions, ppExceptionNames );
403 : :
404 [ + + ]: 57273 : for ( nPos = nParams; nPos--; )
405 : : {
406 : 26981 : rtl_uString_release( pParamInit[nPos].pTypeName );
407 : 26981 : rtl_uString_release( pParamInit[nPos].pParamName );
408 : : }
409 [ + + ]: 48394 : for ( nPos = nExceptions; nPos--; )
410 : : {
411 : 18102 : rtl_uString_release( ppExceptionNames[nPos] );
412 [ + - ][ + - ]: 30292 : }
413 : : }
414 : 30292 : return pRet;
415 : : }
416 : : //==================================================================================================
417 : 97245 : inline static typelib_TypeDescription * createCTD(
418 : : Reference< container::XHierarchicalNameAccess > const & access,
419 : : const Reference< XInterfaceTypeDescription2 > & xType )
420 : : {
421 : 97245 : typelib_TypeDescription * pRet = 0;
422 [ + - ]: 97245 : if (xType.is())
423 : : {
424 [ + - ][ + - ]: 97245 : Sequence< Reference< XTypeDescription > > aBases(xType->getBaseTypes());
425 : 97245 : sal_Int32 nBases = aBases.getLength();
426 : : // Exploit the fact that a typelib_TypeDescription for an interface type
427 : : // is also the typelib_TypeDescriptionReference for that type:
428 : : boost::scoped_array< typelib_TypeDescription * > aBaseTypes(
429 [ + - ]: 97245 : new typelib_TypeDescription *[nBases]);
430 [ + + ]: 156908 : {for (sal_Int32 i = 0; i < nBases; ++i) {
431 [ + - ][ + - ]: 59663 : typelib_TypeDescription * p = createCTD(access, aBases[i]);
432 : : OSL_ASSERT(
433 : : !TYPELIB_TYPEDESCRIPTIONREFERENCE_ISREALLYWEAK(p->eTypeClass));
434 : 59663 : typelib_typedescription_register(&p);
435 : 59663 : aBaseTypes[i] = p;
436 : : }}
437 : : typelib_TypeDescriptionReference ** pBaseTypeRefs
438 : : = reinterpret_cast< typelib_TypeDescriptionReference ** >(
439 : 97245 : aBaseTypes.get());
440 : :
441 : : // construct all member refs
442 [ + - ][ + - ]: 97245 : const Sequence<Reference< XInterfaceMemberTypeDescription > > & rMembers = xType->getMembers();
443 : 97245 : sal_Int32 nMembers = rMembers.getLength();
444 : :
445 : 97245 : typelib_TypeDescriptionReference ** ppMemberRefs = (typelib_TypeDescriptionReference **)alloca(
446 : : sizeof(typelib_TypeDescriptionReference *) * nMembers );
447 : :
448 : 97245 : const Reference< XInterfaceMemberTypeDescription > * pMembers = rMembers.getConstArray();
449 : :
450 [ + - ][ + - ]: 97245 : OUString aTypeName( xType->getName() );
451 : :
452 : : sal_Int32 nPos;
453 [ + + ]: 428971 : for ( nPos = nMembers; nPos--; )
454 : : {
455 [ + - ][ + - ]: 331726 : OUString aMemberTypeName( pMembers[nPos]->getName() );
456 : 331726 : ppMemberRefs[nPos] = 0;
457 : : typelib_typedescriptionreference_new(
458 : : ppMemberRefs + nPos,
459 [ + - ][ + - ]: 331726 : (typelib_TypeClass)pMembers[nPos]->getTypeClass(),
460 : 331726 : aMemberTypeName.pData );
461 : 331726 : }
462 : :
463 [ + - ][ + - ]: 97245 : Uik uik = xType->getUik();
464 : :
465 : : typelib_typedescription_newMIInterface(
466 : : (typelib_InterfaceTypeDescription **)&pRet,
467 : : aTypeName.pData,
468 : : uik.m_Data1, uik.m_Data2, uik.m_Data3, uik.m_Data4, uik.m_Data5,
469 : : nBases, pBaseTypeRefs,
470 : 97245 : nMembers, ppMemberRefs );
471 : :
472 : : // cleanup refs and base type
473 [ + + ]: 156908 : {for (int i = 0; i < nBases; ++i) {
474 : 59663 : typelib_typedescription_release(aBaseTypes[i]);
475 : : }}
476 : :
477 [ + + ]: 428971 : for ( nPos = nMembers; nPos--; )
478 : : {
479 : 331726 : typelib_typedescriptionreference_release( ppMemberRefs[nPos] );
480 [ + - ][ + - ]: 97245 : }
[ + - ]
481 : : }
482 : 97245 : return pRet;
483 : : }
484 : : //==================================================================================================
485 : 1616 : inline static typelib_TypeDescription * createCTD( const Reference< XEnumTypeDescription > & xType )
486 : : {
487 : 1616 : typelib_TypeDescription * pRet = 0;
488 [ + - ]: 1616 : if (xType.is())
489 : : {
490 [ + - ][ + - ]: 1616 : OUString aTypeName( xType->getName() );
491 [ + - ][ + - ]: 1616 : Sequence< OUString > aNames( xType->getEnumNames() );
492 : : OSL_ASSERT( sizeof(OUString) == sizeof(rtl_uString *) ); // !!!
493 [ + - ][ + - ]: 1616 : Sequence< sal_Int32 > aValues( xType->getEnumValues() );
494 : :
495 : : typelib_typedescription_newEnum(
496 [ + - ]: 1616 : &pRet, aTypeName.pData, xType->getDefaultEnumValue(),
497 : : aNames.getLength(),
498 : 1616 : (rtl_uString **)aNames.getConstArray(),
499 [ + - ][ + - ]: 4848 : const_cast< sal_Int32 * >( aValues.getConstArray() ) );
[ + - ]
500 : : }
501 : 1616 : return pRet;
502 : : }
503 : : //==================================================================================================
504 : 316 : inline static typelib_TypeDescription * createCTD(
505 : : Reference< container::XHierarchicalNameAccess > const & access,
506 : : const Reference< XIndirectTypeDescription > & xType )
507 : : {
508 : 316 : typelib_TypeDescription * pRet = 0;
509 [ + - ]: 316 : if (xType.is())
510 : : {
511 : : typelib_TypeDescription * pRefType = createCTD(
512 [ + - ][ + - ]: 316 : access, xType->getReferencedType() );
[ + - ]
513 : 316 : typelib_typedescription_register( &pRefType );
514 : :
515 [ + - ][ + - ]: 316 : OUString aTypeName( xType->getName() );
516 : :
517 : : typelib_typedescription_new(
518 : : &pRet,
519 [ + - ][ + - ]: 316 : (typelib_TypeClass)xType->getTypeClass(),
520 : : aTypeName.pData,
521 : : pRefType->pWeakRef,
522 : 316 : 0, 0 );
523 : :
524 : : // cleanup
525 : 316 : typelib_typedescription_release( pRefType );
526 : : }
527 : 316 : return pRet;
528 : : }
529 : :
530 : : //==================================================================================================
531 : 152303 : static typelib_TypeDescription * createCTD(
532 : : Reference< container::XHierarchicalNameAccess > const & access,
533 : : const Reference< XTypeDescription > & xType )
534 : : {
535 : 152303 : typelib_TypeDescription * pRet = 0;
536 : :
537 [ + + ]: 152303 : if (xType.is())
538 : : {
539 [ + - ][ + - ]: 145830 : switch (xType->getTypeClass())
[ - - - -
- - + - -
- - + - -
- - + + +
+ + + + +
+ ]
540 : : {
541 : : // built in types
542 : : case TypeClass_VOID:
543 : : {
544 [ # # ]: 0 : OUString aTypeName( RTL_CONSTASCII_USTRINGPARAM("void") );
545 : 0 : typelib_typedescription_new( &pRet, typelib_TypeClass_VOID, aTypeName.pData, 0, 0, 0 );
546 : 0 : break;
547 : : }
548 : : case TypeClass_CHAR:
549 : : {
550 [ # # ]: 0 : OUString aTypeName( RTL_CONSTASCII_USTRINGPARAM("char") );
551 : 0 : typelib_typedescription_new( &pRet, typelib_TypeClass_CHAR, aTypeName.pData, 0, 0, 0 );
552 : 0 : break;
553 : : }
554 : : case TypeClass_BOOLEAN:
555 : : {
556 [ # # ]: 0 : OUString aTypeName( RTL_CONSTASCII_USTRINGPARAM("boolean") );
557 : 0 : typelib_typedescription_new( &pRet, typelib_TypeClass_BOOLEAN, aTypeName.pData, 0, 0, 0 );
558 : 0 : break;
559 : : }
560 : : case TypeClass_BYTE:
561 : : {
562 [ # # ]: 0 : OUString aTypeName( RTL_CONSTASCII_USTRINGPARAM("byte") );
563 : 0 : typelib_typedescription_new( &pRet, typelib_TypeClass_BYTE, aTypeName.pData, 0, 0, 0 );
564 : 0 : break;
565 : : }
566 : : case TypeClass_SHORT:
567 : : {
568 [ # # ]: 0 : OUString aTypeName( RTL_CONSTASCII_USTRINGPARAM("short") );
569 : 0 : typelib_typedescription_new( &pRet, typelib_TypeClass_SHORT, aTypeName.pData, 0, 0, 0 );
570 : 0 : break;
571 : : }
572 : : case TypeClass_UNSIGNED_SHORT:
573 : : {
574 [ # # ]: 0 : OUString aTypeName( RTL_CONSTASCII_USTRINGPARAM("unsigned short") );
575 : 0 : typelib_typedescription_new( &pRet, typelib_TypeClass_UNSIGNED_SHORT, aTypeName.pData, 0, 0, 0 );
576 : 0 : break;
577 : : }
578 : : case TypeClass_LONG:
579 : : {
580 [ + - ]: 439 : OUString aTypeName( RTL_CONSTASCII_USTRINGPARAM("long") );
581 : 439 : typelib_typedescription_new( &pRet, typelib_TypeClass_LONG, aTypeName.pData, 0, 0, 0 );
582 : 439 : break;
583 : : }
584 : : case TypeClass_UNSIGNED_LONG:
585 : : {
586 [ # # ]: 0 : OUString aTypeName( RTL_CONSTASCII_USTRINGPARAM("unsigned long") );
587 : 0 : typelib_typedescription_new( &pRet, typelib_TypeClass_UNSIGNED_LONG, aTypeName.pData, 0, 0, 0 );
588 : 0 : break;
589 : : }
590 : : case TypeClass_HYPER:
591 : : {
592 [ # # ]: 0 : OUString aTypeName( RTL_CONSTASCII_USTRINGPARAM("hyper") );
593 : 0 : typelib_typedescription_new( &pRet, typelib_TypeClass_HYPER, aTypeName.pData, 0, 0, 0 );
594 : 0 : break;
595 : : }
596 : : case TypeClass_UNSIGNED_HYPER:
597 : : {
598 [ # # ]: 0 : OUString aTypeName( RTL_CONSTASCII_USTRINGPARAM("unsigned hyper") );
599 : 0 : typelib_typedescription_new( &pRet, typelib_TypeClass_UNSIGNED_HYPER, aTypeName.pData, 0, 0, 0 );
600 : 0 : break;
601 : : }
602 : : case TypeClass_FLOAT:
603 : : {
604 [ # # ]: 0 : OUString aTypeName( RTL_CONSTASCII_USTRINGPARAM("float") );
605 : 0 : typelib_typedescription_new( &pRet, typelib_TypeClass_FLOAT, aTypeName.pData, 0, 0, 0 );
606 : 0 : break;
607 : : }
608 : : case TypeClass_DOUBLE:
609 : : {
610 [ + - ]: 6 : OUString aTypeName( RTL_CONSTASCII_USTRINGPARAM("double") );
611 : 6 : typelib_typedescription_new( &pRet, typelib_TypeClass_DOUBLE, aTypeName.pData, 0, 0, 0 );
612 : 6 : break;
613 : : }
614 : : case TypeClass_STRING:
615 : : {
616 [ # # ]: 0 : OUString aTypeName( RTL_CONSTASCII_USTRINGPARAM("string") );
617 : 0 : typelib_typedescription_new( &pRet, typelib_TypeClass_STRING, aTypeName.pData, 0, 0, 0 );
618 : 0 : break;
619 : : }
620 : : case TypeClass_TYPE:
621 : : {
622 [ # # ]: 0 : OUString aTypeName( RTL_CONSTASCII_USTRINGPARAM("type") );
623 : 0 : typelib_typedescription_new( &pRet, typelib_TypeClass_TYPE, aTypeName.pData, 0, 0, 0 );
624 : 0 : break;
625 : : }
626 : : case TypeClass_ANY:
627 : : {
628 [ # # ]: 0 : OUString aTypeName( RTL_CONSTASCII_USTRINGPARAM("any") );
629 : 0 : typelib_typedescription_new( &pRet, typelib_TypeClass_ANY, aTypeName.pData, 0, 0, 0 );
630 : 0 : break;
631 : : }
632 : :
633 : : case TypeClass_UNION:
634 [ # # ][ # # ]: 0 : pRet = createCTD( Reference< XUnionTypeDescription >::query( xType ) );
635 : 0 : break;
636 : : case TypeClass_EXCEPTION:
637 [ + - ][ + - ]: 733 : pRet = createCTD( Reference< XCompoundTypeDescription >::query( xType ) );
638 : 733 : break;
639 : : case TypeClass_STRUCT:
640 : : pRet = createCTD(
641 [ + - ][ + - ]: 7184 : access, Reference< XStructTypeDescription >::query( xType ) );
642 : 7184 : break;
643 : : case TypeClass_ENUM:
644 [ + - ][ + - ]: 1616 : pRet = createCTD( Reference< XEnumTypeDescription >::query( xType ) );
645 : 1616 : break;
646 : : case TypeClass_TYPEDEF:
647 : : {
648 [ + - ]: 708 : Reference< XIndirectTypeDescription > xTypedef( xType, UNO_QUERY );
649 [ + - ]: 708 : if (xTypedef.is())
650 [ + - ][ + - ]: 708 : pRet = createCTD( access, xTypedef->getReferencedType() );
[ + - ]
651 : 708 : break;
652 : : }
653 : : case TypeClass_SEQUENCE:
654 : : pRet = createCTD(
655 [ + - ][ + - ]: 316 : access, Reference< XIndirectTypeDescription >::query( xType ) );
656 : 316 : break;
657 : : case TypeClass_INTERFACE:
658 : : pRet = createCTD(
659 : : access,
660 [ + - ][ + - ]: 97245 : Reference< XInterfaceTypeDescription2 >::query( xType ) );
661 : 97245 : break;
662 : : case TypeClass_INTERFACE_METHOD:
663 [ + - ][ + - ]: 30292 : pRet = createCTD( Reference< XInterfaceMethodTypeDescription >::query( xType ) );
664 : 30292 : break;
665 : : case TypeClass_INTERFACE_ATTRIBUTE:
666 [ + - ][ + - ]: 6050 : pRet = createCTD( Reference< XInterfaceAttributeTypeDescription2 >::query( xType ) );
667 : 6050 : break;
668 : : default:
669 : 145830 : break;
670 : : }
671 : : }
672 : :
673 : 152303 : return pRet;
674 : : }
675 : :
676 : :
677 : : //==================================================================================================
678 : : extern "C"
679 : : {
680 : 86001 : static void SAL_CALL typelib_callback(
681 : : void * pContext, typelib_TypeDescription ** ppRet, rtl_uString * pTypeName )
682 : : {
683 : : OSL_ENSURE( pContext && ppRet && pTypeName, "### null ptr!" );
684 [ + - ]: 86001 : if (ppRet)
685 : : {
686 [ - + ]: 86001 : if (*ppRet)
687 : : {
688 : 0 : ::typelib_typedescription_release( *ppRet );
689 : 0 : *ppRet = 0;
690 : : }
691 [ + - ][ + - ]: 86001 : if (pContext && pTypeName)
692 : : {
693 : : Reference< container::XHierarchicalNameAccess > access(
694 : : reinterpret_cast< container::XHierarchicalNameAccess * >(
695 [ + - ]: 86001 : pContext));
696 : : try
697 : : {
698 : 86001 : OUString const & rTypeName = OUString::unacquired( &pTypeName );
699 : 86001 : Reference< XTypeDescription > xTD;
700 [ + - ][ + - ]: 86001 : if (access->getByHierarchicalName(rTypeName ) >>= xTD)
[ + + ][ + - ]
701 : : {
702 [ + - ]: 84432 : *ppRet = createCTD( access, xTD );
703 [ # # # ]: 86001 : }
704 : : }
705 [ # # ]: 0 : catch (container::NoSuchElementException & exc)
706 : : {
707 : : (void) exc; // avoid warning about unused variable
708 : : OSL_TRACE(
709 : : "typelibrary type not available: %s",
710 : : OUStringToOString(
711 : : exc.Message, RTL_TEXTENCODING_UTF8 ).getStr() );
712 : : }
713 [ # # ]: 0 : catch (Exception & exc)
714 : : {
715 : : (void) exc; // avoid warning about unused variable
716 : : OSL_TRACE(
717 : : "%s",
718 : : OUStringToOString(
719 : : exc.Message, RTL_TEXTENCODING_UTF8 ).getStr() );
720 : 86001 : }
721 : : }
722 : : }
723 : 86001 : }
724 : : }
725 : :
726 : : //==================================================================================================
727 [ - + ]: 720 : class EventListenerImpl
728 : : : public WeakImplHelper1< lang::XEventListener >
729 : : {
730 : : Reference< container::XHierarchicalNameAccess > m_xTDMgr;
731 : :
732 : : public:
733 : 756 : inline EventListenerImpl(
734 : : Reference< container::XHierarchicalNameAccess > const & xTDMgr )
735 : : SAL_THROW(())
736 : 756 : : m_xTDMgr( xTDMgr )
737 : 756 : {}
738 : :
739 : : // XEventListener
740 : : virtual void SAL_CALL disposing( lang::EventObject const & rEvt )
741 : : throw (RuntimeException);
742 : : };
743 : : //__________________________________________________________________________________________________
744 : 360 : void EventListenerImpl::disposing( lang::EventObject const & rEvt )
745 : : throw (RuntimeException)
746 : : {
747 : 360 : if (rEvt.Source != m_xTDMgr) {
748 : : OSL_ASSERT(false);
749 : : }
750 : : // deregister of c typelib callback
751 : 360 : ::typelib_typedescription_revokeCallback( m_xTDMgr.get(), typelib_callback );
752 : 360 : }
753 : :
754 : : //==================================================================================================
755 : 756 : sal_Bool SAL_CALL installTypeDescriptionManager(
756 : : Reference< container::XHierarchicalNameAccess > const & xTDMgr_c )
757 : : SAL_THROW(())
758 : : {
759 [ + - ][ + - ]: 756 : uno::Environment curr_env(Environment::getCurrent());
760 [ + - ]: 756 : uno::Environment target_env(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(CPPU_STRINGIFY(CPPU_ENV))));
761 : :
762 : 756 : uno::Mapping curr2target(curr_env, target_env);
763 : :
764 : :
765 : : Reference<container::XHierarchicalNameAccess> xTDMgr(
766 : : reinterpret_cast<container::XHierarchicalNameAccess *>(
767 [ + - ][ + - ]: 756 : curr2target.mapInterface(xTDMgr_c.get(), ::getCppuType(&xTDMgr_c))),
[ + - ]
768 [ + - ]: 756 : SAL_NO_ACQUIRE);
769 : :
770 [ + - ]: 756 : Reference< lang::XComponent > xComp( xTDMgr, UNO_QUERY );
771 [ + - ]: 756 : if (xComp.is())
772 : : {
773 [ + - ][ + - ]: 756 : xComp->addEventListener( new EventListenerImpl( xTDMgr ) );
[ + - ][ + - ]
[ + - ]
774 : : // register c typelib callback
775 [ + - ]: 756 : ::typelib_typedescription_registerCallback( xTDMgr.get(), typelib_callback );
776 : 756 : return sal_True;
777 : : }
778 [ + - ][ + - ]: 756 : return sal_False;
[ + - ]
779 : : }
780 : :
781 : : } // end namespace cppu
782 : :
783 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|