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