xref: /trunk/main/configmgr/source/broadcaster.cxx (revision 3a7cf181)
1*3a7cf181SAndrew Rist /**************************************************************
2*3a7cf181SAndrew Rist  *
3*3a7cf181SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*3a7cf181SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*3a7cf181SAndrew Rist  * distributed with this work for additional information
6*3a7cf181SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*3a7cf181SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*3a7cf181SAndrew Rist  * "License"); you may not use this file except in compliance
9*3a7cf181SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*3a7cf181SAndrew Rist  *
11*3a7cf181SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*3a7cf181SAndrew Rist  *
13*3a7cf181SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*3a7cf181SAndrew Rist  * software distributed under the License is distributed on an
15*3a7cf181SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*3a7cf181SAndrew Rist  * KIND, either express or implied.  See the License for the
17*3a7cf181SAndrew Rist  * specific language governing permissions and limitations
18*3a7cf181SAndrew Rist  * under the License.
19*3a7cf181SAndrew Rist  *
20*3a7cf181SAndrew Rist  *************************************************************/
21*3a7cf181SAndrew Rist 
22*3a7cf181SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #include "precompiled_configmgr.hxx"
25cdf0e10cSrcweir #include "sal/config.h"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include "com/sun/star/beans/XPropertiesChangeListener.hpp"
28cdf0e10cSrcweir #include "com/sun/star/beans/XPropertyChangeListener.hpp"
29cdf0e10cSrcweir #include "com/sun/star/container/XContainerListener.hpp"
30cdf0e10cSrcweir #include "com/sun/star/lang/DisposedException.hpp"
31cdf0e10cSrcweir #include "com/sun/star/lang/WrappedTargetRuntimeException.hpp"
32cdf0e10cSrcweir #include "com/sun/star/lang/XEventListener.hpp"
33cdf0e10cSrcweir #include "com/sun/star/uno/Any.hxx"
34cdf0e10cSrcweir #include "com/sun/star/uno/Exception.hpp"
35cdf0e10cSrcweir #include "com/sun/star/uno/Reference.hxx"
36cdf0e10cSrcweir #include "com/sun/star/uno/XInterface.hpp"
37cdf0e10cSrcweir #include "com/sun/star/util/XChangesListener.hpp"
38cdf0e10cSrcweir #include "cppuhelper/exc_hlp.hxx"
39cdf0e10cSrcweir #include "osl/diagnose.hxx"
40cdf0e10cSrcweir #include "rtl/string.h"
41cdf0e10cSrcweir #include "rtl/ustrbuf.hxx"
42cdf0e10cSrcweir #include "rtl/ustring.h"
43cdf0e10cSrcweir #include "rtl/ustring.hxx"
44cdf0e10cSrcweir 
45cdf0e10cSrcweir #include "broadcaster.hxx"
46cdf0e10cSrcweir 
47cdf0e10cSrcweir namespace configmgr {
48cdf0e10cSrcweir 
49cdf0e10cSrcweir namespace {
50cdf0e10cSrcweir 
51cdf0e10cSrcweir namespace css = com::sun::star;
52cdf0e10cSrcweir 
appendMessage(rtl::OUStringBuffer & buffer,css::uno::Exception const & exception)53cdf0e10cSrcweir void appendMessage(
54cdf0e10cSrcweir     rtl::OUStringBuffer & buffer, css::uno::Exception const & exception)
55cdf0e10cSrcweir {
56cdf0e10cSrcweir     buffer.appendAscii(RTL_CONSTASCII_STRINGPARAM("; "));
57cdf0e10cSrcweir     buffer.append(exception.Message);
58cdf0e10cSrcweir }
59cdf0e10cSrcweir 
60cdf0e10cSrcweir }
61cdf0e10cSrcweir 
addDisposeNotification(css::uno::Reference<css::lang::XEventListener> const & listener,css::lang::EventObject const & event)62cdf0e10cSrcweir void Broadcaster::addDisposeNotification(
63cdf0e10cSrcweir     css::uno::Reference< css::lang::XEventListener > const & listener,
64cdf0e10cSrcweir     css::lang::EventObject const & event)
65cdf0e10cSrcweir {
66cdf0e10cSrcweir     disposeNotifications_.push_back(DisposeNotification(listener, event));
67cdf0e10cSrcweir }
68cdf0e10cSrcweir 
addContainerElementReplacedNotification(css::uno::Reference<css::container::XContainerListener> const & listener,css::container::ContainerEvent const & event)69cdf0e10cSrcweir void Broadcaster::addContainerElementReplacedNotification(
70cdf0e10cSrcweir     css::uno::Reference< css::container::XContainerListener > const & listener,
71cdf0e10cSrcweir     css::container::ContainerEvent const & event)
72cdf0e10cSrcweir {
73cdf0e10cSrcweir     containerElementReplacedNotifications_.push_back(
74cdf0e10cSrcweir         ContainerNotification(listener, event));
75cdf0e10cSrcweir }
76cdf0e10cSrcweir 
addContainerElementInsertedNotification(css::uno::Reference<css::container::XContainerListener> const & listener,css::container::ContainerEvent const & event)77cdf0e10cSrcweir void Broadcaster::addContainerElementInsertedNotification(
78cdf0e10cSrcweir     css::uno::Reference< css::container::XContainerListener > const & listener,
79cdf0e10cSrcweir     css::container::ContainerEvent const & event)
80cdf0e10cSrcweir {
81cdf0e10cSrcweir     containerElementInsertedNotifications_.push_back(
82cdf0e10cSrcweir         ContainerNotification(listener, event));
83cdf0e10cSrcweir }
84cdf0e10cSrcweir 
addContainerElementRemovedNotification(css::uno::Reference<css::container::XContainerListener> const & listener,css::container::ContainerEvent const & event)85cdf0e10cSrcweir void Broadcaster::addContainerElementRemovedNotification(
86cdf0e10cSrcweir     css::uno::Reference< css::container::XContainerListener > const & listener,
87cdf0e10cSrcweir     css::container::ContainerEvent const & event)
88cdf0e10cSrcweir {
89cdf0e10cSrcweir     containerElementRemovedNotifications_.push_back(
90cdf0e10cSrcweir         ContainerNotification(listener, event));
91cdf0e10cSrcweir }
92cdf0e10cSrcweir 
addPropertyChangeNotification(css::uno::Reference<css::beans::XPropertyChangeListener> const & listener,css::beans::PropertyChangeEvent const & event)93cdf0e10cSrcweir void Broadcaster::addPropertyChangeNotification(
94cdf0e10cSrcweir     css::uno::Reference< css::beans::XPropertyChangeListener > const & listener,
95cdf0e10cSrcweir     css::beans::PropertyChangeEvent const & event)
96cdf0e10cSrcweir {
97cdf0e10cSrcweir     propertyChangeNotifications_.push_back(
98cdf0e10cSrcweir         PropertyChangeNotification(listener, event));
99cdf0e10cSrcweir }
100cdf0e10cSrcweir 
addPropertiesChangeNotification(css::uno::Reference<css::beans::XPropertiesChangeListener> const & listener,css::uno::Sequence<css::beans::PropertyChangeEvent> const & event)101cdf0e10cSrcweir void Broadcaster::addPropertiesChangeNotification(
102cdf0e10cSrcweir     css::uno::Reference< css::beans::XPropertiesChangeListener > const &
103cdf0e10cSrcweir         listener,
104cdf0e10cSrcweir     css::uno::Sequence< css::beans::PropertyChangeEvent > const & event)
105cdf0e10cSrcweir {
106cdf0e10cSrcweir     propertiesChangeNotifications_.push_back(
107cdf0e10cSrcweir         PropertiesChangeNotification(listener, event));
108cdf0e10cSrcweir }
109cdf0e10cSrcweir 
addChangesNotification(css::uno::Reference<css::util::XChangesListener> const & listener,css::util::ChangesEvent const & event)110cdf0e10cSrcweir void Broadcaster::addChangesNotification(
111cdf0e10cSrcweir     css::uno::Reference< css::util::XChangesListener > const & listener,
112cdf0e10cSrcweir     css::util::ChangesEvent const & event)
113cdf0e10cSrcweir {
114cdf0e10cSrcweir     changesNotifications_.push_back(ChangesNotification(listener, event));
115cdf0e10cSrcweir }
116cdf0e10cSrcweir 
send()117cdf0e10cSrcweir void Broadcaster::send() {
118cdf0e10cSrcweir     css::uno::Any exception;
119cdf0e10cSrcweir     rtl::OUStringBuffer messages;
120cdf0e10cSrcweir     for (DisposeNotifications::iterator i(disposeNotifications_.begin());
121cdf0e10cSrcweir          i != disposeNotifications_.end(); ++i) {
122cdf0e10cSrcweir         try {
123cdf0e10cSrcweir             i->listener->disposing(i->event);
124cdf0e10cSrcweir         } catch (css::lang::DisposedException &) {
125cdf0e10cSrcweir         } catch (css::uno::Exception & e) {
126cdf0e10cSrcweir             exception = cppu::getCaughtException();
127cdf0e10cSrcweir             appendMessage(messages, e);
128cdf0e10cSrcweir         }
129cdf0e10cSrcweir     }
130cdf0e10cSrcweir     for (ContainerNotifications::iterator i(
131cdf0e10cSrcweir              containerElementInsertedNotifications_.begin());
132cdf0e10cSrcweir          i != containerElementInsertedNotifications_.end(); ++i)
133cdf0e10cSrcweir     {
134cdf0e10cSrcweir         try {
135cdf0e10cSrcweir             i->listener->elementInserted(i->event);
136cdf0e10cSrcweir         } catch (css::lang::DisposedException &) {
137cdf0e10cSrcweir         } catch (css::uno::Exception & e) {
138cdf0e10cSrcweir             exception = cppu::getCaughtException();
139cdf0e10cSrcweir             appendMessage(messages, e);
140cdf0e10cSrcweir         }
141cdf0e10cSrcweir     }
142cdf0e10cSrcweir     for (ContainerNotifications::iterator i(
143cdf0e10cSrcweir              containerElementRemovedNotifications_.begin());
144cdf0e10cSrcweir          i != containerElementRemovedNotifications_.end(); ++i)
145cdf0e10cSrcweir     {
146cdf0e10cSrcweir         try {
147cdf0e10cSrcweir             i->listener->elementRemoved(i->event);
148cdf0e10cSrcweir         } catch (css::lang::DisposedException &) {
149cdf0e10cSrcweir         } catch (css::uno::Exception & e) {
150cdf0e10cSrcweir             exception = cppu::getCaughtException();
151cdf0e10cSrcweir             appendMessage(messages, e);
152cdf0e10cSrcweir         }
153cdf0e10cSrcweir     }
154cdf0e10cSrcweir     for (ContainerNotifications::iterator i(
155cdf0e10cSrcweir              containerElementReplacedNotifications_.begin());
156cdf0e10cSrcweir          i != containerElementReplacedNotifications_.end(); ++i)
157cdf0e10cSrcweir     {
158cdf0e10cSrcweir         try {
159cdf0e10cSrcweir             i->listener->elementReplaced(i->event);
160cdf0e10cSrcweir         } catch (css::lang::DisposedException &) {
161cdf0e10cSrcweir         } catch (css::uno::Exception & e) {
162cdf0e10cSrcweir             exception = cppu::getCaughtException();
163cdf0e10cSrcweir             appendMessage(messages, e);
164cdf0e10cSrcweir         }
165cdf0e10cSrcweir     }
166cdf0e10cSrcweir     for (PropertyChangeNotifications::iterator i(
167cdf0e10cSrcweir              propertyChangeNotifications_.begin());
168cdf0e10cSrcweir          i != propertyChangeNotifications_.end(); ++i)
169cdf0e10cSrcweir     {
170cdf0e10cSrcweir         try {
171cdf0e10cSrcweir             i->listener->propertyChange(i->event);
172cdf0e10cSrcweir         } catch (css::lang::DisposedException &) {
173cdf0e10cSrcweir         } catch (css::uno::Exception & e) {
174cdf0e10cSrcweir             exception = cppu::getCaughtException();
175cdf0e10cSrcweir             appendMessage(messages, e);
176cdf0e10cSrcweir         }
177cdf0e10cSrcweir     }
178cdf0e10cSrcweir     for (PropertiesChangeNotifications::iterator i(
179cdf0e10cSrcweir              propertiesChangeNotifications_.begin());
180cdf0e10cSrcweir          i != propertiesChangeNotifications_.end(); ++i)
181cdf0e10cSrcweir     {
182cdf0e10cSrcweir         try {
183cdf0e10cSrcweir             i->listener->propertiesChange(i->event);
184cdf0e10cSrcweir         } catch (css::lang::DisposedException &) {
185cdf0e10cSrcweir         } catch (css::uno::Exception & e) {
186cdf0e10cSrcweir             exception = cppu::getCaughtException();
187cdf0e10cSrcweir             appendMessage(messages, e);
188cdf0e10cSrcweir         }
189cdf0e10cSrcweir     }
190cdf0e10cSrcweir     for (ChangesNotifications::iterator i(changesNotifications_.begin());
191cdf0e10cSrcweir          i != changesNotifications_.end(); ++i) {
192cdf0e10cSrcweir         try {
193cdf0e10cSrcweir             i->listener->changesOccurred(i->event);
194cdf0e10cSrcweir         } catch (css::lang::DisposedException &) {
195cdf0e10cSrcweir         } catch (css::uno::Exception & e) {
196cdf0e10cSrcweir             exception = cppu::getCaughtException();
197cdf0e10cSrcweir             appendMessage(messages, e);
198cdf0e10cSrcweir         }
199cdf0e10cSrcweir     }
200cdf0e10cSrcweir     if (exception.hasValue()) {
201cdf0e10cSrcweir         throw css::lang::WrappedTargetRuntimeException(
202cdf0e10cSrcweir             (rtl::OUString(
203cdf0e10cSrcweir                 RTL_CONSTASCII_USTRINGPARAM(
204cdf0e10cSrcweir                     "configmgr exceptions during listener notification")) +
205cdf0e10cSrcweir              messages.makeStringAndClear()),
206cdf0e10cSrcweir             css::uno::Reference< css::uno::XInterface >(),
207cdf0e10cSrcweir             exception);
208cdf0e10cSrcweir     }
209cdf0e10cSrcweir }
210cdf0e10cSrcweir 
DisposeNotification(css::uno::Reference<css::lang::XEventListener> const & theListener,css::lang::EventObject const & theEvent)211cdf0e10cSrcweir Broadcaster::DisposeNotification::DisposeNotification(
212cdf0e10cSrcweir     css::uno::Reference< css::lang::XEventListener > const & theListener,
213cdf0e10cSrcweir     css::lang::EventObject const & theEvent):
214cdf0e10cSrcweir     listener(theListener), event(theEvent)
215cdf0e10cSrcweir {
216cdf0e10cSrcweir     OSL_ASSERT(theListener.is());
217cdf0e10cSrcweir }
218cdf0e10cSrcweir 
ContainerNotification(css::uno::Reference<css::container::XContainerListener> const & theListener,css::container::ContainerEvent const & theEvent)219cdf0e10cSrcweir Broadcaster::ContainerNotification::ContainerNotification(
220cdf0e10cSrcweir     css::uno::Reference< css::container::XContainerListener > const &
221cdf0e10cSrcweir         theListener,
222cdf0e10cSrcweir     css::container::ContainerEvent const & theEvent):
223cdf0e10cSrcweir     listener(theListener), event(theEvent)
224cdf0e10cSrcweir {
225cdf0e10cSrcweir     OSL_ASSERT(theListener.is());
226cdf0e10cSrcweir }
227cdf0e10cSrcweir 
PropertyChangeNotification(css::uno::Reference<css::beans::XPropertyChangeListener> const & theListener,css::beans::PropertyChangeEvent const & theEvent)228cdf0e10cSrcweir Broadcaster::PropertyChangeNotification::PropertyChangeNotification(
229cdf0e10cSrcweir     css::uno::Reference< css::beans::XPropertyChangeListener > const &
230cdf0e10cSrcweir         theListener,
231cdf0e10cSrcweir     css::beans::PropertyChangeEvent const & theEvent):
232cdf0e10cSrcweir     listener(theListener), event(theEvent)
233cdf0e10cSrcweir {
234cdf0e10cSrcweir     OSL_ASSERT(theListener.is());
235cdf0e10cSrcweir }
236cdf0e10cSrcweir 
PropertiesChangeNotification(css::uno::Reference<css::beans::XPropertiesChangeListener> const & theListener,css::uno::Sequence<css::beans::PropertyChangeEvent> const & theEvent)237cdf0e10cSrcweir Broadcaster::PropertiesChangeNotification::PropertiesChangeNotification(
238cdf0e10cSrcweir     css::uno::Reference< css::beans::XPropertiesChangeListener > const &
239cdf0e10cSrcweir         theListener,
240cdf0e10cSrcweir     css::uno::Sequence< css::beans::PropertyChangeEvent > const & theEvent):
241cdf0e10cSrcweir     listener(theListener), event(theEvent)
242cdf0e10cSrcweir {
243cdf0e10cSrcweir     OSL_ASSERT(theListener.is());
244cdf0e10cSrcweir }
245cdf0e10cSrcweir 
ChangesNotification(css::uno::Reference<css::util::XChangesListener> const & theListener,css::util::ChangesEvent const & theEvent)246cdf0e10cSrcweir Broadcaster::ChangesNotification::ChangesNotification(
247cdf0e10cSrcweir     css::uno::Reference< css::util::XChangesListener > const & theListener,
248cdf0e10cSrcweir     css::util::ChangesEvent const & theEvent):
249cdf0e10cSrcweir     listener(theListener), event(theEvent)
250cdf0e10cSrcweir {
251cdf0e10cSrcweir     OSL_ASSERT(theListener.is());
252cdf0e10cSrcweir }
253cdf0e10cSrcweir 
254cdf0e10cSrcweir }
255