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 .
22 #include <com/sun/star/lang/XServiceInfo.hpp>
23 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
24 #include <com/sun/star/container/XNamed.hpp>
25 #include <com/sun/star/container/XNameAccess.hpp>
26 #include <com/sun/star/ucb/XPropertySetRegistryFactory.hpp>
27 #include <com/sun/star/ucb/XPropertySetRegistry.hpp>
28 #include <com/sun/star/ucb/XPersistentPropertySet.hpp>
29 #include <com/sun/star/uno/XComponentContext.hpp>
30 #include <com/sun/star/beans/XPropertyContainer.hpp>
31 #include <com/sun/star/beans/XPropertySetInfoChangeNotifier.hpp>
32 #include <com/sun/star/beans/XPropertyAccess.hpp>
33 #include <com/sun/star/lang/XComponent.hpp>
34 #include <com/sun/star/lang/XInitialization.hpp>
35 #include <comphelper/interfacecontainer4.hxx>
36 #include <comphelper/multiinterfacecontainer4.hxx>
37 #include <comphelper/compbase.hxx>
38 #include <rtl/ref.hxx>
39 #include <unordered_map>
42 using UcbStore_Base
= comphelper::WeakComponentImplHelper
<
43 css::lang::XServiceInfo
,
44 css::ucb::XPropertySetRegistryFactory
,
45 css::lang::XInitialization
>;
47 class UcbStore
: public UcbStore_Base
49 css::uno::Reference
< css::uno::XComponentContext
> m_xContext
;
50 css::uno::Sequence
< css::uno::Any
> m_aInitArgs
;
51 css::uno::Reference
< css::ucb::XPropertySetRegistry
> m_xTheRegistry
;
54 explicit UcbStore( const css::uno::Reference
< css::uno::XComponentContext
>& xContext
);
55 virtual ~UcbStore() override
;
58 virtual OUString SAL_CALL
getImplementationName() override
;
59 virtual sal_Bool SAL_CALL
supportsService( const OUString
& ServiceName
) override
;
60 virtual css::uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames() override
;
62 // XPropertySetRegistryFactory
63 virtual css::uno::Reference
< css::ucb::XPropertySetRegistry
> SAL_CALL
64 createPropertySetRegistry( const OUString
& URL
) override
;
68 initialize( const css::uno::Sequence
< css::uno::Any
>& aArguments
) override
;
72 class PersistentPropertySet
;
74 // PropertySetMap_Impl.
75 typedef std::unordered_map
< OUString
, PersistentPropertySet
*> PropertySetMap_Impl
;
77 class PropertySetRegistry
: public cppu::WeakImplHelper
<
78 css::lang::XServiceInfo
,
79 css::ucb::XPropertySetRegistry
,
80 css::container::XNameAccess
>
82 friend class PersistentPropertySet
;
84 css::uno::Reference
< css::uno::XComponentContext
> m_xContext
;
85 const css::uno::Sequence
< css::uno::Any
> m_aInitArgs
;
86 PropertySetMap_Impl m_aPropSets
;
87 css::uno::Reference
< css::lang::XMultiServiceFactory
> m_xConfigProvider
;
88 css::uno::Reference
< css::uno::XInterface
> m_xRootReadAccess
;
89 css::uno::Reference
< css::uno::XInterface
> m_xRootWriteAccess
;
91 bool m_bTriedToGetRootReadAccess
;
92 bool m_bTriedToGetRootWriteAccess
;
95 css::uno::Reference
< css::lang::XMultiServiceFactory
>
96 getConfigProvider(std::unique_lock
<std::mutex
>& l
);
98 void add ( std::unique_lock
<std::mutex
>& rCreatorGuard
, PersistentPropertySet
* pSet
);
99 void remove( PersistentPropertySet
* pSet
);
101 void renamePropertySet( const OUString
& rOldKey
,
102 const OUString
& rNewKey
);
106 const css::uno::Reference
< css::uno::XComponentContext
>& xContext
,
107 const css::uno::Sequence
< css::uno::Any
>& rInitArgs
);
108 virtual ~PropertySetRegistry() override
;
112 virtual OUString SAL_CALL
getImplementationName() override
;
113 virtual sal_Bool SAL_CALL
supportsService( const OUString
& ServiceName
) override
;
114 virtual css::uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames() override
;
116 // XPropertySetRegistry
117 virtual css::uno::Reference
< css::ucb::XPersistentPropertySet
> SAL_CALL
118 openPropertySet( const OUString
& key
, sal_Bool create
) override
;
119 virtual void SAL_CALL
120 removePropertySet( const OUString
& key
) override
;
122 // XElementAccess ( XNameAccess is derived from it )
123 virtual css::uno::Type SAL_CALL
124 getElementType() override
;
125 virtual sal_Bool SAL_CALL
126 hasElements() override
;
129 virtual css::uno::Any SAL_CALL
130 getByName( const OUString
& aName
) override
;
131 virtual css::uno::Sequence
< OUString
> SAL_CALL
132 getElementNames() override
;
133 virtual sal_Bool SAL_CALL
134 hasByName( const OUString
& aName
) override
;
136 // Non-interface methods
137 css::uno::Reference
< css::uno::XInterface
>
138 getRootConfigReadAccess();
139 css::uno::Reference
< css::uno::XInterface
>
140 getConfigWriteAccess( const OUString
& rPath
);
142 css::uno::Reference
< css::uno::XInterface
>
143 getRootConfigReadAccessImpl(std::unique_lock
<std::mutex
>& l
);
144 css::uno::Reference
< css::uno::XInterface
>
145 getConfigWriteAccessImpl( std::unique_lock
<std::mutex
>& l
, const OUString
& rPath
);
149 class PropertySetInfo_Impl
;
150 typedef comphelper::OMultiTypeInterfaceContainerHelperVar4
<OUString
, css::beans::XPropertyChangeListener
> PropertyListeners_Impl
;
152 class PersistentPropertySet
: public cppu::WeakImplHelper
<
153 css::lang::XServiceInfo
,
154 css::lang::XComponent
,
155 css::ucb::XPersistentPropertySet
,
156 css::container::XNamed
,
157 css::beans::XPropertyContainer
,
158 css::beans::XPropertySetInfoChangeNotifier
,
159 css::beans::XPropertyAccess
>
161 rtl::Reference
<PropertySetRegistry
> m_pCreator
;
162 rtl::Reference
<PropertySetInfo_Impl
> m_pInfo
;
165 mutable std::mutex m_aMutex
;
166 comphelper::OInterfaceContainerHelper4
<css::lang::XEventListener
> m_aDisposeEventListeners
;
167 comphelper::OInterfaceContainerHelper4
<css::beans::XPropertySetInfoChangeListener
> m_aPropSetChangeListeners
;
168 PropertyListeners_Impl m_aPropertyChangeListeners
;
171 void notifyPropertyChangeEvent(
172 std::unique_lock
<std::mutex
>& rGuard
,
173 const css::beans::PropertyChangeEvent
& rEvent
) const;
174 void notifyPropertySetInfoChange(
175 std::unique_lock
<std::mutex
>& rGuard
,
176 const css::beans::PropertySetInfoChangeEvent
& evt
) const;
179 PersistentPropertySet(
180 std::unique_lock
<std::mutex
>& rCreatorGuard
,
181 PropertySetRegistry
& rCreator
,
183 virtual ~PersistentPropertySet() override
;
186 virtual OUString SAL_CALL
getImplementationName() override
;
187 virtual sal_Bool SAL_CALL
supportsService( const OUString
& ServiceName
) override
;
188 virtual css::uno::Sequence
< OUString
> SAL_CALL
getSupportedServiceNames() override
;
191 virtual void SAL_CALL
193 virtual void SAL_CALL
194 addEventListener( const css::uno::Reference
< css::lang::XEventListener
>& Listener
) override
;
195 virtual void SAL_CALL
196 removeEventListener( const css::uno::Reference
< css::lang::XEventListener
>& Listener
) override
;
199 virtual css::uno::Reference
< css::beans::XPropertySetInfo
> SAL_CALL
200 getPropertySetInfo() override
;
201 virtual void SAL_CALL
202 setPropertyValue( const OUString
& aPropertyName
,
203 const css::uno::Any
& aValue
) override
;
204 virtual css::uno::Any SAL_CALL
205 getPropertyValue( const OUString
& PropertyName
) override
;
206 virtual void SAL_CALL
207 addPropertyChangeListener( const OUString
& aPropertyName
,
208 const css::uno::Reference
< css::beans::XPropertyChangeListener
>& xListener
) override
;
209 virtual void SAL_CALL
210 removePropertyChangeListener( const OUString
& aPropertyName
,
211 const css::uno::Reference
< css::beans::XPropertyChangeListener
>& aListener
) override
;
212 virtual void SAL_CALL
213 addVetoableChangeListener( const OUString
& PropertyName
,
214 const css::uno::Reference
< css::beans::XVetoableChangeListener
>& aListener
) override
;
215 virtual void SAL_CALL
216 removeVetoableChangeListener( const OUString
& PropertyName
,
217 const css::uno::Reference
< css::beans::XVetoableChangeListener
>& aListener
) override
;
219 // XPersistentPropertySet
220 virtual css::uno::Reference
< css::ucb::XPropertySetRegistry
> SAL_CALL
221 getRegistry() override
;
222 virtual OUString SAL_CALL
226 virtual OUString SAL_CALL
228 virtual void SAL_CALL
229 setName( const OUString
& aName
) override
;
231 // XPropertyContainer
232 virtual void SAL_CALL
233 addProperty( const OUString
& Name
,
234 sal_Int16 Attributes
,
235 const css::uno::Any
& DefaultValue
) override
;
236 virtual void SAL_CALL
237 removeProperty( const OUString
& Name
) override
;
239 // XPropertySetInfoChangeNotifier
240 virtual void SAL_CALL
241 addPropertySetInfoChangeListener( const css::uno::Reference
< css::beans::XPropertySetInfoChangeListener
>& Listener
) override
;
242 virtual void SAL_CALL
243 removePropertySetInfoChangeListener( const css::uno::Reference
< css::beans::XPropertySetInfoChangeListener
>& Listener
) override
;
246 virtual css::uno::Sequence
< css::beans::PropertyValue
> SAL_CALL
247 getPropertyValues() override
;
248 virtual void SAL_CALL
249 setPropertyValues( const css::uno::Sequence
< css::beans::PropertyValue
>& aProps
) override
;
251 // Non-interface methods.
252 PropertySetRegistry
& getPropertySetRegistry();
253 OUString
getFullKey();
255 const OUString
& getFullKeyImpl(std::unique_lock
<std::mutex
>&);
258 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */