build fix: no comphelper/profilezone.hxx in this branch
[LibreOffice.git] / dbaccess / source / core / misc / apitools.cxx
blob06f6a1f6481c18a8a28bc302c6c1be0b6233725d
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 #include "apitools.hxx"
21 #include "dbastrings.hrc"
22 #include <cppuhelper/typeprovider.hxx>
23 #include <com/sun/star/lang/XServiceInfo.hpp>
24 #include <osl/diagnose.h>
25 #include <tools/debug.hxx>
27 using namespace ::com::sun::star::uno;
28 using namespace ::com::sun::star::lang;
29 using namespace cppu;
30 using namespace osl;
32 // various helper functions
33 // OSubComponent
34 OSubComponent::OSubComponent(Mutex& _rMutex, const Reference< XInterface > & xParent)
35 :OComponentHelper(_rMutex)
36 ,m_xParent(xParent)
41 OSubComponent::~OSubComponent()
43 m_xParent = nullptr;
47 // css::lang::XTypeProvider
48 Sequence< Type > OSubComponent::getTypes() throw (RuntimeException, std::exception)
50 OTypeCollection aTypes(cppu::UnoType<XComponent>::get(),
51 cppu::UnoType<XTypeProvider>::get(),
52 cppu::UnoType<XWeak>::get());
54 return aTypes.getTypes();
57 // XInterface
59 void OSubComponent::release() throw ( )
61 Reference< XInterface > x( xDelegator );
62 if (! x.is())
64 if (osl_atomic_decrement( &m_refCount ) == 0 )
66 if (! rBHelper.bDisposed)
68 // *before* again incrementing our ref count, ensure that our weak connection point
69 // will not create references to us anymore (via XAdapter::queryAdapted)
70 disposeWeakConnectionPoint();
72 Reference< XInterface > xHoldAlive( *this );
73 // remember the parent
74 Reference< XInterface > xParent;
76 MutexGuard aGuard( rBHelper.rMutex );
77 xParent = m_xParent;
78 m_xParent = nullptr;
81 OSL_ENSURE( m_refCount == 1, "OSubComponent::release: invalid ref count (before dispose)!" );
83 // First dispose
84 dispose();
86 // only the alive ref holds the object
87 OSL_ENSURE( m_refCount == 1, "OSubComponent::release: invalid ref count (after dispose)!" );
89 // release the parent in the ~
90 if (xParent.is())
92 MutexGuard aGuard( rBHelper.rMutex );
93 m_xParent = xParent;
96 // destroy the object if xHoldAlive decrement the refcount to 0
97 return;
100 // restore the reference count
101 osl_atomic_increment( &m_refCount );
104 // as we cover the job of the componenthelper we use the ...
105 OWeakAggObject::release();
108 Any OSubComponent::queryInterface( const Type & rType ) throw(RuntimeException, std::exception)
110 Any aReturn;
111 if (!rType.equals(cppu::UnoType<XAggregation>::get()))
112 aReturn = OComponentHelper::queryInterface(rType);
114 return aReturn;
117 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */