1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_dbaccess.hxx"
30 
31 #ifndef _DBASHARED_APITOOLS_HXX_
32 #include "apitools.hxx"
33 #endif
34 #ifndef DBACCESS_SHARED_DBASTRINGS_HRC
35 #include "dbastrings.hrc"
36 #endif
37 #ifndef _CPPUHELPER_TYPEPROVIDER_HXX_
38 #include <cppuhelper/typeprovider.hxx>
39 #endif
40 #include <com/sun/star/lang/XServiceInfo.hpp>
41 #ifndef _OSL_DIAGNOSE_H_
42 #include <osl/diagnose.h>
43 #endif
44 #ifndef _TOOLS_DEBUG_HXX
45 #include <tools/debug.hxx>
46 #endif
47 
48 using namespace ::com::sun::star::uno;
49 using namespace ::com::sun::star::lang;
50 using namespace cppu;
51 using namespace osl;
52 using namespace dbaccess;
53 
54 //==================================================================================
55 //= various helper functions
56 //==================================================================================
57 //============================================================
58 //= OSubComponent
59 //============================================================
60 DBG_NAME(OSubComponent)
61 //--------------------------------------------------------------------------
62 OSubComponent::OSubComponent(Mutex& _rMutex, const Reference< XInterface > & xParent)
63 			  :OComponentHelper(_rMutex)
64 			  ,m_xParent(xParent)
65 {
66     DBG_CTOR(OSubComponent,NULL);
67 
68 }
69 // -----------------------------------------------------------------------------
70 OSubComponent::~OSubComponent()
71 {
72 	m_xParent = NULL;
73 
74     DBG_DTOR(OSubComponent,NULL);
75 }
76 
77 // com::sun::star::lang::XTypeProvider
78 //--------------------------------------------------------------------------
79 Sequence< Type > OSubComponent::getTypes() throw (RuntimeException)
80 {
81 	OTypeCollection aTypes(::getCppuType( (const Reference< XComponent > *)0 ),
82 						   ::getCppuType( (const Reference< XTypeProvider > *)0 ),
83 						   ::getCppuType( (const Reference< XWeak > *)0 ));
84 
85 	return aTypes.getTypes();
86 }
87 
88 // XInterface
89 //--------------------------------------------------------------------------
90 void OSubComponent::acquire() throw ( )
91 {
92 	OComponentHelper::acquire();
93 }
94 
95 //--------------------------------------------------------------------------
96 void OSubComponent::release() throw ( )
97 {
98 	Reference< XInterface > x( xDelegator );
99 	if (! x.is())
100 	{
101 		if (osl_decrementInterlockedCount( &m_refCount ) == 0 )
102 		{
103 			if (! rBHelper.bDisposed)
104 			{
105                 // *before* again incrementing our ref count, ensure that our weak connection point
106                 // will not create references to us anymore (via XAdapter::queryAdapted)
107                 disposeWeakConnectionPoint();
108 
109                 Reference< XInterface > xHoldAlive( *this );
110 				// remember the parent
111 				Reference< XInterface > xParent;
112 				{
113 					MutexGuard aGuard( rBHelper.rMutex );
114 					xParent = m_xParent;
115 					m_xParent = NULL;
116 				}
117 
118                 OSL_ENSURE( m_refCount == 1, "OSubComponent::release: invalid ref count (before dispose)!" );
119 
120 				// First dispose
121 				dispose();
122 
123 				// only the alive ref holds the object
124 				OSL_ENSURE( m_refCount == 1, "OSubComponent::release: invalid ref count (after dispose)!" );
125 
126 				// release the parent in the ~
127 				if (xParent.is())
128 				{
129 					MutexGuard aGuard( rBHelper.rMutex );
130 					m_xParent = xParent;
131 				}
132 
133 				// destroy the object if xHoldAlive decrement the refcount to 0
134 				return;
135 			}
136 		}
137 		// restore the reference count
138 		osl_incrementInterlockedCount( &m_refCount );
139 	}
140 
141 	// as we cover the job of the componenthelper we use the ...
142 	OWeakAggObject::release();
143 }
144 
145 //--------------------------------------------------------------------------
146 Any OSubComponent::queryInterface( const Type & rType ) throw(RuntimeException)
147 {
148 	Any aReturn;
149 	if (!rType.equals(::getCppuType(static_cast< Reference< XAggregation >* >(NULL))))
150 		aReturn = OComponentHelper::queryInterface(rType);
151 
152 	return aReturn;
153 }
154 
155 
156