Bump version to 4.3-4
[LibreOffice.git] / comphelper / source / container / containermultiplexer.cxx
blob7b8ecc716c63b79ce4a0bb9adc156f5df3ce133d
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <comphelper/containermultiplexer.hxx>
21 #include <comphelper/uno3.hxx>
22 #include <osl/diagnose.h>
24 namespace comphelper
28 using namespace ::com::sun::star::uno;
29 using namespace ::com::sun::star::lang;
30 using namespace ::com::sun::star::container;
33 //= OContainerListener
36 OContainerListener::OContainerListener(::osl::Mutex& _rMutex)
37 :m_pAdapter(NULL)
38 ,m_rMutex(_rMutex)
43 OContainerListener::~OContainerListener()
45 if (m_pAdapter)
47 m_pAdapter->dispose();
48 m_pAdapter = NULL;
53 void OContainerListener::_elementInserted( const ContainerEvent& /*_rEvent*/ )
54 throw (RuntimeException, std::exception)
59 void OContainerListener::_elementRemoved( const ContainerEvent& )
60 throw (RuntimeException, std::exception)
65 void OContainerListener::_elementReplaced( const ContainerEvent& /*_rEvent*/ )
66 throw (RuntimeException, std::exception)
71 void OContainerListener::_disposing(const EventObject& )
72 throw (RuntimeException, std::exception)
77 void OContainerListener::setAdapter(OContainerListenerAdapter* pAdapter)
79 if (m_pAdapter)
81 ::osl::MutexGuard aGuard(m_rMutex);
82 m_pAdapter->release();
83 m_pAdapter = NULL;
86 if (pAdapter)
88 ::osl::MutexGuard aGuard(m_rMutex);
89 m_pAdapter = pAdapter;
90 m_pAdapter->acquire();
95 //= OContainerListenerAdapter
98 OContainerListenerAdapter::OContainerListenerAdapter(OContainerListener* _pListener,
99 const Reference< XContainer >& _rxContainer)
100 :m_xContainer(_rxContainer)
101 ,m_pListener(_pListener)
102 ,m_nLockCount(0)
104 if (m_pListener)
105 m_pListener->setAdapter(this);
107 ::comphelper::increment(m_refCount);
110 m_xContainer->addContainerListener(this);
112 catch(const Exception&)
114 OSL_FAIL("Exception caught!");
116 ::comphelper::decrement(m_refCount);
120 OContainerListenerAdapter::~OContainerListenerAdapter()
125 void OContainerListenerAdapter::dispose()
127 if (m_xContainer.is())
131 Reference< XContainerListener > xPreventDelete(this);
132 m_xContainer->removeContainerListener(xPreventDelete);
133 m_pListener->setAdapter(NULL);
135 catch(const Exception&)
137 OSL_FAIL("Exception caught!");
139 m_xContainer = NULL;
140 m_pListener = NULL;
145 void SAL_CALL OContainerListenerAdapter::disposing( const EventObject& _rSource) throw(RuntimeException, std::exception)
147 if (m_pListener)
149 // tell the listener
150 if (!locked())
151 m_pListener->_disposing(_rSource);
152 // disconnect the listener
153 if ( m_pListener )
154 m_pListener->setAdapter(NULL);
157 m_xContainer = NULL;
158 m_pListener = NULL;
162 void SAL_CALL OContainerListenerAdapter::elementInserted( const ContainerEvent& _rEvent ) throw(RuntimeException, std::exception)
164 if (m_pListener && !locked())
165 m_pListener->_elementInserted(_rEvent);
169 void SAL_CALL OContainerListenerAdapter::elementRemoved( const ContainerEvent& _rEvent ) throw(RuntimeException, std::exception)
171 if (m_pListener && !locked())
172 m_pListener->_elementRemoved(_rEvent);
176 void SAL_CALL OContainerListenerAdapter::elementReplaced( const ContainerEvent& _rEvent ) throw(RuntimeException, std::exception)
178 if (m_pListener && !locked())
179 m_pListener->_elementReplaced(_rEvent);
183 } // namespace comphelper
186 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */