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