From ef4284acb29aca0bdf792ab40356c7955902e307 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Remko=20Tron=C3=A7on?= Date: Fri, 24 Jul 2009 21:28:19 +0200 Subject: LinkLocal: Publish->Register. diff --git a/Swiften/LinkLocal/BonjourPublishQuery.h b/Swiften/LinkLocal/BonjourPublishQuery.h deleted file mode 100644 index a96e25a..0000000 --- a/Swiften/LinkLocal/BonjourPublishQuery.h +++ /dev/null @@ -1,50 +0,0 @@ -#pragma once - -#include "Swiften/LinkLocal/BonjourQuery.h" -#include "Swiften/LinkLocal/DNSSDPublishQuery.h" -#include "Swiften/LinkLocal/LinkLocalServiceInfo.h" -#include "Swiften/Base/ByteArray.h" -#include "Swiften/EventLoop/MainEventLoop.h" - -namespace Swift { - class BonjourQuerier; - - class BonjourPublishQuery : public DNSSDPublishQuery, public BonjourQuery { - public: - BonjourPublishQuery(const String& name, int port, const LinkLocalServiceInfo& info, boost::shared_ptr querier) : BonjourQuery(querier) { - ByteArray txtRecord = info.toTXTRecord(); - DNSServiceErrorType result = DNSServiceRegister( - &sdRef, 0, 0, name.getUTF8Data(), "_presence._tcp", NULL, NULL, port, - txtRecord.getSize(), txtRecord.getData(), - &BonjourPublishQuery::handleServicePublishedStatic, this); - if (result != kDNSServiceErr_NoError) { - // TODO - std::cerr << "Error creating service registration" << std::endl; - } - } - - void publish() { - run(); - } - - void update(const LinkLocalService& info) { - boost::lock_guard lock(sdRefMutex); - ByteArray txtRecord = info.toTXTRecord(); - DNSServiceUpdateRecord(sdRef, NULL, NULL, txtRecord.getSize(), txtRecord.getData(), 0); - } - - private: - static void handleServicePublishedStatic(DNSServiceRef, DNSServiceFlags, DNSServiceErrorType errorCode, const char *name, const char *regtype, const char *domain, void *context) { - static_cast(context)->handleServicePublished(errorCode, name, regtype, domain); - } - - void handleServicePublished(DNSServiceErrorType errorCode, const char *name, const char *regtype, const char *domain) { - if (errorCode != kDNSServiceErr_NoError) { - MainEventLoop::postEvent(boost::bind(boost::ref(onPublishFinished), boost::optional()), shared_from_this()); - } - else { - MainEventLoop::postEvent(boost::bind(boost::ref(onPublishFinished), boost::optional(LinkLocalServiceID(name, regtype, domain, 0))), shared_from_this()); - } - } - }; -} diff --git a/Swiften/LinkLocal/BonjourQuerier.cpp b/Swiften/LinkLocal/BonjourQuerier.cpp index 3080869..7764f51 100644 --- a/Swiften/LinkLocal/BonjourQuerier.cpp +++ b/Swiften/LinkLocal/BonjourQuerier.cpp @@ -6,7 +6,7 @@ #include #include "Swiften/LinkLocal/BonjourBrowseQuery.h" -#include "Swiften/LinkLocal/BonjourPublishQuery.h" +#include "Swiften/LinkLocal/BonjourRegisterQuery.h" #include "Swiften/Base/foreach.h" namespace Swift { @@ -28,8 +28,8 @@ boost::shared_ptr BonjourQuerier::createBrowseQuery() { return boost::shared_ptr(new BonjourBrowseQuery(shared_from_this())); } -boost::shared_ptr BonjourQuerier::createPublishQuery(const String& name, int port, const LinkLocalServiceInfo& info) { - return boost::shared_ptr(new BonjourPublishQuery(name, port, info, shared_from_this())); +boost::shared_ptr BonjourQuerier::createRegisterQuery(const String& name, int port, const LinkLocalServiceInfo& info) { + return boost::shared_ptr(new BonjourRegisterQuery(name, port, info, shared_from_this())); } void BonjourQuerier::addRunningQuery(boost::shared_ptr query) { diff --git a/Swiften/LinkLocal/BonjourQuerier.h b/Swiften/LinkLocal/BonjourQuerier.h index e5ffa49..a35483c 100644 --- a/Swiften/LinkLocal/BonjourQuerier.h +++ b/Swiften/LinkLocal/BonjourQuerier.h @@ -7,7 +7,7 @@ #include #include "Swiften/LinkLocal/DNSSDBrowseQuery.h" -#include "Swiften/LinkLocal/DNSSDPublishQuery.h" +#include "Swiften/LinkLocal/DNSSDRegisterQuery.h" #include "Swiften/LinkLocal/BonjourQuery.h" namespace Swift { @@ -19,7 +19,7 @@ namespace Swift { ~BonjourQuerier(); boost::shared_ptr createBrowseQuery(); - boost::shared_ptr createPublishQuery(const String& name, int port, const LinkLocalServiceInfo& info); + boost::shared_ptr createRegisterQuery(const String& name, int port, const LinkLocalServiceInfo& info); void start(); void stop(); diff --git a/Swiften/LinkLocal/BonjourRegisterQuery.h b/Swiften/LinkLocal/BonjourRegisterQuery.h new file mode 100644 index 0000000..c34ba02 --- /dev/null +++ b/Swiften/LinkLocal/BonjourRegisterQuery.h @@ -0,0 +1,50 @@ +#pragma once + +#include "Swiften/LinkLocal/BonjourQuery.h" +#include "Swiften/LinkLocal/DNSSDRegisterQuery.h" +#include "Swiften/LinkLocal/LinkLocalServiceInfo.h" +#include "Swiften/Base/ByteArray.h" +#include "Swiften/EventLoop/MainEventLoop.h" + +namespace Swift { + class BonjourQuerier; + + class BonjourRegisterQuery : public DNSSDRegisterQuery, public BonjourQuery { + public: + BonjourRegisterQuery(const String& name, int port, const LinkLocalServiceInfo& info, boost::shared_ptr querier) : BonjourQuery(querier) { + ByteArray txtRecord = info.toTXTRecord(); + DNSServiceErrorType result = DNSServiceRegister( + &sdRef, 0, 0, name.getUTF8Data(), "_presence._tcp", NULL, NULL, port, + txtRecord.getSize(), txtRecord.getData(), + &BonjourRegisterQuery::handleServiceRegisteredStatic, this); + if (result != kDNSServiceErr_NoError) { + // TODO + std::cerr << "Error creating service registration" << std::endl; + } + } + + void registerService() { + run(); + } + + void updateServiceInfo(const LinkLocalServiceInfo& info) { + boost::lock_guard lock(sdRefMutex); + ByteArray txtRecord = info.toTXTRecord(); + DNSServiceUpdateRecord(sdRef, NULL, NULL, txtRecord.getSize(), txtRecord.getData(), 0); + } + + private: + static void handleServiceRegisteredStatic(DNSServiceRef, DNSServiceFlags, DNSServiceErrorType errorCode, const char *name, const char *regtype, const char *domain, void *context) { + static_cast(context)->handleServiceRegistered(errorCode, name, regtype, domain); + } + + void handleServiceRegistered(DNSServiceErrorType errorCode, const char *name, const char *regtype, const char *domain) { + if (errorCode != kDNSServiceErr_NoError) { + MainEventLoop::postEvent(boost::bind(boost::ref(onRegisterFinished), boost::optional()), shared_from_this()); + } + else { + MainEventLoop::postEvent(boost::bind(boost::ref(onRegisterFinished), boost::optional(LinkLocalServiceID(name, regtype, domain, 0))), shared_from_this()); + } + } + }; +} diff --git a/Swiften/LinkLocal/DNSSDPublishQuery.cpp b/Swiften/LinkLocal/DNSSDPublishQuery.cpp deleted file mode 100644 index cf3fd25..0000000 --- a/Swiften/LinkLocal/DNSSDPublishQuery.cpp +++ /dev/null @@ -1,8 +0,0 @@ -#include "Swiften/LinkLocal/DNSSDPublishQuery.h" - -namespace Swift { - -DNSSDPublishQuery::~DNSSDPublishQuery() { -} - -} diff --git a/Swiften/LinkLocal/DNSSDPublishQuery.h b/Swiften/LinkLocal/DNSSDPublishQuery.h deleted file mode 100644 index 48c86dc..0000000 --- a/Swiften/LinkLocal/DNSSDPublishQuery.h +++ /dev/null @@ -1,17 +0,0 @@ -#pragma once - -#include -#include - -#include "Swiften/LinkLocal/LinkLocalServiceID.h" - -namespace Swift { - class DNSSDPublishQuery { - public: - virtual ~DNSSDPublishQuery(); - - virtual void publish() = 0; - - boost::signal)> onPublishFinished; - }; -} diff --git a/Swiften/LinkLocal/DNSSDRegisterQuery.cpp b/Swiften/LinkLocal/DNSSDRegisterQuery.cpp new file mode 100644 index 0000000..fe00b02 --- /dev/null +++ b/Swiften/LinkLocal/DNSSDRegisterQuery.cpp @@ -0,0 +1,8 @@ +#include "Swiften/LinkLocal/DNSSDRegisterQuery.h" + +namespace Swift { + +DNSSDRegisterQuery::~DNSSDRegisterQuery() { +} + +} diff --git a/Swiften/LinkLocal/DNSSDRegisterQuery.h b/Swiften/LinkLocal/DNSSDRegisterQuery.h new file mode 100644 index 0000000..252fbf0 --- /dev/null +++ b/Swiften/LinkLocal/DNSSDRegisterQuery.h @@ -0,0 +1,20 @@ +#pragma once + +#include +#include + +#include "Swiften/LinkLocal/LinkLocalServiceID.h" + +namespace Swift { + class LinkLocalServiceInfo; + + class DNSSDRegisterQuery { + public: + virtual ~DNSSDRegisterQuery(); + + virtual void registerService() = 0; + virtual void updateServiceInfo(const LinkLocalServiceInfo& info) = 0; + + boost::signal)> onRegisterFinished; + }; +} diff --git a/Swiften/LinkLocal/Makefile.inc b/Swiften/LinkLocal/Makefile.inc index 902fa7a..a3144ac 100644 --- a/Swiften/LinkLocal/Makefile.inc +++ b/Swiften/LinkLocal/Makefile.inc @@ -1,6 +1,6 @@ SWIFTEN_SOURCES += \ Swiften/LinkLocal/DNSSDBrowseQuery.cpp \ - Swiften/LinkLocal/DNSSDPublishQuery.cpp \ + Swiften/LinkLocal/DNSSDRegisterQuery.cpp \ Swiften/LinkLocal/DNSSDServiceFactory.cpp \ Swiften/LinkLocal/PlatformDNSSDServiceFactory.cpp \ Swiften/LinkLocal/DNSSDService.cpp \ diff --git a/configure.in b/configure.in index 186bc3c..80e69c0 100644 --- a/configure.in +++ b/configure.in @@ -202,6 +202,7 @@ case $host in *-mingw32*) ;; *-*-darwin*) + HAVE_BONJOUR=yes AC_DEFINE(HAVE_BONJOUR) ;; *) -- cgit v0.10.2-6-g49f6