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 "configflush.hxx"
21 #include "constant.hxx"
22 #include <cppuhelper/supportsservice.hxx>
23 
24 
25 namespace filter{
26     namespace config{
27 
ConfigFlush()28 ConfigFlush::ConfigFlush()
29     : BaseLock   (       )
30     , m_lListener(m_aLock)
31 {
32 }
33 
~ConfigFlush()34 ConfigFlush::~ConfigFlush()
35 {
36 }
37 
getImplementationName()38 OUString SAL_CALL ConfigFlush::getImplementationName()
39 {
40     return impl_getImplementationName();
41     // <- SAFE
42 }
43 
supportsService(const OUString & sServiceName)44 sal_Bool SAL_CALL ConfigFlush::supportsService(const OUString& sServiceName)
45 {
46     return cppu::supportsService(this, sServiceName);
47 }
48 
getSupportedServiceNames()49 css::uno::Sequence< OUString > SAL_CALL ConfigFlush::getSupportedServiceNames()
50 {
51     return impl_getSupportedServiceNames();
52 }
53 
refresh()54 void SAL_CALL ConfigFlush::refresh()
55 {
56     // notify listener outside the lock!
57     // The used listener helper lives if we live
58     // and is threadsafe by itself.
59     // Further it's not a good idea to hold the own lock
60     // if an outside object is called :-)
61     css::lang::EventObject             aSource    (static_cast< css::util::XRefreshable* >(this));
62     ::cppu::OInterfaceContainerHelper* pContainer = m_lListener.getContainer(cppu::UnoType<css::util::XRefreshListener>::get());
63     if (pContainer)
64     {
65         ::cppu::OInterfaceIteratorHelper pIterator(*pContainer);
66         while (pIterator.hasMoreElements())
67         {
68             try
69             {
70                 // ... this pointer can be interesting to find out, where will be called as listener
71                 // Don't optimize it to a direct iterator cast :-)
72                 css::util::XRefreshListener* pListener = static_cast<css::util::XRefreshListener*>(pIterator.next());
73                 pListener->refreshed(aSource);
74             }
75             catch(const css::uno::Exception&)
76             {
77                 // ignore any "damaged" flush listener!
78                 // May its remote reference is broken ...
79                 pIterator.remove();
80             }
81         }
82     }
83 }
84 
85 
addRefreshListener(const css::uno::Reference<css::util::XRefreshListener> & xListener)86 void SAL_CALL ConfigFlush::addRefreshListener(const css::uno::Reference< css::util::XRefreshListener >& xListener)
87 {
88     // no locks necessary
89     // used helper lives if we live and is threadsafe by itself ...
90     m_lListener.addInterface(cppu::UnoType<css::util::XRefreshListener>::get(),
91                              xListener);
92 }
93 
94 
removeRefreshListener(const css::uno::Reference<css::util::XRefreshListener> & xListener)95 void SAL_CALL ConfigFlush::removeRefreshListener(const css::uno::Reference< css::util::XRefreshListener >& xListener)
96 {
97     // no locks necessary
98     // used helper lives if we live and is threadsafe by itself ...
99     m_lListener.removeInterface(cppu::UnoType<css::util::XRefreshListener>::get(),
100                                 xListener);
101 }
102 
103 
impl_getImplementationName()104 OUString ConfigFlush::impl_getImplementationName()
105 {
106     return "com.sun.star.comp.filter.config.ConfigFlush";
107 }
108 
109 
impl_getSupportedServiceNames()110 css::uno::Sequence< OUString > ConfigFlush::impl_getSupportedServiceNames()
111 {
112     return { "com.sun.star.document.FilterConfigRefresh" };
113 }
114 
115 
impl_createInstance(const css::uno::Reference<css::lang::XMultiServiceFactory> &)116 css::uno::Reference< css::uno::XInterface > ConfigFlush::impl_createInstance(const css::uno::Reference< css::lang::XMultiServiceFactory >& )
117 {
118     ConfigFlush* pNew = new ConfigFlush;
119     return css::uno::Reference< css::uno::XInterface >(static_cast< css::util::XRefreshable* >(pNew), css::uno::UNO_QUERY);
120 }
121 
122     } // namespace config
123 } // namespace filter
124 
125 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
126