forked from jbagg/QtZeroConf
Applied undo_some_whitespace_changes.patch
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> //
|
||||||
@ -136,19 +136,19 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
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;
|
||||||
@ -162,8 +162,8 @@ public:
|
|||||||
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
|
||||||
@ -209,15 +209,13 @@ public:
|
|||||||
|
|
||||||
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());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub->services.clear();
|
pub->services.clear();
|
||||||
|
|
||||||
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();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -233,8 +231,7 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
QZeroConf::QZeroConf(QObject *parent) : QObject (parent)
|
||||||
QZeroConf::QZeroConf(QObject *parent) : QObject(parent)
|
|
||||||
{
|
{
|
||||||
pri = new QZeroConfPrivate(this);
|
pri = new QZeroConfPrivate(this);
|
||||||
}
|
}
|
||||||
@ -303,7 +300,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;
|
||||||
|
43
bonjour.cpp
43
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"
|
||||||
@ -37,7 +37,6 @@ QZeroConfPrivate::QZeroConfPrivate(QZeroConf *parent)
|
|||||||
browserSocket = NULL;
|
browserSocket = NULL;
|
||||||
resolverSocket = NULL;
|
resolverSocket = NULL;
|
||||||
addressSocket = NULL;
|
addressSocket = 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.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();
|
||||||
}
|
}
|
||||||
@ -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);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
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.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 +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.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);
|
||||||
@ -245,12 +242,10 @@ 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub->services.clear();
|
pub->services.clear();
|
||||||
}
|
}
|
||||||
else if (toClean == dnssRef) {
|
else if (toClean == dnssRef) {
|
||||||
|
10
bonjour_p.h
10
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_
|
||||||
|
@ -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>
|
||||||
@ -53,13 +53,11 @@ mainWindow::mainWindow()
|
|||||||
publishEnabled = 0;
|
publishEnabled = 0;
|
||||||
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;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void mainWindow::buildGUI()
|
void mainWindow::buildGUI()
|
||||||
@ -93,7 +91,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 +100,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 +152,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 +167,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_
|
||||||
@ -47,13 +47,11 @@ private:
|
|||||||
bool publishEnabled;
|
bool publishEnabled;
|
||||||
|
|
||||||
private slots:
|
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_ */
|
||||||
|
14
qzeroconf.h
14
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_
|
||||||
@ -43,8 +43,6 @@
|
|||||||
# define Q_ZEROCONF_EXPORT
|
# define Q_ZEROCONF_EXPORT
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class QZeroConfPrivate;
|
class QZeroConfPrivate;
|
||||||
|
|
||||||
class Q_ZEROCONF_EXPORT QZeroConf : public QObject
|
class Q_ZEROCONF_EXPORT QZeroConf : public QObject
|
||||||
@ -60,7 +58,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);
|
||||||
|
Reference in New Issue
Block a user