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