1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_filter.hxx"
26 
27 #include "configflush.hxx"
28 #include "constant.hxx"
29 
30 //_______________________________________________
31 // includes
32 #include <osl/diagnose.h>
33 
34 //_______________________________________________
35 // namespace
36 
37 namespace css = ::com::sun::star;
38 
39 namespace filter{
40     namespace config{
41 
42 //_______________________________________________
43 // definitions
44 
45 //-----------------------------------------------
ConfigFlush(const css::uno::Reference<css::lang::XMultiServiceFactory> & xSMGR)46 ConfigFlush::ConfigFlush(const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR)
47     : BaseLock   (       )
48     , m_xSMGR    (xSMGR  )
49     , m_lListener(m_aLock)
50 {
51 }
52 
53 //-----------------------------------------------
~ConfigFlush()54 ConfigFlush::~ConfigFlush()
55 {
56 }
57 
58 //-----------------------------------------------
getImplementationName()59 ::rtl::OUString SAL_CALL ConfigFlush::getImplementationName()
60     throw (css::uno::RuntimeException)
61 {
62     return impl_getImplementationName();
63     // <- SAFE
64 }
65 
66 //-----------------------------------------------
supportsService(const::rtl::OUString & sServiceName)67 sal_Bool SAL_CALL ConfigFlush::supportsService(const ::rtl::OUString& sServiceName)
68     throw (css::uno::RuntimeException)
69 {
70           css::uno::Sequence< ::rtl::OUString > lServiceNames = impl_getSupportedServiceNames();
71           sal_Int32                             c             = lServiceNames.getLength();
72     const ::rtl::OUString*                      pNames        = lServiceNames.getConstArray();
73     for (sal_Int32 i=0; i<c; ++i)
74     {
75         if (pNames[i].equals(sServiceName))
76             return sal_True;
77     }
78     return sal_False;
79 }
80 
81 //-----------------------------------------------
getSupportedServiceNames()82 css::uno::Sequence< ::rtl::OUString > SAL_CALL ConfigFlush::getSupportedServiceNames()
83     throw (css::uno::RuntimeException)
84 {
85     return impl_getSupportedServiceNames();
86 }
87 
88 //-----------------------------------------------
refresh()89 void SAL_CALL ConfigFlush::refresh()
90     throw(css::uno::RuntimeException)
91 {
92     // notify listener outside the lock!
93     // The used listener helper lives if we live
94     // and is threadsafe by itself.
95     // Further its not a good idea to hold the own lock
96     // if an outside object is called :-)
97     css::lang::EventObject             aSource    (static_cast< css::util::XRefreshable* >(this));
98     ::cppu::OInterfaceContainerHelper* pContainer = m_lListener.getContainer(::getCppuType(static_cast< css::uno::Reference< css::util::XRefreshListener >* >(NULL)));
99     if (pContainer)
100     {
101         ::cppu::OInterfaceIteratorHelper pIterator(*pContainer);
102         while (pIterator.hasMoreElements())
103         {
104             try
105             {
106                 // ... this pointer can be interesting to find out, where will be called as listener
107                 // Dont optimize it to a direct iterator cast :-)
108                 css::util::XRefreshListener* pListener = (css::util::XRefreshListener*)pIterator.next();
109                 pListener->refreshed(aSource);
110             }
111             catch(const css::uno::Exception&)
112             {
113                 // ignore any "damaged" flush listener!
114                 // May its remote reference is broken ...
115                 pIterator.remove();
116             }
117         }
118     }
119 }
120 
121 //-----------------------------------------------
addRefreshListener(const css::uno::Reference<css::util::XRefreshListener> & xListener)122 void SAL_CALL ConfigFlush::addRefreshListener(const css::uno::Reference< css::util::XRefreshListener >& xListener)
123     throw(css::uno::RuntimeException)
124 {
125     // no locks necessary
126     // used helper lives if we live and is threadsafe by itself ...
127     m_lListener.addInterface(::getCppuType(static_cast< css::uno::Reference< css::util::XRefreshListener >* >(NULL)),
128                              xListener);
129 }
130 
131 //-----------------------------------------------
removeRefreshListener(const css::uno::Reference<css::util::XRefreshListener> & xListener)132 void SAL_CALL ConfigFlush::removeRefreshListener(const css::uno::Reference< css::util::XRefreshListener >& xListener)
133     throw(css::uno::RuntimeException)
134 {
135     // no locks necessary
136     // used helper lives if we live and is threadsafe by itself ...
137     m_lListener.removeInterface(::getCppuType(static_cast< css::uno::Reference< css::util::XRefreshListener >* >(NULL)),
138                                 xListener);
139 }
140 
141 //-----------------------------------------------
impl_getImplementationName()142 ::rtl::OUString ConfigFlush::impl_getImplementationName()
143 {
144     static ::rtl::OUString IMPLNAME = ::rtl::OUString::createFromAscii("com.sun.star.comp.filter.config.ConfigFlush");
145     return IMPLNAME;
146 }
147 
148 //-----------------------------------------------
impl_getSupportedServiceNames()149 css::uno::Sequence< ::rtl::OUString > ConfigFlush::impl_getSupportedServiceNames()
150 {
151     css::uno::Sequence< ::rtl::OUString > lServiceNames(1);
152     lServiceNames[0] = SERVICE_FILTERCONFIGREFRESH;
153     return lServiceNames;
154 }
155 
156 //-----------------------------------------------
impl_createInstance(const css::uno::Reference<css::lang::XMultiServiceFactory> & xSMGR)157 css::uno::Reference< css::uno::XInterface > ConfigFlush::impl_createInstance(const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR)
158 {
159     ConfigFlush* pNew = new ConfigFlush(xSMGR);
160     return css::uno::Reference< css::uno::XInterface >(static_cast< css::util::XRefreshable* >(pNew), css::uno::UNO_QUERY);
161 }
162 
163     } // namespace config
164 } // namespace filter
165