Debian Codegraph @

src/publishsubscribe/qvaluespace.cpp

raw symbols SCIP
1 /****************************************************************************
2 **
3 ** Copyright (C) 2018 The Qt Company Ltd and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtSystems module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see https://www.qt.io/terms-conditions. For further
15 ** information use the contact form at https://www.qt.io/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 3 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL3 included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 3 requirements
23 ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24 **
25 ** GNU General Public License Usage
26 ** Alternatively, this file may be used under the terms of the GNU
27 ** General Public License version 2.0 or (at your option) the GNU General
28 ** Public license version 3 or any later version approved by the KDE Free
29 ** Qt Foundation. The licenses are as published by the Free Software
30 ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31 ** included in the packaging of this file. Please review the following
32 ** information to ensure the GNU General Public License requirements will
33 ** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34 ** https://www.gnu.org/licenses/gpl-3.0.html.
35 **
36 ** $QT_END_LICENSE$
37 **
38 ****************************************************************************/
39
40 #include <qvaluespace.h>
41 #include <qvaluespacepublisher.h>
42
43 #include "qvaluespace_p.h"
44 #include "qvaluespacemanager_p.h"
45
46 QT_BEGIN_NAMESPACE
47
48 /*!
49 \class QAbstractValueSpaceLayer
50 \brief The QAbstractValueSpaceLayer class provides support for adding new logical data layers
51 to the Qt Value Space.
52 \inmodule QtPublishSubscribe
53 \ingroup publishsubscribe
54 \internal
55
56 To create a new layer in the Value Space subclass this class and reimplement all of the virtual
57 functions. The available layers are installed when QValueSpaceManager::init() is called.
58 */
59
60 /*!
61 \typedef QAbstractValueSpaceLayer::Handle
62
63 The Handle type is an opaque, pointer sized contextual handle used to represent paths within
64 Value Space layers. Handles are only ever created by QAbstractValueSpaceLayer::item() and are
65 always released by calls to QAbstractValueSpaceLayer::removeHandle(). The special value,
66 \c {InvalidHandle} is reserved to represent an invalid handle.
67 */
68
69 /*!
70 \enum QAbstractValueSpaceLayer::Properties
71
72 To allow for efficient layer implementations, expensive handle operations, currently only
73 monitoring for changes, are enabled and disabled as needed on a per-handle basis. The
74 Properties enumeration is a bitmask representing the different properties that can exist on a
75 handle.
76
77 \value Publish Enable change notification for the handle. When set, the layer should emit
78 QAbstractValueSpaceLayer::handleChanged() signals when appropriate for the
79 handle.
80 */
81
82 /*!
83 \fn QUuid QAbstractValueSpaceLayer::id()
84
85 Returns a globally unique identifier for the layer.
86 */
87
88 /*!
89 \fn Handle QAbstractValueSpaceLayer::item(Handle parent, const QString &subPath)
90
91 Returns a new opaque handle for the requested \a subPath of \a parent. If \a parent is an
92 InvalidHandle, \a subPath is interpreted as an absolute path.
93
94 The caller should call removeHandle() to free resources used by the handle when it is no longer
95 required.
96 */
97
98 /*!
99 \fn void QAbstractValueSpaceLayer::removeHandle(Handle handle)
100
101 Releases a \a handle previously returned from QAbstractValueSpaceLayer::item().
102 */
103
104 /*!
105 \fn void QAbstractValueSpaceLayer::setProperty(Handle handle, Properties property)
106
107 Apply the specified \a property mask to \a handle.
108 */
109
110 /*!
111 \fn bool QAbstractValueSpaceLayer::value(Handle handle, QVariant *data)
112
113 Returns the value for a particular \a handle. If a value is available, the layer will set
114 \a data and return true. If no value is available, false is returned.
115 */
116
117 /*!
118 \fn bool QAbstractValueSpaceLayer::value(Handle handle, const QString &subPath, QVariant *data)
119
120 Returns the value for a particular \a subPath of \a handle. If a value is available, the
121 layer will set \a data and return true. If no value is available, false is returned.
122 */
123
124 /*!
125 \fn QSet<QString> QAbstractValueSpaceLayer::children(Handle handle)
126
127 Returns the set of children of \a handle. For example, in a layer providing the following items:
128
129 \code
130 /Device/Configuration/Applications/FocusedApplication
131 /Device/Configuration/Buttons/PrimaryInput
132 /Device/Configuration/Name
133 \endcode
134
135 a request for children of "/Device/Configuration" will return
136 { "Applications", "Buttons", "Name" }.
137 */
138
139 /*!
140 \fn QValueSpace::LayerOptions QAbstractValueSpaceLayer::layerOptions() const
141
142 Returns the QValueSpace::LayerOptions describing this layer.
143
144 \sa QValueSpace::LayerOption
145 */
146
147 /*!
148 \fn bool QAbstractValueSpaceLayer::supportsInterestNotification() const
149
150 Returns true if the layer supports interest notifications; otherwise returns false.
151 */
152
153 /*!
154 \fn bool QAbstractValueSpaceLayer::notifyInterest(Handle handle, bool interested)
155
156 Registers or unregisters that the caller is interested in \a handle and any subpaths under it.
157 If \a interested is true interest in \a handle is registered; otherwise it is unregistered.
158
159 The caller should ensure that all calls to this function with \a interested set to true have a
160 matching call with \a interested set to false.
161
162 Returns true if the notification was successfully sent; otherwise returns false.
163 */
164
165 /*!
166 \fn bool QAbstractValueSpaceLayer::setValue(QValueSpacePublisher *creator, Handle handle, const QString &subPath, const QVariant &value)
167
168 Process calls to QValueSpacePublisher::setValue() by setting the value specified by the
169 \a subPath under \a handle to \a value. Ownership of the Value Space item is assigned to
170 \a creator.
171
172 Returns true on success; otherwise returns false.
173 */
174
175 /*!
176 \fn bool QAbstractValueSpaceLayer::removeValue(QValueSpacePublisher *creator, Handle handle, const QString &subPath)
177
178 Process calls to QValueSpacePublisher::resetValue() by removing the Value Space item
179 identified by \a handle and \a subPath and created by \a creator.
180
181 Returns true on success; otherwise returns false.
182 */
183
184 /*!
185 \fn bool QAbstractValueSpaceLayer::removeSubTree(QValueSpacePublisher *creator, Handle handle)
186
187 Process calls to QValueSpacePublisher::~QValueSpacePublisher() by removing the entire sub tree
188 created by \a creator under \a handle.
189
190 Returns true on success; otherwise returns false.
191 */
192
193 /*!
194 \fn void QAbstractValueSpaceLayer::addWatch(QValueSpacePublisher *creator, Handle handle)
195
196 Registers \a creator for change notifications to values under \a handle.
197
198 \sa removeWatches()
199 */
200
201 /*!
202 \fn void QAbstractValueSpaceLayer::removeWatches(QValueSpacePublisher *creator, Handle parent)
203
204 Removes all registered change notifications for \a creator under \a parent.
205
206 \sa addWatch()
207 */
208
209 /*!
210 \fn void QAbstractValueSpaceLayer::sync()
211
212 Flushes all pending changes made by calls to setValue(), removeValue() and removeSubTree().
213 */
214
215 /*!
216 Emits the QValueSpacePublisher::interestChanged() signal on \a publisher with \a path
217 and \a interested.
218 */
219 void QAbstractValueSpaceLayer::emitInterestChanged(QValueSpacePublisher *publisher, const QString &path, bool interested)
220 {
221 emit publisher->interestChanged(path, interested);
222 }
223
224 /*!
225 \fn void QAbstractValueSpaceLayer::handleChanged(quintptr handle)
226
227 Emitted whenever the \a handle's value, or any sub value, changes.
228 */
229
230
231 /*!
232 \namespace QValueSpace
233 \brief The QValueSpace namespace contains miscellaneous identifiers used throughtout the
234 Publish and Subscribe API.
235 \inmodule QtPublishSubscribe
236 */
237
238 /*!
239 \enum QValueSpace::LayerOption
240
241 This enum describes the behaviour of the Value Space layer. In addition this enum is used as
242 a filter when constructing a QValueSpacePublisher or QValueSpaceSubscriber.
243
244 \value UnspecifiedLayer Used as a filter to specify that any layer should be used.
245 \value PermanentLayer Indicates that the layer uses a permanent backing store. When used
246 as a filter only layers that use a permanent backing store will be
247 used.
248 \br
249 Values stored in a layer with this option will persist with in the
250 layer after the QValueSpacePublisher that published them is
251 destroyed.
252 \br
253 This option and the TransientLayer option are mutually
254 exclusive.
255 \value TransientLayer Indicates that the layer does not use a permanent backing store.
256 When used as a filter only layers that do not use permanent backing
257 stores will be used.
258 \br
259 Values stored in a layer with this option will be removed when the
260 QValueSpacePublisher that published them is destroyed.
261 \br
262 This option and the PermanentLayer option are mutually exclusive.
263 \value WritableLayer Indicates that the layer can update its contents. When used as a
264 filter only layers that are writable will be used.
265 \br
266 Applications can use QValueSpacePublisher to publish values to
267 layers that have this option.
268 \br
269 This option and the ReadOnlyLayer option are mutually exclusive.
270 \value ReadOnlyLayer Indicates that the layer cannot update its contents. When used as
271 a filter only layers that are read-only will be used.
272 \br
273 Applications can not publish values to layers with this option.
274 \br
275 This option and the WritableLayer option are mutually exclusive.
276 */
277
278 /*!
279 \macro QVALUESPACE_VOLATILEREGISTRY_LAYER
280 \relates QValueSpace
281
282 The UUID of the Volatile Registry layer as a QUuid. The actual UUID value is
283 {8ceb5811-4968-470f-8fc2-264767e0bbd9}.
284
285 This value can be passed to the constructor of QValueSpacePublisher or QValueSpaceSubscriber to
286 force the constructed object to only access the Volatile Registry layer.
287
288 You can test if the Volatile Registry layer is available by checking if the list returned by
289 QValueSpace::availableLayers() contains this value. The Volatile Registry layer is only
290 available on Windows platforms.
291 */
292
293 /*!
294 \macro QVALUESPACE_NONVOLATILEREGISTRY_LAYER
295 \relates QValueSpace
296
297 The UUID of the Non-Volatile Registry layer as a QUuid. The actual UUID value is
298 {8e29561c-a0f0-4e89-ba56-080664abc017}.
299
300 This value can be passed to the constructor of QValueSpacePublisher or QValueSpaceSubscriber to
301 force the constructed object to only access the Non-Volatile Registry layer.
302
303 You can test if the Non-Volatile Registry layer is available by checking if the list returned
304 by QValueSpace::availableLayers() contains this value. The Non-Volatile Registry layer is only
305 available on Windows platforms.
306 */
307
308 /*!
309 \macro QVALUESPACE_GCONF_LAYER
310 \relates QValueSpace
311
312 The UUID of the GConf layer as a QUuid. The actual UUID value is
313 {0e2e5da0-0044-11df-941c-0002a5d5c51b}.
314
315 This value can be passed to the constructor of QValueSpacePublisher or QValueSpaceSubscriber to
316 force the constructed object to only access the GConf layer.
317
318 You can test if the GConf layer is available by checking if the list returned by
319 QValueSpace::availableLayers() contains this value. The GConf layer is only available on Linux
320 platforms.
321 */
322
323 /*!
324 Returns a list of QUuids of all of the available layers, sorted in the priority order.
325 */
326 QList<QUuid> QValueSpace::availableLayers()
327 {
328 QList<QAbstractValueSpaceLayer *> layers = QValueSpaceManager::instance()->getLayers();
329
330 QList<QUuid> uuids;
331
332 for (int i = 0; i < layers.count(); ++i)
333 uuids.append(layers.at(i)->id());
334
335 return uuids;
336 }
337
338 /*!
339 \internal
340 \inmodule QtPublishSubscribe
341
342 Returns \a path with all duplicate '/' characters removed.
343 */
344 QString qCanonicalPath(const QString &path)
345 {
346 QString result;
347 result.resize(path.length());
348 const QChar *from = path.constData();
349 const QChar *fromend = from + path.length();
350 int outc=0;
351 QChar *to = result.data();
352 do {
353 to[outc++] = QLatin1Char('/');
354 while (from!=fromend && *from == QLatin1Char('/'))
355 ++from;
356 while (from!=fromend && *from != QLatin1Char('/'))
357 to[outc++] = *from++;
358 } while (from != fromend);
359 if (outc > 1 && to[outc-1] == QLatin1Char('/'))
360 --outc;
361 result.resize(outc);
362 return result;
363 }
364
365 QT_END_NAMESPACE