Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / include / comphelper / proxyaggregation.hxx
blob48444355ce23350c40e556c3317f34098ee87b4c
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_COMPHELPER_PROXYAGGREGATION_HXX
21 #define INCLUDED_COMPHELPER_PROXYAGGREGATION_HXX
23 #include <cppuhelper/implbase1.hxx>
24 #include <cppuhelper/interfacecontainer.h>
25 #include <cppuhelper/basemutex.hxx>
26 #include <comphelper/uno3.hxx>
27 #include <cppuhelper/compbase_ex.hxx>
28 #include <comphelper/comphelperdllapi.h>
30 namespace com::sun::star::uno {
31 class XComponentContext;
33 namespace com::sun::star::uno { class XAggregation; }
34 namespace com::sun::star::lang { class XComponent; }
36 /* class hierarchy herein:
38 +-------------------+ helper class for aggregating the proxy to another object
39 | OProxyAggregation | - not ref counted
40 +-------------------+ - no UNO implementation, i.e. not derived from XInterface
41 ^ (neither direct nor indirect)
44 +----------------------------------+ helper class for aggregating a proxy to an XComponent
45 | OComponentProxyAggregationHelper | - life time coupling: if the inner component (the "aggregate")
46 +----------------------------------+ is disposed, the outer (the delegator) is disposed, too, and
47 ^ vice versa
48 | - UNO based, implementing XEventListener
50 +----------------------------+ component aggregating another XComponent
51 | OComponentProxyAggregation | - life time coupling as above
52 +----------------------------+ - ref-counted
53 - implements an XComponent itself
55 If you need to
57 - wrap a foreign object which is a XComponent
58 => use OComponentProxyAggregation
59 - call componentAggregateProxyFor in your ctor
60 - call implEnsureDisposeInDtor in your dtor
62 - wrap a foreign object which is a XComponent, but already have ref-counting mechanisms
63 inherited from somewhere else
64 => use OComponentProxyAggregationHelper
65 - override dispose - don't forget to call the base class' dispose!
66 - call componentAggregateProxyFor in your ctor
68 - wrap a foreign object which is no XComponent
69 => use OProxyAggregation
70 - call baseAggregateProxyFor in your ctor
74 namespace comphelper
78 //= OProxyAggregation
80 /** helper class for aggregating a proxy for a foreign object
82 class OProxyAggregation
84 private:
85 css::uno::Reference< css::uno::XAggregation > m_xProxyAggregate;
86 css::uno::Reference< css::lang::XTypeProvider > m_xProxyTypeAccess;
87 css::uno::Reference< css::uno::XComponentContext > m_xContext;
89 protected:
90 const css::uno::Reference< css::uno::XComponentContext >& getComponentContext() const
92 return m_xContext;
95 protected:
96 OProxyAggregation( const css::uno::Reference< css::uno::XComponentContext >& _rxContext );
97 ~OProxyAggregation();
99 /// to be called from within your ctor
100 void baseAggregateProxyFor(
101 const css::uno::Reference< css::uno::XInterface >& _rxComponent,
102 oslInterlockedCount& _rRefCount,
103 ::cppu::OWeakObject& _rDelegator
106 // XInterface and XTypeProvider
107 /// @throws css::uno::RuntimeException
108 css::uno::Any SAL_CALL queryAggregation( const css::uno::Type& _rType );
109 /// @throws css::uno::RuntimeException
110 css::uno::Sequence< css::uno::Type > SAL_CALL getTypes( );
112 private:
113 OProxyAggregation( const OProxyAggregation& ) = delete;
114 OProxyAggregation& operator=( const OProxyAggregation& ) = delete;
118 //= OComponentProxyAggregationHelper
120 /** a helper class for aggregating a proxy to an XComponent
122 <p>The object couples the life time of itself and the component: if one of the both
123 dies (in a sense of being disposed), the other one dies, too.</p>
125 <p>The class itself does not implement XComponent so you need to forward any XComponent::dispose
126 calls which your derived class gets to the dispose method of this class.</p>
129 class OComponentProxyAggregationHelper :public ::cppu::ImplHelper1 < css::lang::XEventListener
131 ,private OProxyAggregation
133 private:
134 typedef ::cppu::ImplHelper1 < css::lang::XEventListener
135 > BASE; // prevents some MSVC problems
137 protected:
138 css::uno::Reference< css::lang::XComponent >
139 m_xInner;
140 ::cppu::OBroadcastHelper& m_rBHelper;
142 protected:
143 // OProxyAggregation
144 using OProxyAggregation::getComponentContext;
146 // XInterface
147 css::uno::Any SAL_CALL queryInterface( const css::uno::Type& _rType ) override;
149 // XTypeProvider
150 DECLARE_XTYPEPROVIDER( )
152 protected:
153 OComponentProxyAggregationHelper(
154 const css::uno::Reference< css::uno::XComponentContext >& _rxContext,
155 ::cppu::OBroadcastHelper& _rBHelper
157 virtual ~OComponentProxyAggregationHelper( );
159 /// to be called from within your ctor
160 void componentAggregateProxyFor(
161 const css::uno::Reference< css::lang::XComponent >& _rxComponent,
162 oslInterlockedCount& _rRefCount,
163 ::cppu::OWeakObject& _rDelegator
166 // XEventListener
167 virtual void SAL_CALL disposing( const css::lang::EventObject& Source ) override;
169 // XComponent
170 /// @throws css::uno::RuntimeException
171 virtual void SAL_CALL dispose() = 0;
173 private:
174 OComponentProxyAggregationHelper( const OComponentProxyAggregationHelper& ) = delete;
175 OComponentProxyAggregationHelper& operator=( const OComponentProxyAggregationHelper& ) = delete;
179 //= OComponentProxyAggregation
181 class COMPHELPER_DLLPUBLIC OComponentProxyAggregation : public cppu::BaseMutex
182 ,public cppu::WeakComponentImplHelperBase
183 ,public OComponentProxyAggregationHelper
185 protected:
186 OComponentProxyAggregation(
187 const css::uno::Reference< css::uno::XComponentContext >& _rxContext,
188 const css::uno::Reference< css::lang::XComponent >& _rxComponent
191 virtual ~OComponentProxyAggregation() override;
193 // XInterface
194 DECLARE_XINTERFACE()
195 // XTypeProvider
196 DECLARE_XTYPEPROVIDER()
198 // OComponentHelper
199 virtual void SAL_CALL disposing() override;
201 // XEventListener
202 virtual void SAL_CALL disposing( const css::lang::EventObject& _rSource ) override;
204 // XComponent/OComponentProxyAggregationHelper
205 virtual void SAL_CALL dispose() override;
207 private:
208 OComponentProxyAggregation( const OComponentProxyAggregation& ) = delete;
209 OComponentProxyAggregation& operator=( const OComponentProxyAggregation& ) = delete;
213 } // namespace comphelper
216 #endif // INCLUDED_COMPHELPER_PROXYAGGREGATION_HXX
218 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */