1/****************************************************************************
2**
3** Copyright (C) 2015 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:LGPL21$
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 http://www.qt.io/terms-conditions. For further
15** information use the contact form at http://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 2.1 or version 3 as published by the Free
20** Software Foundation and appearing in the file LICENSE.LGPLv21 and
21** LICENSE.LGPLv3 included in the packaging of this file. Please review the
22** following information to ensure the GNU Lesser General Public License
23** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
24** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25**
26** As a special exception, The Qt Company gives you certain additional
27** rights. These rights are described in The Qt Company LGPL Exception
28** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29**
30** $QT_END_LICENSE$
31**
32****************************************************************************/
33
34//
35// W A R N I N G
36// -------------
37//
38// This file is not part of the Qt API. It exists purely as an
39// implementation detail. This header file may change from version to
40// version without notice, or even be removed.
41//
42// We mean it.
43//
44
45#ifndef REGISTRYLAYER_WIN_P_H
46#define REGISTRYLAYER_WIN_P_H
47
48#include "qvaluespace_p.h"
49#include "qvaluespacepublisher.h"
50
51#include <QSet>
52#include <QStringList>
53#include <QEventLoop>
54#include <QTimer>
55#include <QVariant>
56#include <QMutex>
57#include <QDebug>
58
59#if defined(Q_OS_WIN)
60
61// Define win32 version to pull in RegisterWaitForSingleObject and UnregisterWait.
62#define _WIN32_WINNT 0x0500
63#include <windows.h>
64
65#define RegistryCallback WAITORTIMERCALLBACK
66
67QT_BEGIN_NAMESPACE
68
69class RegistryLayer : public QAbstractValueSpaceLayer
70{
71 Q_OBJECT
72
73public:
74 RegistryLayer(const QString &basePath, bool volatileKeys, RegistryCallback callback);
75 ~RegistryLayer();
76
77 /* Common functions */
78 Handle item(Handle parent, const QString &path);
79 void removeHandle(Handle handle);
80 void setProperty(Handle handle, Properties);
81
82 bool value(Handle handle, QVariant *data);
83 bool value(Handle handle, const QString &subPath, QVariant *data);
84 QSet<QString> children(Handle handle);
85
86 /* QValueSpaceSubscriber functions */
87 bool supportsInterestNotification() const;
88 bool notifyInterest(Handle handle, bool interested);
89
90 /* QValueSpacePublisher functions */
91 bool setValue(QValueSpacePublisher *creator, Handle handle, const QVariant &data);
92 bool setValue(QValueSpacePublisher *creator, Handle handle, const QString &path,
93 const QVariant &data);
94 bool removeValue(QValueSpacePublisher *creator, Handle handle, const QString &subPath);
95 bool removeSubTree(QValueSpacePublisher *creator, Handle parent);
96 void addWatch(QValueSpacePublisher *creator, Handle handle);
97 void removeWatches(QValueSpacePublisher *creator, Handle parent);
98 void sync();
99
100public Q_SLOTS:
101 void emitHandleChanged(void *hkey);
102
103private:
104 struct RegistryHandle {
105 RegistryHandle(const QString &p)
106 : path(p), valueHandle(false), refCount(1)
107 {
108 }
109
110 QString path;
111 bool valueHandle;
112 unsigned int refCount;
113 };
114
115 void openRegistryKey(RegistryHandle *handle);
116 bool createRegistryKey(RegistryHandle *handle);
117 bool removeRegistryValue(RegistryHandle *handle, const QString &path);
118 void closeRegistryKey(RegistryHandle *handle);
119 void pruneEmptyKeys(RegistryHandle *handle);
120
121 QMutex localLock;
122 QString m_basePath;
123 bool m_volatileKeys;
124 RegistryCallback m_callback;
125
126 QHash<QString, RegistryHandle *> handles;
127
128 RegistryHandle *registryHandle(Handle handle)
129 {
130 if (handle == InvalidHandle)
131 return 0;
132
133 RegistryHandle *h = reinterpret_cast<RegistryHandle *>(handle);
134 if (handles.values().contains(h))
135 return h;
136
137 return 0;
138 }
139
140 QMap<RegistryHandle *, HKEY> hKeys;
141 QMultiMap<RegistryHandle *, RegistryHandle *> notifyProxies;
142 // MinGW complains about QPair<::HANDLE, ::HANDLE>
143 typedef ::HANDLE HandleType;
144 typedef QPair<HandleType, HandleType> HandlePair;
145 QMap<HKEY, HandlePair > waitHandles;
146
147 QMap<QValueSpacePublisher *, QList<QString> > creators;
148};
149
150class VolatileRegistryLayer : public RegistryLayer
151{
152 Q_OBJECT
153
154public:
155 VolatileRegistryLayer();
156 ~VolatileRegistryLayer();
157
158 /* Common functions */
159 QUuid id();
160
161 QValueSpace::LayerOptions layerOptions() const;
162
163 static VolatileRegistryLayer *instance();
164};
165
166class NonVolatileRegistryLayer : public RegistryLayer
167{
168 Q_OBJECT
169
170public:
171 NonVolatileRegistryLayer();
172 ~NonVolatileRegistryLayer();
173
174 /* Common functions */
175 QUuid id();
176
177 QValueSpace::LayerOptions layerOptions() const;
178
179 static NonVolatileRegistryLayer *instance();
180};
181
182QT_END_NAMESPACE
183
184#endif // Q_OS_WIN
185
186#endif // REGISTRYLAYER_WIN_P_H
187

source code of qtsystems/src/publishsubscribe/registrylayer_win_p.h