1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
12 #include <sal/config.h>
14 #include <comphelper/comphelperdllapi.h>
15 #include <comphelper/interfacecontainer4.hxx>
16 #include <comphelper/unoimplbase.hxx>
17 #include <cppuhelper/weak.hxx>
18 #include <cppuhelper/queryinterface.hxx>
19 #include <cppuhelper/implbase.hxx>
20 #include <com/sun/star/lang/XComponent.hpp>
21 #include <com/sun/star/lang/XTypeProvider.hpp>
28 (1) extracts code that doesn't need to be templated
29 (2) helps to handle the custom where we have conflicting interfaces
30 e.g. multiple UNO interfaces that extend css::lang::XComponent
32 class COMPHELPER_DLLPUBLIC WeakComponentImplHelperBase
: public virtual comphelper::UnoImplBase
,
33 public cppu::OWeakObject
,
34 public css::lang::XComponent
37 virtual ~WeakComponentImplHelperBase() override
;
39 // css::lang::XComponent
40 virtual void SAL_CALL
dispose() override
;
42 addEventListener(css::uno::Reference
<css::lang::XEventListener
> const& rxListener
) override
;
44 removeEventListener(css::uno::Reference
<css::lang::XEventListener
> const& rxListener
) override
;
46 virtual css::uno::Any SAL_CALL
queryInterface(css::uno::Type
const& rType
) override
;
49 Called by dispose for subclasses to do dispose() work.
50 The mutex is held when called, and subclasses can unlock() the guard if necessary.
52 virtual void disposing(std::unique_lock
<std::mutex
>&);
55 void throwIfDisposed(std::unique_lock
<std::mutex
>&)
58 throw css::lang::DisposedException(OUString(), static_cast<cppu::OWeakObject
*>(this));
60 comphelper::OInterfaceContainerHelper4
<css::lang::XEventListener
> maEventListeners
;
63 template <typename
... Ifc
>
64 class SAL_DLLPUBLIC_TEMPLATE WeakComponentImplHelper
: public WeakComponentImplHelperBase
,
65 public css::lang::XTypeProvider
,
69 virtual void SAL_CALL
acquire() noexcept override
{ OWeakObject::acquire(); }
71 virtual void SAL_CALL
release() noexcept override
{ OWeakObject::release(); }
73 // css::lang::XComponent
74 virtual void SAL_CALL
dispose() noexcept final override
76 WeakComponentImplHelperBase::dispose();
78 virtual void SAL_CALL
addEventListener(
79 css::uno::Reference
<css::lang::XEventListener
> const& rxListener
) final override
81 WeakComponentImplHelperBase::addEventListener(rxListener
);
83 virtual void SAL_CALL
removeEventListener(
84 css::uno::Reference
<css::lang::XEventListener
> const& rxListener
) final override
86 WeakComponentImplHelperBase::removeEventListener(rxListener
);
89 virtual css::uno::Any SAL_CALL
queryInterface(css::uno::Type
const& rType
) override
91 return WeakComponentImplHelper_query(rType
, class_data_get(), this);
94 // css::lang::XTypeProvider
95 virtual css::uno::Sequence
<css::uno::Type
> SAL_CALL
getTypes() override
97 static const css::uno::Sequence
<css::uno::Type
> aTypeList
{
98 cppu::UnoType
<css::uno::XWeak
>::get(), cppu::UnoType
<css::lang::XComponent
>::get(),
99 cppu::UnoType
<css::lang::XTypeProvider
>::get(), cppu::UnoType
<Ifc
>::get()...
103 virtual css::uno::Sequence
<sal_Int8
> SAL_CALL
getImplementationId() override
105 return css::uno::Sequence
<sal_Int8
>();
109 static cppu::class_data
* class_data_get()
111 return cppu::detail::ImplClassData
<WeakComponentImplHelper
, Ifc
...>{}();
115 /** WeakComponentImplHelper
117 COMPHELPER_DLLPUBLIC
css::uno::Any
118 WeakComponentImplHelper_query(css::uno::Type
const& rType
, cppu::class_data
* cd
,
119 WeakComponentImplHelperBase
* pBase
);
121 } // namespace comphelper
123 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */