diff options
author | Joachim Lingner <jl@openoffice.org> | 2001-06-18 09:32:32 +0000 |
---|---|---|
committer | Joachim Lingner <jl@openoffice.org> | 2001-06-18 09:32:32 +0000 |
commit | d2c44e121ca80bdffe64fce4d6de76aaf96913c7 (patch) | |
tree | 2386e540f12437e3937a97c37a9d913e9901316a /stoc/source/servicemanager | |
parent | bb9a61415dfd617254af99d1b0b8e95115778265 (diff) |
added support for library unloading
Diffstat (limited to 'stoc/source/servicemanager')
-rw-r--r-- | stoc/source/servicemanager/servicemanager.cxx | 73 |
1 files changed, 70 insertions, 3 deletions
diff --git a/stoc/source/servicemanager/servicemanager.cxx b/stoc/source/servicemanager/servicemanager.cxx index e0e063a6260d..b29b522466e2 100644 --- a/stoc/source/servicemanager/servicemanager.cxx +++ b/stoc/source/servicemanager/servicemanager.cxx @@ -2,9 +2,9 @@ * * $RCSfile: servicemanager.cxx,v $ * - * $Revision: 1.6 $ + * $Revision: 1.7 $ * - * last change: $Author: dbo $ $Date: 2001-05-11 13:43:43 $ + * last change: $Author: jl $ $Date: 2001-06-18 10:32:32 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -71,6 +71,7 @@ #include <hash_map> #include <hash_set> +#include <list> #ifndef _UNO_MAPPING_HXX_ #include <uno/mapping.hxx> @@ -96,7 +97,9 @@ #ifndef _CPPUHELPER_TYPEPROVIDER_HXX_ #include <cppuhelper/typeprovider.hxx> #endif - +#ifndef _RTL_UNLOAD_H_ +#include <rtl/unload.h> +#endif #include <cppuhelper/component_context.hxx> #include <cppuhelper/bootstrap.hxx> @@ -115,6 +118,7 @@ #include <com/sun/star/container/XEnumeration.hpp> #include <com/sun/star/container/XContentEnumerationAccess.hpp> #include <com/sun/star/container/XHierarchicalNameAccess.hpp> +#include <com/sun/star/uno/XUnloadingPreference.hpp> using namespace com::sun::star; using namespace com::sun::star::uno; @@ -127,9 +131,14 @@ using namespace osl; using namespace rtl; using namespace std; + + namespace stoc_smgr { + + + /***************************************************************************** helper functions *****************************************************************************/ @@ -353,6 +362,8 @@ struct OServiceManagerMutex Mutex m_mutex; }; +extern "C" void SAL_CALL smgrUnloadingListener(void* id); + class OServiceManager : public XMultiServiceFactory , public XMultiComponentFactory @@ -363,6 +374,8 @@ class OServiceManager , public OComponentHelper { public: + friend void SAL_CALL smgrUnloadingListener(void* id); + OServiceManager( Reference< XComponentContext > const & xContext ); ~OServiceManager(); @@ -424,12 +437,15 @@ public: virtual void SAL_CALL dispose() throw(::com::sun::star::uno::RuntimeException); protected: + sal_Bool haveFactoryWithThisImplementation(const OUString& aImplName); virtual Reference< XInterface > queryServiceFactory(const OUString& aServiceName); Reference< XComponentContext > m_xContext; + sal_Int32 m_nUnloadingListenerId; private: + Reference<XEventListener > getFactoryListener(); @@ -446,6 +462,7 @@ OServiceManager::OServiceManager( Reference< XComponentContext > const & xContex : OComponentHelper( m_mutex ) , m_xContext( xContext ) { + m_nUnloadingListenerId= rtl_addUnloadingListener( smgrUnloadingListener, this); } /** @@ -453,6 +470,7 @@ OServiceManager::OServiceManager( Reference< XComponentContext > const & xContex */ OServiceManager::~OServiceManager() { + rtl_removeUnloadingListener( m_nUnloadingListenerId ); } // OComponentHelper @@ -1020,6 +1038,7 @@ ORegistryServiceManager::ORegistryServiceManager( Reference< XComponentContext > , m_init( false ) #endif { + m_nUnloadingListenerId= rtl_addUnloadingListener( smgrUnloadingListener, this); } /** @@ -1027,6 +1046,7 @@ ORegistryServiceManager::ORegistryServiceManager( Reference< XComponentContext > */ ORegistryServiceManager::~ORegistryServiceManager() { + rtl_removeUnloadingListener( m_nUnloadingListenerId); } // OComponentHelper @@ -1416,11 +1436,58 @@ static Reference<XInterface > SAL_CALL ORegistryServiceManager_CreateInstance( { return Reference<XInterface >( SAL_STATIC_CAST( XInterface *, SAL_STATIC_CAST( OWeakObject *, new ORegistryServiceManager( xContext ) ) ) ); } +/* This is the listener function used by the service manager in order +to implement the unloading mechanism, id is the this pointer of the +service manager instances. On notification, that is the function is being called +by rtl_unloadUnusedModules, the cached factroies are being removed from the +service manager. +*/ +extern "C" void SAL_CALL smgrUnloadingListener(void* id) +{ + stoc_smgr::OServiceManager* pMgr= reinterpret_cast<stoc_smgr::OServiceManager*>( id); + Reference<XInterface> xInt( static_cast<OWeakObject*>(pMgr) ); + Reference<XEnumerationAccess>xEnumAcc( xInt, UNO_QUERY); + Reference<XSet>xSet( xInt, UNO_QUERY); + + if(xEnumAcc.is() && xSet.is()) + { + Reference<XEnumeration> xEnum= xEnumAcc->createEnumeration(); + if( xEnum.is()) + { + try + { + while( xEnum->hasMoreElements()) + { + Any val= xEnum->nextElement(); + + Reference<XInterface> xIntFactory; + if( val >>= xIntFactory) + { + Reference<XUnloadingPreference>xUnload( xIntFactory, UNO_QUERY); + if( xUnload.is()) + if( xUnload->releaseOnNotification()) + xSet->remove( val); + else + xSet->remove( val); + } + } + } + catch( NoSuchElementException) + { + } + catch( WrappedTargetException) + { + } + } + } +} } // namespace + + //################################################################################################## //################################################################################################## //################################################################################################## |