summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'Swiften')
-rw-r--r--Swiften/LinkLocal/AvahiDNSSDService.cpp2
-rw-r--r--Swiften/LinkLocal/AvahiDNSSDService.h2
-rw-r--r--Swiften/LinkLocal/DNSSDServiceFactory.cpp8
-rw-r--r--Swiften/LinkLocal/DNSSDServiceFactory.h15
-rw-r--r--Swiften/LinkLocal/LinkLocalServiceBrowser.cpp3
-rw-r--r--Swiften/LinkLocal/LinkLocalServiceBrowser.h3
-rw-r--r--Swiften/LinkLocal/Makefile.inc4
-rw-r--r--Swiften/LinkLocal/PlatformDNSSDServiceFactory.cpp38
-rw-r--r--Swiften/LinkLocal/PlatformDNSSDServiceFactory.h13
-rw-r--r--Swiften/LinkLocal/UnitTest/LinkLocalServiceBrowserTest.cpp34
-rw-r--r--Swiften/LinkLocal/UnitTest/MockDNSSDService.h15
11 files changed, 118 insertions, 19 deletions
diff --git a/Swiften/LinkLocal/AvahiDNSSDService.cpp b/Swiften/LinkLocal/AvahiDNSSDService.cpp
index 72039b7..fe9ac83 100644
--- a/Swiften/LinkLocal/AvahiDNSSDService.cpp
+++ b/Swiften/LinkLocal/AvahiDNSSDService.cpp
@@ -82,7 +82,7 @@ void AvahiDNSSDService::startResolvingService(const LinkLocalServiceID& service)
avahi_threaded_poll_unlock(threadedPoll);
}
-void AvahiDNSSDService::stopResolvingService(const Service& service) {
+void AvahiDNSSDService::stopResolvingService(const LinkLocalServiceID& service) {
avahi_threaded_poll_lock(threadedPoll);
ServiceResolverMap::iterator i = serviceResolvers.find(service);
diff --git a/Swiften/LinkLocal/AvahiDNSSDService.h b/Swiften/LinkLocal/AvahiDNSSDService.h
index a5be943..99a1d23 100644
--- a/Swiften/LinkLocal/AvahiDNSSDService.h
+++ b/Swiften/LinkLocal/AvahiDNSSDService.h
@@ -47,7 +47,7 @@ namespace Swift {
AvahiClient* client;
AvahiThreadedPoll* threadedPoll;
AvahiServiceBrowser* serviceBrowser;
- typedef std::map<Service, AvahiServiceResolver*> ServiceResolverMap;
+ typedef std::map<LinkLocalServiceID, AvahiServiceResolver*> ServiceResolverMap;
ServiceResolverMap serviceResolvers;
typedef std::map<String, HostAddress> HostnameAddressMap;
HostnameAddressMap hostnameAddresses;
diff --git a/Swiften/LinkLocal/DNSSDServiceFactory.cpp b/Swiften/LinkLocal/DNSSDServiceFactory.cpp
new file mode 100644
index 0000000..f53660a
--- /dev/null
+++ b/Swiften/LinkLocal/DNSSDServiceFactory.cpp
@@ -0,0 +1,8 @@
+#include "Swiften/LinkLocal/DNSSDServiceFactory.h"
+
+namespace Swift {
+
+DNSSDServiceFactory::~DNSSDServiceFactory() {
+}
+
+}
diff --git a/Swiften/LinkLocal/DNSSDServiceFactory.h b/Swiften/LinkLocal/DNSSDServiceFactory.h
new file mode 100644
index 0000000..6296165
--- /dev/null
+++ b/Swiften/LinkLocal/DNSSDServiceFactory.h
@@ -0,0 +1,15 @@
+#pragma once
+
+#include <boost/shared_ptr.hpp>
+
+namespace Swift {
+ class DNSSDService;
+
+ class DNSSDServiceFactory {
+ public:
+ virtual ~DNSSDServiceFactory();
+ virtual bool canCreate() const = 0;
+
+ virtual boost::shared_ptr<DNSSDService> createDNSSDService() = 0;
+ };
+}
diff --git a/Swiften/LinkLocal/LinkLocalServiceBrowser.cpp b/Swiften/LinkLocal/LinkLocalServiceBrowser.cpp
index fbc3022..904f8f0 100644
--- a/Swiften/LinkLocal/LinkLocalServiceBrowser.cpp
+++ b/Swiften/LinkLocal/LinkLocalServiceBrowser.cpp
@@ -6,7 +6,8 @@
namespace Swift {
-LinkLocalServiceBrowser::LinkLocalServiceBrowser(boost::shared_ptr<DNSSDService> service) : dnsSDService(service) {
+LinkLocalServiceBrowser::LinkLocalServiceBrowser(DNSSDServiceFactory* factory) {
+ dnsSDService = factory->createDNSSDService();
dnsSDService->onServiceAdded.connect(
boost::bind(&LinkLocalServiceBrowser::handleServiceAdded, this, _1));
dnsSDService->onServiceRemoved.connect(
diff --git a/Swiften/LinkLocal/LinkLocalServiceBrowser.h b/Swiften/LinkLocal/LinkLocalServiceBrowser.h
index 6107557..879b286 100644
--- a/Swiften/LinkLocal/LinkLocalServiceBrowser.h
+++ b/Swiften/LinkLocal/LinkLocalServiceBrowser.h
@@ -7,6 +7,7 @@
#include "Swiften/Base/String.h"
#include "Swiften/LinkLocal/DNSSDService.h"
+#include "Swiften/LinkLocal/DNSSDServiceFactory.h"
#include "Swiften/LinkLocal/LinkLocalService.h"
namespace Swift {
@@ -14,7 +15,7 @@ namespace Swift {
class LinkLocalServiceBrowser {
public:
- LinkLocalServiceBrowser(boost::shared_ptr<DNSSDService> service);
+ LinkLocalServiceBrowser(DNSSDServiceFactory*);
std::vector<LinkLocalService> getServices() const;
diff --git a/Swiften/LinkLocal/Makefile.inc b/Swiften/LinkLocal/Makefile.inc
index a890d0a..4bd1b0e 100644
--- a/Swiften/LinkLocal/Makefile.inc
+++ b/Swiften/LinkLocal/Makefile.inc
@@ -1,4 +1,6 @@
SWIFTEN_SOURCES += \
+ Swiften/LinkLocal/DNSSDServiceFactory.cpp \
+ Swiften/LinkLocal/PlatformDNSSDServiceFactory.cpp \
Swiften/LinkLocal/DNSSDService.cpp \
Swiften/LinkLocal/LinkLocalRoster.cpp \
Swiften/LinkLocal/LinkLocalServiceID.cpp \
@@ -8,7 +10,7 @@ SWIFTEN_SOURCES += \
Swiften/LinkLocal/OutgoingLinkLocalSession.cpp \
Swiften/LinkLocal/LinkLocalConnector.cpp
-ifeq ($(MACOSX),1)
+ifeq ($(HAVE_BONJOUR),yes)
SWIFTEN_SOURCES += \
Swiften/LinkLocal/AppleDNSSDService.cpp
endif
diff --git a/Swiften/LinkLocal/PlatformDNSSDServiceFactory.cpp b/Swiften/LinkLocal/PlatformDNSSDServiceFactory.cpp
new file mode 100644
index 0000000..df70506
--- /dev/null
+++ b/Swiften/LinkLocal/PlatformDNSSDServiceFactory.cpp
@@ -0,0 +1,38 @@
+#include "Swiften/LinkLocal/PlatformDNSSDServiceFactory.h"
+
+#include <cassert>
+
+#ifdef HAVE_SWIFTEN_CONFIG_H
+#include "Swiften/config.h"
+#endif
+#if defined(HAVE_AVAHI)
+#include "Swiften/LinkLocal/AvahiDNSSDService.h"
+#elif defined(HAVE_BONJOUR)
+#include "Swiften/LinkLocal/AppleDNSSDService.h"
+#endif
+
+namespace Swift {
+
+PlatformDNSSDServiceFactory::PlatformDNSSDServiceFactory() {
+}
+
+bool PlatformDNSSDServiceFactory::canCreate() const {
+#if defined(HAVE_AVAHI) || defined(HAVE_BONJOUR)
+ return true;
+#else
+ return false;
+#endif
+}
+
+boost::shared_ptr<DNSSDService> PlatformDNSSDServiceFactory::createDNSSDService() {
+#if defined(HAVE_AVAHI)
+ return boost::shared_ptr<DNSSDService>(new AvahiDNSSDService());
+#elif defined(HAVE_BONJOUR)
+ return boost::shared_ptr<DNSSDService>(new AppleDNSSDService());
+#else
+ assert(false);
+ return boost::shared_ptr<DNSSDService>();
+#endif
+}
+
+}
diff --git a/Swiften/LinkLocal/PlatformDNSSDServiceFactory.h b/Swiften/LinkLocal/PlatformDNSSDServiceFactory.h
new file mode 100644
index 0000000..9c4e4e6
--- /dev/null
+++ b/Swiften/LinkLocal/PlatformDNSSDServiceFactory.h
@@ -0,0 +1,13 @@
+#pragma once
+
+#include "Swiften/LinkLocal/DNSSDServiceFactory.h"
+
+namespace Swift {
+ class PlatformDNSSDServiceFactory : public DNSSDServiceFactory {
+ public:
+ PlatformDNSSDServiceFactory();
+
+ bool canCreate() const;
+ virtual boost::shared_ptr<DNSSDService> createDNSSDService();
+ };
+}
diff --git a/Swiften/LinkLocal/UnitTest/LinkLocalServiceBrowserTest.cpp b/Swiften/LinkLocal/UnitTest/LinkLocalServiceBrowserTest.cpp
index 59a113d..34f797c 100644
--- a/Swiften/LinkLocal/UnitTest/LinkLocalServiceBrowserTest.cpp
+++ b/Swiften/LinkLocal/UnitTest/LinkLocalServiceBrowserTest.cpp
@@ -9,7 +9,7 @@
#include "Swiften/LinkLocal/DNSSDService.h"
#include "Swiften/EventLoop/DummyEventLoop.h"
-// Test IP address change
+// Test canCreate() == false
using namespace Swift;
@@ -26,7 +26,7 @@ class LinkLocalServiceBrowserTest : public CppUnit::TestFixture {
void setUp() {
eventLoop = new DummyEventLoop();
- dnsSDService = boost::shared_ptr<MockDNSSDService>(new MockDNSSDService());
+ dnsSDServiceFactory = new MockDNSSDServiceFactory();
testServiceID = new LinkLocalServiceID("foo", "bar.local");
testServiceInfo = new DNSSDService::ResolveResult("xmpp.bar.local", 1234, LinkLocalServiceInfo());
testServiceInfo2 = new DNSSDService::ResolveResult("xmpp.foo.local", 2345, LinkLocalServiceInfo());
@@ -40,14 +40,15 @@ class LinkLocalServiceBrowserTest : public CppUnit::TestFixture {
delete testServiceInfo2;
delete testServiceInfo;
delete testServiceID;
+ delete dnsSDServiceFactory;
delete eventLoop;
}
void testServiceAdded() {
boost::shared_ptr<LinkLocalServiceBrowser> testling = createTestling();
- dnsSDService->setServiceInfo(*testServiceID,*testServiceInfo);
- dnsSDService->addService(*testServiceID);
+ dnsSDService()->setServiceInfo(*testServiceID,*testServiceInfo);
+ dnsSDService()->addService(*testServiceID);
eventLoop->processEvents();
CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(addedServices.size()));
@@ -64,7 +65,7 @@ class LinkLocalServiceBrowserTest : public CppUnit::TestFixture {
void testServiceAdded_NoServiceInfo() {
boost::shared_ptr<LinkLocalServiceBrowser> testling = createTestling();
- dnsSDService->addService(*testServiceID);
+ dnsSDService()->addService(*testServiceID);
eventLoop->processEvents();
CPPUNIT_ASSERT_EQUAL(0, static_cast<int>(addedServices.size()));
@@ -74,11 +75,11 @@ class LinkLocalServiceBrowserTest : public CppUnit::TestFixture {
void testServiceChanged() {
boost::shared_ptr<LinkLocalServiceBrowser> testling = createTestling();
- dnsSDService->setServiceInfo(*testServiceID,*testServiceInfo);
- dnsSDService->addService(*testServiceID);
+ dnsSDService()->setServiceInfo(*testServiceID,*testServiceInfo);
+ dnsSDService()->addService(*testServiceID);
eventLoop->processEvents();
- dnsSDService->setServiceInfo(*testServiceID,*testServiceInfo2);
+ dnsSDService()->setServiceInfo(*testServiceID,*testServiceInfo2);
eventLoop->processEvents();
CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(addedServices.size()));
@@ -94,13 +95,13 @@ class LinkLocalServiceBrowserTest : public CppUnit::TestFixture {
void testServiceRemoved() {
boost::shared_ptr<LinkLocalServiceBrowser> testling = createTestling();
- dnsSDService->setServiceInfo(*testServiceID,*testServiceInfo);
- dnsSDService->addService(*testServiceID);
+ dnsSDService()->setServiceInfo(*testServiceID,*testServiceInfo);
+ dnsSDService()->addService(*testServiceID);
eventLoop->processEvents();
- dnsSDService->removeService(*testServiceID);
+ dnsSDService()->removeService(*testServiceID);
eventLoop->processEvents();
- dnsSDService->setServiceInfo(*testServiceID,*testServiceInfo2);
+ dnsSDService()->setServiceInfo(*testServiceID,*testServiceInfo2);
eventLoop->processEvents();
CPPUNIT_ASSERT_EQUAL(1, static_cast<int>(addedServices.size()));
@@ -114,7 +115,7 @@ class LinkLocalServiceBrowserTest : public CppUnit::TestFixture {
private:
boost::shared_ptr<LinkLocalServiceBrowser> createTestling() {
boost::shared_ptr<LinkLocalServiceBrowser> testling(
- new LinkLocalServiceBrowser(dnsSDService));
+ new LinkLocalServiceBrowser(dnsSDServiceFactory));
testling->onServiceAdded.connect(boost::bind(
&LinkLocalServiceBrowserTest::handleServiceAdded, this, _1));
testling->onServiceChanged.connect(boost::bind(
@@ -136,9 +137,14 @@ class LinkLocalServiceBrowserTest : public CppUnit::TestFixture {
changedServices.push_back(service);
}
+ boost::shared_ptr<MockDNSSDService> dnsSDService() const {
+ CPPUNIT_ASSERT(dnsSDServiceFactory->services.size() > 0);
+ return dnsSDServiceFactory->services[0];
+ }
+
private:
DummyEventLoop* eventLoop;
- boost::shared_ptr<MockDNSSDService> dnsSDService;
+ MockDNSSDServiceFactory* dnsSDServiceFactory;
std::vector<LinkLocalServiceID> addedServices;
std::vector<LinkLocalServiceID> changedServices;
std::vector<LinkLocalServiceID> removedServices;
diff --git a/Swiften/LinkLocal/UnitTest/MockDNSSDService.h b/Swiften/LinkLocal/UnitTest/MockDNSSDService.h
index 56661ee..69ac06d 100644
--- a/Swiften/LinkLocal/UnitTest/MockDNSSDService.h
+++ b/Swiften/LinkLocal/UnitTest/MockDNSSDService.h
@@ -6,6 +6,7 @@
#include "Swiften/EventLoop/MainEventLoop.h"
#include "Swiften/LinkLocal/DNSSDService.h"
+#include "Swiften/LinkLocal/DNSSDServiceFactory.h"
namespace Swift {
class MockDNSSDService : public DNSSDService {
@@ -78,5 +79,19 @@ namespace Swift {
std::vector<LinkLocalServiceID> resolvingServices;
};
+ class MockDNSSDServiceFactory : public DNSSDServiceFactory {
+ public:
+ boost::shared_ptr<DNSSDService> createDNSSDService() {
+ boost::shared_ptr<MockDNSSDService> result(new MockDNSSDService());
+ services.push_back(result);
+ return result;
+ }
+
+ bool canCreate() const {
+ return true;
+ }
+
+ std::vector<boost::shared_ptr<MockDNSSDService> > services;
+ };
}