fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / include / comphelper / proxyaggregation.hxx
blob2c01a7a3587f6cd273e07fd13c40f0f9c12d49ea
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 COMPHELPER_PROXY_AGGREGATION
21 #define COMPHELPER_PROXY_AGGREGATION
23 #include <com/sun/star/uno/XAggregation.hpp>
24 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
25 #include <com/sun/star/lang/XComponent.hpp>
26 #include <cppuhelper/implbase1.hxx>
27 #include <cppuhelper/interfacecontainer.hxx>
28 #include <comphelper/uno3.hxx>
29 #include <comphelper/broadcasthelper.hxx>
30 #include <cppuhelper/compbase_ex.hxx>
31 #include "comphelper/comphelperdllapi.h"
33 /* class hierarchy herein:
35 +-------------------+ helper class for aggregating the proxy to another object
36 | OProxyAggregation | - not ref counted
37 +-------------------+ - no UNO implementation, i.e. not derived from XInterface
38 ^ (neither direct nor indirect)
41 +----------------------------------+ helper class for aggregating a proxy to an XComponent
42 | OComponentProxyAggregationHelper | - life time coupling: if the inner component (the "aggregate")
43 +----------------------------------+ is disposed, the outer (the delegator) is disposed, too, and
44 ^ vice versa
45 | - UNO based, implementing XEventListener
47 +----------------------------+ component aggregating another XComponent
48 | OComponentProxyAggregation | - life time coupling as above
49 +----------------------------+ - ref-counted
50 - implements an XComponent itself
52 If you need to
54 - wrap a foreign object which is a XComponent
55 => use OComponentProxyAggregation
56 - call componentAggregateProxyFor in your ctor
57 - call implEnsureDisposeInDtor in your dtor
59 - wrap a foreign object which is a XComponent, but already have ref-counting mechanisms
60 inherited from somewhere else
61 => use OComponentProxyAggregationHelper
62 - override dispose - don't forget to call the base class' dispose!
63 - call componentAggregateProxyFor in your ctor
65 - wrap a foreign object which is no XComponent
66 => use OProxyAggregation
67 - call baseAggregateProxyFor in your ctor
70 //.............................................................................
71 namespace comphelper
73 //.............................................................................
75 //=========================================================================
76 //= OProxyAggregation
77 //=========================================================================
78 /** helper class for aggregating a proxy for a foreign object
80 class OProxyAggregation
82 private:
83 ::com::sun::star::uno::Reference< ::com::sun::star::uno::XAggregation > m_xProxyAggregate;
84 ::com::sun::star::uno::Reference< ::com::sun::star::lang::XTypeProvider > m_xProxyTypeAccess;
85 ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext > m_xContext;
87 protected:
88 inline const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& getComponentContext()
90 return m_xContext;
93 protected:
94 OProxyAggregation( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& _rxContext );
95 ~OProxyAggregation();
97 /// to be called from within your ctor
98 void baseAggregateProxyFor(
99 const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _rxComponent,
100 oslInterlockedCount& _rRefCount,
101 ::cppu::OWeakObject& _rDelegator
104 // XInterface and XTypeProvider
105 ::com::sun::star::uno::Any SAL_CALL queryAggregation( const ::com::sun::star::uno::Type& _rType ) throw (::com::sun::star::uno::RuntimeException);
106 ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL getTypes( ) throw (::com::sun::star::uno::RuntimeException);
108 private:
109 OProxyAggregation( ); // never implemented
110 OProxyAggregation( const OProxyAggregation& ); // never implemented
111 OProxyAggregation& operator=( const OProxyAggregation& ); // never implemented
114 //=========================================================================
115 //= OComponentProxyAggregationHelper
116 //=========================================================================
117 /** a helper class for aggregating a proxy to an XComponent
119 <p>The object couples the life time of itself and the component: if one of the both
120 dies (in a sense of being disposed), the other one dies, too.</p>
122 <p>The class itself does not implement XComponent so you need to forward any XComponent::dispose
123 calls which your derived class gets to the dispose method of this class.</p>
126 class COMPHELPER_DLLPUBLIC OComponentProxyAggregationHelper :public ::cppu::ImplHelper1 < com::sun::star::lang::XEventListener
128 ,private OProxyAggregation
130 private:
131 typedef ::cppu::ImplHelper1 < ::com::sun::star::lang::XEventListener
132 > BASE; // prevents some MSVC problems
134 protected:
135 ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent >
136 m_xInner;
137 ::cppu::OBroadcastHelper& m_rBHelper;
139 protected:
140 // OProxyAggregation
141 using OProxyAggregation::getComponentContext;
143 // XInterface
144 ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type& _rType ) throw (::com::sun::star::uno::RuntimeException);
146 // XTypeProvider
147 DECLARE_XTYPEPROVIDER( )
149 protected:
150 OComponentProxyAggregationHelper(
151 const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& _rxContext,
152 ::cppu::OBroadcastHelper& _rBHelper
154 virtual ~OComponentProxyAggregationHelper( );
156 /// to be called from within your ctor
157 void componentAggregateProxyFor(
158 const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent >& _rxComponent,
159 oslInterlockedCount& _rRefCount,
160 ::cppu::OWeakObject& _rDelegator
163 // XEventListener
164 virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw (::com::sun::star::uno::RuntimeException);
166 // XComponent
167 virtual void SAL_CALL dispose() throw( ::com::sun::star::uno::RuntimeException );
169 private:
170 COMPHELPER_DLLPRIVATE OComponentProxyAggregationHelper( ); // never implemented
171 COMPHELPER_DLLPRIVATE OComponentProxyAggregationHelper( const OComponentProxyAggregationHelper& ); // never implemented
172 COMPHELPER_DLLPRIVATE OComponentProxyAggregationHelper& operator=( const OComponentProxyAggregationHelper& ); // never implemented
175 //=========================================================================
176 //= OComponentProxyAggregation
177 //=========================================================================
178 class COMPHELPER_DLLPUBLIC OComponentProxyAggregation :public OBaseMutex
179 ,public cppu::WeakComponentImplHelperBase
180 ,public OComponentProxyAggregationHelper
182 protected:
183 OComponentProxyAggregation(
184 const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& _rxContext,
185 const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent >& _rxComponent
188 virtual ~OComponentProxyAggregation();
190 // XInterface
191 DECLARE_XINTERFACE()
192 // XTypeProvider
193 DECLARE_XTYPEPROVIDER()
195 // OComponentHelper
196 virtual void SAL_CALL disposing() throw (::com::sun::star::uno::RuntimeException);
198 // XEventListener
199 virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& _rSource ) throw (::com::sun::star::uno::RuntimeException);
201 // XComponent/OComponentProxyAggregationHelper
202 virtual void SAL_CALL dispose() throw( ::com::sun::star::uno::RuntimeException );
204 protected:
205 // be called from within the dtor of derived classes
206 void implEnsureDisposeInDtor( );
208 private:
209 COMPHELPER_DLLPRIVATE OComponentProxyAggregation( ); // never implemented
210 COMPHELPER_DLLPRIVATE OComponentProxyAggregation( const OComponentProxyAggregation& ); // never implemented
211 COMPHELPER_DLLPRIVATE OComponentProxyAggregation& operator=( const OComponentProxyAggregation& ); // never implemented
214 //.............................................................................
215 } // namespace comphelper
216 //.............................................................................
219 #endif // COMPHELPER_PROXY_AGGREGATION
221 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */