LibreOffice Module comphelper (master) 1
containermultiplexer.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
21#include <com/sun/star/container/XContainer.hpp>
22#include <osl/diagnose.h>
23
24namespace comphelper
25{
26
27
28 using namespace ::com::sun::star::uno;
29 using namespace ::com::sun::star::lang;
30 using namespace ::com::sun::star::container;
31
33 :m_rMutex(_rMutex)
34 {
35 }
36
37
39 {
40 if (m_xAdapter.is())
41 {
42 m_xAdapter->dispose();
43 }
44 }
45
46
47 void OContainerListener::_elementInserted( const ContainerEvent& /*_rEvent*/ )
48 {
49 }
50
51
52 void OContainerListener::_elementRemoved( const ContainerEvent& )
53 {
54 }
55
56
57 void OContainerListener::_elementReplaced( const ContainerEvent& /*_rEvent*/ )
58 {
59 }
60
61
62 void OContainerListener::_disposing(const EventObject& )
63 {
64 }
65
66
68 {
69 ::osl::MutexGuard aGuard(m_rMutex);
70 m_xAdapter = pAdapter;
71 }
72
74 const Reference< XContainer >& _rxContainer)
75 :m_xContainer(_rxContainer)
76 ,m_pListener(_pListener)
77 {
78 if (m_pListener)
80
81 osl_atomic_increment(&m_refCount);
82 try
83 {
84 m_xContainer->addContainerListener(this);
85 }
86 catch(const Exception&)
87 {
88 OSL_FAIL("Exception caught!");
89 }
90 osl_atomic_decrement(&m_refCount);
91 }
92
93
95 {
96 }
97
98
100 {
101 if (!m_xContainer.is())
102 return;
103
104 try
105 {
106 Reference< XContainerListener > xPreventDelete(this);
107 m_xContainer->removeContainerListener(xPreventDelete);
108 m_pListener->setAdapter(nullptr);
109 }
110 catch(const Exception&)
111 {
112 OSL_FAIL("Exception caught!");
113 }
114 m_xContainer = nullptr;
115 m_pListener = nullptr;
116 }
117
118
119 void SAL_CALL OContainerListenerAdapter::disposing( const EventObject& _rSource)
120 {
121 if (m_pListener)
122 {
123 // tell the listener
124 m_pListener->_disposing(_rSource);
125 // disconnect the listener
126 if ( m_pListener )
127 m_pListener->setAdapter(nullptr);
128 }
129
130 m_xContainer = nullptr;
131 m_pListener = nullptr;
132 }
133
134
135 void SAL_CALL OContainerListenerAdapter::elementInserted( const ContainerEvent& _rEvent )
136 {
137 if (m_pListener)
139 }
140
141
142 void SAL_CALL OContainerListenerAdapter::elementRemoved( const ContainerEvent& _rEvent )
143 {
144 if (m_pListener)
146 }
147
148
149 void SAL_CALL OContainerListenerAdapter::elementReplaced( const ContainerEvent& _rEvent )
150 {
151 if (m_pListener)
153 }
154
155
156} // namespace comphelper
157
158
159/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
css::uno::Reference< css::container::XContainer > m_xContainer
virtual void SAL_CALL elementRemoved(const css::container::ContainerEvent &Event) override
virtual void SAL_CALL elementInserted(const css::container::ContainerEvent &Event) override
virtual void SAL_CALL elementReplaced(const css::container::ContainerEvent &Event) override
virtual void SAL_CALL disposing(const css::lang::EventObject &Source) override
OContainerListenerAdapter(OContainerListener *_pListener, const css::uno::Reference< css::container::XContainer > &_rxContainer)
void dispose()
dispose the object. No multiplexing anymore
a non-UNO container listener
OContainerListener(::osl::Mutex &_rMutex)
virtual void _elementReplaced(const css::container::ContainerEvent &_rEvent)
void setAdapter(OContainerListenerAdapter *_pAdapter)
rtl::Reference< OContainerListenerAdapter > m_xAdapter
virtual void _elementRemoved(const css::container::ContainerEvent &_rEvent)
virtual void _disposing(const css::lang::EventObject &_rSource)
virtual void _elementInserted(const css::container::ContainerEvent &_rEvent)
::osl::Mutex & m_rMutex
ULONG m_refCount
@ Exception
Reference< XNameAccess > m_xContainer