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 <comphelper/uno3.hxx>
22 #include <osl/diagnose.h>
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
)
43 OContainerListener::~OContainerListener()
47 m_pAdapter
->dispose();
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
)
81 ::osl::MutexGuard
aGuard(m_rMutex
);
82 m_pAdapter
->release();
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
)
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!");
145 void SAL_CALL
OContainerListenerAdapter::disposing( const EventObject
& _rSource
) throw(RuntimeException
, std::exception
)
151 m_pListener
->_disposing(_rSource
);
152 // disconnect the listener
154 m_pListener
->setAdapter(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: */