1*9877b273SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*9877b273SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*9877b273SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*9877b273SAndrew Rist * distributed with this work for additional information 6*9877b273SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*9877b273SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*9877b273SAndrew Rist * "License"); you may not use this file except in compliance 9*9877b273SAndrew Rist * with the License. You may obtain a copy of the License at 10*9877b273SAndrew Rist * 11*9877b273SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*9877b273SAndrew Rist * 13*9877b273SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*9877b273SAndrew Rist * software distributed under the License is distributed on an 15*9877b273SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*9877b273SAndrew Rist * KIND, either express or implied. See the License for the 17*9877b273SAndrew Rist * specific language governing permissions and limitations 18*9877b273SAndrew Rist * under the License. 19*9877b273SAndrew Rist * 20*9877b273SAndrew Rist *************************************************************/ 21*9877b273SAndrew Rist 22*9877b273SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir #ifndef COMPHELPER_PROXY_AGGREGATION 25cdf0e10cSrcweir #define COMPHELPER_PROXY_AGGREGATION 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include <com/sun/star/uno/XAggregation.hpp> 28cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp> 29cdf0e10cSrcweir #include <com/sun/star/lang/XComponent.hpp> 30cdf0e10cSrcweir #include <cppuhelper/implbase1.hxx> 31cdf0e10cSrcweir #include <cppuhelper/interfacecontainer.hxx> 32cdf0e10cSrcweir #include <comphelper/uno3.hxx> 33cdf0e10cSrcweir #include <comphelper/broadcasthelper.hxx> 34cdf0e10cSrcweir #include <cppuhelper/compbase_ex.hxx> 35cdf0e10cSrcweir #include "comphelper/comphelperdllapi.h" 36cdf0e10cSrcweir 37cdf0e10cSrcweir /* class hierarchy herein: 38cdf0e10cSrcweir 39cdf0e10cSrcweir +-------------------+ helper class for aggregating the proxy to another object 40cdf0e10cSrcweir | OProxyAggregation | - not ref counted 41cdf0e10cSrcweir +-------------------+ - no UNO implementation, i.e. not derived from XInterface 42cdf0e10cSrcweir ^ (neither direct nor indirect) 43cdf0e10cSrcweir | 44cdf0e10cSrcweir | 45cdf0e10cSrcweir +----------------------------------+ helper class for aggregating a proxy to an XComponent 46cdf0e10cSrcweir | OComponentProxyAggregationHelper | - life time coupling: if the inner component (the "aggregate") 47cdf0e10cSrcweir +----------------------------------+ is disposed, the outer (the delegator) is disposed, too, and 48cdf0e10cSrcweir ^ vice versa 49cdf0e10cSrcweir | - UNO based, implementing XEventListener 50cdf0e10cSrcweir | 51cdf0e10cSrcweir +----------------------------+ component aggregating another XComponent 52cdf0e10cSrcweir | OComponentProxyAggregation | - life time coupling as above 53cdf0e10cSrcweir +----------------------------+ - ref-counted 54cdf0e10cSrcweir - implements an XComponent itself 55cdf0e10cSrcweir 56cdf0e10cSrcweir If you need to 57cdf0e10cSrcweir 58cdf0e10cSrcweir - wrap a foreign object which is a XComponent 59cdf0e10cSrcweir => use OComponentProxyAggregation 60cdf0e10cSrcweir - call componentAggregateProxyFor in your ctor 61cdf0e10cSrcweir - call implEnsureDisposeInDtor in your dtor 62cdf0e10cSrcweir 63cdf0e10cSrcweir - wrap a foreign object which is a XComponent, but already have ref-counting mechanisms 64cdf0e10cSrcweir inherited from somewhere else 65cdf0e10cSrcweir => use OComponentProxyAggregationHelper 66cdf0e10cSrcweir - override dispose - don't forget to call the base class' dispose! 67cdf0e10cSrcweir - call componentAggregateProxyFor in your ctor 68cdf0e10cSrcweir 69cdf0e10cSrcweir - wrap a foreign object which is no XComponent 70cdf0e10cSrcweir => use OProxyAggregation 71cdf0e10cSrcweir - call baseAggregateProxyFor in your ctor 72cdf0e10cSrcweir */ 73cdf0e10cSrcweir 74cdf0e10cSrcweir //............................................................................. 75cdf0e10cSrcweir namespace comphelper 76cdf0e10cSrcweir { 77cdf0e10cSrcweir //............................................................................. 78cdf0e10cSrcweir 79cdf0e10cSrcweir //========================================================================= 80cdf0e10cSrcweir //= OProxyAggregation 81cdf0e10cSrcweir //========================================================================= 82cdf0e10cSrcweir /** helper class for aggregating a proxy for a foreign object 83cdf0e10cSrcweir */ 84cdf0e10cSrcweir class OProxyAggregation 85cdf0e10cSrcweir { 86cdf0e10cSrcweir private: 87cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::uno::XAggregation > m_xProxyAggregate; 88cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::lang::XTypeProvider > m_xProxyTypeAccess; 89cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory > m_xORB; 90cdf0e10cSrcweir 91cdf0e10cSrcweir protected: getORB()92cdf0e10cSrcweir inline const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& getORB() 93cdf0e10cSrcweir { 94cdf0e10cSrcweir return m_xORB; 95cdf0e10cSrcweir } 96cdf0e10cSrcweir 97cdf0e10cSrcweir protected: 98cdf0e10cSrcweir OProxyAggregation( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxORB ); 99cdf0e10cSrcweir ~OProxyAggregation(); 100cdf0e10cSrcweir 101cdf0e10cSrcweir /// to be called from within your ctor 102cdf0e10cSrcweir void baseAggregateProxyFor( 103cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _rxComponent, 104cdf0e10cSrcweir oslInterlockedCount& _rRefCount, 105cdf0e10cSrcweir ::cppu::OWeakObject& _rDelegator 106cdf0e10cSrcweir ); 107cdf0e10cSrcweir 108cdf0e10cSrcweir // XInterface and XTypeProvider 109cdf0e10cSrcweir ::com::sun::star::uno::Any SAL_CALL queryAggregation( const ::com::sun::star::uno::Type& _rType ) throw (::com::sun::star::uno::RuntimeException); 110cdf0e10cSrcweir ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL getTypes( ) throw (::com::sun::star::uno::RuntimeException); 111cdf0e10cSrcweir 112cdf0e10cSrcweir private: 113cdf0e10cSrcweir OProxyAggregation( ); // never implemented 114cdf0e10cSrcweir OProxyAggregation( const OProxyAggregation& ); // never implemented 115cdf0e10cSrcweir OProxyAggregation& operator=( const OProxyAggregation& ); // never implemented 116cdf0e10cSrcweir }; 117cdf0e10cSrcweir 118cdf0e10cSrcweir //========================================================================= 119cdf0e10cSrcweir //= OComponentProxyAggregationHelper 120cdf0e10cSrcweir //========================================================================= 121cdf0e10cSrcweir /** a helper class for aggregating a proxy to an XComponent 122cdf0e10cSrcweir 123cdf0e10cSrcweir <p>The object couples the life time of itself and the component: if one of the both 124cdf0e10cSrcweir dies (in a sense of being disposed), the other one dies, too.</p> 125cdf0e10cSrcweir 126cdf0e10cSrcweir <p>The class itself does not implement XComponent so you need to forward any XComponent::dispose 127cdf0e10cSrcweir calls which your derived class gets to the dispose method of this class.</p> 128cdf0e10cSrcweir */ 129cdf0e10cSrcweir 130cdf0e10cSrcweir class COMPHELPER_DLLPUBLIC OComponentProxyAggregationHelper :public ::cppu::ImplHelper1 < com::sun::star::lang::XEventListener 131cdf0e10cSrcweir > 132cdf0e10cSrcweir ,private OProxyAggregation 133cdf0e10cSrcweir { 134cdf0e10cSrcweir private: 135cdf0e10cSrcweir typedef ::cppu::ImplHelper1 < ::com::sun::star::lang::XEventListener 136cdf0e10cSrcweir > BASE; // prevents some MSVC problems 137cdf0e10cSrcweir 138cdf0e10cSrcweir protected: 139cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent > 140cdf0e10cSrcweir m_xInner; 141cdf0e10cSrcweir ::cppu::OBroadcastHelper& m_rBHelper; 142cdf0e10cSrcweir 143cdf0e10cSrcweir protected: 144cdf0e10cSrcweir // OProxyAggregation 145cdf0e10cSrcweir using OProxyAggregation::getORB; 146cdf0e10cSrcweir 147cdf0e10cSrcweir // XInterface 148cdf0e10cSrcweir ::com::sun::star::uno::Any SAL_CALL queryInterface( const ::com::sun::star::uno::Type& _rType ) throw (::com::sun::star::uno::RuntimeException); 149cdf0e10cSrcweir 150cdf0e10cSrcweir // XTypeProvider 151cdf0e10cSrcweir DECLARE_XTYPEPROVIDER( ) 152cdf0e10cSrcweir 153cdf0e10cSrcweir protected: 154cdf0e10cSrcweir OComponentProxyAggregationHelper( 155cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxORB, 156cdf0e10cSrcweir ::cppu::OBroadcastHelper& _rBHelper 157cdf0e10cSrcweir ); 158cdf0e10cSrcweir virtual ~OComponentProxyAggregationHelper( ); 159cdf0e10cSrcweir 160cdf0e10cSrcweir /// to be called from within your ctor 161cdf0e10cSrcweir void componentAggregateProxyFor( 162cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent >& _rxComponent, 163cdf0e10cSrcweir oslInterlockedCount& _rRefCount, 164cdf0e10cSrcweir ::cppu::OWeakObject& _rDelegator 165cdf0e10cSrcweir ); 166cdf0e10cSrcweir 167cdf0e10cSrcweir // XEventListener 168cdf0e10cSrcweir virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw (::com::sun::star::uno::RuntimeException); 169cdf0e10cSrcweir 170cdf0e10cSrcweir // XComponent 171cdf0e10cSrcweir virtual void SAL_CALL dispose() throw( ::com::sun::star::uno::RuntimeException ); 172cdf0e10cSrcweir 173cdf0e10cSrcweir private: 174cdf0e10cSrcweir COMPHELPER_DLLPRIVATE OComponentProxyAggregationHelper( ); // never implemented 175cdf0e10cSrcweir COMPHELPER_DLLPRIVATE OComponentProxyAggregationHelper( const OComponentProxyAggregationHelper& ); // never implemented 176cdf0e10cSrcweir COMPHELPER_DLLPRIVATE OComponentProxyAggregationHelper& operator=( const OComponentProxyAggregationHelper& ); // never implemented 177cdf0e10cSrcweir }; 178cdf0e10cSrcweir 179cdf0e10cSrcweir //========================================================================= 180cdf0e10cSrcweir //= OComponentProxyAggregation 181cdf0e10cSrcweir //========================================================================= 182cdf0e10cSrcweir typedef ::cppu::WeakComponentImplHelperBase OComponentProxyAggregation_CBase; 183cdf0e10cSrcweir 184cdf0e10cSrcweir class COMPHELPER_DLLPUBLIC OComponentProxyAggregation :public OBaseMutex 185cdf0e10cSrcweir ,public OComponentProxyAggregation_CBase 186cdf0e10cSrcweir ,public OComponentProxyAggregationHelper 187cdf0e10cSrcweir { 188cdf0e10cSrcweir protected: 189cdf0e10cSrcweir OComponentProxyAggregation( 190cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _rxORB, 191cdf0e10cSrcweir const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent >& _rxComponent 192cdf0e10cSrcweir ); 193cdf0e10cSrcweir 194cdf0e10cSrcweir virtual ~OComponentProxyAggregation(); 195cdf0e10cSrcweir 196cdf0e10cSrcweir // XInterface 197cdf0e10cSrcweir DECLARE_XINTERFACE() 198cdf0e10cSrcweir // XTypeProvider 199cdf0e10cSrcweir DECLARE_XTYPEPROVIDER() 200cdf0e10cSrcweir 201cdf0e10cSrcweir // OComponentHelper 202cdf0e10cSrcweir virtual void SAL_CALL disposing() throw (::com::sun::star::uno::RuntimeException); 203cdf0e10cSrcweir 204cdf0e10cSrcweir // XEventListener 205cdf0e10cSrcweir virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& _rSource ) throw (::com::sun::star::uno::RuntimeException); 206cdf0e10cSrcweir 207cdf0e10cSrcweir // XComponent/OComponentProxyAggregationHelper 208cdf0e10cSrcweir virtual void SAL_CALL dispose() throw( ::com::sun::star::uno::RuntimeException ); 209cdf0e10cSrcweir 210cdf0e10cSrcweir protected: 211cdf0e10cSrcweir // be called from within the dtor of derived classes 212cdf0e10cSrcweir void implEnsureDisposeInDtor( ); 213cdf0e10cSrcweir 214cdf0e10cSrcweir private: 215cdf0e10cSrcweir COMPHELPER_DLLPRIVATE OComponentProxyAggregation( ); // never implemented 216cdf0e10cSrcweir COMPHELPER_DLLPRIVATE OComponentProxyAggregation( const OComponentProxyAggregation& ); // never implemented 217cdf0e10cSrcweir COMPHELPER_DLLPRIVATE OComponentProxyAggregation& operator=( const OComponentProxyAggregation& ); // never implemented 218cdf0e10cSrcweir }; 219cdf0e10cSrcweir 220cdf0e10cSrcweir //............................................................................. 221cdf0e10cSrcweir } // namespace comphelper 222cdf0e10cSrcweir //............................................................................. 223cdf0e10cSrcweir 224cdf0e10cSrcweir 225cdf0e10cSrcweir #endif // COMPHELPER_PROXY_AGGREGATION 226