LibreOffice Module configmgr (master) 1
rootaccess.cxx
Go to the documentation of this file.
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#include <sal/config.h>
21
22#include <cassert>
23#include <utility>
24#include <vector>
25
26#include <com/sun/star/lang/DisposedException.hpp>
27#include <com/sun/star/lang/EventObject.hpp>
28#include <com/sun/star/uno/Any.hxx>
29#include <com/sun/star/uno/Reference.hxx>
30#include <com/sun/star/uno/RuntimeException.hpp>
31#include <com/sun/star/uno/Type.hxx>
32#include <com/sun/star/uno/XInterface.hpp>
33#include <com/sun/star/util/ChangesEvent.hpp>
34#include <com/sun/star/util/ChangesSet.hpp>
35#include <com/sun/star/util/ElementChange.hpp>
36#include <com/sun/star/util/XChangesBatch.hpp>
37#include <com/sun/star/util/XChangesListener.hpp>
38#include <com/sun/star/util/XChangesNotifier.hpp>
40#include <cppu/unotype.hxx>
42#include <cppuhelper/weak.hxx>
43#include <osl/mutex.hxx>
44#include <rtl/ref.hxx>
45#include <rtl/ustring.hxx>
46
47#include "broadcaster.hxx"
48#include "components.hxx"
49#include "data.hxx"
50#include "lock.hxx"
51#include "modifications.hxx"
52#include "node.hxx"
53#include "rootaccess.hxx"
54
55namespace configmgr {
56
58 Components & components, OUString pathRepresentation,
59 OUString locale, bool update):
60 Access(components), pathRepresentation_(std::move(pathRepresentation)),
61 locale_(std::move(locale)),
62 lock_( lock() ),
63 update_(update), finalized_(false), alive_(true)
64{
65}
66
67std::vector<OUString> RootAccess::getAbsolutePath() {
68 getNode();
69 return path_;
70}
71
73 Modifications::Node const & modifications, Broadcaster * broadcaster)
74{
75 assert(broadcaster != nullptr);
76 std::vector< css::util::ElementChange > changes;
78 modifications, broadcaster, changesListeners_.empty() ? nullptr : &changes);
79 if (changes.empty())
80 return;
81
82 css::util::ChangesSet set(comphelper::containerToSequence(changes));
83 for (auto const& changesListener : changesListeners_)
84 {
85 cppu::OWeakObject* pSource = this;
86 css::uno::Reference< css::uno::XInterface > xBase( pSource, css::uno::UNO_QUERY );
87 broadcaster->addChangesNotification(
88 changesListener,
89 css::util::ChangesEvent(
90 pSource, css::uno::Any( xBase ), set), path_.empty());
91 }
92}
93
94void RootAccess::acquire() noexcept {
96}
97
98void RootAccess::release() noexcept {
100}
101
103 getNode(); // turn pathRepresentation_ into canonic form
104 return pathRepresentation_;
105}
106
107
109 alive_ = b;
110}
111
113 css::uno::Reference< css::util::XChangesListener > const & aListener)
114{
115 assert(thisIs(IS_ANY));
116 {
117 osl::MutexGuard g(*lock_);
119 if (!aListener.is()) {
120 throw css::uno::RuntimeException(
121 "null listener", getXWeak());
122 }
123 if (!isDisposed()) {
124 changesListeners_.insert(aListener);
125 return;
126 }
127 }
128 try {
129 aListener->disposing(
130 css::lang::EventObject(getXWeak()));
131 } catch (css::lang::DisposedException &) {}
132}
133
135 css::uno::Reference< css::util::XChangesListener > const & aListener)
136{
137 assert(thisIs(IS_ANY));
138 osl::MutexGuard g(*lock_);
140 ChangesListeners::iterator i(changesListeners_.find(aListener));
141 if (i != changesListeners_.end()) {
142 changesListeners_.erase(i);
143 }
144}
145
147{
148 assert(thisIs(IS_UPDATE));
149 if (!alive_)
150 {
151 return;
152 }
153 Broadcaster bc;
154 {
155 osl::MutexGuard g(*lock_);
156
158 int finalizedLayer;
159 Modifications globalMods;
161 ((getComponents().resolvePathRepresentation(
162 pathRepresentation_, nullptr, nullptr, &finalizedLayer)
163 == node_) &&
164 finalizedLayer == Data::NO_LAYER),
165 &globalMods);
167 getComponents().initGlobalBroadcaster(globalMods, this, &bc);
168 }
169 bc.send();
170}
171
173 assert(thisIs(IS_UPDATE));
174 osl::MutexGuard g(*lock_);
176 //TODO: Optimize:
177 std::vector< css::util::ElementChange > changes;
178 reportChildChanges(&changes);
179 return !changes.empty();
180}
181
182css::uno::Sequence< ::css::util::ElementChange > RootAccess::getPendingChanges()
183{
184 assert(thisIs(IS_UPDATE));
185 osl::MutexGuard g(*lock_);
187 std::vector< css::util::ElementChange > changes;
188 reportChildChanges(&changes);
189 return comphelper::containerToSequence(changes);
190}
191
193{
194 osl::MutexGuard g(*lock_);
195 if (alive_)
197}
198
199std::vector<OUString> RootAccess::getRelativePath() {
200 return std::vector<OUString>();
201}
202
204 return OUString();
205}
206
208 if (!node_.is()) {
209 OUString canonic;
210 int finalizedLayer;
212 pathRepresentation_, &canonic, &path_, &finalizedLayer);
213 if (!node_.is()) {
214 throw css::uno::RuntimeException(
215 "cannot find " + pathRepresentation_, nullptr);
216 // RootAccess::queryInterface indirectly calls
217 // RootAccess::getNode, so if this RootAccess were passed out in
218 // RuntimeException.Context, client code that called
219 // queryInterface on it would cause trouble; therefore,
220 // RuntimeException.Context is left null here
221 }
222 pathRepresentation_ = canonic;
223 assert(!path_.empty() || node_->kind() == Node::KIND_ROOT);
224 if (!path_.empty()) {
225 name_ = path_.back();
226 }
227 finalized_ = finalizedLayer != Data::NO_LAYER;
228 }
229 return node_;
230}
231
233 getNode();
234 return finalized_;
235}
236
237const OUString & RootAccess::getNameInternal() {
238 getNode();
239 return name_;
240}
241
243 return this;
244}
245
248}
249
250void RootAccess::addTypes(std::vector< css::uno::Type > * types) const {
251 assert(types != nullptr);
254}
255
257 std::vector<OUString> * services)
258{
259 assert(services != nullptr);
260 services->push_back("com.sun.star.configuration.AccessRootElement");
261 if (update_) {
262 services->push_back("com.sun.star.configuration.UpdateRootElement");
263 }
264}
265
267 assert(broadcaster != nullptr);
268 for (auto const& changesListener : changesListeners_)
269 {
270 broadcaster->addDisposeNotification(
271 changesListener,
272 css::lang::EventObject(getXWeak()));
273 }
275}
276
278 changesListeners_.clear();
280}
281
282css::uno::Any RootAccess::queryInterface(css::uno::Type const & aType)
283{
284 assert(thisIs(IS_ANY));
285 osl::MutexGuard g(*lock_);
287 css::uno::Any res(Access::queryInterface(aType));
288 if (res.hasValue()) {
289 return res;
290 }
292 aType, static_cast< css::util::XChangesNotifier * >(this));
293 if (res.hasValue()) {
294 return res;
295 }
296 if (!res.hasValue() && update_) {
298 aType, static_cast< css::util::XChangesBatch * >(this));
299 }
300 return res;
301}
302
304{
305 assert(thisIs(IS_ANY));
306 osl::MutexGuard g(*lock_);
308 return "configmgr.RootAccess";
309}
310
311}
312
313/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void commitChildChanges(bool valid, Modifications *globalModifications)
Definition: access.cxx:1556
Components & getComponents() const
Definition: access.hxx:320
virtual void clearListeners() noexcept
Definition: access.cxx:1277
virtual void initDisposeBroadcaster(Broadcaster *broadcaster)
Definition: access.cxx:1226
void initBroadcasterAndChanges(Modifications::Node const &modifications, Broadcaster *broadcaster, std::vector< css::util::ElementChange > *changes)
Definition: access.cxx:1607
virtual css::uno::Any SAL_CALL queryInterface(css::uno::Type const &aType) override
Definition: access.cxx:1294
bool thisIs(int what)
Definition: access.cxx:2201
void checkLocalizedPropertyAccess()
Definition: access.cxx:1352
void reportChildChanges(std::vector< css::util::ElementChange > *changes)
Definition: access.cxx:1538
bool isDisposed() const
Definition: access.hxx:344
void addChangesNotification(css::uno::Reference< css::util::XChangesListener > const &listener, css::util::ChangesEvent const &event, bool bRootListener)
Definition: broadcaster.cxx:98
void addDisposeNotification(css::uno::Reference< css::lang::XEventListener > const &listener, css::lang::EventObject const &event)
Definition: broadcaster.cxx:55
void removeRootAccess(RootAccess *access)
Definition: components.cxx:229
void initGlobalBroadcaster(Modifications const &modifications, rtl::Reference< RootAccess > const &exclude, Broadcaster *broadcaster)
Definition: components.cxx:233
rtl::Reference< Node > resolvePathRepresentation(OUString const &pathRepresentation, OUString *canonicRepresentation, std::vector< OUString > *path, int *finalizedLayer) const
Definition: components.cxx:211
OUString pathRepresentation_
Definition: rootaccess.hxx:128
rtl::Reference< Node > node_
Definition: rootaccess.hxx:131
virtual void SAL_CALL commitChanges() override
Definition: rootaccess.cxx:146
OUString const & getAbsolutePathRepresentation()
Definition: rootaccess.cxx:102
virtual void SAL_CALL removeChangesListener(css::uno::Reference< css::util::XChangesListener > const &aListener) override
Definition: rootaccess.cxx:134
virtual ~RootAccess() override
Definition: rootaccess.cxx:192
virtual std::vector< OUString > getRelativePath() override
Definition: rootaccess.cxx:199
virtual const OUString & getNameInternal() override
Definition: rootaccess.cxx:237
std::vector< OUString > path_
Definition: rootaccess.hxx:130
virtual void SAL_CALL acquire() noexcept override
Definition: rootaccess.cxx:94
void setAlive(bool b)
Definition: rootaccess.cxx:108
virtual void SAL_CALL addChangesListener(css::uno::Reference< css::util::XChangesListener > const &aListener) override
Definition: rootaccess.cxx:112
virtual rtl::Reference< Access > getParentAccess() override
Definition: rootaccess.cxx:246
virtual OUString SAL_CALL getImplementationName() override
Definition: rootaccess.cxx:303
virtual css::uno::Any SAL_CALL queryInterface(css::uno::Type const &aType) override
Definition: rootaccess.cxx:282
std::shared_ptr< osl::Mutex > lock_
Definition: rootaccess.hxx:135
virtual std::vector< OUString > getAbsolutePath() override
Definition: rootaccess.cxx:67
virtual void addSupportedServiceNames(std::vector< OUString > *services) override
Definition: rootaccess.cxx:256
virtual void clearListeners() noexcept override
Definition: rootaccess.cxx:277
virtual rtl::Reference< RootAccess > getRootAccess() override
Definition: rootaccess.cxx:242
virtual OUString getRelativePathRepresentation() override
Definition: rootaccess.cxx:203
virtual void addTypes(std::vector< css::uno::Type > *types) const override
Definition: rootaccess.cxx:250
virtual rtl::Reference< Node > getNode() override
Definition: rootaccess.cxx:207
virtual void initDisposeBroadcaster(Broadcaster *broadcaster) override
Definition: rootaccess.cxx:266
ChangesListeners changesListeners_
Definition: rootaccess.hxx:133
virtual bool isFinalized() override
Definition: rootaccess.cxx:232
virtual void initBroadcaster(Modifications::Node const &modifications, Broadcaster *broadcaster) override
Definition: rootaccess.cxx:72
virtual sal_Bool SAL_CALL hasPendingChanges() override
Definition: rootaccess.cxx:172
virtual void SAL_CALL release() noexcept override
Definition: rootaccess.cxx:98
virtual css::uno::Sequence< ::css::util::ElementChange > SAL_CALL getPendingChanges() override
Definition: rootaccess.cxx:182
RootAccess(Components &components, OUString pathRepresentation, OUString locale, bool update)
Definition: rootaccess.cxx:57
virtual void SAL_CALL acquire() SAL_NOEXCEPT SAL_OVERRIDE
virtual void SAL_CALL release() SAL_NOEXCEPT SAL_OVERRIDE
OUString locale_
std::shared_ptr< osl::Mutex > lock_
void set(css::uno::UnoInterfaceReference const &value)
css::uno::Sequence< DstElementType > containerToSequence(const SrcType &i_Container)
std::shared_ptr< osl::Mutex > const & lock()
Definition: lock.cxx:28
css::uno::Any SAL_CALL queryInterface(const css::uno::Type &rType, Interface1 *p1)
int i
unsigned char sal_Bool
bool update()