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 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 65 OConnectionPointHelper::~OConnectionPointHelper() 66 { 67 } 68 69 //____________________________________________________________________________________________________________ 70 // XInterface 71 //____________________________________________________________________________________________________________ 72 73 Any SAL_CALL OConnectionPointHelper::queryInterface( const Type& aType ) 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 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 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 124 Type SAL_CALL OConnectionPointHelper::getConnectionType() 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 148 Reference< XConnectionPointContainer > SAL_CALL OConnectionPointHelper::getConnectionPointContainer() 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 160 void SAL_CALL OConnectionPointHelper::advise( const Reference< XInterface >& xListener ) 161 { 162 // Ready for multithreading 163 MutexGuard aGuard( m_aSharedMutex ); 164 165 // If type of listener not the same for this special container ... 166 Any aCheckType = xListener->queryInterface( m_aInterfaceType ); 167 if ( aCheckType.hasValue() ) 168 { 169 // ... throw an exception. 170 throw InvalidListenerException(); 171 } 172 173 // ListenerExistException is obsolete!? 174 // Its the same container for XConnectionPointContainer and XConnectionPoint. But only here we must control, if a listener already exist!? 175 // You can add a listener more then one time at XConnectionPointContainer, but here only one ... 176 177 // Operation is permitted only, if reference to container is valid! 178 if ( impl_LockContainer() == sal_False ) 179 { 180 // Container not exist! Its an runtime error. 181 throw RuntimeException(); 182 } 183 // Forward it to OConnectionPointHelperContainer! 184 m_pContainerImplementation->advise( m_aInterfaceType, xListener ); 185 // Don't forget this! 186 impl_UnlockContainer(); 187 } 188 189 //______________________________________________________________________________________________________________ 190 // XConnectionPoint 191 //______________________________________________________________________________________________________________ 192 193 void SAL_CALL OConnectionPointHelper::unadvise( const Reference< XInterface >& xListener ) 194 { 195 // Ready for multithreading 196 MutexGuard aGuard( m_aSharedMutex ); 197 // Operation is permitted only, if reference to container is valid! 198 if ( impl_LockContainer() == sal_False ) 199 { 200 // Container not exist! Its an runtime error. 201 throw RuntimeException(); 202 203 } 204 // Forward it to OConnectionPointHelperContainer! 205 m_pContainerImplementation->unadvise( m_aInterfaceType, xListener ); 206 // Don't forget this! 207 impl_UnlockContainer(); 208 } 209 210 //______________________________________________________________________________________________________________ 211 // XConnectionPoint 212 //______________________________________________________________________________________________________________ 213 214 Sequence< Reference< XInterface > > SAL_CALL OConnectionPointHelper::getConnections() 215 { 216 // Ready for multithreading 217 MutexGuard aGuard( m_aSharedMutex ); 218 // Operation is permitted only, if reference to container is valid! 219 if ( impl_LockContainer() == sal_False ) 220 { 221 // Container not exist! Its an runtime error. 222 throw RuntimeException(); 223 } 224 // Set default return value, if method failed. 225 Sequence< Reference< XInterface > > seqReturnConnections = Sequence< Reference< XInterface > >(); 226 // Get reference to private member of OConnectionPointHelperContainer! 227 OMultiTypeInterfaceContainerHelper& aSharedContainer = m_pContainerImplementation->impl_getMultiTypeContainer(); 228 // Get pointer to specialized container which hold all interfaces of searched type. 229 OInterfaceContainerHelper* pSpecialContainer = aSharedContainer.getContainer( m_aInterfaceType ); 230 // Get elements of searched type, if somelse exist. 231 if ( pSpecialContainer != NULL ) 232 { 233 seqReturnConnections = pSpecialContainer->getElements(); 234 } 235 // Don't forget this! 236 impl_UnlockContainer(); 237 238 return seqReturnConnections; 239 } 240 241 //______________________________________________________________________________________________________________ 242 // private method 243 //______________________________________________________________________________________________________________ 244 245 sal_Bool OConnectionPointHelper::impl_LockContainer() 246 { 247 // Convert weakreference to hard uno3-reference and return state. 248 // If this reference different from NULL, there exist a hard reference to container. Container-instance can't be destroyed. 249 // Don't forget to "unlock" this reference! 250 m_xLock = m_oContainerWeakReference.get(); 251 return m_xLock.is(); 252 } 253 254 //______________________________________________________________________________________________________________ 255 // private method 256 //______________________________________________________________________________________________________________ 257 258 void OConnectionPointHelper::impl_UnlockContainer() 259 { 260 // Free hard uno3-reference to container. 261 // see also "impl_LockContainer()" 262 m_xLock = Reference< XInterface >(); 263 } 264 265 } // namespace unocontrols 266