diff options
-rw-r--r-- | cppu/inc/uno/current_context.h | 23 | ||||
-rw-r--r-- | cppu/inc/uno/current_context.hxx | 59 | ||||
-rw-r--r-- | cppu/prj/d.lst | 2 | ||||
-rw-r--r-- | cppu/source/threadpool/current.cxx | 625 | ||||
-rw-r--r-- | cppu/source/threadpool/current.hxx | 9 | ||||
-rw-r--r-- | cppu/test/makefile.mk | 10 | ||||
-rw-r--r-- | cppu/test/testcppu.cxx | 82 |
7 files changed, 330 insertions, 480 deletions
diff --git a/cppu/inc/uno/current_context.h b/cppu/inc/uno/current_context.h index c540544d3378..f2edc275c0f6 100644 --- a/cppu/inc/uno/current_context.h +++ b/cppu/inc/uno/current_context.h @@ -2,9 +2,9 @@ * * $RCSfile: current_context.h,v $ * - * $Revision: 1.3 $ + * $Revision: 1.4 $ * - * last change: $Author: dbo $ $Date: 2001-03-28 10:46:06 $ + * last change: $Author: dbo $ $Date: 2001-05-07 15:06:56 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -70,17 +70,30 @@ extern "C" { #endif -/** Gets the current thread's context. +/** Gets the current task's context. - @param ppCompEnv out param current context of type com.sun.star.uno.XCurrentContext + @param ppCurrentContext inout param current context of type com.sun.star.uno.XCurrentContext @param pEnvTypeName type name of returned interface's environment @param pEnvContext context of returned interface's environment (commonly 0) + @return true, if context ref was transferred (even if null ref) */ -void SAL_CALL uno_getCurrentContext( +sal_Bool SAL_CALL uno_getCurrentContext( void ** ppCurrentContext, rtl_uString * pEnvTypeName, void * pEnvContext ) SAL_THROW_EXTERN_C(); +/** Sets the current task's context. + + @param pCurrentContext in param current context of type com.sun.star.uno.XCurrentContext + @param pEnvTypeName type name of interface's environment + @param pEnvContext context of interface's environment (commonly 0) + @return true, if context ref was transferred (even if null ref) +*/ +sal_Bool SAL_CALL uno_setCurrentContext( + void * pCurrentContext, + rtl_uString * pEnvTypeName, void * pEnvContext ) + SAL_THROW_EXTERN_C(); + #ifdef __cplusplus } #endif diff --git a/cppu/inc/uno/current_context.hxx b/cppu/inc/uno/current_context.hxx index 0859c2ca4b1f..ca0282b0ddb0 100644 --- a/cppu/inc/uno/current_context.hxx +++ b/cppu/inc/uno/current_context.hxx @@ -2,9 +2,9 @@ * * $RCSfile: current_context.hxx,v $ * - * $Revision: 1.2 $ + * $Revision: 1.3 $ * - * last change: $Author: dbo $ $Date: 2001-03-09 12:10:56 $ + * last change: $Author: dbo $ $Date: 2001-05-07 15:06:56 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -61,9 +61,7 @@ #ifndef _UNO_CURRENT_CONTEXT_HXX_ #define _UNO_CURRENT_CONTEXT_HXX_ -#include <osl/diagnose.h> #include <uno/current_context.h> - #include <cppu/macros.hxx> #include <com/sun/star/uno/XCurrentContext.hpp> @@ -82,38 +80,49 @@ namespace star namespace uno { -/** Current context. +/** Getting the current context. + + @return current context or null ref, if none is set */ -inline Reference< XCurrentContext > SAL_CALL getCurrentContext() SAL_THROW( () ) +inline Reference< XCurrentContext > SAL_CALL getCurrentContext() + SAL_THROW( () ) { - ::rtl::OUString aEnvTypeName( RTL_CONSTASCII_USTRINGPARAM(CPPU_CURRENT_LANGUAGE_BINDING_NAME) ); - Reference< XCurrentContext > xRet; + ::rtl::OUString aEnvTypeName( RTL_CONSTASCII_USTRINGPARAM(CPPU_CURRENT_LANGUAGE_BINDING_NAME) ); ::uno_getCurrentContext( (void **)&xRet, aEnvTypeName.pData, 0 ); - return xRet; } +/** Setting the current context. -/** Security support. + @param xContext current context to be set + @return true, if context has been successfully set */ -inline void SAL_CALL checkPermission( - const ::com::sun::star::security::Permission & rPerm ) - SAL_THROW( (::com::sun::star::security::AccessControlException) ) +inline bool SAL_CALL setCurrentContext( + Reference< XCurrentContext > const & xContext ) + SAL_THROW( () ) { - Reference< XCurrentContext > xContext( getCurrentContext() ); - OSL_ENSURE( xContext.is(), "### cannot get current thread's uno context!" ); - - if (xContext.is()) - { - Reference< ::com::sun::star::security::XAccessController > xAC( - xContext->getAccessController() ); - if (xAC.is()) // access controller installed? - { - xAC->checkPermission( rPerm ); - } - } + ::rtl::OUString aEnvTypeName( RTL_CONSTASCII_USTRINGPARAM(CPPU_CURRENT_LANGUAGE_BINDING_NAME) ); + return (::uno_setCurrentContext( xContext.get(), aEnvTypeName.pData, 0 ) != sal_False); } +// /** Permission check. +// */ +// inline void SAL_CALL checkPermission( +// ::com::sun::star::security::Permission const & rPerm ) +// SAL_THROW( (::com::sun::star::security::AccessControlException) ) +// { +// Reference< XCurrentContext > xContext( getCurrentContext() ); +// if (xContext.is()) +// { +// Reference< ::com::sun::star::security::XAccessController > xAC; +// if (xContext->getValueByName( OUString( +// RTL_CONSTASCII_USTRINGPARAM("com.sun.star.security.AccessController") ) ) >>= xAC) +// { +// xAC->checkPermission( rPerm ); +// } +// } +// } + } } } diff --git a/cppu/prj/d.lst b/cppu/prj/d.lst index ba84a4b960c5..c6b6446917ea 100644 --- a/cppu/prj/d.lst +++ b/cppu/prj/d.lst @@ -34,6 +34,8 @@ mkdir: %_DEST%\inc%_EXT%\uno ..\inc\uno\mapping.h %_DEST%\inc%_EXT%\uno\mapping.h ..\inc\uno\mapping.hxx %_DEST%\inc%_EXT%\uno\mapping.hxx ..\inc\uno\threadpool.h %_DEST%\inc%_EXT%\uno\threadpool.h +..\inc\uno\current_context.h %_DEST%\inc%_EXT%\uno\current_context.h +..\inc\uno\current_context.hxx %_DEST%\inc%_EXT%\uno\current_context.hxx ..\%__SRC%\lib\icppu.lib %_DEST%\lib%_EXT%\icppu.lib ..\%__SRC%\bin\cppu* %_DEST%\bin%_EXT%\* 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; } diff --git a/cppu/source/threadpool/current.hxx b/cppu/source/threadpool/current.hxx index 2e0a8a32d51e..a817e66e2ebf 100644 --- a/cppu/source/threadpool/current.hxx +++ b/cppu/source/threadpool/current.hxx @@ -2,9 +2,9 @@ * * $RCSfile: current.hxx,v $ * - * $Revision: 1.2 $ + * $Revision: 1.3 $ * - * last change: $Author: dbo $ $Date: 2001-03-09 12:10:56 $ + * last change: $Author: dbo $ $Date: 2001-05-07 15:07:01 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -61,13 +61,16 @@ #include <rtl/byteseq.h> +typedef struct _uno_ExtEnvironment uno_ExtEnvironment; + namespace cppu { struct CurrentContext; struct IdContainer { - CurrentContext * pCurrent; + void * pCurrentContext; + uno_ExtEnvironment * pCurrentContextEnv; // sal_Bool bInit; sal_Sequence * pLocalThreadId; diff --git a/cppu/test/makefile.mk b/cppu/test/makefile.mk index 567f93ba6a7f..6a73c51f01b6 100644 --- a/cppu/test/makefile.mk +++ b/cppu/test/makefile.mk @@ -2,9 +2,9 @@ # # $RCSfile: makefile.mk,v $ # -# $Revision: 1.18 $ +# $Revision: 1.19 $ # -# last change: $Author: dbo $ $Date: 2001-04-27 11:01:07 $ +# last change: $Author: dbo $ $Date: 2001-05-07 15:07:01 $ # # The Contents of this file are made available subject to the terms of # either of the following licenses @@ -154,9 +154,9 @@ TYPES:= -Ttest.XLanguageBindingTest \ -Tcom.sun.star.uno.XAdapter \ -Tcom.sun.star.uno.XAggregation \ -Tcom.sun.star.uno.XWeak \ - -Tcom.sun.star.reflection.XIdlClassProvider - -# -Tcom.sun.star.uno.XCurrentContext \ + -Tcom.sun.star.beans.XPropertySet \ + -Tcom.sun.star.reflection.XIdlClassProvider \ + -Tcom.sun.star.uno.XCurrentContext $(BIN)$/testcppu.rdb: $(ALLIDLFILES) +idlc -I$(PRJ) -I$(SOLARIDLDIR) -O$(BIN) $? diff --git a/cppu/test/testcppu.cxx b/cppu/test/testcppu.cxx index 2b367f8fdc26..3577173eb9fa 100644 --- a/cppu/test/testcppu.cxx +++ b/cppu/test/testcppu.cxx @@ -2,9 +2,9 @@ * * $RCSfile: testcppu.cxx,v $ * - * $Revision: 1.18 $ + * $Revision: 1.19 $ * - * last change: $Author: dbo $ $Date: 2001-04-27 11:01:07 $ + * last change: $Author: dbo $ $Date: 2001-05-07 15:07:01 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -83,9 +83,13 @@ #include <test/Base1.hpp> #include <test/Base2.hpp> +#include <uno/current_context.hxx> #include <cppuhelper/servicefactory.hxx> +#include <cppuhelper/implbase1.hxx> #include <com/sun/star/lang/XComponent.hpp> +#include <com/sun/star/uno/XCurrentContext.hpp> +#include <com/sun/star/beans/XPropertySet.hpp> #include <test/XSimpleInterface.hpp> #include <test/XLanguageBindingTest.hpp> @@ -93,6 +97,7 @@ using namespace test; using namespace rtl; using namespace osl; +using namespace com::sun::star; using namespace com::sun::star::uno; using namespace com::sun::star::lang; using namespace com::sun::star::registry; @@ -853,6 +858,67 @@ inline const ::com::sun::star::uno::Type& SAL_CALL getCppuType( const Sequence< return getCppuSequenceType< OUString[2][4] >( getCppuArrayType2( (const OUString (*)[2][4])0 ) ); } +//================================================================================================== +class Test_CContext + : public ::cppu::WeakImplHelper1< XCurrentContext > +{ + Reference< XCurrentContext > m_xDel; + sal_Int32 m_value; + OUString m_name; +public: + inline Test_CContext( sal_Int32 val, OUString const & rName, + Reference< XCurrentContext > const & xDel ) + SAL_THROW( () ) + : m_xDel( xDel ) + , m_value( val ) + , m_name( rName ) + {} + + virtual Any SAL_CALL getValueByName( OUString const & rName ) + throw (RuntimeException); +}; +//__________________________________________________________________________________________________ +Any Test_CContext::getValueByName( OUString const & rName ) + throw (RuntimeException) +{ + if (rName == m_name) + { + return makeAny( m_value ); + } + else if (m_xDel.is()) + { + return m_xDel->getValueByName( rName ); + } + return Any(); +} +//================================================================================================== +static void testCurrentContext() +{ + setCurrentContext( new Test_CContext( + 5, OUString( RTL_CONSTASCII_USTRINGPARAM("Value1") ), + Reference< XCurrentContext >() ) ); + Reference< XCurrentContext > xCC( getCurrentContext() ); + OSL_ASSERT( + xCC.is() && + xCC->getValueByName( OUString( RTL_CONSTASCII_USTRINGPARAM("Value1") ) ) == (sal_Int16)5 && + !xCC->getValueByName( OUString( RTL_CONSTASCII_USTRINGPARAM("Value2") ) ).hasValue() ); + + setCurrentContext( new Test_CContext( + 7, OUString( RTL_CONSTASCII_USTRINGPARAM("Value2") ), + xCC ) ); + xCC = getCurrentContext(); + OSL_ASSERT( + xCC.is() && + xCC->getValueByName( OUString( RTL_CONSTASCII_USTRINGPARAM("Value1") ) ) == (sal_Int16)5 && + xCC->getValueByName( OUString( RTL_CONSTASCII_USTRINGPARAM("Value2") ) ) == (sal_Int16)7 && + !xCC->getValueByName( OUString( RTL_CONSTASCII_USTRINGPARAM("dummy") ) ).hasValue() ); + + uno_Interface * pContext = 0; + OUString aEnvName( RTL_CONSTASCII_USTRINGPARAM(UNO_LB_UNO) ); + OSL_VERIFY( ::uno_getCurrentContext( (void **)&pContext, aEnvName.pData, 0 ) ); + (*pContext->release)( pContext ); +} + void testArray(void) { long a[5][6]; @@ -1026,6 +1092,7 @@ int SAL_CALL main(int argc, char **argv) // test_CBridge(); // test_CBridge2(); + testCurrentContext(); testAssignment(); testCppu(); // testArray(); @@ -1037,10 +1104,15 @@ int SAL_CALL main(int argc, char **argv) // shutdown #ifdef SAL_W32 - Reference< XComponent > xComp( xMgr, UNO_QUERY ); - OSL_ENSURE( xComp.is(), "### serivce manager has to implement XComponent!" ); + { + Reference< XComponent > xComp; + Reference< beans::XPropertySet > xProps( xMgr, UNO_QUERY ); + OSL_ENSURE( xProps.is(), "### servicemanager has to implement XPropertySet!" ); + xProps->getPropertyValue( + OUString( RTL_CONSTASCII_USTRINGPARAM("DefaultContext") ) ) >>= xComp; + OSL_ENSURE( xComp.is(), "### serivce manager's default (root) context has to implement XComponent!" ); xComp->dispose(); - xMgr.clear(); + } #endif typelib_setCacheSize( 0 ); testEnvironments(); |