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