1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 
20 #pragma once
21 
22 #include <com/sun/star/lang/XServiceInfo.hpp>
23 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
24 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
25 #include <com/sun/star/container/XNamed.hpp>
26 #include <com/sun/star/container/XNameAccess.hpp>
27 #include <com/sun/star/ucb/XPropertySetRegistryFactory.hpp>
28 #include <com/sun/star/ucb/XPropertySetRegistry.hpp>
29 #include <com/sun/star/ucb/XPersistentPropertySet.hpp>
30 #include <com/sun/star/uno/XComponentContext.hpp>
31 #include <com/sun/star/beans/XPropertyContainer.hpp>
32 #include <com/sun/star/beans/XPropertySetInfoChangeNotifier.hpp>
33 #include <com/sun/star/beans/XPropertyAccess.hpp>
34 #include <com/sun/star/lang/XComponent.hpp>
35 #include <com/sun/star/lang/XInitialization.hpp>
36 #include <cppuhelper/compbase.hxx>
37 #include <cppuhelper/basemutex.hxx>
38 #include <memory>
39 
40 
41 struct UcbStore_Impl;
42 
43 using UcbStore_Base = cppu::WeakComponentImplHelper <
44                         css::lang::XServiceInfo,
45                         css::ucb::XPropertySetRegistryFactory,
46                         css::lang::XInitialization >;
47 
48 class UcbStore : public cppu::BaseMutex, public UcbStore_Base
49 {
50     css::uno::Reference< css::uno::XComponentContext > m_xContext;
51     std::unique_ptr<UcbStore_Impl> m_pImpl;
52 
53 public:
54     explicit UcbStore( const css::uno::Reference< css::uno::XComponentContext >& xContext );
55     virtual ~UcbStore() override;
56 
57     // XServiceInfo
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;
61 
62     // XPropertySetRegistryFactory
63     virtual css::uno::Reference< css::ucb::XPropertySetRegistry > SAL_CALL
64     createPropertySetRegistry( const OUString& URL ) override;
65 
66     // XInitialization
67     virtual void SAL_CALL
68     initialize( const css::uno::Sequence< css::uno::Any >& aArguments ) override;
69 };
70 
71 
72 struct PropertySetRegistry_Impl;
73 class PersistentPropertySet;
74 
75 class PropertySetRegistry : public cppu::WeakImplHelper <
76     css::lang::XServiceInfo,
77     css::ucb::XPropertySetRegistry,
78     css::container::XNameAccess >
79 {
80     friend class PersistentPropertySet;
81 
82     css::uno::Reference< css::uno::XComponentContext > m_xContext;
83     std::unique_ptr<PropertySetRegistry_Impl> m_pImpl;
84 
85 private:
86     css::uno::Reference< css::lang::XMultiServiceFactory >
87     getConfigProvider();
88 
89     void add   ( PersistentPropertySet* pSet );
90     void remove( PersistentPropertySet* pSet );
91 
92     void renamePropertySet( const OUString& rOldKey,
93                             const OUString& rNewKey );
94 
95 public:
96     PropertySetRegistry(
97         const css::uno::Reference< css::uno::XComponentContext >& xContext,
98         const css::uno::Sequence< css::uno::Any >& rInitArgs);
99     virtual ~PropertySetRegistry() override;
100 
101 
102     // XServiceInfo
103     virtual OUString SAL_CALL getImplementationName() override;
104     virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
105     virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
106 
107     // XPropertySetRegistry
108     virtual css::uno::Reference< css::ucb::XPersistentPropertySet > SAL_CALL
109     openPropertySet( const OUString& key, sal_Bool create ) override;
110     virtual void SAL_CALL
111     removePropertySet( const OUString& key ) override;
112 
113     // XElementAccess ( XNameAccess is derived from it )
114     virtual css::uno::Type SAL_CALL
115     getElementType() override;
116     virtual sal_Bool SAL_CALL
117     hasElements() override;
118 
119     // XNameAccess
120     virtual css::uno::Any SAL_CALL
121     getByName( const OUString& aName ) override;
122     virtual css::uno::Sequence< OUString > SAL_CALL
123     getElementNames() override;
124     virtual sal_Bool SAL_CALL
125     hasByName( const OUString& aName ) override;
126 
127     // Non-interface methods
128     css::uno::Reference< css::uno::XInterface >
129     getRootConfigReadAccess();
130     css::uno::Reference< css::uno::XInterface >
131     getConfigWriteAccess( const OUString& rPath );
132 };
133 
134 
135 struct PersistentPropertySet_Impl;
136 
137 class PersistentPropertySet : public cppu::WeakImplHelper <
138     css::lang::XServiceInfo,
139     css::lang::XComponent,
140     css::ucb::XPersistentPropertySet,
141     css::container::XNamed,
142     css::beans::XPropertyContainer,
143     css::beans::XPropertySetInfoChangeNotifier,
144     css::beans::XPropertyAccess >
145 {
146     std::unique_ptr<PersistentPropertySet_Impl> m_pImpl;
147 
148 private:
149     void notifyPropertyChangeEvent(
150         const css::beans::PropertyChangeEvent& rEvent ) const;
151     void notifyPropertySetInfoChange(
152         const css::beans::PropertySetInfoChangeEvent& evt ) const;
153 
154 public:
155     PersistentPropertySet(
156         PropertySetRegistry& rCreator,
157         const OUString& rKey );
158     virtual ~PersistentPropertySet() override;
159 
160     // XServiceInfo
161     virtual OUString SAL_CALL getImplementationName() override;
162     virtual sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override;
163     virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override;
164 
165     // XComponent
166     virtual void SAL_CALL
167     dispose() override;
168     virtual void SAL_CALL
169     addEventListener( const css::uno::Reference< css::lang::XEventListener >& Listener ) override;
170     virtual void SAL_CALL
171     removeEventListener( const css::uno::Reference< css::lang::XEventListener >& Listener ) override;
172 
173     // XPropertySet
174     virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL
175     getPropertySetInfo() override;
176     virtual void SAL_CALL
177     setPropertyValue( const OUString& aPropertyName,
178                       const css::uno::Any& aValue ) override;
179     virtual css::uno::Any SAL_CALL
180     getPropertyValue( const OUString& PropertyName ) override;
181     virtual void SAL_CALL
182     addPropertyChangeListener( const OUString& aPropertyName,
183                                const css::uno::Reference< css::beans::XPropertyChangeListener >& xListener ) override;
184     virtual void SAL_CALL
185     removePropertyChangeListener( const OUString& aPropertyName,
186                                   const css::uno::Reference< css::beans::XPropertyChangeListener >& aListener ) override;
187     virtual void SAL_CALL
188     addVetoableChangeListener( const OUString& PropertyName,
189                                const css::uno::Reference< css::beans::XVetoableChangeListener >& aListener ) override;
190     virtual void SAL_CALL
191     removeVetoableChangeListener( const OUString& PropertyName,
192                                   const css::uno::Reference< css::beans::XVetoableChangeListener >& aListener ) override;
193 
194     // XPersistentPropertySet
195     virtual css::uno::Reference< css::ucb::XPropertySetRegistry > SAL_CALL
196     getRegistry() override;
197     virtual OUString SAL_CALL
198     getKey() override;
199 
200     // XNamed
201     virtual OUString SAL_CALL
202     getName() override;
203     virtual void SAL_CALL
204     setName( const OUString& aName ) override;
205 
206     // XPropertyContainer
207     virtual void SAL_CALL
208     addProperty( const OUString& Name,
209                  sal_Int16 Attributes,
210                  const css::uno::Any& DefaultValue ) override;
211     virtual void SAL_CALL
212     removeProperty( const OUString& Name ) override;
213 
214     // XPropertySetInfoChangeNotifier
215     virtual void SAL_CALL
216     addPropertySetInfoChangeListener( const css::uno::Reference< css::beans::XPropertySetInfoChangeListener >& Listener ) override;
217     virtual void SAL_CALL
218     removePropertySetInfoChangeListener( const css::uno::Reference< css::beans::XPropertySetInfoChangeListener >& Listener ) override;
219 
220     // XPropertyAccess
221     virtual css::uno::Sequence< css::beans::PropertyValue > SAL_CALL
222     getPropertyValues() override;
223     virtual void SAL_CALL
224     setPropertyValues( const css::uno::Sequence< css::beans::PropertyValue >& aProps ) override;
225 
226     // Non-interface methods.
227     PropertySetRegistry& getPropertySetRegistry();
228     const OUString& getFullKey();
229 };
230 
231 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
232