xref: /AOO42X/main/filter/source/config/cache/basecontainer.hxx (revision a20a167bf92e72b6a7380d695bf6b310032dae91)
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 #ifndef __FILTER_CONFIG_BASECONTAINER_HXX_
23 #define __FILTER_CONFIG_BASECONTAINER_HXX_
24 
25 //_______________________________________________
26 // includes
27 
28 #include "filtercache.hxx"
29 #include <com/sun/star/uno/Exception.hpp>
30 #include <com/sun/star/lang/XServiceInfo.hpp>
31 #include <com/sun/star/util/XRefreshable.hpp>
32 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
33 #include <com/sun/star/container/XNameContainer.hpp>
34 #include <com/sun/star/container/XContainerQuery.hpp>
35 #include <com/sun/star/util/XFlushable.hpp>
36 #include <cppuhelper/interfacecontainer.h>
37 #include <salhelper/singletonref.hxx>
38 #include <cppuhelper/implbase4.hxx>
39 #include <cppuhelper/weakref.hxx>
40 #include <rtl/ustring.hxx>
41 
42 //_______________________________________________
43 // namespace
44 
45 namespace filter{
46     namespace config{
47 
48 //_______________________________________________
49 // definitions
50 
51 //_______________________________________________
52 
53 /** @short      implements the interface css::container::XNameContainer
54                 on top of a FilterCache reference.
55 
56     @descr      This class can be used as base for own service implementations,
57                 which must provide read/write access to the filter configuration.
58                 Parameters regulate read/write access, which sub set of information
59                 should be available etc.
60 
61     @attention  The base class BaseLock must be the first of declared ones.
62                 Otherwise we can't be sure, that our own mutex member (which is
63                 present by this base class!) was full initialized inside our own
64                 ctor as first!
65  */
66 class BaseContainer : public BaseLock
67                     , public ::cppu::WeakImplHelper4< css::lang::XServiceInfo         ,
68                                                       css::container::XNameContainer  , // => XNameReplace => XNameAccess => XElementAccess
69                                                       css::container::XContainerQuery ,
70                                                       css::util::XFlushable           >
71 {
72     //-------------------------------------------
73     // member
74 
75     protected:
76 
77         /** @short  reference to an uno service manager, which can be used
78                     to create own needed services. */
79         css::uno::Reference< css::lang::XMultiServiceFactory > m_xSMGR;
80 
81         // TODO
82         css::uno::WeakReference< css::util::XRefreshable > m_xRefreshBroadcaster;
83 
84         /** @short  the implementation name of our derived class, which we provide
85                     at the interface XServiceInfo of our class ... */
86         ::rtl::OUString m_sImplementationName;
87 
88         /** @short  the list of supported uno service names of our derived class, which we provide
89                     at the interface XServiceInfo of our class ... */
90         css::uno::Sequence< ::rtl::OUString > m_lServiceNames;
91 
92         /** @short  reference(!) to a singleton filter cache implementation,
93                     which is used to work with the underlying configuration. */
94         ::salhelper::SingletonRef< FilterCache > m_rCache;
95 
96         /** @short  local filter cache, which is used to collect changes on the
97                     filter configuration first and flush it later.
98 
99             @descr  Normally this member isn't used nor initialized. That's true,
100                     if this container is used for reading only. The first write access
101                     (e.g. by calling insertByName()) creates a copy of the current
102                     global cache m_rCache to initialize the m_pFlushCache member.
103 
104                     Afterwards only the flush cache copy is used. Inside flush() this
105                     copy will be removed and m_rCache can be used again.
106 
107                     m_pFlushCache and m_rCache must not be synchronized manually here.
108                     m_rCache listen on the global configuration, where m_pFlushCache
109                     write its data. m_rCache update itself automatically.
110          */
111         FilterCache* m_pFlushCache;
112 
113         /** @short  specify, which sub container of the used filter cache
114                     must be wrapped by this container interface. */
115         FilterCache::EItemType m_eType;
116 
117         /** @short  holds all listener, which are registered at this instance. */
118         ::cppu::OMultiTypeInterfaceContainerHelper m_lListener;
119 
120         /** @short  hold at least on filter cache instance alive and
121                     prevent he office from unloading this cache if no filter
122                     is currently used.*/
123         static ::salhelper::SingletonRef< FilterCache >* m_pPerformanceOptimizer;
124 
125     //-------------------------------------------
126     // native interface
127 
128     public:
129 
130         //---------------------------------------
131         // ctor/dtor
132 
133         /** @short  standard ctor.
134 
135             @descr  Because mostly this class is used as base class for own service
136                     implementations in combination with a ImplInheritanceHelper2 template ...
137                     there is no way to provide some initializing data through the ctor :-(
138                     This base class will be created inside its default ctor and must be
139                     initialized with its needed parameters explicitly by calling: "init()".
140 
141             @see    init()
142          */
143         BaseContainer();
144 
145         //---------------------------------------
146 
147         /** @short  standard dtor.
148          */
149         virtual ~BaseContainer();
150 
151         //---------------------------------------
152 
153         /** @short  initialize this generic instance with some specialized values
154                     from our derived object.
155 
156             @descr  Because an outside class must use ImplInheritanceHelper2 template to
157                     use us a base class ... and there is no way to pass such initializing
158                     parameters through a required default ctor ... we must be initialized
159                     by this special method. Of course this method must be called first before
160                     any other interface method is used.
161 
162             @param  xSMGR
163                     reference to the uno service manager, which created this service instance.
164 
165             @param  sImplementationName
166                     the implementation name of our derived class, which we provide
167                     at the interface XServiceInfo of our class ...
168 
169             @param  lServiceNames
170                     the list of supported uno service names of our derived class, which we provide
171                     at the interface XServiceInfo of our class ...
172 
173             @param  eType
174                     specify, which sub container of the used filter cache
175                     must be wrapped by this container interface.
176          */
177         virtual void init(const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR              ,
178                           const ::rtl::OUString&                                        sImplementationName,
179                           const css::uno::Sequence< ::rtl::OUString >&                  lServiceNames      ,
180                                 FilterCache::EItemType                                  eType              );
181 
182     //-------------------------------------------
183     // helper
184 
185     protected:
186 
187         //---------------------------------------
188 
189         /** @short  check if the underlying configuration data was already loaded
190                     and do it if necessary automatically.
191          */
192         void impl_loadOnDemand();
193 
194         //---------------------------------------
195 
196         /** @short  it creates the global instance m_pFilterCache, which is a copy
197                     of the global instance m_rCache, and will be used to change the
198                     configuration.
199 
200             @descr  If no exception occurs, its guaranteed, that the member m_rFlushCache
201                     was initialized right and can be used further.
202          */
203         void impl_initFlushMode()
204             throw (css::uno::RuntimeException);
205 
206         //---------------------------------------
207 
208         /** @short  returns a pointer to the current used cache member.
209 
210             @descr  Its a point to the FilterCache instance behind m_pFlushCache
211                     or m_rCache.
212 
213             @note   The lifetime of this pointer is restricted to the time, where
214                     the mutex of this BaseContainer instance is locked.
215                     Otherwise maybe the interface method flush() will destroy
216                     m_pFlushCache and the here returned pointer will be invalid!
217 
218                     Use:
219 
220                         Guard aLock(m_aLock);
221                             FilterCache* p = impl_getWorkingCache();
222                             p->doSomething();
223                         aLock.clear();
224                         // after this point p can't b e guaranteed any longer!
225          */
226         FilterCache* impl_getWorkingCache() const;
227 
228     //-------------------------------------------
229     // uno interface
230 
231     public:
232 
233         //---------------------------------------
234         // XServiceInfo
235 
236         virtual ::rtl::OUString SAL_CALL getImplementationName()
237             throw (css::uno::RuntimeException);
238 
239         virtual sal_Bool SAL_CALL supportsService(const ::rtl::OUString& sServiceName)
240             throw (css::uno::RuntimeException);
241 
242         virtual css::uno::Sequence< ::rtl::OUString > SAL_CALL getSupportedServiceNames()
243             throw (css::uno::RuntimeException);
244 
245         //---------------------------------------
246         // XNameContainer
247 
248         virtual void SAL_CALL insertByName(const ::rtl::OUString& sItem ,
249                                            const css::uno::Any&   aValue)
250             throw (css::lang::IllegalArgumentException  ,
251                    css::container::ElementExistException,
252                    css::lang::WrappedTargetException    ,
253                    css::uno::RuntimeException           );
254 
255         virtual void SAL_CALL removeByName(const ::rtl::OUString& sItem)
256             throw (css::container::NoSuchElementException,
257                    css::lang::WrappedTargetException     ,
258                    css::uno::RuntimeException            );
259 
260         //---------------------------------------
261         // XNameReplace
262 
263         virtual void SAL_CALL replaceByName(const ::rtl::OUString& sItem ,
264                                             const css::uno::Any&   aValue)
265             throw (css::lang::IllegalArgumentException   ,
266                    css::container::NoSuchElementException,
267                    css::lang::WrappedTargetException     ,
268                    css::uno::RuntimeException            );
269 
270         //---------------------------------------
271         // XElementAccess
272 
273         virtual css::uno::Any SAL_CALL getByName(const ::rtl::OUString& sItem)
274             throw (css::container::NoSuchElementException,
275                    css::lang::WrappedTargetException     ,
276                    css::uno::RuntimeException            );
277 
278         virtual css::uno::Sequence< ::rtl::OUString > SAL_CALL getElementNames()
279             throw (css::uno::RuntimeException);
280 
281         virtual sal_Bool SAL_CALL hasByName(const ::rtl::OUString& sItem)
282             throw (css::uno::RuntimeException);
283 
284         virtual css::uno::Type SAL_CALL getElementType()
285             throw (css::uno::RuntimeException);
286 
287         virtual sal_Bool SAL_CALL hasElements()
288             throw (css::uno::RuntimeException);
289 
290         //---------------------------------------
291         // XContainerQuery
292 
293         // must be implemented really by derived class ...
294         // We implement return of an empty result here only!
295         // But we show an assertion :-)
296         virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createSubSetEnumerationByQuery(const ::rtl::OUString& sQuery)
297             throw (css::uno::RuntimeException);
298 
299         virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createSubSetEnumerationByProperties(const css::uno::Sequence< css::beans::NamedValue >& lProperties)
300             throw (css::uno::RuntimeException);
301 
302         //---------------------------------------
303         // XFlushable
304 
305         virtual void SAL_CALL flush()
306             throw (css::uno::RuntimeException);
307 
308         virtual void SAL_CALL addFlushListener(const css::uno::Reference< css::util::XFlushListener >& xListener)
309             throw (css::uno::RuntimeException);
310 
311         virtual void SAL_CALL removeFlushListener(const css::uno::Reference< css::util::XFlushListener >& xListener)
312             throw (css::uno::RuntimeException);
313 };
314 
315     } // namespace config
316 } // namespace filter
317 
318 #endif // __FILTER_CONFIG_BASECONTAINER_HXX_
319 
320 /* vim: set noet sw=4 ts=4: */
321