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 //______________________________________________________________________________________________________________
25 //	my own include
26 //______________________________________________________________________________________________________________
27 
28 #include "OConnectionPointContainerHelper.hxx"
29 
30 //______________________________________________________________________________________________________________
31 //	includes of other projects
32 //______________________________________________________________________________________________________________
33 
34 //______________________________________________________________________________________________________________
35 //	include of my own project
36 //______________________________________________________________________________________________________________
37 #include "OConnectionPointHelper.hxx"
38 
39 //______________________________________________________________________________________________________________
40 //	namespaces
41 //______________________________________________________________________________________________________________
42 
43 using namespace	::rtl					;
44 using namespace	::osl					;
45 using namespace	::cppu					;
46 using namespace	::com::sun::star::uno	;
47 using namespace	::com::sun::star::lang	;
48 
49 namespace unocontrols{
50 
51 //______________________________________________________________________________________________________________
52 //	construct/destruct
53 //______________________________________________________________________________________________________________
54 
OConnectionPointContainerHelper(Mutex & aMutex)55 OConnectionPointContainerHelper::OConnectionPointContainerHelper( Mutex& aMutex )
56 	: m_aSharedMutex		( aMutex	)
57 	, m_aMultiTypeContainer	( aMutex	)
58 {
59 }
60 
~OConnectionPointContainerHelper()61 OConnectionPointContainerHelper::~OConnectionPointContainerHelper()
62 {
63 }
64 
65 //____________________________________________________________________________________________________________
66 //	XInterface
67 //____________________________________________________________________________________________________________
68 
queryInterface(const Type & aType)69 Any SAL_CALL OConnectionPointContainerHelper::queryInterface( const Type& aType ) throw( RuntimeException )
70 {
71 	// Attention:
72 	//	Don't use mutex or guard in this method!!! Is a method of XInterface.
73 
74 	// Ask for my own supported interfaces ...
75 	Any aReturn	( ::cppu::queryInterface(	aType												,
76 									   		static_cast< XConnectionPointContainer*	> ( this )
77 										)
78 				);
79 
80 	// If searched interface not supported by this class ...
81 	if ( aReturn.hasValue() == sal_False )
82 	{
83 		// ... ask baseclasses.
84 		aReturn = OWeakObject::queryInterface( aType );
85 	}
86 
87 	return aReturn ;
88 }
89 
90 //____________________________________________________________________________________________________________
91 //	XInterface
92 //____________________________________________________________________________________________________________
93 
acquire()94 void SAL_CALL OConnectionPointContainerHelper::acquire() throw()
95 {
96 	// Attention:
97 	//	Don't use mutex or guard in this method!!! Is a method of XInterface.
98 
99 	// Forward to baseclass
100 	OWeakObject::acquire();
101 }
102 
103 //____________________________________________________________________________________________________________
104 //	XInterface
105 //____________________________________________________________________________________________________________
106 
release()107 void SAL_CALL OConnectionPointContainerHelper::release() throw()
108 {
109 	// Attention:
110 	//	Don't use mutex or guard in this method!!! Is a method of XInterface.
111 
112 	// Forward to baseclass
113 	OWeakObject::release();
114 }
115 
116 //______________________________________________________________________________________________________________
117 //	XConnectionPointContainer
118 //______________________________________________________________________________________________________________
119 
getConnectionPointTypes()120 Sequence< Type > SAL_CALL OConnectionPointContainerHelper::getConnectionPointTypes() throw( RuntimeException )
121 {
122 	// Container is threadsafe himself !
123 	return m_aMultiTypeContainer.getContainedTypes();
124 }
125 
126 //______________________________________________________________________________________________________________
127 //	XConnectionPointContainer
128 //______________________________________________________________________________________________________________
129 
queryConnectionPoint(const Type & aType)130 Reference< XConnectionPoint > SAL_CALL OConnectionPointContainerHelper::queryConnectionPoint( const Type& aType ) throw( RuntimeException )
131 {
132 	// Set default return value, if method failed.
133 	Reference< XConnectionPoint > xConnectionPoint = Reference< XConnectionPoint >();
134 
135 	// Get all elements of the container, which have the searched type.
136 	OInterfaceContainerHelper* pSpecialContainer = m_aMultiTypeContainer.getContainer( aType );
137 	if ( pSpecialContainer && pSpecialContainer->getLength() > 0 )
138 	{
139 		// Ready for multithreading
140 		MutexGuard aGuard( m_aSharedMutex );
141 		// If this container contains elements, build a connectionpoint-instance.
142 		OConnectionPointHelper* pNewConnectionPoint = new OConnectionPointHelper( m_aSharedMutex, this, aType );
143 		xConnectionPoint = Reference< XConnectionPoint >( (OWeakObject*)pNewConnectionPoint, UNO_QUERY );
144 	}
145 
146 	return xConnectionPoint ;
147 }
148 
149 //______________________________________________________________________________________________________________
150 //	XConnectionPointContainer
151 //______________________________________________________________________________________________________________
152 
advise(const Type & aType,const Reference<XInterface> & xListener)153 void SAL_CALL OConnectionPointContainerHelper::advise(	const	Type&	   					aType		,
154 														const	Reference< XInterface >&	xListener	) throw( RuntimeException )
155 {
156 	// Container is threadsafe himself !
157 	m_aMultiTypeContainer.addInterface( aType, xListener );
158 }
159 
160 //______________________________________________________________________________________________________________
161 //	XConnectionPointContainer
162 //______________________________________________________________________________________________________________
163 
unadvise(const Type & aType,const Reference<XInterface> & xListener)164 void SAL_CALL OConnectionPointContainerHelper::unadvise(	const	Type&	   					aType		,
165 															const	Reference< XInterface >&	xListener	) throw( RuntimeException )
166 {
167 	// Container is threadsafe himself !
168 	m_aMultiTypeContainer.removeInterface( aType, xListener );
169 }
170 
171 //______________________________________________________________________________________________________________
172 //	public but impl method!
173 //	Is neccessary to get container member at OConnectionPoint-instance.
174 //______________________________________________________________________________________________________________
175 
impl_getMultiTypeContainer()176 OMultiTypeInterfaceContainerHelper& OConnectionPointContainerHelper::impl_getMultiTypeContainer()
177 {
178 	// Impl methods are not threadsafe!
179 	// "Parent" function must do this.
180 	return m_aMultiTypeContainer;
181 }
182 
183 }	// namespace unocontrols
184