forked from jbagg/QtZeroConf
spaces to tabs
This commit is contained in:
@ -16,12 +16,12 @@
|
|||||||
You should have received a copy of the GNU Lesser General Public License
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
along with QtZeroConf. If not, see <http://www.gnu.org/licenses/>.
|
along with QtZeroConf. If not, see <http://www.gnu.org/licenses/>.
|
||||||
---------------------------------------------------------------------------------------------------
|
---------------------------------------------------------------------------------------------------
|
||||||
Project name : QtZeroConf
|
Project name : QtZeroConf
|
||||||
File name : avahiclient.cpp
|
File name : avahiclient.cpp
|
||||||
Created : 20 July 2015
|
Created : 20 July 2015
|
||||||
Author(s) : Jonathan Bagg
|
Author(s) : Jonathan Bagg
|
||||||
---------------------------------------------------------------------------------------------------
|
---------------------------------------------------------------------------------------------------
|
||||||
Avahi-client wrapper for use in Desktop Linux systems
|
Avahi-client wrapper for use in Desktop Linux systems
|
||||||
---------------------------------------------------------------------------------------------------
|
---------------------------------------------------------------------------------------------------
|
||||||
**************************************************************************************************/
|
**************************************************************************************************/
|
||||||
//#include <avahi-qt4/qt-watch.h> //
|
//#include <avahi-qt4/qt-watch.h> //
|
||||||
@ -105,7 +105,7 @@ 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;
|
QZeroConfService zcs;
|
||||||
|
|
||||||
switch (event) {
|
switch (event) {
|
||||||
case AVAHI_BROWSER_FAILURE:
|
case AVAHI_BROWSER_FAILURE:
|
||||||
@ -129,29 +129,29 @@ public:
|
|||||||
ref->pub->services.remove(key);
|
ref->pub->services.remove(key);
|
||||||
emit ref->pub->serviceRemoved(zcs);
|
emit ref->pub->serviceRemoved(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:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void resolveCallback(
|
static void resolveCallback(
|
||||||
AVAHI_GCC_UNUSED AvahiServiceResolver *r,
|
AVAHI_GCC_UNUSED AvahiServiceResolver *r,
|
||||||
AVAHI_GCC_UNUSED AvahiIfIndex interface,
|
AVAHI_GCC_UNUSED AvahiIfIndex interface,
|
||||||
AVAHI_GCC_UNUSED AvahiProtocol protocol,
|
AVAHI_GCC_UNUSED AvahiProtocol protocol,
|
||||||
AvahiResolverEvent event,
|
AvahiResolverEvent event,
|
||||||
const char *name,
|
const char *name,
|
||||||
const char *type,
|
const char *type,
|
||||||
const char *domain,
|
const char *domain,
|
||||||
const char *host_name,
|
const char *host_name,
|
||||||
const AvahiAddress *address,
|
const AvahiAddress *address,
|
||||||
uint16_t port,
|
uint16_t port,
|
||||||
AvahiStringList *txt,
|
AvahiStringList *txt,
|
||||||
AvahiLookupResultFlags,
|
AvahiLookupResultFlags,
|
||||||
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 +159,21 @@ public:
|
|||||||
if (ref->pub->services.contains(key))
|
if (ref->pub->services.contains(key))
|
||||||
zcs = ref->pub->services[key];
|
zcs = ref->pub->services[key];
|
||||||
else {
|
else {
|
||||||
newRecord = 1;
|
newRecord = 1;
|
||||||
zcs.setName(name);
|
zcs.setName(name);
|
||||||
zcs.setType(type);
|
zcs.setType(type);
|
||||||
zcs.setDomain( domain);
|
zcs.setDomain( domain);
|
||||||
zcs.setHost( host_name);
|
zcs.setHost( host_name);
|
||||||
zcs.setInterfaceIndex(interface);
|
zcs.setInterfaceIndex(interface);
|
||||||
zcs.setPort(port);
|
zcs.setPort(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.appendTxt(pair.at(0), pair.at(1));
|
zcs.appendTxt(pair.at(0), pair.at(1));
|
||||||
else
|
else
|
||||||
zcs.appendTxt(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,11 +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);
|
QHostAddress addr(a);
|
||||||
if (protocol == AVAHI_PROTO_INET6)
|
if (protocol == AVAHI_PROTO_INET6)
|
||||||
zcs.setIpv6(addr);
|
zcs.setIpv6(addr);
|
||||||
else if (protocol == AVAHI_PROTO_INET)
|
else if (protocol == AVAHI_PROTO_INET)
|
||||||
zcs.setIp(addr);
|
zcs.setIp(addr);
|
||||||
|
|
||||||
if (newRecord)
|
if (newRecord)
|
||||||
emit ref->pub->serviceAdded(zcs);
|
emit ref->pub->serviceAdded(zcs);
|
||||||
@ -196,7 +196,7 @@ 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);
|
||||||
// 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,9 +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.value());
|
emit pub->serviceRemoved(i.value());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -217,7 +217,7 @@ public:
|
|||||||
|
|
||||||
QMap<QString, AvahiServiceResolver *>::iterator r;
|
QMap<QString, AvahiServiceResolver *>::iterator r;
|
||||||
for (r = resolvers.begin(); r != resolvers.end(); r++)
|
for (r = resolvers.begin(); r != resolvers.end(); r++)
|
||||||
avahi_service_resolver_free(*r);
|
avahi_service_resolver_free(*r);
|
||||||
resolvers.clear();
|
resolvers.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -303,7 +303,7 @@ void QZeroConf::clearServiceTxtRecords()
|
|||||||
|
|
||||||
void QZeroConf::startBrowser(QString type, QAbstractSocket::NetworkLayerProtocol protocol)
|
void QZeroConf::startBrowser(QString type, QAbstractSocket::NetworkLayerProtocol protocol)
|
||||||
{
|
{
|
||||||
AvahiProtocol avahiProtocol;
|
AvahiProtocol avahiProtocol;
|
||||||
|
|
||||||
if (pri->browser)
|
if (pri->browser)
|
||||||
emit error(QZeroConf::browserFailed);
|
emit error(QZeroConf::browserFailed);
|
||||||
|
@ -16,12 +16,12 @@
|
|||||||
You should have received a copy of the GNU Lesser General Public License
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
along with QtZeroConf. If not, see <http://www.gnu.org/licenses/>.
|
along with QtZeroConf. If not, see <http://www.gnu.org/licenses/>.
|
||||||
---------------------------------------------------------------------------------------------------
|
---------------------------------------------------------------------------------------------------
|
||||||
Project name : QtZeroConf
|
Project name : QtZeroConf
|
||||||
File name : avahicore.cpp
|
File name : avahicore.cpp
|
||||||
Created : 9 September 2015
|
Created : 9 September 2015
|
||||||
Author(s) : Jonathan Bagg
|
Author(s) : Jonathan Bagg
|
||||||
---------------------------------------------------------------------------------------------------
|
---------------------------------------------------------------------------------------------------
|
||||||
Avahi-core wrapper for use in embedded Linux systems (Android)
|
Avahi-core wrapper for use in embedded Linux systems (Android)
|
||||||
---------------------------------------------------------------------------------------------------
|
---------------------------------------------------------------------------------------------------
|
||||||
**************************************************************************************************/
|
**************************************************************************************************/
|
||||||
//#include <avahi-qt4/qt-watch.h> //
|
//#include <avahi-qt4/qt-watch.h> //
|
||||||
@ -67,9 +67,9 @@ public:
|
|||||||
switch (state) {
|
switch (state) {
|
||||||
case AVAHI_SERVER_RUNNING:
|
case AVAHI_SERVER_RUNNING:
|
||||||
ref->ready = 1;
|
ref->ready = 1;
|
||||||
if (ref->registerWaiting) {
|
if (ref->registerWaiting) {
|
||||||
ref->registerWaiting = 0;
|
ref->registerWaiting = 0;
|
||||||
ref->registerService(ref->name.toUtf8(), ref->type.toUtf8(), ref->domain.toUtf8(), ref->port);
|
ref->registerService(ref->name.toUtf8(), ref->type.toUtf8(), ref->domain.toUtf8(), ref->port);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case AVAHI_SERVER_COLLISION:
|
case AVAHI_SERVER_COLLISION:
|
||||||
@ -147,19 +147,19 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void resolveCallback(
|
static void resolveCallback(
|
||||||
AVAHI_GCC_UNUSED AvahiSServiceResolver *r,
|
AVAHI_GCC_UNUSED AvahiSServiceResolver *r,
|
||||||
AVAHI_GCC_UNUSED AvahiIfIndex interface,
|
AVAHI_GCC_UNUSED AvahiIfIndex interface,
|
||||||
AVAHI_GCC_UNUSED AvahiProtocol protocol,
|
AVAHI_GCC_UNUSED AvahiProtocol protocol,
|
||||||
AvahiResolverEvent event,
|
AvahiResolverEvent event,
|
||||||
const char *name,
|
const char *name,
|
||||||
const char *type,
|
const char *type,
|
||||||
const char *domain,
|
const char *domain,
|
||||||
const char *host_name,
|
const char *host_name,
|
||||||
const AvahiAddress *address,
|
const AvahiAddress *address,
|
||||||
uint16_t port,
|
uint16_t port,
|
||||||
AvahiStringList *txt,
|
AvahiStringList *txt,
|
||||||
AvahiLookupResultFlags,
|
AvahiLookupResultFlags,
|
||||||
AVAHI_GCC_UNUSED void* userdata)
|
AVAHI_GCC_UNUSED void* userdata)
|
||||||
{
|
{
|
||||||
bool newRecord = 0;
|
bool newRecord = 0;
|
||||||
QZeroConfService *zcs;
|
QZeroConfService *zcs;
|
||||||
|
44
bonjour.cpp
44
bonjour.cpp
@ -16,12 +16,12 @@
|
|||||||
You should have received a copy of the GNU Lesser General Public License
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
along with QtZeroConf. If not, see <http://www.gnu.org/licenses/>.
|
along with QtZeroConf. If not, see <http://www.gnu.org/licenses/>.
|
||||||
---------------------------------------------------------------------------------------------------
|
---------------------------------------------------------------------------------------------------
|
||||||
Project name : QtZeroConf
|
Project name : QtZeroConf
|
||||||
File name : bonjour.cpp
|
File name : bonjour.cpp
|
||||||
Created : 20 July 2015
|
Created : 20 July 2015
|
||||||
Author(s) : Jonathan Bagg
|
Author(s) : Jonathan Bagg
|
||||||
---------------------------------------------------------------------------------------------------
|
---------------------------------------------------------------------------------------------------
|
||||||
Wrapper for Apple's Bonjour library for use on Windows, MACs and iOS
|
Wrapper for Apple's Bonjour library for use on Windows, MACs and iOS
|
||||||
---------------------------------------------------------------------------------------------------
|
---------------------------------------------------------------------------------------------------
|
||||||
**************************************************************************************************/
|
**************************************************************************************************/
|
||||||
#include "qzeroconf.h"
|
#include "qzeroconf.h"
|
||||||
@ -69,7 +69,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 +103,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 +111,12 @@ 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 = new QZeroConfService;
|
||||||
zcs.setName(name);
|
zcs.setName(name);
|
||||||
zcs.setType( type);
|
zcs.setType( type);
|
||||||
zcs.setDomain(domain);
|
zcs.setDomain(domain);
|
||||||
zcs.setInterfaceIndex(interfaceIndex);
|
zcs.setInterfaceIndex(interfaceIndex);
|
||||||
if (!ref->newService.isValid()) {
|
if (!ref->newService.isValid()) {
|
||||||
ref->newService = zcs;
|
ref->newService = zcs;
|
||||||
ref->resolve();
|
ref->resolve();
|
||||||
}
|
}
|
||||||
@ -157,15 +157,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.appendTxt(pair.at(0), pair.at(1));
|
ref->newService.appendTxt(pair.at(0), pair.at(1));
|
||||||
else
|
else
|
||||||
ref->newService.appendTxt(pair.at(0));
|
ref->newService.appendTxt(pair.at(0));
|
||||||
|
|
||||||
txtLen-= recLen + 1;
|
txtLen-= recLen + 1;
|
||||||
txtRecord+= recLen;
|
txtRecord+= recLen;
|
||||||
}
|
}
|
||||||
ref->newService.setHost(hostName);
|
ref->newService.setHost(hostName);
|
||||||
ref->newService.setPort(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 +198,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.setIpv6(hAddress);
|
ref->newService.setIpv6(hAddress);
|
||||||
else
|
else
|
||||||
ref->newService.setIp(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 +212,7 @@ void DNSSD_API QZeroConfPrivate::addressReply(DNSServiceRef sdRef,
|
|||||||
|
|
||||||
}
|
}
|
||||||
if (!(flags & kDNSServiceFlagsMoreComing)) {
|
if (!(flags & kDNSServiceFlagsMoreComing)) {
|
||||||
ref->newService = QZeroConfService(); // 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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -246,7 +246,7 @@ void QZeroConfPrivate::cleanUp(DNSServiceRef toClean)
|
|||||||
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);
|
||||||
}
|
}
|
||||||
|
14
bonjour_p.h
14
bonjour_p.h
@ -16,12 +16,12 @@
|
|||||||
You should have received a copy of the GNU Lesser General Public License
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
along with QtZeroConf. If not, see <http://www.gnu.org/licenses/>.
|
along with QtZeroConf. If not, see <http://www.gnu.org/licenses/>.
|
||||||
---------------------------------------------------------------------------------------------------
|
---------------------------------------------------------------------------------------------------
|
||||||
Project name : QtZeroConf
|
Project name : QtZeroConf
|
||||||
File name : bonjour_p.h
|
File name : bonjour_p.h
|
||||||
Created : 22 July 2015
|
Created : 22 July 2015
|
||||||
Author(s) : Jonathan Bagg
|
Author(s) : Jonathan Bagg
|
||||||
---------------------------------------------------------------------------------------------------
|
---------------------------------------------------------------------------------------------------
|
||||||
Part of wrapper for Apple's Bonjour library for use on Windows, MACs and iOS. Needed for slots.
|
Part of wrapper for Apple's Bonjour library for use on Windows, MACs and iOS. Needed for slots.
|
||||||
---------------------------------------------------------------------------------------------------
|
---------------------------------------------------------------------------------------------------
|
||||||
**************************************************************************************************/
|
**************************************************************************************************/
|
||||||
#ifndef QZEROCONFPRIVATE_H_
|
#ifndef QZEROCONFPRIVATE_H_
|
||||||
@ -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:
|
||||||
|
@ -16,12 +16,12 @@
|
|||||||
You should have received a copy of the GNU Lesser General Public License
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
along with QtZeroConf. If not, see <http://www.gnu.org/licenses/>.
|
along with QtZeroConf. If not, see <http://www.gnu.org/licenses/>.
|
||||||
---------------------------------------------------------------------------------------------------
|
---------------------------------------------------------------------------------------------------
|
||||||
Project name : QtZeroConf Example
|
Project name : QtZeroConf Example
|
||||||
File name : main.cpp
|
File name : main.cpp
|
||||||
Created : 3 November 2015
|
Created : 3 November 2015
|
||||||
Author(s) : Jonathan Bagg
|
Author(s) : Jonathan Bagg
|
||||||
---------------------------------------------------------------------------------------------------
|
---------------------------------------------------------------------------------------------------
|
||||||
Example app to demonstrate service publishing and service discovery
|
Example app to demonstrate service publishing and service discovery
|
||||||
---------------------------------------------------------------------------------------------------
|
---------------------------------------------------------------------------------------------------
|
||||||
**************************************************************************************************/
|
**************************************************************************************************/
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
|
@ -16,12 +16,12 @@
|
|||||||
You should have received a copy of the GNU Lesser General Public License
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
along with QtZeroConf. If not, see <http://www.gnu.org/licenses/>.
|
along with QtZeroConf. If not, see <http://www.gnu.org/licenses/>.
|
||||||
---------------------------------------------------------------------------------------------------
|
---------------------------------------------------------------------------------------------------
|
||||||
Project name : QtZeroConf Example
|
Project name : QtZeroConf Example
|
||||||
File name : window.cpp
|
File name : window.cpp
|
||||||
Created : 3 November 2015
|
Created : 3 November 2015
|
||||||
Author(s) : Jonathan Bagg
|
Author(s) : Jonathan Bagg
|
||||||
---------------------------------------------------------------------------------------------------
|
---------------------------------------------------------------------------------------------------
|
||||||
Example app to demonstrate service publishing and service discovery
|
Example app to demonstrate service publishing and service discovery
|
||||||
---------------------------------------------------------------------------------------------------
|
---------------------------------------------------------------------------------------------------
|
||||||
**************************************************************************************************/
|
**************************************************************************************************/
|
||||||
#include <QGuiApplication>
|
#include <QGuiApplication>
|
||||||
@ -54,8 +54,8 @@ mainWindow::mainWindow()
|
|||||||
buildGUI();
|
buildGUI();
|
||||||
|
|
||||||
|
|
||||||
connect(&zeroConf, &QZeroConf::serviceAdded, this, &mainWindow::addService);
|
connect(&zeroConf, &QZeroConf::serviceAdded, this, &mainWindow::addService);
|
||||||
connect(&zeroConf, &QZeroConf::serviceRemoved, this, &mainWindow::removeService);
|
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;
|
||||||
@ -93,7 +93,7 @@ void mainWindow::buildGUI()
|
|||||||
|
|
||||||
QString mainWindow::buildName(void)
|
QString mainWindow::buildName(void)
|
||||||
{
|
{
|
||||||
QString name;
|
QString name;
|
||||||
|
|
||||||
QList<QNetworkInterface> list = QNetworkInterface::allInterfaces(); // now you have interfaces list
|
QList<QNetworkInterface> list = QNetworkInterface::allInterfaces(); // now you have interfaces list
|
||||||
|
|
||||||
@ -102,7 +102,7 @@ QString mainWindow::buildName(void)
|
|||||||
name.remove(0, 6);
|
name.remove(0, 6);
|
||||||
name+= ')';
|
name+= ')';
|
||||||
name.prepend("Qt ZeroConf Test - " OS_NAME " (");
|
name.prepend("Qt ZeroConf Test - " OS_NAME " (");
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
void mainWindow::appStateChanged(Qt::ApplicationState state)
|
void mainWindow::appStateChanged(Qt::ApplicationState state)
|
||||||
@ -154,9 +154,9 @@ void mainWindow::addService(QZeroConfService zcs)
|
|||||||
|
|
||||||
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))
|
||||||
@ -169,12 +169,12 @@ 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);
|
||||||
|
@ -16,12 +16,12 @@
|
|||||||
You should have received a copy of the GNU Lesser General Public License
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
along with QtZeroConf. If not, see <http://www.gnu.org/licenses/>.
|
along with QtZeroConf. If not, see <http://www.gnu.org/licenses/>.
|
||||||
---------------------------------------------------------------------------------------------------
|
---------------------------------------------------------------------------------------------------
|
||||||
Project name : QtZeroConf Example
|
Project name : QtZeroConf Example
|
||||||
File name : window.h
|
File name : window.h
|
||||||
Created : 3 November 2015
|
Created : 3 November 2015
|
||||||
Author(s) : Jonathan Bagg
|
Author(s) : Jonathan Bagg
|
||||||
---------------------------------------------------------------------------------------------------
|
---------------------------------------------------------------------------------------------------
|
||||||
Example app to demonstrate service publishing and service discovery
|
Example app to demonstrate service publishing and service discovery
|
||||||
---------------------------------------------------------------------------------------------------
|
---------------------------------------------------------------------------------------------------
|
||||||
**************************************************************************************************/
|
**************************************************************************************************/
|
||||||
#ifndef WINDOW_H_
|
#ifndef WINDOW_H_
|
||||||
@ -51,8 +51,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);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
20
qzeroconf.h
20
qzeroconf.h
@ -16,12 +16,12 @@
|
|||||||
You should have received a copy of the GNU Lesser General Public License
|
You should have received a copy of the GNU Lesser General Public License
|
||||||
along with QtZeroConf. If not, see <http://www.gnu.org/licenses/>.
|
along with QtZeroConf. If not, see <http://www.gnu.org/licenses/>.
|
||||||
---------------------------------------------------------------------------------------------------
|
---------------------------------------------------------------------------------------------------
|
||||||
Project name : QtZeroConf
|
Project name : QtZeroConf
|
||||||
File name : qzeroconf.h
|
File name : qzeroconf.h
|
||||||
Created : 20 July 2015
|
Created : 20 July 2015
|
||||||
Author(s) : Jonathan Bagg
|
Author(s) : Jonathan Bagg
|
||||||
---------------------------------------------------------------------------------------------------
|
---------------------------------------------------------------------------------------------------
|
||||||
QtZeroConf class definition
|
QtZeroConf class definition
|
||||||
---------------------------------------------------------------------------------------------------
|
---------------------------------------------------------------------------------------------------
|
||||||
**************************************************************************************************/
|
**************************************************************************************************/
|
||||||
#ifndef QZEROCONF_H_
|
#ifndef QZEROCONF_H_
|
||||||
@ -60,7 +60,7 @@ public:
|
|||||||
serviceNameCollision = -2,
|
serviceNameCollision = -2,
|
||||||
browserFailed = -3,
|
browserFailed = -3,
|
||||||
};
|
};
|
||||||
QZeroConf(QObject *parent = Q_NULLPTR);
|
QZeroConf(QObject *parent = Q_NULLPTR);
|
||||||
~QZeroConf();
|
~QZeroConf();
|
||||||
void startServicePublish(const char *name, const char *type, const char *domain, quint16 port);
|
void startServicePublish(const char *name, const char *type, const char *domain, quint16 port);
|
||||||
void stopServicePublish(void);
|
void stopServicePublish(void);
|
||||||
@ -79,13 +79,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;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -4,15 +4,15 @@
|
|||||||
class QZeroConfServiceData : public QSharedData
|
class QZeroConfServiceData : public QSharedData
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
QString name;
|
QString name;
|
||||||
QString type;
|
QString type;
|
||||||
QString domain;
|
QString domain;
|
||||||
QString host;
|
QString host;
|
||||||
QHostAddress ip;
|
QHostAddress ip;
|
||||||
QHostAddress ipv6;
|
QHostAddress ipv6;
|
||||||
quint32 interfaceIndex;
|
quint32 interfaceIndex;
|
||||||
quint16 port = 0;
|
quint16 port = 0;
|
||||||
QMap <QByteArray, QByteArray> txt;
|
QMap <QByteArray, QByteArray> txt;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -28,9 +28,9 @@ QZeroConfService::QZeroConfService(const QZeroConfService &rhs) : data(rhs.data)
|
|||||||
|
|
||||||
QZeroConfService &QZeroConfService::operator=(const QZeroConfService &rhs)
|
QZeroConfService &QZeroConfService::operator=(const QZeroConfService &rhs)
|
||||||
{
|
{
|
||||||
if (this != &rhs)
|
if (this != &rhs)
|
||||||
data.operator=(rhs.data);
|
data.operator=(rhs.data);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
QZeroConfService::~QZeroConfService()
|
QZeroConfService::~QZeroConfService()
|
||||||
@ -40,108 +40,106 @@ QZeroConfService::~QZeroConfService()
|
|||||||
|
|
||||||
QString QZeroConfService::name() const
|
QString QZeroConfService::name() const
|
||||||
{
|
{
|
||||||
return data->name;
|
return data->name;
|
||||||
}
|
}
|
||||||
|
|
||||||
void QZeroConfService::setName(const QString &name)
|
void QZeroConfService::setName(const QString &name)
|
||||||
{
|
{
|
||||||
data->name = name;
|
data->name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString QZeroConfService::type() const
|
QString QZeroConfService::type() const
|
||||||
{
|
{
|
||||||
return data->type;
|
return data->type;
|
||||||
}
|
}
|
||||||
|
|
||||||
void QZeroConfService::setType(const QString &type)
|
void QZeroConfService::setType(const QString &type)
|
||||||
{
|
{
|
||||||
data->type = type;
|
data->type = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString QZeroConfService::domain() const
|
QString QZeroConfService::domain() const
|
||||||
{
|
{
|
||||||
return data->domain;
|
return data->domain;
|
||||||
}
|
}
|
||||||
|
|
||||||
void QZeroConfService::setDomain(const QString &domain)
|
void QZeroConfService::setDomain(const QString &domain)
|
||||||
{
|
{
|
||||||
data->domain = domain;
|
data->domain = domain;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString QZeroConfService::host() const
|
QString QZeroConfService::host() const
|
||||||
{
|
{
|
||||||
return data->host;
|
return data->host;
|
||||||
}
|
}
|
||||||
|
|
||||||
void QZeroConfService::setHost(const QString &host)
|
void QZeroConfService::setHost(const QString &host)
|
||||||
{
|
{
|
||||||
data->host = host;
|
data->host = host;
|
||||||
}
|
}
|
||||||
|
|
||||||
QHostAddress QZeroConfService::ip() const
|
QHostAddress QZeroConfService::ip() const
|
||||||
{
|
{
|
||||||
return data->ip;
|
return data->ip;
|
||||||
}
|
}
|
||||||
|
|
||||||
void QZeroConfService::setIp(QHostAddress &ip)
|
void QZeroConfService::setIp(QHostAddress &ip)
|
||||||
{
|
{
|
||||||
data->ip = ip;
|
data->ip = ip;
|
||||||
}
|
}
|
||||||
|
|
||||||
QHostAddress QZeroConfService::ipv6() const
|
QHostAddress QZeroConfService::ipv6() const
|
||||||
{
|
{
|
||||||
return data->ipv6;
|
return data->ipv6;
|
||||||
}
|
}
|
||||||
|
|
||||||
void QZeroConfService::setIpv6(const QHostAddress &ipv6)
|
void QZeroConfService::setIpv6(const QHostAddress &ipv6)
|
||||||
{
|
{
|
||||||
data->ipv6 = ipv6;
|
data->ipv6 = ipv6;
|
||||||
}
|
}
|
||||||
|
|
||||||
quint32 QZeroConfService::interfaceIndex() const
|
quint32 QZeroConfService::interfaceIndex() const
|
||||||
{
|
{
|
||||||
return data->interfaceIndex;
|
return data->interfaceIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
void QZeroConfService::setInterfaceIndex(const quint32 &interfaceIndex)
|
void QZeroConfService::setInterfaceIndex(const quint32 &interfaceIndex)
|
||||||
{
|
{
|
||||||
data->interfaceIndex = interfaceIndex;
|
data->interfaceIndex = interfaceIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
quint16 QZeroConfService::port() const
|
quint16 QZeroConfService::port() const
|
||||||
{
|
{
|
||||||
return data->port;
|
return data->port;
|
||||||
}
|
}
|
||||||
|
|
||||||
void QZeroConfService::setPort(const quint16 port)
|
void QZeroConfService::setPort(const quint16 port)
|
||||||
{
|
{
|
||||||
data->port = port;
|
data->port = port;
|
||||||
}
|
}
|
||||||
|
|
||||||
QMap<QByteArray, QByteArray> QZeroConfService::txt() const
|
QMap<QByteArray, QByteArray> QZeroConfService::txt() const
|
||||||
{
|
{
|
||||||
return data->txt;
|
return data->txt;
|
||||||
}
|
}
|
||||||
|
|
||||||
void QZeroConfService::setTxt(const QMap<QByteArray, QByteArray> txt)
|
void QZeroConfService::setTxt(const QMap<QByteArray, QByteArray> txt)
|
||||||
{
|
{
|
||||||
data->txt = txt;
|
data->txt = txt;
|
||||||
}
|
}
|
||||||
|
|
||||||
void QZeroConfService::appendTxt(QByteArray idx, QByteArray val)
|
void QZeroConfService::appendTxt(QByteArray idx, QByteArray val)
|
||||||
{
|
{
|
||||||
data->txt[idx] = val;
|
data->txt[idx] = val;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QZeroConfService::isValid() const
|
bool QZeroConfService::isValid() const
|
||||||
{
|
{
|
||||||
|
|
||||||
return (!data->name.isEmpty());
|
return (!data->name.isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
bool QZeroConfService::operator==(const QZeroConfService &rhs) const
|
bool QZeroConfService::operator==(const QZeroConfService &rhs) const
|
||||||
{
|
{
|
||||||
return this->name() == rhs.name() && (this->ip() == rhs.ip() || this->ipv6() == rhs.ipv6());
|
return this->name() == rhs.name() && (this->ip() == rhs.ip() || this->ipv6() == rhs.ipv6());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -8,45 +8,45 @@ class QZeroConfServiceData;
|
|||||||
|
|
||||||
class QZeroConfService
|
class QZeroConfService
|
||||||
{
|
{
|
||||||
Q_GADGET
|
Q_GADGET
|
||||||
Q_PROPERTY( QString name READ name )
|
Q_PROPERTY( QString name READ name )
|
||||||
Q_PROPERTY( QString type READ type )
|
Q_PROPERTY( QString type READ type )
|
||||||
Q_PROPERTY( QString domain READ domain )
|
Q_PROPERTY( QString domain READ domain )
|
||||||
Q_PROPERTY( QString host READ host )
|
Q_PROPERTY( QString host READ host )
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
QZeroConfService();
|
QZeroConfService();
|
||||||
QZeroConfService(const QZeroConfService &);
|
QZeroConfService(const QZeroConfService &);
|
||||||
QZeroConfService &operator=(const QZeroConfService &);
|
QZeroConfService &operator=(const QZeroConfService &);
|
||||||
~QZeroConfService();
|
~QZeroConfService();
|
||||||
|
|
||||||
|
|
||||||
QString name() const;
|
QString name() const;
|
||||||
void setName(const QString &name);
|
void setName(const QString &name);
|
||||||
QString type() const;
|
QString type() const;
|
||||||
void setType(const QString &type);
|
void setType(const QString &type);
|
||||||
QString domain() const;
|
QString domain() const;
|
||||||
void setDomain(const QString &domain);
|
void setDomain(const QString &domain);
|
||||||
QString host() const;
|
QString host() const;
|
||||||
void setHost(const QString &host);
|
void setHost(const QString &host);
|
||||||
QHostAddress ip() const;
|
QHostAddress ip() const;
|
||||||
void setIp(QHostAddress &ip);
|
void setIp(QHostAddress &ip);
|
||||||
QHostAddress ipv6() const;
|
QHostAddress ipv6() const;
|
||||||
void setIpv6(const QHostAddress &ipv6);
|
void setIpv6(const QHostAddress &ipv6);
|
||||||
quint32 interfaceIndex() const;
|
quint32 interfaceIndex() const;
|
||||||
void setInterfaceIndex(const quint32 &interfaceIndex);
|
void setInterfaceIndex(const quint32 &interfaceIndex);
|
||||||
quint16 port() const;
|
quint16 port() const;
|
||||||
void setPort(const quint16 port);
|
void setPort(const quint16 port);
|
||||||
QMap <QByteArray, QByteArray> txt() const;
|
QMap <QByteArray, QByteArray> txt() const;
|
||||||
void setTxt(const QMap<QByteArray, QByteArray> txt);
|
void setTxt(const QMap<QByteArray, QByteArray> txt);
|
||||||
void appendTxt(QByteArray idx, QByteArray val = "");
|
void appendTxt(QByteArray idx, QByteArray val = "");
|
||||||
|
|
||||||
bool isValid() const;
|
bool isValid() const;
|
||||||
bool operator==(const QZeroConfService &rhs) const;
|
bool operator==(const QZeroConfService &rhs) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QSharedDataPointer<QZeroConfServiceData> data;
|
QSharedDataPointer<QZeroConfServiceData> data;
|
||||||
};
|
};
|
||||||
|
|
||||||
Q_DECLARE_METATYPE(QZeroConfService)
|
Q_DECLARE_METATYPE(QZeroConfService)
|
||||||
|
Reference in New Issue
Block a user