• Skip to content
  • Skip to link menu
KDE 4.1 API Reference
  • KDE API Reference
  • kdelibs
  • Sitemap
  • Contact Us
 

DNSSD

avahi-remoteservice.cpp

Go to the documentation of this file.
00001 /* This file is part of the KDE project
00002  *
00003  * Copyright (C) 2004, 2005 Jakub Stachowski <qbast@go2.pl>
00004  *
00005  * This library is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU Library General Public
00007  * License as published by the Free Software Foundation; either
00008  * version 2 of the License, or (at your option) any later version.
00009  *
00010  * This library is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013  * Library General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU Library General Public License
00016  * along with this library; see the file COPYING.LIB.  If not, write to
00017  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018  * Boston, MA 02110-1301, USA.
00019  */
00020 
00021 #include "avahi-remoteservice_p.h"
00022 #include <netinet/in.h>
00023 #include <QtCore/QEventLoop>
00024 #include <QtGui/QApplication>
00025 #include <kdebug.h>
00026 #include "remoteservice.h"
00027 #include "avahi_server_interface.h"
00028 #include "avahi_serviceresolver_interface.h"
00029 #ifndef KDE_USE_FINAL
00030 Q_DECLARE_METATYPE(QList<QByteArray>)
00031 #endif
00032 namespace DNSSD
00033 {
00034 
00035 RemoteService::RemoteService(const QString& name,const QString& type,const QString& domain)
00036         : ServiceBase(new RemoteServicePrivate(this, name,type,domain))
00037 {
00038 }
00039 
00040 
00041 RemoteService::~RemoteService()
00042 {
00043 }
00044 
00045 bool RemoteService::resolve()
00046 {
00047     K_D;
00048     resolveAsync();
00049     while (d->m_running && !d->m_resolved) QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
00050     return d->m_resolved;
00051 }
00052 
00053 void RemoteService::resolveAsync()
00054 {
00055     K_D;
00056     if (d->m_running) return;
00057     d->m_resolved = false;
00058         registerTypes();
00059     kDebug() << this << ":Starting resolve of : " << d->m_serviceName << " " << d->m_type << " " << d->m_domain << "\n";
00060     org::freedesktop::Avahi::Server s("org.freedesktop.Avahi","/",QDBusConnection::systemBus());
00061     //FIXME: don't use LOOKUP_NO_ADDRESS if NSS unavailable 
00062     QDBusReply<QDBusObjectPath> rep=s.ServiceResolverNew(-1, -1, d->m_serviceName, d->m_type, 
00063         domainToDNS(d->m_domain), -1, 8 /*AVAHI_LOOKUP_NO_ADDRESS*/);
00064     if (!rep.isValid()) {
00065         emit resolved(false);
00066         return;
00067     }
00068     
00069     org::freedesktop::Avahi::ServiceResolver *b=new org::freedesktop::Avahi::ServiceResolver("org.freedesktop.Avahi",rep.value().path(),
00070         QDBusConnection::systemBus());
00071     connect(b,SIGNAL(Found(int,int,const QString &,const QString &,const QString &,const QString &, int, const QString &,ushort,
00072          const QList<QByteArray>&, uint)),d, SLOT(gotFound(int,int,const QString &,const QString &,const QString &,const QString &,
00073          int, const QString &,ushort , const QList<QByteArray>&, uint)));
00074     connect(b,SIGNAL(Failure(const QString&)),d, SLOT(gotError()));
00075     d->m_running=true;
00076 }
00077 
00078 bool RemoteService::isResolved() const
00079 {
00080     K_D;
00081     return d->m_resolved;
00082 }
00083 
00084 void RemoteServicePrivate::gotError()
00085 {
00086     m_resolved=false;
00087     stop();
00088         
00089     emit m_parent->resolved(false);
00090 }
00091 
00092 void RemoteServicePrivate::gotFound(int, int, const QString &name, const QString &, const QString &domain, const QString &host, int, const QString &, ushort port, const QList<QByteArray> &txt, uint)
00093 {
00094     m_serviceName = name;
00095     m_hostName = host;
00096     m_port = port;
00097     m_domain=DNSToDomain(domain);
00098     Q_FOREACH(const QByteArray &x, txt) {
00099         int pos=x.indexOf("=");
00100         if (pos==-1) m_textData[x]=QByteArray();
00101         else m_textData[x.mid(0,pos)]=x.mid(pos+1,x.size()-pos);
00102     }
00103     m_resolved = true;
00104     emit m_parent->resolved(true);
00105 }
00106 
00107 void RemoteServicePrivate::stop()
00108 {
00109     if (m_resolver) m_resolver->Free();
00110     delete m_resolver;
00111     m_resolver=0;
00112     m_running=false;
00113 }
00114 
00115 void RemoteService::virtual_hook(int, void*)
00116 {
00117     // BASE::virtual_hook(int, void*);
00118 }
00119 
00120 
00121 }
00122 
00123 #include "remoteservice.moc"
00124 #include "avahi-remoteservice_p.moc"

DNSSD

Skip menu "DNSSD"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • KIO
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • Kross
  • KUtils
  • Nepomuk
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal