bump product version to 6.3.0.0.beta1
[LibreOffice.git] / configmgr / source / broadcaster.cxx
blob206b6366f3f3f14d82754ebd2e010f0fc7239a23
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <sal/config.h>
22 #include <cassert>
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>
41 #include "broadcaster.hxx"
43 namespace configmgr {
45 namespace {
47 void appendMessage(
48 OUStringBuffer & buffer, css::uno::Exception const & exception)
50 buffer.append("; ");
51 buffer.append(exception.Message);
56 void Broadcaster::addDisposeNotification(
57 css::uno::Reference< css::lang::XEventListener > const & listener,
58 css::lang::EventObject const & event)
60 disposeNotifications_.emplace_back(listener, event);
63 void Broadcaster::addContainerElementReplacedNotification(
64 css::uno::Reference< css::container::XContainerListener > const & listener,
65 css::container::ContainerEvent const & event)
67 containerElementReplacedNotifications_.emplace_back(listener, event);
70 void Broadcaster::addContainerElementInsertedNotification(
71 css::uno::Reference< css::container::XContainerListener > const & listener,
72 css::container::ContainerEvent const & event)
74 containerElementInsertedNotifications_.emplace_back(listener, event);
77 void Broadcaster::addContainerElementRemovedNotification(
78 css::uno::Reference< css::container::XContainerListener > const & listener,
79 css::container::ContainerEvent const & event)
81 containerElementRemovedNotifications_.emplace_back(listener, event);
84 void Broadcaster::addPropertyChangeNotification(
85 css::uno::Reference< css::beans::XPropertyChangeListener > const & listener,
86 css::beans::PropertyChangeEvent const & event)
88 propertyChangeNotifications_.emplace_back(listener, event);
91 void Broadcaster::addPropertiesChangeNotification(
92 css::uno::Reference< css::beans::XPropertiesChangeListener > const &
93 listener,
94 css::uno::Sequence< css::beans::PropertyChangeEvent > const & event)
96 propertiesChangeNotifications_.emplace_back(listener, event);
99 void Broadcaster::addChangesNotification(
100 css::uno::Reference< css::util::XChangesListener > const & listener,
101 css::util::ChangesEvent const & event)
103 changesNotifications_.emplace_back(listener, event);
106 void Broadcaster::send() {
107 css::uno::Any exception;
108 OUStringBuffer messages;
109 for (auto& rNotification : disposeNotifications_) {
110 try {
111 rNotification.listener->disposing(rNotification.event);
112 } catch (css::lang::DisposedException &) {
113 } catch (css::uno::Exception & e) {
114 exception = cppu::getCaughtException();
115 appendMessage(messages, e);
118 for (auto& rNotification : containerElementInsertedNotifications_)
120 try {
121 rNotification.listener->elementInserted(rNotification.event);
122 } catch (css::lang::DisposedException &) {
123 } catch (css::uno::Exception & e) {
124 exception = cppu::getCaughtException();
125 appendMessage(messages, e);
128 for (auto& rNotification : containerElementRemovedNotifications_)
130 try {
131 rNotification.listener->elementRemoved(rNotification.event);
132 } catch (css::lang::DisposedException &) {
133 } catch (css::uno::Exception & e) {
134 exception = cppu::getCaughtException();
135 appendMessage(messages, e);
138 for (auto& rNotification : containerElementReplacedNotifications_)
140 try {
141 rNotification.listener->elementReplaced(rNotification.event);
142 } catch (css::lang::DisposedException &) {
143 } catch (css::uno::Exception & e) {
144 exception = cppu::getCaughtException();
145 appendMessage(messages, e);
148 for (auto& rNotification : propertyChangeNotifications_)
150 try {
151 rNotification.listener->propertyChange(rNotification.event);
152 } catch (css::lang::DisposedException &) {
153 } catch (css::uno::Exception & e) {
154 exception = cppu::getCaughtException();
155 appendMessage(messages, e);
158 for (auto& rNotification : propertiesChangeNotifications_)
160 try {
161 rNotification.listener->propertiesChange(rNotification.event);
162 } catch (css::lang::DisposedException &) {
163 } catch (css::uno::Exception & e) {
164 exception = cppu::getCaughtException();
165 appendMessage(messages, e);
168 for (auto& rNotification : changesNotifications_) {
169 try {
170 rNotification.listener->changesOccurred(rNotification.event);
171 } catch (css::lang::DisposedException &) {
172 } catch (css::uno::Exception & e) {
173 exception = cppu::getCaughtException();
174 appendMessage(messages, e);
177 if (exception.hasValue()) {
178 throw css::lang::WrappedTargetRuntimeException(
179 ("configmgr exceptions during listener notification" +
180 messages.makeStringAndClear()),
181 css::uno::Reference< css::uno::XInterface >(),
182 exception);
186 Broadcaster::DisposeNotification::DisposeNotification(
187 css::uno::Reference< css::lang::XEventListener > const & theListener,
188 css::lang::EventObject const & theEvent):
189 listener(theListener), event(theEvent)
191 assert(theListener.is());
194 Broadcaster::ContainerNotification::ContainerNotification(
195 css::uno::Reference< css::container::XContainerListener > const &
196 theListener,
197 css::container::ContainerEvent const & theEvent):
198 listener(theListener), event(theEvent)
200 assert(theListener.is());
203 Broadcaster::PropertyChangeNotification::PropertyChangeNotification(
204 css::uno::Reference< css::beans::XPropertyChangeListener > const &
205 theListener,
206 css::beans::PropertyChangeEvent const & theEvent):
207 listener(theListener), event(theEvent)
209 assert(theListener.is());
212 Broadcaster::PropertiesChangeNotification::PropertiesChangeNotification(
213 css::uno::Reference< css::beans::XPropertiesChangeListener > const &
214 theListener,
215 css::uno::Sequence< css::beans::PropertyChangeEvent > const & theEvent):
216 listener(theListener), event(theEvent)
218 assert(theListener.is());
221 Broadcaster::ChangesNotification::ChangesNotification(
222 css::uno::Reference< css::util::XChangesListener > const & theListener,
223 css::util::ChangesEvent const & theEvent):
224 listener(theListener), event(theEvent)
226 assert(theListener.is());
231 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */