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 // MARKER(update_precomp.py): autogen include statement, do not remove 25 #include "precompiled_sd.hxx" 26 #include <com/sun/star/lang/XComponent.hpp> 27 #include <tools/list.hxx> 28 29 #include <unowcntr.hxx> 30 31 using namespace ::rtl; 32 using namespace ::com::sun::star; 33 34 DECLARE_LIST( WeakRefList, uno::WeakReference< uno::XInterface >* ) 35 36 SvUnoWeakContainer::SvUnoWeakContainer() throw() 37 { 38 mpList = new WeakRefList; 39 } 40 41 SvUnoWeakContainer::~SvUnoWeakContainer() throw() 42 { 43 uno::WeakReference< uno::XInterface >* pRef = mpList->First(); 44 while( pRef ) 45 { 46 delete mpList->Remove(); 47 pRef = mpList->GetCurObject(); 48 } 49 delete mpList; 50 } 51 52 /** inserts the given ref into this container */ 53 void SvUnoWeakContainer::insert( uno::WeakReference< uno::XInterface > xRef ) throw() 54 { 55 uno::WeakReference< uno::XInterface >* pRef = mpList->First(); 56 while( pRef ) 57 { 58 ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > xTestRef( *pRef ); 59 if(! xTestRef.is() ) 60 { 61 delete mpList->Remove(); 62 pRef = mpList->GetCurObject(); 63 } 64 else 65 { 66 if( *pRef == xRef ) 67 return; 68 69 pRef = mpList->Next(); 70 } 71 } 72 73 mpList->Insert( new uno::WeakReference< uno::XInterface >( xRef ) ); 74 } 75 76 /** searches the container for a ref that returns true on the given 77 search function 78 */ 79 sal_Bool SvUnoWeakContainer::findRef( uno::WeakReference< uno::XInterface >& rRef, void* pSearchData, weakref_searchfunc pSearchFunc ) 80 { 81 uno::WeakReference< uno::XInterface >* pRef = mpList->First(); 82 while( pRef ) 83 { 84 uno::Reference< ::com::sun::star::uno::XInterface > xTestRef( *pRef ); 85 if(!xTestRef.is()) 86 { 87 delete mpList->Remove(); 88 pRef = mpList->GetCurObject(); 89 } 90 else 91 { 92 if( (*pSearchFunc)( *pRef, pSearchData ) ) 93 { 94 rRef = *pRef; 95 return sal_True; 96 } 97 98 pRef = mpList->Next(); 99 } 100 } 101 102 return sal_False; 103 } 104 105 void SvUnoWeakContainer::dispose() 106 { 107 uno::WeakReference< uno::XInterface >* pRef = mpList->First(); 108 while( pRef ) 109 { 110 uno::Reference< uno::XInterface > xTestRef( *pRef ); 111 if(xTestRef.is()) 112 { 113 uno::Reference< lang::XComponent > xComp( xTestRef, uno::UNO_QUERY ); 114 if( xComp.is() ) 115 xComp->dispose(); 116 } 117 118 pRef = mpList->Next(); 119 } 120 } 121 122