1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: OConnectionPointHelper.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 //______________________________________________________________________________________________________________
33 //______________________________________________________________________________________________________________
35 #include "OConnectionPointHelper.hxx"
37 //______________________________________________________________________________________________________________
38 // includes of other projects
39 //______________________________________________________________________________________________________________
41 //______________________________________________________________________________________________________________
42 // include of my own project
43 //______________________________________________________________________________________________________________
44 #include "OConnectionPointContainerHelper.hxx"
46 //______________________________________________________________________________________________________________
48 //______________________________________________________________________________________________________________
50 using namespace ::rtl
;
51 using namespace ::osl
;
52 using namespace ::cppu
;
53 using namespace ::com::sun::star::uno
;
54 using namespace ::com::sun::star::lang
;
56 namespace unocontrols
{
58 //______________________________________________________________________________________________________________
60 //______________________________________________________________________________________________________________
62 OConnectionPointHelper::OConnectionPointHelper( Mutex
& aMutex
,
63 OConnectionPointContainerHelper
* pContainerImplementation
,
65 : m_aSharedMutex ( aMutex
)
66 , m_oContainerWeakReference ( pContainerImplementation
)
67 , m_pContainerImplementation ( pContainerImplementation
)
68 , m_aInterfaceType ( aType
)
72 OConnectionPointHelper::~OConnectionPointHelper()
76 //____________________________________________________________________________________________________________
78 //____________________________________________________________________________________________________________
80 Any SAL_CALL
OConnectionPointHelper::queryInterface( const Type
& aType
) throw( RuntimeException
)
83 // Don't use mutex or guard in this method!!! Is a method of XInterface.
85 // Ask for my own supported interfaces ...
86 Any
aReturn ( ::cppu::queryInterface( aType
,
87 static_cast< XConnectionPoint
* > ( this )
91 // If searched interface not supported by this class ...
92 if ( aReturn
.hasValue() == sal_False
)
94 // ... ask baseclasses.
95 aReturn
= OWeakObject::queryInterface( aType
);
101 //____________________________________________________________________________________________________________
103 //____________________________________________________________________________________________________________
105 void SAL_CALL
OConnectionPointHelper::acquire() throw()
108 // Don't use mutex or guard in this method!!! Is a method of XInterface.
110 // Forward to baseclass
111 OWeakObject::acquire();
114 //____________________________________________________________________________________________________________
116 //____________________________________________________________________________________________________________
118 void SAL_CALL
OConnectionPointHelper::release() throw()
121 // Don't use mutex or guard in this method!!! Is a method of XInterface.
123 // Forward to baseclass
124 OWeakObject::release();
127 //______________________________________________________________________________________________________________
129 //______________________________________________________________________________________________________________
131 Type SAL_CALL
OConnectionPointHelper::getConnectionType() throw( RuntimeException
)
133 // Ready for multithreading
134 MutexGuard
aGuard( m_aSharedMutex
);
136 // Set default return value, if method failed.
137 if ( impl_LockContainer() == sal_False
)
139 // Container not exist! Its an runtime error.
140 throw RuntimeException();
143 // If container reference valid, return right type of supported interfaces of THIS connectionpoint.
144 Type aReturnType
= m_aInterfaceType
;
145 // Don't forget this!
146 impl_UnlockContainer();
151 //______________________________________________________________________________________________________________
153 //______________________________________________________________________________________________________________
155 Reference
< XConnectionPointContainer
> SAL_CALL
OConnectionPointHelper::getConnectionPointContainer() throw( RuntimeException
)
157 // Ready for multithreading
158 MutexGuard
aGuard( m_aSharedMutex
);
159 // Convert weakreference to correct uno3-reference and return value. It can be NULL, if container destroyed!
160 return Reference
< XConnectionPointContainer
>( m_oContainerWeakReference
.get(), UNO_QUERY
);
163 //______________________________________________________________________________________________________________
165 //______________________________________________________________________________________________________________
167 void SAL_CALL
OConnectionPointHelper::advise( const Reference
< XInterface
>& xListener
) throw( ListenerExistException
,
168 InvalidListenerException
,
171 // Ready for multithreading
172 MutexGuard
aGuard( m_aSharedMutex
);
174 // If type of listener not the same for this special container ...
175 Any aCheckType
= xListener
->queryInterface( m_aInterfaceType
);
176 if ( aCheckType
.hasValue() )
178 // ... throw an exception.
179 throw InvalidListenerException();
182 // ListenerExistException is obsolete!?
183 // Its the same container for XConnectionPointContainer and XConnectionPoint. But only here we must control, if a listener already exist!?
184 // You can add a listener more then one time at XConnectionPointContainer, but here only one ...
186 // Operation is permitted only, if reference to container is valid!
187 if ( impl_LockContainer() == sal_False
)
189 // Container not exist! Its an runtime error.
190 throw RuntimeException();
192 // Forward it to OConnectionPointHelperContainer!
193 m_pContainerImplementation
->advise( m_aInterfaceType
, xListener
);
194 // Don't forget this!
195 impl_UnlockContainer();
198 //______________________________________________________________________________________________________________
200 //______________________________________________________________________________________________________________
202 void SAL_CALL
OConnectionPointHelper::unadvise( const Reference
< XInterface
>& xListener
) throw( RuntimeException
)
204 // Ready for multithreading
205 MutexGuard
aGuard( m_aSharedMutex
);
206 // Operation is permitted only, if reference to container is valid!
207 if ( impl_LockContainer() == sal_False
)
209 // Container not exist! Its an runtime error.
210 throw RuntimeException();
213 // Forward it to OConnectionPointHelperContainer!
214 m_pContainerImplementation
->unadvise( m_aInterfaceType
, xListener
);
215 // Don't forget this!
216 impl_UnlockContainer();
219 //______________________________________________________________________________________________________________
221 //______________________________________________________________________________________________________________
223 Sequence
< Reference
< XInterface
> > SAL_CALL
OConnectionPointHelper::getConnections() throw( RuntimeException
)
225 // Ready for multithreading
226 MutexGuard
aGuard( m_aSharedMutex
);
227 // Operation is permitted only, if reference to container is valid!
228 if ( impl_LockContainer() == sal_False
)
230 // Container not exist! Its an runtime error.
231 throw RuntimeException();
233 // Set default return value, if method failed.
234 Sequence
< Reference
< XInterface
> > seqReturnConnections
= Sequence
< Reference
< XInterface
> >();
235 // Get reference to private member of OConnectionPointHelperContainer!
236 OMultiTypeInterfaceContainerHelper
& aSharedContainer
= m_pContainerImplementation
->impl_getMultiTypeContainer();
237 // Get pointer to specialized container which hold all interfaces of searched type.
238 OInterfaceContainerHelper
* pSpecialContainer
= aSharedContainer
.getContainer( m_aInterfaceType
);
239 // Get elements of searched type, if somelse exist.
240 if ( pSpecialContainer
!= NULL
)
242 seqReturnConnections
= pSpecialContainer
->getElements();
244 // Don't forget this!
245 impl_UnlockContainer();
247 return seqReturnConnections
;
250 //______________________________________________________________________________________________________________
252 //______________________________________________________________________________________________________________
254 sal_Bool
OConnectionPointHelper::impl_LockContainer()
256 // Convert weakreference to hard uno3-reference and return state.
257 // If this reference different from NULL, there exist a hard reference to container. Container-instance can't be destroyed.
258 // Don't forget to "unlock" this reference!
259 m_xLock
= m_oContainerWeakReference
.get();
263 //______________________________________________________________________________________________________________
265 //______________________________________________________________________________________________________________
267 void OConnectionPointHelper::impl_UnlockContainer()
269 // Free hard uno3-reference to container.
270 // see also "impl_LockContainer()"
271 m_xLock
= Reference
< XInterface
>();
274 } // namespace unocontrols