From e7ab68e8daf120d932d9eefc9053e9e064ca29af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Remko=20Tron=C3=A7on?= Date: Sun, 26 Jul 2009 17:06:11 +0200 Subject: Make DNSSD independent of LinkLocalServiceInfo. diff --git a/Swiften/LinkLocal/DNSSD/Bonjour/BonjourQuerier.cpp b/Swiften/LinkLocal/DNSSD/Bonjour/BonjourQuerier.cpp index 70fbc7c..9c9e64e 100644 --- a/Swiften/LinkLocal/DNSSD/Bonjour/BonjourQuerier.cpp +++ b/Swiften/LinkLocal/DNSSD/Bonjour/BonjourQuerier.cpp @@ -29,7 +29,7 @@ boost::shared_ptr BonjourQuerier::createBrowseQuery() { return boost::shared_ptr(new BonjourBrowseQuery(shared_from_this())); } -boost::shared_ptr BonjourQuerier::createRegisterQuery(const String& name, int port, const LinkLocalServiceInfo& info) { +boost::shared_ptr BonjourQuerier::createRegisterQuery(const String& name, int port, const ByteArray& info) { return boost::shared_ptr(new BonjourRegisterQuery(name, port, info, shared_from_this())); } diff --git a/Swiften/LinkLocal/DNSSD/Bonjour/BonjourQuerier.h b/Swiften/LinkLocal/DNSSD/Bonjour/BonjourQuerier.h index 644a8d9..d12f94f 100644 --- a/Swiften/LinkLocal/DNSSD/Bonjour/BonjourQuerier.h +++ b/Swiften/LinkLocal/DNSSD/Bonjour/BonjourQuerier.h @@ -10,7 +10,7 @@ #include "Swiften/LinkLocal/DNSSD/Bonjour/BonjourQuery.h" namespace Swift { - class LinkLocalServiceInfo; + class ByteArray; class BonjourQuerier : public DNSSDQuerier, @@ -21,7 +21,7 @@ namespace Swift { boost::shared_ptr createBrowseQuery(); boost::shared_ptr createRegisterQuery( - const String& name, int port, const LinkLocalServiceInfo& info); + const String& name, int port, const ByteArray& info); boost::shared_ptr createResolveServiceQuery( const DNSSDServiceID&); boost::shared_ptr createResolveHostnameQuery( diff --git a/Swiften/LinkLocal/DNSSD/Bonjour/BonjourRegisterQuery.h b/Swiften/LinkLocal/DNSSD/Bonjour/BonjourRegisterQuery.h index 41e5831..c85b90f 100644 --- a/Swiften/LinkLocal/DNSSD/Bonjour/BonjourRegisterQuery.h +++ b/Swiften/LinkLocal/DNSSD/Bonjour/BonjourRegisterQuery.h @@ -2,7 +2,6 @@ #include "Swiften/LinkLocal/DNSSD/Bonjour/BonjourQuery.h" #include "Swiften/LinkLocal/DNSSD/DNSSDRegisterQuery.h" -#include "Swiften/LinkLocal/LinkLocalServiceInfo.h" #include "Swiften/Base/ByteArray.h" #include "Swiften/EventLoop/MainEventLoop.h" @@ -11,8 +10,7 @@ namespace Swift { 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(); + BonjourRegisterQuery(const String& name, int port, const ByteArray& txtRecord, boost::shared_ptr querier) : BonjourQuery(querier) { DNSServiceErrorType result = DNSServiceRegister( &sdRef, 0, 0, name.getUTF8Data(), "_presence._tcp", NULL, NULL, port, txtRecord.getSize(), txtRecord.getData(), @@ -35,9 +33,8 @@ namespace Swift { stop(); } - void updateServiceInfo(const LinkLocalServiceInfo& info) { + void updateServiceInfo(const ByteArray& txtRecord) { boost::lock_guard lock(sdRefMutex); - ByteArray txtRecord = info.toTXTRecord(); DNSServiceUpdateRecord(sdRef, NULL, NULL, txtRecord.getSize(), txtRecord.getData(), 0); } diff --git a/Swiften/LinkLocal/DNSSD/DNSSDQuerier.h b/Swiften/LinkLocal/DNSSD/DNSSDQuerier.h index 6c7b576..799bc0c 100644 --- a/Swiften/LinkLocal/DNSSD/DNSSDQuerier.h +++ b/Swiften/LinkLocal/DNSSD/DNSSDQuerier.h @@ -4,7 +4,7 @@ namespace Swift { class String; - class LinkLocalServiceInfo; + class ByteArray; class DNSSDServiceID; class DNSSDBrowseQuery; class DNSSDRegisterQuery; @@ -17,7 +17,7 @@ namespace Swift { virtual boost::shared_ptr createBrowseQuery() = 0; virtual boost::shared_ptr createRegisterQuery( - const String& name, int port, const LinkLocalServiceInfo& info) = 0; + const String& name, int port, const ByteArray& info) = 0; virtual boost::shared_ptr createResolveServiceQuery( const DNSSDServiceID&) = 0; virtual boost::shared_ptr createResolveHostnameQuery( diff --git a/Swiften/LinkLocal/DNSSD/DNSSDRegisterQuery.h b/Swiften/LinkLocal/DNSSD/DNSSDRegisterQuery.h index 627cc6b..4a04fa9 100644 --- a/Swiften/LinkLocal/DNSSD/DNSSDRegisterQuery.h +++ b/Swiften/LinkLocal/DNSSD/DNSSDRegisterQuery.h @@ -6,7 +6,7 @@ #include "Swiften/LinkLocal/DNSSD/DNSSDServiceID.h" namespace Swift { - class LinkLocalServiceInfo; + class ByteArray; class DNSSDRegisterQuery { public: @@ -14,7 +14,7 @@ namespace Swift { virtual void registerService() = 0; virtual void unregisterService() = 0; - virtual void updateServiceInfo(const LinkLocalServiceInfo& info) = 0; + virtual void updateServiceInfo(const ByteArray& info) = 0; boost::signal)> onRegisterFinished; }; diff --git a/Swiften/LinkLocal/DNSSD/DNSSDResolveServiceQuery.h b/Swiften/LinkLocal/DNSSD/DNSSDResolveServiceQuery.h index f79b537..217e396 100644 --- a/Swiften/LinkLocal/DNSSD/DNSSDResolveServiceQuery.h +++ b/Swiften/LinkLocal/DNSSD/DNSSDResolveServiceQuery.h @@ -4,19 +4,18 @@ #include #include "Swiften/LinkLocal/DNSSD/DNSSDServiceID.h" -#include "Swiften/LinkLocal/LinkLocalServiceInfo.h" +#include "Swiften/Base/ByteArray.h" namespace Swift { class DNSSDResolveServiceQuery { public: struct Result { - Result(const String& fullName, const String& host, int port, - const LinkLocalServiceInfo& info) : + Result(const String& fullName, const String& host, int port, const ByteArray& info) : fullName(fullName), host(host), port(port), info(info) {} String fullName; String host; int port; - LinkLocalServiceInfo info; + ByteArray info; }; virtual ~DNSSDResolveServiceQuery(); diff --git a/Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDQuerier.cpp b/Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDQuerier.cpp index 222500a..88c7774 100644 --- a/Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDQuerier.cpp +++ b/Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDQuerier.cpp @@ -17,7 +17,7 @@ boost::shared_ptr FakeDNSSDQuerier::createBrowseQuery() { return boost::shared_ptr(new FakeDNSSDBrowseQuery(shared_from_this())); } -boost::shared_ptr FakeDNSSDQuerier::createRegisterQuery(const String& name, int port, const LinkLocalServiceInfo& info) { +boost::shared_ptr FakeDNSSDQuerier::createRegisterQuery(const String& name, int port, const ByteArray& info) { return boost::shared_ptr(new FakeDNSSDRegisterQuery(name, port, info, shared_from_this())); } diff --git a/Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDQuerier.h b/Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDQuerier.h index 6c5f343..43b717e 100644 --- a/Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDQuerier.h +++ b/Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDQuerier.h @@ -11,7 +11,7 @@ #include "Swiften/LinkLocal/DNSSD/DNSSDResolveServiceQuery.h" namespace Swift { - class LinkLocalServiceInfo; + class ByteArray; class FakeDNSSDQuery; class FakeDNSSDBrowseQuery; @@ -24,7 +24,7 @@ namespace Swift { boost::shared_ptr createBrowseQuery(); boost::shared_ptr createRegisterQuery( - const String& name, int port, const LinkLocalServiceInfo& info); + const String& name, int port, const ByteArray& info); boost::shared_ptr createResolveServiceQuery( const DNSSDServiceID&); boost::shared_ptr createResolveHostnameQuery( diff --git a/Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDRegisterQuery.h b/Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDRegisterQuery.h index b4646fd..82ec623 100644 --- a/Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDRegisterQuery.h +++ b/Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDRegisterQuery.h @@ -2,7 +2,7 @@ #include "Swiften/LinkLocal/DNSSD/Fake/FakeDNSSDQuery.h" #include "Swiften/LinkLocal/DNSSD/DNSSDRegisterQuery.h" -#include "Swiften/LinkLocal/LinkLocalServiceInfo.h" +#include "Swiften/Base/ByteArray.h" #include "Swiften/Base/String.h" namespace Swift { @@ -10,14 +10,15 @@ namespace Swift { class FakeDNSSDRegisterQuery : public DNSSDRegisterQuery, public FakeDNSSDQuery { public: - FakeDNSSDRegisterQuery(const String& name, int port, const LinkLocalServiceInfo& info, boost::shared_ptr querier) : FakeDNSSDQuery(querier), name(name), port(port), info(info) { + FakeDNSSDRegisterQuery(const String& name, int port, const ByteArray& info, boost::shared_ptr querier) : FakeDNSSDQuery(querier), name(name), port(port), info(info) { } void registerService() { run(); } - void updateServiceInfo(const LinkLocalServiceInfo&) { + void updateServiceInfo(const ByteArray& i) { + info = i; } void unregisterService() { @@ -26,6 +27,6 @@ namespace Swift { String name; int port; - LinkLocalServiceInfo info; + ByteArray info; }; } diff --git a/Swiften/LinkLocal/LinkLocalService.h b/Swiften/LinkLocal/LinkLocalService.h index 0c675a3..37f2130 100644 --- a/Swiften/LinkLocal/LinkLocalService.h +++ b/Swiften/LinkLocal/LinkLocalService.h @@ -30,8 +30,8 @@ namespace Swift { return info.host; } - const LinkLocalServiceInfo& getInfo() const { - return info.info; + LinkLocalServiceInfo getInfo() const { + return LinkLocalServiceInfo::createFromTXTRecord(info.info); } private: diff --git a/Swiften/LinkLocal/LinkLocalServiceBrowser.cpp b/Swiften/LinkLocal/LinkLocalServiceBrowser.cpp index aed917a..265acc1 100644 --- a/Swiften/LinkLocal/LinkLocalServiceBrowser.cpp +++ b/Swiften/LinkLocal/LinkLocalServiceBrowser.cpp @@ -57,7 +57,7 @@ bool LinkLocalServiceBrowser::isRegistered() const { void LinkLocalServiceBrowser::registerService(const String& name, int port, const LinkLocalServiceInfo& info) { assert(!registerQuery); - registerQuery = querier->createRegisterQuery(name, port, info); + registerQuery = querier->createRegisterQuery(name, port, info.toTXTRecord()); registerQuery->onRegisterFinished.connect( boost::bind(&LinkLocalServiceBrowser::handleRegisterFinished, this, _1)); registerQuery->registerService(); diff --git a/Swiften/LinkLocal/UnitTest/LinkLocalServiceBrowserTest.cpp b/Swiften/LinkLocal/UnitTest/LinkLocalServiceBrowserTest.cpp index 7e2dd26..ab42834 100644 --- a/Swiften/LinkLocal/UnitTest/LinkLocalServiceBrowserTest.cpp +++ b/Swiften/LinkLocal/UnitTest/LinkLocalServiceBrowserTest.cpp @@ -34,8 +34,8 @@ class LinkLocalServiceBrowserTest : public CppUnit::TestFixture { eventLoop = new DummyEventLoop(); querier = boost::shared_ptr(new FakeDNSSDQuerier()); testServiceID = new DNSSDServiceID("foo", "bar.local"); - testServiceInfo = new DNSSDResolveServiceQuery::Result("_presence._tcp.bar.local", "xmpp.bar.local", 1234, LinkLocalServiceInfo()); - testServiceInfo2 = new DNSSDResolveServiceQuery::Result("_presence.tcp.bar.local", "xmpp.foo.local", 2345, LinkLocalServiceInfo()); + testServiceInfo = new DNSSDResolveServiceQuery::Result("_presence._tcp.bar.local", "xmpp.bar.local", 1234, LinkLocalServiceInfo().toTXTRecord()); + testServiceInfo2 = new DNSSDResolveServiceQuery::Result("_presence.tcp.bar.local", "xmpp.foo.local", 2345, LinkLocalServiceInfo().toTXTRecord()); } void tearDown() { -- cgit v0.10.2-6-g49f6