bump product version to 4.1.6.2
[LibreOffice.git] / filter / source / config / cache / basecontainer.hxx
blobf52a63da4f68e2a3e7900b507c35dea5de79cb85
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
19 #ifndef __FILTER_CONFIG_BASECONTAINER_HXX_
20 #define __FILTER_CONFIG_BASECONTAINER_HXX_
22 #include "filtercache.hxx"
23 #include <com/sun/star/uno/Exception.hpp>
24 #include <com/sun/star/lang/XServiceInfo.hpp>
25 #include <com/sun/star/util/XRefreshable.hpp>
26 #include <com/sun/star/uno/XComponentContext.hpp>
27 #include <com/sun/star/container/XNameContainer.hpp>
28 #include <com/sun/star/container/XContainerQuery.hpp>
29 #include <com/sun/star/util/XFlushable.hpp>
30 #include <cppuhelper/interfacecontainer.h>
31 #include <salhelper/singletonref.hxx>
32 #include <cppuhelper/implbase4.hxx>
33 #include <cppuhelper/weakref.hxx>
34 #include <rtl/ustring.hxx>
37 namespace filter{
38 namespace config{
41 //_______________________________________________
43 /** @short implements the interface css::container::XNameContainer
44 on top of a FilterCache reference.
46 @descr This class can be used as base for own service implementations,
47 which must provide read/write access to the filter configuration.
48 Parameters regulate read/write access, which sub set of information
49 should be available etc.
51 @attention The base class BaseLock must be the first of declared ones.
52 Otherwise we cant be shure, that our own mutex member (which is
53 present by this base class!) was full initialized inside our own
54 ctor as first!
56 class BaseContainer : public BaseLock
57 , public ::cppu::WeakImplHelper4< css::lang::XServiceInfo ,
58 css::container::XNameContainer , // => XNameReplace => XNameAccess => XElementAccess
59 css::container::XContainerQuery ,
60 css::util::XFlushable >
62 //-------------------------------------------
63 // member
65 protected:
67 // TODO
68 css::uno::WeakReference< css::util::XRefreshable > m_xRefreshBroadcaster;
70 /** @short the implementation name of our derived class, which we provide
71 at the interface XServiceInfo of our class ... */
72 OUString m_sImplementationName;
74 /** @short the list of supported uno service names of our derived class, which we provide
75 at the interface XServiceInfo of our class ... */
76 css::uno::Sequence< OUString > m_lServiceNames;
78 /** @short reference(!) to a singleton filter cache implementation,
79 which is used to work with the underlying configuration. */
80 ::salhelper::SingletonRef< FilterCache > m_rCache;
82 /** @short local filter cache, which is used to collect changes on the
83 filter configuration first and flush it later.
85 @descr Normaly this member isnt used nor initialized. Thats true,
86 if this container is used for reading only. The first write access
87 (e.g. by calling insertByName()) creates a copy of the current
88 global cache m_rCache to initialize the m_pFlushCache member.
90 Afterwards only the flush cache copy is used. Inside flush() this
91 copy will be removed and m_rCache can be used again.
93 m_pFlushCache and m_rCache must not be synchronized manually here.
94 m_rCache listen on the global configuration, where m_pFlushCache
95 write its data. m_rCache update itself automaticly.
97 FilterCache* m_pFlushCache;
99 /** @short specify, which sub container of the used filter cache
100 must be wrapped by this container interface. */
101 FilterCache::EItemType m_eType;
103 /** @short holds all listener, which are registered at this instance. */
104 ::cppu::OMultiTypeInterfaceContainerHelper m_lListener;
106 //-------------------------------------------
107 // native interface
109 public:
111 //---------------------------------------
112 // ctor/dtor
114 /** @short standard ctor.
116 @descr Because mostly this class is used as base class for own service
117 implementations in combination with a ImplInheritanceHelper2 template ...
118 there is no way to provide some initializing data through the ctor :-(
119 This base class will be created inside its default ctor and must be
120 initialized with its needed parameters explicitly by calling: "init()".
122 @see init()
124 BaseContainer();
126 //---------------------------------------
128 /** @short standard dtor.
130 virtual ~BaseContainer();
132 //---------------------------------------
134 /** @short initialize this generic intsnace with some specialized values
135 from our derived object.
137 @descr Because an outside class must use ImplInheritanceHelper2 template to
138 use us a base class ... and there is no way to pass such initializing
139 parameters trough a required default ctor ... we must be initialized
140 by this special method. Of course this method must be called first before
141 any other interface method is used.
143 @param rxContext
144 reference to the uno service manager, which created this service instance.
146 @param sImplementationName
147 the implementation name of our derived class, which we provide
148 at the interface XServiceInfo of our class ...
150 @param lServiceNames
151 the list of supported uno service names of our derived class, which we provide
152 at the interface XServiceInfo of our class ...
154 @param eType
155 specify, which sub container of the used filter cache
156 must be wrapped by this container interface.
158 virtual void init(const css::uno::Reference< css::uno::XComponentContext >& rxContext ,
159 const OUString& sImplementationName,
160 const css::uno::Sequence< OUString >& lServiceNames ,
161 FilterCache::EItemType eType );
163 //-------------------------------------------
164 // helper
166 protected:
168 //---------------------------------------
170 /** @short check if the underlying configuration data was already loaded
171 and do it if neccessary automaticly.
173 void impl_loadOnDemand();
175 //---------------------------------------
177 /** @short it creates the global instance m_pFilterCache, which is a copy
178 of the global instance m_rCache, and will be used to change the
179 configuration.
181 @descr If no exception occures, its guaranteed, that the member m_rFlushCache
182 was initialized right and can be used further.
184 void impl_initFlushMode()
185 throw (css::uno::RuntimeException);
187 //---------------------------------------
189 /** @short returns a pointer to the current used cache member.
191 @descr Its a point to the FilterCache instance behind m_pFlushCache
192 or m_rCache.
194 @note The lifetime of this pointer is restricted to the time, where
195 the mutex of this BaseContainer instance is locked.
196 Otherwise may be the interface method flush() will destroy
197 m_pFlushCache and the here returned pointer will be invalid!
199 Use:
201 Guard aLock(m_aLock);
202 FilterCache* p = impl_getWorkingCache();
203 p->doSomething();
204 aLock.clear();
205 // after this point p cant b e guaranteed any longer!
207 FilterCache* impl_getWorkingCache() const;
209 //-------------------------------------------
210 // uno interface
212 public:
214 //---------------------------------------
215 // XServiceInfo
217 virtual OUString SAL_CALL getImplementationName()
218 throw (css::uno::RuntimeException);
220 virtual sal_Bool SAL_CALL supportsService(const OUString& sServiceName)
221 throw (css::uno::RuntimeException);
223 virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames()
224 throw (css::uno::RuntimeException);
226 //---------------------------------------
227 // XNameContainer
229 virtual void SAL_CALL insertByName(const OUString& sItem ,
230 const css::uno::Any& aValue)
231 throw (css::lang::IllegalArgumentException ,
232 css::container::ElementExistException,
233 css::lang::WrappedTargetException ,
234 css::uno::RuntimeException );
236 virtual void SAL_CALL removeByName(const OUString& sItem)
237 throw (css::container::NoSuchElementException,
238 css::lang::WrappedTargetException ,
239 css::uno::RuntimeException );
241 //---------------------------------------
242 // XNameReplace
244 virtual void SAL_CALL replaceByName(const OUString& sItem ,
245 const css::uno::Any& aValue)
246 throw (css::lang::IllegalArgumentException ,
247 css::container::NoSuchElementException,
248 css::lang::WrappedTargetException ,
249 css::uno::RuntimeException );
251 //---------------------------------------
252 // XElementAccess
254 virtual css::uno::Any SAL_CALL getByName(const OUString& sItem)
255 throw (css::container::NoSuchElementException,
256 css::lang::WrappedTargetException ,
257 css::uno::RuntimeException );
259 virtual css::uno::Sequence< OUString > SAL_CALL getElementNames()
260 throw (css::uno::RuntimeException);
262 virtual sal_Bool SAL_CALL hasByName(const OUString& sItem)
263 throw (css::uno::RuntimeException);
265 virtual css::uno::Type SAL_CALL getElementType()
266 throw (css::uno::RuntimeException);
268 virtual sal_Bool SAL_CALL hasElements()
269 throw (css::uno::RuntimeException);
271 //---------------------------------------
272 // XContainerQuery
274 // must be implemented realy by derived class ...
275 // We implement return of an empty result here only!
276 // But we show an assertion :-)
277 virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createSubSetEnumerationByQuery(const OUString& sQuery)
278 throw (css::uno::RuntimeException);
280 virtual css::uno::Reference< css::container::XEnumeration > SAL_CALL createSubSetEnumerationByProperties(const css::uno::Sequence< css::beans::NamedValue >& lProperties)
281 throw (css::uno::RuntimeException);
283 //---------------------------------------
284 // XFlushable
286 virtual void SAL_CALL flush()
287 throw (css::uno::RuntimeException);
289 virtual void SAL_CALL addFlushListener(const css::uno::Reference< css::util::XFlushListener >& xListener)
290 throw (css::uno::RuntimeException);
292 virtual void SAL_CALL removeFlushListener(const css::uno::Reference< css::util::XFlushListener >& xListener)
293 throw (css::uno::RuntimeException);
296 } // namespace config
297 } // namespace filter
299 #endif // __FILTER_CONFIG_BASECONTAINER_HXX_
301 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */