diff options
Diffstat (limited to 'bridges/inc/bridges/cpp_uno')
-rw-r--r-- | bridges/inc/bridges/cpp_uno/bridge.hxx | 503 | ||||
-rw-r--r-- | bridges/inc/bridges/cpp_uno/shared/arraypointer.hxx | 55 | ||||
-rw-r--r-- | bridges/inc/bridges/cpp_uno/shared/bridge.hxx | 128 | ||||
-rw-r--r-- | bridges/inc/bridges/cpp_uno/shared/cppinterfaceproxy.hxx | 106 | ||||
-rw-r--r-- | bridges/inc/bridges/cpp_uno/shared/types.hxx | 77 | ||||
-rw-r--r-- | bridges/inc/bridges/cpp_uno/shared/unointerfaceproxy.hxx | 116 | ||||
-rw-r--r-- | bridges/inc/bridges/cpp_uno/shared/vtablefactory.hxx | 214 | ||||
-rw-r--r-- | bridges/inc/bridges/cpp_uno/shared/vtables.hxx | 108 | ||||
-rw-r--r-- | bridges/inc/bridges/cpp_uno/type_misc.hxx | 129 |
9 files changed, 1436 insertions, 0 deletions
diff --git a/bridges/inc/bridges/cpp_uno/bridge.hxx b/bridges/inc/bridges/cpp_uno/bridge.hxx new file mode 100644 index 000000000000..9175adfb7858 --- /dev/null +++ b/bridges/inc/bridges/cpp_uno/bridge.hxx @@ -0,0 +1,503 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef _BRIDGES_CPP_UNO_BRIDGE_HXX_ +#define _BRIDGES_CPP_UNO_BRIDGE_HXX_ + +#ifndef _BRIDGES_CPP_UNO_BRIDGE_H_ +#include <bridges/cpp_uno/bridge.h> +#endif +#include <osl/mutex.hxx> +#include <rtl/process.h> +#include <rtl/ustrbuf.hxx> +#include <com/sun/star/uno/genfunc.hxx> +#include <com/sun/star/uno/XInterface.hpp> + + +namespace CPPU_CURRENT_NAMESPACE +{ + +//-------------------------------------------------------------------------------------------------- +inline void SAL_CALL cppu_cppInterfaceProxy_free( uno_ExtEnvironment * pEnv, void * pProxy ) SAL_THROW( () ) +{ + cppu_cppInterfaceProxy * pThis = + static_cast< cppu_cppInterfaceProxy * >( + reinterpret_cast< ::com::sun::star::uno::XInterface * >( pProxy ) ); + OSL_ASSERT( pEnv == pThis->pBridge->pCppEnv ); + + (*pThis->pBridge->pUnoEnv->revokeInterface)( pThis->pBridge->pUnoEnv, pThis->pUnoI ); + (*pThis->pUnoI->release)( pThis->pUnoI ); + ::typelib_typedescription_release( (typelib_TypeDescription *)pThis->pTypeDescr ); + pThis->pBridge->release(); + +#if OSL_DEBUG_LEVEL > 1 + *(int *)pProxy = 0xdeadbabe; +#endif + delete pThis; +} +//-------------------------------------------------------------------------------------------------- +inline void SAL_CALL cppu_Mapping_uno2cpp( + uno_Mapping * pMapping, void ** ppCppI, + void * pUnoI, typelib_InterfaceTypeDescription * pTypeDescr ) SAL_THROW( () ) +{ + OSL_ASSERT( ppCppI && pTypeDescr ); + if (*ppCppI) + { + reinterpret_cast< ::com::sun::star::uno::XInterface * >( *ppCppI )->release(); + *ppCppI = 0; + } + if (pUnoI) + { + cppu_Bridge * pBridge = static_cast< cppu_Mapping * >( pMapping )->pBridge; + + // get object id of uno interface to be wrapped + rtl_uString * pOId = 0; + (*pBridge->pUnoEnv->getObjectIdentifier)( pBridge->pUnoEnv, &pOId, pUnoI ); + OSL_ASSERT( pOId ); + + // try to get any known interface from target environment + (*pBridge->pCppEnv->getRegisteredInterface)( + pBridge->pCppEnv, ppCppI, pOId, pTypeDescr ); + + if (! *ppCppI) // no existing interface, register new proxy interface + { + // try to publish a new proxy (ref count initially 1) + cppu_cppInterfaceProxy * pProxy = new cppu_cppInterfaceProxy( + pBridge, reinterpret_cast< uno_Interface * >( pUnoI ), pTypeDescr, pOId ); + ::com::sun::star::uno::XInterface * pSurrogate = pProxy; + cppu_cppInterfaceProxy_patchVtable( pSurrogate, pProxy->pTypeDescr ); + + // proxy may be exchanged during registration + (*pBridge->pCppEnv->registerProxyInterface)( + pBridge->pCppEnv, reinterpret_cast< void ** >( &pSurrogate ), + (uno_freeProxyFunc)cppu_cppInterfaceProxy_free, pOId, pTypeDescr ); + + *ppCppI = pSurrogate; + } + ::rtl_uString_release( pOId ); + } +} +//__________________________________________________________________________________________________ +inline void cppu_cppInterfaceProxy::acquireProxy() SAL_THROW( () ) +{ + if (1 == osl_incrementInterlockedCount( &nRef )) + { + // rebirth of proxy zombie + // register at cpp env + void * pThis = static_cast< ::com::sun::star::uno::XInterface * >( this ); + (*pBridge->pCppEnv->registerProxyInterface)( + pBridge->pCppEnv, &pThis, (uno_freeProxyFunc)cppu_cppInterfaceProxy_free, + oid.pData, pTypeDescr ); + OSL_ASSERT( pThis == static_cast< ::com::sun::star::uno::XInterface * >( this ) ); + } +} +//__________________________________________________________________________________________________ +inline void cppu_cppInterfaceProxy::releaseProxy() SAL_THROW( () ) +{ + if (! osl_decrementInterlockedCount( &nRef )) // last release + { + // revoke from cpp env + (*pBridge->pCppEnv->revokeInterface)( + pBridge->pCppEnv, static_cast< ::com::sun::star::uno::XInterface * >( this ) ); + } +} +//__________________________________________________________________________________________________ +inline cppu_cppInterfaceProxy::cppu_cppInterfaceProxy( + cppu_Bridge * pBridge_, uno_Interface * pUnoI_, + typelib_InterfaceTypeDescription * pTypeDescr_, const ::rtl::OUString & rOId_ ) SAL_THROW( () ) + : nRef( 1 ) + , pBridge( pBridge_ ) + , pUnoI( pUnoI_ ) + , pTypeDescr( pTypeDescr_ ) + , oid( rOId_ ) +{ + pBridge->acquire(); + ::typelib_typedescription_acquire( (typelib_TypeDescription *)pTypeDescr ); + if (! ((typelib_TypeDescription *)pTypeDescr)->bComplete) + ::typelib_typedescription_complete( (typelib_TypeDescription **)&pTypeDescr ); + OSL_ENSURE( ((typelib_TypeDescription *)pTypeDescr)->bComplete, "### type is incomplete!" ); + (*pUnoI->acquire)( pUnoI ); + (*pBridge->pUnoEnv->registerInterface)( + pBridge->pUnoEnv, reinterpret_cast< void ** >( &pUnoI ), oid.pData, pTypeDescr ); +} + + +//################################################################################################## +//################################################################################################## +//################################################################################################## + + +//-------------------------------------------------------------------------------------------------- +inline void SAL_CALL cppu_unoInterfaceProxy_free( uno_ExtEnvironment * pEnv, void * pProxy ) SAL_THROW( () ) +{ + cppu_unoInterfaceProxy * pThis = + static_cast< cppu_unoInterfaceProxy * >( + reinterpret_cast< uno_Interface * >( pProxy ) ); + OSL_ASSERT( pEnv == pThis->pBridge->pUnoEnv ); + + (*pThis->pBridge->pCppEnv->revokeInterface)( pThis->pBridge->pCppEnv, pThis->pCppI ); + pThis->pCppI->release(); + ::typelib_typedescription_release( (typelib_TypeDescription *)pThis->pTypeDescr ); + pThis->pBridge->release(); + +#if OSL_DEBUG_LEVEL > 1 + *(int *)pProxy = 0xdeadbabe; +#endif + delete pThis; +} +//-------------------------------------------------------------------------------------------------- +inline void SAL_CALL cppu_unoInterfaceProxy_acquire( uno_Interface * pUnoI ) SAL_THROW( () ) +{ + if (1 == osl_incrementInterlockedCount( & static_cast< cppu_unoInterfaceProxy * >( pUnoI )->nRef )) + { + // rebirth of proxy zombie + // register at uno env +#if OSL_DEBUG_LEVEL > 1 + void * pThis = pUnoI; +#endif + (*static_cast< cppu_unoInterfaceProxy * >( pUnoI )->pBridge->pUnoEnv->registerProxyInterface)( + static_cast< cppu_unoInterfaceProxy * >( pUnoI )->pBridge->pUnoEnv, + reinterpret_cast< void ** >( &pUnoI ), + (uno_freeProxyFunc)cppu_unoInterfaceProxy_free, + static_cast< cppu_unoInterfaceProxy * >( pUnoI )->oid.pData, + static_cast< cppu_unoInterfaceProxy * >( pUnoI )->pTypeDescr ); +#if OSL_DEBUG_LEVEL > 1 + OSL_ASSERT( pThis == pUnoI ); +#endif + } +} +//-------------------------------------------------------------------------------------------------- +inline void SAL_CALL cppu_unoInterfaceProxy_release( uno_Interface * pUnoI ) SAL_THROW( () ) +{ + if (! osl_decrementInterlockedCount( & static_cast< cppu_unoInterfaceProxy * >( pUnoI )->nRef )) + { + // revoke from uno env on last release + (*static_cast< cppu_unoInterfaceProxy * >( pUnoI )->pBridge->pUnoEnv->revokeInterface)( + static_cast< cppu_unoInterfaceProxy * >( pUnoI )->pBridge->pUnoEnv, pUnoI ); + } +} +//-------------------------------------------------------------------------------------------------- +inline void SAL_CALL cppu_Mapping_cpp2uno( + uno_Mapping * pMapping, void ** ppUnoI, + void * pCppI, typelib_InterfaceTypeDescription * pTypeDescr ) SAL_THROW( () ) +{ + OSL_ENSURE( ppUnoI && pTypeDescr, "### null ptr!" ); + if (*ppUnoI) + { + (*reinterpret_cast< uno_Interface * >( *ppUnoI )->release)( + reinterpret_cast< uno_Interface * >( *ppUnoI ) ); + *ppUnoI = 0; + } + if (pCppI) + { + cppu_Bridge * pBridge = static_cast< cppu_Mapping * >( pMapping )->pBridge; + + // get object id of interface to be wrapped + rtl_uString * pOId = 0; + (*pBridge->pCppEnv->getObjectIdentifier)( pBridge->pCppEnv, &pOId, pCppI ); + OSL_ASSERT( pOId ); + + // try to get any known interface from target environment + (*pBridge->pUnoEnv->getRegisteredInterface)( + pBridge->pUnoEnv, ppUnoI, pOId, pTypeDescr ); + + if (! *ppUnoI) // no existing interface, register new proxy interface + { + // try to publish a new proxy (refcount initially 1) + uno_Interface * pSurrogate = new cppu_unoInterfaceProxy( + pBridge, reinterpret_cast< ::com::sun::star::uno::XInterface * >( pCppI ), + pTypeDescr, pOId ); + + // proxy may be exchanged during registration + (*pBridge->pUnoEnv->registerProxyInterface)( + pBridge->pUnoEnv, reinterpret_cast< void ** >( &pSurrogate ), + (uno_freeProxyFunc)cppu_unoInterfaceProxy_free, pOId, pTypeDescr ); + + *ppUnoI = pSurrogate; + } + ::rtl_uString_release( pOId ); + } +} +//__________________________________________________________________________________________________ +inline cppu_unoInterfaceProxy::cppu_unoInterfaceProxy( + cppu_Bridge * pBridge_, ::com::sun::star::uno::XInterface * pCppI_, + typelib_InterfaceTypeDescription * pTypeDescr_, const ::rtl::OUString & rOId_ ) SAL_THROW( () ) + : nRef( 1 ) + , pBridge( pBridge_ ) + , pCppI( pCppI_ ) + , pTypeDescr( pTypeDescr_ ) + , oid( rOId_ ) +{ + pBridge->acquire(); + ::typelib_typedescription_acquire( (typelib_TypeDescription *)pTypeDescr ); + if (! ((typelib_TypeDescription *)pTypeDescr)->bComplete) + ::typelib_typedescription_complete( (typelib_TypeDescription **)&pTypeDescr ); + OSL_ENSURE( ((typelib_TypeDescription *)pTypeDescr)->bComplete, "### type is incomplete!" ); + pCppI->acquire(); + (*pBridge->pCppEnv->registerInterface)( + pBridge->pCppEnv, reinterpret_cast< void ** >( &pCppI ), oid.pData, pTypeDescr ); + + // uno_Interface + uno_Interface::acquire = cppu_unoInterfaceProxy_acquire; + uno_Interface::release = cppu_unoInterfaceProxy_release; + uno_Interface::pDispatcher = (uno_DispatchMethod)cppu_unoInterfaceProxy_dispatch; +} + + +//################################################################################################## +//################################################################################################## +//################################################################################################## + + +//-------------------------------------------------------------------------------------------------- +inline void SAL_CALL cppu_Mapping_acquire( uno_Mapping * pMapping ) SAL_THROW( () ) +{ + static_cast< cppu_Mapping * >( pMapping )->pBridge->acquire(); +} +//-------------------------------------------------------------------------------------------------- +inline void SAL_CALL cppu_Mapping_release( uno_Mapping * pMapping ) SAL_THROW( () ) +{ + static_cast< cppu_Mapping * >( pMapping )->pBridge->release(); +} +//__________________________________________________________________________________________________ +inline cppu_Bridge::cppu_Bridge( + uno_ExtEnvironment * pCppEnv_, uno_ExtEnvironment * pUnoEnv_, + sal_Bool bExportCpp2Uno_ ) SAL_THROW( () ) + : nRef( 1 ) + , pCppEnv( pCppEnv_ ) + , pUnoEnv( pUnoEnv_ ) + , bExportCpp2Uno( bExportCpp2Uno_ ) +{ + g_moduleCount.modCnt.acquire( &g_moduleCount.modCnt ); + + aCpp2Uno.pBridge = this; + aCpp2Uno.acquire = cppu_Mapping_acquire; + aCpp2Uno.release = cppu_Mapping_release; + aCpp2Uno.mapInterface = cppu_Mapping_cpp2uno; + + aUno2Cpp.pBridge = this; + aUno2Cpp.acquire = cppu_Mapping_acquire; + aUno2Cpp.release = cppu_Mapping_release; + aUno2Cpp.mapInterface = cppu_Mapping_uno2cpp; + + (*((uno_Environment *)pCppEnv)->acquire)( (uno_Environment *)pCppEnv ); + (*((uno_Environment *)pUnoEnv)->acquire)( (uno_Environment *)pUnoEnv ); +} +//__________________________________________________________________________________________________ +inline cppu_Bridge::~cppu_Bridge() SAL_THROW( () ) +{ + (*((uno_Environment *)pUnoEnv)->release)( (uno_Environment *)pUnoEnv ); + (*((uno_Environment *)pCppEnv)->release)( (uno_Environment *)pCppEnv ); + g_moduleCount.modCnt.release( &g_moduleCount.modCnt ); +} +//__________________________________________________________________________________________________ +inline void SAL_CALL cppu_Bridge_free( uno_Mapping * pMapping ) SAL_THROW( () ) +{ + delete static_cast< cppu_Mapping * >( pMapping )->pBridge; +} +//__________________________________________________________________________________________________ +inline void cppu_Bridge::acquire() SAL_THROW( () ) +{ + if (1 == osl_incrementInterlockedCount( &nRef )) + { + if (bExportCpp2Uno) + { + uno_Mapping * pMapping = &aCpp2Uno; + ::uno_registerMapping( + &pMapping, cppu_Bridge_free, + (uno_Environment *)pCppEnv, (uno_Environment *)pUnoEnv, 0 ); + } + else + { + uno_Mapping * pMapping = &aUno2Cpp; + ::uno_registerMapping( + &pMapping, cppu_Bridge_free, + (uno_Environment *)pUnoEnv, (uno_Environment *)pCppEnv, 0 ); + } + } +} +//__________________________________________________________________________________________________ +inline void cppu_Bridge::release() SAL_THROW( () ) +{ + if (! osl_decrementInterlockedCount( &nRef )) + { + ::uno_revokeMapping( bExportCpp2Uno ? &aCpp2Uno : &aUno2Cpp ); + } +} + +//################################################################################################## +inline void SAL_CALL cppu_ext_getMapping( + uno_Mapping ** ppMapping, uno_Environment * pFrom, uno_Environment * pTo ) SAL_THROW( () ) +{ + OSL_ASSERT( ppMapping && pFrom && pTo ); + if (ppMapping && pFrom && pTo && pFrom->pExtEnv && pTo->pExtEnv) + { + uno_Mapping * pMapping = 0; + + if (0 == rtl_ustr_ascii_compare( pFrom->pTypeName->buffer, CPPU_CURRENT_LANGUAGE_BINDING_NAME ) && + 0 == rtl_ustr_ascii_compare( pTo->pTypeName->buffer, UNO_LB_UNO )) + { + // ref count initially 1 + pMapping = &(new cppu_Bridge( pFrom->pExtEnv, pTo->pExtEnv, sal_True ))->aCpp2Uno; + ::uno_registerMapping( + &pMapping, cppu_Bridge_free, + (uno_Environment *)pFrom->pExtEnv, + (uno_Environment *)pTo->pExtEnv, 0 ); + } + else if (0 == rtl_ustr_ascii_compare( pTo->pTypeName->buffer, CPPU_CURRENT_LANGUAGE_BINDING_NAME ) && + 0 == rtl_ustr_ascii_compare( pFrom->pTypeName->buffer, UNO_LB_UNO )) + { + // ref count initially 1 + pMapping = &(new cppu_Bridge( pTo->pExtEnv, pFrom->pExtEnv, sal_False ))->aUno2Cpp; + ::uno_registerMapping( + &pMapping, cppu_Bridge_free, + (uno_Environment *)pFrom->pExtEnv, + (uno_Environment *)pTo->pExtEnv, 0 ); + } + + if (*ppMapping) + { + (*(*ppMapping)->release)( *ppMapping ); + } + if (pMapping) + *ppMapping = pMapping; + } +} + + +//################################################################################################## +//################################################################################################## +//################################################################################################## + +#if (defined(__SUNPRO_CC) && (__SUNPRO_CC == 0x500)) +static ::rtl::OUString * s_pStaticOidPart = 0; +#endif + +// environment init stuff +//-------------------------------------------------------------------------------------------------- +inline const ::rtl::OUString & SAL_CALL cppu_cppenv_getStaticOIdPart() SAL_THROW( () ) +{ +#if ! (defined(__SUNPRO_CC) && (__SUNPRO_CC == 0x500)) + static ::rtl::OUString * s_pStaticOidPart = 0; +#endif + if (! s_pStaticOidPart) + { + ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() ); + if (! s_pStaticOidPart) + { + ::rtl::OUStringBuffer aRet( 64 ); + aRet.appendAscii( RTL_CONSTASCII_STRINGPARAM("];") ); + // good guid + sal_uInt8 ar[16]; + ::rtl_getGlobalProcessId( ar ); + for ( sal_Int32 i = 0; i < 16; ++i ) + { + aRet.append( (sal_Int32)ar[i], 16 ); + } +#if (defined(__SUNPRO_CC) && (__SUNPRO_CC == 0x500)) + s_pStaticOidPart = new ::rtl::OUString( aRet.makeStringAndClear() ); +#else + static ::rtl::OUString s_aStaticOidPart( aRet.makeStringAndClear() ); + s_pStaticOidPart = &s_aStaticOidPart; +#endif + } + } + return *s_pStaticOidPart; +} +// functions set at environment init +//-------------------------------------------------------------------------------------------------- +inline void SAL_CALL cppu_cppenv_computeObjectIdentifier( + uno_ExtEnvironment * pEnv, rtl_uString ** ppOId, void * pInterface ) SAL_THROW( () ) +{ + OSL_ENSURE( pEnv && ppOId && pInterface, "### null ptr!" ); + if (pEnv && ppOId && pInterface) + { + if (*ppOId) + { + rtl_uString_release( *ppOId ); + *ppOId = 0; + } + + try + { + ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > xHome( + reinterpret_cast< ::com::sun::star::uno::XInterface * >( pInterface ), + ::com::sun::star::uno::UNO_QUERY ); + OSL_ENSURE( xHome.is(), "### query to XInterface failed!" ); + if (xHome.is()) + { + // interface + ::rtl::OUStringBuffer oid( 64 ); + oid.append( (sal_Int64)xHome.get(), 16 ); + oid.append( (sal_Unicode)';' ); + // ;environment[context] + oid.append( + *reinterpret_cast< ::rtl::OUString const * >( + &((uno_Environment *) pEnv)->pTypeName ) ); + oid.append( (sal_Unicode)'[' ); + oid.append( (sal_Int64)((uno_Environment *)pEnv)->pContext, 16 ); + // ];good guid + oid.append( cppu_cppenv_getStaticOIdPart() ); + ::rtl::OUString aRet( oid.makeStringAndClear() ); + ::rtl_uString_acquire( *ppOId = aRet.pData ); + } + } + catch (::com::sun::star::uno::RuntimeException &) + { + OSL_ENSURE( 0, "### RuntimeException occured udring queryInterface()!" ); + } + } +} +//-------------------------------------------------------------------------------------------------- +inline void SAL_CALL cppu_cppenv_acquireInterface( uno_ExtEnvironment *, void * pCppI ) SAL_THROW( () ) +{ + reinterpret_cast< ::com::sun::star::uno::XInterface * >( pCppI )->acquire(); +} +//-------------------------------------------------------------------------------------------------- +inline void SAL_CALL cppu_cppenv_releaseInterface( uno_ExtEnvironment *, void * pCppI ) SAL_THROW( () ) +{ + reinterpret_cast< ::com::sun::star::uno::XInterface * >( pCppI )->release(); +} +//-------------------------------------------------------------------------------------------------- +inline void SAL_CALL cppu_cppenv_environmentDisposing( uno_Environment * ) SAL_THROW( () ) +{ + g_moduleCount.modCnt.release( &g_moduleCount.modCnt ); +} +//-------------------------------------------------------------------------------------------------- +inline void SAL_CALL cppu_cppenv_initEnvironment( uno_Environment * pCppEnv ) SAL_THROW( () ) +{ + OSL_ENSURE( pCppEnv->pExtEnv, "### expected extended environment!" ); + OSL_ENSURE( ::rtl_ustr_ascii_compare( pCppEnv->pTypeName->buffer, CPPU_CURRENT_LANGUAGE_BINDING_NAME ) == 0, "### wrong environment type!" ); + g_moduleCount.modCnt.acquire( &g_moduleCount.modCnt ); + ((uno_ExtEnvironment *)pCppEnv)->computeObjectIdentifier = cppu_cppenv_computeObjectIdentifier; + ((uno_ExtEnvironment *)pCppEnv)->acquireInterface = cppu_cppenv_acquireInterface; + ((uno_ExtEnvironment *)pCppEnv)->releaseInterface = cppu_cppenv_releaseInterface; + pCppEnv->environmentDisposing = cppu_cppenv_environmentDisposing; +} + +} + +#endif diff --git a/bridges/inc/bridges/cpp_uno/shared/arraypointer.hxx b/bridges/inc/bridges/cpp_uno/shared/arraypointer.hxx new file mode 100644 index 000000000000..07d6c179a9ab --- /dev/null +++ b/bridges/inc/bridges/cpp_uno/shared/arraypointer.hxx @@ -0,0 +1,55 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef INCLUDED_BRIDGES_CPP_UNO_SHARED_ARRAYPOINTER_HXX +#define INCLUDED_BRIDGES_CPP_UNO_SHARED_ARRAYPOINTER_HXX + +#include "sal/config.h" + +namespace bridges { namespace cpp_uno { namespace shared { + +/** + * A simple smart pointer that holds an array until it is being released. + */ +template< typename T > class ArrayPointer { +public: + ArrayPointer(T * p): p_(p) {} + + ~ArrayPointer() { delete[] p_; } + + T * release() { T * t = p_; p_ = 0; return t; } + +private: + ArrayPointer(ArrayPointer &); // not defined + void operator =(ArrayPointer &); // not defined + + T * p_; +}; + +} } } + +#endif diff --git a/bridges/inc/bridges/cpp_uno/shared/bridge.hxx b/bridges/inc/bridges/cpp_uno/shared/bridge.hxx new file mode 100644 index 000000000000..38d722c6dc3c --- /dev/null +++ b/bridges/inc/bridges/cpp_uno/shared/bridge.hxx @@ -0,0 +1,128 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef INCLUDED_BRIDGES_CPP_UNO_SHARED_BRIDGE_HXX +#define INCLUDED_BRIDGES_CPP_UNO_SHARED_BRIDGE_HXX + +#include "osl/interlck.h" +#include "sal/types.h" +#include "typelib/typedescription.h" +#include "uno/environment.h" +#include "uno/mapping.h" + +namespace bridges { namespace cpp_uno { namespace shared { + +// private: +extern "C" typedef void SAL_CALL FreeMapping(uno_Mapping *); +FreeMapping freeMapping; + +// private: +extern "C" +typedef void SAL_CALL AcquireMapping(uno_Mapping *); +AcquireMapping acquireMapping; + +// private: +extern "C" +typedef void SAL_CALL ReleaseMapping(uno_Mapping *); +ReleaseMapping releaseMapping; + +// private: +extern "C" typedef void SAL_CALL Cpp2unoMapping( + uno_Mapping *, void **, void *, typelib_InterfaceTypeDescription *); +Cpp2unoMapping cpp2unoMapping; + +// private: +extern "C" typedef void SAL_CALL Uno2cppMapping( + uno_Mapping *, void **, void *, typelib_InterfaceTypeDescription *); +Uno2cppMapping uno2cppMapping; + +/** + * Holding environments and mappings. + */ +class Bridge { +public: + // Interface for generic/component.cxx: + + static uno_Mapping * createMapping( + uno_ExtEnvironment * pCppEnv, uno_ExtEnvironment * pUnoEnv, + bool bExportCpp2Uno) SAL_THROW(()); + + // Interface for Cpp/UnoInterfaceProxy: + + void acquire() SAL_THROW(()); + void release() SAL_THROW(()); + + // Interface for individual CPP--UNO bridges: + + uno_ExtEnvironment * getCppEnv() { return pCppEnv; } + uno_ExtEnvironment * getUnoEnv() { return pUnoEnv; } + + uno_Mapping * getCpp2Uno() { return &aCpp2Uno; } + uno_Mapping * getUno2Cpp() { return &aUno2Cpp; } + +private: + Bridge(Bridge &); // not implemented + void operator =(Bridge); // not implemented + + Bridge( + uno_ExtEnvironment * pCppEnv_, uno_ExtEnvironment * pUnoEnv_, + bool bExportCpp2Uno_) SAL_THROW(()); + + ~Bridge() SAL_THROW(()); + + struct Mapping: public uno_Mapping { + Bridge * pBridge; + }; + + oslInterlockedCount nRef; + + uno_ExtEnvironment * pCppEnv; + uno_ExtEnvironment * pUnoEnv; + + Mapping aCpp2Uno; + Mapping aUno2Cpp; + + bool bExportCpp2Uno; + + friend void SAL_CALL freeMapping(uno_Mapping * pMapping); + + friend void SAL_CALL acquireMapping(uno_Mapping * pMapping); + + friend void SAL_CALL releaseMapping(uno_Mapping * pMapping); + + friend void SAL_CALL cpp2unoMapping( + uno_Mapping * pMapping, void ** ppUnoI, void * pCppI, + typelib_InterfaceTypeDescription * pTypeDescr); + + friend void SAL_CALL uno2cppMapping( + uno_Mapping * pMapping, void ** ppCppI, void * pUnoI, + typelib_InterfaceTypeDescription * pTypeDescr); +}; + +} } } + +#endif diff --git a/bridges/inc/bridges/cpp_uno/shared/cppinterfaceproxy.hxx b/bridges/inc/bridges/cpp_uno/shared/cppinterfaceproxy.hxx new file mode 100644 index 000000000000..e3cafcc41101 --- /dev/null +++ b/bridges/inc/bridges/cpp_uno/shared/cppinterfaceproxy.hxx @@ -0,0 +1,106 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef INCLUDED_BRIDGES_CPP_UNO_SHARED_CPPINTERFACEPROXY_HXX +#define INCLUDED_BRIDGES_CPP_UNO_SHARED_CPPINTERFACEPROXY_HXX + +#include "osl/interlck.h" +#include "rtl/ustring.hxx" +#include "sal/types.h" +#include "typelib/typedescription.h" +#include "uno/dispatcher.h" +#include "uno/environment.h" +#include "bridges/cpp_uno/shared/vtablefactory.hxx" + +namespace com { namespace sun { namespace star { namespace uno { + class XInterface; +} } } } + +namespace bridges { namespace cpp_uno { namespace shared { + +class Bridge; + +extern "C" typedef void SAL_CALL FreeCppInterfaceProxy( + uno_ExtEnvironment * pEnv, void * pInterface); +FreeCppInterfaceProxy freeCppInterfaceProxy; + +/** + * A cpp proxy wrapping a uno interface. + */ +class CppInterfaceProxy { +public: + // Interface for Bridge: + + static com::sun::star::uno::XInterface * create( + Bridge * pBridge, uno_Interface * pUnoI, + typelib_InterfaceTypeDescription * pTypeDescr, + rtl::OUString const & rOId) SAL_THROW(()); + + // Interface for individual CPP--UNO bridges: + + Bridge * getBridge() { return pBridge; } + uno_Interface * getUnoI() { return pUnoI; } + typelib_InterfaceTypeDescription * getTypeDescr() { return pTypeDescr; } + rtl::OUString getOid() { return oid; } + + // non virtual methods called on incoming vtable calls #1, #2 + void acquireProxy() SAL_THROW(()); + void releaseProxy() SAL_THROW(()); + + static CppInterfaceProxy * castInterfaceToProxy(void * pInterface); + +private: + CppInterfaceProxy(CppInterfaceProxy &); // not implemented + void operator =(CppInterfaceProxy); // not implemented + + CppInterfaceProxy( + Bridge * pBridge_, uno_Interface * pUnoI_, + typelib_InterfaceTypeDescription * pTypeDescr_, + rtl::OUString const & rOId_) SAL_THROW(()); + + ~CppInterfaceProxy(); + + static com::sun::star::uno::XInterface * castProxyToInterface( + CppInterfaceProxy * pProxy); + + oslInterlockedCount nRef; + Bridge * pBridge; + + // mapping information + uno_Interface * pUnoI; // wrapped interface + typelib_InterfaceTypeDescription * pTypeDescr; + rtl::OUString oid; + + VtableFactory::Slot * vtables[1]; + + friend void SAL_CALL freeCppInterfaceProxy( + uno_ExtEnvironment * pEnv, void * pInterface); +}; + +} } } + +#endif diff --git a/bridges/inc/bridges/cpp_uno/shared/types.hxx b/bridges/inc/bridges/cpp_uno/shared/types.hxx new file mode 100644 index 000000000000..fa87637578ae --- /dev/null +++ b/bridges/inc/bridges/cpp_uno/shared/types.hxx @@ -0,0 +1,77 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef INCLUDED_BRIDGES_CPP_UNO_SHARED_TYPES_HXX +#define INCLUDED_BRIDGES_CPP_UNO_SHARED_TYPES_HXX + +#include "typelib/typeclass.h" +#include "typelib/typedescription.h" + +namespace bridges { namespace cpp_uno { namespace shared { + +/** + * Determines whether a type is a "simple" type (VOID, BOOLEAN, BYTE, SHORT, + * UNSIGNED SHORT, LONG, UNSIGNED LONG, HYPER, UNSIGNED HYPER, FLOAT, DOUBLE, + * CHAR, or an enum type). + * + * @param typeClass a type class + * @return true if the given type is "simple" + */ +bool isSimpleType(typelib_TypeClass typeClass); + +/** + * Determines whether a type is a "simple" type (VOID, BOOLEAN, BYTE, SHORT, + * UNSIGNED SHORT, LONG, UNSIGNED LONG, HYPER, UNSIGNED HYPER, FLOAT, DOUBLE, + * CHAR, or an enum type). + * + * @param type a non-null pointer to a type description reference + * @return true if the given type is "simple" + */ +bool isSimpleType(typelib_TypeDescriptionReference const * type); + +/** + * Determines whether a type is a "simple" type (VOID, BOOLEAN, BYTE, SHORT, + * UNSIGNED SHORT, LONG, UNSIGNED LONG, HYPER, UNSIGNED HYPER, FLOAT, DOUBLE, + * CHAR, or an enum type). + * + * @param type a non-null pointer to a type description + * @return true if the given type is "simple" + */ +bool isSimpleType(typelib_TypeDescription const * type); + +/** + * Determines whether a type relates to an interface type (is itself an + * interface type, or might contain entities of interface type). + * + * @param type a non-null pointer to a type description + * @return true if the given type relates to an interface type + */ +bool relatesToInterfaceType(typelib_TypeDescription const * type); + +} } } + +#endif diff --git a/bridges/inc/bridges/cpp_uno/shared/unointerfaceproxy.hxx b/bridges/inc/bridges/cpp_uno/shared/unointerfaceproxy.hxx new file mode 100644 index 000000000000..4836348cdfe9 --- /dev/null +++ b/bridges/inc/bridges/cpp_uno/shared/unointerfaceproxy.hxx @@ -0,0 +1,116 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef INCLUDED_BRIDGES_CPP_UNO_SHARED_UNOINTERFACEPROXY_HXX +#define INCLUDED_BRIDGES_CPP_UNO_SHARED_UNOINTERFACEPROXY_HXX + +#include "osl/interlck.h" +#include "rtl/ustring.hxx" +#include "sal/types.h" +#include "typelib/typedescription.h" +#include "uno/dispatcher.h" +#include "uno/environment.h" + +namespace com { namespace sun { namespace star { namespace uno { + class XInterface; +} } } } + +namespace bridges { namespace cpp_uno { namespace shared { + +class Bridge; + +extern "C" typedef void SAL_CALL FreeUnoInterfaceProxy( + uno_ExtEnvironment * pEnv, void * pProxy); +FreeUnoInterfaceProxy freeUnoInterfaceProxy; + +// private: +extern "C" typedef void SAL_CALL UnoInterfaceProxyDispatch( + uno_Interface * pUnoI, typelib_TypeDescription const * pMemberDescr, + void * pReturn, void * pArgs[], uno_Any ** ppException); +UnoInterfaceProxyDispatch unoInterfaceProxyDispatch; + // this function is not defined in the generic part, but instead has to be + // defined individually for each CPP--UNO bridge + +// private: +extern "C" typedef void SAL_CALL AcquireProxy(uno_Interface *); +AcquireProxy acquireProxy; + +// private: +extern "C" typedef void SAL_CALL ReleaseProxy(uno_Interface *); +ReleaseProxy releaseProxy; + +/** + * A uno proxy wrapping a cpp interface. + */ +class UnoInterfaceProxy: public uno_Interface { +public: + // Interface for Bridge: + + static UnoInterfaceProxy * create( + Bridge * pBridge, com::sun::star::uno::XInterface * pCppI, + typelib_InterfaceTypeDescription * pTypeDescr, + rtl::OUString const & rOId) SAL_THROW(()); + + // Interface for individual CPP--UNO bridges: + + Bridge * getBridge() { return pBridge; } + com::sun::star::uno::XInterface * getCppI() { return pCppI; } + +private: + UnoInterfaceProxy(UnoInterfaceProxy &); // not implemented + void operator =(UnoInterfaceProxy); // not implemented + + UnoInterfaceProxy( + Bridge * pBridge_, com::sun::star::uno::XInterface * pCppI_, + typelib_InterfaceTypeDescription * pTypeDescr_, + rtl::OUString const & rOId_) SAL_THROW(()); + + ~UnoInterfaceProxy(); + + oslInterlockedCount nRef; + Bridge * pBridge; + + // mapping information + com::sun::star::uno::XInterface * pCppI; // wrapped interface + typelib_InterfaceTypeDescription * pTypeDescr; + rtl::OUString oid; + + friend void SAL_CALL freeUnoInterfaceProxy( + uno_ExtEnvironment * pEnv, void * pProxy); + + friend void SAL_CALL unoInterfaceProxyDispatch( + uno_Interface * pUnoI, typelib_TypeDescription const * pMemberDescr, + void * pReturn, void * pArgs[], uno_Any ** ppException); + + friend void SAL_CALL acquireProxy(uno_Interface * pUnoI); + + friend void SAL_CALL releaseProxy(uno_Interface * pUnoI); +}; + +} } } + +#endif diff --git a/bridges/inc/bridges/cpp_uno/shared/vtablefactory.hxx b/bridges/inc/bridges/cpp_uno/shared/vtablefactory.hxx new file mode 100644 index 000000000000..434e0c6a0a28 --- /dev/null +++ b/bridges/inc/bridges/cpp_uno/shared/vtablefactory.hxx @@ -0,0 +1,214 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef INCLUDED_BRIDGES_CPP_UNO_SHARED_VTABLEFACTORY_HXX +#define INCLUDED_BRIDGES_CPP_UNO_SHARED_VTABLEFACTORY_HXX + +#include "osl/mutex.hxx" +#include "rtl/alloc.h" +#include "rtl/ustring.hxx" +#include "sal/types.h" +#include "typelib/typedescription.hxx" + +#include <hash_map> + +/*See: http://people.redhat.com/drepper/selinux-mem.html*/ +#ifdef LINUX +#define USE_DOUBLE_MMAP +#endif + +namespace bridges { namespace cpp_uno { namespace shared { + +/** Hand out vtable structures for interface type descriptions. + */ +class VtableFactory { +public: + // This structure is not defined in the generic part, but instead has to be + // defined individually for each CPP--UNO bridge: + /** A vtable slot. + */ + struct Slot; + + /** A raw vtable block. + */ + struct Block { + /** The start of the raw vtable block. + + It points to the start of the allocated memory block, whereas the + vtable pointer typically points some bytes into the block (e.g., + skipping an RTTI pointer, see mapBlockToVtable). Also, the block + contains any generated code snippets, after the vtable itself. + */ + void * start; + +#ifdef USE_DOUBLE_MMAP + /** When seperately mmapping the block for writing and executing + exec points to the same memory as start, except start is used + exclusively for writing and exec for executing + */ + void * exec; + + /** File handle for the underlying anonymous file + */ + int fd; +#endif + + /** The size of the raw vtable block, in bytes. + */ + sal_Size size; + }; + + /** The vtable structure corresponding to an interface type. + */ + struct Vtables { + /** The number of blocks/vtables. + */ + sal_Int32 count; + + /** An array of blocks, representing the multiple vtables of a + (multiple-inheritance) type. + + <p>A block is a raw vtable. It points to the start of the allocated + memory block, whereas the vtable pointer typically points some bytes + into the block (e.g., skipping an RTTI pointer, see + mapBlockToVtable). Also, the block contains any generated code + snippets, after the vtable itself.</p> + */ + Block * blocks; + }; + + VtableFactory(); + + ~VtableFactory(); + + /** Given an interface type description, return its corresponding vtable + structure. + */ + Vtables getVtables(typelib_InterfaceTypeDescription * type); + + // This function is not defined in the generic part, but instead has to be + // defined individually for each CPP--UNO bridge: + /** Given a pointer to a block, turn it into a vtable pointer. + */ + static Slot * mapBlockToVtable(void * block); + +private: + class GuardedBlocks; + friend class GuardedBlocks; + + class BaseOffset; + + VtableFactory(VtableFactory &); // not implemented + void operator =(VtableFactory); // not implemented + + bool createBlock(Block &block, sal_Int32 slotCount) const; + + void freeBlock(Block const & block) const; + + void createVtables( + GuardedBlocks & blocks, BaseOffset const & baseOffset, + typelib_InterfaceTypeDescription * type, bool includePrimary) const; + + // This function is not defined in the generic part, but instead has to be + // defined individually for each CPP--UNO bridge: + /** Calculate the size of a raw vtable block. + + @param slotCount the number of virtual function slots the returned + vtable block shall support (if there are any platform-specific slots, + like an RTTI pointer, or a pointer to a destructor, they are not covered + by slotCount) + @return the size of the raw vtable block, in bytes + */ + static sal_Size getBlockSize(sal_Int32 slotCount); + + // This function is not defined in the generic part, but instead has to be + // defined individually for each CPP--UNO bridge: + /** Initialize a raw vtable block. + + @param block the start address of the raw vtable block + @param slotCount the number of slots + @return a pointer past the last vtable slot + */ + static Slot * initializeBlock(void * block, sal_Int32 slotCount); + + // This function is not defined in the generic part, but instead has to be + // defined individually for each CPP--UNO bridge: + /** Fill the vtable slots corresponding to all local (i.e., not inherited) + functions of a given interface type (and generate any necessary code + snippets for them). + + @param slots on input, points past the vtable slot to be filled with + the last virtual function local to the given type; on output, points to + the vtable slot filled with the first virtual function local to the + given type + @param code points to the start of the area where code snippets can be + generated + @param writetoexecdiff when the same code area is mmaped twice, once for + writing for code-generation, and once for code-execution, then this + records the offset from a writable address to its executable address + @param type the interface type description for which to generate vtable + slots + @param functionOffset the function offset of the first vtable slot + (typically coded into the code snippet for that vtable slot) + @param functionCount the number of vtable slots to fill (the number of + local functions of the given type, passed in so that it need not be + recomputed) + @param vtableOffset the offset of this vtable (needed to adjust the + this pointer, typically coded into the code snippets for all the filled + vtable slots) + @return a pointer to the remaining code snippet area + */ + static unsigned char * addLocalFunctions( + Slot ** slots, unsigned char * code, +#ifdef USE_DOUBLE_MMAP + sal_PtrDiff writetoexecdiff, +#endif + typelib_InterfaceTypeDescription const * type, sal_Int32 functionOffset, + sal_Int32 functionCount, sal_Int32 vtableOffset); + + // This function is not defined in the generic part, but instead has to be + // defined individually for each CPP--UNO bridge: + /** Flush all the generated code snippets of a vtable, on platforms that + require it. + + @param begin points to the start of the code snippet area + @param end points behind the end of the code snippet area + */ + static void flushCode( + unsigned char const * begin, unsigned char const * end); + + typedef std::hash_map< rtl::OUString, Vtables, rtl::OUStringHash > Map; + + osl::Mutex m_mutex; + Map m_map; + + rtl_arena_type * m_arena; +}; + +} } } + +#endif diff --git a/bridges/inc/bridges/cpp_uno/shared/vtables.hxx b/bridges/inc/bridges/cpp_uno/shared/vtables.hxx new file mode 100644 index 000000000000..37cc9bf8eca2 --- /dev/null +++ b/bridges/inc/bridges/cpp_uno/shared/vtables.hxx @@ -0,0 +1,108 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifndef INCLUDED_BRIDGES_CPP_UNO_SHARED_VTABLES_HXX +#define INCLUDED_BRIDGES_CPP_UNO_SHARED_VTABLES_HXX + +#include "sal/types.h" +#include "typelib/typedescription.h" + +namespace bridges { namespace cpp_uno { namespace shared { + +/** + * Calculate the number of local functions of an interface type. + * + * <p><em>Local</em> functions are those not inherited from any base types. The + * number of <em>functions</em> is potentially larger than the number of + * <em>members</em>, as each read–write attribute member counts as two + * functions.</p> + * + * @param type a non-null pointer to an interface type description, for which + * <code>typelib_typedescription_complete</code> must already have been + * executed + * @return the number of local functions of the given interface type + */ +sal_Int32 getLocalFunctions(typelib_InterfaceTypeDescription const * type); + +/** + * Calculate the number of primary functions of an interface type. + * + * <p>The number of primary functions of an interface is the number of local + * functions of that interface (see <code>getLocalFunctions</code>), plus the + * number of primary functions of that interface's first base type (if it has at + * least one base type).</p> + * + * @param type a pointer to an interface type description; may be null + * @return the number of primary functions of the given interface type, or zero + * if the given interface type is null + */ +sal_Int32 getPrimaryFunctions(typelib_InterfaceTypeDescription * type); + +/** + * Represents a vtable slot of a C++ class. + */ +struct VtableSlot { + /** + * The offset of the vtable. + * + * <p>Multiple-inheritance C++ classes have more than one vtable. The + * offset is logical (<em>not</em> a byte offset), and must be + * non-negative.</p> + */ + sal_Int32 offset; + + /** + * The index within the vtable. + * + * <p>The index is logical (<em>not</em> a byte offset), and must be + * non-negative.</p> + */ + sal_Int32 index; +}; + +/** + * Calculates the vtable slot associated with an interface attribute member. + * + * @param ifcMember a non-null pointer to an interface attribute member + * description + * @return the vtable slot associated with the given interface member + */ +VtableSlot getVtableSlot( + typelib_InterfaceAttributeTypeDescription const * ifcMember); + +/** + * Calculates the vtable slot associated with an interface method member. + * + * @param ifcMember a non-null pointer to an interface method member description + * @return the vtable slot associated with the given interface member + */ +VtableSlot getVtableSlot( + typelib_InterfaceMethodTypeDescription const * ifcMember); + +} } } + +#endif diff --git a/bridges/inc/bridges/cpp_uno/type_misc.hxx b/bridges/inc/bridges/cpp_uno/type_misc.hxx new file mode 100644 index 000000000000..775373b2b47e --- /dev/null +++ b/bridges/inc/bridges/cpp_uno/type_misc.hxx @@ -0,0 +1,129 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ +#ifndef _BRIDGES_CPP_UNO_TYPE_MISC_HXX_ +#define _BRIDGES_CPP_UNO_TYPE_MISC_HXX_ + +#include <sal/types.h> +#include <typelib/typedescription.h> + + +/** Determines whether given type might relate or relates to an interface, + i.e. values of this type are interface or may contain interface(s).<br> + @param pTypeDescr type description of type + @return true if type might relate to an interface, false otherwise +*/ +inline bool cppu_relatesToInterface( typelib_TypeDescription * pTypeDescr ) SAL_THROW( () ) +{ + switch (pTypeDescr->eTypeClass) + { +// case typelib_TypeClass_TYPEDEF: + case typelib_TypeClass_SEQUENCE: + { + switch (((typelib_IndirectTypeDescription *)pTypeDescr)->pType->eTypeClass) + { + case typelib_TypeClass_INTERFACE: + case typelib_TypeClass_UNION: // might relate to interface + case typelib_TypeClass_ANY: // might relate to interface + return true; + case typelib_TypeClass_SEQUENCE: + case typelib_TypeClass_STRUCT: + case typelib_TypeClass_EXCEPTION: + { + typelib_TypeDescription * pTD = 0; + TYPELIB_DANGER_GET( &pTD, ((typelib_IndirectTypeDescription *)pTypeDescr)->pType ); + bool bRel = cppu_relatesToInterface( pTD ); + TYPELIB_DANGER_RELEASE( pTD ); + return bRel; + } + default: + return false; + } + } + case typelib_TypeClass_STRUCT: + case typelib_TypeClass_EXCEPTION: + { + // ...optimized... to avoid getDescription() calls! + typelib_CompoundTypeDescription * pComp = (typelib_CompoundTypeDescription *)pTypeDescr; + typelib_TypeDescriptionReference ** pTypes = pComp->ppTypeRefs; + for ( sal_Int32 nPos = pComp->nMembers; nPos--; ) + { + switch (pTypes[nPos]->eTypeClass) + { + case typelib_TypeClass_INTERFACE: + case typelib_TypeClass_UNION: // might relate to interface + case typelib_TypeClass_ANY: // might relate to interface + return true; +// case typelib_TypeClass_TYPEDEF: + case typelib_TypeClass_SEQUENCE: + case typelib_TypeClass_STRUCT: + case typelib_TypeClass_EXCEPTION: + { + typelib_TypeDescription * pTD = 0; + TYPELIB_DANGER_GET( &pTD, pTypes[nPos] ); + bool bRel = cppu_relatesToInterface( pTD ); + TYPELIB_DANGER_RELEASE( pTD ); + if (bRel) + return true; + } + default: + break; + } + } + if (pComp->pBaseTypeDescription) + return cppu_relatesToInterface( (typelib_TypeDescription *)pComp->pBaseTypeDescription ); + return false; + } + case typelib_TypeClass_UNION: // might relate to interface + case typelib_TypeClass_ANY: // might relate to interface + case typelib_TypeClass_INTERFACE: + return true; + default: + return false; + } +} + +/** Determines whether given type is a cpp simple type, e.g. int, enum.<br> + @param eTypeClass type class of type + @return true if type is a cpp simple type, false otherwise +*/ +inline bool cppu_isSimpleType( typelib_TypeClass eTypeClass ) SAL_THROW( () ) +{ + return (eTypeClass <= typelib_TypeClass_ENUM && + eTypeClass != typelib_TypeClass_STRING && + eTypeClass != typelib_TypeClass_ANY && + eTypeClass != typelib_TypeClass_TYPE); +} +/** Determines whether given type is a cpp simple type, e.g. int, enum.<br> + @param pTypeDescr type description of type + @return true if type is a cpp simple type, false otherwise +*/ +inline bool cppu_isSimpleType( typelib_TypeDescription * pTypeDescr ) SAL_THROW( () ) +{ + return cppu_isSimpleType( pTypeDescr->eTypeClass ); +} + +#endif |