Version 6.4.0.3, tag libreoffice-6.4.0.3
[LibreOffice.git] / configmgr / source / access.hxx
blobd3cf9011a0ca4566b02ac0c573fb0a5bd1792394
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 .
20 #ifndef INCLUDED_CONFIGMGR_SOURCE_ACCESS_HXX
21 #define INCLUDED_CONFIGMGR_SOURCE_ACCESS_HXX
23 #include <sal/config.h>
25 #include <memory>
26 #include <set>
27 #include <vector>
28 #include "config_map.hxx"
30 #include <com/sun/star/beans/XExactName.hpp>
31 #include <com/sun/star/beans/XHierarchicalPropertySet.hpp>
32 #include <com/sun/star/beans/XHierarchicalPropertySetInfo.hpp>
33 #include <com/sun/star/beans/XMultiHierarchicalPropertySet.hpp>
34 #include <com/sun/star/beans/XMultiPropertySet.hpp>
35 #include <com/sun/star/beans/XProperty.hpp>
36 #include <com/sun/star/beans/XPropertySet.hpp>
37 #include <com/sun/star/beans/XPropertySetInfo.hpp>
38 #include <com/sun/star/container/XContainer.hpp>
39 #include <com/sun/star/container/XHierarchicalName.hpp>
40 #include <com/sun/star/container/XHierarchicalNameReplace.hpp>
41 #include <com/sun/star/container/XNameContainer.hpp>
42 #include <com/sun/star/container/XNamed.hpp>
43 #include <com/sun/star/lang/XComponent.hpp>
44 #include <com/sun/star/lang/XServiceInfo.hpp>
45 #include <com/sun/star/lang/XTypeProvider.hpp>
46 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
47 #include <com/sun/star/uno/Reference.hxx>
48 #include <com/sun/star/uno/Sequence.hxx>
49 #include <cppuhelper/weak.hxx>
50 #include <osl/interlck.h>
51 #include <rtl/ref.hxx>
52 #include <sal/types.h>
54 #include "modifications.hxx"
55 #include "type.hxx"
57 namespace com { namespace sun { namespace star {
58 namespace beans {
59 class XHierarchicalPropertySetInfo;
60 class XPropertiesChangeListener;
61 class XPropertyChangeListener;
62 class XVetoableChangeListener;
63 struct Property;
65 namespace container { class XContainerListener; }
66 namespace lang { class XEventListener; }
67 namespace uno {
68 class Any;
69 class Type;
70 class XInterface;
72 namespace util { struct ElementChange; }
73 } } }
75 namespace configmgr {
77 class Broadcaster;
78 class ChildAccess;
79 class Components;
80 class Node;
81 class RootAccess;
83 class Access:
84 public cppu::OWeakObject, public css::lang::XTypeProvider,
85 public css::lang::XServiceInfo,
86 public css::lang::XComponent,
87 public css::container::XHierarchicalNameReplace,
88 public css::container::XContainer,
89 public css::beans::XExactName,
90 public css::beans::XPropertySetInfo,
91 public css::container::XHierarchicalName,
92 public css::container::XNamed,
93 public css::beans::XProperty,
94 public css::beans::XPropertySet,
95 public css::beans::XMultiPropertySet,
96 public css::beans::XHierarchicalPropertySet,
97 public css::beans::XMultiHierarchicalPropertySet,
98 public css::beans::XHierarchicalPropertySetInfo,
99 public css::container::XNameContainer,
100 public css::lang::XSingleServiceFactory
102 public:
103 oslInterlockedCount acquireCounting();
105 void releaseNondeleting();
107 bool isValue();
109 void markChildAsModified(rtl::Reference< ChildAccess > const & child);
110 void releaseChild(OUString const & name);
112 virtual std::vector<OUString> getAbsolutePath() = 0;
113 virtual std::vector<OUString> getRelativePath() = 0;
115 virtual OUString getRelativePathRepresentation() = 0;
116 virtual rtl::Reference< Node > getNode() = 0;
118 virtual bool isFinalized() = 0;
120 virtual void initBroadcaster(
121 Modifications::Node const & modifications, Broadcaster * broadcaster);
123 using OWeakObject::acquire;
124 using OWeakObject::release;
126 virtual css::uno::Sequence< css::uno::Type > SAL_CALL
127 getTypes() override;
129 virtual css::uno::Sequence< sal_Int8 > SAL_CALL
130 getImplementationId() override;
132 virtual OUString SAL_CALL getImplementationName() override;
134 virtual sal_Bool SAL_CALL supportsService(OUString const & ServiceName) override;
136 virtual css::uno::Sequence< OUString > SAL_CALL
137 getSupportedServiceNames() override;
139 virtual void SAL_CALL dispose() override;
141 virtual void SAL_CALL addEventListener(
142 css::uno::Reference< css::lang::XEventListener >
143 const & xListener) override;
145 virtual void SAL_CALL removeEventListener(
146 css::uno::Reference< css::lang::XEventListener >
147 const & aListener) override;
149 virtual css::uno::Type SAL_CALL getElementType() override;
151 virtual sal_Bool SAL_CALL hasElements() override;
153 virtual css::uno::Any SAL_CALL getByName(
154 OUString const & aName) override;
156 virtual css::uno::Sequence< OUString > SAL_CALL
157 getElementNames() override;
159 virtual sal_Bool SAL_CALL hasByName(OUString const & aName) override;
161 virtual css::uno::Any SAL_CALL getByHierarchicalName(
162 OUString const & aName) override;
164 virtual sal_Bool SAL_CALL hasByHierarchicalName(OUString const & aName) override;
166 virtual void SAL_CALL replaceByHierarchicalName(
167 OUString const & aName, css::uno::Any const & aElement) override;
169 virtual void SAL_CALL addContainerListener(
170 css::uno::Reference<
171 css::container::XContainerListener > const & xListener) override;
173 virtual void SAL_CALL removeContainerListener(
174 css::uno::Reference<
175 css::container::XContainerListener > const & xListener) override;
177 virtual OUString SAL_CALL getExactName(
178 OUString const & aApproximateName) override;
180 virtual css::uno::Sequence< css::beans::Property >
181 SAL_CALL getProperties() override;
183 virtual css::beans::Property SAL_CALL getPropertyByName(
184 OUString const & aName) override;
186 virtual sal_Bool SAL_CALL hasPropertyByName(OUString const & Name) override;
188 virtual OUString SAL_CALL getHierarchicalName() override;
190 virtual OUString SAL_CALL composeHierarchicalName(
191 OUString const & aRelativeName) override;
193 virtual OUString SAL_CALL getName() override;
195 virtual void SAL_CALL setName(OUString const & aName) override;
197 virtual css::beans::Property SAL_CALL getAsProperty() override;
199 virtual
200 css::uno::Reference< css::beans::XPropertySetInfo >
201 SAL_CALL getPropertySetInfo() override;
203 virtual void SAL_CALL setPropertyValue(
204 OUString const & aPropertyName,
205 css::uno::Any const & aValue) override;
207 virtual css::uno::Any SAL_CALL getPropertyValue(
208 OUString const & PropertyName) override;
210 virtual void SAL_CALL addPropertyChangeListener(
211 OUString const & aPropertyName,
212 css::uno::Reference<
213 css::beans::XPropertyChangeListener > const & xListener) override;
215 virtual void SAL_CALL removePropertyChangeListener(
216 OUString const & aPropertyName,
217 css::uno::Reference<
218 css::beans::XPropertyChangeListener > const & aListener) override;
220 virtual void SAL_CALL addVetoableChangeListener(
221 OUString const & PropertyName,
222 css::uno::Reference<
223 css::beans::XVetoableChangeListener > const & aListener) override;
225 virtual void SAL_CALL removeVetoableChangeListener(
226 OUString const & PropertyName,
227 css::uno::Reference<
228 css::beans::XVetoableChangeListener > const & aListener) override;
230 virtual void SAL_CALL setPropertyValues(
231 css::uno::Sequence< OUString > const & aPropertyNames,
232 css::uno::Sequence< css::uno::Any > const &
233 aValues) override;
235 virtual css::uno::Sequence< css::uno::Any > SAL_CALL
236 getPropertyValues(
237 css::uno::Sequence< OUString > const & aPropertyNames) override;
239 virtual void SAL_CALL addPropertiesChangeListener(
240 css::uno::Sequence< OUString > const & aPropertyNames,
241 css::uno::Reference<
242 css::beans::XPropertiesChangeListener > const &
243 xListener) override;
245 virtual void SAL_CALL removePropertiesChangeListener(
246 css::uno::Reference<
247 css::beans::XPropertiesChangeListener > const &
248 xListener) override;
250 virtual void SAL_CALL firePropertiesChangeEvent(
251 css::uno::Sequence< OUString > const & aPropertyNames,
252 css::uno::Reference<
253 css::beans::XPropertiesChangeListener > const &
254 xListener) override;
256 virtual
257 css::uno::Reference<
258 css::beans::XHierarchicalPropertySetInfo > SAL_CALL
259 getHierarchicalPropertySetInfo() override;
261 virtual void SAL_CALL setHierarchicalPropertyValue(
262 OUString const & aHierarchicalPropertyName,
263 css::uno::Any const & aValue) override;
265 virtual css::uno::Any SAL_CALL getHierarchicalPropertyValue(
266 OUString const & aHierarchicalPropertyName) override;
268 virtual void SAL_CALL setHierarchicalPropertyValues(
269 css::uno::Sequence< OUString > const &
270 aHierarchicalPropertyNames,
271 css::uno::Sequence< css::uno::Any > const &
272 Values) override;
274 virtual css::uno::Sequence< css::uno::Any > SAL_CALL
275 getHierarchicalPropertyValues(
276 css::uno::Sequence< OUString > const &
277 aHierarchicalPropertyNames) override;
279 virtual css::beans::Property SAL_CALL
280 getPropertyByHierarchicalName(OUString const & aHierarchicalName) override;
282 virtual sal_Bool SAL_CALL hasPropertyByHierarchicalName(
283 OUString const & aHierarchicalName) override;
285 virtual void SAL_CALL replaceByName(
286 OUString const & aName, css::uno::Any const & aElement) override;
288 virtual void SAL_CALL insertByName(
289 OUString const & aName, css::uno::Any const & aElement) override;
291 virtual void SAL_CALL removeByName(OUString const & aName) override;
293 virtual css::uno::Reference< css::uno::XInterface >
294 SAL_CALL createInstance() override;
296 virtual css::uno::Reference< css::uno::XInterface >
297 SAL_CALL createInstanceWithArguments(
298 css::uno::Sequence< css::uno::Any > const &
299 aArguments) override;
301 protected:
302 explicit Access(Components & components);
304 virtual ~Access() override;
306 virtual OUString getNameInternal() = 0;
307 virtual rtl::Reference< RootAccess > getRootAccess() = 0;
308 virtual rtl::Reference< Access > getParentAccess() = 0;
310 virtual void addTypes(std::vector< css::uno::Type > * types)
311 const = 0;
313 virtual void addSupportedServiceNames(
314 std::vector<OUString> * services) = 0;
316 virtual void initDisposeBroadcaster(Broadcaster * broadcaster);
317 virtual void clearListeners() throw ();
319 virtual css::uno::Any SAL_CALL queryInterface(
320 css::uno::Type const & aType) override;
322 Components & getComponents() const { return components_;}
324 void checkLocalizedPropertyAccess();
326 rtl::Reference< Node > getParentNode();
327 rtl::Reference< ChildAccess > getChild(OUString const & name);
328 std::vector< rtl::Reference< ChildAccess > > getAllChildren();
330 void checkValue(
331 css::uno::Any const & value, Type type, bool nillable);
333 void insertLocalizedValueChild(
334 OUString const & name, css::uno::Any const & value,
335 Modifications * localModifications);
337 void reportChildChanges(
338 std::vector< css::util::ElementChange > * changes);
340 void commitChildChanges(bool valid, Modifications * globalModifications);
342 void initBroadcasterAndChanges(
343 Modifications::Node const & modifications, Broadcaster * broadcaster,
344 std::vector< css::util::ElementChange > * changes);
346 bool isDisposed() const { return disposed_;}
348 private:
349 Access(const Access&) = delete;
350 Access& operator=(const Access&) = delete;
352 struct ModifiedChild {
353 rtl::Reference< ChildAccess > child;
354 bool directlyModified;
356 ModifiedChild();
358 ModifiedChild(
359 rtl::Reference< ChildAccess > const & theChild,
360 bool theDirectlyModified);
363 typedef config_map< ModifiedChild > ModifiedChildren;
365 rtl::Reference< ChildAccess > getModifiedChild(
366 ModifiedChildren::iterator const & childIterator);
368 rtl::Reference< ChildAccess > getUnmodifiedChild(
369 OUString const & name);
371 rtl::Reference< ChildAccess > getSubChild(OUString const & path);
373 bool setChildProperty(
374 OUString const & name, css::uno::Any const & value,
375 Modifications * localModifications);
377 css::beans::Property asProperty();
379 bool getByNameFast(const OUString & name, css::uno::Any & value);
380 rtl::Reference< ChildAccess > createUnmodifiedChild(const OUString &name,
381 const rtl::Reference< Node > &node);
383 void checkFinalized();
385 void checkKnownProperty(OUString const & descriptor);
387 rtl::Reference< ChildAccess > getFreeSetMember( css::uno::Any const & value);
389 rtl::Reference< Access > getNotificationRoot();
391 typedef config_map< ChildAccess * > WeakChildMap;
393 typedef
394 std::multiset<
395 css::uno::Reference<
396 css::lang::XEventListener > >
397 DisposeListeners;
399 typedef
400 std::multiset<
401 css::uno::Reference<
402 css::container::XContainerListener > >
403 ContainerListeners;
405 typedef
406 std::multiset<
407 css::uno::Reference<
408 css::beans::XPropertyChangeListener > >
409 PropertyChangeListenersElement;
411 typedef config_map< PropertyChangeListenersElement >
412 PropertyChangeListeners;
414 typedef
415 std::multiset<
416 css::uno::Reference<
417 css::beans::XVetoableChangeListener > >
418 VetoableChangeListenersElement;
420 typedef config_map< VetoableChangeListenersElement >
421 VetoableChangeListeners;
423 typedef
424 std::multiset<
425 css::uno::Reference<
426 css::beans::XPropertiesChangeListener > >
427 PropertiesChangeListeners;
429 Components & components_;
430 ModifiedChildren modifiedChildren_;
431 WeakChildMap cachedChildren_;
432 DisposeListeners disposeListeners_;
433 ContainerListeners containerListeners_;
434 PropertyChangeListeners propertyChangeListeners_;
435 VetoableChangeListeners vetoableChangeListeners_;
436 PropertiesChangeListeners propertiesChangeListeners_;
437 bool disposed_;
439 std::shared_ptr<osl::Mutex> lock_;
441 #if !defined NDEBUG
442 protected:
443 enum {
444 IS_ANY = 0, IS_GROUP = 0x01, IS_SET = 0x02, IS_EXTENSIBLE = 0x04,
445 IS_GROUP_MEMBER = 0x08, IS_SET_MEMBER = 0x10, IS_UPDATE = 0x20 };
446 bool thisIs(int what);
447 #endif
452 #endif
454 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */