/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file incorporates work covered by the following license notice: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed * with this work for additional information regarding copyright * ownership. The ASF licenses this file to you under the Apache * License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ #ifndef INCLUDED_COMPHELPER_PROXYAGGREGATION_HXX #define INCLUDED_COMPHELPER_PROXYAGGREGATION_HXX #include #include #include #include #include #include #include #include #include namespace com { namespace sun { namespace star { namespace uno { class XComponentContext; } } } } /* class hierarchy herein: +-------------------+ helper class for aggregating the proxy to another object | OProxyAggregation | - not ref counted +-------------------+ - no UNO implementation, i.e. not derived from XInterface ^ (neither direct nor indirect) | | +----------------------------------+ helper class for aggregating a proxy to an XComponent | OComponentProxyAggregationHelper | - life time coupling: if the inner component (the "aggregate") +----------------------------------+ is disposed, the outer (the delegator) is disposed, too, and ^ vice versa | - UNO based, implementing XEventListener | +----------------------------+ component aggregating another XComponent | OComponentProxyAggregation | - life time coupling as above +----------------------------+ - ref-counted - implements an XComponent itself If you need to - wrap a foreign object which is a XComponent => use OComponentProxyAggregation - call componentAggregateProxyFor in your ctor - call implEnsureDisposeInDtor in your dtor - wrap a foreign object which is a XComponent, but already have ref-counting mechanisms inherited from somewhere else => use OComponentProxyAggregationHelper - override dispose - don't forget to call the base class' dispose! - call componentAggregateProxyFor in your ctor - wrap a foreign object which is no XComponent => use OProxyAggregation - call baseAggregateProxyFor in your ctor */ namespace comphelper { //= OProxyAggregation /** helper class for aggregating a proxy for a foreign object */ class OProxyAggregation { private: css::uno::Reference< css::uno::XAggregation > m_xProxyAggregate; css::uno::Reference< css::lang::XTypeProvider > m_xProxyTypeAccess; css::uno::Reference< css::uno::XComponentContext > m_xContext; protected: const css::uno::Reference< css::uno::XComponentContext >& getComponentContext() const { return m_xContext; } protected: OProxyAggregation( const css::uno::Reference< css::uno::XComponentContext >& _rxContext ); ~OProxyAggregation(); /// to be called from within your ctor void baseAggregateProxyFor( const css::uno::Reference< css::uno::XInterface >& _rxComponent, oslInterlockedCount& _rRefCount, ::cppu::OWeakObject& _rDelegator ); // XInterface and XTypeProvider /// @throws css::uno::RuntimeException css::uno::Any SAL_CALL queryAggregation( const css::uno::Type& _rType ); /// @throws css::uno::RuntimeException css::uno::Sequence< css::uno::Type > SAL_CALL getTypes( ); private: OProxyAggregation( const OProxyAggregation& ) = delete; OProxyAggregation& operator=( const OProxyAggregation& ) = delete; }; //= OComponentProxyAggregationHelper /** a helper class for aggregating a proxy to an XComponent

The object couples the life time of itself and the component: if one of the both dies (in a sense of being disposed), the other one dies, too.

The class itself does not implement XComponent so you need to forward any XComponent::dispose calls which your derived class gets to the dispose method of this class.

*/ class COMPHELPER_DLLPUBLIC OComponentProxyAggregationHelper :public ::cppu::ImplHelper1 < css::lang::XEventListener > ,private OProxyAggregation { private: typedef ::cppu::ImplHelper1 < css::lang::XEventListener > BASE; // prevents some MSVC problems protected: css::uno::Reference< css::lang::XComponent > m_xInner; ::cppu::OBroadcastHelper& m_rBHelper; protected: // OProxyAggregation using OProxyAggregation::getComponentContext; // XInterface css::uno::Any SAL_CALL queryInterface( const css::uno::Type& _rType ) override; // XTypeProvider DECLARE_XTYPEPROVIDER( ) protected: OComponentProxyAggregationHelper( const css::uno::Reference< css::uno::XComponentContext >& _rxContext, ::cppu::OBroadcastHelper& _rBHelper ); virtual ~OComponentProxyAggregationHelper( ); /// to be called from within your ctor void componentAggregateProxyFor( const css::uno::Reference< css::lang::XComponent >& _rxComponent, oslInterlockedCount& _rRefCount, ::cppu::OWeakObject& _rDelegator ); // XEventListener virtual void SAL_CALL disposing( const css::lang::EventObject& Source ) override; // XComponent /// @throws css::uno::RuntimeException virtual void SAL_CALL dispose() = 0; private: OComponentProxyAggregationHelper( const OComponentProxyAggregationHelper& ) = delete; OComponentProxyAggregationHelper& operator=( const OComponentProxyAggregationHelper& ) = delete; }; //= OComponentProxyAggregation class COMPHELPER_DLLPUBLIC OComponentProxyAggregation : public cppu::BaseMutex ,public cppu::WeakComponentImplHelperBase ,public OComponentProxyAggregationHelper { protected: OComponentProxyAggregation( const css::uno::Reference< css::uno::XComponentContext >& _rxContext, const css::uno::Reference< css::lang::XComponent >& _rxComponent ); virtual ~OComponentProxyAggregation() override; // XInterface DECLARE_XINTERFACE() // XTypeProvider DECLARE_XTYPEPROVIDER() // OComponentHelper virtual void SAL_CALL disposing() override; // XEventListener virtual void SAL_CALL disposing( const css::lang::EventObject& _rSource ) override; // XComponent/OComponentProxyAggregationHelper virtual void SAL_CALL dispose() override; private: OComponentProxyAggregation( const OComponentProxyAggregation& ) = delete; OComponentProxyAggregation& operator=( const OComponentProxyAggregation& ) = delete; }; } // namespace comphelper #endif // INCLUDED_COMPHELPER_PROXYAGGREGATION_HXX /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ stro/nisz/libreoffice-7-1'>distro/nisz/libreoffice-7-1 LibreOffice 核心代码仓库文档基金会
summaryrefslogtreecommitdiff
AgeCommit message (Expand)Author
2017-06-23Fix typos: uniform registeredAndrea Gelmini
2017-06-12Translate German comments and debug strings (leftovers in dirs j... to q...)Johnny_M
2017-05-09cleanup osl/diagnose.h includesJochen Nitschke
2017-05-07revert OSL_ASSERT changesChris Sherlock
2017-05-07tdf#43157: convert javaunohelper from OSL_ASSERT to assertChris Sherlock
2017-04-21gbuild: Remove MSVC 2013 legacy codeDavid Ostrovsky
2017-03-25Fix typosAndrea Gelmini
2017-01-31teach lolugin:stringconstant about calling constructorsNoel Grandin
2017-01-26Remove dynamic exception specificationsStephan Bergmann
2017-01-17Typo: listerner->listenerJulien Nabet
2016-12-13OSL_TRACE->SAL in framework..salNoel Grandin
2016-02-17javaunohelper: fix all javadoc warningsMichael Stahl
2016-02-08cid#1326918 FB.NP_CLONE_COULD_RETURN_NULLStephan Bergmann
2016-02-04coverity#1326400 Dereference null return valueCaolán McNamara
2015-12-30coverity#1326973 SBSC: String concatenation in loop using + operatorCaolán McNamara
2015-12-21related tdf#86784: new API got backported to 5.1Thorsten Behrens
2015-12-21cid#1343654 FindBugs: Bad practice (FB.DMI_RANDOM_USED_ONLY_ONCE)Stephan Bergmann
2015-12-20Fix @since tagsStephan Bergmann
2015-12-18tdf#86784: Pass custom options to Java bootstrapKatarina Behrens
2015-12-03Add build toolchain to upload LibreOffice API to Maven CentralDavid Ostrovsky
2015-12-01Expose metadata to deploy LibreOffice artifacts on Maven CentralDavid Ostrovsky
2015-11-24cppcheck: noExplicitConstructorCaolán McNamara
2015-11-17Don't assume sal_Unicode is unsigned shortStephan Bergmann
2015-11-11coverity#1338592 Explicit null dereferencedCaolán McNamara
2015-11-10loplugin:nullptr (automatic rewrite)Stephan Bergmann
2015-11-09new loplugin: oncevarNoel Grandin
2015-11-05java: remove ((unnecessary)) parenthesesNoel Grandin
2015-11-05java: combine nested if statementsNoel Grandin
2015-11-05java:no need to explicitly create these constructorsNoel Grandin
2015-10-30UNO: no need to use OUString constructor when calling createInstanceNoel Grandin