1*6d739b60SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*6d739b60SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*6d739b60SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*6d739b60SAndrew Rist * distributed with this work for additional information 6*6d739b60SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*6d739b60SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*6d739b60SAndrew Rist * "License"); you may not use this file except in compliance 9*6d739b60SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*6d739b60SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*6d739b60SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*6d739b60SAndrew Rist * software distributed under the License is distributed on an 15*6d739b60SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*6d739b60SAndrew Rist * KIND, either express or implied. See the License for the 17*6d739b60SAndrew Rist * specific language governing permissions and limitations 18*6d739b60SAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*6d739b60SAndrew Rist *************************************************************/ 21*6d739b60SAndrew Rist 22*6d739b60SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_framework.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 28cdf0e10cSrcweir // my own includes 29cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 30cdf0e10cSrcweir #include <helper/ocomponentenumeration.hxx> 31cdf0e10cSrcweir 32cdf0e10cSrcweir #ifndef _FRAMEWORK_THREADHELP_RESETABLEGUARD_HXX_ 33cdf0e10cSrcweir #include <threadhelp/resetableguard.hxx> 34cdf0e10cSrcweir #endif 35cdf0e10cSrcweir 36cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 37cdf0e10cSrcweir // interface includes 38cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 39cdf0e10cSrcweir 40cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 41cdf0e10cSrcweir // includes of other projects 42cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 43cdf0e10cSrcweir #include <vcl/svapp.hxx> 44cdf0e10cSrcweir 45cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 46cdf0e10cSrcweir // namespace 47cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 48cdf0e10cSrcweir 49cdf0e10cSrcweir namespace framework{ 50cdf0e10cSrcweir 51cdf0e10cSrcweir using namespace ::com::sun::star::container ; 52cdf0e10cSrcweir using namespace ::com::sun::star::lang ; 53cdf0e10cSrcweir using namespace ::com::sun::star::uno ; 54cdf0e10cSrcweir using namespace ::cppu ; 55cdf0e10cSrcweir using namespace ::osl ; 56cdf0e10cSrcweir using namespace ::rtl ; 57cdf0e10cSrcweir 58cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 59cdf0e10cSrcweir // non exported const 60cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 61cdf0e10cSrcweir 62cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 63cdf0e10cSrcweir // non exported definitions 64cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 65cdf0e10cSrcweir 66cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 67cdf0e10cSrcweir // declarations 68cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 69cdf0e10cSrcweir 70cdf0e10cSrcweir //***************************************************************************************************************** 71cdf0e10cSrcweir // constructor 72cdf0e10cSrcweir //***************************************************************************************************************** 73cdf0e10cSrcweir OComponentEnumeration::OComponentEnumeration( const Sequence< css::uno::Reference< XComponent > >& seqComponents ) 74cdf0e10cSrcweir // Init baseclasses first 75cdf0e10cSrcweir // Attention: 76cdf0e10cSrcweir // Don't change order of initialization! 77cdf0e10cSrcweir // ThreadHelpBase is a struct with a mutex as member. We can't use a mutex as member, while 78cdf0e10cSrcweir // we must garant right initialization and a valid value of this! First initialize 79cdf0e10cSrcweir // baseclasses and then members. And we need the mutex for other baseclasses !!! 80cdf0e10cSrcweir : ThreadHelpBase ( &Application::GetSolarMutex() ) 81cdf0e10cSrcweir // Init member 82cdf0e10cSrcweir , m_nPosition ( 0 ) // 0 is the first position for a valid list and the right value for an invalid list to! 83cdf0e10cSrcweir , m_seqComponents ( seqComponents ) 84cdf0e10cSrcweir { 85cdf0e10cSrcweir // Safe impossible states 86cdf0e10cSrcweir // "Method" not defined for ALL parameters! 87cdf0e10cSrcweir LOG_ASSERT( impldbg_checkParameter_OComponentEnumerationCtor( seqComponents ), "OComponentEnumeration::OComponentEnumeration()\nInvalid parameter detected!\n" ) 88cdf0e10cSrcweir } 89cdf0e10cSrcweir 90cdf0e10cSrcweir //***************************************************************************************************************** 91cdf0e10cSrcweir // destructor 92cdf0e10cSrcweir //***************************************************************************************************************** 93cdf0e10cSrcweir OComponentEnumeration::~OComponentEnumeration() 94cdf0e10cSrcweir { 95cdf0e10cSrcweir // Reset instance, free memory .... 96cdf0e10cSrcweir impl_resetObject(); 97cdf0e10cSrcweir } 98cdf0e10cSrcweir 99cdf0e10cSrcweir //***************************************************************************************************************** 100cdf0e10cSrcweir // XEventListener 101cdf0e10cSrcweir //***************************************************************************************************************** 102cdf0e10cSrcweir void SAL_CALL OComponentEnumeration::disposing( const EventObject& 103cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 0 104cdf0e10cSrcweir aEvent 105cdf0e10cSrcweir #endif 106cdf0e10cSrcweir ) throw( RuntimeException ) 107cdf0e10cSrcweir { 108cdf0e10cSrcweir // Ready for multithreading 109cdf0e10cSrcweir ResetableGuard aGuard( m_aLock ); 110cdf0e10cSrcweir 111cdf0e10cSrcweir // Safe impossible cases 112cdf0e10cSrcweir // This method is not specified for all incoming parameters. 113cdf0e10cSrcweir LOG_ASSERT( impldbg_checkParameter_disposing( aEvent ), "OComponentEnumeration::disposing()\nInvalid parameter detected!\n" ) 114cdf0e10cSrcweir 115cdf0e10cSrcweir // Reset instance to defaults, release references and free memory. 116cdf0e10cSrcweir impl_resetObject(); 117cdf0e10cSrcweir } 118cdf0e10cSrcweir 119cdf0e10cSrcweir //***************************************************************************************************************** 120cdf0e10cSrcweir // XEnumeration 121cdf0e10cSrcweir //***************************************************************************************************************** 122cdf0e10cSrcweir sal_Bool SAL_CALL OComponentEnumeration::hasMoreElements() throw( RuntimeException ) 123cdf0e10cSrcweir { 124cdf0e10cSrcweir // Ready for multithreading 125cdf0e10cSrcweir ResetableGuard aGuard( m_aLock ); 126cdf0e10cSrcweir 127cdf0e10cSrcweir // First position in a valid list is 0. 128cdf0e10cSrcweir // => The last one is getLength() - 1! 129cdf0e10cSrcweir // m_nPosition's current value is the position for the next element, which will be return, if user call "nextElement()" 130cdf0e10cSrcweir // => We have more elements if current position less then the length of the list! 131cdf0e10cSrcweir return ( m_nPosition < (sal_uInt32)(m_seqComponents.getLength()) ); 132cdf0e10cSrcweir } 133cdf0e10cSrcweir 134cdf0e10cSrcweir //***************************************************************************************************************** 135cdf0e10cSrcweir // XEnumeration 136cdf0e10cSrcweir //***************************************************************************************************************** 137cdf0e10cSrcweir Any SAL_CALL OComponentEnumeration::nextElement() throw( NoSuchElementException , 138cdf0e10cSrcweir WrappedTargetException , 139cdf0e10cSrcweir RuntimeException ) 140cdf0e10cSrcweir { 141cdf0e10cSrcweir // Ready for multithreading 142cdf0e10cSrcweir ResetableGuard aGuard( m_aLock ); 143cdf0e10cSrcweir 144cdf0e10cSrcweir // If we have no elements or end of enumeration is arrived ... 145cdf0e10cSrcweir if ( hasMoreElements() == sal_False ) 146cdf0e10cSrcweir { 147cdf0e10cSrcweir // .. throw an exception! 148cdf0e10cSrcweir throw NoSuchElementException(); 149cdf0e10cSrcweir } 150cdf0e10cSrcweir 151cdf0e10cSrcweir // Else; Get next element from list ... 152cdf0e10cSrcweir Any aComponent; 153cdf0e10cSrcweir aComponent <<= m_seqComponents[m_nPosition]; 154cdf0e10cSrcweir // ... and step to next element! 155cdf0e10cSrcweir ++m_nPosition; 156cdf0e10cSrcweir 157cdf0e10cSrcweir // Return listitem. 158cdf0e10cSrcweir return aComponent; 159cdf0e10cSrcweir } 160cdf0e10cSrcweir 161cdf0e10cSrcweir //***************************************************************************************************************** 162cdf0e10cSrcweir // proteced method 163cdf0e10cSrcweir //***************************************************************************************************************** 164cdf0e10cSrcweir void OComponentEnumeration::impl_resetObject() 165cdf0e10cSrcweir { 166cdf0e10cSrcweir // Attention: 167cdf0e10cSrcweir // Write this for multiple calls - NOT AT THE SAME TIME - but for more then one call again)! 168cdf0e10cSrcweir // It exist two ways to call this method. From destructor and from disposing(). 169cdf0e10cSrcweir // I can't say, which one is the first. Normaly the disposing-call - but other way .... 170cdf0e10cSrcweir 171cdf0e10cSrcweir // Delete list of components. 172cdf0e10cSrcweir m_seqComponents.realloc( 0 ); 173cdf0e10cSrcweir // Reset position in list. 174cdf0e10cSrcweir // The list has no elements anymore. m_nPosition is normaly the current position in list for nextElement! 175cdf0e10cSrcweir // But a position of 0 in a list of 0 items is an invalid state. This constellation can't work in future. 176cdf0e10cSrcweir // End of enumeration is arrived! 177cdf0e10cSrcweir // (see hasMoreElements() for more details...) 178cdf0e10cSrcweir m_nPosition = 0 ; 179cdf0e10cSrcweir } 180cdf0e10cSrcweir 181cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 182cdf0e10cSrcweir // debug methods 183cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 184cdf0e10cSrcweir 185cdf0e10cSrcweir /*----------------------------------------------------------------------------------------------------------------- 186cdf0e10cSrcweir The follow methods checks the parameter for other functions. If a parameter or his value is non valid, 187cdf0e10cSrcweir we return "sal_False". (else sal_True) This mechanism is used to throw an ASSERT! 188cdf0e10cSrcweir 189cdf0e10cSrcweir ATTENTION 190cdf0e10cSrcweir 191cdf0e10cSrcweir If you miss a test for one of this parameters, contact the autor or add it himself !(?) 192cdf0e10cSrcweir But ... look for right testing! See using of this methods! 193cdf0e10cSrcweir -----------------------------------------------------------------------------------------------------------------*/ 194cdf0e10cSrcweir 195cdf0e10cSrcweir #ifdef ENABLE_ASSERTIONS 196cdf0e10cSrcweir 197cdf0e10cSrcweir //***************************************************************************************************************** 198cdf0e10cSrcweir // An empty list is allowed ... hasMoreElements() will return false then! 199cdf0e10cSrcweir sal_Bool OComponentEnumeration::impldbg_checkParameter_OComponentEnumerationCtor( const Sequence< css::uno::Reference< XComponent > >& seqComponents ) 200cdf0e10cSrcweir { 201cdf0e10cSrcweir // Set default return value. 202cdf0e10cSrcweir sal_Bool bOK = sal_True; 203cdf0e10cSrcweir // Check parameter. 204cdf0e10cSrcweir if ( 205cdf0e10cSrcweir ( &seqComponents == NULL ) 206cdf0e10cSrcweir ) 207cdf0e10cSrcweir { 208cdf0e10cSrcweir bOK = sal_False ; 209cdf0e10cSrcweir } 210cdf0e10cSrcweir // Return result of check. 211cdf0e10cSrcweir return bOK ; 212cdf0e10cSrcweir } 213cdf0e10cSrcweir 214cdf0e10cSrcweir //***************************************************************************************************************** 215cdf0e10cSrcweir sal_Bool OComponentEnumeration::impldbg_checkParameter_disposing( const EventObject& aEvent ) 216cdf0e10cSrcweir { 217cdf0e10cSrcweir // Set default return value. 218cdf0e10cSrcweir sal_Bool bOK = sal_True; 219cdf0e10cSrcweir // Check parameter. 220cdf0e10cSrcweir if ( 221cdf0e10cSrcweir ( &aEvent == NULL ) || 222cdf0e10cSrcweir ( aEvent.Source.is() == sal_False ) 223cdf0e10cSrcweir ) 224cdf0e10cSrcweir { 225cdf0e10cSrcweir bOK = sal_False ; 226cdf0e10cSrcweir } 227cdf0e10cSrcweir // Return result of check. 228cdf0e10cSrcweir return bOK ; 229cdf0e10cSrcweir } 230cdf0e10cSrcweir 231cdf0e10cSrcweir #endif // #ifdef ENABLE_ASSERTIONS 232cdf0e10cSrcweir 233cdf0e10cSrcweir } // namespace framework 234