LibreOffice Module configmgr (master) 1
broadcaster.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
20#include <sal/config.h>
21
22#include <cassert>
23
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>
36#include <rtl/ustrbuf.hxx>
37#include <rtl/ustring.hxx>
38#include <utility>
39
40#include "broadcaster.hxx"
41
42namespace configmgr {
43
44namespace {
45
46void appendMessage(
47 OUStringBuffer & buffer, css::uno::Exception const & exception)
48{
49 buffer.append("; ");
50 buffer.append(exception.Message);
51}
52
53}
54
56 css::uno::Reference< css::lang::XEventListener > const & listener,
57 css::lang::EventObject const & event)
58{
59 disposeNotifications_.emplace_back(listener, event);
60}
61
63 css::uno::Reference< css::container::XContainerListener > const & listener,
64 css::container::ContainerEvent const & event)
65{
66 containerElementReplacedNotifications_.emplace_back(listener, event);
67}
68
70 css::uno::Reference< css::container::XContainerListener > const & listener,
71 css::container::ContainerEvent const & event)
72{
73 containerElementInsertedNotifications_.emplace_back(listener, event);
74}
75
77 css::uno::Reference< css::container::XContainerListener > const & listener,
78 css::container::ContainerEvent const & event)
79{
80 containerElementRemovedNotifications_.emplace_back(listener, event);
81}
82
84 css::uno::Reference< css::beans::XPropertyChangeListener > const & listener,
85 css::beans::PropertyChangeEvent const & event)
86{
87 propertyChangeNotifications_.emplace_back(listener, event);
88}
89
91 css::uno::Reference< css::beans::XPropertiesChangeListener > const &
92 listener,
93 css::uno::Sequence< css::beans::PropertyChangeEvent > const & event)
94{
95 propertiesChangeNotifications_.emplace_back(listener, event);
96}
97
99 css::uno::Reference< css::util::XChangesListener > const & listener,
100 css::util::ChangesEvent const & event, bool bRootListener)
101{
102 if (bRootListener)
103 rootChangesNotifications_.emplace_back(listener, event);
104 else
105 changesNotifications_.emplace_back(listener, event);
106}
107
109 css::uno::Any exception;
110 OUStringBuffer messages;
111 for (auto& rNotification : disposeNotifications_) {
112 try {
113 rNotification.listener->disposing(rNotification.event);
114 } catch (css::lang::DisposedException &) {
115 } catch (css::uno::Exception & e) {
116 exception = cppu::getCaughtException();
117 appendMessage(messages, e);
118 }
119 }
120 for (auto& rNotification : containerElementInsertedNotifications_)
121 {
122 try {
123 rNotification.listener->elementInserted(rNotification.event);
124 } catch (css::lang::DisposedException &) {
125 } catch (css::uno::Exception & e) {
126 exception = cppu::getCaughtException();
127 appendMessage(messages, e);
128 }
129 }
130 for (auto& rNotification : containerElementRemovedNotifications_)
131 {
132 try {
133 rNotification.listener->elementRemoved(rNotification.event);
134 } catch (css::lang::DisposedException &) {
135 } catch (css::uno::Exception & e) {
136 exception = cppu::getCaughtException();
137 appendMessage(messages, e);
138 }
139 }
140 for (auto& rNotification : containerElementReplacedNotifications_)
141 {
142 try {
143 rNotification.listener->elementReplaced(rNotification.event);
144 } catch (css::lang::DisposedException &) {
145 } catch (css::uno::Exception & e) {
146 exception = cppu::getCaughtException();
147 appendMessage(messages, e);
148 }
149 }
150 for (auto& rNotification : propertyChangeNotifications_)
151 {
152 try {
153 rNotification.listener->propertyChange(rNotification.event);
154 } catch (css::lang::DisposedException &) {
155 } catch (css::uno::Exception & e) {
156 exception = cppu::getCaughtException();
157 appendMessage(messages, e);
158 }
159 }
160 for (auto& rNotification : propertiesChangeNotifications_)
161 {
162 try {
163 rNotification.listener->propertiesChange(rNotification.event);
164 } catch (css::lang::DisposedException &) {
165 } catch (css::uno::Exception & e) {
166 exception = cppu::getCaughtException();
167 appendMessage(messages, e);
168 }
169 }
170 // First root listeners, then the rest
171 for (const auto& container : { rootChangesNotifications_ , changesNotifications_})
172 {
173 for (auto& rNotification : container) {
174 try {
175 rNotification.listener->changesOccurred(rNotification.event);
176 } catch (css::lang::DisposedException &) {
177 } catch (css::uno::Exception & e) {
178 exception = cppu::getCaughtException();
179 appendMessage(messages, e);
180 }
181 }
182 }
183 if (exception.hasValue()) {
184 throw css::lang::WrappedTargetRuntimeException(
185 ("configmgr exceptions during listener notification" +
186 messages),
187 css::uno::Reference< css::uno::XInterface >(),
188 exception);
189 }
190}
191
193 css::uno::Reference< css::lang::XEventListener > const & theListener,
194 css::lang::EventObject theEvent):
195 listener(theListener), event(std::move(theEvent))
196{
197 assert(theListener.is());
198}
199
201 css::uno::Reference< css::container::XContainerListener > const &
202 theListener,
203 css::container::ContainerEvent theEvent):
204 listener(theListener), event(std::move(theEvent))
205{
206 assert(theListener.is());
207}
208
210 css::uno::Reference< css::beans::XPropertyChangeListener > const &
211 theListener,
212 css::beans::PropertyChangeEvent theEvent):
213 listener(theListener), event(std::move(theEvent))
214{
215 assert(theListener.is());
216}
217
219 css::uno::Reference< css::beans::XPropertiesChangeListener > const &
220 theListener,
221 css::uno::Sequence< css::beans::PropertyChangeEvent > const & theEvent):
222 listener(theListener), event(theEvent)
223{
224 assert(theListener.is());
225}
226
228 css::uno::Reference< css::util::XChangesListener > const & theListener,
229 css::util::ChangesEvent theEvent):
230 listener(theListener), event(std::move(theEvent))
231{
232 assert(theListener.is());
233}
234
235}
236
237/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void addContainerElementRemovedNotification(css::uno::Reference< css::container::XContainerListener > const &listener, css::container::ContainerEvent const &event)
Definition: broadcaster.cxx:76
void addChangesNotification(css::uno::Reference< css::util::XChangesListener > const &listener, css::util::ChangesEvent const &event, bool bRootListener)
Definition: broadcaster.cxx:98
std::vector< ContainerNotification > containerElementRemovedNotifications_
std::vector< ChangesNotification > rootChangesNotifications_
std::vector< ChangesNotification > changesNotifications_
void addContainerElementReplacedNotification(css::uno::Reference< css::container::XContainerListener > const &listener, css::container::ContainerEvent const &event)
Definition: broadcaster.cxx:62
std::vector< ContainerNotification > containerElementReplacedNotifications_
void addContainerElementInsertedNotification(css::uno::Reference< css::container::XContainerListener > const &listener, css::container::ContainerEvent const &event)
Definition: broadcaster.cxx:69
std::vector< ContainerNotification > containerElementInsertedNotifications_
void addPropertyChangeNotification(css::uno::Reference< css::beans::XPropertyChangeListener > const &listener, css::beans::PropertyChangeEvent const &event)
Definition: broadcaster.cxx:83
std::vector< PropertiesChangeNotification > propertiesChangeNotifications_
void addDisposeNotification(css::uno::Reference< css::lang::XEventListener > const &listener, css::lang::EventObject const &event)
Definition: broadcaster.cxx:55
void addPropertiesChangeNotification(css::uno::Reference< css::beans::XPropertiesChangeListener > const &listener, css::uno::Sequence< css::beans::PropertyChangeEvent > const &event)
Definition: broadcaster.cxx:90
std::vector< PropertyChangeNotification > propertyChangeNotifications_
std::vector< DisposeNotification > disposeNotifications_
Any SAL_CALL getCaughtException()
ChangesNotification(css::uno::Reference< css::util::XChangesListener > const &theListener, css::util::ChangesEvent theEvent)
ContainerNotification(css::uno::Reference< css::container::XContainerListener > const &theListener, css::container::ContainerEvent theEvent)
DisposeNotification(css::uno::Reference< css::lang::XEventListener > const &theListener, css::lang::EventObject theEvent)
PropertiesChangeNotification(css::uno::Reference< css::beans::XPropertiesChangeListener > const &theListener, css::uno::Sequence< css::beans::PropertyChangeEvent > const &theEvent)
PropertyChangeNotification(css::uno::Reference< css::beans::XPropertyChangeListener > const &theListener, css::beans::PropertyChangeEvent theEvent)