1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 <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 namespace com
{ namespace sun
{ namespace star
{ namespace uno
{
34 class XComponentContext
;
37 /* class hierarchy herein:
39 +-------------------+ helper class for aggregating the proxy to another object
40 | OProxyAggregation | - not ref counted
41 +-------------------+ - no UNO implementation, i.e. not derived from XInterface
42 ^ (neither direct nor indirect)
45 +----------------------------------+ helper class for aggregating a proxy to an XComponent
46 | OComponentProxyAggregationHelper | - life time coupling: if the inner component (the "aggregate")
47 +----------------------------------+ is disposed, the outer (the delegator) is disposed, too, and
49 | - UNO based, implementing XEventListener
51 +----------------------------+ component aggregating another XComponent
52 | OComponentProxyAggregation | - life time coupling as above
53 +----------------------------+ - ref-counted
54 - implements an XComponent itself
58 - wrap a foreign object which is a XComponent
59 => use OComponentProxyAggregation
60 - call componentAggregateProxyFor in your ctor
61 - call implEnsureDisposeInDtor in your dtor
63 - wrap a foreign object which is a XComponent, but already have ref-counting mechanisms
64 inherited from somewhere else
65 => use OComponentProxyAggregationHelper
66 - override dispose - don't forget to call the base class' dispose!
67 - call componentAggregateProxyFor in your ctor
69 - wrap a foreign object which is no XComponent
70 => use OProxyAggregation
71 - call baseAggregateProxyFor in your ctor
82 /** helper class for aggregating a proxy for a foreign object
84 class OProxyAggregation
87 ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XAggregation
> m_xProxyAggregate
;
88 ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XTypeProvider
> m_xProxyTypeAccess
;
89 ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
> m_xContext
;
92 inline const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
>& getComponentContext()
98 OProxyAggregation( const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
>& _rxContext
);
101 /// to be called from within your ctor
102 void baseAggregateProxyFor(
103 const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XInterface
>& _rxComponent
,
104 oslInterlockedCount
& _rRefCount
,
105 ::cppu::OWeakObject
& _rDelegator
108 // XInterface and XTypeProvider
109 ::com::sun::star::uno::Any SAL_CALL
queryAggregation( const ::com::sun::star::uno::Type
& _rType
) throw (::com::sun::star::uno::RuntimeException
);
110 ::com::sun::star::uno::Sequence
< ::com::sun::star::uno::Type
> SAL_CALL
getTypes( ) throw (::com::sun::star::uno::RuntimeException
);
113 OProxyAggregation( const OProxyAggregation
& ) SAL_DELETED_FUNCTION
;
114 OProxyAggregation
& operator=( const OProxyAggregation
& ) SAL_DELETED_FUNCTION
;
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 COMPHELPER_DLLPUBLIC OComponentProxyAggregationHelper
:public ::cppu::ImplHelper1
< com::sun::star::lang::XEventListener
131 ,private OProxyAggregation
134 typedef ::cppu::ImplHelper1
< ::com::sun::star::lang::XEventListener
135 > BASE
; // prevents some MSVC problems
138 ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XComponent
>
140 ::cppu::OBroadcastHelper
& m_rBHelper
;
144 using OProxyAggregation::getComponentContext
;
147 ::com::sun::star::uno::Any SAL_CALL
queryInterface( const ::com::sun::star::uno::Type
& _rType
) throw (::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
150 DECLARE_XTYPEPROVIDER( )
153 OComponentProxyAggregationHelper(
154 const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
>& _rxContext
,
155 ::cppu::OBroadcastHelper
& _rBHelper
157 virtual ~OComponentProxyAggregationHelper( );
159 /// to be called from within your ctor
160 void componentAggregateProxyFor(
161 const ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XComponent
>& _rxComponent
,
162 oslInterlockedCount
& _rRefCount
,
163 ::cppu::OWeakObject
& _rDelegator
167 virtual void SAL_CALL
disposing( const ::com::sun::star::lang::EventObject
& Source
) throw (::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
170 virtual void SAL_CALL
dispose() throw( ::com::sun::star::uno::RuntimeException
, std::exception
) = 0;
173 OComponentProxyAggregationHelper( const OComponentProxyAggregationHelper
& ) SAL_DELETED_FUNCTION
;
174 OComponentProxyAggregationHelper
& operator=( const OComponentProxyAggregationHelper
& ) SAL_DELETED_FUNCTION
;
178 //= OComponentProxyAggregation
180 class COMPHELPER_DLLPUBLIC OComponentProxyAggregation
:public OBaseMutex
181 ,public cppu::WeakComponentImplHelperBase
182 ,public OComponentProxyAggregationHelper
185 OComponentProxyAggregation(
186 const ::com::sun::star::uno::Reference
< ::com::sun::star::uno::XComponentContext
>& _rxContext
,
187 const ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XComponent
>& _rxComponent
190 virtual ~OComponentProxyAggregation();
195 DECLARE_XTYPEPROVIDER()
198 virtual void SAL_CALL
disposing() throw (::com::sun::star::uno::RuntimeException
) SAL_OVERRIDE
;
201 virtual void SAL_CALL
disposing( const ::com::sun::star::lang::EventObject
& _rSource
) throw (::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
203 // XComponent/OComponentProxyAggregationHelper
204 virtual void SAL_CALL
dispose() throw( ::com::sun::star::uno::RuntimeException
, std::exception
) SAL_OVERRIDE
;
207 // be called from within the dtor of derived classes
208 void implEnsureDisposeInDtor( );
211 OComponentProxyAggregation( const OComponentProxyAggregation
& ) SAL_DELETED_FUNCTION
;
212 OComponentProxyAggregation
& operator=( const OComponentProxyAggregation
& ) SAL_DELETED_FUNCTION
;
216 } // namespace comphelper
220 #endif // INCLUDED_COMPHELPER_PROXYAGGREGATION_HXX
222 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */