diff options
author | Noel Grandin <noel@peralex.com> | 2020-07-21 15:16:21 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2020-07-24 12:32:33 +0200 |
commit | b34e36146fbe1139255f0abf9f5df8e89e2ac024 (patch) | |
tree | 54e4173005d29067ea42cfc30084fbc9e44c782d /dtrans/source | |
parent | 3bb40b608d524b7795aa0e61be97feceac0f1840 (diff) |
dtrans/generic: create instances with uno constructors
See tdf#74608 for motivation.
Change-Id: Id5c585f28cb8696f37513bd2a2112af8d278648c
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/99161
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'dtrans/source')
-rw-r--r-- | dtrans/source/generic/clipboardmanager.cxx | 97 | ||||
-rw-r--r-- | dtrans/source/generic/clipboardmanager.hxx | 6 | ||||
-rw-r--r-- | dtrans/source/generic/dtrans.component | 8 | ||||
-rw-r--r-- | dtrans/source/generic/dtrans.cxx | 74 | ||||
-rw-r--r-- | dtrans/source/generic/generic_clipboard.cxx | 18 | ||||
-rw-r--r-- | dtrans/source/generic/generic_clipboard.hxx | 6 |
6 files changed, 68 insertions, 141 deletions
diff --git a/dtrans/source/generic/clipboardmanager.cxx b/dtrans/source/generic/clipboardmanager.cxx index 0c5dd396fec9..8cea07171f78 100644 --- a/dtrans/source/generic/clipboardmanager.cxx +++ b/dtrans/source/generic/clipboardmanager.cxx @@ -22,8 +22,10 @@ #include <com/sun/star/container/NoSuchElementException.hpp> #include <com/sun/star/lang/DisposedException.hpp> #include <com/sun/star/lang/IllegalArgumentException.hpp> +#include <com/sun/star/uno/XComponentContext.hpp> #include <cppuhelper/supportsservice.hxx> #include <comphelper/sequence.hxx> +#include <rtl/ref.hxx> using namespace com::sun::star::container; using namespace com::sun::star::datatransfer; @@ -36,6 +38,11 @@ using namespace std; using ::dtrans::ClipboardManager; +static osl::Mutex g_InstanceGuard; +static rtl::Reference<ClipboardManager> g_Instance; +static bool g_Disposed = false; + + ClipboardManager::ClipboardManager(): WeakComponentImplHelper< XClipboardManager, XEventListener, XServiceInfo > (m_aMutex), m_aDefaultName(OUString("default")) @@ -48,7 +55,7 @@ ClipboardManager::~ClipboardManager() OUString SAL_CALL ClipboardManager::getImplementationName( ) { - return CLIPBOARDMANAGER_IMPLEMENTATION_NAME; + return "com.sun.star.comp.datatransfer.ClipboardManager"; } sal_Bool SAL_CALL ClipboardManager::supportsService( const OUString& ServiceName ) @@ -58,7 +65,7 @@ sal_Bool SAL_CALL ClipboardManager::supportsService( const OUString& ServiceName Sequence< OUString > SAL_CALL ClipboardManager::getSupportedServiceNames( ) { - return ClipboardManager_getSupportedServiceNames(); + return { "com.sun.star.datatransfer.clipboard.ClipboardManager" }; } Reference< XClipboard > SAL_CALL ClipboardManager::getClipboard( const OUString& aName ) @@ -139,43 +146,50 @@ Sequence< OUString > SAL_CALL ClipboardManager::listClipboardNames() void SAL_CALL ClipboardManager::dispose() { - ClearableMutexGuard aGuard( rBHelper.rMutex ); - if (!rBHelper.bDisposed && !rBHelper.bInDispose) { - rBHelper.bInDispose = true; - aGuard.clear(); - - // give everyone a chance to save his clipboard instance - EventObject aEvt(static_cast < XClipboardManager * > (this)); - rBHelper.aLC.disposeAndClear( aEvt ); - - // removeClipboard is still allowed here, so make a copy of the - // list (to ensure integrity) and clear the original. - ClearableMutexGuard aGuard2( rBHelper.rMutex ); - ClipboardMap aCopy(m_aClipboardMap); - m_aClipboardMap.clear(); - aGuard2.clear(); - - // dispose all clipboards still in list - for (auto const& elem : aCopy) + osl::MutexGuard aGuard(g_InstanceGuard); + g_Instance.clear(); + g_Disposed = true; + } + { + ClearableMutexGuard aGuard( rBHelper.rMutex ); + if (!rBHelper.bDisposed && !rBHelper.bInDispose) { - Reference< XComponent > xComponent(elem.second, UNO_QUERY); - if (xComponent.is()) + rBHelper.bInDispose = true; + aGuard.clear(); + + // give everyone a chance to save his clipboard instance + EventObject aEvt(static_cast < XClipboardManager * > (this)); + rBHelper.aLC.disposeAndClear( aEvt ); + + // removeClipboard is still allowed here, so make a copy of the + // list (to ensure integrity) and clear the original. + ClearableMutexGuard aGuard2( rBHelper.rMutex ); + ClipboardMap aCopy(m_aClipboardMap); + m_aClipboardMap.clear(); + aGuard2.clear(); + + // dispose all clipboards still in list + for (auto const& elem : aCopy) { - try - { - xComponent->removeEventListener(static_cast < XEventListener * > (this)); - xComponent->dispose(); - } - catch (const Exception&) + Reference< XComponent > xComponent(elem.second, UNO_QUERY); + if (xComponent.is()) { - // exceptions can be safely ignored here. + try + { + xComponent->removeEventListener(static_cast < XEventListener * > (this)); + xComponent->dispose(); + } + catch (const Exception&) + { + // exceptions can be safely ignored here. + } } } - } - rBHelper.bDisposed = true; - rBHelper.bInDispose = false; + rBHelper.bDisposed = true; + rBHelper.bInDispose = false; + } } } @@ -187,16 +201,17 @@ void SAL_CALL ClipboardManager::disposing( const EventObject& event ) removeClipboard(xClipboard->getName()); } -Reference< XInterface > ClipboardManager_createInstance( - const Reference< XMultiServiceFactory > & /*xMultiServiceFactory*/) -{ - return Reference < XInterface >(static_cast<OWeakObject *>(new ClipboardManager())); -} - -Sequence< OUString > ClipboardManager_getSupportedServiceNames() +extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface* +dtrans_ClipboardManager_get_implementation( + css::uno::XComponentContext* , css::uno::Sequence<css::uno::Any> const&) { - Sequence < OUString > SupportedServicesNames { "com.sun.star.datatransfer.clipboard.ClipboardManager" }; - return SupportedServicesNames; + osl::MutexGuard aGuard(g_InstanceGuard); + if (g_Disposed) + return nullptr; + if (!g_Instance) + g_Instance.set(new ClipboardManager()); + g_Instance->acquire(); + return static_cast<cppu::OWeakObject*>(g_Instance.get()); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/dtrans/source/generic/clipboardmanager.hxx b/dtrans/source/generic/clipboardmanager.hxx index e3217f6bf6bb..2750b61246cb 100644 --- a/dtrans/source/generic/clipboardmanager.hxx +++ b/dtrans/source/generic/clipboardmanager.hxx @@ -28,8 +28,6 @@ #include <map> -#define CLIPBOARDMANAGER_IMPLEMENTATION_NAME "com.sun.star.comp.datatransfer.ClipboardManager" - typedef std::map< OUString, css::uno::Reference< css::datatransfer::clipboard::XClipboard > > ClipboardMap; namespace dtrans @@ -90,10 +88,6 @@ namespace dtrans } -css::uno::Sequence< OUString > ClipboardManager_getSupportedServiceNames(); -css::uno::Reference< css::uno::XInterface > ClipboardManager_createInstance( - const css::uno::Reference< css::lang::XMultiServiceFactory > & xMultiServiceFactory); - #endif /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/dtrans/source/generic/dtrans.component b/dtrans/source/generic/dtrans.component index 915e3f0bcf8f..1bfb643be4d0 100644 --- a/dtrans/source/generic/dtrans.component +++ b/dtrans/source/generic/dtrans.component @@ -18,11 +18,13 @@ --> <component loader="com.sun.star.loader.SharedLibrary" environment="@CPPU_ENV@" - prefix="dtrans" xmlns="http://openoffice.org/2010/uno-components"> - <implementation name="com.sun.star.comp.datatransfer.ClipboardManager"> + xmlns="http://openoffice.org/2010/uno-components"> + <implementation name="com.sun.star.comp.datatransfer.ClipboardManager" + constructor="dtrans_ClipboardManager_get_implementation"> <service name="com.sun.star.datatransfer.clipboard.ClipboardManager"/> </implementation> - <implementation name="com.sun.star.comp.datatransfer.clipboard.GenericClipboard"> + <implementation name="com.sun.star.comp.datatransfer.clipboard.GenericClipboard" + constructor="dtrans_GenericClipboard_get_implementation"> <service name="com.sun.star.datatransfer.clipboard.GenericClipboard"/> </implementation> </component> diff --git a/dtrans/source/generic/dtrans.cxx b/dtrans/source/generic/dtrans.cxx deleted file mode 100644 index 0630b9a6f538..000000000000 --- a/dtrans/source/generic/dtrans.cxx +++ /dev/null @@ -1,74 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ - -#include <cppuhelper/factory.hxx> -#include <com/sun/star/lang/XSingleServiceFactory.hpp> -#include "clipboardmanager.hxx" -#include "generic_clipboard.hxx" - -using namespace com::sun::star::lang; -using namespace com::sun::star::registry; -using namespace com::sun::star::uno; -using namespace cppu; - -extern "C" -{ - -SAL_DLLPUBLIC_EXPORT void * dtrans_component_getFactory( - const char * pImplName, - void * pServiceManager, - void * /*pRegistryKey*/ -) -{ - void * pRet = nullptr; - - if (pServiceManager) - { - Reference< XSingleServiceFactory > xFactory; - - if (rtl_str_compare( pImplName, CLIPBOARDMANAGER_IMPLEMENTATION_NAME ) == 0) - { - xFactory = createOneInstanceFactory( - static_cast< XMultiServiceFactory * >( pServiceManager ), - OUString::createFromAscii( pImplName ), - ClipboardManager_createInstance, - ClipboardManager_getSupportedServiceNames() ); - } - else if (rtl_str_compare( pImplName, GENERIC_CLIPBOARD_IMPLEMENTATION_NAME ) == 0) - { - xFactory = createSingleFactory( - static_cast< XMultiServiceFactory * >( pServiceManager ), - OUString::createFromAscii( pImplName ), - GenericClipboard_createInstance, - GenericClipboard_getSupportedServiceNames() ); - } - - if (xFactory.is()) - { - xFactory->acquire(); - pRet = xFactory.get(); - } - } - - return pRet; -} - -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/dtrans/source/generic/generic_clipboard.cxx b/dtrans/source/generic/generic_clipboard.cxx index 4f358db37336..0394353601c8 100644 --- a/dtrans/source/generic/generic_clipboard.cxx +++ b/dtrans/source/generic/generic_clipboard.cxx @@ -20,6 +20,7 @@ #include "generic_clipboard.hxx" #include <com/sun/star/lang/DisposedException.hpp> #include <com/sun/star/datatransfer/clipboard/RenderingCapabilities.hpp> +#include <com/sun/star/uno/XComponentContext.hpp> #include <cppuhelper/supportsservice.hxx> using namespace com::sun::star::datatransfer; @@ -56,7 +57,7 @@ void SAL_CALL GenericClipboard::initialize( const Sequence< Any >& aArguments ) OUString SAL_CALL GenericClipboard::getImplementationName( ) { - return GENERIC_CLIPBOARD_IMPLEMENTATION_NAME; + return "com.sun.star.comp.datatransfer.clipboard.GenericClipboard"; } sal_Bool SAL_CALL GenericClipboard::supportsService( const OUString& ServiceName ) @@ -66,7 +67,7 @@ sal_Bool SAL_CALL GenericClipboard::supportsService( const OUString& ServiceName Sequence< OUString > SAL_CALL GenericClipboard::getSupportedServiceNames( ) { - return GenericClipboard_getSupportedServiceNames(); + return { "com.sun.star.datatransfer.clipboard.GenericClipboard" }; } Reference< XTransferable > SAL_CALL GenericClipboard::getContents() @@ -137,16 +138,11 @@ void SAL_CALL GenericClipboard::removeClipboardListener( const Reference< XClipb rBHelper.aLC.removeInterface( cppu::UnoType<XClipboardListener>::get(), listener ); } -Sequence< OUString > GenericClipboard_getSupportedServiceNames() +extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface* +dtrans_GenericClipboard_get_implementation( + css::uno::XComponentContext* , css::uno::Sequence<css::uno::Any> const&) { - Sequence< OUString > aRet { "com.sun.star.datatransfer.clipboard.GenericClipboard" }; - return aRet; -} - -Reference< XInterface > GenericClipboard_createInstance( - const Reference< XMultiServiceFactory > & /*xMultiServiceFactory*/) -{ - return Reference < XInterface >(static_cast<OWeakObject *>(new GenericClipboard())); + return cppu::acquire(static_cast<cppu::OWeakObject*>(new GenericClipboard())); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/dtrans/source/generic/generic_clipboard.hxx b/dtrans/source/generic/generic_clipboard.hxx index 2b31d063229c..f23a0cc9a120 100644 --- a/dtrans/source/generic/generic_clipboard.hxx +++ b/dtrans/source/generic/generic_clipboard.hxx @@ -29,8 +29,6 @@ #include <com/sun/star/lang/XServiceInfo.hpp> #include <com/sun/star/lang/XInitialization.hpp> -#define GENERIC_CLIPBOARD_IMPLEMENTATION_NAME "com.sun.star.comp.datatransfer.clipboard.GenericClipboard" - namespace dtrans { @@ -101,10 +99,6 @@ namespace dtrans } -css::uno::Sequence< OUString > GenericClipboard_getSupportedServiceNames(); -css::uno::Reference< css::uno::XInterface > GenericClipboard_createInstance( - const css::uno::Reference< css::lang::XMultiServiceFactory > & xMultiServiceFactory); - #endif /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |