Line data Source code
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"
35 : #include "cppuhelper/exc_hlp.hxx"
36 : #include "rtl/string.h"
37 : #include "rtl/ustrbuf.hxx"
38 : #include "rtl/ustring.h"
39 : #include "rtl/ustring.hxx"
40 :
41 : #include "broadcaster.hxx"
42 :
43 : namespace configmgr {
44 :
45 : namespace {
46 :
47 0 : void appendMessage(
48 : OUStringBuffer & buffer, css::uno::Exception const & exception)
49 : {
50 0 : buffer.appendAscii("; ");
51 0 : buffer.append(exception.Message);
52 0 : }
53 :
54 : }
55 :
56 0 : void Broadcaster::addDisposeNotification(
57 : css::uno::Reference< css::lang::XEventListener > const & listener,
58 : css::lang::EventObject const & event)
59 : {
60 0 : disposeNotifications_.push_back(DisposeNotification(listener, event));
61 0 : }
62 :
63 0 : void Broadcaster::addContainerElementReplacedNotification(
64 : css::uno::Reference< css::container::XContainerListener > const & listener,
65 : css::container::ContainerEvent const & event)
66 : {
67 : containerElementReplacedNotifications_.push_back(
68 0 : ContainerNotification(listener, event));
69 0 : }
70 :
71 0 : void Broadcaster::addContainerElementInsertedNotification(
72 : css::uno::Reference< css::container::XContainerListener > const & listener,
73 : css::container::ContainerEvent const & event)
74 : {
75 : containerElementInsertedNotifications_.push_back(
76 0 : ContainerNotification(listener, event));
77 0 : }
78 :
79 0 : void Broadcaster::addContainerElementRemovedNotification(
80 : css::uno::Reference< css::container::XContainerListener > const & listener,
81 : css::container::ContainerEvent const & event)
82 : {
83 : containerElementRemovedNotifications_.push_back(
84 0 : ContainerNotification(listener, event));
85 0 : }
86 :
87 0 : void Broadcaster::addPropertyChangeNotification(
88 : css::uno::Reference< css::beans::XPropertyChangeListener > const & listener,
89 : css::beans::PropertyChangeEvent const & event)
90 : {
91 : propertyChangeNotifications_.push_back(
92 0 : PropertyChangeNotification(listener, event));
93 0 : }
94 :
95 0 : void Broadcaster::addPropertiesChangeNotification(
96 : css::uno::Reference< css::beans::XPropertiesChangeListener > const &
97 : listener,
98 : css::uno::Sequence< css::beans::PropertyChangeEvent > const & event)
99 : {
100 : propertiesChangeNotifications_.push_back(
101 0 : PropertiesChangeNotification(listener, event));
102 0 : }
103 :
104 100 : void Broadcaster::addChangesNotification(
105 : css::uno::Reference< css::util::XChangesListener > const & listener,
106 : css::util::ChangesEvent const & event)
107 : {
108 100 : changesNotifications_.push_back(ChangesNotification(listener, event));
109 100 : }
110 :
111 6321 : void Broadcaster::send() {
112 6321 : css::uno::Any exception;
113 6321 : OUStringBuffer messages;
114 18963 : for (DisposeNotifications::iterator i(disposeNotifications_.begin());
115 12642 : i != disposeNotifications_.end(); ++i) {
116 : try {
117 0 : i->listener->disposing(i->event);
118 0 : } catch (css::lang::DisposedException &) {
119 0 : } catch (css::uno::Exception & e) {
120 0 : exception = cppu::getCaughtException();
121 0 : appendMessage(messages, e);
122 : }
123 : }
124 18963 : for (ContainerNotifications::iterator i(
125 6321 : containerElementInsertedNotifications_.begin());
126 12642 : i != containerElementInsertedNotifications_.end(); ++i)
127 : {
128 : try {
129 0 : i->listener->elementInserted(i->event);
130 0 : } catch (css::lang::DisposedException &) {
131 0 : } catch (css::uno::Exception & e) {
132 0 : exception = cppu::getCaughtException();
133 0 : appendMessage(messages, e);
134 : }
135 : }
136 18963 : for (ContainerNotifications::iterator i(
137 6321 : containerElementRemovedNotifications_.begin());
138 12642 : i != containerElementRemovedNotifications_.end(); ++i)
139 : {
140 : try {
141 0 : i->listener->elementRemoved(i->event);
142 0 : } catch (css::lang::DisposedException &) {
143 0 : } catch (css::uno::Exception & e) {
144 0 : exception = cppu::getCaughtException();
145 0 : appendMessage(messages, e);
146 : }
147 : }
148 18963 : for (ContainerNotifications::iterator i(
149 6321 : containerElementReplacedNotifications_.begin());
150 12642 : i != containerElementReplacedNotifications_.end(); ++i)
151 : {
152 : try {
153 0 : i->listener->elementReplaced(i->event);
154 0 : } catch (css::lang::DisposedException &) {
155 0 : } catch (css::uno::Exception & e) {
156 0 : exception = cppu::getCaughtException();
157 0 : appendMessage(messages, e);
158 : }
159 : }
160 18963 : for (PropertyChangeNotifications::iterator i(
161 6321 : propertyChangeNotifications_.begin());
162 12642 : i != propertyChangeNotifications_.end(); ++i)
163 : {
164 : try {
165 0 : i->listener->propertyChange(i->event);
166 0 : } catch (css::lang::DisposedException &) {
167 0 : } catch (css::uno::Exception & e) {
168 0 : exception = cppu::getCaughtException();
169 0 : appendMessage(messages, e);
170 : }
171 : }
172 18963 : for (PropertiesChangeNotifications::iterator i(
173 6321 : propertiesChangeNotifications_.begin());
174 12642 : i != propertiesChangeNotifications_.end(); ++i)
175 : {
176 : try {
177 0 : i->listener->propertiesChange(i->event);
178 0 : } catch (css::lang::DisposedException &) {
179 0 : } catch (css::uno::Exception & e) {
180 0 : exception = cppu::getCaughtException();
181 0 : appendMessage(messages, e);
182 : }
183 : }
184 19263 : for (ChangesNotifications::iterator i(changesNotifications_.begin());
185 12842 : i != changesNotifications_.end(); ++i) {
186 : try {
187 100 : i->listener->changesOccurred(i->event);
188 0 : } catch (css::lang::DisposedException &) {
189 0 : } catch (css::uno::Exception & e) {
190 0 : exception = cppu::getCaughtException();
191 0 : appendMessage(messages, e);
192 : }
193 : }
194 6321 : if (exception.hasValue()) {
195 : throw css::lang::WrappedTargetRuntimeException(
196 : (OUString("configmgr exceptions during listener notification") +
197 0 : messages.makeStringAndClear()),
198 : css::uno::Reference< css::uno::XInterface >(),
199 0 : exception);
200 6321 : }
201 6321 : }
202 :
203 0 : Broadcaster::DisposeNotification::DisposeNotification(
204 : css::uno::Reference< css::lang::XEventListener > const & theListener,
205 : css::lang::EventObject const & theEvent):
206 0 : listener(theListener), event(theEvent)
207 : {
208 : assert(theListener.is());
209 0 : }
210 :
211 0 : Broadcaster::ContainerNotification::ContainerNotification(
212 : css::uno::Reference< css::container::XContainerListener > const &
213 : theListener,
214 : css::container::ContainerEvent const & theEvent):
215 0 : listener(theListener), event(theEvent)
216 : {
217 : assert(theListener.is());
218 0 : }
219 :
220 0 : Broadcaster::PropertyChangeNotification::PropertyChangeNotification(
221 : css::uno::Reference< css::beans::XPropertyChangeListener > const &
222 : theListener,
223 : css::beans::PropertyChangeEvent const & theEvent):
224 0 : listener(theListener), event(theEvent)
225 : {
226 : assert(theListener.is());
227 0 : }
228 :
229 0 : Broadcaster::PropertiesChangeNotification::PropertiesChangeNotification(
230 : css::uno::Reference< css::beans::XPropertiesChangeListener > const &
231 : theListener,
232 : css::uno::Sequence< css::beans::PropertyChangeEvent > const & theEvent):
233 0 : listener(theListener), event(theEvent)
234 : {
235 : assert(theListener.is());
236 0 : }
237 :
238 100 : Broadcaster::ChangesNotification::ChangesNotification(
239 : css::uno::Reference< css::util::XChangesListener > const & theListener,
240 : css::util::ChangesEvent const & theEvent):
241 100 : listener(theListener), event(theEvent)
242 : {
243 : assert(theListener.is());
244 100 : }
245 :
246 : }
247 :
248 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|