Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 :
21 : #include <sal/config.h>
22 :
23 : #include <vector>
24 :
25 : #include <sal/alloca.h>
26 :
27 : #include <osl/diagnose.h>
28 : #include <rtl/alloc.h>
29 : #include <rtl/ustring.hxx>
30 :
31 : #include <uno/lbnames.h>
32 : #include <uno/mapping.hxx>
33 :
34 : #include <cppuhelper/bootstrap.hxx>
35 : #include <cppuhelper/implbase1.hxx>
36 : #include <typelib/typedescription.h>
37 :
38 : #include <com/sun/star/lang/XComponent.hpp>
39 : #include <com/sun/star/container/XHierarchicalNameAccess.hpp>
40 : #include <com/sun/star/reflection/XTypeDescription.hpp>
41 : #include <com/sun/star/reflection/XEnumTypeDescription.hpp>
42 : #include <com/sun/star/reflection/XIndirectTypeDescription.hpp>
43 : #include <com/sun/star/reflection/XInterfaceMemberTypeDescription.hpp>
44 : #include <com/sun/star/reflection/XInterfaceAttributeTypeDescription2.hpp>
45 : #include <com/sun/star/reflection/XMethodParameter.hpp>
46 : #include <com/sun/star/reflection/XInterfaceMethodTypeDescription.hpp>
47 : #include <com/sun/star/reflection/XInterfaceTypeDescription2.hpp>
48 : #include <com/sun/star/reflection/XCompoundTypeDescription.hpp>
49 : #include <com/sun/star/reflection/XStructTypeDescription.hpp>
50 : #include <com/sun/star/uno/RuntimeException.hpp>
51 :
52 : #include <boost/scoped_array.hpp>
53 :
54 : using namespace ::com::sun::star;
55 : using namespace ::com::sun::star::uno;
56 : using namespace ::com::sun::star::reflection;
57 :
58 : using rtl::OUString;
59 :
60 : namespace cppu
61 : {
62 :
63 : static typelib_TypeDescription * createCTD(
64 : Reference< container::XHierarchicalNameAccess > const & access,
65 : const Reference< XTypeDescription > & xType );
66 :
67 :
68 2153 : inline static typelib_TypeDescription * createCTD(
69 : const Reference< XCompoundTypeDescription > & xType )
70 : {
71 2153 : typelib_TypeDescription * pRet = 0;
72 2153 : if (xType.is())
73 : {
74 : typelib_TypeDescription * pBaseType = createCTD(
75 1621 : Reference< XCompoundTypeDescription >::query( xType->getBaseType() ) );
76 1621 : if (pBaseType)
77 1089 : typelib_typedescription_register( &pBaseType );
78 :
79 : // construct member init array
80 1621 : const Sequence<Reference< XTypeDescription > > & rMemberTypes = xType->getMemberTypes();
81 3242 : const Sequence< OUString > & rMemberNames = xType->getMemberNames();
82 :
83 1621 : const Reference< XTypeDescription > * pMemberTypes = rMemberTypes.getConstArray();
84 1621 : const OUString * pMemberNames = rMemberNames.getConstArray();
85 :
86 1621 : sal_Int32 nMembers = rMemberTypes.getLength();
87 : OSL_ENSURE( nMembers == rMemberNames.getLength(), "### lens differ!" );
88 :
89 3242 : OUString aTypeName( xType->getName() );
90 :
91 1621 : typelib_CompoundMember_Init * pMemberInits = static_cast<typelib_CompoundMember_Init *>(alloca(
92 1621 : sizeof(typelib_CompoundMember_Init) * nMembers ));
93 :
94 : sal_Int32 nPos;
95 5281 : for ( nPos = nMembers; nPos--; )
96 : {
97 2039 : typelib_CompoundMember_Init & rInit = pMemberInits[nPos];
98 2039 : rInit.eTypeClass = (typelib_TypeClass)pMemberTypes[nPos]->getTypeClass();
99 :
100 2039 : OUString aMemberTypeName( pMemberTypes[nPos]->getName() );
101 2039 : rtl_uString_acquire( rInit.pTypeName = aMemberTypeName.pData );
102 :
103 : // string is held by rMemberNames
104 2039 : rInit.pMemberName = pMemberNames[nPos].pData;
105 2039 : }
106 :
107 : typelib_typedescription_new(
108 : &pRet,
109 3242 : (typelib_TypeClass)xType->getTypeClass(),
110 : aTypeName.pData,
111 : (pBaseType ? pBaseType->pWeakRef : 0),
112 4863 : nMembers, pMemberInits );
113 :
114 : // cleanup
115 5281 : for ( nPos = nMembers; nPos--; )
116 : {
117 2039 : rtl_uString_release( pMemberInits[nPos].pTypeName );
118 : }
119 1621 : if (pBaseType)
120 2710 : typelib_typedescription_release( pBaseType );
121 : }
122 2153 : return pRet;
123 : }
124 :
125 5782 : inline static typelib_TypeDescription * createCTD(
126 : Reference< container::XHierarchicalNameAccess > const & access,
127 : const Reference< XStructTypeDescription > & xType )
128 : {
129 5782 : typelib_TypeDescription * pRet = 0;
130 5782 : if (xType.is() && xType->getTypeParameters().getLength() == 0)
131 : {
132 : typelib_TypeDescription * pBaseType = createCTD(
133 5782 : access, xType->getBaseType() );
134 5782 : if (pBaseType)
135 714 : typelib_typedescription_register( &pBaseType );
136 :
137 : // construct member init array
138 5782 : const Sequence<Reference< XTypeDescription > > & rMemberTypes = xType->getMemberTypes();
139 11564 : const Sequence< OUString > & rMemberNames = xType->getMemberNames();
140 :
141 5782 : const Reference< XTypeDescription > * pMemberTypes = rMemberTypes.getConstArray();
142 5782 : const OUString * pMemberNames = rMemberNames.getConstArray();
143 :
144 5782 : sal_Int32 nMembers = rMemberTypes.getLength();
145 : OSL_ENSURE( nMembers == rMemberNames.getLength(), "### lens differ!" );
146 :
147 11564 : OUString aTypeName( xType->getName() );
148 :
149 5782 : typelib_StructMember_Init * pMemberInits = static_cast<typelib_StructMember_Init *>(alloca(
150 5782 : sizeof(typelib_StructMember_Init) * nMembers ));
151 :
152 11564 : Sequence< Reference< XTypeDescription > > templateMemberTypes;
153 5782 : sal_Int32 i = aTypeName.indexOf('<');
154 5782 : if (i >= 0) {
155 : Reference< XStructTypeDescription > templateDesc(
156 215 : access->getByHierarchicalName(aTypeName.copy(0, i)),
157 215 : UNO_QUERY_THROW);
158 : OSL_ASSERT(
159 : templateDesc->getTypeParameters().getLength()
160 : == xType->getTypeArguments().getLength());
161 215 : templateMemberTypes = templateDesc->getMemberTypes();
162 215 : OSL_ASSERT(templateMemberTypes.getLength() == nMembers);
163 : }
164 :
165 : sal_Int32 nPos;
166 32460 : for ( nPos = nMembers; nPos--; )
167 : {
168 20896 : typelib_StructMember_Init & rInit = pMemberInits[nPos];
169 : rInit.aBase.eTypeClass
170 20896 : = (typelib_TypeClass)pMemberTypes[nPos]->getTypeClass();
171 :
172 20896 : OUString aMemberTypeName( pMemberTypes[nPos]->getName() );
173 : rtl_uString_acquire(
174 20896 : rInit.aBase.pTypeName = aMemberTypeName.pData );
175 :
176 : // string is held by rMemberNames
177 20896 : rInit.aBase.pMemberName = pMemberNames[nPos].pData;
178 :
179 20896 : rInit.bParameterizedType = templateMemberTypes.getLength() != 0
180 20896 : && (templateMemberTypes[nPos]->getTypeClass()
181 20896 : == TypeClass_UNKNOWN);
182 20896 : }
183 :
184 : typelib_typedescription_newStruct(
185 : &pRet,
186 : aTypeName.pData,
187 : (pBaseType ? pBaseType->pWeakRef : 0),
188 5782 : nMembers, pMemberInits );
189 :
190 : // cleanup
191 32460 : for ( nPos = nMembers; nPos--; )
192 : {
193 20896 : rtl_uString_release( pMemberInits[nPos].aBase.pTypeName );
194 : }
195 5782 : if (pBaseType)
196 6496 : typelib_typedescription_release( pBaseType );
197 : }
198 5782 : return pRet;
199 : }
200 :
201 4773 : inline static typelib_TypeDescription * createCTD(
202 : const Reference< XInterfaceAttributeTypeDescription2 > & xAttribute )
203 : {
204 4773 : typelib_TypeDescription * pRet = 0;
205 4773 : if (xAttribute.is())
206 : {
207 4773 : OUString aMemberName( xAttribute->getName() );
208 9546 : Reference< XTypeDescription > xType( xAttribute->getType() );
209 9546 : OUString aMemberTypeName( xType->getName() );
210 9546 : std::vector< rtl_uString * > getExc;
211 : Sequence< Reference< XCompoundTypeDescription > > getExcs(
212 9546 : xAttribute->getGetExceptions() );
213 4846 : for (sal_Int32 i = 0; i != getExcs.getLength(); ++i)
214 : {
215 : OSL_ASSERT( getExcs[i].is() );
216 73 : getExc.push_back( getExcs[i]->getName().pData );
217 : }
218 9546 : std::vector< rtl_uString * > setExc;
219 : Sequence< Reference< XCompoundTypeDescription > > setExcs(
220 9546 : xAttribute->getSetExceptions() );
221 5291 : for (sal_Int32 i = 0; i != setExcs.getLength(); ++i)
222 : {
223 : OSL_ASSERT( setExcs[i].is() );
224 518 : setExc.push_back( setExcs[i]->getName().pData );
225 : }
226 : typelib_typedescription_newExtendedInterfaceAttribute(
227 : reinterpret_cast<typelib_InterfaceAttributeTypeDescription **>(&pRet),
228 9546 : xAttribute->getPosition(),
229 : aMemberName.pData, // name
230 4773 : (typelib_TypeClass)xType->getTypeClass(),
231 : aMemberTypeName.pData, // type name
232 4773 : xAttribute->isReadOnly(),
233 4773 : getExc.size(), getExc.data(),
234 33411 : setExc.size(), setExc.data() );
235 : }
236 4773 : return pRet;
237 : }
238 :
239 23849 : static typelib_TypeDescription * createCTD(
240 : const Reference< XInterfaceMethodTypeDescription > & xMethod )
241 : {
242 23849 : typelib_TypeDescription * pRet = 0;
243 23849 : if (xMethod.is())
244 : {
245 23849 : Reference< XTypeDescription > xReturnType( xMethod->getReturnType() );
246 :
247 : // init all params
248 47698 : const Sequence<Reference< XMethodParameter > > & rParams = xMethod->getParameters();
249 23849 : const Reference< XMethodParameter > * pParams = rParams.getConstArray();
250 23849 : sal_Int32 nParams = rParams.getLength();
251 :
252 23849 : typelib_Parameter_Init * pParamInit = static_cast<typelib_Parameter_Init *>(alloca(
253 23849 : sizeof(typelib_Parameter_Init) * nParams ));
254 :
255 : sal_Int32 nPos;
256 67593 : for ( nPos = nParams; nPos--; )
257 : {
258 19895 : const Reference< XMethodParameter > & xParam = pParams[nPos];
259 19895 : const Reference< XTypeDescription > & xType = xParam->getType();
260 19895 : typelib_Parameter_Init & rInit = pParamInit[xParam->getPosition()];
261 :
262 19895 : rInit.eTypeClass = (typelib_TypeClass)xType->getTypeClass();
263 39790 : OUString aParamTypeName( xType->getName() );
264 19895 : rtl_uString_acquire( rInit.pTypeName = aParamTypeName.pData );
265 39790 : OUString aParamName( xParam->getName() );
266 19895 : rtl_uString_acquire( rInit.pParamName = aParamName.pData );
267 19895 : rInit.bIn = xParam->isIn();
268 19895 : rInit.bOut = xParam->isOut();
269 19895 : }
270 :
271 : // init all exception strings
272 47698 : const Sequence<Reference< XTypeDescription > > & rExceptions = xMethod->getExceptions();
273 23849 : const Reference< XTypeDescription > * pExceptions = rExceptions.getConstArray();
274 23849 : sal_Int32 nExceptions = rExceptions.getLength();
275 23849 : rtl_uString ** ppExceptionNames = static_cast<rtl_uString **>(alloca(
276 23849 : sizeof(rtl_uString *) * nExceptions ));
277 :
278 61297 : for ( nPos = nExceptions; nPos--; )
279 : {
280 13599 : OUString aExceptionTypeName( pExceptions[nPos]->getName() );
281 13599 : rtl_uString_acquire( ppExceptionNames[nPos] = aExceptionTypeName.pData );
282 13599 : }
283 :
284 47698 : OUString aTypeName( xMethod->getName() );
285 47698 : OUString aReturnTypeName( xReturnType->getName() );
286 :
287 : typelib_typedescription_newInterfaceMethod(
288 : reinterpret_cast<typelib_InterfaceMethodTypeDescription **>(&pRet),
289 47698 : xMethod->getPosition(),
290 23849 : xMethod->isOneway(),
291 : aTypeName.pData,
292 23849 : (typelib_TypeClass)xReturnType->getTypeClass(),
293 : aReturnTypeName.pData,
294 : nParams, pParamInit,
295 119245 : nExceptions, ppExceptionNames );
296 :
297 67593 : for ( nPos = nParams; nPos--; )
298 : {
299 19895 : rtl_uString_release( pParamInit[nPos].pTypeName );
300 19895 : rtl_uString_release( pParamInit[nPos].pParamName );
301 : }
302 61297 : for ( nPos = nExceptions; nPos--; )
303 : {
304 13599 : rtl_uString_release( ppExceptionNames[nPos] );
305 23849 : }
306 : }
307 23849 : return pRet;
308 : }
309 :
310 92983 : inline static typelib_TypeDescription * createCTD(
311 : Reference< container::XHierarchicalNameAccess > const & access,
312 : const Reference< XInterfaceTypeDescription2 > & xType )
313 : {
314 92983 : typelib_TypeDescription * pRet = 0;
315 92983 : if (xType.is())
316 : {
317 92983 : Sequence< Reference< XTypeDescription > > aBases(xType->getBaseTypes());
318 92983 : sal_Int32 nBases = aBases.getLength();
319 : // Exploit the fact that a typelib_TypeDescription for an interface type
320 : // is also the typelib_TypeDescriptionReference for that type:
321 : boost::scoped_array< typelib_TypeDescription * > aBaseTypes(
322 185966 : new typelib_TypeDescription *[nBases]);
323 155076 : for (sal_Int32 i = 0; i < nBases; ++i) {
324 62093 : typelib_TypeDescription * p = createCTD(access, aBases[i]);
325 : OSL_ASSERT(
326 : !TYPELIB_TYPEDESCRIPTIONREFERENCE_ISREALLYWEAK(p->eTypeClass));
327 62093 : typelib_typedescription_register(&p);
328 62093 : aBaseTypes[i] = p;
329 : }
330 : typelib_TypeDescriptionReference ** pBaseTypeRefs
331 : = reinterpret_cast< typelib_TypeDescriptionReference ** >(
332 92983 : aBaseTypes.get());
333 :
334 : // construct all member refs
335 185966 : const Sequence<Reference< XInterfaceMemberTypeDescription > > & rMembers = xType->getMembers();
336 92983 : sal_Int32 nMembers = rMembers.getLength();
337 :
338 92983 : typelib_TypeDescriptionReference ** ppMemberRefs = static_cast<typelib_TypeDescriptionReference **>(alloca(
339 92983 : sizeof(typelib_TypeDescriptionReference *) * nMembers ));
340 :
341 92983 : const Reference< XInterfaceMemberTypeDescription > * pMembers = rMembers.getConstArray();
342 :
343 185966 : OUString aTypeName( xType->getName() );
344 :
345 : sal_Int32 nPos;
346 490184 : for ( nPos = nMembers; nPos--; )
347 : {
348 304218 : OUString aMemberTypeName( pMembers[nPos]->getName() );
349 304218 : ppMemberRefs[nPos] = 0;
350 : typelib_typedescriptionreference_new(
351 : ppMemberRefs + nPos,
352 608436 : (typelib_TypeClass)pMembers[nPos]->getTypeClass(),
353 912654 : aMemberTypeName.pData );
354 304218 : }
355 :
356 : typelib_typedescription_newMIInterface(
357 : reinterpret_cast<typelib_InterfaceTypeDescription **>(&pRet),
358 : aTypeName.pData,
359 : 0, 0, 0, 0, 0,
360 : nBases, pBaseTypeRefs,
361 92983 : nMembers, ppMemberRefs );
362 :
363 : // cleanup refs and base type
364 155076 : for (int i = 0; i < nBases; ++i) {
365 62093 : typelib_typedescription_release(aBaseTypes[i]);
366 : }
367 :
368 490184 : for ( nPos = nMembers; nPos--; )
369 : {
370 304218 : typelib_typedescriptionreference_release( ppMemberRefs[nPos] );
371 92983 : }
372 : }
373 92983 : return pRet;
374 : }
375 :
376 1011 : inline static typelib_TypeDescription * createCTD( const Reference< XEnumTypeDescription > & xType )
377 : {
378 1011 : typelib_TypeDescription * pRet = 0;
379 1011 : if (xType.is())
380 : {
381 1011 : OUString aTypeName( xType->getName() );
382 2022 : Sequence< OUString > aNames( xType->getEnumNames() );
383 : OSL_ASSERT( sizeof(OUString) == sizeof(rtl_uString *) ); // !!!
384 2022 : Sequence< sal_Int32 > aValues( xType->getEnumValues() );
385 :
386 : typelib_typedescription_newEnum(
387 1011 : &pRet, aTypeName.pData, xType->getDefaultEnumValue(),
388 : aNames.getLength(),
389 1011 : const_cast<rtl_uString **>(reinterpret_cast<rtl_uString * const *>(aNames.getConstArray())),
390 4044 : const_cast< sal_Int32 * >( aValues.getConstArray() ) );
391 : }
392 1011 : return pRet;
393 : }
394 :
395 227 : inline static typelib_TypeDescription * createCTD(
396 : Reference< container::XHierarchicalNameAccess > const & access,
397 : const Reference< XIndirectTypeDescription > & xType )
398 : {
399 227 : typelib_TypeDescription * pRet = 0;
400 227 : if (xType.is())
401 : {
402 : typelib_TypeDescription * pRefType = createCTD(
403 227 : access, xType->getReferencedType() );
404 227 : typelib_typedescription_register( &pRefType );
405 :
406 227 : OUString aTypeName( xType->getName() );
407 :
408 : typelib_typedescription_new(
409 : &pRet,
410 454 : (typelib_TypeClass)xType->getTypeClass(),
411 : aTypeName.pData,
412 : pRefType->pWeakRef,
413 681 : 0, 0 );
414 :
415 : // cleanup
416 227 : typelib_typedescription_release( pRefType );
417 : }
418 227 : return pRet;
419 : }
420 :
421 :
422 135753 : static typelib_TypeDescription * createCTD(
423 : Reference< container::XHierarchicalNameAccess > const & access,
424 : const Reference< XTypeDescription > & xType )
425 : {
426 135753 : typelib_TypeDescription * pRet = 0;
427 :
428 135753 : if (xType.is())
429 : {
430 130685 : switch (xType->getTypeClass())
431 : {
432 : // built in types
433 : case TypeClass_VOID:
434 : {
435 0 : OUString aTypeName("void");
436 0 : typelib_typedescription_new( &pRet, typelib_TypeClass_VOID, aTypeName.pData, 0, 0, 0 );
437 0 : break;
438 : }
439 : case TypeClass_CHAR:
440 : {
441 0 : OUString aTypeName("char");
442 0 : typelib_typedescription_new( &pRet, typelib_TypeClass_CHAR, aTypeName.pData, 0, 0, 0 );
443 0 : break;
444 : }
445 : case TypeClass_BOOLEAN:
446 : {
447 0 : OUString aTypeName("boolean");
448 0 : typelib_typedescription_new( &pRet, typelib_TypeClass_BOOLEAN, aTypeName.pData, 0, 0, 0 );
449 0 : break;
450 : }
451 : case TypeClass_BYTE:
452 : {
453 0 : OUString aTypeName("byte");
454 0 : typelib_typedescription_new( &pRet, typelib_TypeClass_BYTE, aTypeName.pData, 0, 0, 0 );
455 0 : break;
456 : }
457 : case TypeClass_SHORT:
458 : {
459 0 : OUString aTypeName("short");
460 0 : typelib_typedescription_new( &pRet, typelib_TypeClass_SHORT, aTypeName.pData, 0, 0, 0 );
461 0 : break;
462 : }
463 : case TypeClass_UNSIGNED_SHORT:
464 : {
465 0 : OUString aTypeName("unsigned short");
466 0 : typelib_typedescription_new( &pRet, typelib_TypeClass_UNSIGNED_SHORT, aTypeName.pData, 0, 0, 0 );
467 0 : break;
468 : }
469 : case TypeClass_LONG:
470 : {
471 516 : OUString aTypeName("long");
472 516 : typelib_typedescription_new( &pRet, typelib_TypeClass_LONG, aTypeName.pData, 0, 0, 0 );
473 516 : break;
474 : }
475 : case TypeClass_UNSIGNED_LONG:
476 : {
477 0 : OUString aTypeName("unsigned long");
478 0 : typelib_typedescription_new( &pRet, typelib_TypeClass_UNSIGNED_LONG, aTypeName.pData, 0, 0, 0 );
479 0 : break;
480 : }
481 : case TypeClass_HYPER:
482 : {
483 0 : OUString aTypeName("hyper");
484 0 : typelib_typedescription_new( &pRet, typelib_TypeClass_HYPER, aTypeName.pData, 0, 0, 0 );
485 0 : break;
486 : }
487 : case TypeClass_UNSIGNED_HYPER:
488 : {
489 0 : OUString aTypeName("unsigned hyper");
490 0 : typelib_typedescription_new( &pRet, typelib_TypeClass_UNSIGNED_HYPER, aTypeName.pData, 0, 0, 0 );
491 0 : break;
492 : }
493 : case TypeClass_FLOAT:
494 : {
495 0 : OUString aTypeName("float");
496 0 : typelib_typedescription_new( &pRet, typelib_TypeClass_FLOAT, aTypeName.pData, 0, 0, 0 );
497 0 : break;
498 : }
499 : case TypeClass_DOUBLE:
500 : {
501 26 : OUString aTypeName("double");
502 26 : typelib_typedescription_new( &pRet, typelib_TypeClass_DOUBLE, aTypeName.pData, 0, 0, 0 );
503 26 : break;
504 : }
505 : case TypeClass_STRING:
506 : {
507 0 : OUString aTypeName("string");
508 0 : typelib_typedescription_new( &pRet, typelib_TypeClass_STRING, aTypeName.pData, 0, 0, 0 );
509 0 : break;
510 : }
511 : case TypeClass_TYPE:
512 : {
513 0 : OUString aTypeName("type");
514 0 : typelib_typedescription_new( &pRet, typelib_TypeClass_TYPE, aTypeName.pData, 0, 0, 0 );
515 0 : break;
516 : }
517 : case TypeClass_ANY:
518 : {
519 0 : OUString aTypeName("any");
520 0 : typelib_typedescription_new( &pRet, typelib_TypeClass_ANY, aTypeName.pData, 0, 0, 0 );
521 0 : break;
522 : }
523 :
524 : case TypeClass_EXCEPTION:
525 532 : pRet = createCTD( Reference< XCompoundTypeDescription >::query( xType ) );
526 532 : break;
527 : case TypeClass_STRUCT:
528 : pRet = createCTD(
529 5782 : access, Reference< XStructTypeDescription >::query( xType ) );
530 5782 : break;
531 : case TypeClass_ENUM:
532 1011 : pRet = createCTD( Reference< XEnumTypeDescription >::query( xType ) );
533 1011 : break;
534 : case TypeClass_TYPEDEF:
535 : {
536 761 : Reference< XIndirectTypeDescription > xTypedef( xType, UNO_QUERY );
537 761 : if (xTypedef.is())
538 761 : pRet = createCTD( access, xTypedef->getReferencedType() );
539 761 : break;
540 : }
541 : case TypeClass_SEQUENCE:
542 : pRet = createCTD(
543 227 : access, Reference< XIndirectTypeDescription >::query( xType ) );
544 227 : break;
545 : case TypeClass_INTERFACE:
546 : pRet = createCTD(
547 : access,
548 92983 : Reference< XInterfaceTypeDescription2 >::query( xType ) );
549 92983 : break;
550 : case TypeClass_INTERFACE_METHOD:
551 23849 : pRet = createCTD( Reference< XInterfaceMethodTypeDescription >::query( xType ) );
552 23849 : break;
553 : case TypeClass_INTERFACE_ATTRIBUTE:
554 4773 : pRet = createCTD( Reference< XInterfaceAttributeTypeDescription2 >::query( xType ) );
555 4773 : break;
556 : default:
557 225 : break;
558 : }
559 : }
560 :
561 135753 : return pRet;
562 : }
563 :
564 :
565 :
566 : extern "C"
567 : {
568 66922 : static void SAL_CALL typelib_callback(
569 : void * pContext, typelib_TypeDescription ** ppRet, rtl_uString * pTypeName )
570 : {
571 : OSL_ENSURE( pContext && ppRet && pTypeName, "### null ptr!" );
572 66922 : if (ppRet)
573 : {
574 66922 : if (*ppRet)
575 : {
576 0 : ::typelib_typedescription_release( *ppRet );
577 0 : *ppRet = 0;
578 : }
579 66922 : if (pContext && pTypeName)
580 : {
581 : Reference< container::XHierarchicalNameAccess > access(
582 : static_cast< container::XHierarchicalNameAccess * >(
583 66922 : pContext));
584 : try
585 : {
586 66922 : OUString const & rTypeName = OUString::unacquired( &pTypeName );
587 66922 : Reference< XTypeDescription > xTD;
588 66922 : if (access->getByHierarchicalName(rTypeName ) >>= xTD)
589 : {
590 66890 : *ppRet = createCTD( access, xTD );
591 66922 : }
592 : }
593 2 : catch (container::NoSuchElementException & exc)
594 : {
595 : (void) exc; // avoid warning about unused variable
596 : OSL_TRACE(
597 : "typelibrary type not available: %s",
598 : OUStringToOString(
599 : exc.Message, RTL_TEXTENCODING_UTF8 ).getStr() );
600 : }
601 0 : catch (Exception & exc)
602 : {
603 : (void) exc; // avoid warning about unused variable
604 : OSL_TRACE(
605 : "%s",
606 : OUStringToOString(
607 : exc.Message, RTL_TEXTENCODING_UTF8 ).getStr() );
608 66922 : }
609 : }
610 : }
611 66922 : }
612 : }
613 :
614 :
615 1030 : class EventListenerImpl
616 : : public WeakImplHelper1< lang::XEventListener >
617 : {
618 : Reference< container::XHierarchicalNameAccess > m_xTDMgr;
619 :
620 : public:
621 519 : explicit EventListenerImpl(
622 : Reference< container::XHierarchicalNameAccess > const & xTDMgr )
623 519 : : m_xTDMgr( xTDMgr )
624 519 : {}
625 :
626 : // XEventListener
627 : virtual void SAL_CALL disposing( lang::EventObject const & rEvt )
628 : throw (RuntimeException, std::exception) SAL_OVERRIDE;
629 : };
630 :
631 515 : void EventListenerImpl::disposing( lang::EventObject const & rEvt )
632 : throw (RuntimeException, std::exception)
633 : {
634 515 : if (rEvt.Source != m_xTDMgr) {
635 : OSL_ASSERT(false);
636 : }
637 : // deregister of c typelib callback
638 515 : ::typelib_typedescription_revokeCallback( m_xTDMgr.get(), typelib_callback );
639 515 : }
640 :
641 :
642 519 : sal_Bool SAL_CALL installTypeDescriptionManager(
643 : Reference< container::XHierarchicalNameAccess > const & xTDMgr_c )
644 : {
645 519 : uno::Environment curr_env(Environment::getCurrent());
646 1038 : uno::Environment target_env(CPPU_CURRENT_LANGUAGE_BINDING_NAME);
647 :
648 1038 : uno::Mapping curr2target(curr_env, target_env);
649 :
650 :
651 : Reference<container::XHierarchicalNameAccess> xTDMgr(
652 : static_cast<container::XHierarchicalNameAccess *>(
653 519 : curr2target.mapInterface(xTDMgr_c.get(), cppu::UnoType<decltype(xTDMgr_c)>::get())),
654 1038 : SAL_NO_ACQUIRE);
655 :
656 1038 : Reference< lang::XComponent > xComp( xTDMgr, UNO_QUERY );
657 519 : if (xComp.is())
658 : {
659 519 : xComp->addEventListener( new EventListenerImpl( xTDMgr ) );
660 : // register c typelib callback
661 519 : ::typelib_typedescription_registerCallback( xTDMgr.get(), typelib_callback );
662 519 : return sal_True;
663 : }
664 519 : return sal_False;
665 : }
666 :
667 : } // end namespace cppu
668 :
669 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|