1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  *   Licensed to the Apache Software Foundation (ASF) under one or more
12  *   contributor license agreements. See the NOTICE file distributed
13  *   with this work for additional information regarding copyright
14  *   ownership. The ASF licenses this file to you under the Apache
15  *   License, Version 2.0 (the "License"); you may not use this file
16  *   except in compliance with the License. You may obtain a copy of
17  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 
20 #ifndef INCLUDED_CPPUHELPER_COMPBASE_HXX
21 #define INCLUDED_CPPUHELPER_COMPBASE_HXX
22 
23 #include "sal/config.h"
24 
25 #include "com/sun/star/lang/XTypeProvider.hpp"
26 #include "com/sun/star/uno/Any.h"
27 #include "com/sun/star/uno/Reference.h"
28 #include "com/sun/star/uno/Sequence.h"
29 #include "com/sun/star/uno/Type.h"
30 #include "cppuhelper/compbase_ex.hxx"
31 #include "cppuhelper/implbase.hxx"
32 #include "rtl/instance.hxx"
33 #include "sal/types.h"
34 
35 namespace com { namespace sun { namespace star { namespace lang {
36     class XEventListener;
37 } } } }
38 namespace osl { class Mutex; }
39 
40 #if defined LIBO_INTERNAL_ONLY
41 
42 // A replacement for WeakAggComponentImplHelper1 has deliberately been left out,
43 // as the underlying aggregation mechanism is known broken in general and should
44 // not be used.
45 
46 namespace cppu {
47 
48 /** Implementation helper implementing interfaces
49     css::uno::XInterface, css::lang::XTypeProvider, and
50     css::lang::XComponent.
51 
52     Like WeakComponentImplHelper, but does not define
53     XComponent::add/removeEventListener.  Use for classes deriving from multiple
54     UNO interfaces with competing add/removeEventListener methods, to avoid
55     warnings about hiding of overloaded virtual functions.
56 
57     Upon disposing objects of this class, sub-classes receive a disposing()
58     call.
59 
60     @attention
61     The mutex reference passed to the constructor has to outlive the constructed
62     instance.
63 */
64 template<typename... Ifc>
65 class SAL_NO_VTABLE SAL_DLLPUBLIC_TEMPLATE PartialWeakComponentImplHelper:
66     public WeakComponentImplHelperBase, public css::lang::XTypeProvider,
67     public Ifc...
68 {
69     struct cd:
70         rtl::StaticAggregate<
71             class_data,
72             detail::ImplClassData<PartialWeakComponentImplHelper, Ifc...>>
73     {};
74 
75 public:
PartialWeakComponentImplHelper(osl::Mutex & mutex)76     PartialWeakComponentImplHelper(osl::Mutex & mutex) throw ():
77         WeakComponentImplHelperBase(mutex) {}
78 
queryInterface(css::uno::Type const & aType)79     css::uno::Any SAL_CALL queryInterface(css::uno::Type const & aType) SAL_OVERRIDE
80     { return WeakComponentImplHelper_query(aType, cd::get(), this, this); }
81 
acquire()82     void SAL_CALL acquire() throw () SAL_OVERRIDE
83     { WeakComponentImplHelperBase::acquire(); }
84 
release()85     void SAL_CALL release() throw () SAL_OVERRIDE
86     { WeakComponentImplHelperBase::release(); }
87 
dispose()88     void SAL_CALL dispose()
89         SAL_OVERRIDE
90     { WeakComponentImplHelperBase::dispose(); }
91 
getTypes()92     css::uno::Sequence<css::uno::Type> SAL_CALL getTypes() SAL_OVERRIDE
93     { return WeakComponentImplHelper_getTypes(cd::get()); }
94 
getImplementationId()95     css::uno::Sequence<sal_Int8> SAL_CALL getImplementationId() SAL_OVERRIDE
96     { return css::uno::Sequence<sal_Int8>(); }
97 };
98 
99 /** Implementation helper implementing interfaces
100     css::uno::XInterface, css::lang::XTypeProvider, and
101     css::lang::XComponent.
102 
103     Upon disposing objects of this class, sub-classes receive a disposing()
104     call.
105 
106     @attention
107     The mutex reference passed to the constructor has to outlive the constructed
108     instance.
109 */
110 template<typename... Ifc>
111 class SAL_NO_VTABLE SAL_DLLPUBLIC_TEMPLATE WeakComponentImplHelper:
112     public PartialWeakComponentImplHelper<Ifc...>
113 {
114 public:
WeakComponentImplHelper(osl::Mutex & mutex)115     WeakComponentImplHelper(osl::Mutex & mutex) throw ():
116         PartialWeakComponentImplHelper<Ifc...>(mutex) {}
117 
addEventListener(css::uno::Reference<css::lang::XEventListener> const & xListener)118     void SAL_CALL addEventListener(
119         css::uno::Reference<css::lang::XEventListener> const & xListener) SAL_OVERRIDE
120     { WeakComponentImplHelperBase::addEventListener(xListener); }
121 
removeEventListener(css::uno::Reference<css::lang::XEventListener> const & aListener)122     void SAL_CALL removeEventListener(
123         css::uno::Reference<css::lang::XEventListener> const & aListener) SAL_OVERRIDE
124     { WeakComponentImplHelperBase::removeEventListener(aListener); }
125 };
126 
127 }
128 
129 #endif
130 
131 #endif
132 
133 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
134