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