diff options
author | Daniel Boelzle <dbo@openoffice.org> | 2001-05-07 14:07:01 +0000 |
---|---|---|
committer | Daniel Boelzle <dbo@openoffice.org> | 2001-05-07 14:07:01 +0000 |
commit | ca133d88841acd4680e6290556504e58c59703b3 (patch) | |
tree | 71042e8196ce242d9c9328b523020b4b710389ed /cppu/source/threadpool/current.cxx | |
parent | 5675e380b626619fc428c39e550dc746ddf1b478 (diff) |
revisited current context impl
Diffstat (limited to 'cppu/source/threadpool/current.cxx')
-rw-r--r-- | cppu/source/threadpool/current.cxx | 625 |
1 files changed, 188 insertions, 437 deletions
diff --git a/cppu/source/threadpool/current.cxx b/cppu/source/threadpool/current.cxx index 8f4a460dd0bc..01f19995d550 100644 --- a/cppu/source/threadpool/current.cxx +++ b/cppu/source/threadpool/current.cxx @@ -2,9 +2,9 @@ * * $RCSfile: current.cxx,v $ * - * $Revision: 1.4 $ + * $Revision: 1.5 $ * - * last change: $Author: dbo $ $Date: 2001-03-28 10:46:08 $ + * last change: $Author: dbo $ $Date: 2001-05-07 15:07:00 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -65,13 +65,10 @@ #include <osl/thread.h> #include <osl/mutex.hxx> -// #include <uno/current_context.hxx> +#include <uno/current_context.hxx> #include <uno/environment.h> #include <uno/mapping.hxx> -#include <com/sun/star/lang/XTypeProvider.hpp> -#include <com/sun/star/container/XNameContainer.hpp> - #include "current.hxx" @@ -80,10 +77,6 @@ using namespace ::rtl; using namespace ::cppu; using namespace ::com::sun::star::uno; -using namespace ::com::sun::star::lang; -using namespace ::com::sun::star::container; -// using namespace ::com::sun::star::security; -// using namespace ::com::sun::star::security::auth::login; namespace cppu @@ -130,481 +123,239 @@ inline oslThreadKey ThreadKey::getThreadKey() SAL_THROW( () ) } return _hThreadKey; } -/* -//================================================================================================== -struct CurrentContext - : public XTypeProvider - , public XCurrentContext - , XNameContainer -{ - oslInterlockedCount _nRef; - - uno_ExtEnvironment * _pCachedEnv; - void * _pCachedInterface; - inline void setCachedInterface( void * pInterface, uno_ExtEnvironment * pEnv ) SAL_THROW( () ); - - Reference< XMultiServiceFactory > _xMgr; - Reference< XAccessController > _xAccessController; - Reference< XLoginContext > _xLoginContext; - - typedef ::std::hash_map< OUString, Any, OUStringHash, ::std::equal_to< OUString > > - t_String2Any; - - t_String2Any _env; - - // XInterface - virtual Any SAL_CALL queryInterface( const Type & rType ) - throw (RuntimeException); - virtual void SAL_CALL acquire() - throw (); - virtual void SAL_CALL release() - throw (); - // XTypeProvider - virtual Sequence< Type > SAL_CALL getTypes() - throw (RuntimeException); - virtual Sequence< sal_Int8 > SAL_CALL getImplementationId() - throw (RuntimeException); - // XCurrentContext - virtual Reference< XMultiServiceFactory > SAL_CALL getServiceManager() - throw (RuntimeException); - virtual Reference< XAccessController > SAL_CALL getAccessController() - throw (RuntimeException); - virtual Reference< XLoginContext > SAL_CALL getLoginContext() - throw (RuntimeException); - // XNameContainer - virtual void SAL_CALL insertByName( const OUString & rName, const Any & rElement ) - throw (IllegalArgumentException, ElementExistException, WrappedTargetException, RuntimeException); - virtual void SAL_CALL removeByName( const OUString & rName ) - throw (NoSuchElementException, WrappedTargetException, RuntimeException); - // XNameReplace - virtual void SAL_CALL replaceByName( const OUString & rName, const Any & rElement ) - throw (IllegalArgumentException, NoSuchElementException, WrappedTargetException, RuntimeException); - // XNameAccess - virtual Any SAL_CALL getByName( const OUString & rName ) - throw (NoSuchElementException, WrappedTargetException, RuntimeException); - virtual Sequence< OUString > SAL_CALL getElementNames() - throw (RuntimeException); - virtual sal_Bool SAL_CALL hasByName( const OUString & rName ) - throw (RuntimeException); - // XElementAccess - virtual Type SAL_CALL getElementType() - throw (RuntimeException); - virtual sal_Bool SAL_CALL hasElements() - throw (RuntimeException); - - inline CurrentContext() SAL_THROW( () ); - inline ~CurrentContext() SAL_THROW( () ); -}; -//__________________________________________________________________________________________________ -inline CurrentContext::~CurrentContext() SAL_THROW( () ) -{ -#ifdef CPPU_ASSERTIONS - OSL_TRACE( "\n> destructing current context..." ); -#endif - setCachedInterface( 0, 0 ); -} -//__________________________________________________________________________________________________ -inline CurrentContext::CurrentContext() SAL_THROW( () ) - : _nRef( 0 ) - , _pCachedEnv( 0 ) - , _pCachedInterface( 0 ) -{ -} -//__________________________________________________________________________________________________ -inline void CurrentContext::setCachedInterface( - void * pInterface, uno_ExtEnvironment * pEnv ) SAL_THROW( () ) -{ - // acquire new one - if (pInterface) - { - (*pEnv->acquireInterface)( pEnv, pInterface ); - } - if (pEnv) - { - (((uno_Environment *)pEnv)->acquire)( (uno_Environment *)pEnv ); - } - - if (_pCachedInterface) - { - (*_pCachedEnv->releaseInterface)( _pCachedEnv, _pCachedInterface ); - (((uno_Environment *)_pCachedEnv)->release)( (uno_Environment *)_pCachedEnv ); - } - - _pCachedEnv = pEnv; - _pCachedInterface = pInterface; -} - -// XInterface -//__________________________________________________________________________________________________ -Any CurrentContext::queryInterface( const Type & rType ) - throw (RuntimeException) -{ - if (rType == ::getCppuType( (const Reference< XCurrentContext > *)0 )) - { - return makeAny( Reference< XCurrentContext >( static_cast< XCurrentContext * >( this ) ) ); - } - else if (rType == ::getCppuType( (const Reference< XInterface > *)0 )) - { - return makeAny( Reference< XInterface >( static_cast< XCurrentContext * >( this ) ) ); - } - else if (rType == ::getCppuType( (const Reference< XNameContainer > *)0 )) - { - return makeAny( Reference< XNameContainer >( static_cast< XNameContainer * >( this ) ) ); - } - else if (rType == ::getCppuType( (const Reference< XNameReplace > *)0 )) - { - return makeAny( Reference< XNameReplace >( static_cast< XNameReplace * >( this ) ) ); - } - else if (rType == ::getCppuType( (const Reference< XNameAccess > *)0 )) - { - return makeAny( Reference< XNameAccess >( static_cast< XNameAccess * >( this ) ) ); - } - else if (rType == ::getCppuType( (const Reference< XElementAccess > *)0 )) - { - return makeAny( Reference< XElementAccess >( static_cast< XElementAccess * >( this ) ) ); - } - else if (rType == ::getCppuType( (const Reference< XTypeProvider > *)0 )) - { - return makeAny( Reference< XTypeProvider >( static_cast< XTypeProvider * >( this ) ) ); - } - else - { - return Any(); - } -} -//__________________________________________________________________________________________________ -void CurrentContext::acquire() - throw () -{ - ::osl_incrementInterlockedCount( & _nRef ); -} -//__________________________________________________________________________________________________ -void CurrentContext::release() - throw () -{ - if (! ::osl_decrementInterlockedCount( & _nRef )) - { - delete this; - } -} - -// XTypeProvider -//__________________________________________________________________________________________________ -Sequence< Type > CurrentContext::getTypes() - throw (RuntimeException) -{ - Type ar[2] = { ::getCppuType( (const Reference< XCurrentContext > *)0 ), - ::getCppuType( (const Reference< XNameContainer > *)0 ) }; - return Sequence< Type >( ar, 2 ); -} -//__________________________________________________________________________________________________ -Sequence< sal_Int8 > CurrentContext::getImplementationId() - throw (RuntimeException) -{ - static Sequence< sal_Int8 > * s_pSeq = 0; - if (! s_pSeq) - { - MutexGuard aGuard( Mutex::getGlobalMutex() ); - if (! s_pSeq) - { - static Sequence< sal_Int8 > s_aSeq( 16 ); - ::rtl_createUuid( (sal_uInt8 *)s_aSeq.getArray(), 0, sal_True ); - s_pSeq = & s_aSeq; - } - } - return * s_pSeq; -} -// XCurrentContext -//__________________________________________________________________________________________________ -Reference< XMultiServiceFactory > CurrentContext::getServiceManager() - throw (RuntimeException) -{ - return _xMgr; -} -//__________________________________________________________________________________________________ -Reference< XLoginContext > CurrentContext::getLoginContext() - throw (RuntimeException) -{ - return _xLoginContext; -} -//__________________________________________________________________________________________________ -Reference< XAccessController > CurrentContext::getAccessController() - throw (RuntimeException) -{ - return _xAccessController; -} - -// XNameContainer -//__________________________________________________________________________________________________ -void CurrentContext::insertByName( const OUString & rName, const Any & rElement ) - throw (IllegalArgumentException, ElementExistException, WrappedTargetException, RuntimeException) +//================================================================================================== +extern "C" void SAL_CALL delete_IdContainer( void * p ) { - const t_String2Any::const_iterator iFind( _env.find( rName ) ); - if (iFind != _env.end()) - { - throw ElementExistException( - rName + OUString( RTL_CONSTASCII_USTRINGPARAM(": element exists!") ), - static_cast< XCurrentContext * >( this ) ); - } - _env[ rName ] = rElement; - - if (rName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("com.sun.star.lang.ServiceManager") )) - { - if (!(rElement >>= _xMgr) || !_xMgr.is()) - { - _env.erase( rName ); - throw IllegalArgumentException( - rName + OUString( RTL_CONSTASCII_USTRINGPARAM(": no XMultiServiceFactory given!") ), - static_cast< XCurrentContext * >( this ), 1 ); - } - } - else if (rName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("com.sun.star.security.AccessController") )) + if (p) { - if (!(rElement >>= _xAccessController) || !_xAccessController.is()) + IdContainer * pId = reinterpret_cast< IdContainer * >( p ); + if (pId->pCurrentContext) { - _env.erase( rName ); - throw IllegalArgumentException( - rName + OUString( RTL_CONSTASCII_USTRINGPARAM(": no XAccessController given!") ), - static_cast< XCurrentContext * >( this ), 1 ); + if (pId->pCurrentContextEnv) + { + (*pId->pCurrentContextEnv->releaseInterface)( + pId->pCurrentContextEnv, pId->pCurrentContext ); + (*((uno_Environment *)pId->pCurrentContextEnv)->release)( + (uno_Environment *)pId->pCurrentContextEnv ); + } + else // current compiler used for context interface implementation + { + reinterpret_cast< XInterface * >( pId->pCurrentContext )->release(); + } } - } - else if (rName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("com.sun.star.security.auth.login.LoginContext") )) - { - if (!(rElement >>= _xLoginContext) || !_xLoginContext.is()) + if (pId->bInit) { - _env.erase( rName ); - throw IllegalArgumentException( - rName + OUString( RTL_CONSTASCII_USTRINGPARAM(": no XLoginContext given!") ), - static_cast< XCurrentContext * >( this ), 1 ); + ::rtl_byte_sequence_release( pId->pLocalThreadId ); + ::rtl_byte_sequence_release( pId->pCurrentId ); } + delete pId; } } -//__________________________________________________________________________________________________ -void CurrentContext::removeByName( const OUString & rName ) - throw (NoSuchElementException, WrappedTargetException, RuntimeException) +//================================================================================================== +IdContainer * getIdContainer() SAL_THROW( () ) { - const t_String2Any::iterator iFind( _env.find( rName ) ); - if (iFind == _env.end()) - { - throw NoSuchElementException( - rName + OUString( RTL_CONSTASCII_USTRINGPARAM(": no such element!") ), - static_cast< XCurrentContext * >( this ) ); - } - _env.erase( iFind ); + static ThreadKey s_key( delete_IdContainer ); + oslThreadKey aKey = s_key.getThreadKey(); - if (rName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("com.sun.star.lang.ServiceManager") )) - { - _xMgr.clear(); - } - else if (rName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("com.sun.star.security.AccessController") )) + IdContainer * pId = reinterpret_cast< IdContainer * >( ::osl_getThreadKeyData( aKey ) ); + if (! pId) { - _xAccessController.clear(); - } - else if (rName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("com.sun.star.security.auth.login.LoginContext") )) - { - _xLoginContext.clear(); + pId = new IdContainer(); + pId->pCurrentContext = 0; + pId->pCurrentContextEnv = 0; + pId->bInit = sal_False; + ::osl_setThreadKeyData( aKey, pId ); } + return pId; } -// XNameReplace -//__________________________________________________________________________________________________ -void CurrentContext::replaceByName( const OUString & rName, const Any & rElement ) - throw (IllegalArgumentException, NoSuchElementException, WrappedTargetException, RuntimeException) + +} + +//################################################################################################## +extern "C" sal_Bool SAL_CALL uno_setCurrentContext( + void * pCurrentContext, + rtl_uString * pEnvTypeName, void * pEnvContext ) + SAL_THROW_EXTERN_C() { - const t_String2Any::iterator iFind( _env.find( rName ) ); - if (iFind == _env.end()) - { - throw NoSuchElementException( - rName + OUString( RTL_CONSTASCII_USTRINGPARAM(": no such element!") ), - static_cast< XCurrentContext * >( this ) ); - } - iFind->second = rElement; + IdContainer * pId = getIdContainer(); + OSL_ASSERT( pId ); - if (rName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("com.sun.star.lang.ServiceManager") )) + // free old one + if (pId->pCurrentContext) { - if (!(rElement >>= _xMgr) || !_xMgr.is()) + if (pId->pCurrentContextEnv) { - _env.erase( iFind ); - throw IllegalArgumentException( - rName + OUString( RTL_CONSTASCII_USTRINGPARAM(": no XMultiServiceFactory given!") ), - static_cast< XCurrentContext * >( this ), 1 ); + (*pId->pCurrentContextEnv->releaseInterface)( + pId->pCurrentContextEnv, pId->pCurrentContext ); + (*((uno_Environment *)pId->pCurrentContextEnv)->release)( + (uno_Environment *)pId->pCurrentContextEnv ); + pId->pCurrentContextEnv = 0; } - } - else if (rName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("com.sun.star.security.AccessController") )) - { - if (!(rElement >>= _xAccessController) || !_xAccessController.is()) + else // current compiler used for context interface implementation { - _env.erase( iFind ); - throw IllegalArgumentException( - rName + OUString( RTL_CONSTASCII_USTRINGPARAM(": no XAccessController given!") ), - static_cast< XCurrentContext * >( this ), 1 ); + reinterpret_cast< XInterface * >( pId->pCurrentContext )->release(); } + pId->pCurrentContext = 0; } - else if (rName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM("com.sun.star.security.auth.login.LoginContext") )) + + if (pCurrentContext) { - if (!(rElement >>= _xLoginContext) || !_xLoginContext.is()) + OUString const & rEnvTypeName = * reinterpret_cast< OUString const * >( &pEnvTypeName ); + if (rEnvTypeName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM(CPPU_CURRENT_LANGUAGE_BINDING_NAME) )) { - _env.erase( iFind ); - throw IllegalArgumentException( - rName + OUString( RTL_CONSTASCII_USTRINGPARAM(": no XLoginContext given!") ), - static_cast< XCurrentContext * >( this ), 1 ); + reinterpret_cast< XInterface * >( pCurrentContext )->acquire(); + pId->pCurrentContext = pCurrentContext; + pId->pCurrentContextEnv = 0; } - } -} -// XNameAccess -//__________________________________________________________________________________________________ -Any CurrentContext::getByName( const OUString & rName ) - throw (NoSuchElementException, WrappedTargetException, RuntimeException) -{ - const t_String2Any::const_iterator iFind( _env.find( rName ) ); - if (iFind != _env.end()) - { - return iFind->second; - } - - throw NoSuchElementException( - rName + OUString( RTL_CONSTASCII_USTRINGPARAM(": no such element!") ), - static_cast< XCurrentContext * >( this ) ); -} -//__________________________________________________________________________________________________ -Sequence< OUString > CurrentContext::getElementNames() - throw (RuntimeException) -{ - Sequence< OUString > keys( _env.size() ); - OUString * pKeys = keys.getArray(); - sal_uInt32 nPos = 0; - for ( t_String2Any::const_iterator iPos( _env.begin() ); iPos != _env.end(); ++iPos ) - { - pKeys[ nPos++ ] = iPos->first; - } - OSL_ASSERT( nPos == _env.size() ); - return keys; -} -//__________________________________________________________________________________________________ -sal_Bool CurrentContext::hasByName( const OUString & rName ) - throw (RuntimeException) -{ - const t_String2Any::const_iterator iFind( _env.find( rName ) ); - return (iFind != _env.end()); -} -// XElementAccess -//__________________________________________________________________________________________________ -Type CurrentContext::getElementType() - throw (RuntimeException) -{ - return ::getCppuVoidType(); -} -//__________________________________________________________________________________________________ -sal_Bool CurrentContext::hasElements() - throw (RuntimeException) -{ - return (! _env.empty()); -} -*/ -//================================================================================================== -extern "C" void SAL_CALL delete_IdContainer( void * p ) -{ - if (p) - { - IdContainer * pId = reinterpret_cast< IdContainer * >( p ); -// if (pId->pCurrent) -// { -// pId->pCurrent->release(); -// } - if (pId->bInit) + else { - rtl_byte_sequence_release( pId->pLocalThreadId ); - rtl_byte_sequence_release( pId->pCurrentId ); + uno_Environment * pEnv = 0; + ::uno_getEnvironment( &pEnv, pEnvTypeName, pEnvContext ); + OSL_ENSURE( pEnv && pEnv->pExtEnv, "### cannot get env of current context!" ); + if (pEnv) + { + if (pEnv->pExtEnv) + { + pId->pCurrentContextEnv = pEnv->pExtEnv; + (*pId->pCurrentContextEnv->acquireInterface)( + pId->pCurrentContextEnv, pCurrentContext ); + pId->pCurrentContext = pCurrentContext; + } + else + { + (*pEnv->release)( pEnv ); + return sal_False; + } + } + else + { + return sal_False; + } } - delete pId; - } -} -//================================================================================================== -IdContainer * getIdContainer() SAL_THROW( () ) -{ - static ThreadKey s_key( delete_IdContainer ); - oslThreadKey aKey = s_key.getThreadKey(); - - IdContainer * pContainer = reinterpret_cast< IdContainer * >( ::osl_getThreadKeyData( aKey ) ); - if (! pContainer) - { - pContainer = new IdContainer(); - pContainer->pCurrent = 0; - pContainer->bInit = sal_False; - ::osl_setThreadKeyData( aKey, pContainer ); } - return pContainer; -} + return sal_True; } - //################################################################################################## -extern "C" void SAL_CALL uno_getCurrentContext( +extern "C" sal_Bool SAL_CALL uno_getCurrentContext( void ** ppCurrentContext, rtl_uString * pEnvTypeName, void * pEnvContext ) SAL_THROW_EXTERN_C() { - *ppCurrentContext = 0; - /* - IdContainer * pContainer = getIdContainer(); - CurrentContext * that = pContainer->pCurrent; - if (! that) - { - that = new CurrentContext(); - that->acquire(); - pContainer->pCurrent = that; - } + IdContainer * pId = getIdContainer(); + OSL_ASSERT( pId ); - const OUString & rEnvTypeName = * reinterpret_cast< const OUString * >( & pEnvTypeName ); + uno_Environment * pTargetEnv = 0; + OUString const & rEnvTypeName = * reinterpret_cast< OUString const * >( &pEnvTypeName ); - // current env matches? - if (rEnvTypeName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM(CPPU_CURRENT_LANGUAGE_BINDING_NAME) ) && - !pEnvContext) - { - that->acquire(); - *ppCurrentContext = static_cast< XCurrentContext * >( that ); - } - // cached interface matches? - else if (that->_pCachedInterface && that->_pCachedEnv && - rEnvTypeName.equals( ((uno_Environment *)that->_pCachedEnv)->pTypeName ) && - pEnvContext == ((uno_Environment *)that->_pCachedEnv)->pContext) - { - (*that->_pCachedEnv->acquireInterface)( that->_pCachedEnv, that->_pCachedInterface ); - *ppCurrentContext = that->_pCachedInterface; - } - // map and set as cached - else + // release inout parameter + if (*ppCurrentContext) { + if (rEnvTypeName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM(CPPU_CURRENT_LANGUAGE_BINDING_NAME) )) + { + reinterpret_cast< XInterface * >( *ppCurrentContext )->release(); + } + else + { + ::uno_getEnvironment( &pTargetEnv, pEnvTypeName, pEnvContext ); + OSL_ENSURE( pTargetEnv, "### cannot get env of target current context!" ); + if (pTargetEnv) + { + uno_ExtEnvironment * pEnv = pTargetEnv->pExtEnv; + OSL_ENSURE( pEnv, "### cannot release given interface, because of incomplete env!" ); + if (pEnv) + { + (*pEnv->releaseInterface)( pEnv, *ppCurrentContext ); + } + else + { + (*pTargetEnv->release)( pTargetEnv ); + return sal_False; + } + } + else + { + return sal_False; + } + } *ppCurrentContext = 0; + } - uno_Environment * pTargetEnv = 0; - ::uno_getEnvironment( &pTargetEnv, pEnvTypeName, pEnvContext ); - OSL_ASSERT( pTargetEnv ); - if (pTargetEnv) + sal_Bool bRet = sal_False; + + if (pId->pCurrentContext) + { + if (pId->pCurrentContextEnv) + { + if (::rtl_ustr_compare( + ((uno_Environment *)pId->pCurrentContextEnv)->pTypeName->buffer, pEnvTypeName->buffer ) && + ((uno_Environment *)pId->pCurrentContextEnv)->pContext == pEnvContext) // same env + { + (*pId->pCurrentContextEnv->acquireInterface)( + pId->pCurrentContextEnv, pId->pCurrentContext ); + *ppCurrentContext = pId->pCurrentContext; + bRet = sal_True; + } + else // map from set context to target + { + if (! pTargetEnv) + { + ::uno_getEnvironment( &pTargetEnv, pEnvTypeName, pEnvContext ); + } + if (pTargetEnv) + { + Mapping aMapping( (uno_Environment *)pId->pCurrentContextEnv, pTargetEnv ); + if (aMapping.is()) + { + aMapping.mapInterface( + ppCurrentContext, pId->pCurrentContext, + ::getCppuType( (Reference< XCurrentContext > const *)0 ) ); + bRet = sal_True; + } + } + } + } + else if (pTargetEnv || + !rEnvTypeName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM(CPPU_CURRENT_LANGUAGE_BINDING_NAME) ) || + pEnvContext) + // mapping needed from current to target { - uno_Environment * pThisEnv = 0; - OUString aCurrentName( RTL_CONSTASCII_USTRINGPARAM(CPPU_CURRENT_LANGUAGE_BINDING_NAME) ); - ::uno_getEnvironment( &pThisEnv, aCurrentName.pData, 0 ); - OSL_ASSERT( pThisEnv ); - if (pThisEnv) + if (! pTargetEnv) { - Mapping aMapping( pThisEnv, pTargetEnv ); - if (aMapping.is()) + ::uno_getEnvironment( &pTargetEnv, pEnvTypeName, pEnvContext ); + } + if (pTargetEnv) + { + OUString aCurrentEnv( RTL_CONSTASCII_USTRINGPARAM(CPPU_CURRENT_LANGUAGE_BINDING_NAME) ); + uno_Environment * pCurrentEnv = 0; + ::uno_getEnvironment( &pCurrentEnv, aCurrentEnv.pData, 0 ); + OSL_ASSERT( pCurrentEnv ); + if (pCurrentEnv) { - aMapping.mapInterface( - ppCurrentContext, static_cast< XCurrentContext * >( that ), - ::getCppuType( (const Reference< XCurrentContext > *)0 ) ); - // set as cached - if (*ppCurrentContext && pTargetEnv->pExtEnv) + Mapping aMapping( pCurrentEnv, pTargetEnv ); + if (aMapping.is()) { - that->setCachedInterface( - *ppCurrentContext, pTargetEnv->pExtEnv ); + aMapping.mapInterface( + ppCurrentContext, pId->pCurrentContext, + ::getCppuType( (Reference< XCurrentContext > const *)0 ) ); + bRet = sal_True; } } - (*pThisEnv->release)( pThisEnv ); } + } + else // set env is current env is target env => no mapping needed + { + reinterpret_cast< XInterface * >( pId->pCurrentContext )->acquire(); + *ppCurrentContext = pId->pCurrentContext; + bRet = sal_True; + } + + if (pTargetEnv) + { (*pTargetEnv->release)( pTargetEnv ); } } - */ + + return bRet; } |