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 #ifndef INCLUDED_CONFIGMGR_SOURCE_ACCESS_HXX 21 #define INCLUDED_CONFIGMGR_SOURCE_ACCESS_HXX 22 23 #include <sal/config.h> 24 25 #include <memory> 26 #include <set> 27 #include <vector> 28 #include "config_map.hxx" 29 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> 53 54 #include "modifications.hxx" 55 #include "type.hxx" 56 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; 64 } 65 namespace container { class XContainerListener; } 66 namespace lang { class XEventListener; } 67 namespace uno { 68 class Any; 69 class Type; 70 class XInterface; 71 } 72 namespace util { struct ElementChange; } 73 } } } 74 75 namespace configmgr { 76 77 class Broadcaster; 78 class ChildAccess; 79 class Components; 80 class Node; 81 class RootAccess; 82 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 101 { 102 public: 103 oslInterlockedCount acquireCounting(); 104 105 void releaseNondeleting(); 106 107 bool isValue(); 108 109 void markChildAsModified(rtl::Reference< ChildAccess > const & child); 110 void releaseChild(OUString const & name); 111 112 virtual std::vector<OUString> getAbsolutePath() = 0; 113 virtual std::vector<OUString> getRelativePath() = 0; 114 115 virtual OUString getRelativePathRepresentation() = 0; 116 virtual rtl::Reference< Node > getNode() = 0; 117 118 virtual bool isFinalized() = 0; 119 120 virtual void initBroadcaster( 121 Modifications::Node const & modifications, Broadcaster * broadcaster); 122 123 using OWeakObject::acquire; 124 using OWeakObject::release; 125 126 virtual css::uno::Sequence< css::uno::Type > SAL_CALL 127 getTypes() override; 128 129 virtual css::uno::Sequence< sal_Int8 > SAL_CALL 130 getImplementationId() override; 131 132 virtual OUString SAL_CALL getImplementationName() override; 133 134 virtual sal_Bool SAL_CALL supportsService(OUString const & ServiceName) override; 135 136 virtual css::uno::Sequence< OUString > SAL_CALL 137 getSupportedServiceNames() override; 138 139 virtual void SAL_CALL dispose() override; 140 141 virtual void SAL_CALL addEventListener( 142 css::uno::Reference< css::lang::XEventListener > 143 const & xListener) override; 144 145 virtual void SAL_CALL removeEventListener( 146 css::uno::Reference< css::lang::XEventListener > 147 const & aListener) override; 148 149 virtual css::uno::Type SAL_CALL getElementType() override; 150 151 virtual sal_Bool SAL_CALL hasElements() override; 152 153 virtual css::uno::Any SAL_CALL getByName( 154 OUString const & aName) override; 155 156 virtual css::uno::Sequence< OUString > SAL_CALL 157 getElementNames() override; 158 159 virtual sal_Bool SAL_CALL hasByName(OUString const & aName) override; 160 161 virtual css::uno::Any SAL_CALL getByHierarchicalName( 162 OUString const & aName) override; 163 164 virtual sal_Bool SAL_CALL hasByHierarchicalName(OUString const & aName) override; 165 166 virtual void SAL_CALL replaceByHierarchicalName( 167 OUString const & aName, css::uno::Any const & aElement) override; 168 169 virtual void SAL_CALL addContainerListener( 170 css::uno::Reference< 171 css::container::XContainerListener > const & xListener) override; 172 173 virtual void SAL_CALL removeContainerListener( 174 css::uno::Reference< 175 css::container::XContainerListener > const & xListener) override; 176 177 virtual OUString SAL_CALL getExactName( 178 OUString const & aApproximateName) override; 179 180 virtual css::uno::Sequence< css::beans::Property > 181 SAL_CALL getProperties() override; 182 183 virtual css::beans::Property SAL_CALL getPropertyByName( 184 OUString const & aName) override; 185 186 virtual sal_Bool SAL_CALL hasPropertyByName(OUString const & Name) override; 187 188 virtual OUString SAL_CALL getHierarchicalName() override; 189 190 virtual OUString SAL_CALL composeHierarchicalName( 191 OUString const & aRelativeName) override; 192 193 virtual OUString SAL_CALL getName() override; 194 195 virtual void SAL_CALL setName(OUString const & aName) override; 196 197 virtual css::beans::Property SAL_CALL getAsProperty() override; 198 199 virtual 200 css::uno::Reference< css::beans::XPropertySetInfo > 201 SAL_CALL getPropertySetInfo() override; 202 203 virtual void SAL_CALL setPropertyValue( 204 OUString const & aPropertyName, 205 css::uno::Any const & aValue) override; 206 207 virtual css::uno::Any SAL_CALL getPropertyValue( 208 OUString const & PropertyName) override; 209 210 virtual void SAL_CALL addPropertyChangeListener( 211 OUString const & aPropertyName, 212 css::uno::Reference< 213 css::beans::XPropertyChangeListener > const & xListener) override; 214 215 virtual void SAL_CALL removePropertyChangeListener( 216 OUString const & aPropertyName, 217 css::uno::Reference< 218 css::beans::XPropertyChangeListener > const & aListener) override; 219 220 virtual void SAL_CALL addVetoableChangeListener( 221 OUString const & PropertyName, 222 css::uno::Reference< 223 css::beans::XVetoableChangeListener > const & aListener) override; 224 225 virtual void SAL_CALL removeVetoableChangeListener( 226 OUString const & PropertyName, 227 css::uno::Reference< 228 css::beans::XVetoableChangeListener > const & aListener) override; 229 230 virtual void SAL_CALL setPropertyValues( 231 css::uno::Sequence< OUString > const & aPropertyNames, 232 css::uno::Sequence< css::uno::Any > const & 233 aValues) override; 234 235 virtual css::uno::Sequence< css::uno::Any > SAL_CALL 236 getPropertyValues( 237 css::uno::Sequence< OUString > const & aPropertyNames) override; 238 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; 244 245 virtual void SAL_CALL removePropertiesChangeListener( 246 css::uno::Reference< 247 css::beans::XPropertiesChangeListener > const & 248 xListener) override; 249 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; 255 256 virtual 257 css::uno::Reference< 258 css::beans::XHierarchicalPropertySetInfo > SAL_CALL 259 getHierarchicalPropertySetInfo() override; 260 261 virtual void SAL_CALL setHierarchicalPropertyValue( 262 OUString const & aHierarchicalPropertyName, 263 css::uno::Any const & aValue) override; 264 265 virtual css::uno::Any SAL_CALL getHierarchicalPropertyValue( 266 OUString const & aHierarchicalPropertyName) override; 267 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; 273 274 virtual css::uno::Sequence< css::uno::Any > SAL_CALL 275 getHierarchicalPropertyValues( 276 css::uno::Sequence< OUString > const & 277 aHierarchicalPropertyNames) override; 278 279 virtual css::beans::Property SAL_CALL 280 getPropertyByHierarchicalName(OUString const & aHierarchicalName) override; 281 282 virtual sal_Bool SAL_CALL hasPropertyByHierarchicalName( 283 OUString const & aHierarchicalName) override; 284 285 virtual void SAL_CALL replaceByName( 286 OUString const & aName, css::uno::Any const & aElement) override; 287 288 virtual void SAL_CALL insertByName( 289 OUString const & aName, css::uno::Any const & aElement) override; 290 291 virtual void SAL_CALL removeByName(OUString const & aName) override; 292 293 virtual css::uno::Reference< css::uno::XInterface > 294 SAL_CALL createInstance() override; 295 296 virtual css::uno::Reference< css::uno::XInterface > 297 SAL_CALL createInstanceWithArguments( 298 css::uno::Sequence< css::uno::Any > const & 299 aArguments) override; 300 301 protected: 302 explicit Access(Components & components); 303 304 virtual ~Access() override; 305 306 virtual OUString getNameInternal() = 0; 307 virtual rtl::Reference< RootAccess > getRootAccess() = 0; 308 virtual rtl::Reference< Access > getParentAccess() = 0; 309 310 virtual void addTypes(std::vector< css::uno::Type > * types) 311 const = 0; 312 313 virtual void addSupportedServiceNames( 314 std::vector<OUString> * services) = 0; 315 316 virtual void initDisposeBroadcaster(Broadcaster * broadcaster); 317 virtual void clearListeners() throw (); 318 319 virtual css::uno::Any SAL_CALL queryInterface( 320 css::uno::Type const & aType) override; 321 getComponents() const322 Components & getComponents() const { return components_;} 323 324 void checkLocalizedPropertyAccess(); 325 326 rtl::Reference< Node > getParentNode(); 327 rtl::Reference< ChildAccess > getChild(OUString const & name); 328 std::vector< rtl::Reference< ChildAccess > > getAllChildren(); 329 330 void checkValue( 331 css::uno::Any const & value, Type type, bool nillable); 332 333 void insertLocalizedValueChild( 334 OUString const & name, css::uno::Any const & value, 335 Modifications * localModifications); 336 337 void reportChildChanges( 338 std::vector< css::util::ElementChange > * changes); 339 340 void commitChildChanges(bool valid, Modifications * globalModifications); 341 342 void initBroadcasterAndChanges( 343 Modifications::Node const & modifications, Broadcaster * broadcaster, 344 std::vector< css::util::ElementChange > * changes); 345 isDisposed() const346 bool isDisposed() const { return disposed_;} 347 348 private: 349 Access(const Access&) = delete; 350 Access& operator=(const Access&) = delete; 351 352 struct ModifiedChild { 353 rtl::Reference< ChildAccess > child; 354 bool directlyModified; 355 356 ModifiedChild(); 357 358 ModifiedChild( 359 rtl::Reference< ChildAccess > const & theChild, 360 bool theDirectlyModified); 361 }; 362 363 typedef config_map< ModifiedChild > ModifiedChildren; 364 365 rtl::Reference< ChildAccess > getModifiedChild( 366 ModifiedChildren::iterator const & childIterator); 367 368 rtl::Reference< ChildAccess > getUnmodifiedChild( 369 OUString const & name); 370 371 rtl::Reference< ChildAccess > getSubChild(OUString const & path); 372 373 bool setChildProperty( 374 OUString const & name, css::uno::Any const & value, 375 Modifications * localModifications); 376 377 css::beans::Property asProperty(); 378 379 bool getByNameFast(const OUString & name, css::uno::Any & value); 380 rtl::Reference< ChildAccess > createUnmodifiedChild(const OUString &name, 381 const rtl::Reference< Node > &node); 382 383 void checkFinalized(); 384 385 void checkKnownProperty(OUString const & descriptor); 386 387 rtl::Reference< ChildAccess > getFreeSetMember( css::uno::Any const & value); 388 389 rtl::Reference< Access > getNotificationRoot(); 390 391 typedef config_map< ChildAccess * > WeakChildMap; 392 393 typedef 394 std::multiset< 395 css::uno::Reference< 396 css::lang::XEventListener > > 397 DisposeListeners; 398 399 typedef 400 std::multiset< 401 css::uno::Reference< 402 css::container::XContainerListener > > 403 ContainerListeners; 404 405 typedef 406 std::multiset< 407 css::uno::Reference< 408 css::beans::XPropertyChangeListener > > 409 PropertyChangeListenersElement; 410 411 typedef config_map< PropertyChangeListenersElement > 412 PropertyChangeListeners; 413 414 typedef 415 std::multiset< 416 css::uno::Reference< 417 css::beans::XVetoableChangeListener > > 418 VetoableChangeListenersElement; 419 420 typedef config_map< VetoableChangeListenersElement > 421 VetoableChangeListeners; 422 423 typedef 424 std::multiset< 425 css::uno::Reference< 426 css::beans::XPropertiesChangeListener > > 427 PropertiesChangeListeners; 428 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_; 438 439 std::shared_ptr<osl::Mutex> lock_; 440 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 448 }; 449 450 } 451 452 #endif 453 454 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ 455