1*96de5490SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*96de5490SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*96de5490SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*96de5490SAndrew Rist  * distributed with this work for additional information
6*96de5490SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*96de5490SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*96de5490SAndrew Rist  * "License"); you may not use this file except in compliance
9*96de5490SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*96de5490SAndrew Rist  *
11*96de5490SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*96de5490SAndrew Rist  *
13*96de5490SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*96de5490SAndrew Rist  * software distributed under the License is distributed on an
15*96de5490SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*96de5490SAndrew Rist  * KIND, either express or implied.  See the License for the
17*96de5490SAndrew Rist  * specific language governing permissions and limitations
18*96de5490SAndrew Rist  * under the License.
19*96de5490SAndrew Rist  *
20*96de5490SAndrew Rist  *************************************************************/
21*96de5490SAndrew Rist 
22*96de5490SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_dbaccess.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #ifndef _DBASHARED_APITOOLS_HXX_
28cdf0e10cSrcweir #include "apitools.hxx"
29cdf0e10cSrcweir #endif
30cdf0e10cSrcweir #ifndef DBACCESS_SHARED_DBASTRINGS_HRC
31cdf0e10cSrcweir #include "dbastrings.hrc"
32cdf0e10cSrcweir #endif
33cdf0e10cSrcweir #ifndef _CPPUHELPER_TYPEPROVIDER_HXX_
34cdf0e10cSrcweir #include <cppuhelper/typeprovider.hxx>
35cdf0e10cSrcweir #endif
36cdf0e10cSrcweir #include <com/sun/star/lang/XServiceInfo.hpp>
37cdf0e10cSrcweir #ifndef _OSL_DIAGNOSE_H_
38cdf0e10cSrcweir #include <osl/diagnose.h>
39cdf0e10cSrcweir #endif
40cdf0e10cSrcweir #ifndef _TOOLS_DEBUG_HXX
41cdf0e10cSrcweir #include <tools/debug.hxx>
42cdf0e10cSrcweir #endif
43cdf0e10cSrcweir 
44cdf0e10cSrcweir using namespace ::com::sun::star::uno;
45cdf0e10cSrcweir using namespace ::com::sun::star::lang;
46cdf0e10cSrcweir using namespace cppu;
47cdf0e10cSrcweir using namespace osl;
48cdf0e10cSrcweir using namespace dbaccess;
49cdf0e10cSrcweir 
50cdf0e10cSrcweir //==================================================================================
51cdf0e10cSrcweir //= various helper functions
52cdf0e10cSrcweir //==================================================================================
53cdf0e10cSrcweir //============================================================
54cdf0e10cSrcweir //= OSubComponent
55cdf0e10cSrcweir //============================================================
DBG_NAME(OSubComponent)56cdf0e10cSrcweir DBG_NAME(OSubComponent)
57cdf0e10cSrcweir //--------------------------------------------------------------------------
58cdf0e10cSrcweir OSubComponent::OSubComponent(Mutex& _rMutex, const Reference< XInterface > & xParent)
59cdf0e10cSrcweir 			  :OComponentHelper(_rMutex)
60cdf0e10cSrcweir 			  ,m_xParent(xParent)
61cdf0e10cSrcweir {
62cdf0e10cSrcweir     DBG_CTOR(OSubComponent,NULL);
63cdf0e10cSrcweir 
64cdf0e10cSrcweir }
65cdf0e10cSrcweir // -----------------------------------------------------------------------------
~OSubComponent()66cdf0e10cSrcweir OSubComponent::~OSubComponent()
67cdf0e10cSrcweir {
68cdf0e10cSrcweir 	m_xParent = NULL;
69cdf0e10cSrcweir 
70cdf0e10cSrcweir     DBG_DTOR(OSubComponent,NULL);
71cdf0e10cSrcweir }
72cdf0e10cSrcweir 
73cdf0e10cSrcweir // com::sun::star::lang::XTypeProvider
74cdf0e10cSrcweir //--------------------------------------------------------------------------
getTypes()75cdf0e10cSrcweir Sequence< Type > OSubComponent::getTypes() throw (RuntimeException)
76cdf0e10cSrcweir {
77cdf0e10cSrcweir 	OTypeCollection aTypes(::getCppuType( (const Reference< XComponent > *)0 ),
78cdf0e10cSrcweir 						   ::getCppuType( (const Reference< XTypeProvider > *)0 ),
79cdf0e10cSrcweir 						   ::getCppuType( (const Reference< XWeak > *)0 ));
80cdf0e10cSrcweir 
81cdf0e10cSrcweir 	return aTypes.getTypes();
82cdf0e10cSrcweir }
83cdf0e10cSrcweir 
84cdf0e10cSrcweir // XInterface
85cdf0e10cSrcweir //--------------------------------------------------------------------------
acquire()86cdf0e10cSrcweir void OSubComponent::acquire() throw ( )
87cdf0e10cSrcweir {
88cdf0e10cSrcweir 	OComponentHelper::acquire();
89cdf0e10cSrcweir }
90cdf0e10cSrcweir 
91cdf0e10cSrcweir //--------------------------------------------------------------------------
release()92cdf0e10cSrcweir void OSubComponent::release() throw ( )
93cdf0e10cSrcweir {
94cdf0e10cSrcweir 	Reference< XInterface > x( xDelegator );
95cdf0e10cSrcweir 	if (! x.is())
96cdf0e10cSrcweir 	{
97cdf0e10cSrcweir 		if (osl_decrementInterlockedCount( &m_refCount ) == 0 )
98cdf0e10cSrcweir 		{
99cdf0e10cSrcweir 			if (! rBHelper.bDisposed)
100cdf0e10cSrcweir 			{
101cdf0e10cSrcweir                 // *before* again incrementing our ref count, ensure that our weak connection point
102cdf0e10cSrcweir                 // will not create references to us anymore (via XAdapter::queryAdapted)
103cdf0e10cSrcweir                 disposeWeakConnectionPoint();
104cdf0e10cSrcweir 
105cdf0e10cSrcweir                 Reference< XInterface > xHoldAlive( *this );
106cdf0e10cSrcweir 				// remember the parent
107cdf0e10cSrcweir 				Reference< XInterface > xParent;
108cdf0e10cSrcweir 				{
109cdf0e10cSrcweir 					MutexGuard aGuard( rBHelper.rMutex );
110cdf0e10cSrcweir 					xParent = m_xParent;
111cdf0e10cSrcweir 					m_xParent = NULL;
112cdf0e10cSrcweir 				}
113cdf0e10cSrcweir 
114cdf0e10cSrcweir                 OSL_ENSURE( m_refCount == 1, "OSubComponent::release: invalid ref count (before dispose)!" );
115cdf0e10cSrcweir 
116cdf0e10cSrcweir 				// First dispose
117cdf0e10cSrcweir 				dispose();
118cdf0e10cSrcweir 
119cdf0e10cSrcweir 				// only the alive ref holds the object
120cdf0e10cSrcweir 				OSL_ENSURE( m_refCount == 1, "OSubComponent::release: invalid ref count (after dispose)!" );
121cdf0e10cSrcweir 
122cdf0e10cSrcweir 				// release the parent in the ~
123cdf0e10cSrcweir 				if (xParent.is())
124cdf0e10cSrcweir 				{
125cdf0e10cSrcweir 					MutexGuard aGuard( rBHelper.rMutex );
126cdf0e10cSrcweir 					m_xParent = xParent;
127cdf0e10cSrcweir 				}
128cdf0e10cSrcweir 
129cdf0e10cSrcweir 				// destroy the object if xHoldAlive decrement the refcount to 0
130cdf0e10cSrcweir 				return;
131cdf0e10cSrcweir 			}
132cdf0e10cSrcweir 		}
133cdf0e10cSrcweir 		// restore the reference count
134cdf0e10cSrcweir 		osl_incrementInterlockedCount( &m_refCount );
135cdf0e10cSrcweir 	}
136cdf0e10cSrcweir 
137cdf0e10cSrcweir 	// as we cover the job of the componenthelper we use the ...
138cdf0e10cSrcweir 	OWeakAggObject::release();
139cdf0e10cSrcweir }
140cdf0e10cSrcweir 
141cdf0e10cSrcweir //--------------------------------------------------------------------------
queryInterface(const Type & rType)142cdf0e10cSrcweir Any OSubComponent::queryInterface( const Type & rType ) throw(RuntimeException)
143cdf0e10cSrcweir {
144cdf0e10cSrcweir 	Any aReturn;
145cdf0e10cSrcweir 	if (!rType.equals(::getCppuType(static_cast< Reference< XAggregation >* >(NULL))))
146cdf0e10cSrcweir 		aReturn = OComponentHelper::queryInterface(rType);
147cdf0e10cSrcweir 
148cdf0e10cSrcweir 	return aReturn;
149cdf0e10cSrcweir }
150cdf0e10cSrcweir 
151cdf0e10cSrcweir 
152