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>
35 #include <cppuhelper/exc_hlp.hxx>
36 #include <rtl/ustrbuf.hxx>
37 #include <rtl/ustring.hxx>
38 #include <utility>
39 
40 #include "broadcaster.hxx"
41 
42 namespace configmgr {
43 
44 namespace {
45 
46 void 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)
101 {
102  changesNotifications_.emplace_back(listener, event);
103 }
104 
106  css::uno::Any exception;
107  OUStringBuffer messages;
108  for (auto& rNotification : disposeNotifications_) {
109  try {
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);
115  }
116  }
117  for (auto& rNotification : containerElementInsertedNotifications_)
118  {
119  try {
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);
125  }
126  }
127  for (auto& rNotification : containerElementRemovedNotifications_)
128  {
129  try {
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);
135  }
136  }
137  for (auto& rNotification : containerElementReplacedNotifications_)
138  {
139  try {
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);
145  }
146  }
147  for (auto& rNotification : propertyChangeNotifications_)
148  {
149  try {
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);
155  }
156  }
157  for (auto& rNotification : propertiesChangeNotifications_)
158  {
159  try {
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);
165  }
166  }
167  for (auto& rNotification : changesNotifications_) {
168  try {
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);
174  }
175  }
176  if (exception.hasValue()) {
177  throw css::lang::WrappedTargetRuntimeException(
178  ("configmgr exceptions during listener notification" +
179  messages.makeStringAndClear()),
180  css::uno::Reference< css::uno::XInterface >(),
181  exception);
182  }
183 }
184 
186  css::uno::Reference< css::lang::XEventListener > const & theListener,
187  css::lang::EventObject theEvent):
188  listener(theListener), event(std::move(theEvent))
189 {
190  assert(theListener.is());
191 }
192 
194  css::uno::Reference< css::container::XContainerListener > const &
195  theListener,
196  css::container::ContainerEvent theEvent):
197  listener(theListener), event(std::move(theEvent))
198 {
199  assert(theListener.is());
200 }
201 
203  css::uno::Reference< css::beans::XPropertyChangeListener > const &
204  theListener,
205  css::beans::PropertyChangeEvent theEvent):
206  listener(theListener), event(std::move(theEvent))
207 {
208  assert(theListener.is());
209 }
210 
212  css::uno::Reference< css::beans::XPropertiesChangeListener > const &
213  theListener,
214  css::uno::Sequence< css::beans::PropertyChangeEvent > const & theEvent):
215  listener(theListener), event(theEvent)
216 {
217  assert(theListener.is());
218 }
219 
221  css::uno::Reference< css::util::XChangesListener > const & theListener,
222  css::util::ChangesEvent theEvent):
223  listener(theListener), event(std::move(theEvent))
224 {
225  assert(theListener.is());
226 }
227 
228 }
229 
230 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
PropertiesChangeNotification(css::uno::Reference< css::beans::XPropertiesChangeListener > const &theListener, css::uno::Sequence< css::beans::PropertyChangeEvent > const &theEvent)
void addChangesNotification(css::uno::Reference< css::util::XChangesListener > const &listener, css::util::ChangesEvent const &event)
Definition: broadcaster.cxx:98
ChangesNotification(css::uno::Reference< css::util::XChangesListener > const &theListener, css::util::ChangesEvent theEvent)
std::vector< ChangesNotification > changesNotifications_
void addPropertiesChangeNotification(css::uno::Reference< css::beans::XPropertiesChangeListener > const &listener, css::uno::Sequence< css::beans::PropertyChangeEvent > const &event)
Definition: broadcaster.cxx:90
ContainerNotification(css::uno::Reference< css::container::XContainerListener > const &theListener, css::container::ContainerEvent theEvent)
void addContainerElementRemovedNotification(css::uno::Reference< css::container::XContainerListener > const &listener, css::container::ContainerEvent const &event)
Definition: broadcaster.cxx:76
void addDisposeNotification(css::uno::Reference< css::lang::XEventListener > const &listener, css::lang::EventObject const &event)
Definition: broadcaster.cxx:55
void addContainerElementReplacedNotification(css::uno::Reference< css::container::XContainerListener > const &listener, css::container::ContainerEvent const &event)
Definition: broadcaster.cxx:62
Any SAL_CALL getCaughtException()
std::vector< ContainerNotification > containerElementInsertedNotifications_
std::vector< PropertiesChangeNotification > propertiesChangeNotifications_
void addContainerElementInsertedNotification(css::uno::Reference< css::container::XContainerListener > const &listener, css::container::ContainerEvent const &event)
Definition: broadcaster.cxx:69
std::vector< ContainerNotification > containerElementRemovedNotifications_
std::vector< PropertyChangeNotification > propertyChangeNotifications_
PropertyChangeNotification(css::uno::Reference< css::beans::XPropertyChangeListener > const &theListener, css::beans::PropertyChangeEvent theEvent)
DisposeNotification(css::uno::Reference< css::lang::XEventListener > const &theListener, css::lang::EventObject theEvent)
std::vector< ContainerNotification > containerElementReplacedNotifications_
std::vector< DisposeNotification > disposeNotifications_
void addPropertyChangeNotification(css::uno::Reference< css::beans::XPropertyChangeListener > const &listener, css::beans::PropertyChangeEvent const &event)
Definition: broadcaster.cxx:83