Branch data 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 : :
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>
27 : :
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;
33 : :
34 : : //==================================================================================
35 : : //= various helper functions
36 : : //==================================================================================
37 : : //============================================================
38 : : //= OSubComponent
39 : : //============================================================
40 : : DBG_NAME(OSubComponent)
41 : : //--------------------------------------------------------------------------
42 : 246 : OSubComponent::OSubComponent(Mutex& _rMutex, const Reference< XInterface > & xParent)
43 : : :OComponentHelper(_rMutex)
44 : 246 : ,m_xParent(xParent)
45 : : {
46 : : DBG_CTOR(OSubComponent,NULL);
47 : :
48 : 246 : }
49 : : // -----------------------------------------------------------------------------
50 : 246 : OSubComponent::~OSubComponent()
51 : : {
52 [ + - ]: 246 : m_xParent = NULL;
53 : :
54 : : DBG_DTOR(OSubComponent,NULL);
55 [ - + ]: 246 : }
56 : :
57 : : // com::sun::star::lang::XTypeProvider
58 : : //--------------------------------------------------------------------------
59 : 2 : Sequence< Type > OSubComponent::getTypes() throw (RuntimeException)
60 : : {
61 [ + - ]: 2 : OTypeCollection aTypes(::getCppuType( (const Reference< XComponent > *)0 ),
62 [ + - ]: 2 : ::getCppuType( (const Reference< XTypeProvider > *)0 ),
63 [ + - ][ + - ]: 4 : ::getCppuType( (const Reference< XWeak > *)0 ));
[ + - ][ + - ]
64 : :
65 [ + - ][ + - ]: 2 : return aTypes.getTypes();
66 : : }
67 : :
68 : : // XInterface
69 : : //--------------------------------------------------------------------------
70 : 47924 : void OSubComponent::acquire() throw ( )
71 : : {
72 : 47924 : OComponentHelper::acquire();
73 : 47924 : }
74 : :
75 : : //--------------------------------------------------------------------------
76 : 47832 : void OSubComponent::release() throw ( )
77 : : {
78 [ + - ]: 47832 : Reference< XInterface > x( xDelegator );
79 [ + - ]: 47832 : if (! x.is())
80 : : {
81 [ + - ][ + + ]: 47832 : if (osl_decrementInterlockedCount( &m_refCount ) == 0 )
82 : : {
83 [ + + ]: 296 : if (! rBHelper.bDisposed)
84 : : {
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 [ + - ]: 50 : disposeWeakConnectionPoint();
88 : :
89 [ + - ]: 50 : Reference< XInterface > xHoldAlive( *this );
90 : : // remember the parent
91 : 50 : Reference< XInterface > xParent;
92 : : {
93 [ + - ]: 50 : MutexGuard aGuard( rBHelper.rMutex );
94 [ + - ]: 50 : xParent = m_xParent;
95 [ + - ][ + - ]: 50 : m_xParent = NULL;
96 : : }
97 : :
98 : : OSL_ENSURE( m_refCount == 1, "OSubComponent::release: invalid ref count (before dispose)!" );
99 : :
100 : : // First dispose
101 [ + - ]: 50 : dispose();
102 : :
103 : : // only the alive ref holds the object
104 : : OSL_ENSURE( m_refCount == 1, "OSubComponent::release: invalid ref count (after dispose)!" );
105 : :
106 : : // release the parent in the ~
107 [ + - ]: 50 : if (xParent.is())
108 : : {
109 [ + - ]: 50 : MutexGuard aGuard( rBHelper.rMutex );
110 [ + - ][ + - ]: 50 : m_xParent = xParent;
111 : : }
112 : :
113 : : // destroy the object if xHoldAlive decrement the refcount to 0
114 : 47882 : return;
115 : : }
116 : : }
117 : : // restore the reference count
118 [ + - ]: 47782 : osl_incrementInterlockedCount( &m_refCount );
119 : : }
120 : :
121 : : // as we cover the job of the componenthelper we use the ...
122 [ + + ]: 47832 : OWeakAggObject::release();
123 : : }
124 : :
125 : : //--------------------------------------------------------------------------
126 : 3910 : Any OSubComponent::queryInterface( const Type & rType ) throw(RuntimeException)
127 : : {
128 : 3910 : Any aReturn;
129 [ + - ][ + - ]: 3910 : if (!rType.equals(::getCppuType(static_cast< Reference< XAggregation >* >(NULL))))
130 [ + - ]: 3910 : aReturn = OComponentHelper::queryInterface(rType);
131 : :
132 : 3910 : return aReturn;
133 : : }
134 : :
135 : :
136 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|