1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
29 //______________________________________________________________________________________________________________
31 //______________________________________________________________________________________________________________
33 #include "OConnectionPointHelper.hxx"
35 //______________________________________________________________________________________________________________
36 // includes of other projects
37 //______________________________________________________________________________________________________________
39 //______________________________________________________________________________________________________________
40 // include of my own project
41 //______________________________________________________________________________________________________________
42 #include "OConnectionPointContainerHelper.hxx"
44 //______________________________________________________________________________________________________________
46 //______________________________________________________________________________________________________________
48 using namespace ::rtl
;
49 using namespace ::osl
;
50 using namespace ::cppu
;
51 using namespace ::com::sun::star::uno
;
52 using namespace ::com::sun::star::lang
;
54 namespace unocontrols
{
56 //______________________________________________________________________________________________________________
58 //______________________________________________________________________________________________________________
60 OConnectionPointHelper::OConnectionPointHelper(
62 OConnectionPointContainerHelper
* pContainerImplementation
,
64 ) : m_aSharedMutex ( aMutex
)
65 , m_oContainerWeakReference ( pContainerImplementation
)
66 , m_pContainerImplementation ( pContainerImplementation
)
67 , m_aInterfaceType ( aType
)
71 OConnectionPointHelper::~OConnectionPointHelper()
75 //____________________________________________________________________________________________________________
77 //____________________________________________________________________________________________________________
79 Any SAL_CALL
OConnectionPointHelper::queryInterface( const Type
& aType
) throw( RuntimeException
)
82 // Don't use mutex or guard in this method!!! Is a method of XInterface.
84 // Ask for my own supported interfaces ...
85 Any
aReturn ( ::cppu::queryInterface( aType
,
86 static_cast< XConnectionPoint
* > ( this )
90 // If searched interface not supported by this class ...
91 if ( aReturn
.hasValue() == sal_False
)
93 // ... ask baseclasses.
94 aReturn
= OWeakObject::queryInterface( aType
);
100 //____________________________________________________________________________________________________________
102 //____________________________________________________________________________________________________________
104 void SAL_CALL
OConnectionPointHelper::acquire() throw()
107 // Don't use mutex or guard in this method!!! Is a method of XInterface.
109 // Forward to baseclass
110 OWeakObject::acquire();
113 //____________________________________________________________________________________________________________
115 //____________________________________________________________________________________________________________
117 void SAL_CALL
OConnectionPointHelper::release() throw()
120 // Don't use mutex or guard in this method!!! Is a method of XInterface.
122 // Forward to baseclass
123 OWeakObject::release();
126 //______________________________________________________________________________________________________________
128 //______________________________________________________________________________________________________________
130 Type SAL_CALL
OConnectionPointHelper::getConnectionType() throw( RuntimeException
)
132 // Ready for multithreading
133 MutexGuard
aGuard( m_aSharedMutex
);
135 // Set default return value, if method failed.
136 if ( impl_LockContainer() == sal_False
)
138 // Container not exist! Its an runtime error.
139 throw RuntimeException();
142 // If container reference valid, return right type of supported interfaces of THIS connectionpoint.
143 Type aReturnType
= m_aInterfaceType
;
144 // Don't forget this!
145 impl_UnlockContainer();
150 //______________________________________________________________________________________________________________
152 //______________________________________________________________________________________________________________
154 Reference
< XConnectionPointContainer
> SAL_CALL
OConnectionPointHelper::getConnectionPointContainer() throw( RuntimeException
)
156 // Ready for multithreading
157 MutexGuard
aGuard( m_aSharedMutex
);
158 // Convert weakreference to correct uno3-reference and return value. It can be NULL, if container destroyed!
159 return Reference
< XConnectionPointContainer
>( m_oContainerWeakReference
.get(), UNO_QUERY
);
162 //______________________________________________________________________________________________________________
164 //______________________________________________________________________________________________________________
166 void SAL_CALL
OConnectionPointHelper::advise( const Reference
< XInterface
>& xListener
) throw( ListenerExistException
,
167 InvalidListenerException
,
170 // Ready for multithreading
171 MutexGuard
aGuard( m_aSharedMutex
);
173 // If type of listener not the same for this special container ...
174 Any aCheckType
= xListener
->queryInterface( m_aInterfaceType
);
175 if ( aCheckType
.hasValue() )
177 // ... throw an exception.
178 throw InvalidListenerException();
181 // ListenerExistException is obsolete!?
182 // Its the same container for XConnectionPointContainer and XConnectionPoint. But only here we must control, if a listener already exist!?
183 // You can add a listener more then one time at XConnectionPointContainer, but here only one ...
185 // Operation is permitted only, if reference to container is valid!
186 if ( impl_LockContainer() == sal_False
)
188 // Container not exist! Its an runtime error.
189 throw RuntimeException();
191 // Forward it to OConnectionPointHelperContainer!
192 m_pContainerImplementation
->advise( m_aInterfaceType
, xListener
);
193 // Don't forget this!
194 impl_UnlockContainer();
197 //______________________________________________________________________________________________________________
199 //______________________________________________________________________________________________________________
201 void SAL_CALL
OConnectionPointHelper::unadvise( const Reference
< XInterface
>& xListener
) throw( RuntimeException
)
203 // Ready for multithreading
204 MutexGuard
aGuard( m_aSharedMutex
);
205 // Operation is permitted only, if reference to container is valid!
206 if ( impl_LockContainer() == sal_False
)
208 // Container not exist! Its an runtime error.
209 throw RuntimeException();
212 // Forward it to OConnectionPointHelperContainer!
213 m_pContainerImplementation
->unadvise( m_aInterfaceType
, xListener
);
214 // Don't forget this!
215 impl_UnlockContainer();
218 //______________________________________________________________________________________________________________
220 //______________________________________________________________________________________________________________
222 Sequence
< Reference
< XInterface
> > SAL_CALL
OConnectionPointHelper::getConnections() throw( RuntimeException
)
224 // Ready for multithreading
225 MutexGuard
aGuard( m_aSharedMutex
);
226 // Operation is permitted only, if reference to container is valid!
227 if ( impl_LockContainer() == sal_False
)
229 // Container not exist! Its an runtime error.
230 throw RuntimeException();
232 // Set default return value, if method failed.
233 Sequence
< Reference
< XInterface
> > seqReturnConnections
= Sequence
< Reference
< XInterface
> >();
234 // Get reference to private member of OConnectionPointHelperContainer!
235 OMultiTypeInterfaceContainerHelper
& aSharedContainer
= m_pContainerImplementation
->impl_getMultiTypeContainer();
236 // Get pointer to specialized container which hold all interfaces of searched type.
237 OInterfaceContainerHelper
* pSpecialContainer
= aSharedContainer
.getContainer( m_aInterfaceType
);
238 // Get elements of searched type, if somelse exist.
239 if ( pSpecialContainer
!= NULL
)
241 seqReturnConnections
= pSpecialContainer
->getElements();
243 // Don't forget this!
244 impl_UnlockContainer();
246 return seqReturnConnections
;
249 //______________________________________________________________________________________________________________
251 //______________________________________________________________________________________________________________
253 sal_Bool
OConnectionPointHelper::impl_LockContainer()
255 // Convert weakreference to hard uno3-reference and return state.
256 // If this reference different from NULL, there exist a hard reference to container. Container-instance can't be destroyed.
257 // Don't forget to "unlock" this reference!
258 m_xLock
= m_oContainerWeakReference
.get();
262 //______________________________________________________________________________________________________________
264 //______________________________________________________________________________________________________________
266 void OConnectionPointHelper::impl_UnlockContainer()
268 // Free hard uno3-reference to container.
269 // see also "impl_LockContainer()"
270 m_xLock
= Reference
< XInterface
>();
273 } // namespace unocontrols
275 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */