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