forked from jbagg/QtZeroConf
Avahicore - switch to SharedData
This commit is contained in:
@ -116,6 +116,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;
|
||||||
|
|
||||||
switch (event) {
|
switch (event) {
|
||||||
case AVAHI_BROWSER_FAILURE:
|
case AVAHI_BROWSER_FAILURE:
|
||||||
@ -134,11 +135,9 @@ 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:
|
||||||
@ -162,7 +161,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);
|
||||||
@ -171,21 +170,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);
|
||||||
@ -193,10 +191,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);
|
||||||
@ -207,7 +206,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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -219,10 +217,9 @@ public:
|
|||||||
avahi_s_service_browser_free(browser);
|
avahi_s_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();
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user