summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2009-07-24 19:28:19 (GMT)
committerRemko Tronçon <git@el-tramo.be>2009-07-24 19:33:35 (GMT)
commitef4284acb29aca0bdf792ab40356c7955902e307 (patch)
tree0ccd86089c626f4d7aab02b0d64a6131e0b45a7d
parent8cad7cff0462d8a48a5bc9762ce6d6b62e74d0e5 (diff)
downloadswift-ef4284acb29aca0bdf792ab40356c7955902e307.zip
swift-ef4284acb29aca0bdf792ab40356c7955902e307.tar.bz2
LinkLocal: Publish->Register.
-rw-r--r--Swiften/LinkLocal/BonjourPublishQuery.h50
-rw-r--r--Swiften/LinkLocal/BonjourQuerier.cpp6
-rw-r--r--Swiften/LinkLocal/BonjourQuerier.h4
-rw-r--r--Swiften/LinkLocal/BonjourRegisterQuery.h50
-rw-r--r--Swiften/LinkLocal/DNSSDPublishQuery.cpp8
-rw-r--r--Swiften/LinkLocal/DNSSDPublishQuery.h17
-rw-r--r--Swiften/LinkLocal/DNSSDRegisterQuery.cpp8
-rw-r--r--Swiften/LinkLocal/DNSSDRegisterQuery.h20
-rw-r--r--Swiften/LinkLocal/Makefile.inc2
-rw-r--r--configure.in1
10 files changed, 85 insertions, 81 deletions
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<BonjourQuerier> 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<boost::mutex> 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<BonjourPublishQuery*>(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<LinkLocalServiceID>()), shared_from_this());
- }
- else {
- MainEventLoop::postEvent(boost::bind(boost::ref(onPublishFinished), boost::optional<LinkLocalServiceID>(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 <fcntl.h>
#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<DNSSDBrowseQuery> BonjourQuerier::createBrowseQuery() {
return boost::shared_ptr<DNSSDBrowseQuery>(new BonjourBrowseQuery(shared_from_this()));
}
-boost::shared_ptr<DNSSDPublishQuery> BonjourQuerier::createPublishQuery(const String& name, int port, const LinkLocalServiceInfo& info) {
- return boost::shared_ptr<DNSSDPublishQuery>(new BonjourPublishQuery(name, port, info, shared_from_this()));
+boost::shared_ptr<DNSSDRegisterQuery> BonjourQuerier::createRegisterQuery(const String& name, int port, const LinkLocalServiceInfo& info) {
+ return boost::shared_ptr<DNSSDRegisterQuery>(new BonjourRegisterQuery(name, port, info, shared_from_this()));
}
void BonjourQuerier::addRunningQuery(boost::shared_ptr<BonjourQuery> 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 <boost/thread/mutex.hpp>
#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<DNSSDBrowseQuery> createBrowseQuery();
- boost::shared_ptr<DNSSDPublishQuery> createPublishQuery(const String& name, int port, const LinkLocalServiceInfo& info);
+ boost::shared_ptr<DNSSDRegisterQuery> 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<BonjourQuerier> 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<boost::mutex> 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<BonjourRegisterQuery*>(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<LinkLocalServiceID>()), shared_from_this());
+ }
+ else {
+ MainEventLoop::postEvent(boost::bind(boost::ref(onRegisterFinished), boost::optional<LinkLocalServiceID>(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 <boost/signal.hpp>
-#include <boost/optional.hpp>
-
-#include "Swiften/LinkLocal/LinkLocalServiceID.h"
-
-namespace Swift {
- class DNSSDPublishQuery {
- public:
- virtual ~DNSSDPublishQuery();
-
- virtual void publish() = 0;
-
- boost::signal<void (boost::optional<LinkLocalServiceID>)> 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 <boost/signal.hpp>
+#include <boost/optional.hpp>
+
+#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<void (boost::optional<LinkLocalServiceID>)> 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)
;;
*)