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 #ifndef _UNO_MAPPING_HXX_ 28*cdf0e10cSrcweir #define _UNO_MAPPING_HXX_ 29*cdf0e10cSrcweir 30*cdf0e10cSrcweir #include <cppu/macros.hxx> 31*cdf0e10cSrcweir #include <rtl/alloc.h> 32*cdf0e10cSrcweir #include <rtl/ustring.hxx> 33*cdf0e10cSrcweir #include <uno/mapping.h> 34*cdf0e10cSrcweir #include <com/sun/star/uno/Type.hxx> 35*cdf0e10cSrcweir #include <com/sun/star/uno/Reference.hxx> 36*cdf0e10cSrcweir #include "cppu/unotype.hxx" 37*cdf0e10cSrcweir #include "uno/environment.hxx" 38*cdf0e10cSrcweir 39*cdf0e10cSrcweir typedef struct _typelib_TypeDescription typelib_TypeDescription; 40*cdf0e10cSrcweir typedef struct _typelib_InterfaceTypeDescription typelib_InterfaceTypeDescription; 41*cdf0e10cSrcweir typedef struct _uno_Interface uno_Interface; 42*cdf0e10cSrcweir 43*cdf0e10cSrcweir namespace com 44*cdf0e10cSrcweir { 45*cdf0e10cSrcweir namespace sun 46*cdf0e10cSrcweir { 47*cdf0e10cSrcweir namespace star 48*cdf0e10cSrcweir { 49*cdf0e10cSrcweir namespace uno 50*cdf0e10cSrcweir { 51*cdf0e10cSrcweir 52*cdf0e10cSrcweir /** C++ wrapper for C uno_Mapping. 53*cdf0e10cSrcweir 54*cdf0e10cSrcweir @see uno_Mapping 55*cdf0e10cSrcweir */ 56*cdf0e10cSrcweir class Mapping 57*cdf0e10cSrcweir { 58*cdf0e10cSrcweir uno_Mapping * _pMapping; 59*cdf0e10cSrcweir 60*cdf0e10cSrcweir public: 61*cdf0e10cSrcweir // these are here to force memory de/allocation to sal lib. 62*cdf0e10cSrcweir /** @internal */ 63*cdf0e10cSrcweir inline static void * SAL_CALL operator new ( size_t nSize ) SAL_THROW( () ) 64*cdf0e10cSrcweir { return ::rtl_allocateMemory( nSize ); } 65*cdf0e10cSrcweir /** @internal */ 66*cdf0e10cSrcweir inline static void SAL_CALL operator delete ( void * pMem ) SAL_THROW( () ) 67*cdf0e10cSrcweir { ::rtl_freeMemory( pMem ); } 68*cdf0e10cSrcweir /** @internal */ 69*cdf0e10cSrcweir inline static void * SAL_CALL operator new ( size_t, void * pMem ) SAL_THROW( () ) 70*cdf0e10cSrcweir { return pMem; } 71*cdf0e10cSrcweir /** @internal */ 72*cdf0e10cSrcweir inline static void SAL_CALL operator delete ( void *, void * ) SAL_THROW( () ) 73*cdf0e10cSrcweir {} 74*cdf0e10cSrcweir 75*cdf0e10cSrcweir /** Holds a mapping from the specified source to the specified destination by environment 76*cdf0e10cSrcweir type names. 77*cdf0e10cSrcweir 78*cdf0e10cSrcweir @param rFrom type name of source environment 79*cdf0e10cSrcweir @param rTo type name of destination environment 80*cdf0e10cSrcweir @param rAddPurpose additional purpose 81*cdf0e10cSrcweir */ 82*cdf0e10cSrcweir inline Mapping( 83*cdf0e10cSrcweir const ::rtl::OUString & rFrom, const ::rtl::OUString & rTo, 84*cdf0e10cSrcweir const ::rtl::OUString & rAddPurpose = ::rtl::OUString() ) 85*cdf0e10cSrcweir SAL_THROW( () ); 86*cdf0e10cSrcweir 87*cdf0e10cSrcweir /** Holds a mapping from the specified source to the specified destination. 88*cdf0e10cSrcweir 89*cdf0e10cSrcweir @param pFrom source environment 90*cdf0e10cSrcweir @param pTo destination environment 91*cdf0e10cSrcweir @param rAddPurpose additional purpose 92*cdf0e10cSrcweir */ 93*cdf0e10cSrcweir inline Mapping( 94*cdf0e10cSrcweir uno_Environment * pFrom, uno_Environment * pTo, 95*cdf0e10cSrcweir const ::rtl::OUString & rAddPurpose = ::rtl::OUString() ) 96*cdf0e10cSrcweir SAL_THROW( () ); 97*cdf0e10cSrcweir 98*cdf0e10cSrcweir /** Holds a mapping from the specified source to the specified destination 99*cdf0e10cSrcweir environment. 100*cdf0e10cSrcweir 101*cdf0e10cSrcweir @param from source environment 102*cdf0e10cSrcweir @param to destination environment 103*cdf0e10cSrcweir @param rAddPurpose additional purpose 104*cdf0e10cSrcweir */ 105*cdf0e10cSrcweir inline Mapping(const Environment & rFrom, const Environment & rTo, 106*cdf0e10cSrcweir const ::rtl::OUString & rAddPurpose = ::rtl::OUString() ) 107*cdf0e10cSrcweir SAL_THROW( () ); 108*cdf0e10cSrcweir 109*cdf0e10cSrcweir /** Constructor. 110*cdf0e10cSrcweir 111*cdf0e10cSrcweir @param pMapping another mapping 112*cdf0e10cSrcweir */ 113*cdf0e10cSrcweir inline Mapping( uno_Mapping * pMapping = 0 ) SAL_THROW( () ); 114*cdf0e10cSrcweir 115*cdf0e10cSrcweir /** Copy constructor. 116*cdf0e10cSrcweir 117*cdf0e10cSrcweir @param rMapping another mapping 118*cdf0e10cSrcweir */ 119*cdf0e10cSrcweir inline Mapping( const Mapping & rMapping ) SAL_THROW( () ); 120*cdf0e10cSrcweir 121*cdf0e10cSrcweir /** Destructor. 122*cdf0e10cSrcweir */ 123*cdf0e10cSrcweir inline ~Mapping() SAL_THROW( () ); 124*cdf0e10cSrcweir 125*cdf0e10cSrcweir /** Sets a given mapping. 126*cdf0e10cSrcweir 127*cdf0e10cSrcweir @param pMapping another mapping 128*cdf0e10cSrcweir @return this mapping 129*cdf0e10cSrcweir */ 130*cdf0e10cSrcweir inline Mapping & SAL_CALL operator = ( uno_Mapping * pMapping ) SAL_THROW( () ); 131*cdf0e10cSrcweir /** Sets a given mapping. 132*cdf0e10cSrcweir 133*cdf0e10cSrcweir @param rMapping another mapping 134*cdf0e10cSrcweir @return this mapping 135*cdf0e10cSrcweir */ 136*cdf0e10cSrcweir inline Mapping & SAL_CALL operator = ( const Mapping & rMapping ) SAL_THROW( () ) 137*cdf0e10cSrcweir { return operator = ( rMapping._pMapping ); } 138*cdf0e10cSrcweir 139*cdf0e10cSrcweir /** Provides a pointer to the C mapping. The returned mapping is NOT acquired! 140*cdf0e10cSrcweir 141*cdf0e10cSrcweir @return UNacquired C mapping 142*cdf0e10cSrcweir */ 143*cdf0e10cSrcweir inline uno_Mapping * SAL_CALL get() const SAL_THROW( () ) 144*cdf0e10cSrcweir { return _pMapping; } 145*cdf0e10cSrcweir 146*cdf0e10cSrcweir /** Tests if a mapping is set. 147*cdf0e10cSrcweir 148*cdf0e10cSrcweir @return true if a mapping is set 149*cdf0e10cSrcweir */ 150*cdf0e10cSrcweir inline sal_Bool SAL_CALL is() const SAL_THROW( () ) 151*cdf0e10cSrcweir { return (_pMapping != 0); } 152*cdf0e10cSrcweir 153*cdf0e10cSrcweir /** Releases a set mapping. 154*cdf0e10cSrcweir */ 155*cdf0e10cSrcweir inline void SAL_CALL clear() SAL_THROW( () ); 156*cdf0e10cSrcweir 157*cdf0e10cSrcweir /** Maps an interface from one environment to another. 158*cdf0e10cSrcweir 159*cdf0e10cSrcweir @param pInterface source interface 160*cdf0e10cSrcweir @param pTypeDescr type description of interface 161*cdf0e10cSrcweir @return mapped interface 162*cdf0e10cSrcweir */ 163*cdf0e10cSrcweir inline void * SAL_CALL mapInterface( void * pInterface, typelib_InterfaceTypeDescription * pTypeDescr ) const SAL_THROW( () ); 164*cdf0e10cSrcweir /** Maps an interface from one environment to another. 165*cdf0e10cSrcweir 166*cdf0e10cSrcweir @param pInterface source interface 167*cdf0e10cSrcweir @param pTypeDescr type description of interface 168*cdf0e10cSrcweir @return mapped interface 169*cdf0e10cSrcweir */ 170*cdf0e10cSrcweir inline void * SAL_CALL mapInterface( void * pInterface, typelib_TypeDescription * pTypeDescr ) const SAL_THROW( () ) 171*cdf0e10cSrcweir { return mapInterface( pInterface, (typelib_InterfaceTypeDescription *)pTypeDescr ); } 172*cdf0e10cSrcweir 173*cdf0e10cSrcweir /** Maps an interface from one environment to another. 174*cdf0e10cSrcweir 175*cdf0e10cSrcweir @param pInterface source interface 176*cdf0e10cSrcweir @param rType type of interface 177*cdf0e10cSrcweir @return mapped interface 178*cdf0e10cSrcweir */ 179*cdf0e10cSrcweir inline void * SAL_CALL mapInterface( 180*cdf0e10cSrcweir void * pInterface, const ::com::sun::star::uno::Type & rType ) const SAL_THROW( () ); 181*cdf0e10cSrcweir 182*cdf0e10cSrcweir /** Maps an interface from one environment to another. 183*cdf0e10cSrcweir 184*cdf0e10cSrcweir @param ppOut inout mapped interface 185*cdf0e10cSrcweir @param pInterface source interface 186*cdf0e10cSrcweir @param pTypeDescr type description of interface 187*cdf0e10cSrcweir */ 188*cdf0e10cSrcweir inline void SAL_CALL mapInterface( void ** ppOut, void * pInterface, typelib_InterfaceTypeDescription * pTypeDescr ) const SAL_THROW( () ) 189*cdf0e10cSrcweir { (*_pMapping->mapInterface)( _pMapping, ppOut, pInterface, pTypeDescr ); } 190*cdf0e10cSrcweir /** Maps an interface from one environment to another. 191*cdf0e10cSrcweir 192*cdf0e10cSrcweir @param ppOut inout mapped interface 193*cdf0e10cSrcweir @param pInterface source interface 194*cdf0e10cSrcweir @param pTypeDescr type description of interface 195*cdf0e10cSrcweir */ 196*cdf0e10cSrcweir inline void SAL_CALL mapInterface( void ** ppOut, void * pInterface, typelib_TypeDescription * pTypeDescr ) const SAL_THROW( () ) 197*cdf0e10cSrcweir { (*_pMapping->mapInterface)( _pMapping, ppOut, pInterface, (typelib_InterfaceTypeDescription *)pTypeDescr ); } 198*cdf0e10cSrcweir 199*cdf0e10cSrcweir /** Maps an interface from one environment to another. 200*cdf0e10cSrcweir 201*cdf0e10cSrcweir @param ppOut inout mapped interface 202*cdf0e10cSrcweir @param pInterface source interface 203*cdf0e10cSrcweir @param rType type of interface to be mapped 204*cdf0e10cSrcweir */ 205*cdf0e10cSrcweir inline void SAL_CALL mapInterface( void ** ppOut, void * pInterface, const ::com::sun::star::uno::Type & rType ) const SAL_THROW( () ); 206*cdf0e10cSrcweir }; 207*cdf0e10cSrcweir //__________________________________________________________________________________________________ 208*cdf0e10cSrcweir inline Mapping::Mapping( 209*cdf0e10cSrcweir const ::rtl::OUString & rFrom, const ::rtl::OUString & rTo, const ::rtl::OUString & rAddPurpose ) 210*cdf0e10cSrcweir SAL_THROW( () ) 211*cdf0e10cSrcweir : _pMapping( 0 ) 212*cdf0e10cSrcweir { 213*cdf0e10cSrcweir uno_getMappingByName( &_pMapping, rFrom.pData, rTo.pData, rAddPurpose.pData ); 214*cdf0e10cSrcweir } 215*cdf0e10cSrcweir //__________________________________________________________________________________________________ 216*cdf0e10cSrcweir inline Mapping::Mapping( 217*cdf0e10cSrcweir uno_Environment * pFrom, uno_Environment * pTo, const ::rtl::OUString & rAddPurpose ) 218*cdf0e10cSrcweir SAL_THROW( () ) 219*cdf0e10cSrcweir : _pMapping( 0 ) 220*cdf0e10cSrcweir { 221*cdf0e10cSrcweir uno_getMapping( &_pMapping, pFrom, pTo, rAddPurpose.pData ); 222*cdf0e10cSrcweir } 223*cdf0e10cSrcweir //__________________________________________________________________________________________________ 224*cdf0e10cSrcweir inline Mapping::Mapping( 225*cdf0e10cSrcweir const Environment & rFrom, const Environment & rTo, const ::rtl::OUString & rAddPurpose ) 226*cdf0e10cSrcweir SAL_THROW( () ) 227*cdf0e10cSrcweir : _pMapping(0) 228*cdf0e10cSrcweir { 229*cdf0e10cSrcweir uno_getMapping( &_pMapping, rFrom.get(), rTo.get(), rAddPurpose.pData ); 230*cdf0e10cSrcweir } 231*cdf0e10cSrcweir //__________________________________________________________________________________________________ 232*cdf0e10cSrcweir inline Mapping::Mapping( uno_Mapping * pMapping ) SAL_THROW( () ) 233*cdf0e10cSrcweir : _pMapping( pMapping ) 234*cdf0e10cSrcweir { 235*cdf0e10cSrcweir if (_pMapping) 236*cdf0e10cSrcweir (*_pMapping->acquire)( _pMapping ); 237*cdf0e10cSrcweir } 238*cdf0e10cSrcweir //__________________________________________________________________________________________________ 239*cdf0e10cSrcweir inline Mapping::Mapping( const Mapping & rMapping ) SAL_THROW( () ) 240*cdf0e10cSrcweir : _pMapping( rMapping._pMapping ) 241*cdf0e10cSrcweir { 242*cdf0e10cSrcweir if (_pMapping) 243*cdf0e10cSrcweir (*_pMapping->acquire)( _pMapping ); 244*cdf0e10cSrcweir } 245*cdf0e10cSrcweir //__________________________________________________________________________________________________ 246*cdf0e10cSrcweir inline Mapping::~Mapping() SAL_THROW( () ) 247*cdf0e10cSrcweir { 248*cdf0e10cSrcweir if (_pMapping) 249*cdf0e10cSrcweir (*_pMapping->release)( _pMapping ); 250*cdf0e10cSrcweir } 251*cdf0e10cSrcweir //__________________________________________________________________________________________________ 252*cdf0e10cSrcweir inline void Mapping::clear() SAL_THROW( () ) 253*cdf0e10cSrcweir { 254*cdf0e10cSrcweir if (_pMapping) 255*cdf0e10cSrcweir { 256*cdf0e10cSrcweir (*_pMapping->release)( _pMapping ); 257*cdf0e10cSrcweir _pMapping = 0; 258*cdf0e10cSrcweir } 259*cdf0e10cSrcweir } 260*cdf0e10cSrcweir //__________________________________________________________________________________________________ 261*cdf0e10cSrcweir inline Mapping & Mapping::operator = ( uno_Mapping * pMapping ) SAL_THROW( () ) 262*cdf0e10cSrcweir { 263*cdf0e10cSrcweir if (pMapping) 264*cdf0e10cSrcweir (*pMapping->acquire)( pMapping ); 265*cdf0e10cSrcweir if (_pMapping) 266*cdf0e10cSrcweir (*_pMapping->release)( _pMapping ); 267*cdf0e10cSrcweir _pMapping = pMapping; 268*cdf0e10cSrcweir return *this; 269*cdf0e10cSrcweir } 270*cdf0e10cSrcweir //__________________________________________________________________________________________________ 271*cdf0e10cSrcweir inline void Mapping::mapInterface( 272*cdf0e10cSrcweir void ** ppOut, void * pInterface, const ::com::sun::star::uno::Type & rType ) const 273*cdf0e10cSrcweir SAL_THROW( () ) 274*cdf0e10cSrcweir { 275*cdf0e10cSrcweir typelib_TypeDescription * pTD = 0; 276*cdf0e10cSrcweir TYPELIB_DANGER_GET( &pTD, rType.getTypeLibType() ); 277*cdf0e10cSrcweir if (pTD) 278*cdf0e10cSrcweir { 279*cdf0e10cSrcweir (*_pMapping->mapInterface)( _pMapping, ppOut, pInterface, (typelib_InterfaceTypeDescription *)pTD ); 280*cdf0e10cSrcweir TYPELIB_DANGER_RELEASE( pTD ); 281*cdf0e10cSrcweir } 282*cdf0e10cSrcweir } 283*cdf0e10cSrcweir //__________________________________________________________________________________________________ 284*cdf0e10cSrcweir inline void * Mapping::mapInterface( 285*cdf0e10cSrcweir void * pInterface, typelib_InterfaceTypeDescription * pTypeDescr ) const 286*cdf0e10cSrcweir SAL_THROW( () ) 287*cdf0e10cSrcweir { 288*cdf0e10cSrcweir void * pOut = 0; 289*cdf0e10cSrcweir (*_pMapping->mapInterface)( _pMapping, &pOut, pInterface, pTypeDescr ); 290*cdf0e10cSrcweir return pOut; 291*cdf0e10cSrcweir } 292*cdf0e10cSrcweir //__________________________________________________________________________________________________ 293*cdf0e10cSrcweir inline void * Mapping::mapInterface( 294*cdf0e10cSrcweir void * pInterface, const ::com::sun::star::uno::Type & rType ) const 295*cdf0e10cSrcweir SAL_THROW( () ) 296*cdf0e10cSrcweir { 297*cdf0e10cSrcweir void * pOut = 0; 298*cdf0e10cSrcweir mapInterface( &pOut, pInterface, rType ); 299*cdf0e10cSrcweir return pOut; 300*cdf0e10cSrcweir } 301*cdf0e10cSrcweir 302*cdf0e10cSrcweir /** Deprecated. This function DOES NOT WORK with Purpose Environments 303*cdf0e10cSrcweir (http://wiki.services.openoffice.org/wiki/Uno/Binary/Spec/Purpose Environments) 304*cdf0e10cSrcweir 305*cdf0e10cSrcweir Maps an binary C UNO interface to be used in the currently used compiler environment. 306*cdf0e10cSrcweir 307*cdf0e10cSrcweir @tplparam C interface type 308*cdf0e10cSrcweir @param ppRet inout returned interface pointer 309*cdf0e10cSrcweir @param pUnoI binary C UNO interface 310*cdf0e10cSrcweir @return true if successful, false otherwise 311*cdf0e10cSrcweir 312*cdf0e10cSrcweir @deprecated 313*cdf0e10cSrcweir */ 314*cdf0e10cSrcweir template< class C > 315*cdf0e10cSrcweir inline sal_Bool mapToCpp( Reference< C > * ppRet, uno_Interface * pUnoI ) SAL_THROW( () ) 316*cdf0e10cSrcweir { 317*cdf0e10cSrcweir Mapping aMapping( 318*cdf0e10cSrcweir ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(UNO_LB_UNO) ), 319*cdf0e10cSrcweir ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(CPPU_CURRENT_LANGUAGE_BINDING_NAME) ) ); 320*cdf0e10cSrcweir OSL_ASSERT( aMapping.is() ); 321*cdf0e10cSrcweir aMapping.mapInterface( 322*cdf0e10cSrcweir (void **)ppRet, pUnoI, ::cppu::getTypeFavourUnsigned( ppRet ) ); 323*cdf0e10cSrcweir return (0 != *ppRet); 324*cdf0e10cSrcweir } 325*cdf0e10cSrcweir /** Deprecated. This function DOES NOT WORK with Purpose Environments 326*cdf0e10cSrcweir (http://wiki.services.openoffice.org/wiki/Uno/Binary/Spec/Purpose Environments) 327*cdf0e10cSrcweir 328*cdf0e10cSrcweir Maps an UNO interface of the currently used compiler environment to binary C UNO. 329*cdf0e10cSrcweir 330*cdf0e10cSrcweir @tplparam C interface type 331*cdf0e10cSrcweir @param ppRet inout returned interface pointer 332*cdf0e10cSrcweir @param x interface reference 333*cdf0e10cSrcweir @return true if successful, false otherwise 334*cdf0e10cSrcweir 335*cdf0e10cSrcweir @deprecated 336*cdf0e10cSrcweir */ 337*cdf0e10cSrcweir template< class C > 338*cdf0e10cSrcweir inline sal_Bool mapToUno( uno_Interface ** ppRet, const Reference< C > & x ) SAL_THROW( () ) 339*cdf0e10cSrcweir { 340*cdf0e10cSrcweir Mapping aMapping( 341*cdf0e10cSrcweir ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(CPPU_CURRENT_LANGUAGE_BINDING_NAME) ), 342*cdf0e10cSrcweir ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(UNO_LB_UNO) ) ); 343*cdf0e10cSrcweir OSL_ASSERT( aMapping.is() ); 344*cdf0e10cSrcweir aMapping.mapInterface( 345*cdf0e10cSrcweir (void **)ppRet, x.get(), ::cppu::getTypeFavourUnsigned( &x ) ); 346*cdf0e10cSrcweir return (0 != *ppRet); 347*cdf0e10cSrcweir } 348*cdf0e10cSrcweir 349*cdf0e10cSrcweir } 350*cdf0e10cSrcweir } 351*cdf0e10cSrcweir } 352*cdf0e10cSrcweir } 353*cdf0e10cSrcweir 354*cdf0e10cSrcweir #endif 355