10b4ced1dSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
30b4ced1dSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
40b4ced1dSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
50b4ced1dSAndrew Rist  * distributed with this work for additional information
60b4ced1dSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
70b4ced1dSAndrew Rist  * to you under the Apache License, Version 2.0 (the
80b4ced1dSAndrew Rist  * "License"); you may not use this file except in compliance
90b4ced1dSAndrew Rist  * with the License.  You may obtain a copy of the License at
100b4ced1dSAndrew Rist  *
110b4ced1dSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
120b4ced1dSAndrew Rist  *
130b4ced1dSAndrew Rist  * Unless required by applicable law or agreed to in writing,
140b4ced1dSAndrew Rist  * software distributed under the License is distributed on an
150b4ced1dSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
160b4ced1dSAndrew Rist  * KIND, either express or implied.  See the License for the
170b4ced1dSAndrew Rist  * specific language governing permissions and limitations
180b4ced1dSAndrew Rist  * under the License.
190b4ced1dSAndrew Rist  *
200b4ced1dSAndrew Rist  *************************************************************/
210b4ced1dSAndrew Rist 
220b4ced1dSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir //______________________________________________________________________________________________________________
25cdf0e10cSrcweir //	my own include
26cdf0e10cSrcweir //______________________________________________________________________________________________________________
27cdf0e10cSrcweir 
28cdf0e10cSrcweir #include "OConnectionPointContainerHelper.hxx"
29cdf0e10cSrcweir 
30cdf0e10cSrcweir //______________________________________________________________________________________________________________
31cdf0e10cSrcweir //	includes of other projects
32cdf0e10cSrcweir //______________________________________________________________________________________________________________
33cdf0e10cSrcweir 
34cdf0e10cSrcweir //______________________________________________________________________________________________________________
35cdf0e10cSrcweir //	include of my own project
36cdf0e10cSrcweir //______________________________________________________________________________________________________________
37cdf0e10cSrcweir #include "OConnectionPointHelper.hxx"
38cdf0e10cSrcweir 
39cdf0e10cSrcweir //______________________________________________________________________________________________________________
40cdf0e10cSrcweir //	namespaces
41cdf0e10cSrcweir //______________________________________________________________________________________________________________
42cdf0e10cSrcweir 
43cdf0e10cSrcweir using namespace	::rtl					;
44cdf0e10cSrcweir using namespace	::osl					;
45cdf0e10cSrcweir using namespace	::cppu					;
46cdf0e10cSrcweir using namespace	::com::sun::star::uno	;
47cdf0e10cSrcweir using namespace	::com::sun::star::lang	;
48cdf0e10cSrcweir 
49cdf0e10cSrcweir namespace unocontrols{
50cdf0e10cSrcweir 
51cdf0e10cSrcweir //______________________________________________________________________________________________________________
52cdf0e10cSrcweir //	construct/destruct
53cdf0e10cSrcweir //______________________________________________________________________________________________________________
54cdf0e10cSrcweir 
OConnectionPointContainerHelper(Mutex & aMutex)55cdf0e10cSrcweir OConnectionPointContainerHelper::OConnectionPointContainerHelper( Mutex& aMutex )
56cdf0e10cSrcweir 	: m_aSharedMutex		( aMutex	)
57cdf0e10cSrcweir 	, m_aMultiTypeContainer	( aMutex	)
58cdf0e10cSrcweir {
59cdf0e10cSrcweir }
60cdf0e10cSrcweir 
~OConnectionPointContainerHelper()61cdf0e10cSrcweir OConnectionPointContainerHelper::~OConnectionPointContainerHelper()
62cdf0e10cSrcweir {
63cdf0e10cSrcweir }
64cdf0e10cSrcweir 
65cdf0e10cSrcweir //____________________________________________________________________________________________________________
66cdf0e10cSrcweir //	XInterface
67cdf0e10cSrcweir //____________________________________________________________________________________________________________
68cdf0e10cSrcweir 
queryInterface(const Type & aType)69cdf0e10cSrcweir Any SAL_CALL OConnectionPointContainerHelper::queryInterface( const Type& aType ) throw( RuntimeException )
70cdf0e10cSrcweir {
71cdf0e10cSrcweir 	// Attention:
72cdf0e10cSrcweir 	//	Don't use mutex or guard in this method!!! Is a method of XInterface.
73cdf0e10cSrcweir 
74cdf0e10cSrcweir 	// Ask for my own supported interfaces ...
75cdf0e10cSrcweir 	Any aReturn	( ::cppu::queryInterface(	aType												,
76cdf0e10cSrcweir 									   		static_cast< XConnectionPointContainer*	> ( this )
77cdf0e10cSrcweir 										)
78cdf0e10cSrcweir 				);
79cdf0e10cSrcweir 
80cdf0e10cSrcweir 	// If searched interface not supported by this class ...
81cdf0e10cSrcweir 	if ( aReturn.hasValue() == sal_False )
82cdf0e10cSrcweir 	{
83cdf0e10cSrcweir 		// ... ask baseclasses.
84cdf0e10cSrcweir 		aReturn = OWeakObject::queryInterface( aType );
85cdf0e10cSrcweir 	}
86cdf0e10cSrcweir 
87cdf0e10cSrcweir 	return aReturn ;
88cdf0e10cSrcweir }
89cdf0e10cSrcweir 
90cdf0e10cSrcweir //____________________________________________________________________________________________________________
91cdf0e10cSrcweir //	XInterface
92cdf0e10cSrcweir //____________________________________________________________________________________________________________
93cdf0e10cSrcweir 
acquire()94cdf0e10cSrcweir void SAL_CALL OConnectionPointContainerHelper::acquire() throw()
95cdf0e10cSrcweir {
96cdf0e10cSrcweir 	// Attention:
97cdf0e10cSrcweir 	//	Don't use mutex or guard in this method!!! Is a method of XInterface.
98cdf0e10cSrcweir 
99cdf0e10cSrcweir 	// Forward to baseclass
100cdf0e10cSrcweir 	OWeakObject::acquire();
101cdf0e10cSrcweir }
102cdf0e10cSrcweir 
103cdf0e10cSrcweir //____________________________________________________________________________________________________________
104cdf0e10cSrcweir //	XInterface
105cdf0e10cSrcweir //____________________________________________________________________________________________________________
106cdf0e10cSrcweir 
release()107cdf0e10cSrcweir void SAL_CALL OConnectionPointContainerHelper::release() throw()
108cdf0e10cSrcweir {
109cdf0e10cSrcweir 	// Attention:
110cdf0e10cSrcweir 	//	Don't use mutex or guard in this method!!! Is a method of XInterface.
111cdf0e10cSrcweir 
112cdf0e10cSrcweir 	// Forward to baseclass
113cdf0e10cSrcweir 	OWeakObject::release();
114cdf0e10cSrcweir }
115cdf0e10cSrcweir 
116cdf0e10cSrcweir //______________________________________________________________________________________________________________
117cdf0e10cSrcweir //	XConnectionPointContainer
118cdf0e10cSrcweir //______________________________________________________________________________________________________________
119cdf0e10cSrcweir 
getConnectionPointTypes()120cdf0e10cSrcweir Sequence< Type > SAL_CALL OConnectionPointContainerHelper::getConnectionPointTypes() throw( RuntimeException )
121cdf0e10cSrcweir {
122cdf0e10cSrcweir 	// Container is threadsafe himself !
123cdf0e10cSrcweir 	return m_aMultiTypeContainer.getContainedTypes();
124cdf0e10cSrcweir }
125cdf0e10cSrcweir 
126cdf0e10cSrcweir //______________________________________________________________________________________________________________
127cdf0e10cSrcweir //	XConnectionPointContainer
128cdf0e10cSrcweir //______________________________________________________________________________________________________________
129cdf0e10cSrcweir 
queryConnectionPoint(const Type & aType)130cdf0e10cSrcweir Reference< XConnectionPoint > SAL_CALL OConnectionPointContainerHelper::queryConnectionPoint( const Type& aType ) throw( RuntimeException )
131cdf0e10cSrcweir {
132cdf0e10cSrcweir 	// Set default return value, if method failed.
133cdf0e10cSrcweir 	Reference< XConnectionPoint > xConnectionPoint = Reference< XConnectionPoint >();
134cdf0e10cSrcweir 
135cdf0e10cSrcweir 	// Get all elements of the container, which have the searched type.
136cdf0e10cSrcweir 	OInterfaceContainerHelper* pSpecialContainer = m_aMultiTypeContainer.getContainer( aType );
137cdf0e10cSrcweir 	if ( pSpecialContainer && pSpecialContainer->getLength() > 0 )
138cdf0e10cSrcweir 	{
139cdf0e10cSrcweir 		// Ready for multithreading
140cdf0e10cSrcweir 		MutexGuard aGuard( m_aSharedMutex );
141cdf0e10cSrcweir 		// If this container contains elements, build a connectionpoint-instance.
142cdf0e10cSrcweir 		OConnectionPointHelper* pNewConnectionPoint = new OConnectionPointHelper( m_aSharedMutex, this, aType );
143cdf0e10cSrcweir 		xConnectionPoint = Reference< XConnectionPoint >( (OWeakObject*)pNewConnectionPoint, UNO_QUERY );
144cdf0e10cSrcweir 	}
145cdf0e10cSrcweir 
146cdf0e10cSrcweir 	return xConnectionPoint ;
147cdf0e10cSrcweir }
148cdf0e10cSrcweir 
149cdf0e10cSrcweir //______________________________________________________________________________________________________________
150cdf0e10cSrcweir //	XConnectionPointContainer
151cdf0e10cSrcweir //______________________________________________________________________________________________________________
152cdf0e10cSrcweir 
advise(const Type & aType,const Reference<XInterface> & xListener)153cdf0e10cSrcweir void SAL_CALL OConnectionPointContainerHelper::advise(	const	Type&	   					aType		,
154cdf0e10cSrcweir 														const	Reference< XInterface >&	xListener	) throw( RuntimeException )
155cdf0e10cSrcweir {
156cdf0e10cSrcweir 	// Container is threadsafe himself !
157cdf0e10cSrcweir 	m_aMultiTypeContainer.addInterface( aType, xListener );
158cdf0e10cSrcweir }
159cdf0e10cSrcweir 
160cdf0e10cSrcweir //______________________________________________________________________________________________________________
161cdf0e10cSrcweir //	XConnectionPointContainer
162cdf0e10cSrcweir //______________________________________________________________________________________________________________
163cdf0e10cSrcweir 
unadvise(const Type & aType,const Reference<XInterface> & xListener)164cdf0e10cSrcweir void SAL_CALL OConnectionPointContainerHelper::unadvise(	const	Type&	   					aType		,
165cdf0e10cSrcweir 															const	Reference< XInterface >&	xListener	) throw( RuntimeException )
166cdf0e10cSrcweir {
167cdf0e10cSrcweir 	// Container is threadsafe himself !
168cdf0e10cSrcweir 	m_aMultiTypeContainer.removeInterface( aType, xListener );
169cdf0e10cSrcweir }
170cdf0e10cSrcweir 
171cdf0e10cSrcweir //______________________________________________________________________________________________________________
172cdf0e10cSrcweir //	public but impl method!
173*b4abecfeSPedro Giffuni //	Is necessary to get container member at OConnectionPoint-instance.
174cdf0e10cSrcweir //______________________________________________________________________________________________________________
175cdf0e10cSrcweir 
impl_getMultiTypeContainer()176cdf0e10cSrcweir OMultiTypeInterfaceContainerHelper& OConnectionPointContainerHelper::impl_getMultiTypeContainer()
177cdf0e10cSrcweir {
178cdf0e10cSrcweir 	// Impl methods are not threadsafe!
179cdf0e10cSrcweir 	// "Parent" function must do this.
180cdf0e10cSrcweir 	return m_aMultiTypeContainer;
181cdf0e10cSrcweir }
182cdf0e10cSrcweir 
183cdf0e10cSrcweir }	// namespace unocontrols
184