LCOV - code coverage report
Current view: top level - include/comphelper - proxyaggregation.hxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 2 0.0 %
Date: 2014-04-14 Functions: 0 1 0.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 COMPHELPER_PROXY_AGGREGATION
      21             : #define COMPHELPER_PROXY_AGGREGATION
      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           0 :         inline const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& getComponentContext()
      93             :         {
      94           0 :             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( );                                       // never implemented
     114             :         OProxyAggregation( const OProxyAggregation& );              // never implemented
     115             :         OProxyAggregation& operator=( const OProxyAggregation& );   // never implemented
     116             :     };
     117             : 
     118             : 
     119             :     //= OComponentProxyAggregationHelper
     120             : 
     121             :     /** a helper class for aggregating a proxy to an XComponent
     122             : 
     123             :         <p>The object couples the life time of itself and the component: if one of the both
     124             :         dies (in a sense of being disposed), the other one dies, too.</p>
     125             : 
     126             :         <p>The class itself does not implement XComponent so you need to forward any XComponent::dispose
     127             :         calls which your derived class gets to the dispose method of this class.</p>
     128             :     */
     129             : 
     130             :     class COMPHELPER_DLLPUBLIC OComponentProxyAggregationHelper :public ::cppu::ImplHelper1 <   com::sun::star::lang::XEventListener
     131             :                                                                         >
     132             :                                             ,private OProxyAggregation
     133             :     {
     134             :     private:
     135             :         typedef ::cppu::ImplHelper1 <   ::com::sun::star::lang::XEventListener
     136             :                                     >   BASE;   // prevents some MSVC problems
     137             : 
     138             :     protected:
     139             :         ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent >
     140             :                                             m_xInner;
     141             :         ::cppu::OBroadcastHelper&           m_rBHelper;
     142             : 
     143             :     protected:
     144             :         // OProxyAggregation
     145             :         using OProxyAggregation::getComponentContext;
     146             : 
     147             :         // XInterface
     148             :         ::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;
     149             : 
     150             :         // XTypeProvider
     151             :         DECLARE_XTYPEPROVIDER( )
     152             : 
     153             :     protected:
     154             :         OComponentProxyAggregationHelper(
     155             :             const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& _rxContext,
     156             :             ::cppu::OBroadcastHelper& _rBHelper
     157             :         );
     158             :         virtual ~OComponentProxyAggregationHelper( );
     159             : 
     160             :         /// to be called from within your ctor
     161             :         void componentAggregateProxyFor(
     162             :             const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent >& _rxComponent,
     163             :             oslInterlockedCount& _rRefCount,
     164             :             ::cppu::OWeakObject& _rDelegator
     165             :         );
     166             : 
     167             :         // XEventListener
     168             :         virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& Source ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     169             : 
     170             :         // XComponent
     171             :         virtual void SAL_CALL dispose() throw( ::com::sun::star::uno::RuntimeException, std::exception ) = 0;
     172             : 
     173             :     private:
     174             :         COMPHELPER_DLLPRIVATE OComponentProxyAggregationHelper( );                                                  // never implemented
     175             :         COMPHELPER_DLLPRIVATE OComponentProxyAggregationHelper( const OComponentProxyAggregationHelper& );          // never implemented
     176             :         COMPHELPER_DLLPRIVATE OComponentProxyAggregationHelper& operator=( const OComponentProxyAggregationHelper& );   // never implemented
     177             :     };
     178             : 
     179             : 
     180             :     //= OComponentProxyAggregation
     181             : 
     182             :     class COMPHELPER_DLLPUBLIC OComponentProxyAggregation   :public OBaseMutex
     183             :                                         ,public cppu::WeakComponentImplHelperBase
     184             :                                         ,public OComponentProxyAggregationHelper
     185             :     {
     186             :     protected:
     187             :         OComponentProxyAggregation(
     188             :             const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext >& _rxContext,
     189             :             const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XComponent >& _rxComponent
     190             :         );
     191             : 
     192             :         virtual ~OComponentProxyAggregation();
     193             : 
     194             :         // XInterface
     195             :         DECLARE_XINTERFACE()
     196             :         // XTypeProvider
     197             :         DECLARE_XTYPEPROVIDER()
     198             : 
     199             :         // OComponentHelper
     200             :         virtual void SAL_CALL disposing()  throw (::com::sun::star::uno::RuntimeException) SAL_OVERRIDE;
     201             : 
     202             :         // XEventListener
     203             :         virtual void SAL_CALL disposing( const ::com::sun::star::lang::EventObject& _rSource ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
     204             : 
     205             :         // XComponent/OComponentProxyAggregationHelper
     206             :         virtual void SAL_CALL dispose() throw( ::com::sun::star::uno::RuntimeException, std::exception ) SAL_OVERRIDE;
     207             : 
     208             :     protected:
     209             :         // be called from within the dtor of derived classes
     210             :         void implEnsureDisposeInDtor( );
     211             : 
     212             :     private:
     213             :         COMPHELPER_DLLPRIVATE OComponentProxyAggregation( );                                                // never implemented
     214             :         COMPHELPER_DLLPRIVATE OComponentProxyAggregation( const OComponentProxyAggregation& );          // never implemented
     215             :         COMPHELPER_DLLPRIVATE OComponentProxyAggregation& operator=( const OComponentProxyAggregation& );   // never implemented
     216             :     };
     217             : 
     218             : 
     219             : }   // namespace comphelper
     220             : 
     221             : 
     222             : 
     223             : #endif // COMPHELPER_PROXY_AGGREGATION
     224             : 
     225             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10