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