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