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