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 0 : inline static typelib_TypeDescription * createCTD(
69 : const Reference< XCompoundTypeDescription > & xType )
70 : {
71 0 : typelib_TypeDescription * pRet = 0;
72 0 : if (xType.is())
73 : {
74 : typelib_TypeDescription * pBaseType = createCTD(
75 0 : Reference< XCompoundTypeDescription >::query( xType->getBaseType() ) );
76 0 : if (pBaseType)
77 0 : typelib_typedescription_register( &pBaseType );
78 :
79 : // construct member init array
80 0 : const Sequence<Reference< XTypeDescription > > & rMemberTypes = xType->getMemberTypes();
81 0 : const Sequence< OUString > & rMemberNames = xType->getMemberNames();
82 :
83 0 : const Reference< XTypeDescription > * pMemberTypes = rMemberTypes.getConstArray();
84 0 : const OUString * pMemberNames = rMemberNames.getConstArray();
85 :
86 0 : sal_Int32 nMembers = rMemberTypes.getLength();
87 : OSL_ENSURE( nMembers == rMemberNames.getLength(), "### lens differ!" );
88 :
89 0 : OUString aTypeName( xType->getName() );
90 :
91 0 : typelib_CompoundMember_Init * pMemberInits = (typelib_CompoundMember_Init *)alloca(
92 : sizeof(typelib_CompoundMember_Init) * nMembers );
93 :
94 : sal_Int32 nPos;
95 0 : for ( nPos = nMembers; nPos--; )
96 : {
97 0 : typelib_CompoundMember_Init & rInit = pMemberInits[nPos];
98 0 : rInit.eTypeClass = (typelib_TypeClass)pMemberTypes[nPos]->getTypeClass();
99 :
100 0 : OUString aMemberTypeName( pMemberTypes[nPos]->getName() );
101 0 : rtl_uString_acquire( rInit.pTypeName = aMemberTypeName.pData );
102 :
103 : // string is held by rMemberNames
104 0 : rInit.pMemberName = pMemberNames[nPos].pData;
105 0 : }
106 :
107 : typelib_typedescription_new(
108 : &pRet,
109 0 : (typelib_TypeClass)xType->getTypeClass(),
110 : aTypeName.pData,
111 : (pBaseType ? pBaseType->pWeakRef : 0),
112 0 : nMembers, pMemberInits );
113 :
114 : // cleanup
115 0 : for ( nPos = nMembers; nPos--; )
116 : {
117 0 : rtl_uString_release( pMemberInits[nPos].pTypeName );
118 : }
119 0 : if (pBaseType)
120 0 : typelib_typedescription_release( pBaseType );
121 : }
122 0 : return pRet;
123 : }
124 :
125 1 : inline static typelib_TypeDescription * createCTD(
126 : Reference< container::XHierarchicalNameAccess > const & access,
127 : const Reference< XStructTypeDescription > & xType )
128 : {
129 1 : typelib_TypeDescription * pRet = 0;
130 1 : if (xType.is() && xType->getTypeParameters().getLength() == 0)
131 : {
132 : typelib_TypeDescription * pBaseType = createCTD(
133 1 : access, xType->getBaseType() );
134 1 : if (pBaseType)
135 0 : typelib_typedescription_register( &pBaseType );
136 :
137 : // construct member init array
138 1 : const Sequence<Reference< XTypeDescription > > & rMemberTypes = xType->getMemberTypes();
139 2 : const Sequence< OUString > & rMemberNames = xType->getMemberNames();
140 :
141 1 : const Reference< XTypeDescription > * pMemberTypes = rMemberTypes.getConstArray();
142 1 : const OUString * pMemberNames = rMemberNames.getConstArray();
143 :
144 1 : sal_Int32 nMembers = rMemberTypes.getLength();
145 : OSL_ENSURE( nMembers == rMemberNames.getLength(), "### lens differ!" );
146 :
147 2 : OUString aTypeName( xType->getName() );
148 :
149 1 : typelib_StructMember_Init * pMemberInits = (typelib_StructMember_Init *)alloca(
150 : sizeof(typelib_StructMember_Init) * nMembers );
151 :
152 2 : Sequence< Reference< XTypeDescription > > templateMemberTypes;
153 1 : sal_Int32 i = aTypeName.indexOf('<');
154 1 : if (i >= 0) {
155 : Reference< XStructTypeDescription > templateDesc(
156 1 : access->getByHierarchicalName(aTypeName.copy(0, i)),
157 1 : UNO_QUERY_THROW);
158 : OSL_ASSERT(
159 : templateDesc->getTypeParameters().getLength()
160 : == xType->getTypeArguments().getLength());
161 1 : templateMemberTypes = templateDesc->getMemberTypes();
162 1 : OSL_ASSERT(templateMemberTypes.getLength() == nMembers);
163 : }
164 :
165 : sal_Int32 nPos;
166 4 : for ( nPos = nMembers; nPos--; )
167 : {
168 2 : typelib_StructMember_Init & rInit = pMemberInits[nPos];
169 : rInit.aBase.eTypeClass
170 2 : = (typelib_TypeClass)pMemberTypes[nPos]->getTypeClass();
171 :
172 2 : OUString aMemberTypeName( pMemberTypes[nPos]->getName() );
173 : rtl_uString_acquire(
174 2 : rInit.aBase.pTypeName = aMemberTypeName.pData );
175 :
176 : // string is held by rMemberNames
177 2 : rInit.aBase.pMemberName = pMemberNames[nPos].pData;
178 :
179 2 : rInit.bParameterizedType = templateMemberTypes.getLength() != 0
180 2 : && (templateMemberTypes[nPos]->getTypeClass()
181 2 : == TypeClass_UNKNOWN);
182 2 : }
183 :
184 : typelib_typedescription_newStruct(
185 : &pRet,
186 : aTypeName.pData,
187 : (pBaseType ? pBaseType->pWeakRef : 0),
188 1 : nMembers, pMemberInits );
189 :
190 : // cleanup
191 4 : for ( nPos = nMembers; nPos--; )
192 : {
193 2 : rtl_uString_release( pMemberInits[nPos].aBase.pTypeName );
194 : }
195 1 : if (pBaseType)
196 1 : typelib_typedescription_release( pBaseType );
197 : }
198 1 : return pRet;
199 : }
200 :
201 0 : inline static typelib_TypeDescription * createCTD(
202 : const Reference< XInterfaceAttributeTypeDescription2 > & xAttribute )
203 : {
204 0 : typelib_TypeDescription * pRet = 0;
205 0 : if (xAttribute.is())
206 : {
207 0 : OUString aMemberName( xAttribute->getName() );
208 0 : Reference< XTypeDescription > xType( xAttribute->getType() );
209 0 : OUString aMemberTypeName( xType->getName() );
210 0 : std::vector< rtl_uString * > getExc;
211 : Sequence< Reference< XCompoundTypeDescription > > getExcs(
212 0 : xAttribute->getGetExceptions() );
213 0 : for (sal_Int32 i = 0; i != getExcs.getLength(); ++i)
214 : {
215 : OSL_ASSERT( getExcs[i].is() );
216 0 : getExc.push_back( getExcs[i]->getName().pData );
217 : }
218 0 : std::vector< rtl_uString * > setExc;
219 : Sequence< Reference< XCompoundTypeDescription > > setExcs(
220 0 : xAttribute->getSetExceptions() );
221 0 : for (sal_Int32 i = 0; i != setExcs.getLength(); ++i)
222 : {
223 : OSL_ASSERT( setExcs[i].is() );
224 0 : setExc.push_back( setExcs[i]->getName().pData );
225 : }
226 : typelib_typedescription_newExtendedInterfaceAttribute(
227 : (typelib_InterfaceAttributeTypeDescription **)&pRet,
228 0 : xAttribute->getPosition(),
229 : aMemberName.pData, // name
230 0 : (typelib_TypeClass)xType->getTypeClass(),
231 : aMemberTypeName.pData, // type name
232 0 : xAttribute->isReadOnly(),
233 0 : getExc.size(), getExc.empty() ? 0 : &getExc[0],
234 0 : setExc.size(), setExc.empty() ? 0 : &setExc[0] );
235 : }
236 0 : return pRet;
237 : }
238 :
239 0 : static typelib_TypeDescription * createCTD(
240 : const Reference< XInterfaceMethodTypeDescription > & xMethod )
241 : {
242 0 : typelib_TypeDescription * pRet = 0;
243 0 : if (xMethod.is())
244 : {
245 0 : Reference< XTypeDescription > xReturnType( xMethod->getReturnType() );
246 :
247 : // init all params
248 0 : const Sequence<Reference< XMethodParameter > > & rParams = xMethod->getParameters();
249 0 : const Reference< XMethodParameter > * pParams = rParams.getConstArray();
250 0 : sal_Int32 nParams = rParams.getLength();
251 :
252 0 : typelib_Parameter_Init * pParamInit = (typelib_Parameter_Init *)alloca(
253 : sizeof(typelib_Parameter_Init) * nParams );
254 :
255 : sal_Int32 nPos;
256 0 : for ( nPos = nParams; nPos--; )
257 : {
258 0 : const Reference< XMethodParameter > & xParam = pParams[nPos];
259 0 : const Reference< XTypeDescription > & xType = xParam->getType();
260 0 : typelib_Parameter_Init & rInit = pParamInit[xParam->getPosition()];
261 :
262 0 : rInit.eTypeClass = (typelib_TypeClass)xType->getTypeClass();
263 0 : OUString aParamTypeName( xType->getName() );
264 0 : rtl_uString_acquire( rInit.pTypeName = aParamTypeName.pData );
265 0 : OUString aParamName( xParam->getName() );
266 0 : rtl_uString_acquire( rInit.pParamName = aParamName.pData );
267 0 : rInit.bIn = xParam->isIn();
268 0 : rInit.bOut = xParam->isOut();
269 0 : }
270 :
271 : // init all exception strings
272 0 : const Sequence<Reference< XTypeDescription > > & rExceptions = xMethod->getExceptions();
273 0 : const Reference< XTypeDescription > * pExceptions = rExceptions.getConstArray();
274 0 : sal_Int32 nExceptions = rExceptions.getLength();
275 0 : rtl_uString ** ppExceptionNames = (rtl_uString **)alloca(
276 : sizeof(rtl_uString *) * nExceptions );
277 :
278 0 : for ( nPos = nExceptions; nPos--; )
279 : {
280 0 : OUString aExceptionTypeName( pExceptions[nPos]->getName() );
281 0 : rtl_uString_acquire( ppExceptionNames[nPos] = aExceptionTypeName.pData );
282 0 : }
283 :
284 0 : OUString aTypeName( xMethod->getName() );
285 0 : OUString aReturnTypeName( xReturnType->getName() );
286 :
287 : typelib_typedescription_newInterfaceMethod(
288 : (typelib_InterfaceMethodTypeDescription **)&pRet,
289 0 : xMethod->getPosition(),
290 0 : xMethod->isOneway(),
291 : aTypeName.pData,
292 0 : (typelib_TypeClass)xReturnType->getTypeClass(),
293 : aReturnTypeName.pData,
294 : nParams, pParamInit,
295 0 : nExceptions, ppExceptionNames );
296 :
297 0 : for ( nPos = nParams; nPos--; )
298 : {
299 0 : rtl_uString_release( pParamInit[nPos].pTypeName );
300 0 : rtl_uString_release( pParamInit[nPos].pParamName );
301 : }
302 0 : for ( nPos = nExceptions; nPos--; )
303 : {
304 0 : rtl_uString_release( ppExceptionNames[nPos] );
305 0 : }
306 : }
307 0 : return pRet;
308 : }
309 :
310 6 : inline static typelib_TypeDescription * createCTD(
311 : Reference< container::XHierarchicalNameAccess > const & access,
312 : const Reference< XInterfaceTypeDescription2 > & xType )
313 : {
314 6 : typelib_TypeDescription * pRet = 0;
315 6 : if (xType.is())
316 : {
317 6 : Sequence< Reference< XTypeDescription > > aBases(xType->getBaseTypes());
318 6 : 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 12 : new typelib_TypeDescription *[nBases]);
323 9 : for (sal_Int32 i = 0; i < nBases; ++i) {
324 3 : typelib_TypeDescription * p = createCTD(access, aBases[i]);
325 : OSL_ASSERT(
326 : !TYPELIB_TYPEDESCRIPTIONREFERENCE_ISREALLYWEAK(p->eTypeClass));
327 3 : typelib_typedescription_register(&p);
328 3 : aBaseTypes[i] = p;
329 : }
330 : typelib_TypeDescriptionReference ** pBaseTypeRefs
331 : = reinterpret_cast< typelib_TypeDescriptionReference ** >(
332 6 : aBaseTypes.get());
333 :
334 : // construct all member refs
335 12 : const Sequence<Reference< XInterfaceMemberTypeDescription > > & rMembers = xType->getMembers();
336 6 : sal_Int32 nMembers = rMembers.getLength();
337 :
338 6 : typelib_TypeDescriptionReference ** ppMemberRefs = (typelib_TypeDescriptionReference **)alloca(
339 : sizeof(typelib_TypeDescriptionReference *) * nMembers );
340 :
341 6 : const Reference< XInterfaceMemberTypeDescription > * pMembers = rMembers.getConstArray();
342 :
343 12 : OUString aTypeName( xType->getName() );
344 :
345 : sal_Int32 nPos;
346 29 : for ( nPos = nMembers; nPos--; )
347 : {
348 17 : OUString aMemberTypeName( pMembers[nPos]->getName() );
349 17 : ppMemberRefs[nPos] = 0;
350 : typelib_typedescriptionreference_new(
351 : ppMemberRefs + nPos,
352 34 : (typelib_TypeClass)pMembers[nPos]->getTypeClass(),
353 51 : aMemberTypeName.pData );
354 17 : }
355 :
356 : typelib_typedescription_newMIInterface(
357 : (typelib_InterfaceTypeDescription **)&pRet,
358 : aTypeName.pData,
359 : 0, 0, 0, 0, 0,
360 : nBases, pBaseTypeRefs,
361 6 : nMembers, ppMemberRefs );
362 :
363 : // cleanup refs and base type
364 9 : for (int i = 0; i < nBases; ++i) {
365 3 : typelib_typedescription_release(aBaseTypes[i]);
366 : }
367 :
368 29 : for ( nPos = nMembers; nPos--; )
369 : {
370 17 : typelib_typedescriptionreference_release( ppMemberRefs[nPos] );
371 6 : }
372 : }
373 6 : return pRet;
374 : }
375 :
376 0 : inline static typelib_TypeDescription * createCTD( const Reference< XEnumTypeDescription > & xType )
377 : {
378 0 : typelib_TypeDescription * pRet = 0;
379 0 : if (xType.is())
380 : {
381 0 : OUString aTypeName( xType->getName() );
382 0 : Sequence< OUString > aNames( xType->getEnumNames() );
383 : OSL_ASSERT( sizeof(OUString) == sizeof(rtl_uString *) ); // !!!
384 0 : Sequence< sal_Int32 > aValues( xType->getEnumValues() );
385 :
386 : typelib_typedescription_newEnum(
387 0 : &pRet, aTypeName.pData, xType->getDefaultEnumValue(),
388 : aNames.getLength(),
389 0 : (rtl_uString **)aNames.getConstArray(),
390 0 : const_cast< sal_Int32 * >( aValues.getConstArray() ) );
391 : }
392 0 : return pRet;
393 : }
394 :
395 0 : inline static typelib_TypeDescription * createCTD(
396 : Reference< container::XHierarchicalNameAccess > const & access,
397 : const Reference< XIndirectTypeDescription > & xType )
398 : {
399 0 : typelib_TypeDescription * pRet = 0;
400 0 : if (xType.is())
401 : {
402 : typelib_TypeDescription * pRefType = createCTD(
403 0 : access, xType->getReferencedType() );
404 0 : typelib_typedescription_register( &pRefType );
405 :
406 0 : OUString aTypeName( xType->getName() );
407 :
408 : typelib_typedescription_new(
409 : &pRet,
410 0 : (typelib_TypeClass)xType->getTypeClass(),
411 : aTypeName.pData,
412 : pRefType->pWeakRef,
413 0 : 0, 0 );
414 :
415 : // cleanup
416 0 : typelib_typedescription_release( pRefType );
417 : }
418 0 : return pRet;
419 : }
420 :
421 :
422 8 : static typelib_TypeDescription * createCTD(
423 : Reference< container::XHierarchicalNameAccess > const & access,
424 : const Reference< XTypeDescription > & xType )
425 : {
426 8 : typelib_TypeDescription * pRet = 0;
427 :
428 8 : if (xType.is())
429 : {
430 7 : 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 0 : OUString aTypeName("long");
472 0 : typelib_typedescription_new( &pRet, typelib_TypeClass_LONG, aTypeName.pData, 0, 0, 0 );
473 0 : 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 0 : OUString aTypeName("double");
502 0 : typelib_typedescription_new( &pRet, typelib_TypeClass_DOUBLE, aTypeName.pData, 0, 0, 0 );
503 0 : 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 0 : pRet = createCTD( Reference< XCompoundTypeDescription >::query( xType ) );
526 0 : break;
527 : case TypeClass_STRUCT:
528 : pRet = createCTD(
529 1 : access, Reference< XStructTypeDescription >::query( xType ) );
530 1 : break;
531 : case TypeClass_ENUM:
532 0 : pRet = createCTD( Reference< XEnumTypeDescription >::query( xType ) );
533 0 : break;
534 : case TypeClass_TYPEDEF:
535 : {
536 0 : Reference< XIndirectTypeDescription > xTypedef( xType, UNO_QUERY );
537 0 : if (xTypedef.is())
538 0 : pRet = createCTD( access, xTypedef->getReferencedType() );
539 0 : break;
540 : }
541 : case TypeClass_SEQUENCE:
542 : pRet = createCTD(
543 0 : access, Reference< XIndirectTypeDescription >::query( xType ) );
544 0 : break;
545 : case TypeClass_INTERFACE:
546 : pRet = createCTD(
547 : access,
548 6 : Reference< XInterfaceTypeDescription2 >::query( xType ) );
549 6 : break;
550 : case TypeClass_INTERFACE_METHOD:
551 0 : pRet = createCTD( Reference< XInterfaceMethodTypeDescription >::query( xType ) );
552 0 : break;
553 : case TypeClass_INTERFACE_ATTRIBUTE:
554 0 : pRet = createCTD( Reference< XInterfaceAttributeTypeDescription2 >::query( xType ) );
555 0 : break;
556 : default:
557 0 : break;
558 : }
559 : }
560 :
561 8 : return pRet;
562 : }
563 :
564 :
565 :
566 : extern "C"
567 : {
568 4 : 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 4 : if (ppRet)
573 : {
574 4 : if (*ppRet)
575 : {
576 0 : ::typelib_typedescription_release( *ppRet );
577 0 : *ppRet = 0;
578 : }
579 4 : if (pContext && pTypeName)
580 : {
581 : Reference< container::XHierarchicalNameAccess > access(
582 : reinterpret_cast< container::XHierarchicalNameAccess * >(
583 4 : pContext));
584 : try
585 : {
586 4 : OUString const & rTypeName = OUString::unacquired( &pTypeName );
587 4 : Reference< XTypeDescription > xTD;
588 4 : if (access->getByHierarchicalName(rTypeName ) >>= xTD)
589 : {
590 4 : *ppRet = createCTD( access, xTD );
591 4 : }
592 : }
593 0 : 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 4 : }
609 : }
610 : }
611 4 : }
612 : }
613 :
614 :
615 2 : class EventListenerImpl
616 : : public WeakImplHelper1< lang::XEventListener >
617 : {
618 : Reference< container::XHierarchicalNameAccess > m_xTDMgr;
619 :
620 : public:
621 1 : inline EventListenerImpl(
622 : Reference< container::XHierarchicalNameAccess > const & xTDMgr )
623 : SAL_THROW(())
624 1 : : m_xTDMgr( xTDMgr )
625 1 : {}
626 :
627 : // XEventListener
628 : virtual void SAL_CALL disposing( lang::EventObject const & rEvt )
629 : throw (RuntimeException, std::exception) SAL_OVERRIDE;
630 : };
631 :
632 1 : void EventListenerImpl::disposing( lang::EventObject const & rEvt )
633 : throw (RuntimeException, std::exception)
634 : {
635 1 : if (rEvt.Source != m_xTDMgr) {
636 : OSL_ASSERT(false);
637 : }
638 : // deregister of c typelib callback
639 1 : ::typelib_typedescription_revokeCallback( m_xTDMgr.get(), typelib_callback );
640 1 : }
641 :
642 :
643 1 : sal_Bool SAL_CALL installTypeDescriptionManager(
644 : Reference< container::XHierarchicalNameAccess > const & xTDMgr_c )
645 : SAL_THROW(())
646 : {
647 1 : uno::Environment curr_env(Environment::getCurrent());
648 2 : uno::Environment target_env(CPPU_CURRENT_LANGUAGE_BINDING_NAME);
649 :
650 2 : uno::Mapping curr2target(curr_env, target_env);
651 :
652 :
653 : Reference<container::XHierarchicalNameAccess> xTDMgr(
654 : reinterpret_cast<container::XHierarchicalNameAccess *>(
655 1 : curr2target.mapInterface(xTDMgr_c.get(), ::getCppuType(&xTDMgr_c))),
656 2 : SAL_NO_ACQUIRE);
657 :
658 2 : Reference< lang::XComponent > xComp( xTDMgr, UNO_QUERY );
659 1 : if (xComp.is())
660 : {
661 1 : xComp->addEventListener( new EventListenerImpl( xTDMgr ) );
662 : // register c typelib callback
663 1 : ::typelib_typedescription_registerCallback( xTDMgr.get(), typelib_callback );
664 1 : return sal_True;
665 : }
666 1 : return sal_False;
667 : }
668 :
669 : } // end namespace cppu
670 :
671 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|