Version 4.0.0.1, tag libreoffice-4.0.0.1
[LibreOffice.git] / dbaccess / source / core / misc / apitools.cxx
blobcdf690b37895b23d15ad851b9889e820fe9c094b
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 .
21 #include "apitools.hxx"
22 #include "dbastrings.hrc"
23 #include <cppuhelper/typeprovider.hxx>
24 #include <com/sun/star/lang/XServiceInfo.hpp>
25 #include <osl/diagnose.h>
26 #include <tools/debug.hxx>
28 using namespace ::com::sun::star::uno;
29 using namespace ::com::sun::star::lang;
30 using namespace cppu;
31 using namespace osl;
32 using namespace dbaccess;
34 //==================================================================================
35 //= various helper functions
36 //==================================================================================
37 //============================================================
38 //= OSubComponent
39 //============================================================
40 DBG_NAME(OSubComponent)
41 //--------------------------------------------------------------------------
42 OSubComponent::OSubComponent(Mutex& _rMutex, const Reference< XInterface > & xParent)
43 :OComponentHelper(_rMutex)
44 ,m_xParent(xParent)
46 DBG_CTOR(OSubComponent,NULL);
49 // -----------------------------------------------------------------------------
50 OSubComponent::~OSubComponent()
52 m_xParent = NULL;
54 DBG_DTOR(OSubComponent,NULL);
57 // com::sun::star::lang::XTypeProvider
58 //--------------------------------------------------------------------------
59 Sequence< Type > OSubComponent::getTypes() throw (RuntimeException)
61 OTypeCollection aTypes(::getCppuType( (const Reference< XComponent > *)0 ),
62 ::getCppuType( (const Reference< XTypeProvider > *)0 ),
63 ::getCppuType( (const Reference< XWeak > *)0 ));
65 return aTypes.getTypes();
68 // XInterface
69 //--------------------------------------------------------------------------
70 void OSubComponent::acquire() throw ( )
72 OComponentHelper::acquire();
75 //--------------------------------------------------------------------------
76 void OSubComponent::release() throw ( )
78 Reference< XInterface > x( xDelegator );
79 if (! x.is())
81 if (osl_atomic_decrement( &m_refCount ) == 0 )
83 if (! rBHelper.bDisposed)
85 // *before* again incrementing our ref count, ensure that our weak connection point
86 // will not create references to us anymore (via XAdapter::queryAdapted)
87 disposeWeakConnectionPoint();
89 Reference< XInterface > xHoldAlive( *this );
90 // remember the parent
91 Reference< XInterface > xParent;
93 MutexGuard aGuard( rBHelper.rMutex );
94 xParent = m_xParent;
95 m_xParent = NULL;
98 OSL_ENSURE( m_refCount == 1, "OSubComponent::release: invalid ref count (before dispose)!" );
100 // First dispose
101 dispose();
103 // only the alive ref holds the object
104 OSL_ENSURE( m_refCount == 1, "OSubComponent::release: invalid ref count (after dispose)!" );
106 // release the parent in the ~
107 if (xParent.is())
109 MutexGuard aGuard( rBHelper.rMutex );
110 m_xParent = xParent;
113 // destroy the object if xHoldAlive decrement the refcount to 0
114 return;
117 // restore the reference count
118 osl_atomic_increment( &m_refCount );
121 // as we cover the job of the componenthelper we use the ...
122 OWeakAggObject::release();
125 //--------------------------------------------------------------------------
126 Any OSubComponent::queryInterface( const Type & rType ) throw(RuntimeException)
128 Any aReturn;
129 if (!rType.equals(::getCppuType(static_cast< Reference< XAggregation >* >(NULL))))
130 aReturn = OComponentHelper::queryInterface(rType);
132 return aReturn;
136 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */