1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir //______________________________________________________________________________________________________________ 29*cdf0e10cSrcweir // my own include 30*cdf0e10cSrcweir //______________________________________________________________________________________________________________ 31*cdf0e10cSrcweir 32*cdf0e10cSrcweir #include "OConnectionPointHelper.hxx" 33*cdf0e10cSrcweir 34*cdf0e10cSrcweir //______________________________________________________________________________________________________________ 35*cdf0e10cSrcweir // includes of other projects 36*cdf0e10cSrcweir //______________________________________________________________________________________________________________ 37*cdf0e10cSrcweir 38*cdf0e10cSrcweir //______________________________________________________________________________________________________________ 39*cdf0e10cSrcweir // include of my own project 40*cdf0e10cSrcweir //______________________________________________________________________________________________________________ 41*cdf0e10cSrcweir #include "OConnectionPointContainerHelper.hxx" 42*cdf0e10cSrcweir 43*cdf0e10cSrcweir //______________________________________________________________________________________________________________ 44*cdf0e10cSrcweir // namespaces 45*cdf0e10cSrcweir //______________________________________________________________________________________________________________ 46*cdf0e10cSrcweir 47*cdf0e10cSrcweir using namespace ::rtl ; 48*cdf0e10cSrcweir using namespace ::osl ; 49*cdf0e10cSrcweir using namespace ::cppu ; 50*cdf0e10cSrcweir using namespace ::com::sun::star::uno ; 51*cdf0e10cSrcweir using namespace ::com::sun::star::lang ; 52*cdf0e10cSrcweir 53*cdf0e10cSrcweir namespace unocontrols{ 54*cdf0e10cSrcweir 55*cdf0e10cSrcweir //______________________________________________________________________________________________________________ 56*cdf0e10cSrcweir // construct/destruct 57*cdf0e10cSrcweir //______________________________________________________________________________________________________________ 58*cdf0e10cSrcweir 59*cdf0e10cSrcweir OConnectionPointHelper::OConnectionPointHelper( Mutex& aMutex , 60*cdf0e10cSrcweir OConnectionPointContainerHelper* pContainerImplementation , 61*cdf0e10cSrcweir UNO3_TYPE aType ) 62*cdf0e10cSrcweir : m_aSharedMutex ( aMutex ) 63*cdf0e10cSrcweir , m_oContainerWeakReference ( pContainerImplementation ) 64*cdf0e10cSrcweir , m_pContainerImplementation ( pContainerImplementation ) 65*cdf0e10cSrcweir , m_aInterfaceType ( aType ) 66*cdf0e10cSrcweir { 67*cdf0e10cSrcweir } 68*cdf0e10cSrcweir 69*cdf0e10cSrcweir OConnectionPointHelper::~OConnectionPointHelper() 70*cdf0e10cSrcweir { 71*cdf0e10cSrcweir } 72*cdf0e10cSrcweir 73*cdf0e10cSrcweir //____________________________________________________________________________________________________________ 74*cdf0e10cSrcweir // XInterface 75*cdf0e10cSrcweir //____________________________________________________________________________________________________________ 76*cdf0e10cSrcweir 77*cdf0e10cSrcweir Any SAL_CALL OConnectionPointHelper::queryInterface( const Type& aType ) throw( RuntimeException ) 78*cdf0e10cSrcweir { 79*cdf0e10cSrcweir // Attention: 80*cdf0e10cSrcweir // Don't use mutex or guard in this method!!! Is a method of XInterface. 81*cdf0e10cSrcweir 82*cdf0e10cSrcweir // Ask for my own supported interfaces ... 83*cdf0e10cSrcweir Any aReturn ( ::cppu::queryInterface( aType , 84*cdf0e10cSrcweir static_cast< XConnectionPoint* > ( this ) 85*cdf0e10cSrcweir ) 86*cdf0e10cSrcweir ); 87*cdf0e10cSrcweir 88*cdf0e10cSrcweir // If searched interface not supported by this class ... 89*cdf0e10cSrcweir if ( aReturn.hasValue() == sal_False ) 90*cdf0e10cSrcweir { 91*cdf0e10cSrcweir // ... ask baseclasses. 92*cdf0e10cSrcweir aReturn = OWeakObject::queryInterface( aType ); 93*cdf0e10cSrcweir } 94*cdf0e10cSrcweir 95*cdf0e10cSrcweir return aReturn ; 96*cdf0e10cSrcweir } 97*cdf0e10cSrcweir 98*cdf0e10cSrcweir //____________________________________________________________________________________________________________ 99*cdf0e10cSrcweir // XInterface 100*cdf0e10cSrcweir //____________________________________________________________________________________________________________ 101*cdf0e10cSrcweir 102*cdf0e10cSrcweir void SAL_CALL OConnectionPointHelper::acquire() throw() 103*cdf0e10cSrcweir { 104*cdf0e10cSrcweir // Attention: 105*cdf0e10cSrcweir // Don't use mutex or guard in this method!!! Is a method of XInterface. 106*cdf0e10cSrcweir 107*cdf0e10cSrcweir // Forward to baseclass 108*cdf0e10cSrcweir OWeakObject::acquire(); 109*cdf0e10cSrcweir } 110*cdf0e10cSrcweir 111*cdf0e10cSrcweir //____________________________________________________________________________________________________________ 112*cdf0e10cSrcweir // XInterface 113*cdf0e10cSrcweir //____________________________________________________________________________________________________________ 114*cdf0e10cSrcweir 115*cdf0e10cSrcweir void SAL_CALL OConnectionPointHelper::release() throw() 116*cdf0e10cSrcweir { 117*cdf0e10cSrcweir // Attention: 118*cdf0e10cSrcweir // Don't use mutex or guard in this method!!! Is a method of XInterface. 119*cdf0e10cSrcweir 120*cdf0e10cSrcweir // Forward to baseclass 121*cdf0e10cSrcweir OWeakObject::release(); 122*cdf0e10cSrcweir } 123*cdf0e10cSrcweir 124*cdf0e10cSrcweir //______________________________________________________________________________________________________________ 125*cdf0e10cSrcweir // XConnectionPoint 126*cdf0e10cSrcweir //______________________________________________________________________________________________________________ 127*cdf0e10cSrcweir 128*cdf0e10cSrcweir Type SAL_CALL OConnectionPointHelper::getConnectionType() throw( RuntimeException ) 129*cdf0e10cSrcweir { 130*cdf0e10cSrcweir // Ready for multithreading 131*cdf0e10cSrcweir MutexGuard aGuard( m_aSharedMutex ); 132*cdf0e10cSrcweir 133*cdf0e10cSrcweir // Set default return value, if method failed. 134*cdf0e10cSrcweir if ( impl_LockContainer() == sal_False ) 135*cdf0e10cSrcweir { 136*cdf0e10cSrcweir // Container not exist! Its an runtime error. 137*cdf0e10cSrcweir throw RuntimeException(); 138*cdf0e10cSrcweir } 139*cdf0e10cSrcweir 140*cdf0e10cSrcweir // If container reference valid, return right type of supported interfaces of THIS connectionpoint. 141*cdf0e10cSrcweir Type aReturnType = m_aInterfaceType ; 142*cdf0e10cSrcweir // Don't forget this! 143*cdf0e10cSrcweir impl_UnlockContainer(); 144*cdf0e10cSrcweir 145*cdf0e10cSrcweir return aReturnType; 146*cdf0e10cSrcweir } 147*cdf0e10cSrcweir 148*cdf0e10cSrcweir //______________________________________________________________________________________________________________ 149*cdf0e10cSrcweir // XConnectionPoint 150*cdf0e10cSrcweir //______________________________________________________________________________________________________________ 151*cdf0e10cSrcweir 152*cdf0e10cSrcweir Reference< XConnectionPointContainer > SAL_CALL OConnectionPointHelper::getConnectionPointContainer() throw( RuntimeException ) 153*cdf0e10cSrcweir { 154*cdf0e10cSrcweir // Ready for multithreading 155*cdf0e10cSrcweir MutexGuard aGuard( m_aSharedMutex ); 156*cdf0e10cSrcweir // Convert weakreference to correct uno3-reference and return value. It can be NULL, if container destroyed! 157*cdf0e10cSrcweir return Reference< XConnectionPointContainer >( m_oContainerWeakReference.get(), UNO_QUERY ); 158*cdf0e10cSrcweir } 159*cdf0e10cSrcweir 160*cdf0e10cSrcweir //______________________________________________________________________________________________________________ 161*cdf0e10cSrcweir // XConnectionPoint 162*cdf0e10cSrcweir //______________________________________________________________________________________________________________ 163*cdf0e10cSrcweir 164*cdf0e10cSrcweir void SAL_CALL OConnectionPointHelper::advise( const Reference< XInterface >& xListener ) throw( ListenerExistException , 165*cdf0e10cSrcweir InvalidListenerException , 166*cdf0e10cSrcweir RuntimeException ) 167*cdf0e10cSrcweir { 168*cdf0e10cSrcweir // Ready for multithreading 169*cdf0e10cSrcweir MutexGuard aGuard( m_aSharedMutex ); 170*cdf0e10cSrcweir 171*cdf0e10cSrcweir // If type of listener not the same for this special container ... 172*cdf0e10cSrcweir Any aCheckType = xListener->queryInterface( m_aInterfaceType ); 173*cdf0e10cSrcweir if ( aCheckType.hasValue() ) 174*cdf0e10cSrcweir { 175*cdf0e10cSrcweir // ... throw an exception. 176*cdf0e10cSrcweir throw InvalidListenerException(); 177*cdf0e10cSrcweir } 178*cdf0e10cSrcweir 179*cdf0e10cSrcweir // ListenerExistException is obsolete!? 180*cdf0e10cSrcweir // Its the same container for XConnectionPointContainer and XConnectionPoint. But only here we must control, if a listener already exist!? 181*cdf0e10cSrcweir // You can add a listener more then one time at XConnectionPointContainer, but here only one ... 182*cdf0e10cSrcweir 183*cdf0e10cSrcweir // Operation is permitted only, if reference to container is valid! 184*cdf0e10cSrcweir if ( impl_LockContainer() == sal_False ) 185*cdf0e10cSrcweir { 186*cdf0e10cSrcweir // Container not exist! Its an runtime error. 187*cdf0e10cSrcweir throw RuntimeException(); 188*cdf0e10cSrcweir } 189*cdf0e10cSrcweir // Forward it to OConnectionPointHelperContainer! 190*cdf0e10cSrcweir m_pContainerImplementation->advise( m_aInterfaceType, xListener ); 191*cdf0e10cSrcweir // Don't forget this! 192*cdf0e10cSrcweir impl_UnlockContainer(); 193*cdf0e10cSrcweir } 194*cdf0e10cSrcweir 195*cdf0e10cSrcweir //______________________________________________________________________________________________________________ 196*cdf0e10cSrcweir // XConnectionPoint 197*cdf0e10cSrcweir //______________________________________________________________________________________________________________ 198*cdf0e10cSrcweir 199*cdf0e10cSrcweir void SAL_CALL OConnectionPointHelper::unadvise( const Reference< XInterface >& xListener ) throw( RuntimeException ) 200*cdf0e10cSrcweir { 201*cdf0e10cSrcweir // Ready for multithreading 202*cdf0e10cSrcweir MutexGuard aGuard( m_aSharedMutex ); 203*cdf0e10cSrcweir // Operation is permitted only, if reference to container is valid! 204*cdf0e10cSrcweir if ( impl_LockContainer() == sal_False ) 205*cdf0e10cSrcweir { 206*cdf0e10cSrcweir // Container not exist! Its an runtime error. 207*cdf0e10cSrcweir throw RuntimeException(); 208*cdf0e10cSrcweir 209*cdf0e10cSrcweir } 210*cdf0e10cSrcweir // Forward it to OConnectionPointHelperContainer! 211*cdf0e10cSrcweir m_pContainerImplementation->unadvise( m_aInterfaceType, xListener ); 212*cdf0e10cSrcweir // Don't forget this! 213*cdf0e10cSrcweir impl_UnlockContainer(); 214*cdf0e10cSrcweir } 215*cdf0e10cSrcweir 216*cdf0e10cSrcweir //______________________________________________________________________________________________________________ 217*cdf0e10cSrcweir // XConnectionPoint 218*cdf0e10cSrcweir //______________________________________________________________________________________________________________ 219*cdf0e10cSrcweir 220*cdf0e10cSrcweir Sequence< Reference< XInterface > > SAL_CALL OConnectionPointHelper::getConnections() throw( RuntimeException ) 221*cdf0e10cSrcweir { 222*cdf0e10cSrcweir // Ready for multithreading 223*cdf0e10cSrcweir MutexGuard aGuard( m_aSharedMutex ); 224*cdf0e10cSrcweir // Operation is permitted only, if reference to container is valid! 225*cdf0e10cSrcweir if ( impl_LockContainer() == sal_False ) 226*cdf0e10cSrcweir { 227*cdf0e10cSrcweir // Container not exist! Its an runtime error. 228*cdf0e10cSrcweir throw RuntimeException(); 229*cdf0e10cSrcweir } 230*cdf0e10cSrcweir // Set default return value, if method failed. 231*cdf0e10cSrcweir Sequence< Reference< XInterface > > seqReturnConnections = Sequence< Reference< XInterface > >(); 232*cdf0e10cSrcweir // Get reference to private member of OConnectionPointHelperContainer! 233*cdf0e10cSrcweir OMultiTypeInterfaceContainerHelper& aSharedContainer = m_pContainerImplementation->impl_getMultiTypeContainer(); 234*cdf0e10cSrcweir // Get pointer to specialized container which hold all interfaces of searched type. 235*cdf0e10cSrcweir OInterfaceContainerHelper* pSpecialContainer = aSharedContainer.getContainer( m_aInterfaceType ); 236*cdf0e10cSrcweir // Get elements of searched type, if somelse exist. 237*cdf0e10cSrcweir if ( pSpecialContainer != NULL ) 238*cdf0e10cSrcweir { 239*cdf0e10cSrcweir seqReturnConnections = pSpecialContainer->getElements(); 240*cdf0e10cSrcweir } 241*cdf0e10cSrcweir // Don't forget this! 242*cdf0e10cSrcweir impl_UnlockContainer(); 243*cdf0e10cSrcweir 244*cdf0e10cSrcweir return seqReturnConnections; 245*cdf0e10cSrcweir } 246*cdf0e10cSrcweir 247*cdf0e10cSrcweir //______________________________________________________________________________________________________________ 248*cdf0e10cSrcweir // private method 249*cdf0e10cSrcweir //______________________________________________________________________________________________________________ 250*cdf0e10cSrcweir 251*cdf0e10cSrcweir sal_Bool OConnectionPointHelper::impl_LockContainer() 252*cdf0e10cSrcweir { 253*cdf0e10cSrcweir // Convert weakreference to hard uno3-reference and return state. 254*cdf0e10cSrcweir // If this reference different from NULL, there exist a hard reference to container. Container-instance can't be destroyed. 255*cdf0e10cSrcweir // Don't forget to "unlock" this reference! 256*cdf0e10cSrcweir m_xLock = m_oContainerWeakReference.get(); 257*cdf0e10cSrcweir return m_xLock.is(); 258*cdf0e10cSrcweir } 259*cdf0e10cSrcweir 260*cdf0e10cSrcweir //______________________________________________________________________________________________________________ 261*cdf0e10cSrcweir // private method 262*cdf0e10cSrcweir //______________________________________________________________________________________________________________ 263*cdf0e10cSrcweir 264*cdf0e10cSrcweir void OConnectionPointHelper::impl_UnlockContainer() 265*cdf0e10cSrcweir { 266*cdf0e10cSrcweir // Free hard uno3-reference to container. 267*cdf0e10cSrcweir // see also "impl_LockContainer()" 268*cdf0e10cSrcweir m_xLock = Reference< XInterface >(); 269*cdf0e10cSrcweir } 270*cdf0e10cSrcweir 271*cdf0e10cSrcweir } // namespace unocontrols 272