| 1 |
/**************************************************************************** |
| 2 |
** |
| 3 |
** Copyright (C) 2017 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 documentation of the Qt Toolkit. |
| 7 |
** |
| 8 |
** $QT_BEGIN_LICENSE:FDL$ |
| 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 Free Documentation License Usage |
| 18 |
** Alternatively, this file may be used under the terms of the GNU Free |
| 19 |
** Documentation License version 1.3 as published by the Free Software |
| 20 |
** Foundation and appearing in the file included in the packaging of |
| 21 |
** this file. Please review the following information to ensure |
| 22 |
** the GNU Free Documentation License version 1.3 requirements |
| 23 |
** will be met: https://www.gnu.org/licenses/fdl-1.3.html. |
| 24 |
** $QT_END_LICENSE$ |
| 25 |
** |
| 26 |
****************************************************************************/ |
| 27 |
|
| 28 |
/*! |
| 29 |
\page publ-subs.html |
| 30 |
|
| 31 |
\title Qt Publish Subscribe Module |
| 32 |
\brief A set of APIs to publish and read values. |
| 33 |
|
| 34 |
\tableofcontents |
| 35 |
|
| 36 |
\ingroup technology-apis |
| 37 |
|
| 38 |
The Qt Publish Subscribe module enables applications to read item values, |
| 39 |
navigate through and subscribe to change notifications. |
| 40 |
|
| 41 |
\section1 Overview |
| 42 |
|
| 43 |
The Value Space, inside which all the item values are stored, unifies various |
| 44 |
sources of hierarchical data into a single consistent model. Conceptually |
| 45 |
the Value Space is a hierarchical tree of which each node or leaf can optionally |
| 46 |
contain a QVariant value. A serialized version of a simple example Value |
| 47 |
Space might look like this: |
| 48 |
|
| 49 |
\code |
| 50 |
/Device/Buttons = 3 |
| 51 |
/Device/Buttons/1/Name = Menu |
| 52 |
/Device/Buttons/1/Usable = true |
| 53 |
/Device/Buttons/2/Name = Select |
| 54 |
/Device/Buttons/2/Usable = false |
| 55 |
/Device/Buttons/3/Name = Back |
| 56 |
/Device/Buttons/3/Usable = true |
| 57 |
\endcode |
| 58 |
|
| 59 |
Existing values within the Value Space are accessed through the QValueSpaceSubscriber class. This |
| 60 |
class provides a means to read values, receive change notifications for a given path and navigate |
| 61 |
through the Value Space. |
| 62 |
|
| 63 |
New values are added to the Value Space via the QValueSpacePublisher class. This class allows |
| 64 |
applications to publish values and receive interest notifications when applications connect to a |
| 65 |
path. Interest notifications can be used to refrain from updating values in the Value Space when |
| 66 |
there are no interested parties. |
| 67 |
|
| 68 |
Nodes in the Value Space can be thought of as representing schema objects. |
| 69 |
Obviously this is a conceptual differentiation and not a physical one, as |
| 70 |
internally the Value Space is treated as one large tree. By applying |
| 71 |
structured schema to the space "explore-ability" is increased. For example, |
| 72 |
the \c {/Device/Buttons} schema can be defined as containing a value |
| 73 |
representing the number of mappable buttons on a device, and a sub-item for |
| 74 |
each adhering to the \c {MappableButton} schema. The \c {MappableButton} |
| 75 |
schema itself may be defined as containing two attributes \c {Name} and |
| 76 |
\c {Usable}. Change notification is modeled in this fashion also. Were the |
| 77 |
\c {/Device/Buttons/1/Name} item to change, the \c {/Device/Buttons/1} item |
| 78 |
would also be marked as changed, and so on up the tree. This allows, for example, |
| 79 |
subscribers to \c {/Device/Buttons} to be notified when anything "button" related changes. |
| 80 |
|
| 81 |
Internally, the Value Space consists of an arbitrary number of data source trees, or layers, which |
| 82 |
are stacked on top of each other to form the final unified view. If two layers contain the same |
| 83 |
item, e.g. \c {/Device/Buttons}, the value in the layer with a higher priority will shadow that |
| 84 |
with the layer of the lower priority. However, if only the layer with the lower priority contained |
| 85 |
this item, it would be visible through the QValueSpaceSubscriber class, even if the higher priority |
| 86 |
layer contained sub-items such as \c {/Device/Buttons/1}. That is, layer shadowing occurs by value |
| 87 |
not by path. Layer priority is fixed and is defined in the layer implementation. |
| 88 |
|
| 89 |
The following Value Space layers are available: |
| 90 |
|
| 91 |
\table |
| 92 |
\header |
| 93 |
\li Operating System |
| 94 |
\li Layer |
| 95 |
\li Description |
| 96 |
\row |
| 97 |
\li {1, 2} Windows |
| 98 |
\li Non-volatile Registry Layer |
| 99 |
\li The Non-volatile Registry layer provides a permanent Value Space backing store using |
| 100 |
keys stored in the Windows' registry. |
| 101 |
\br |
| 102 |
The Non-volatile Registry layer has a higher priority. |
| 103 |
\row |
| 104 |
\li Volatile Registry Layer |
| 105 |
\li The Volatile Registry layer provides a non-permanent Value Space backing store using |
| 106 |
volatile keys stored in the Windows' registry. |
| 107 |
\br |
| 108 |
The Volatile Registry layer has a lower priority. |
| 109 |
\row |
| 110 |
\li Linux |
| 111 |
\li \l{GConf Layer} |
| 112 |
\li The GConf Layer provides a permanent Value Space backing store using GConf. This |
| 113 |
layer is only available on systems where the GConf is available. |
| 114 |
\br |
| 115 |
The GConf Layer has a higher priority. |
| 116 |
\endtable |
| 117 |
|
| 118 |
\section1 Detailed Layer Descriptions |
| 119 |
|
| 120 |
\section2 GConf Layer |
| 121 |
|
| 122 |
The Qt Publish Subscribe module can be used to access the GConf configuration system. |
| 123 |
|
| 124 |
\section3 \b{Limitations of GConf Layer} |
| 125 |
|
| 126 |
GConf can natively store only a limited set of QVariant data types. These types are Bool, Int, Double, |
| 127 |
String, StringList and List. When publishing other data types the values are automatically serialized |
| 128 |
and stored to GConf as BASE64 encoded strings. When reading these values they are automatically |
| 129 |
converted back to the original data types. The serialization/deserialization is transparent operation |
| 130 |
to the API user but may cause interoperatibility issues with native applications that access the same |
| 131 |
data directly. |
| 132 |
|
| 133 |
\section1 Examples |
| 134 |
|
| 135 |
\section2 Publish and Subscribe |
| 136 |
|
| 137 |
In the example \l {publish-subscribe}{Publish and Subscribe} the Value Space is used as a method of |
| 138 |
communicating changes in one dialog (the publisher) to another dialog (the subscriber). |
| 139 |
|
| 140 |
\section2 Battery Charging - Accessing Publish and Subscribe from QML |
| 141 |
|
| 142 |
In the example \l {battery-charge}{Accessing Publish and Subscribe from QML} the Publish and |
| 143 |
Subscribe concept is now extended to make the publisher an input of the level of charge in a |
| 144 |
battery. A slider on the publisher dialog represents the modifiable level of charge. The Value |
| 145 |
Space acts as a communications medium between the publisher dialog and the subscriber graphical |
| 146 |
battery animation. The battery is implemented in QML and C++ with Value Space supplying the |
| 147 |
charge level for the animation to represent. |
| 148 |
|
| 149 |
\section1 Namespaces and Classes |
| 150 |
|
| 151 |
\section2 C++ Classes |
| 152 |
|
| 153 |
\annotatedlist publishsubscribe |
| 154 |
|
| 155 |
\section2 QML Elements |
| 156 |
|
| 157 |
\annotatedlist qml-publishsubscribe |
| 158 |
*/ |