1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
23 #include "filtercache.hxx"
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 <comphelper/interfacecontainer4.hxx>
31 #include <cppuhelper/implbase.hxx>
32 #include <cppuhelper/weakref.hxx>
33 #include <rtl/ustring.hxx>
36 namespace filter::config
{
39 /** @short implements the interface css::container::XNameContainer
40 on top of a FilterCache reference.
42 @descr This class can be used as base for own service implementations,
43 which must provide read/write access to the filter configuration.
44 Parameters regulate read/write access, which sub set of information
45 should be available etc.
47 @attention The base class BaseLock must be the first of declared ones.
48 Otherwise we can't be sure, that our own mutex member (which is
49 present by this base class!) was full initialized inside our own
52 class BaseContainer
: public ::cppu::WeakImplHelper
< css::lang::XServiceInfo
,
53 css::container::XNameContainer
, // => XNameReplace => XNameAccess => XElementAccess
54 css::container::XContainerQuery
,
55 css::util::XFlushable
>
61 mutable std::mutex m_aMutex
;
63 /** @short the implementation name of our derived class, which we provide
64 at the interface XServiceInfo of our class... */
65 OUString m_sImplementationName
;
67 /** @short the list of supported uno service names of our derived class, which we provide
68 at the interface XServiceInfo of our class... */
69 css::uno::Sequence
< OUString
> m_lServiceNames
;
71 /** @short local filter cache, which is used to collect changes on the
72 filter configuration first and flush it later.
74 @descr Normally this member isn't used nor initialized. That's true,
75 if this container is used for reading only. The first write access
76 (e.g. by calling insertByName()) creates a copy of the current
77 global cache m_rCache to initialize the m_pFlushCache member.
79 Afterwards only the flush cache copy is used. Inside flush() this
80 copy will be removed and m_rCache can be used again.
82 m_pFlushCache and m_rCache must not be synchronized manually here.
83 m_rCache listen on the global configuration, where m_pFlushCache
84 write its data. m_rCache update itself automatically.
86 std::unique_ptr
<FilterCache
> m_pFlushCache
;
88 /** @short specify, which sub container of the used filter cache
89 must be wrapped by this container interface. */
90 FilterCache::EItemType m_eType
;
92 /** @short holds all listener, which are registered at this instance. */
93 comphelper::OInterfaceContainerHelper4
<css::util::XFlushListener
> m_lListener
;
103 /** @short standard ctor.
105 @descr Because mostly this class is used as base class for own service
106 implementations in combination with an ImplInheritanceHelper template...
107 there is no way to provide some initializing data through the ctor :-(
108 This base class will be created inside its default ctor and must be
109 initialized with its needed parameters explicitly by calling: "init()".
116 /** @short standard dtor.
118 virtual ~BaseContainer() override
;
121 /** @short initialize this generic instance with some specialized values
122 from our derived object.
124 @descr Because an outside class must use ImplInheritanceHelper template to
125 use us a base class... and there is no way to pass such initializing
126 parameters through a required default ctor... we must be initialized
127 by this special method. Of course this method must be called first before
128 any other interface method is used.
131 reference to the uno service manager, which created this service instance.
133 @param sImplementationName
134 the implementation name of our derived class, which we provide
135 at the interface XServiceInfo of our class...
138 the list of supported uno service names of our derived class, which we provide
139 at the interface XServiceInfo of our class...
142 specify, which sub container of the used filter cache
143 must be wrapped by this container interface.
145 void init( const OUString
& sImplementationName
,
146 const css::uno::Sequence
< OUString
>& lServiceNames
,
147 FilterCache::EItemType eType
);
155 /** @short check if the underlying configuration data was already loaded
156 and do it if necessary automatically.
158 void impl_loadOnDemand(std::unique_lock
<std::mutex
>& rGuard
);
161 /** @short it creates the global instance m_pFilterCache, which is a copy
162 of the global instance m_rCache, and will be used to change the
165 @descr If no exception occurs, its guaranteed, that the member m_rFlushCache
166 was initialized right and can be used further.
168 @throws css::uno::RuntimeException
170 void impl_initFlushMode(std::unique_lock
<std::mutex
>& rGuard
);
173 /** @short returns a pointer to the current used cache member.
175 @descr It's a point to the FilterCache instance behind m_pFlushCache
178 @note The lifetime of this pointer is restricted to the time, where
179 the mutex of this BaseContainer instance is locked.
180 Otherwise may be the interface method flush() will destroy
181 m_pFlushCache and the here returned pointer will be invalid!
185 Guard aLock(m_aLock);
186 FilterCache* p = impl_getWorkingCache();
189 // after this point p can't b e guaranteed any longer!
191 FilterCache
* impl_getWorkingCache(std::unique_lock
<std::mutex
>& rGuard
) const;
201 virtual OUString SAL_CALL
getImplementationName() override
;
203 virtual sal_Bool SAL_CALL
supportsService(const OUString
& sServiceName
) override
;
205 virtual css::uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames() override
;
210 virtual void SAL_CALL
insertByName(const OUString
& sItem
,
211 const css::uno::Any
& aValue
) override
;
213 virtual void SAL_CALL
removeByName(const OUString
& sItem
) override
;
218 virtual void SAL_CALL
replaceByName(const OUString
& sItem
,
219 const css::uno::Any
& aValue
) override
;
224 virtual css::uno::Any SAL_CALL
getByName(const OUString
& sItem
) override
;
226 virtual css::uno::Sequence
< OUString
> SAL_CALL
getElementNames() override
;
228 virtual sal_Bool SAL_CALL
hasByName(const OUString
& sItem
) override
;
230 virtual css::uno::Type SAL_CALL
getElementType() override
;
232 virtual sal_Bool SAL_CALL
hasElements() override
;
237 // must be implemented really by derived class...
238 // We implement return of an empty result here only!
239 // But we show an assertion :-)
240 virtual css::uno::Reference
< css::container::XEnumeration
> SAL_CALL
createSubSetEnumerationByQuery(const OUString
& sQuery
) override
;
242 virtual css::uno::Reference
< css::container::XEnumeration
> SAL_CALL
createSubSetEnumerationByProperties(const css::uno::Sequence
< css::beans::NamedValue
>& lProperties
) override
;
247 virtual void SAL_CALL
flush() override
;
249 virtual void SAL_CALL
addFlushListener(const css::uno::Reference
< css::util::XFlushListener
>& xListener
) override
;
251 virtual void SAL_CALL
removeFlushListener(const css::uno::Reference
< css::util::XFlushListener
>& xListener
) override
;
254 } // namespace filter::config
256 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */