-
Notifications
You must be signed in to change notification settings - Fork 75
/
Copy pathservice.h
239 lines (201 loc) · 6.45 KB
/
service.h
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
/****************************************************************************
**
** 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>
**
****************************************************************************/
#ifndef SERVICE_H
#define SERVICE_H
#include <QObject>
#include <QQmlListProperty>
#include "servicediscoveryitem.h"
#include "servicediscoveryfilter.h"
#include "servicediscoveryquery.h"
namespace qtquickvcp {
class Service : public QObject
{
Q_OBJECT
Q_PROPERTY(QString type READ type WRITE setType NOTIFY typeChanged)
Q_PROPERTY(QString domain READ domain WRITE setDomain NOTIFY domainChanged)
Q_PROPERTY(QString baseType READ baseType WRITE setBaseType NOTIFY baseTypeChanged)
Q_PROPERTY(QString protocol READ protocol WRITE setProtocol NOTIFY protocolChanged)
Q_PROPERTY(QString name READ name NOTIFY nameChanged)
Q_PROPERTY(QString uri READ uri NOTIFY uriChanged)
Q_PROPERTY(QString uuid READ uuid NOTIFY uuidChanged)
Q_PROPERTY(int version READ version NOTIFY versionChanged)
Q_PROPERTY(bool ready READ isReady NOTIFY readyChanged)
Q_PROPERTY(ServiceDiscoveryFilter *filter READ filter WRITE setFilter NOTIFY filterChanged)
Q_PROPERTY(QQmlListProperty<qtquickvcp::ServiceDiscoveryItem> items READ items NOTIFY itemsChanged)
Q_PROPERTY(bool required READ required WRITE setRequired NOTIFY requiredChanged)
Q_PROPERTY(QQmlListProperty<qtquickvcp::ServiceDiscoveryQuery> queries READ queries)
Q_PROPERTY(QString hostName READ hostName NOTIFY hostNameChanged)
Q_PROPERTY(QString hostAddress READ hostAddress NOTIFY hostAddressChanged)
public:
explicit Service(QObject *parent = 0);
QQmlListProperty<ServiceDiscoveryItem> items();
int itemCount() const;
ServiceDiscoveryItem *item(int index) const;
QQmlListProperty<ServiceDiscoveryQuery> queries();
int queriesCount() const;
ServiceDiscoveryQuery *query(int index) const;
inline QList<ServiceDiscoveryQuery*>::iterator begin() { return m_queries.begin(); }
inline QList<ServiceDiscoveryQuery*>::iterator end() { return m_queries.end(); }
QString uri() const
{
return m_uri;
}
int version() const
{
return m_version;
}
bool isReady() const
{
return m_ready;
}
QString type() const
{
return m_type;
}
QString domain() const
{
return m_domain;
}
QString baseType() const
{
return m_baseType;
}
QString protocol() const
{
return m_protocol;
}
QString name() const
{
return m_name;
}
ServiceDiscoveryFilter *filter() const
{
return m_filter;
}
QString uuid() const
{
return m_uuid;
}
bool required() const
{
return m_required;
}
QString hostName() const
{
return m_hostName;
}
QString hostAddress() const
{
return m_hostAddress;
}
public slots:
void setType(const QString &arg)
{
if (m_type != arg) {
m_type = arg;
emit typeChanged(arg);
}
}
void setDomain(const QString &domain)
{
if (m_domain == domain) {
return;
}
m_domain = domain;
emit domainChanged(domain);
}
void setBaseType(const QString &baseType)
{
if (m_baseType == baseType) {
return;
}
m_baseType = baseType;
emit baseTypeChanged(baseType);
}
void setProtocol(const QString &protocol)
{
if (m_protocol == protocol) {
return;
}
m_protocol = protocol;
emit protocolChanged(protocol);
}
void setFilter(ServiceDiscoveryFilter *arg)
{
if (m_filter != arg) {
m_filter = arg;
emit filterChanged(arg);
m_serviceQuery->setFilter(m_filter); // pass the filter to the underlying query
}
}
void setRequired(bool arg)
{
if (m_required == arg) {
return;
}
m_required = arg;
emit requiredChanged(arg);
}
private:
QString m_type;
QString m_domain;
QString m_baseType;
QString m_protocol;
QString m_name;
QString m_uri;
QString m_uuid;
int m_version;
bool m_ready;
ServiceDiscoveryFilter *m_filter;
QList<ServiceDiscoveryItem *> m_items;
bool m_required;
ServiceDiscoveryQuery *m_serviceQuery;
QList<ServiceDiscoveryQuery *> m_queries;
bool m_itemsReady; // true when we have items
QString m_rawUri; // the raw uri from the items
QString m_hostName; // the hostname that is queried
QString m_hostAddress; // the address that was resolved
const QString composeSdString(const QString &type, const QString &domain, const QString &protocol);
const QString composeSdString(const QString &subType, const QString &type, const QString &domain, const QString &protocol);
private slots:
void updateUri();
void updateServiceQuery();
void serviceQueryItemsUpdated(QQmlListProperty<ServiceDiscoveryItem> newItems);
signals:
void uriChanged(const QString &arg);
void versionChanged(int arg);
void readyChanged(bool arg);
void typeChanged(const QString &arg);
void domainChanged(const QString &domain);
void baseTypeChanged(const QString &baseType);
void protocolChanged(const QString &protocol);
void nameChanged(const QString &arg);
void itemsChanged(QQmlListProperty<ServiceDiscoveryItem> arg);
void filterChanged(ServiceDiscoveryFilter *arg);
void uuidChanged(const QString &arg);
void requiredChanged(bool arg);
void queriesChanged();
void hostNameChanged(const QString &hostName);
void hostAddressChanged(const QString &hostAddress);
}; // class Service
} // namespace qtquickvcp
#endif // SERVICE_H