1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
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
)
38 OContainerListener::~OContainerListener()
42 m_pAdapter
->dispose();
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
)
76 ::osl::MutexGuard
aGuard(m_rMutex
);
77 m_pAdapter
->release();
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
)
96 m_pListener
->setAdapter(this);
98 osl_atomic_increment(&m_refCount
);
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!");
136 void SAL_CALL
OContainerListenerAdapter::disposing( const EventObject
& _rSource
) throw(RuntimeException
, std::exception
)
142 m_pListener
->_disposing(_rSource
);
143 // disconnect the listener
145 m_pListener
->setAdapter(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: */