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>
40 #include "broadcaster.hxx"
47 OUStringBuffer
& buffer
, css::uno::Exception
const & exception
)
50 buffer
.append(exception
.Message
);
55 void Broadcaster::addDisposeNotification(
56 css::uno::Reference
< css::lang::XEventListener
> const & listener
,
57 css::lang::EventObject
const & event
)
59 disposeNotifications_
.emplace_back(listener
, event
);
62 void Broadcaster::addContainerElementReplacedNotification(
63 css::uno::Reference
< css::container::XContainerListener
> const & listener
,
64 css::container::ContainerEvent
const & event
)
66 containerElementReplacedNotifications_
.emplace_back(listener
, event
);
69 void Broadcaster::addContainerElementInsertedNotification(
70 css::uno::Reference
< css::container::XContainerListener
> const & listener
,
71 css::container::ContainerEvent
const & event
)
73 containerElementInsertedNotifications_
.emplace_back(listener
, event
);
76 void Broadcaster::addContainerElementRemovedNotification(
77 css::uno::Reference
< css::container::XContainerListener
> const & listener
,
78 css::container::ContainerEvent
const & event
)
80 containerElementRemovedNotifications_
.emplace_back(listener
, event
);
83 void Broadcaster::addPropertyChangeNotification(
84 css::uno::Reference
< css::beans::XPropertyChangeListener
> const & listener
,
85 css::beans::PropertyChangeEvent
const & event
)
87 propertyChangeNotifications_
.emplace_back(listener
, event
);
90 void Broadcaster::addPropertiesChangeNotification(
91 css::uno::Reference
< css::beans::XPropertiesChangeListener
> const &
93 css::uno::Sequence
< css::beans::PropertyChangeEvent
> const & event
)
95 propertiesChangeNotifications_
.emplace_back(listener
, event
);
98 void Broadcaster::addChangesNotification(
99 css::uno::Reference
< css::util::XChangesListener
> const & listener
,
100 css::util::ChangesEvent
const & event
)
102 changesNotifications_
.emplace_back(listener
, event
);
105 void Broadcaster::send() {
106 css::uno::Any exception
;
107 OUStringBuffer messages
;
108 for (auto& rNotification
: disposeNotifications_
) {
110 rNotification
.listener
->disposing(rNotification
.event
);
111 } catch (css::lang::DisposedException
&) {
112 } catch (css::uno::Exception
& e
) {
113 exception
= cppu::getCaughtException();
114 appendMessage(messages
, e
);
117 for (auto& rNotification
: containerElementInsertedNotifications_
)
120 rNotification
.listener
->elementInserted(rNotification
.event
);
121 } catch (css::lang::DisposedException
&) {
122 } catch (css::uno::Exception
& e
) {
123 exception
= cppu::getCaughtException();
124 appendMessage(messages
, e
);
127 for (auto& rNotification
: containerElementRemovedNotifications_
)
130 rNotification
.listener
->elementRemoved(rNotification
.event
);
131 } catch (css::lang::DisposedException
&) {
132 } catch (css::uno::Exception
& e
) {
133 exception
= cppu::getCaughtException();
134 appendMessage(messages
, e
);
137 for (auto& rNotification
: containerElementReplacedNotifications_
)
140 rNotification
.listener
->elementReplaced(rNotification
.event
);
141 } catch (css::lang::DisposedException
&) {
142 } catch (css::uno::Exception
& e
) {
143 exception
= cppu::getCaughtException();
144 appendMessage(messages
, e
);
147 for (auto& rNotification
: propertyChangeNotifications_
)
150 rNotification
.listener
->propertyChange(rNotification
.event
);
151 } catch (css::lang::DisposedException
&) {
152 } catch (css::uno::Exception
& e
) {
153 exception
= cppu::getCaughtException();
154 appendMessage(messages
, e
);
157 for (auto& rNotification
: propertiesChangeNotifications_
)
160 rNotification
.listener
->propertiesChange(rNotification
.event
);
161 } catch (css::lang::DisposedException
&) {
162 } catch (css::uno::Exception
& e
) {
163 exception
= cppu::getCaughtException();
164 appendMessage(messages
, e
);
167 for (auto& rNotification
: changesNotifications_
) {
169 rNotification
.listener
->changesOccurred(rNotification
.event
);
170 } catch (css::lang::DisposedException
&) {
171 } catch (css::uno::Exception
& e
) {
172 exception
= cppu::getCaughtException();
173 appendMessage(messages
, e
);
176 if (exception
.hasValue()) {
177 throw css::lang::WrappedTargetRuntimeException(
178 ("configmgr exceptions during listener notification" +
180 css::uno::Reference
< css::uno::XInterface
>(),
185 Broadcaster::DisposeNotification::DisposeNotification(
186 css::uno::Reference
< css::lang::XEventListener
> const & theListener
,
187 css::lang::EventObject theEvent
):
188 listener(theListener
), event(std::move(theEvent
))
190 assert(theListener
.is());
193 Broadcaster::ContainerNotification::ContainerNotification(
194 css::uno::Reference
< css::container::XContainerListener
> const &
196 css::container::ContainerEvent theEvent
):
197 listener(theListener
), event(std::move(theEvent
))
199 assert(theListener
.is());
202 Broadcaster::PropertyChangeNotification::PropertyChangeNotification(
203 css::uno::Reference
< css::beans::XPropertyChangeListener
> const &
205 css::beans::PropertyChangeEvent theEvent
):
206 listener(theListener
), event(std::move(theEvent
))
208 assert(theListener
.is());
211 Broadcaster::PropertiesChangeNotification::PropertiesChangeNotification(
212 css::uno::Reference
< css::beans::XPropertiesChangeListener
> const &
214 css::uno::Sequence
< css::beans::PropertyChangeEvent
> const & theEvent
):
215 listener(theListener
), event(theEvent
)
217 assert(theListener
.is());
220 Broadcaster::ChangesNotification::ChangesNotification(
221 css::uno::Reference
< css::util::XChangesListener
> const & theListener
,
222 css::util::ChangesEvent theEvent
):
223 listener(theListener
), event(std::move(theEvent
))
225 assert(theListener
.is());
230 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */