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 "OConnectionPointHelper.hxx"
29
30 //______________________________________________________________________________________________________________
31 // includes of other projects
32 //______________________________________________________________________________________________________________
33
34 //______________________________________________________________________________________________________________
35 // include of my own project
36 //______________________________________________________________________________________________________________
37 #include "OConnectionPointContainerHelper.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
OConnectionPointHelper(Mutex & aMutex,OConnectionPointContainerHelper * pContainerImplementation,UNO3_TYPE aType)55 OConnectionPointHelper::OConnectionPointHelper( Mutex& aMutex ,
56 OConnectionPointContainerHelper* pContainerImplementation ,
57 UNO3_TYPE aType )
58 : m_aSharedMutex ( aMutex )
59 , m_oContainerWeakReference ( pContainerImplementation )
60 , m_pContainerImplementation ( pContainerImplementation )
61 , m_aInterfaceType ( aType )
62 {
63 }
64
~OConnectionPointHelper()65 OConnectionPointHelper::~OConnectionPointHelper()
66 {
67 }
68
69 //____________________________________________________________________________________________________________
70 // XInterface
71 //____________________________________________________________________________________________________________
72
queryInterface(const Type & aType)73 Any SAL_CALL OConnectionPointHelper::queryInterface( const Type& aType ) throw( RuntimeException )
74 {
75 // Attention:
76 // Don't use mutex or guard in this method!!! Is a method of XInterface.
77
78 // Ask for my own supported interfaces ...
79 Any aReturn ( ::cppu::queryInterface( aType ,
80 static_cast< XConnectionPoint* > ( this )
81 )
82 );
83
84 // If searched interface not supported by this class ...
85 if ( aReturn.hasValue() == sal_False )
86 {
87 // ... ask baseclasses.
88 aReturn = OWeakObject::queryInterface( aType );
89 }
90
91 return aReturn ;
92 }
93
94 //____________________________________________________________________________________________________________
95 // XInterface
96 //____________________________________________________________________________________________________________
97
acquire()98 void SAL_CALL OConnectionPointHelper::acquire() throw()
99 {
100 // Attention:
101 // Don't use mutex or guard in this method!!! Is a method of XInterface.
102
103 // Forward to baseclass
104 OWeakObject::acquire();
105 }
106
107 //____________________________________________________________________________________________________________
108 // XInterface
109 //____________________________________________________________________________________________________________
110
release()111 void SAL_CALL OConnectionPointHelper::release() throw()
112 {
113 // Attention:
114 // Don't use mutex or guard in this method!!! Is a method of XInterface.
115
116 // Forward to baseclass
117 OWeakObject::release();
118 }
119
120 //______________________________________________________________________________________________________________
121 // XConnectionPoint
122 //______________________________________________________________________________________________________________
123
getConnectionType()124 Type SAL_CALL OConnectionPointHelper::getConnectionType() throw( RuntimeException )
125 {
126 // Ready for multithreading
127 MutexGuard aGuard( m_aSharedMutex );
128
129 // Set default return value, if method failed.
130 if ( impl_LockContainer() == sal_False )
131 {
132 // Container not exist! Its an runtime error.
133 throw RuntimeException();
134 }
135
136 // If container reference valid, return right type of supported interfaces of THIS connectionpoint.
137 Type aReturnType = m_aInterfaceType ;
138 // Don't forget this!
139 impl_UnlockContainer();
140
141 return aReturnType;
142 }
143
144 //______________________________________________________________________________________________________________
145 // XConnectionPoint
146 //______________________________________________________________________________________________________________
147
getConnectionPointContainer()148 Reference< XConnectionPointContainer > SAL_CALL OConnectionPointHelper::getConnectionPointContainer() throw( RuntimeException )
149 {
150 // Ready for multithreading
151 MutexGuard aGuard( m_aSharedMutex );
152 // Convert weakreference to correct uno3-reference and return value. It can be NULL, if container destroyed!
153 return Reference< XConnectionPointContainer >( m_oContainerWeakReference.get(), UNO_QUERY );
154 }
155
156 //______________________________________________________________________________________________________________
157 // XConnectionPoint
158 //______________________________________________________________________________________________________________
159
advise(const Reference<XInterface> & xListener)160 void SAL_CALL OConnectionPointHelper::advise( const Reference< XInterface >& xListener ) throw( ListenerExistException ,
161 InvalidListenerException ,
162 RuntimeException )
163 {
164 // Ready for multithreading
165 MutexGuard aGuard( m_aSharedMutex );
166
167 // If type of listener not the same for this special container ...
168 Any aCheckType = xListener->queryInterface( m_aInterfaceType );
169 if ( aCheckType.hasValue() )
170 {
171 // ... throw an exception.
172 throw InvalidListenerException();
173 }
174
175 // ListenerExistException is obsolete!?
176 // Its the same container for XConnectionPointContainer and XConnectionPoint. But only here we must control, if a listener already exist!?
177 // You can add a listener more then one time at XConnectionPointContainer, but here only one ...
178
179 // Operation is permitted only, if reference to container is valid!
180 if ( impl_LockContainer() == sal_False )
181 {
182 // Container not exist! Its an runtime error.
183 throw RuntimeException();
184 }
185 // Forward it to OConnectionPointHelperContainer!
186 m_pContainerImplementation->advise( m_aInterfaceType, xListener );
187 // Don't forget this!
188 impl_UnlockContainer();
189 }
190
191 //______________________________________________________________________________________________________________
192 // XConnectionPoint
193 //______________________________________________________________________________________________________________
194
unadvise(const Reference<XInterface> & xListener)195 void SAL_CALL OConnectionPointHelper::unadvise( const Reference< XInterface >& xListener ) throw( RuntimeException )
196 {
197 // Ready for multithreading
198 MutexGuard aGuard( m_aSharedMutex );
199 // Operation is permitted only, if reference to container is valid!
200 if ( impl_LockContainer() == sal_False )
201 {
202 // Container not exist! Its an runtime error.
203 throw RuntimeException();
204
205 }
206 // Forward it to OConnectionPointHelperContainer!
207 m_pContainerImplementation->unadvise( m_aInterfaceType, xListener );
208 // Don't forget this!
209 impl_UnlockContainer();
210 }
211
212 //______________________________________________________________________________________________________________
213 // XConnectionPoint
214 //______________________________________________________________________________________________________________
215
getConnections()216 Sequence< Reference< XInterface > > SAL_CALL OConnectionPointHelper::getConnections() throw( RuntimeException )
217 {
218 // Ready for multithreading
219 MutexGuard aGuard( m_aSharedMutex );
220 // Operation is permitted only, if reference to container is valid!
221 if ( impl_LockContainer() == sal_False )
222 {
223 // Container not exist! Its an runtime error.
224 throw RuntimeException();
225 }
226 // Set default return value, if method failed.
227 Sequence< Reference< XInterface > > seqReturnConnections = Sequence< Reference< XInterface > >();
228 // Get reference to private member of OConnectionPointHelperContainer!
229 OMultiTypeInterfaceContainerHelper& aSharedContainer = m_pContainerImplementation->impl_getMultiTypeContainer();
230 // Get pointer to specialized container which hold all interfaces of searched type.
231 OInterfaceContainerHelper* pSpecialContainer = aSharedContainer.getContainer( m_aInterfaceType );
232 // Get elements of searched type, if somelse exist.
233 if ( pSpecialContainer != NULL )
234 {
235 seqReturnConnections = pSpecialContainer->getElements();
236 }
237 // Don't forget this!
238 impl_UnlockContainer();
239
240 return seqReturnConnections;
241 }
242
243 //______________________________________________________________________________________________________________
244 // private method
245 //______________________________________________________________________________________________________________
246
impl_LockContainer()247 sal_Bool OConnectionPointHelper::impl_LockContainer()
248 {
249 // Convert weakreference to hard uno3-reference and return state.
250 // If this reference different from NULL, there exist a hard reference to container. Container-instance can't be destroyed.
251 // Don't forget to "unlock" this reference!
252 m_xLock = m_oContainerWeakReference.get();
253 return m_xLock.is();
254 }
255
256 //______________________________________________________________________________________________________________
257 // private method
258 //______________________________________________________________________________________________________________
259
impl_UnlockContainer()260 void OConnectionPointHelper::impl_UnlockContainer()
261 {
262 // Free hard uno3-reference to container.
263 // see also "impl_LockContainer()"
264 m_xLock = Reference< XInterface >();
265 }
266
267 } // namespace unocontrols
268