From 9ad9d64ca686a83800deaefcb06504f2cca43ca2 Mon Sep 17 00:00:00 2001 From: Tim Jansen Date: Mon, 12 Aug 2002 11:26:39 +0000 Subject: [PATCH] Move KServiceRegistry members into private class svn path=/trunk/kdenetwork/krfb/; revision=171547 --- TODO | 2 ++ srvloc/Makefile.am | 2 +- srvloc/kinetaddr.h | 2 +- srvloc/kserviceregistry.cpp | 64 ++++++++++++++++++++++++------------- srvloc/kserviceregistry.h | 33 +++++++------------ 5 files changed, 56 insertions(+), 47 deletions(-) diff --git a/TODO b/TODO index 568b4ed7..3ab3c6d9 100644 --- a/TODO +++ b/TODO @@ -1,4 +1,5 @@ For 3.1: +- remove krfb from all user-visible places - write SLP service template for remote desktop protocols (documentation) @@ -10,6 +11,7 @@ Todo (unscheduled features): - NAT traversal support if I can find an acceptable implementation (probably using TURN, as soon as there is a server and newer spec for that) - split krfb into 2 separate programs (server and invitation) +- soundex support in SLP attributes - look into adding an extension to xfree to improve speed (get noticed of screen updates) - cut & paste support diff --git a/srvloc/Makefile.am b/srvloc/Makefile.am index 564a94d3..b6411388 100644 --- a/srvloc/Makefile.am +++ b/srvloc/Makefile.am @@ -6,7 +6,7 @@ noinst_LTLIBRARIES = libsrvloc.la libsrvloc_la_SOURCES = kinetaddr.cpp kinetaddr_ipfinder.cpp \ kserviceregistry.cpp kuser.cpp libsrvloc_la_LIBADD = $(LIB_QT) $(LIB_KDECORE) $(LIB_SLP) -libsrvloc_la_LDFLAGS = $(all_libraries) -no-undefined +libsrvloc_la_LDFLAGS = $(all_libraries) -no-undefined noinst_HEADERS = kinetaddr.h kserviceregistry.h kuser.h # set the include path for X, qt and KDE diff --git a/srvloc/kinetaddr.h b/srvloc/kinetaddr.h index fc4e44bf..25310cf1 100644 --- a/srvloc/kinetaddr.h +++ b/srvloc/kinetaddr.h @@ -126,7 +126,7 @@ public: * Returns an address that can be used for communication with * other computers on the internet. * Note that the returned address is not always a real - * internet address, because the computer may not be able to connect + * internet address, because the computer couble be unable to connect * to the internet or is behind a NAT gateway. * In the worst case you will get the address of the local loopback * interface. diff --git a/srvloc/kserviceregistry.cpp b/srvloc/kserviceregistry.cpp index 34cdb6ef..1a14f9b0 100644 --- a/srvloc/kserviceregistry.cpp +++ b/srvloc/kserviceregistry.cpp @@ -17,34 +17,57 @@ * the Free Software Foundation, Inc., 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. */ +/** + * TODO: see below.. + */ #include "config.h" #include "kserviceregistry.h" #include + #ifdef HAVE_SLP +#include + +class KServiceRegistryPrivate { +public: + KServiceRegistryPrivate(const QString &lang) : + m_opened(false), + m_lang(lang) { + } + bool ensureOpen(); + + bool m_opened; + QString m_lang; + + SLPHandle m_handle; + friend void KServiceRegistryRegReport(SLPHandle slp, + SLPError errcode, + void* cookie); + bool m_cbSuccess; +}; void KServiceRegistryRegReport(SLPHandle, SLPError errcode, void* cookie) { - KServiceRegistry *s = (KServiceRegistry*) cookie; + KServiceRegistryPrivate *s = (KServiceRegistryPrivate*) cookie; s->m_cbSuccess = (errcode == SLP_OK); if (errcode < 0) kdDebug() << "KServiceRegistry: error in callback:" << errcode <m_opened) + SLPClose(d->m_handle); + delete d; } -bool KServiceRegistry::ensureOpen() { +bool KServiceRegistryPrivate::ensureOpen() { SLPError e; if (m_opened) @@ -60,35 +83,35 @@ bool KServiceRegistry::ensureOpen() { } bool KServiceRegistry::available() { - return ensureOpen(); + return d->ensureOpen(); } bool KServiceRegistry::registerService(const QString &serviceURL, QString attributes, unsigned short lifetime) { - if (!ensureOpen()) + if (!d->ensureOpen()) return false; - m_cbSuccess = true; - SLPError e = SLPReg(m_handle, + d->m_cbSuccess = true; + SLPError e = SLPReg(d->m_handle, serviceURL.latin1(), lifetime > 0 ? lifetime : SLP_LIFETIME_MAXIMUM, 0, attributes.isNull() ? "" : attributes.latin1(), SLP_TRUE, KServiceRegistryRegReport, - this); + d); if (e != SLP_OK) { kdDebug() << "KServiceRegistry: error in registerService:" << e <m_cbSuccess; } bool KServiceRegistry::registerService(const QString &serviceURL, QMap attributes, unsigned short lifetime) { - if (!ensureOpen()) + if (!d->ensureOpen()) return false; // TODO: encode strings in map? QString s; @@ -103,11 +126,11 @@ bool KServiceRegistry::registerService(const QString &serviceURL, } void KServiceRegistry::unregisterService(const QString &serviceURL) { - if (!m_opened) + if (!d->m_opened) return; - SLPDereg(m_handle, serviceURL.latin1(), + SLPDereg(d->m_handle, serviceURL.latin1(), KServiceRegistryRegReport, - this); + d); } QString KServiceRegistry::encodeAttributeValue(const QString &value) { @@ -123,17 +146,12 @@ QString KServiceRegistry::encodeAttributeValue(const QString &value) { #else KServiceRegistry::KServiceRegistry(const QString &lang) : - m_opened(false), - m_lang(lang) { + d(0) { } KServiceRegistry::~KServiceRegistry() { } -bool KServiceRegistry::ensureOpen() { - return false; -} - bool KServiceRegistry::available() { return false; } diff --git a/srvloc/kserviceregistry.h b/srvloc/kserviceregistry.h index c2140e0a..f017b129 100644 --- a/srvloc/kserviceregistry.h +++ b/srvloc/kserviceregistry.h @@ -25,18 +25,12 @@ #ifndef __KSERVICEREGISTRY_H #define __KSERVICEREGISTRY_H -#ifdef HAVE_CONFIG_H -#include -#endif - -#ifdef HAVE_SLP -#include -#endif - #include #include #include +class KServiceRegistryPrivate; + /** * KServiceRegistry allows you to announce your service using SLP (RFC 2608). * @@ -80,8 +74,14 @@ * templates is described in RFC 2609, you can find the existing service * templates at http://www.iana.org/assignments/svrloc-templates.htm . * - * - * TODO: example of obtaining host address and registering service + * Example: + *
+ *   KServiceRegistry ksr;
+ *   KInetAddress kia = KInetAddress->getLocalAddress();
+ *   ksr.registerService(QString("service:remotedesktop.kde:vnc://%1:0").arg(kia->nodeName()),
+ *                       "(type=shared)");
+ *   delete kia;
+ * 
* * @version $Id$ * @author Tim Jansen, tim@tjansen.de @@ -155,18 +155,7 @@ class KServiceRegistry { void unregisterService(const QString &serviceURL); private: - bool ensureOpen(); - - bool m_opened; - QString m_lang; - -#ifdef HAVE_SLP - SLPHandle m_handle; - friend void KServiceRegistryRegReport(SLPHandle slp, - SLPError errcode, - void* cookie); -#endif - bool m_cbSuccess; + KServiceRegistryPrivate *d; }; #endif