LCOV - code coverage report
Current view: top level - include/comphelper - proxyaggregation.hxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 2 2 100.0 %
Date: 2015-06-13 12:38:46 Functions: 1 1 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       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_COMPHELPER_PROXYAGGREGATION_HXX
      21             : #define INCLUDED_COMPHELPER_PROXYAGGREGATION_HXX
      22             : 
      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>
      32             : 
      33             : namespace com { namespace sun { namespace star { namespace uno {
      34             :     class XComponentContext;
      35             : } } } }
      36             : 
      37             : /* class hierarchy herein:
      38             : 
      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)
      43             :                    |
      44             :                    |
      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
      48             :                    ^                      vice versa
      49             :                    |                    - UNO based, implementing XEventListener
      50             :                    |
      51             :      +----------------------------+     component aggregating another XComponent
      52             :      | OComponentProxyAggregation |     - life time coupling as above
      53             :      +----------------------------+     - ref-counted
      54             :                                         - implements an XComponent itself
      55             : 
      56             :   If you need to
      57             : 
      58             :   - wrap a foreign object which is a XComponent
      59             :     => use OComponentProxyAggregation
      60             :        - call componentAggregateProxyFor in your ctor
      61             :        - call implEnsureDisposeInDtor in your dtor
      62             : 
      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
      68             : 
      69             :   - wrap a foreign object which is no XComponent
      70             :     => use OProxyAggregation
      71             :        - call baseAggregateProxyFor in your ctor
      72             : */
      73             : 
      74             : 
      75             : namespace comphelper
      76             : {
      77             : 
      78             : 
      79             : 
      80             :     //= OProxyAggregation
      81             : 
      82             :     /** helper class for aggregating a proxy for a foreign object
      83             :     */
      84             :     class OProxyAggregation
      85             :     {
      86             :     private:
      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;
      90             : 
      91             :     protected:
      92         288 :         inline const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& getComponentContext()
      93             :         {
      94         288 :             return m_xContext;
      95             :         }
      96             : 
      97             :     protected:
      98             :         OProxyAggregation( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& _rxContext );
      99             :         ~OProxyAggregation();
     100             : 
     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
     106             :         );
     107             : 
     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);
     111             : 
     112             :     private:
     113             :         OProxyAggregation( const OProxyAggregation& ) SAL_DELETED_FUNCTION;
     114             :         OProxyAggregation& operator=( const OProxyAggregation& ) SAL_DELETED_FUNCTION;
     115             :     };
     116             : 
     117             : 
     118             :     //= OComponentProxyAggregationHelper
     119             : 
     120             :     /** a helper class for aggregating a proxy to an XComponent
     121             : 
     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>
     124             : 
     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>
     127             :     */
     128             : 
     129             :     class COMPHELPER_DLLPUBLIC OComponentProxyAggregationHelper :public ::cppu::ImplHelper1 <   com::sun::star::lang::XEventListener
     130             :                                                                         >
     131             :                                             ,private OProxyAggregation
     132             :     {
     133             :     private:
     134             :         typedef ::cppu::ImplHelper1 <   ::com::sun::star::lang::XEventListener
     135             :                                     >   BASE;   // prevents some MSVC problems
     136             : 
     137             :     protected:
     138             :         ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent >
     139             :                                             m_xInner;
     140             :         ::cppu::OBroadcastHelper&           m_rBHelper;
     141             : 
     142             :     protected:
     143             :         // OProxyAggregation
     144             :         using OProxyAggregation::getComponentContext;
     145             : 
     146             :         // XInterface
     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;
     148             : 
     149             :         // XTypeProvider
     150             :         DECLARE_XTYPEPROVIDER( )
     151             : 
     152             :     protected:
     153             :         OComponentProxyAggregationHelper(
     154             :             const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& _rxContext,
     155             :             ::cppu::OBroadcastHelper& _rBHelper
     156             :         );
     157             :         virtual ~OComponentProxyAggregationHelper( );
     158             : 
     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
     164             :         );
     165             : 
     166             :         // XEventListener
     167             :         virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     168             : 
     169             :         // XComponent
     170             :         virtual void SAL_CALL dispose() throw( ::com::sun::star::uno::RuntimeException, std::exception ) = 0;
     171             : 
     172             :     private:
     173             :         OComponentProxyAggregationHelper( const OComponentProxyAggregationHelper& ) SAL_DELETED_FUNCTION;
     174             :         OComponentProxyAggregationHelper& operator=( const OComponentProxyAggregationHelper& ) SAL_DELETED_FUNCTION;
     175             :     };
     176             : 
     177             : 
     178             :     //= OComponentProxyAggregation
     179             : 
     180             :     class COMPHELPER_DLLPUBLIC OComponentProxyAggregation   :public OBaseMutex
     181             :                                         ,public cppu::WeakComponentImplHelperBase
     182             :                                         ,public OComponentProxyAggregationHelper
     183             :     {
     184             :     protected:
     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
     188             :         );
     189             : 
     190             :         virtual ~OComponentProxyAggregation();
     191             : 
     192             :         // XInterface
     193             :         DECLARE_XINTERFACE()
     194             :         // XTypeProvider
     195             :         DECLARE_XTYPEPROVIDER()
     196             : 
     197             :         // OComponentHelper
     198             :         virtual void SAL_CALL disposing()  throw (::com::sun::star::uno::RuntimeException) SAL_OVERRIDE;
     199             : 
     200             :         // XEventListener
     201             :         virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& _rSource ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     202             : 
     203             :         // XComponent/OComponentProxyAggregationHelper
     204             :         virtual void SAL_CALL dispose() throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
     205             : 
     206             :     protected:
     207             :         // be called from within the dtor of derived classes
     208             :         void implEnsureDisposeInDtor( );
     209             : 
     210             :     private:
     211             :         OComponentProxyAggregation( const OComponentProxyAggregation& ) SAL_DELETED_FUNCTION;
     212             :         OComponentProxyAggregation& operator=( const OComponentProxyAggregation& ) SAL_DELETED_FUNCTION;
     213             :     };
     214             : 
     215             : 
     216             : }   // namespace comphelper
     217             : 
     218             : 
     219             : 
     220             : #endif // INCLUDED_COMPHELPER_PROXYAGGREGATION_HXX
     221             : 
     222             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11