LCOV - code coverage report
Current view: top level - cppuhelper/source - tdmgr.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 236 278 84.9 %
Date: 2014-04-11 Functions: 14 14 100.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10