1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 //______________________________________________________________________________________________________________ 29 // my own include 30 //______________________________________________________________________________________________________________ 31 32 #include "OConnectionPointContainerHelper.hxx" 33 34 //______________________________________________________________________________________________________________ 35 // includes of other projects 36 //______________________________________________________________________________________________________________ 37 38 //______________________________________________________________________________________________________________ 39 // include of my own project 40 //______________________________________________________________________________________________________________ 41 #include "OConnectionPointHelper.hxx" 42 43 //______________________________________________________________________________________________________________ 44 // namespaces 45 //______________________________________________________________________________________________________________ 46 47 using namespace ::rtl ; 48 using namespace ::osl ; 49 using namespace ::cppu ; 50 using namespace ::com::sun::star::uno ; 51 using namespace ::com::sun::star::lang ; 52 53 namespace unocontrols{ 54 55 //______________________________________________________________________________________________________________ 56 // construct/destruct 57 //______________________________________________________________________________________________________________ 58 59 OConnectionPointContainerHelper::OConnectionPointContainerHelper( Mutex& aMutex ) 60 : m_aSharedMutex ( aMutex ) 61 , m_aMultiTypeContainer ( aMutex ) 62 { 63 } 64 65 OConnectionPointContainerHelper::~OConnectionPointContainerHelper() 66 { 67 } 68 69 //____________________________________________________________________________________________________________ 70 // XInterface 71 //____________________________________________________________________________________________________________ 72 73 Any SAL_CALL OConnectionPointContainerHelper::queryInterface( const Type& aType ) throw( RuntimeException ) 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< XConnectionPointContainer* > ( 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 OConnectionPointContainerHelper::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 OConnectionPointContainerHelper::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 // XConnectionPointContainer 122 //______________________________________________________________________________________________________________ 123 124 Sequence< Type > SAL_CALL OConnectionPointContainerHelper::getConnectionPointTypes() throw( RuntimeException ) 125 { 126 // Container is threadsafe himself ! 127 return m_aMultiTypeContainer.getContainedTypes(); 128 } 129 130 //______________________________________________________________________________________________________________ 131 // XConnectionPointContainer 132 //______________________________________________________________________________________________________________ 133 134 Reference< XConnectionPoint > SAL_CALL OConnectionPointContainerHelper::queryConnectionPoint( const Type& aType ) throw( RuntimeException ) 135 { 136 // Set default return value, if method failed. 137 Reference< XConnectionPoint > xConnectionPoint = Reference< XConnectionPoint >(); 138 139 // Get all elements of the container, which have the searched type. 140 OInterfaceContainerHelper* pSpecialContainer = m_aMultiTypeContainer.getContainer( aType ); 141 if ( pSpecialContainer && pSpecialContainer->getLength() > 0 ) 142 { 143 // Ready for multithreading 144 MutexGuard aGuard( m_aSharedMutex ); 145 // If this container contains elements, build a connectionpoint-instance. 146 OConnectionPointHelper* pNewConnectionPoint = new OConnectionPointHelper( m_aSharedMutex, this, aType ); 147 xConnectionPoint = Reference< XConnectionPoint >( (OWeakObject*)pNewConnectionPoint, UNO_QUERY ); 148 } 149 150 return xConnectionPoint ; 151 } 152 153 //______________________________________________________________________________________________________________ 154 // XConnectionPointContainer 155 //______________________________________________________________________________________________________________ 156 157 void SAL_CALL OConnectionPointContainerHelper::advise( const Type& aType , 158 const Reference< XInterface >& xListener ) throw( RuntimeException ) 159 { 160 // Container is threadsafe himself ! 161 m_aMultiTypeContainer.addInterface( aType, xListener ); 162 } 163 164 //______________________________________________________________________________________________________________ 165 // XConnectionPointContainer 166 //______________________________________________________________________________________________________________ 167 168 void SAL_CALL OConnectionPointContainerHelper::unadvise( const Type& aType , 169 const Reference< XInterface >& xListener ) throw( RuntimeException ) 170 { 171 // Container is threadsafe himself ! 172 m_aMultiTypeContainer.removeInterface( aType, xListener ); 173 } 174 175 //______________________________________________________________________________________________________________ 176 // public but impl method! 177 // Is neccessary to get container member at OConnectionPoint-instance. 178 //______________________________________________________________________________________________________________ 179 180 OMultiTypeInterfaceContainerHelper& OConnectionPointContainerHelper::impl_getMultiTypeContainer() 181 { 182 // Impl methods are not threadsafe! 183 // "Parent" function must do this. 184 return m_aMultiTypeContainer; 185 } 186 187 } // namespace unocontrols 188