bump product version to 5.0.4.1
[LibreOffice.git] / comphelper / source / container / containermultiplexer.cxx
blob8758b42712258d4c64b1062709423d83488fd41e
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 <osl/diagnose.h>
23 namespace comphelper
27 using namespace ::com::sun::star::uno;
28 using namespace ::com::sun::star::lang;
29 using namespace ::com::sun::star::container;
31 OContainerListener::OContainerListener(::osl::Mutex& _rMutex)
32 :m_pAdapter(NULL)
33 ,m_rMutex(_rMutex)
38 OContainerListener::~OContainerListener()
40 if (m_pAdapter)
42 m_pAdapter->dispose();
43 m_pAdapter = NULL;
48 void OContainerListener::_elementInserted( const ContainerEvent& /*_rEvent*/ )
49 throw (RuntimeException, std::exception)
54 void OContainerListener::_elementRemoved( const ContainerEvent& )
55 throw (RuntimeException, std::exception)
60 void OContainerListener::_elementReplaced( const ContainerEvent& /*_rEvent*/ )
61 throw (RuntimeException, std::exception)
66 void OContainerListener::_disposing(const EventObject& )
67 throw (RuntimeException, std::exception)
72 void OContainerListener::setAdapter(OContainerListenerAdapter* pAdapter)
74 if (m_pAdapter)
76 ::osl::MutexGuard aGuard(m_rMutex);
77 m_pAdapter->release();
78 m_pAdapter = NULL;
81 if (pAdapter)
83 ::osl::MutexGuard aGuard(m_rMutex);
84 m_pAdapter = pAdapter;
85 m_pAdapter->acquire();
89 OContainerListenerAdapter::OContainerListenerAdapter(OContainerListener* _pListener,
90 const Reference< XContainer >& _rxContainer)
91 :m_xContainer(_rxContainer)
92 ,m_pListener(_pListener)
93 ,m_nLockCount(0)
95 if (m_pListener)
96 m_pListener->setAdapter(this);
98 osl_atomic_increment(&m_refCount);
99 try
101 m_xContainer->addContainerListener(this);
103 catch(const Exception&)
105 OSL_FAIL("Exception caught!");
107 osl_atomic_decrement(&m_refCount);
111 OContainerListenerAdapter::~OContainerListenerAdapter()
116 void OContainerListenerAdapter::dispose()
118 if (m_xContainer.is())
122 Reference< XContainerListener > xPreventDelete(this);
123 m_xContainer->removeContainerListener(xPreventDelete);
124 m_pListener->setAdapter(NULL);
126 catch(const Exception&)
128 OSL_FAIL("Exception caught!");
130 m_xContainer = NULL;
131 m_pListener = NULL;
136 void SAL_CALL OContainerListenerAdapter::disposing( const EventObject& _rSource) throw(RuntimeException, std::exception)
138 if (m_pListener)
140 // tell the listener
141 if (!locked())
142 m_pListener->_disposing(_rSource);
143 // disconnect the listener
144 if ( m_pListener )
145 m_pListener->setAdapter(NULL);
148 m_xContainer = NULL;
149 m_pListener = NULL;
153 void SAL_CALL OContainerListenerAdapter::elementInserted( const ContainerEvent& _rEvent ) throw(RuntimeException, std::exception)
155 if (m_pListener && !locked())
156 m_pListener->_elementInserted(_rEvent);
160 void SAL_CALL OContainerListenerAdapter::elementRemoved( const ContainerEvent& _rEvent ) throw(RuntimeException, std::exception)
162 if (m_pListener && !locked())
163 m_pListener->_elementRemoved(_rEvent);
167 void SAL_CALL OContainerListenerAdapter::elementReplaced( const ContainerEvent& _rEvent ) throw(RuntimeException, std::exception)
169 if (m_pListener && !locked())
170 m_pListener->_elementReplaced(_rEvent);
174 } // namespace comphelper
177 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */