Attempt to fix compilation when Avahi is not available

git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdelibs@1152784 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
v3.5.13-sru
tpearson 15 years ago
parent cfa3abbed0
commit 847c48556b

@ -34,6 +34,7 @@
namespace DNSSD
{
#ifdef HAVE_DNSSD
#ifdef AVAHI_API_0_6
void domains_callback(AvahiDomainBrowser*, AvahiIfIndex, AvahiProtocol, AvahiBrowserEvent event, const char* replyDomain,
AvahiLookupResultFlags, void* context);
@ -41,6 +42,7 @@ void domains_callback(AvahiDomainBrowser*, AvahiIfIndex, AvahiProtocol, AvahiBr
void domains_callback(AvahiDomainBrowser*, AvahiIfIndex, AvahiProtocol, AvahiBrowserEvent event, const char* replyDomain,
void* context);
#endif
#endif
class DomainBrowserPrivate
@ -100,6 +102,7 @@ void DomainBrowser::startBrowse()
if (ServiceBrowser::isAvailable()!=ServiceBrowser::Working) return;
QStringList::const_iterator itEnd = d->m_domains.end();
for (QStringList::const_iterator it=d->m_domains.begin(); it!=itEnd; ++it ) emit domainAdded(*it);
#ifdef HAVE_DNSSD
if (d->m_browseLAN)
#ifdef AVAHI_API_0_6
d->m_browser = avahi_domain_browser_new(Responder::self().client(), AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC,
@ -108,6 +111,7 @@ void DomainBrowser::startBrowse()
d->m_browser = avahi_domain_browser_new(Responder::self().client(), AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC,
"local.", AVAHI_DOMAIN_BROWSER_BROWSE, domains_callback, this);
#endif
#endif
}
void DomainBrowser::gotNewDomain(const QString& domain)
@ -163,6 +167,7 @@ bool DomainBrowser::isRunning() const
void DomainBrowser::virtual_hook(int, void*)
{}
#ifdef HAVE_DNSSD
#ifdef AVAHI_API_0_6
void domains_callback(AvahiDomainBrowser*, AvahiIfIndex, AvahiProtocol, AvahiBrowserEvent event, const char* replyDomain,
AvahiLookupResultFlags,void* context)
@ -177,7 +182,7 @@ void domains_callback(AvahiDomainBrowser*, AvahiIfIndex, AvahiProtocol, AvahiBr
DNSToDomain(replyDomain));
QApplication::postEvent(obj, arev);
}
#endif
}
#include "domainbrowser.moc"

@ -45,7 +45,9 @@ namespace DNSSD
{
static unsigned long publicIP();
#ifdef HAVE_DNSSD
void publish_callback (AvahiEntryGroup*, AvahiEntryGroupState s, void *context);
#endif
class PublicServicePrivate
{
@ -209,12 +211,15 @@ void PublicService::publishAsync()
emit published(false);
return;
}
#ifdef HAVE_DNSSD
AvahiClientState s=Responder::self().state();
#endif
d->m_running=true;
d->m_collision=true; // make it look like server is getting out of collision to force registering
clientState(s);
}
#ifdef HAVE_DNSSD
void publish_callback (AvahiEntryGroup*, AvahiEntryGroupState s, void *context)
{
QObject *obj = reinterpret_cast<QObject*>(context);
@ -222,6 +227,7 @@ void publish_callback (AvahiEntryGroup*, AvahiEntryGroupState s, void *context)
PublishEvent* pev=new PublishEvent(s==AVAHI_ENTRY_GROUP_ESTABLISHED);
QApplication::postEvent(obj, pev);
}
#endif
const KURL PublicService::toInvitation(const QString& host)
{

@ -35,6 +35,7 @@
namespace DNSSD
{
#ifdef HAVE_DNSSD
#ifdef AVAHI_API_0_6
void services_callback(AvahiServiceBrowser*, AvahiIfIndex, AvahiProtocol, AvahiBrowserEvent event, const char* name,
@ -49,6 +50,7 @@ void types_callback(AvahiServiceTypeBrowser*, AvahiIfIndex, AvahiProtocol, Avahi
void domains_callback(AvahiDomainBrowser*, AvahiIfIndex, AvahiProtocol, AvahiBrowserEvent event, const char* replyDomain,
void* context);
#endif
#endif
enum BrowserType { Types, Services };
@ -106,21 +108,25 @@ void Query::startQuery()
d->m_finished = false;
if (d->m_type=="_services._dns-sd._udp") {
d->m_browserType = Types;
#ifdef HAVE_DNSSD
#ifdef AVAHI_API_0_6
d->m_browser = avahi_service_type_browser_new(Responder::self().client(), AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC,
domainToDNS(d->m_domain), (AvahiLookupFlags)0, types_callback, this);
#else
d->m_browser = avahi_service_type_browser_new(Responder::self().client(), AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC,
d->m_domain.utf8(), types_callback, this);
#endif
#endif
} else {
d->m_browserType = Services;
#ifdef HAVE_DNSSD
#ifdef AVAHI_API_0_6
d->m_browser = avahi_service_browser_new(Responder::self().client(), AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC,
d->m_type.ascii(),domainToDNS(d->m_domain), (AvahiLookupFlags)0, services_callback,this);
#else
d->m_browser = avahi_service_browser_new(Responder::self().client(), AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC,
d->m_type.ascii(),d->m_domain.utf8(),services_callback,this);
#endif
#endif
}
if (d->m_browser) {
@ -152,6 +158,7 @@ void Query::timeout()
emit finished();
}
#ifdef HAVE_DNSSD
#ifdef AVAHI_API_0_6
void services_callback (AvahiServiceBrowser*, AvahiIfIndex, AvahiProtocol, AvahiBrowserEvent event,
const char* serviceName, const char* regtype, const char* replyDomain, AvahiLookupResultFlags, void* context)
@ -181,6 +188,7 @@ void types_callback(AvahiServiceTypeBrowser*, AvahiIfIndex, AvahiProtocol, Avahi
DNSToDomain(replyDomain));
QApplication::postEvent(obj, arev);
}
#endif
}
#include "query.moc"

@ -38,6 +38,7 @@
namespace DNSSD
{
#ifdef HAVE_DNSSD
#ifdef AVAHI_API_0_6
void resolve_callback(AvahiServiceResolver*, AvahiIfIndex, AvahiProtocol proto, AvahiResolverEvent e,
const char* name, const char* type, const char* domain, const char* hostname, const AvahiAddress* a,
@ -47,6 +48,7 @@ void resolve_callback(AvahiServiceResolver*, AvahiIfIndex, AvahiProtocol proto,
const char* name, const char* type, const char* domain, const char* hostname, const AvahiAddress* a,
uint16_t port, AvahiStringList* txt, void* context);
#endif
#endif
class RemoteServicePrivate : public Responder
{
@ -106,6 +108,7 @@ void RemoteService::resolveAsync()
if (d->m_running) return;
d->m_resolved = false;
// FIXME: first protocol should be set?
#ifdef HAVE_DNSSD
#ifdef AVAHI_API_0_6
d->m_resolver = avahi_service_resolver_new(Responder::self().client(),AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC,
m_serviceName.utf8(), m_type.ascii(), domainToDNS(m_domain), AVAHI_PROTO_UNSPEC, AVAHI_LOOKUP_NO_ADDRESS,
@ -113,6 +116,7 @@ void RemoteService::resolveAsync()
#else
d->m_resolver = avahi_service_resolver_new(Responder::self().client(),AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC,
m_serviceName.utf8(), m_type.ascii(), m_domain.utf8(), AVAHI_PROTO_UNSPEC, resolve_callback, this);
#endif
#endif
if (d->m_resolver) d->m_running=true;
else emit resolved(false);
@ -164,6 +168,7 @@ QDataStream & operator>> (QDataStream & s, RemoteService & a)
return s;
}
#ifdef HAVE_DNSSD
#ifdef AVAHI_API_0_6
void resolve_callback(AvahiServiceResolver*, AvahiIfIndex, AvahiProtocol, AvahiResolverEvent e,
const char*, const char*, const char*, const char* hostname, const AvahiAddress*,
@ -191,6 +196,7 @@ void resolve_callback(AvahiServiceResolver*, AvahiIfIndex, AvahiProtocol, AvahiR
ResolveEvent rev(DNSToDomain(hostname),port,map);
QApplication::sendEvent(obj, &rev);
}
#endif
}

@ -33,16 +33,19 @@ namespace DNSSD
static KStaticDeleter<Responder> responder_sd;
Responder* Responder::m_self = 0;
#ifdef HAVE_DNSSD
void client_callback(AvahiClient *, AvahiClientState s, void* u)
{
Responder *r = reinterpret_cast<Responder*>(u);
emit (r->stateChanged(s));
}
#endif
Responder::Responder()
{
int error;
#ifdef HAVE_DNSSD
const AvahiPoll* poll = avahi_qt_poll_get();
#ifdef AVAHI_API_0_6
m_client = avahi_client_new(poll, AVAHI_CLIENT_IGNORE_USER_CONFIG,client_callback, this, &error);
@ -50,11 +53,14 @@ Responder::Responder()
m_client = avahi_client_new(poll, client_callback, this, &error);
#endif
if (!m_client) kdWarning() << "Failed to create avahi client" << endl;
#endif
}
Responder::~Responder()
{
#ifdef HAVE_DNSSD
if (m_client) avahi_client_free(m_client);
#endif
}
Responder& Responder::self()
@ -68,6 +74,7 @@ void Responder::process()
qApp->eventLoop()->processEvents(QEventLoop::ExcludeUserInput);
}
#ifdef HAVE_DNSSD
AvahiClientState Responder::state() const
{
#ifdef AVAHI_API_0_6
@ -76,6 +83,7 @@ AvahiClientState Responder::state() const
return (m_client) ? (avahi_client_get_state(m_client)) : AVAHI_CLIENT_DISCONNECTED;
#endif
}
#endif
bool domainIsLocal(const QString& domain)
{

@ -25,7 +25,12 @@
#include <qsocketnotifier.h>
#include <qsignal.h>
#include <config.h>
#ifdef HAVE_DNSSD
#include <avahi-client/client.h>
#else
#define DNSServiceRef void*
#endif
namespace DNSSD
{
@ -45,15 +50,21 @@ public:
~Responder();
static Responder& self();
#ifdef HAVE_DNSSD
AvahiClientState state() const;
AvahiClient* client() const { return m_client; }
#endif
void process();
signals:
void stateChanged(AvahiClientState);
private:
#ifdef HAVE_DNSSD
AvahiClient* m_client;
#endif
static Responder* m_self;
#ifdef HAVE_DNSSD
friend void client_callback(AvahiClient*, AvahiClientState, void*);
#endif
};

@ -26,7 +26,9 @@
#include "responder.h"
#include "query.h"
#include "servicebrowser.h"
#ifdef HAVE_DNSSD
#include <avahi-client/client.h>
#endif
#include <config.h>
namespace DNSSD
@ -82,12 +84,16 @@ ServiceBrowser::ServiceBrowser(const QString& type,const QString& domain,int fla
const ServiceBrowser::State ServiceBrowser::isAvailable()
{
#ifdef HAVE_DNSSD
AvahiClientState s = Responder::self().state();
#ifdef AVAHI_API_0_6
return (s==AVAHI_CLIENT_FAILURE) ? Stopped : Working;
#else
return (s==AVAHI_CLIENT_S_INVALID || s==AVAHI_CLIENT_DISCONNECTED) ? Stopped : Working;
#endif
#else
return Unsupported;
#endif
}
ServiceBrowser::~ ServiceBrowser()
{

Loading…
Cancel
Save