• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • dnssd
 

dnssd

  • dnssd
responder.cpp
1/* This file is part of the KDE project
2 *
3 * Copyright (C) 2004 Jakub Stachowski <qbast@go2.pl>
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
14 *
15 * You should have received a copy of the GNU Library General Public License
16 * along with this library; see the file COPYING.LIB. If not, write to
17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19 */
20
21#include "responder.h"
22#include <tqapplication.h>
23#include <tqeventloop.h>
24#include <kstaticdeleter.h>
25#include <kidna.h>
26#include <kdebug.h>
27#ifdef HAVE_DNSSD
28#include <avahi-tqt/qt-watch.h>
29#endif
30
31namespace DNSSD
32{
33
34static KStaticDeleter<Responder> responder_sd;
35Responder* Responder::m_self = 0;
36
37#ifdef HAVE_DNSSD
38void client_callback(AvahiClient *, AvahiClientState s, void* u)
39{
40 Responder *r = reinterpret_cast<Responder*>(u);
41 emit (r->stateChanged(s));
42}
43#endif
44
45
46Responder::Responder()
47{
48 int error;
49#ifdef HAVE_DNSSD
50 const AvahiPoll* poll = avahi_qt_poll_get();
51#ifdef AVAHI_API_0_6
52 m_client = avahi_client_new(poll, AVAHI_CLIENT_IGNORE_USER_CONFIG,client_callback, this, &error);
53#else
54 m_client = avahi_client_new(poll, client_callback, this, &error);
55#endif
56 if (!m_client) kdWarning() << "Failed to create avahi client" << endl;
57#endif
58}
59
60Responder::~Responder()
61{
62#ifdef HAVE_DNSSD
63 if (m_client) avahi_client_free(m_client);
64#endif
65}
66
67Responder& Responder::self()
68{
69 if (!m_self) responder_sd.setObject(m_self, new Responder);
70 return *m_self;
71}
72
73void Responder::process()
74{
75 tqApp->eventLoop()->processEvents(TQEventLoop::ExcludeUserInput);
76}
77
78#ifdef HAVE_DNSSD
79AvahiClientState Responder::state() const
80{
81#ifdef AVAHI_API_0_6
82 return (m_client) ? (avahi_client_get_state(m_client)) : AVAHI_CLIENT_FAILURE;
83#else
84 return (m_client) ? (avahi_client_get_state(m_client)) : AVAHI_CLIENT_DISCONNECTED;
85#endif
86}
87#endif
88
89bool domainIsLocal(const TQString& domain)
90{
91 return TQString(domain.section('.',-1,-1)).lower()=="local";
92}
93
94TQCString domainToDNS(const TQString &domain)
95{
96 if (domainIsLocal(domain)) return domain.utf8();
97 else return KIDNA::toAsciiCString(domain);
98}
99
100TQString DNSToDomain(const char* domain)
101{
102 if (domainIsLocal(domain)) return TQString::fromUtf8(domain);
103 else return KIDNA::toUnicode(domain);
104}
105
106
107}
108#include "responder.moc"

dnssd

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

dnssd

Skip menu "dnssd"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for dnssd by doxygen 1.9.4
This website is maintained by Timothy Pearson.