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