mirror of
https://github.com/jbagg/QtZeroConf.git
synced 2025-08-02 19:04:25 +02:00
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
*.user
|
@@ -105,6 +105,8 @@ public:
|
|||||||
QString key = name + QString::number(interface);
|
QString key = name + QString::number(interface);
|
||||||
QZeroConfPrivate *ref = static_cast<QZeroConfPrivate *>(userdata);
|
QZeroConfPrivate *ref = static_cast<QZeroConfPrivate *>(userdata);
|
||||||
|
|
||||||
|
QZeroConfService zcs;
|
||||||
|
|
||||||
switch (event) {
|
switch (event) {
|
||||||
case AVAHI_BROWSER_FAILURE:
|
case AVAHI_BROWSER_FAILURE:
|
||||||
ref->broswerCleanUp();
|
ref->broswerCleanUp();
|
||||||
@@ -122,11 +124,10 @@ public:
|
|||||||
|
|
||||||
if (!ref->pub->services.contains(key))
|
if (!ref->pub->services.contains(key))
|
||||||
return;
|
return;
|
||||||
QZeroConfService *zcs;
|
|
||||||
zcs = ref->pub->services[key];
|
zcs = ref->pub->services[key];
|
||||||
ref->pub->services.remove(key);
|
ref->pub->services.remove(key);
|
||||||
emit ref->pub->serviceRemoved(zcs);
|
emit ref->pub->serviceRemoved(zcs);
|
||||||
delete zcs;
|
|
||||||
break;
|
break;
|
||||||
case AVAHI_BROWSER_ALL_FOR_NOW:
|
case AVAHI_BROWSER_ALL_FOR_NOW:
|
||||||
case AVAHI_BROWSER_CACHE_EXHAUSTED:
|
case AVAHI_BROWSER_CACHE_EXHAUSTED:
|
||||||
@@ -150,7 +151,7 @@ public:
|
|||||||
AVAHI_GCC_UNUSED void* userdata)
|
AVAHI_GCC_UNUSED void* userdata)
|
||||||
{
|
{
|
||||||
bool newRecord = 0;
|
bool newRecord = 0;
|
||||||
QZeroConfService *zcs;
|
QZeroConfService zcs;
|
||||||
QZeroConfPrivate *ref = static_cast<QZeroConfPrivate *>(userdata);
|
QZeroConfPrivate *ref = static_cast<QZeroConfPrivate *>(userdata);
|
||||||
|
|
||||||
QString key = name + QString::number(interface);
|
QString key = name + QString::number(interface);
|
||||||
@@ -159,21 +160,20 @@ public:
|
|||||||
zcs = ref->pub->services[key];
|
zcs = ref->pub->services[key];
|
||||||
else {
|
else {
|
||||||
newRecord = 1;
|
newRecord = 1;
|
||||||
zcs = new QZeroConfService;
|
zcs.setName(name);
|
||||||
zcs->name = name;
|
zcs.setType(type);
|
||||||
zcs->type = type;
|
zcs.setDomain(domain);
|
||||||
zcs->domain = domain;
|
zcs.setHost(host_name);
|
||||||
zcs->host = host_name;
|
zcs.setInterfaceIndex(interface);
|
||||||
zcs->interfaceIndex = interface;
|
zcs.setPort(port);
|
||||||
zcs->port = port;
|
|
||||||
while (txt) // get txt records
|
while (txt) // get txt records
|
||||||
{
|
{
|
||||||
QByteArray avahiText((const char *)txt->text, txt->size);
|
QByteArray avahiText((const char *)txt->text, txt->size);
|
||||||
QList<QByteArray> pair = avahiText.split('=');
|
QList<QByteArray> pair = avahiText.split('=');
|
||||||
if (pair.size() == 2)
|
if (pair.size() == 2)
|
||||||
zcs->txt[pair.at(0)] = pair.at(1);
|
zcs.appendTxt(pair.at(0), pair.at(1));
|
||||||
else
|
else
|
||||||
zcs->txt[pair.at(0)] = "";
|
zcs.appendTxt(pair.at(0));
|
||||||
txt = txt->next;
|
txt = txt->next;
|
||||||
}
|
}
|
||||||
ref->pub->services.insert(key, zcs);
|
ref->pub->services.insert(key, zcs);
|
||||||
@@ -181,10 +181,11 @@ public:
|
|||||||
|
|
||||||
char a[AVAHI_ADDRESS_STR_MAX];
|
char a[AVAHI_ADDRESS_STR_MAX];
|
||||||
avahi_address_snprint(a, sizeof(a), address);
|
avahi_address_snprint(a, sizeof(a), address);
|
||||||
|
QHostAddress addr(a);
|
||||||
if (protocol == AVAHI_PROTO_INET6)
|
if (protocol == AVAHI_PROTO_INET6)
|
||||||
zcs->ipv6 = QHostAddress(a);
|
zcs.setIpv6(addr);
|
||||||
else if (protocol == AVAHI_PROTO_INET)
|
else if (protocol == AVAHI_PROTO_INET)
|
||||||
zcs->ip = QHostAddress (a);
|
zcs.setIp(addr);
|
||||||
|
|
||||||
if (newRecord)
|
if (newRecord)
|
||||||
emit ref->pub->serviceAdded(zcs);
|
emit ref->pub->serviceAdded(zcs);
|
||||||
@@ -195,7 +196,6 @@ public:
|
|||||||
zcs = ref->pub->services[key];
|
zcs = ref->pub->services[key];
|
||||||
ref->pub->services.remove(key);
|
ref->pub->services.remove(key);
|
||||||
emit ref->pub->serviceRemoved(zcs);
|
emit ref->pub->serviceRemoved(zcs);
|
||||||
delete zcs;
|
|
||||||
// don't delete the resolver here...we need to keep it around so Avahi will keep updating....might be able to resolve the service in the future
|
// don't delete the resolver here...we need to keep it around so Avahi will keep updating....might be able to resolve the service in the future
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -207,10 +207,9 @@ public:
|
|||||||
avahi_service_browser_free(browser);
|
avahi_service_browser_free(browser);
|
||||||
browser = NULL;
|
browser = NULL;
|
||||||
|
|
||||||
QMap<QString, QZeroConfService *>::iterator i;
|
QMap<QString, QZeroConfService>::iterator i;
|
||||||
for (i = pub->services.begin(); i != pub->services.end(); i++) {
|
for (i = pub->services.begin(); i != pub->services.end(); i++) {
|
||||||
emit pub->serviceRemoved(*i);
|
emit pub->serviceRemoved(i.value());
|
||||||
delete *i;
|
|
||||||
}
|
}
|
||||||
pub->services.clear();
|
pub->services.clear();
|
||||||
|
|
||||||
|
40
bonjour.cpp
40
bonjour.cpp
@@ -37,7 +37,6 @@ QZeroConfPrivate::QZeroConfPrivate(QZeroConf *parent)
|
|||||||
browserSocket = NULL;
|
browserSocket = NULL;
|
||||||
resolverSocket = NULL;
|
resolverSocket = NULL;
|
||||||
addressSocket = NULL;
|
addressSocket = NULL;
|
||||||
newService = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void QZeroConfPrivate::bsRead()
|
void QZeroConfPrivate::bsRead()
|
||||||
@@ -69,7 +68,7 @@ void QZeroConfPrivate::resolve(void)
|
|||||||
{
|
{
|
||||||
DNSServiceErrorType err;
|
DNSServiceErrorType err;
|
||||||
|
|
||||||
err = DNSServiceResolve(&resolver, kDNSServiceFlagsTimeout, newService->interfaceIndex, newService->name.toUtf8(), newService->type.toUtf8(), newService->domain.toUtf8(), (DNSServiceResolveReply) resolverCallback, this);
|
err = DNSServiceResolve(&resolver, kDNSServiceFlagsTimeout, newService.interfaceIndex(), newService.name().toUtf8(), newService.type().toUtf8(), newService.domain().toUtf8(), (DNSServiceResolveReply) resolverCallback, this);
|
||||||
if (err == kDNSServiceErr_NoError) {
|
if (err == kDNSServiceErr_NoError) {
|
||||||
int sockfd = DNSServiceRefSockFD(resolver);
|
int sockfd = DNSServiceRefSockFD(resolver);
|
||||||
if (sockfd == -1) {
|
if (sockfd == -1) {
|
||||||
@@ -103,7 +102,7 @@ void DNSSD_API QZeroConfPrivate::browseCallback(DNSServiceRef, DNSServiceFlags f
|
|||||||
const char *type, const char *domain, void *userdata)
|
const char *type, const char *domain, void *userdata)
|
||||||
{
|
{
|
||||||
QString key;
|
QString key;
|
||||||
QZeroConfService *zcs;
|
QZeroConfService zcs;
|
||||||
QZeroConfPrivate *ref = static_cast<QZeroConfPrivate *>(userdata);
|
QZeroConfPrivate *ref = static_cast<QZeroConfPrivate *>(userdata);
|
||||||
|
|
||||||
//qDebug() << name;
|
//qDebug() << name;
|
||||||
@@ -111,12 +110,11 @@ void DNSSD_API QZeroConfPrivate::browseCallback(DNSServiceRef, DNSServiceFlags f
|
|||||||
key = name + QString::number(interfaceIndex);
|
key = name + QString::number(interfaceIndex);
|
||||||
if (flags & kDNSServiceFlagsAdd) {
|
if (flags & kDNSServiceFlagsAdd) {
|
||||||
if (!ref->pub->services.contains(key)) {
|
if (!ref->pub->services.contains(key)) {
|
||||||
zcs = new QZeroConfService;
|
zcs.setName(name);
|
||||||
zcs->name = name;
|
zcs.setType(type);
|
||||||
zcs->type = type;
|
zcs.setDomain(domain);
|
||||||
zcs->domain = domain;
|
zcs.setInterfaceIndex(interfaceIndex);
|
||||||
zcs->interfaceIndex = interfaceIndex;
|
if (!ref->newService.isValid()) {
|
||||||
if (!ref->newService) {
|
|
||||||
ref->newService = zcs;
|
ref->newService = zcs;
|
||||||
ref->resolve();
|
ref->resolve();
|
||||||
}
|
}
|
||||||
@@ -128,7 +126,6 @@ void DNSSD_API QZeroConfPrivate::browseCallback(DNSServiceRef, DNSServiceFlags f
|
|||||||
zcs = ref->pub->services[key];
|
zcs = ref->pub->services[key];
|
||||||
ref->pub->services.remove(key);
|
ref->pub->services.remove(key);
|
||||||
emit ref->pub->serviceRemoved(zcs);
|
emit ref->pub->serviceRemoved(zcs);
|
||||||
delete zcs;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@@ -157,15 +154,15 @@ void DNSSD_API QZeroConfPrivate::resolverCallback(DNSServiceRef, DNSServiceFlags
|
|||||||
QByteArray avahiText((const char *)txtRecord, recLen);
|
QByteArray avahiText((const char *)txtRecord, recLen);
|
||||||
QList<QByteArray> pair = avahiText.split('=');
|
QList<QByteArray> pair = avahiText.split('=');
|
||||||
if (pair.size() == 2)
|
if (pair.size() == 2)
|
||||||
ref->newService->txt[pair.at(0)] = pair.at(1);
|
ref->newService.appendTxt(pair.at(0), pair.at(1));
|
||||||
else
|
else
|
||||||
ref->newService->txt[pair.at(0)] = "";
|
ref->newService.appendTxt(pair.at(0));
|
||||||
|
|
||||||
txtLen-= recLen + 1;
|
txtLen-= recLen + 1;
|
||||||
txtRecord+= recLen;
|
txtRecord+= recLen;
|
||||||
}
|
}
|
||||||
ref->newService->host = hostName;
|
ref->newService.setHost(hostName);
|
||||||
ref->newService->port = qFromBigEndian<quint16>(port);
|
ref->newService.setPort(qFromBigEndian<quint16>(port));
|
||||||
err = DNSServiceGetAddrInfo(&ref->resolver, kDNSServiceFlagsForceMulticast, interfaceIndex, ref->protocol, hostName, (DNSServiceGetAddrInfoReply) addressReply, ref);
|
err = DNSServiceGetAddrInfo(&ref->resolver, kDNSServiceFlagsForceMulticast, interfaceIndex, ref->protocol, hostName, (DNSServiceGetAddrInfoReply) addressReply, ref);
|
||||||
if (err == kDNSServiceErr_NoError) {
|
if (err == kDNSServiceErr_NoError) {
|
||||||
int sockfd = DNSServiceRefSockFD(ref->resolver);
|
int sockfd = DNSServiceRefSockFD(ref->resolver);
|
||||||
@@ -198,11 +195,11 @@ void DNSSD_API QZeroConfPrivate::addressReply(DNSServiceRef sdRef,
|
|||||||
if ((flags & kDNSServiceFlagsAdd) != 0) {
|
if ((flags & kDNSServiceFlagsAdd) != 0) {
|
||||||
QHostAddress hAddress(address);
|
QHostAddress hAddress(address);
|
||||||
if (hAddress.protocol() == QAbstractSocket::IPv6Protocol)
|
if (hAddress.protocol() == QAbstractSocket::IPv6Protocol)
|
||||||
ref->newService->ipv6 = hAddress;
|
ref->newService.setIpv6(hAddress);
|
||||||
else
|
else
|
||||||
ref->newService->ip = hAddress;
|
ref->newService.setIp(hAddress);
|
||||||
|
|
||||||
QString key = ref->newService->name + QString::number(interfaceIndex);
|
QString key = ref->newService.name() + QString::number(interfaceIndex);
|
||||||
if (!ref->pub->services.contains(key)) {
|
if (!ref->pub->services.contains(key)) {
|
||||||
ref->pub->services.insert(key, ref->newService);
|
ref->pub->services.insert(key, ref->newService);
|
||||||
emit ref->pub->serviceAdded(ref->newService);
|
emit ref->pub->serviceAdded(ref->newService);
|
||||||
@@ -212,7 +209,7 @@ void DNSSD_API QZeroConfPrivate::addressReply(DNSServiceRef sdRef,
|
|||||||
|
|
||||||
}
|
}
|
||||||
if (!(flags & kDNSServiceFlagsMoreComing)) {
|
if (!(flags & kDNSServiceFlagsMoreComing)) {
|
||||||
ref->newService = NULL; // newService resolve succeeded so don't let cleanUp delete it!
|
ref->newService = QZeroConfService(); // newService resolve succeeded so don't let cleanUp delete it!
|
||||||
ref->cleanUp(ref->resolver);
|
ref->cleanUp(ref->resolver);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -233,10 +230,6 @@ void QZeroConfPrivate::cleanUp(DNSServiceRef toClean)
|
|||||||
delete resolverSocket;
|
delete resolverSocket;
|
||||||
resolverSocket = NULL;
|
resolverSocket = NULL;
|
||||||
}
|
}
|
||||||
if (newService) {
|
|
||||||
delete newService;
|
|
||||||
newService = NULL;
|
|
||||||
}
|
|
||||||
if (work.size()) {
|
if (work.size()) {
|
||||||
newService = work.first();
|
newService = work.first();
|
||||||
work.removeFirst();
|
work.removeFirst();
|
||||||
@@ -249,10 +242,9 @@ void QZeroConfPrivate::cleanUp(DNSServiceRef toClean)
|
|||||||
delete browserSocket;
|
delete browserSocket;
|
||||||
browserSocket = NULL;
|
browserSocket = NULL;
|
||||||
}
|
}
|
||||||
QMap<QString, QZeroConfService *>::iterator i;
|
QMap<QString, QZeroConfService >::iterator i;
|
||||||
for (i = pub->services.begin(); i != pub->services.end(); i++) {
|
for (i = pub->services.begin(); i != pub->services.end(); i++) {
|
||||||
emit pub->serviceRemoved(*i);
|
emit pub->serviceRemoved(*i);
|
||||||
delete *i;
|
|
||||||
}
|
}
|
||||||
pub->services.clear();
|
pub->services.clear();
|
||||||
}
|
}
|
||||||
|
@@ -64,8 +64,8 @@ public:
|
|||||||
DNSServiceRef dnssRef, browser, resolver;
|
DNSServiceRef dnssRef, browser, resolver;
|
||||||
DNSServiceProtocol protocol;
|
DNSServiceProtocol protocol;
|
||||||
QSocketNotifier *bs, *browserSocket, *resolverSocket, *addressSocket;
|
QSocketNotifier *bs, *browserSocket, *resolverSocket, *addressSocket;
|
||||||
QZeroConfService *newService;
|
QZeroConfService newService;
|
||||||
QList<QZeroConfService *> work;
|
QList<QZeroConfService> work;
|
||||||
QByteArray txt;
|
QByteArray txt;
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
@@ -53,8 +53,8 @@ mainWindow::mainWindow()
|
|||||||
publishEnabled = 0;
|
publishEnabled = 0;
|
||||||
buildGUI();
|
buildGUI();
|
||||||
|
|
||||||
connect(&zeroConf, SIGNAL(serviceAdded(QZeroConfService *)), this, SLOT(addService(QZeroConfService *)));
|
connect(&zeroConf, &QZeroConf::serviceAdded, this, &mainWindow::addService);
|
||||||
connect(&zeroConf, SIGNAL(serviceRemoved(QZeroConfService *)), this, SLOT(removeService(QZeroConfService *)));
|
connect(&zeroConf, &QZeroConf::serviceRemoved, this, &mainWindow::removeService);
|
||||||
connect(qGuiApp, SIGNAL(applicationStateChanged(Qt::ApplicationState)), this, SLOT(appStateChanged(Qt::ApplicationState)));
|
connect(qGuiApp, SIGNAL(applicationStateChanged(Qt::ApplicationState)), this, SLOT(appStateChanged(Qt::ApplicationState)));
|
||||||
|
|
||||||
publishEnabled = 1;
|
publishEnabled = 1;
|
||||||
@@ -145,16 +145,16 @@ void mainWindow::stopPublishClicked()
|
|||||||
|
|
||||||
// ---------- Discovery Callbacks ----------
|
// ---------- Discovery Callbacks ----------
|
||||||
|
|
||||||
void mainWindow::addService(QZeroConfService *zcs)
|
void mainWindow::addService(QZeroConfService zcs)
|
||||||
{
|
{
|
||||||
qint32 row;
|
qint32 row;
|
||||||
QTableWidgetItem *cell;
|
QTableWidgetItem *cell;
|
||||||
|
|
||||||
row = table.rowCount();
|
row = table.rowCount();
|
||||||
table.insertRow(row);
|
table.insertRow(row);
|
||||||
cell = new QTableWidgetItem(zcs->name);
|
cell = new QTableWidgetItem(zcs.name());
|
||||||
table.setItem(row, 0, cell);
|
table.setItem(row, 0, cell);
|
||||||
cell = new QTableWidgetItem(zcs->ip.toString());
|
cell = new QTableWidgetItem(zcs.ip().toString());
|
||||||
table.setItem(row, 1, cell);
|
table.setItem(row, 1, cell);
|
||||||
table.resizeColumnsToContents();
|
table.resizeColumnsToContents();
|
||||||
#if !(defined(Q_OS_IOS) || defined(Q_OS_ANDROID))
|
#if !(defined(Q_OS_IOS) || defined(Q_OS_ANDROID))
|
||||||
@@ -162,17 +162,17 @@ void mainWindow::addService(QZeroConfService *zcs)
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void mainWindow::removeService(QZeroConfService *zcs)
|
void mainWindow::removeService(QZeroConfService zcs)
|
||||||
{
|
{
|
||||||
qint32 i, row;
|
qint32 i, row;
|
||||||
QTableWidgetItem *nameItem, *ipItem;
|
QTableWidgetItem *nameItem, *ipItem;
|
||||||
|
|
||||||
QList <QTableWidgetItem*> search = table.findItems(zcs->name, Qt::MatchExactly);
|
QList <QTableWidgetItem*> search = table.findItems(zcs.name(), Qt::MatchExactly);
|
||||||
for (i=0; i<search.size(); i++) {
|
for (i=0; i<search.size(); i++) {
|
||||||
nameItem = search.at(i);
|
nameItem = search.at(i);
|
||||||
row = nameItem->row();
|
row = nameItem->row();
|
||||||
ipItem = table.item(row, 1);
|
ipItem = table.item(row, 1);
|
||||||
if (table.item(row, 1)->text() == zcs->ip.toString()) { // match ip address in case of dual homed systems
|
if (table.item(row, 1)->text() == zcs.ip().toString()) { // match ip address in case of dual homed systems
|
||||||
delete nameItem;
|
delete nameItem;
|
||||||
delete ipItem;
|
delete ipItem;
|
||||||
table.removeRow(row);
|
table.removeRow(row);
|
||||||
|
@@ -50,8 +50,8 @@ private slots:
|
|||||||
void appStateChanged(Qt::ApplicationState state);
|
void appStateChanged(Qt::ApplicationState state);
|
||||||
void startPublishClicked();
|
void startPublishClicked();
|
||||||
void stopPublishClicked();
|
void stopPublishClicked();
|
||||||
void addService(QZeroConfService *item);
|
void addService(QZeroConfService item);
|
||||||
void removeService(QZeroConfService *item);
|
void removeService(QZeroConfService item);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* WINDOW_H_ */
|
#endif /* WINDOW_H_ */
|
||||||
|
@@ -115,3 +115,9 @@ android {
|
|||||||
SOURCES+= $$ACR/wide-area.c
|
SOURCES+= $$ACR/wide-area.c
|
||||||
#avahi-core/iface-none.c avahi-core/iface-pfroute.c avahi-core/avahi-reflector.c
|
#avahi-core/iface-none.c avahi-core/iface-pfroute.c avahi-core/avahi-reflector.c
|
||||||
}
|
}
|
||||||
|
|
||||||
|
HEADERS += \
|
||||||
|
$$PWD/qzeroconfservice.h
|
||||||
|
|
||||||
|
SOURCES += \
|
||||||
|
$$PWD/qzeroconfservice.cpp
|
||||||
|
22
qzeroconf.h
22
qzeroconf.h
@@ -31,6 +31,7 @@
|
|||||||
#include <QHostAddress>
|
#include <QHostAddress>
|
||||||
#include <QMap>
|
#include <QMap>
|
||||||
#include <QtCore/QtGlobal>
|
#include <QtCore/QtGlobal>
|
||||||
|
#include "qzeroconfservice.h"
|
||||||
|
|
||||||
#if (!defined(QT_STATIC) && !defined(QZEROCONF_STATIC))
|
#if (!defined(QT_STATIC) && !defined(QZEROCONF_STATIC))
|
||||||
# ifdef QT_BUILD_ZEROCONF_LIB
|
# ifdef QT_BUILD_ZEROCONF_LIB
|
||||||
@@ -42,19 +43,6 @@
|
|||||||
# define Q_ZEROCONF_EXPORT
|
# define Q_ZEROCONF_EXPORT
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
struct QZeroConfService
|
|
||||||
{
|
|
||||||
QString name;
|
|
||||||
QString type;
|
|
||||||
QString domain;
|
|
||||||
QString host;
|
|
||||||
QHostAddress ip;
|
|
||||||
QHostAddress ipv6;
|
|
||||||
quint32 interfaceIndex;
|
|
||||||
quint16 port;
|
|
||||||
QMap <QByteArray, QByteArray> txt;
|
|
||||||
};
|
|
||||||
|
|
||||||
class QZeroConfPrivate;
|
class QZeroConfPrivate;
|
||||||
|
|
||||||
class Q_ZEROCONF_EXPORT QZeroConf : public QObject
|
class Q_ZEROCONF_EXPORT QZeroConf : public QObject
|
||||||
@@ -89,13 +77,13 @@ public:
|
|||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
void servicePublished(void);
|
void servicePublished(void);
|
||||||
void error(QZeroConf::error_t);
|
void error(QZeroConf::error_t);
|
||||||
void serviceAdded(QZeroConfService *);
|
void serviceAdded(QZeroConfService);
|
||||||
void serviceUpdated(QZeroConfService *);
|
void serviceUpdated(QZeroConfService);
|
||||||
void serviceRemoved(QZeroConfService *);
|
void serviceRemoved(QZeroConfService);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QZeroConfPrivate *pri;
|
QZeroConfPrivate *pri;
|
||||||
QMap<QString, QZeroConfService *> services;
|
QMap<QString, QZeroConfService> services;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
145
qzeroconfservice.cpp
Normal file
145
qzeroconfservice.cpp
Normal file
@@ -0,0 +1,145 @@
|
|||||||
|
#include "qzeroconfservice.h"
|
||||||
|
|
||||||
|
|
||||||
|
class QZeroConfServiceData : public QSharedData
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
QString name;
|
||||||
|
QString type;
|
||||||
|
QString domain;
|
||||||
|
QString host;
|
||||||
|
QHostAddress ip;
|
||||||
|
QHostAddress ipv6;
|
||||||
|
quint32 interfaceIndex;
|
||||||
|
quint16 port = 0;
|
||||||
|
QMap <QByteArray, QByteArray> txt;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
QZeroConfService::QZeroConfService() : data(new QZeroConfServiceData)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
QZeroConfService::QZeroConfService(const QZeroConfService &rhs) : data(rhs.data)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
QZeroConfService &QZeroConfService::operator=(const QZeroConfService &rhs)
|
||||||
|
{
|
||||||
|
if (this != &rhs)
|
||||||
|
data.operator=(rhs.data);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
QZeroConfService::~QZeroConfService()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
QString QZeroConfService::name() const
|
||||||
|
{
|
||||||
|
return data->name;
|
||||||
|
}
|
||||||
|
|
||||||
|
void QZeroConfService::setName(const QString &name)
|
||||||
|
{
|
||||||
|
data->name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString QZeroConfService::type() const
|
||||||
|
{
|
||||||
|
return data->type;
|
||||||
|
}
|
||||||
|
|
||||||
|
void QZeroConfService::setType(const QString &type)
|
||||||
|
{
|
||||||
|
data->type = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString QZeroConfService::domain() const
|
||||||
|
{
|
||||||
|
return data->domain;
|
||||||
|
}
|
||||||
|
|
||||||
|
void QZeroConfService::setDomain(const QString &domain)
|
||||||
|
{
|
||||||
|
data->domain = domain;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString QZeroConfService::host() const
|
||||||
|
{
|
||||||
|
return data->host;
|
||||||
|
}
|
||||||
|
|
||||||
|
void QZeroConfService::setHost(const QString &host)
|
||||||
|
{
|
||||||
|
data->host = host;
|
||||||
|
}
|
||||||
|
|
||||||
|
QHostAddress QZeroConfService::ip() const
|
||||||
|
{
|
||||||
|
return data->ip;
|
||||||
|
}
|
||||||
|
|
||||||
|
void QZeroConfService::setIp(QHostAddress &ip)
|
||||||
|
{
|
||||||
|
data->ip = ip;
|
||||||
|
}
|
||||||
|
|
||||||
|
QHostAddress QZeroConfService::ipv6() const
|
||||||
|
{
|
||||||
|
return data->ipv6;
|
||||||
|
}
|
||||||
|
|
||||||
|
void QZeroConfService::setIpv6(const QHostAddress &ipv6)
|
||||||
|
{
|
||||||
|
data->ipv6 = ipv6;
|
||||||
|
}
|
||||||
|
|
||||||
|
quint32 QZeroConfService::interfaceIndex() const
|
||||||
|
{
|
||||||
|
return data->interfaceIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
void QZeroConfService::setInterfaceIndex(const quint32 &interfaceIndex)
|
||||||
|
{
|
||||||
|
data->interfaceIndex = interfaceIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
quint16 QZeroConfService::port() const
|
||||||
|
{
|
||||||
|
return data->port;
|
||||||
|
}
|
||||||
|
|
||||||
|
void QZeroConfService::setPort(const quint16 port)
|
||||||
|
{
|
||||||
|
data->port = port;
|
||||||
|
}
|
||||||
|
|
||||||
|
QMap<QByteArray, QByteArray> QZeroConfService::txt() const
|
||||||
|
{
|
||||||
|
return data->txt;
|
||||||
|
}
|
||||||
|
|
||||||
|
void QZeroConfService::setTxt(const QMap<QByteArray, QByteArray> txt)
|
||||||
|
{
|
||||||
|
data->txt = txt;
|
||||||
|
}
|
||||||
|
|
||||||
|
void QZeroConfService::appendTxt(QByteArray idx, QByteArray val)
|
||||||
|
{
|
||||||
|
data->txt[idx] = val;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool QZeroConfService::isValid() const
|
||||||
|
{
|
||||||
|
|
||||||
|
return (!data->name.isEmpty());
|
||||||
|
}
|
||||||
|
|
||||||
|
bool QZeroConfService::operator==(const QZeroConfService &rhs) const
|
||||||
|
{
|
||||||
|
return this->name() == rhs.name() && (this->ip() == rhs.ip() || this->ipv6() == rhs.ipv6());
|
||||||
|
}
|
54
qzeroconfservice.h
Normal file
54
qzeroconfservice.h
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
#ifndef QZEROCONFSERVICE_H
|
||||||
|
#define QZEROCONFSERVICE_H
|
||||||
|
|
||||||
|
#include <QSharedDataPointer>
|
||||||
|
#include <QHostAddress>
|
||||||
|
|
||||||
|
class QZeroConfServiceData;
|
||||||
|
|
||||||
|
class QZeroConfService
|
||||||
|
{
|
||||||
|
Q_GADGET
|
||||||
|
Q_PROPERTY( QString name READ name )
|
||||||
|
Q_PROPERTY( QString type READ type )
|
||||||
|
Q_PROPERTY( QString domain READ domain )
|
||||||
|
Q_PROPERTY( QString host READ host )
|
||||||
|
|
||||||
|
public:
|
||||||
|
|
||||||
|
QZeroConfService();
|
||||||
|
QZeroConfService(const QZeroConfService &);
|
||||||
|
QZeroConfService &operator=(const QZeroConfService &);
|
||||||
|
~QZeroConfService();
|
||||||
|
|
||||||
|
|
||||||
|
QString name() const;
|
||||||
|
void setName(const QString &name);
|
||||||
|
QString type() const;
|
||||||
|
void setType(const QString &type);
|
||||||
|
QString domain() const;
|
||||||
|
void setDomain(const QString &domain);
|
||||||
|
QString host() const;
|
||||||
|
void setHost(const QString &host);
|
||||||
|
QHostAddress ip() const;
|
||||||
|
void setIp(QHostAddress &ip);
|
||||||
|
QHostAddress ipv6() const;
|
||||||
|
void setIpv6(const QHostAddress &ipv6);
|
||||||
|
quint32 interfaceIndex() const;
|
||||||
|
void setInterfaceIndex(const quint32 &interfaceIndex);
|
||||||
|
quint16 port() const;
|
||||||
|
void setPort(const quint16 port);
|
||||||
|
QMap <QByteArray, QByteArray> txt() const;
|
||||||
|
void setTxt(const QMap<QByteArray, QByteArray> txt);
|
||||||
|
void appendTxt(QByteArray idx, QByteArray val = "");
|
||||||
|
|
||||||
|
bool isValid() const;
|
||||||
|
bool operator==(const QZeroConfService &rhs) const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
QSharedDataPointer<QZeroConfServiceData> data;
|
||||||
|
};
|
||||||
|
|
||||||
|
Q_DECLARE_METATYPE(QZeroConfService)
|
||||||
|
|
||||||
|
#endif // QZEROCONFSERVICE_H
|
Reference in New Issue
Block a user