diff options
Diffstat (limited to 'bridges/inc/bridges')
19 files changed, 2427 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..3c27ab056904 --- /dev/null +++ b/bridges/inc/bridges/cpp_uno/bridge.hxx @@ -0,0 +1,504 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * 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_ + +#include <bridges/cpp_uno/bridge.h> +#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 occurred 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 + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ 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..542be6e0f3d6 --- /dev/null +++ b/bridges/inc/bridges/cpp_uno/shared/arraypointer.hxx @@ -0,0 +1,58 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * 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 + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ 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..4ee69e37b416 --- /dev/null +++ b/bridges/inc/bridges/cpp_uno/shared/bridge.hxx @@ -0,0 +1,131 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * 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 + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ 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..31e19cc94d00 --- /dev/null +++ b/bridges/inc/bridges/cpp_uno/shared/cppinterfaceproxy.hxx @@ -0,0 +1,109 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * 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 + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ 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..0cc87864af0e --- /dev/null +++ b/bridges/inc/bridges/cpp_uno/shared/types.hxx @@ -0,0 +1,80 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * 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 + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ 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..87c96ec36689 --- /dev/null +++ b/bridges/inc/bridges/cpp_uno/shared/unointerfaceproxy.hxx @@ -0,0 +1,119 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * 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 + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ 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..c21fb7672bc3 --- /dev/null +++ b/bridges/inc/bridges/cpp_uno/shared/vtablefactory.hxx @@ -0,0 +1,218 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * 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 <boost/unordered_map.hpp> + +/*See: http://people.redhat.com/drepper/selinux-mem.html*/ +#if defined(LINUX) || defined(OPENBSD) || defined(FREEBSD) \ + || defined(NETBSD) || defined(DRAGONFLY) +#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 boost::unordered_map< rtl::OUString, Vtables, rtl::OUStringHash > Map; + + osl::Mutex m_mutex; + Map m_map; + + rtl_arena_type * m_arena; +}; + +} } } + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ 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..2ea5c7c83121 --- /dev/null +++ b/bridges/inc/bridges/cpp_uno/shared/vtables.hxx @@ -0,0 +1,111 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * 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 + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ 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..5fbd0da45cac --- /dev/null +++ b/bridges/inc/bridges/cpp_uno/type_misc.hxx @@ -0,0 +1,132 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * 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 + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/bridges/inc/bridges/remote/bridgeimpl.hxx b/bridges/inc/bridges/remote/bridgeimpl.hxx new file mode 100644 index 000000000000..bb166d50a153 --- /dev/null +++ b/bridges/inc/bridges/remote/bridgeimpl.hxx @@ -0,0 +1,97 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * 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_REMOTE_BRIDGEIMPL_HXX_ +#define _BRIDGES_REMOTE_BRIDGEIMPL_HXX_ +#include <osl/interlck.h> + +#include <uno/environment.h> + +#include <bridges/remote/context.h> +#include <bridges/remote/remote.h> + + +struct remote_BridgeImpl +{ + void (SAL_CALL * m_allThreadsAreGone ) ( uno_Environment * ); + requestClientSideDispatcher m_sendRequest; + oslInterlockedCount m_nRemoteThreads; + sal_Bool m_bDisposed; + sal_Bool m_bReleaseStubsCalled; +}; + +namespace bridges_remote { + + enum RemoteThreadCounter_HoldEnvWeak + { + RTC_HOLDENVWEAK = 0x1 + }; + + class RemoteThreadCounter + { + public: + // performance optimization. In some cases, it is not necessary to acquire the + // environment. + RemoteThreadCounter( uno_Environment *pEnvRemote, RemoteThreadCounter_HoldEnvWeak ) + : m_bReleaseEnvironment( sal_False ) + , m_pEnvRemote( pEnvRemote ) + { + remote_Context *pContext = ((remote_Context *) m_pEnvRemote->pContext ); + osl_incrementInterlockedCount( &( pContext->m_pBridgeImpl->m_nRemoteThreads ) ); + } + + RemoteThreadCounter( uno_Environment *pEnvRemote ) + : m_bReleaseEnvironment( sal_True ) + , m_pEnvRemote( pEnvRemote ) + { + m_pEnvRemote->acquire( m_pEnvRemote ); + + remote_Context *pContext = ((remote_Context *) m_pEnvRemote->pContext ); + osl_incrementInterlockedCount( &( pContext->m_pBridgeImpl->m_nRemoteThreads ) ); + } + + ~RemoteThreadCounter( ) + { + remote_Context *pContext = ((remote_Context *) m_pEnvRemote->pContext ); + if( 0 == osl_decrementInterlockedCount( &( pContext->m_pBridgeImpl->m_nRemoteThreads)) && + pContext->m_pBridgeImpl->m_bDisposed && + ! pContext->m_pBridgeImpl->m_bReleaseStubsCalled ) + { + pContext->m_pBridgeImpl->m_allThreadsAreGone( m_pEnvRemote ); + } + if( m_bReleaseEnvironment ) + m_pEnvRemote->release( m_pEnvRemote ); + } + + sal_Bool m_bReleaseEnvironment; + uno_Environment *m_pEnvRemote; + }; +} + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/bridges/inc/bridges/remote/connection.h b/bridges/inc/bridges/remote/connection.h new file mode 100644 index 000000000000..1e173944f242 --- /dev/null +++ b/bridges/inc/bridges/remote/connection.h @@ -0,0 +1,70 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * 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_REMOTE_CONNECTION_H_ +#define _BRIDGES_REMOTE_CONNECTION_H_ +#include <sal/types.h> + +/** Specfies a C-interface for a bidirectional bytestream, + which is used by a UNO remote environment. + */ +struct remote_Connection +{ + void ( SAL_CALL * acquire ) ( remote_Connection *); + + void ( SAL_CALL * release ) ( remote_Connection *); + + /** + reads nSize bytes from the connection. This method blocks, until + all bytes are available or an error occurs. + @return Number of bytes read. + If the return value is less than nSize, an unrecoverable + i/o error has occurred or the connection was closed. + + */ + sal_Int32 (SAL_CALL * read)(remote_Connection *, sal_Int8 *pDest, sal_Int32 nSize ); + + /** + @return Number of bytes written. + if the return value is less than nSize an unrecoverable + i/o error has occurred or the connection was closed. + */ + sal_Int32 (SAL_CALL * write)(remote_Connection *, const sal_Int8 *pSource, sal_Int32 nSize ); + + void ( SAL_CALL * flush ) ( remote_Connection * ); + + /** closes the connection. + Any read or write operation after this call shall not be served + anymore. Any ongoing read or write operation must return immeadiatly after this call. + The implementation should cope with multiple calls to this method. + */ + void (SAL_CALL * close) ( remote_Connection * ); +}; + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/bridges/inc/bridges/remote/context.h b/bridges/inc/bridges/remote/context.h new file mode 100644 index 000000000000..8ff83adfb128 --- /dev/null +++ b/bridges/inc/bridges/remote/context.h @@ -0,0 +1,262 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * 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_REMOTE_CONTEXT_H_ +#define _BRIDGES_REMOTE_CONTEXT_H_ +#include <osl/interlck.h> +#include <osl/conditn.h> + +#include <typelib/typedescription.h> + +#include <uno/environment.h> +#include <uno/any2.h> + + +/** Interface for refcounted contexts of uno-environments. + + Not all uno_Contexts need to be refcounted, in case they are, + they should be 'derived' from this struct. + This is used as a base class for the remote_Context. + @see uno_Environment + @see uno_getEnvironment() + @see remote_Context + */ +struct uno_Context +{ + /** increase the refcount of the context + */ + void (SAL_CALL * acquire)( uno_Context *pContext ); + + /** decrements the recount of the context. In case the recount drops to zero, + the context gets destroye. + */ + void (SAL_CALL * release)( uno_Context *pContext); + + /** Allows to query for a different interface of the uno_Context. + The result of the void pointer is unspecified and depends on the concrete context. + */ + void * (SAL_CALL *query ) ( uno_Context *pContext , rtl_uString *pId); +}; + +struct remote_Connection; +struct remote_Context; +struct remote_Interface; + + + +/** performs a query-interface for a certain interface via the remote connection ! + + @param pEnvRemote The environment, that shall perform the call. + @param ppRemoteI in/out parameter contains the interface returned by queryInterface + @param pOid the oid of the 'ghost' object on which the call must be done. + ***/ +typedef void ( SAL_CALL * remote_getInstanceFunc ) ( + uno_Environment *pEnvRemote, + remote_Interface **ppRemoteI, + rtl_uString *pOid, + typelib_TypeDescriptionReference *pInterfaceTypeRef, + uno_Any **ppException ); + + +/** refcounted C-interface, which provides object by name. + */ +struct remote_InstanceProvider +{ + void (SAL_CALL * acquire ) ( remote_InstanceProvider * pProvider ); + void (SAL_CALL * release ) ( remote_InstanceProvider * pProvider ); + void (SAL_CALL * getInstance ) ( remote_InstanceProvider * pProvider , + uno_Environment *pEnvRemote, + remote_Interface **ppRemoteI, + rtl_uString *pInstanceName, + typelib_InterfaceTypeDescription *pType, + uno_Any **ppException ); +}; + +/** refcounted C-interface, which allows to register a listener to an + remote bridge to be informed when the bridge gets disposed. + + @see remote_Context + */ +struct remote_DisposingListener +{ + void (SAL_CALL * acquire ) ( remote_DisposingListener * pProvider ); + void (SAL_CALL * release ) ( remote_DisposingListener * pProvider ); + void (SAL_CALL * disposing ) ( remote_DisposingListener * pProvider, + rtl_uString *pBridgeName ); +}; + + +/** + Try to get an existing context characterized by the pIdString. Each ID-String must + uniquely charcterize a certain connection. The context can't be retrieved via this + function anymore, after it got disposed. + + @return 0 when such a context does not exist, otherwise + a pointer to an acquired remote_Context. + **/ +extern "C" remote_Context * SAL_CALL +remote_getContext( rtl_uString *pIdString ); + +/** + Create an acquired remote context. The Context is weakly held by the context administration + and can be accessed later through remote_getContext() (using the same id-string). + + @param pIdString A string, that uniquely describes the connection. For e.g. a socket connection, + host and port of the local and remote host should be in the string. + + @param pDescription + Description of the connection, that may brought up to the user. + + @param pProtocol + The protocol, that the environment uses for + communicating with the remote process. + The format of the protocol string is : "protocolname,para1=para1value,..." + @return 0, when a context with this name already exists. + + @see remote_getContext() + @see remote_Context + */ +extern "C" remote_Context * SAL_CALL +remote_createContext( remote_Connection *pConnection, + rtl_uString *pIdStr, + rtl_uString *pDescription, + rtl_uString *pProtocol, + remote_InstanceProvider *); + +const sal_Int32 REMOTE_CONTEXT_CREATE = 1; +const sal_Int32 REMOTE_CONTEXT_DESTROY = 2; + +typedef void ( SAL_CALL * remote_contextListenerFunc ) ( + void *pThis, + sal_Int32 nRemoteContextMode, + rtl_uString *sName, + rtl_uString *sDescription + ); + +/** Registers a listener at the context administration, which allows to keep + track of existing remote connections. + @param pObject object which is handed to the listener function, when called. + */ +extern "C" void SAL_CALL +remote_addContextListener( remote_contextListenerFunc listener, void *pObject ); + + +/** Removes a listener from the context administration. + */ +extern "C" void SAL_CALL +remote_removeContextListener( remote_contextListenerFunc listener , void *pObject ); + +/** Allows to retrieve all existing context strings. + + @param pnStringCount out parameter. Contains the number of rtl_uStrings in the array + @param memAlloc a memory allocation function for the array of pointers to rtl_uStrings + + @return array of rtl strings. The caller must call release on all rtl_uString s and must free + the pointer array. + */ +extern "C" rtl_uString ** SAL_CALL +remote_getContextList( + sal_Int32 *pnStringCount, + void * ( SAL_CALL * memAlloc ) ( sal_Size nBytesToAlloc ) ); + + +struct remote_BridgeImpl; + +/** The context structure for a remote bridge. + + @see uno_getEnvironment() + */ +struct remote_Context +{ + struct uno_Context aBase; + + /** + These methods are implemented by context administration + */ + void ( SAL_CALL * addDisposingListener ) ( remote_Context *, + remote_DisposingListener * ); + void ( SAL_CALL * removeDisposingListener ) ( remote_Context *, + remote_DisposingListener * ); + /** + will be called by the environment when it gets disposed + */ + void ( SAL_CALL * dispose ) ( remote_Context * ); + + /** The method is set by the remote-environment during environment initialization. + @see remote_getInstanceFunc + */ + remote_getInstanceFunc getRemoteInstance; + + /** + The protocol, that the environment uses for communicating with the remote process. + The format of the protocol string is : "protocolname,para1=para1value,..." + The parameters are protocol dependend + */ + rtl_uString *m_pProtocol; + + /** + It may be the same as m_pName. + Livetime is handled by the context administration. + */ + rtl_uString *m_pDescription; + + /** + The name of this context at context administration. + A string, that uniquely describes this environment. + Livetime is handled by the context administration. + */ + rtl_uString *m_pName; + + /** The instance-provider, which is used to look up unknown object identifiers. + Is usually called on server side, when the first client request comes in. + Maybe 0. Livetime is handled by the context administration. + */ + remote_InstanceProvider *m_pInstanceProvider; + + /** + The connection of this context. + Livetime is handled by the context administration. + */ + remote_Connection *m_pConnection; + + /** + Here arbitrary data may be stored. It may be used by a connection + service to store environment specific data. The bridge does not + use it. + */ + void *m_pAdditionalInformation; + + /** + here the bridge stores its private per environment data. + */ + struct remote_BridgeImpl *m_pBridgeImpl; +}; + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/bridges/inc/bridges/remote/counter.hxx b/bridges/inc/bridges/remote/counter.hxx new file mode 100644 index 000000000000..8bcb547008af --- /dev/null +++ b/bridges/inc/bridges/remote/counter.hxx @@ -0,0 +1,60 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * 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_REMOTE_COUNTER_H_ +#define _BRIDGES_REMOTE_COUNTER_H_ +#include <stdio.h> +#if OSL_DEBUG_LEVEL > 1 +struct MyCounter +{ + MyCounter( sal_Char const *pName ) : + m_nCounter( 0 ), + m_pName ( pName ) + { + } + ~MyCounter() + { + if( m_nCounter ) { + printf( + "%s : %ld left\n", m_pName, + sal::static_int_cast< long >(m_nCounter) ); + } + } + void acquire() + { m_nCounter ++; } + void release() + { m_nCounter --; } + + + sal_Int32 m_nCounter; + sal_Char const *m_pName; +}; +#endif + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/bridges/inc/bridges/remote/helper.hxx b/bridges/inc/bridges/remote/helper.hxx new file mode 100644 index 000000000000..56de06b7d8c8 --- /dev/null +++ b/bridges/inc/bridges/remote/helper.hxx @@ -0,0 +1,71 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * 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. + * + ************************************************************************/ +#include <bridges/remote/bridgeimpl.hxx> + +typedef void ( SAL_CALL * ReleaseRemoteCallbackFunc ) ( + remote_Interface *ppRemoteI, + rtl_uString *pOid, + typelib_TypeDescriptionReference *pTypeRef, + uno_Environment *pEnvRemote + ); + +typedef void ( SAL_CALL * remote_createStubFunc ) ( + remote_Interface **ppRemoteI, + rtl_uString *pOid , + typelib_TypeDescriptionReference *pTypeRef, + uno_Environment *pEnvRemote, + ReleaseRemoteCallbackFunc callback + ); +namespace bridges_remote +{ + + /** @param callback If the bridge implementation wants to handle the remote release call, + it can do it giving this callback. If callback == 0, the releaseRemote + method of the stub is called. + */ + void SAL_CALL remote_createStub ( + remote_Interface **ppRemoteI, + rtl_uString *pOid , + typelib_TypeDescriptionReference *pType, + uno_Environment *pEnvRemote, + ReleaseRemoteCallbackFunc callback ); + + void SAL_CALL remote_retrieveOidFromProxy( + remote_Interface *pRemtoeI, + rtl_uString **ppOid ); + + void SAL_CALL remote_sendQueryInterface( + uno_Environment *pEnvRemote, + remote_Interface **ppRemoteI, + rtl_uString *pOid , + typelib_TypeDescriptionReference *pType, + uno_Any **ppException + ); +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/bridges/inc/bridges/remote/mapping.hxx b/bridges/inc/bridges/remote/mapping.hxx new file mode 100644 index 000000000000..28903eff8ac2 --- /dev/null +++ b/bridges/inc/bridges/remote/mapping.hxx @@ -0,0 +1,72 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * 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_REMOTE_MAPPING_HXX_ +#define _BRIDGES_REMOTE_MAPPING_HXX_ + +#include <osl/interlck.h> +#include <rtl/ustring.hxx> + +#include <typelib/typedescription.h> + +#include <bridges/remote/remote.h> + +typedef struct _uno_Environment uno_Environment; + +namespace bridges_remote +{ + extern "C" typedef void SAL_CALL RemoteToUno( + uno_Mapping *pMapping, void **ppOut, void *pInterface, + typelib_InterfaceTypeDescription *pInterfaceTypeDescr ); + RemoteToUno remoteToUno; + + extern "C" typedef void SAL_CALL UnoToRemote( + uno_Mapping *pMapping, void **ppOut, void *pInterface, + typelib_InterfaceTypeDescription *pInterfaceTypeDescr ); + UnoToRemote unoToRemote; + + extern "C" typedef void SAL_CALL FreeRemoteMapping(uno_Mapping * mapping); + FreeRemoteMapping freeRemoteMapping; + + class RemoteMapping : + public remote_Mapping + { + public: + RemoteMapping( uno_Environment *pEnvUno , + uno_Environment *pEnvRemote, + uno_MapInterfaceFunc func , + const ::rtl::OUString sPurpose); + ~RemoteMapping(); + + oslInterlockedCount m_nRef; + ::rtl::OUString m_sPurpose; + }; + +} +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/bridges/inc/bridges/remote/proxy.hxx b/bridges/inc/bridges/remote/proxy.hxx new file mode 100644 index 000000000000..25afecca6c13 --- /dev/null +++ b/bridges/inc/bridges/remote/proxy.hxx @@ -0,0 +1,94 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * 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. + * + ************************************************************************/ +#include <osl/interlck.h> + +#include <uno/environment.h> +#include <uno/dispatcher.h> +#include <uno/mapping.hxx> + +#include <bridges/remote/remote.h> + +namespace bridges_remote { + +extern "C" typedef void SAL_CALL FreeRemote2UnoProxy( + uno_ExtEnvironment * environment, void * proxy); +FreeRemote2UnoProxy freeRemote2UnoProxy; + +// private: +extern "C" typedef void SAL_CALL AcquireRemote2UnoProxy(uno_Interface *); +AcquireRemote2UnoProxy acquireRemote2UnoProxy; + +// private: +extern "C" typedef void SAL_CALL ReleaseRemote2UnoProxy(uno_Interface *); +ReleaseRemote2UnoProxy releaseRemote2UnoProxy; + +// private: +extern "C" typedef void SAL_CALL DispatchRemote2UnoProxy( + uno_Interface *, typelib_TypeDescription const *, void *, void **, + uno_Any **); +DispatchRemote2UnoProxy dispatchRemote2UnoProxy; + +extern "C" void SAL_CALL remote_release( void * ); + +class Remote2UnoProxy : + public uno_Interface +{ +public: + Remote2UnoProxy( + remote_Interface *pRemoteI, + rtl_uString *pOid, + typelib_InterfaceTypeDescription *pType , + uno_Environment *pEnvUno, + uno_Environment *pEnvRemote + ); + + ~Remote2UnoProxy(); + +private: + ::rtl::OUString m_sOid; + typelib_InterfaceTypeDescription *m_pType; + remote_Interface *m_pRemoteI; + uno_Environment *m_pEnvUno; + uno_Environment *m_pEnvRemote; + ::com::sun::star::uno::Mapping m_mapRemote2Uno; + ::com::sun::star::uno::Mapping m_mapUno2Remote; + + oslInterlockedCount m_nRef; + + friend void SAL_CALL acquireRemote2UnoProxy(uno_Interface *); + + friend void SAL_CALL releaseRemote2UnoProxy(uno_Interface *); + + friend void SAL_CALL dispatchRemote2UnoProxy( + uno_Interface *, typelib_TypeDescription const *, void *, void **, + uno_Any **); +}; + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/bridges/inc/bridges/remote/remote.h b/bridges/inc/bridges/remote/remote.h new file mode 100644 index 000000000000..1e8ebabf2b93 --- /dev/null +++ b/bridges/inc/bridges/remote/remote.h @@ -0,0 +1,96 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * 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_REMOTE_REMOTE_H +#define _BRIDGES_REMOTE_REMOTE_H +#include <uno/mapping.h> +#include <uno/any2.h> + +#include <typelib/typedescription.h> +#include <uno/environment.h> + +#define CORBA_STRING8_NAME "com.sun.star.corba.CorbaString8" +#define CORBA_STRING8_NAME_LENGTH (sizeof(CORBA_STRING8_NAME)-1) + +#define CORBA_UNION_NAME "com.sun.star.corba.CorbaUnion" +#define CORBA_UNION_NAME_LENGTH (sizeof(CORBA_UNION_NAME)-1) + +#define REMOTE_MARSHALED_MSGHDR_SIZE 12 +#define REMOTE_RELEASE_METHOD_INDEX 2 +#define REMOTE_RELEASE_METHOD_NAME "release" + +#define CURRENT_IIOP_PROTOCOL_MAJOR 1 +#define CURRENT_IIOP_PROTOCOL_MINOR 2 + +extern "C" { + +struct remote_Interface; + +/** @internal + */ +typedef void (SAL_CALL * remote_DispatchMethod)( + remote_Interface * pRemoteI, typelib_TypeDescription const * pMemberType, + void * pReturn, void * pArgs[], uno_Any ** ppException ); + +/** + @internal + */ +typedef void ( SAL_CALL * requestClientSideDispatcher ) ( + uno_Environment *pEnvRemote, + typelib_TypeDescription const * pMemberType, + rtl_uString *pOid, + typelib_InterfaceTypeDescription *pInterfaceType, + void *pReturn, + void *ppArgs[], + uno_Any **ppException ); + +/** The base class of an UNO interface in a remote environment. + */ +struct remote_Interface +{ + void (SAL_CALL * acquire)( remote_Interface * pInterface ); + + void (SAL_CALL * release)( remote_Interface * pInterface ); + + remote_DispatchMethod pDispatcher; +}; + +/** The mapping between an binary-c-uno and a remote environment. + @internal + */ +struct remote_Mapping +{ + uno_Mapping aBase; + uno_Environment *pEnvRemote; + uno_Environment *pEnvUno; +}; + +} + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/bridges/inc/bridges/remote/remote.hxx b/bridges/inc/bridges/remote/remote.hxx new file mode 100644 index 000000000000..a4fcac21f1c8 --- /dev/null +++ b/bridges/inc/bridges/remote/remote.hxx @@ -0,0 +1,76 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * 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_REMOTE_REMOTE_HXX_ +#define _BRIDGES_REMOTE_REMOTE_HXX_ +#include <list> + +#include <osl/mutex.hxx> +#include <osl/conditn.h> +#include <osl/interlck.h> + +#include <uno/environment.h> + +#include <bridges/remote/remote.h> +#include <bridges/remote/connection.h> + +#include <com/sun/star/uno/Sequence.hxx> + +namespace bridges_remote { + +extern "C" typedef void SAL_CALL AcquireRemote2RemoteStub( + remote_Interface * pThis); +AcquireRemote2RemoteStub acquireRemote2RemoteStub; + +extern "C" typedef void SAL_CALL FreeRemote2RemoteStub( + uno_ExtEnvironment * environment, void * stub); +FreeRemote2RemoteStub freeRemote2RemoteStub; + +class Remote2RemoteStub : + public remote_Interface +{ +public: + Remote2RemoteStub(rtl_uString *pOid, + typelib_InterfaceTypeDescription *pType, + uno_Environment *pEnvRemote, + requestClientSideDispatcher dispatch ); + ~Remote2RemoteStub(); + + void releaseRemote(); +public: + ::rtl::OUString m_sOid; + typelib_InterfaceTypeDescription *m_pType; + oslInterlockedCount m_nRef; + uno_Environment *m_pEnvRemote; + requestClientSideDispatcher m_dispatch; + oslInterlockedCount m_nReleaseRemote; +}; + +} +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/bridges/inc/bridges/remote/stub.hxx b/bridges/inc/bridges/remote/stub.hxx new file mode 100644 index 000000000000..b89389ec50fe --- /dev/null +++ b/bridges/inc/bridges/remote/stub.hxx @@ -0,0 +1,67 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * 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. + * + ************************************************************************/ +#include <bridges/remote/remote.hxx> + +#include <uno/dispatcher.h> +#include <uno/mapping.hxx> + +namespace bridges_remote { + +extern "C" typedef void SAL_CALL AcquireUno2RemoteStub( remote_Interface *pThis ); +AcquireUno2RemoteStub acquireUno2RemoteStub; + +extern "C" typedef void SAL_CALL FreeUno2RemoteStub( + uno_ExtEnvironment * environment, void * stub); +FreeUno2RemoteStub freeUno2RemoteStub; + +class Uno2RemoteStub : + public remote_Interface +{ +public: + Uno2RemoteStub( uno_Interface *pUnoI, + rtl_uString *pOid, + typelib_InterfaceTypeDescription *pType, + uno_Environment *pEnvUno, + uno_Environment *pEnvRemote ); + ~Uno2RemoteStub(); + +public: + ::rtl::OUString m_sOid; + typelib_InterfaceTypeDescription *m_pType; + uno_Interface *m_pUnoI; + oslInterlockedCount m_nRef; + + uno_Environment *m_pEnvUno; + uno_Environment *m_pEnvRemote; + ::com::sun::star::uno::Mapping m_mapRemote2Uno; + ::com::sun::star::uno::Mapping m_mapUno2Remote; +}; + +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |