-
Notifications
You must be signed in to change notification settings - Fork 75
/
Copy pathservicediscoveryitem.cpp
309 lines (252 loc) · 6.47 KB
/
servicediscoveryitem.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
/****************************************************************************
**
** Copyright (C) 2014 Alexander Rössler
** License: LGPL version 2.1
**
** This file is part of QtQuickVcp.
**
** All rights reserved. This program and the accompanying materials
** are made available under the terms of the GNU Lesser General Public License
** (LGPL) version 2.1 which accompanies this distribution, and is available at
** http://www.gnu.org/licenses/lgpl-2.1.html
**
** This library is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
** Lesser General Public License for more details.
**
** Contributors:
** Alexander Rössler @ The Cool Tool GmbH <mail DOT aroessler AT gmail DOT com>
**
****************************************************************************/
#include "servicediscoveryitem.h"
namespace qtquickvcp {
/*!
\qmltype ServiceDiscoveryItem
\instantiates QServiceDiscoveryItem
\inqmlmodule Machinekit.HalRemote
\brief Service discovery item
\ingroup halremote
This component is used to store information and data of resolved services.
The properties \l{uuid}, \l{uri} and \l{version} are provided for
convenience reasons and filled with the corresponding data from the
\l txtRecords.
\sa Service
*/
/*! \qmlproperty string ServiceDiscoveryItem::type
This property holds the type of the service.
*/
/*! \qmlproperty string ServiceDiscoveryItem::name
This property holds the name of the service.
*/
/*! \qmlproperty string ServiceDiscoveryItem::uri
This property holds the uri of the service.
*/
/*! \qmlproperty string ServiceDiscoveryItem::uuid
This property holds the uuid of the service. The uuid can be used to
create a filter for filtering instances.
*/
/*! \qmlproperty int ServiceDiscoveryItem::version
This property holds the version of the service. This property is \c 0
if no version is specified within the service.
*/
/*! \qmlproperty int ServiceDiscoveryItem::port
This property holds the port of the service.
*/
/*! \qmlproperty string ServiceDiscoveryItem::hostAddress
This property holds the host address of the service.
*/
/*! \qmlproperty string ServiceDiscoveryItem::hostName
This property holds the host name of the service.
*/
/*! \qmlproperty list<string> ServiceDiscoveryItem::txtRecords
This property holds the TXT records of the service.
*/
ServiceDiscoveryItem::ServiceDiscoveryItem(QObject *parent) :
QObject(parent),
m_name(""),
m_type(""),
m_uri(""),
m_uuid(""),
m_version(0),
m_port(0),
m_hostName(""),
m_hostAddress(""),
m_txtRecords(QStringList()),
m_outstandingRequests(QSet<int>()),
m_updated(false),
m_errorCount(0)
{
}
QString ServiceDiscoveryItem::uri() const
{
return m_uri;
}
int ServiceDiscoveryItem::port() const
{
return m_port;
}
QString ServiceDiscoveryItem::hostName() const
{
return m_hostName;
}
QString ServiceDiscoveryItem::hostAddress() const
{
return m_hostAddress;
}
QString ServiceDiscoveryItem::name() const
{
return m_name;
}
QString ServiceDiscoveryItem::type() const
{
return m_type;
}
QStringList ServiceDiscoveryItem::txtRecords() const
{
return m_txtRecords;
}
QString ServiceDiscoveryItem::uuid() const
{
return m_uuid;
}
QSet<int> ServiceDiscoveryItem::outstandingRequests() const
{
return m_outstandingRequests;
}
bool ServiceDiscoveryItem::hasOutstandingRequests()
{
return (!m_outstandingRequests.isEmpty());
}
int ServiceDiscoveryItem::version() const
{
return m_version;
}
bool ServiceDiscoveryItem::updated() const
{
return m_updated;
}
int ServiceDiscoveryItem::errorCount() const
{
return m_errorCount;
}
void ServiceDiscoveryItem::setUri(const QString &arg)
{
if (m_uri != arg) {
m_uri = arg;
emit uriChanged(arg);
}
}
void ServiceDiscoveryItem::setPort(int arg)
{
if (m_port != arg) {
m_port = arg;
emit portChanged(arg);
}
}
void ServiceDiscoveryItem::setHostName(const QString &arg)
{
if (m_hostName != arg) {
m_hostName = arg;
emit hostNameChanged(arg);
}
}
void ServiceDiscoveryItem::setHostAddress(const QString &arg)
{
if (m_hostAddress != arg) {
m_hostAddress = arg;
emit hostAddressChanged(arg);
}
}
void ServiceDiscoveryItem::setName(const QString &arg)
{
if (m_name != arg) {
m_name = arg;
emit nameChanged(arg);
}
}
void ServiceDiscoveryItem::setType(const QString &arg)
{
if (m_type != arg) {
m_type = arg;
emit typeChanged(arg);
}
}
void ServiceDiscoveryItem::setUuid(const QString &arg)
{
if (m_uuid != arg) {
m_uuid = arg;
emit uuidChanged(arg);
}
}
void ServiceDiscoveryItem::addOutstandingRequest(int arg)
{
m_outstandingRequests.insert(arg);
}
void ServiceDiscoveryItem::removeOutstandingRequest(int arg)
{
m_outstandingRequests.remove(arg);
}
void ServiceDiscoveryItem::clearOutstandingRequests()
{
m_outstandingRequests.clear();
}
void ServiceDiscoveryItem::setVersion(int arg)
{
if (m_version != arg) {
m_version = arg;
emit versionChanged(arg);
}
}
void ServiceDiscoveryItem::setUpdated(bool arg)
{
if (m_updated != arg) {
m_updated = arg;
emit updatedChanged(arg);
}
}
void ServiceDiscoveryItem::setErrorCount(int errorCount)
{
if (m_errorCount == errorCount)
return;
m_errorCount = errorCount;
}
void ServiceDiscoveryItem::resetErrorCount()
{
m_errorCount = 0;
}
void ServiceDiscoveryItem::increaseErrorCount()
{
m_errorCount += 1;
}
void ServiceDiscoveryItem::setTxtRecords(const QStringList &arg)
{
if (m_txtRecords != arg) {
m_txtRecords = arg;
QString uri("");
QString uuid("");
int version(0);
for (const QString &string: qAsConst(m_txtRecords))
{
QStringList keyValue;
keyValue = string.split("=");
if (keyValue.at(0) == "dsn")
{
uri = keyValue.at(1);
}
else if (keyValue.at(0) == "uuid")
{
uuid = keyValue.at(1);
}
else if (keyValue.at(0) == "version")
{
version = keyValue.at(1).toInt();
}
}
setUri(uri);
setUuid(uuid);
setVersion(version);
emit txtRecordsChanged(arg);
}
}
} // namespace qtquickvcp