LCOV - code coverage report
Current view: top level - configmgr/source - broadcaster.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 46 103 44.7 %
Date: 2015-06-13 12:38:46 Functions: 7 14 50.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.11