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 <sal/config.h>
24 #include <com/sun/star/beans/XPropertiesChangeListener.hpp>
25 #include <com/sun/star/beans/XPropertyChangeListener.hpp>
26 #include <com/sun/star/container/XContainerListener.hpp>
27 #include <com/sun/star/lang/DisposedException.hpp>
28 #include <com/sun/star/lang/WrappedTargetRuntimeException.hpp>
29 #include <com/sun/star/lang/XEventListener.hpp>
30 #include <com/sun/star/uno/Any.hxx>
31 #include <com/sun/star/uno/Exception.hpp>
32 #include <com/sun/star/uno/Reference.hxx>
33 #include <com/sun/star/uno/XInterface.hpp>
34 #include <com/sun/star/util/XChangesListener.hpp>
35 #include <cppuhelper/exc_hlp.hxx>
36 #include <rtl/ustrbuf.hxx>
37 #include <rtl/ustring.hxx>
39 #include "broadcaster.hxx"
46 OUStringBuffer
& buffer
, css::uno::Exception
const & exception
)
49 buffer
.append(exception
.Message
);
54 void Broadcaster::addDisposeNotification(
55 css::uno::Reference
< css::lang::XEventListener
> const & listener
,
56 css::lang::EventObject
const & event
)
58 disposeNotifications_
.emplace_back(listener
, event
);
61 void Broadcaster::addContainerElementReplacedNotification(
62 css::uno::Reference
< css::container::XContainerListener
> const & listener
,
63 css::container::ContainerEvent
const & event
)
65 containerElementReplacedNotifications_
.emplace_back(listener
, event
);
68 void Broadcaster::addContainerElementInsertedNotification(
69 css::uno::Reference
< css::container::XContainerListener
> const & listener
,
70 css::container::ContainerEvent
const & event
)
72 containerElementInsertedNotifications_
.emplace_back(listener
, event
);
75 void Broadcaster::addContainerElementRemovedNotification(
76 css::uno::Reference
< css::container::XContainerListener
> const & listener
,
77 css::container::ContainerEvent
const & event
)
79 containerElementRemovedNotifications_
.emplace_back(listener
, event
);
82 void Broadcaster::addPropertyChangeNotification(
83 css::uno::Reference
< css::beans::XPropertyChangeListener
> const & listener
,
84 css::beans::PropertyChangeEvent
const & event
)
86 propertyChangeNotifications_
.emplace_back(listener
, event
);
89 void Broadcaster::addPropertiesChangeNotification(
90 css::uno::Reference
< css::beans::XPropertiesChangeListener
> const &
92 css::uno::Sequence
< css::beans::PropertyChangeEvent
> const & event
)
94 propertiesChangeNotifications_
.emplace_back(listener
, event
);
97 void Broadcaster::addChangesNotification(
98 css::uno::Reference
< css::util::XChangesListener
> const & listener
,
99 css::util::ChangesEvent
const & event
)
101 changesNotifications_
.emplace_back(listener
, event
);
104 void Broadcaster::send() {
105 css::uno::Any exception
;
106 OUStringBuffer messages
;
107 for (auto& rNotification
: disposeNotifications_
) {
109 rNotification
.listener
->disposing(rNotification
.event
);
110 } catch (css::lang::DisposedException
&) {
111 } catch (css::uno::Exception
& e
) {
112 exception
= cppu::getCaughtException();
113 appendMessage(messages
, e
);
116 for (auto& rNotification
: containerElementInsertedNotifications_
)
119 rNotification
.listener
->elementInserted(rNotification
.event
);
120 } catch (css::lang::DisposedException
&) {
121 } catch (css::uno::Exception
& e
) {
122 exception
= cppu::getCaughtException();
123 appendMessage(messages
, e
);
126 for (auto& rNotification
: containerElementRemovedNotifications_
)
129 rNotification
.listener
->elementRemoved(rNotification
.event
);
130 } catch (css::lang::DisposedException
&) {
131 } catch (css::uno::Exception
& e
) {
132 exception
= cppu::getCaughtException();
133 appendMessage(messages
, e
);
136 for (auto& rNotification
: containerElementReplacedNotifications_
)
139 rNotification
.listener
->elementReplaced(rNotification
.event
);
140 } catch (css::lang::DisposedException
&) {
141 } catch (css::uno::Exception
& e
) {
142 exception
= cppu::getCaughtException();
143 appendMessage(messages
, e
);
146 for (auto& rNotification
: propertyChangeNotifications_
)
149 rNotification
.listener
->propertyChange(rNotification
.event
);
150 } catch (css::lang::DisposedException
&) {
151 } catch (css::uno::Exception
& e
) {
152 exception
= cppu::getCaughtException();
153 appendMessage(messages
, e
);
156 for (auto& rNotification
: propertiesChangeNotifications_
)
159 rNotification
.listener
->propertiesChange(rNotification
.event
);
160 } catch (css::lang::DisposedException
&) {
161 } catch (css::uno::Exception
& e
) {
162 exception
= cppu::getCaughtException();
163 appendMessage(messages
, e
);
166 for (auto& rNotification
: changesNotifications_
) {
168 rNotification
.listener
->changesOccurred(rNotification
.event
);
169 } catch (css::lang::DisposedException
&) {
170 } catch (css::uno::Exception
& e
) {
171 exception
= cppu::getCaughtException();
172 appendMessage(messages
, e
);
175 if (exception
.hasValue()) {
176 throw css::lang::WrappedTargetRuntimeException(
177 ("configmgr exceptions during listener notification" +
178 messages
.makeStringAndClear()),
179 css::uno::Reference
< css::uno::XInterface
>(),
184 Broadcaster::DisposeNotification::DisposeNotification(
185 css::uno::Reference
< css::lang::XEventListener
> const & theListener
,
186 css::lang::EventObject
const & theEvent
):
187 listener(theListener
), event(theEvent
)
189 assert(theListener
.is());
192 Broadcaster::ContainerNotification::ContainerNotification(
193 css::uno::Reference
< css::container::XContainerListener
> const &
195 css::container::ContainerEvent
const & theEvent
):
196 listener(theListener
), event(theEvent
)
198 assert(theListener
.is());
201 Broadcaster::PropertyChangeNotification::PropertyChangeNotification(
202 css::uno::Reference
< css::beans::XPropertyChangeListener
> const &
204 css::beans::PropertyChangeEvent
const & theEvent
):
205 listener(theListener
), event(theEvent
)
207 assert(theListener
.is());
210 Broadcaster::PropertiesChangeNotification::PropertiesChangeNotification(
211 css::uno::Reference
< css::beans::XPropertiesChangeListener
> const &
213 css::uno::Sequence
< css::beans::PropertyChangeEvent
> const & theEvent
):
214 listener(theListener
), event(theEvent
)
216 assert(theListener
.is());
219 Broadcaster::ChangesNotification::ChangesNotification(
220 css::uno::Reference
< css::util::XChangesListener
> const & theListener
,
221 css::util::ChangesEvent
const & theEvent
):
222 listener(theListener
), event(theEvent
)
224 assert(theListener
.is());
229 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */