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