summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2009-07-24 06:30:33 (GMT)
committerRemko Tronçon <git@el-tramo.be>2009-07-24 07:16:35 (GMT)
commit42e410208ca9aa8af5f27c85a6b33af488a0b6cc (patch)
tree42c7793effd1225ebe6617c7405cf64635530a53 /Swiften
parent714e831bb9ea2b14cba3c2696c12e2e13b1bb9d7 (diff)
downloadswift-42e410208ca9aa8af5f27c85a6b33af488a0b6cc.zip
swift-42e410208ca9aa8af5f27c85a6b33af488a0b6cc.tar.bz2
More DNSSD framework.
Diffstat (limited to 'Swiften')
-rw-r--r--Swiften/LinkLocal/BonjourBrowseQuery.h25
-rw-r--r--Swiften/LinkLocal/BonjourPublishQuery.h41
-rw-r--r--Swiften/LinkLocal/BonjourQuerier.cpp14
-rw-r--r--Swiften/LinkLocal/BonjourQuerier.h4
-rw-r--r--Swiften/LinkLocal/BonjourQuery.cpp2
-rw-r--r--Swiften/LinkLocal/DNSSDBrowseQuery.h3
-rw-r--r--Swiften/LinkLocal/DNSSDPublishQuery.cpp8
-rw-r--r--Swiften/LinkLocal/DNSSDPublishQuery.h17
-rw-r--r--Swiften/LinkLocal/Makefile.inc1
9 files changed, 95 insertions, 20 deletions
diff --git a/Swiften/LinkLocal/BonjourBrowseQuery.h b/Swiften/LinkLocal/BonjourBrowseQuery.h
index 5b14d30..6a50a61 100644
--- a/Swiften/LinkLocal/BonjourBrowseQuery.h
+++ b/Swiften/LinkLocal/BonjourBrowseQuery.h
@@ -11,8 +11,9 @@ namespace Swift {
BonjourBrowseQuery(boost::shared_ptr<BonjourQuerier> q) : BonjourQuery(q) {
DNSServiceErrorType result = DNSServiceBrowse(
&sdRef, 0, 0, "_presence._tcp", 0,
- &BonjourBrowseQuery::handleServiceDiscoveredGlobal , this);
+ &BonjourBrowseQuery::handleServiceDiscovered, this);
if (result != kDNSServiceErr_NoError) {
+ std::cout << "Error" << std::endl;
// TODO
}
}
@@ -27,29 +28,21 @@ namespace Swift {
}
private:
- static void handleServiceDiscoveredGlobal(DNSServiceRef, DNSServiceFlags flags, uint32_t interfaceIndex, DNSServiceErrorType errorCode, const char *serviceName, const char *regtype, const char *replyDomain, void *context) {
- static_cast<BonjourBrowseQuery*>(context)->handleServiceDiscovered(flags, interfaceIndex, errorCode, serviceName, regtype, replyDomain);
- }
-
- void handleServiceDiscovered(
- DNSServiceFlags flags,
- uint32_t interfaceIndex,
- DNSServiceErrorType errorCode,
- const char *serviceName,
- const char *type,
- const char *domain) {
+ static void handleServiceDiscovered(DNSServiceRef, DNSServiceFlags flags, uint32_t interfaceIndex, DNSServiceErrorType errorCode, const char *name, const char *type, const char *domain, void *context) {
if (errorCode != kDNSServiceErr_NoError) {
return;
}
else {
- LinkLocalServiceID service(serviceName, type, domain, interfaceIndex);
+ BonjourBrowseQuery* query = static_cast<BonjourBrowseQuery*>(context);
+ LinkLocalServiceID service(name, type, domain, interfaceIndex);
+ std::cout << "Service discovered: " << name << std::endl;
if (flags & kDNSServiceFlagsAdd) {
- onServiceAdded(service);
+ query->onServiceAdded(service);
}
else {
- onServiceRemoved(service);
+ query->onServiceRemoved(service);
}
}
- }
+ }
};
}
diff --git a/Swiften/LinkLocal/BonjourPublishQuery.h b/Swiften/LinkLocal/BonjourPublishQuery.h
new file mode 100644
index 0000000..4e7fd2f
--- /dev/null
+++ b/Swiften/LinkLocal/BonjourPublishQuery.h
@@ -0,0 +1,41 @@
+#pragma once
+
+#include "Swiften/LinkLocal/BonjourQuery.h"
+#include "Swiften/LinkLocal/DNSSDPublishQuery.h"
+#include "Swiften/LinkLocal/LinkLocalServiceInfo.h"
+#include "Swiften/Base/ByteArray.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::handleServiceRegistered, this);
+ if (result != kDNSServiceErr_NoError) {
+ // TODO
+ std::cerr << "Error creating service registration" << std::endl;
+ }
+ }
+
+ void publish() {
+ run();
+ }
+
+ private:
+ static void handleServiceRegistered(DNSServiceRef, DNSServiceFlags, DNSServiceErrorType errorCode, const char *name, const char *regtype, const char *domain, void *context) {
+ std::cout << "Publish finished " << name << std::endl;
+ BonjourPublishQuery* query = static_cast<BonjourPublishQuery*>(context);
+ if (errorCode != kDNSServiceErr_NoError) {
+ query->onPublishFinished(boost::optional<LinkLocalServiceID>());
+ }
+ else {
+ query->onPublishFinished(boost::optional<LinkLocalServiceID>(LinkLocalServiceID(name, regtype, domain, 0)));
+ }
+ }
+ };
+}
diff --git a/Swiften/LinkLocal/BonjourQuerier.cpp b/Swiften/LinkLocal/BonjourQuerier.cpp
index 1ddbd9d..93259c1 100644
--- a/Swiften/LinkLocal/BonjourQuerier.cpp
+++ b/Swiften/LinkLocal/BonjourQuerier.cpp
@@ -7,6 +7,7 @@
#include "Swiften/EventLoop/MainEventLoop.h"
#include "Swiften/LinkLocal/BonjourBrowseQuery.h"
+#include "Swiften/LinkLocal/BonjourPublishQuery.h"
#include "Swiften/Base/foreach.h"
namespace Swift {
@@ -18,7 +19,6 @@ BonjourQuerier::BonjourQuerier() : stopRequested(false), thread(0) {
interruptSelectReadSocket = fds[0];
fcntl(interruptSelectReadSocket, F_SETFL, fcntl(interruptSelectReadSocket, F_GETFL)|O_NONBLOCK);
interruptSelectWriteSocket = fds[1];
- // TODO: Schedule thread
}
BonjourQuerier::~BonjourQuerier() {
@@ -29,6 +29,10 @@ 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()));
+}
+
void BonjourQuerier::addRunningQuery(boost::shared_ptr<BonjourQuery> query) {
{
boost::lock_guard<boost::mutex> lock(runningQueriesMutex);
@@ -74,14 +78,16 @@ void BonjourQuerier::run() {
int maxSocket;
{
boost::unique_lock<boost::mutex> lock(runningQueriesMutex);
- runningQueriesAvailableEvent.wait(lock);
if (runningQueries.empty()) {
- continue;
+ runningQueriesAvailableEvent.wait(lock);
+ if (runningQueries.empty()) {
+ continue;
+ }
}
// Run all running queries
FD_ZERO(&fdSet);
- int maxSocket = interruptSelectReadSocket;
+ maxSocket = interruptSelectReadSocket;
FD_SET(interruptSelectReadSocket, &fdSet);
foreach(const boost::shared_ptr<BonjourQuery>& query, runningQueries) {
diff --git a/Swiften/LinkLocal/BonjourQuerier.h b/Swiften/LinkLocal/BonjourQuerier.h
index 037d9e6..5f69ad6 100644
--- a/Swiften/LinkLocal/BonjourQuerier.h
+++ b/Swiften/LinkLocal/BonjourQuerier.h
@@ -8,9 +8,12 @@
#include "Swiften/EventLoop/EventOwner.h"
#include "Swiften/LinkLocal/DNSSDBrowseQuery.h"
+#include "Swiften/LinkLocal/DNSSDPublishQuery.h"
#include "Swiften/LinkLocal/BonjourQuery.h"
namespace Swift {
+ class LinkLocalServiceInfo;
+
class BonjourQuerier :
public boost::enable_shared_from_this<BonjourQuerier>,
public EventOwner {
@@ -19,6 +22,7 @@ namespace Swift {
~BonjourQuerier();
boost::shared_ptr<DNSSDBrowseQuery> createBrowseQuery();
+ boost::shared_ptr<DNSSDPublishQuery> createPublishQuery(const String& name, int port, const LinkLocalServiceInfo& info);
void start();
void stop();
diff --git a/Swiften/LinkLocal/BonjourQuery.cpp b/Swiften/LinkLocal/BonjourQuery.cpp
index a9c13fb..965a845 100644
--- a/Swiften/LinkLocal/BonjourQuery.cpp
+++ b/Swiften/LinkLocal/BonjourQuery.cpp
@@ -11,7 +11,9 @@ BonjourQuery::~BonjourQuery() {
}
void BonjourQuery::processResult() {
+ std::cout << "Process result" << std::endl;
boost::lock_guard<boost::mutex> lock(sdRefMutex);
+ std::cout << "DNSSDServiceProcessResult" << std::endl;
DNSServiceProcessResult(sdRef);
}
diff --git a/Swiften/LinkLocal/DNSSDBrowseQuery.h b/Swiften/LinkLocal/DNSSDBrowseQuery.h
index b46d968..e548ca5 100644
--- a/Swiften/LinkLocal/DNSSDBrowseQuery.h
+++ b/Swiften/LinkLocal/DNSSDBrowseQuery.h
@@ -9,6 +9,9 @@ namespace Swift {
public:
virtual ~DNSSDBrowseQuery();
+ virtual void startBrowsing() = 0;
+ virtual void stopBrowsing() = 0;
+
boost::signal<void (const LinkLocalServiceID&)> onServiceAdded;
boost::signal<void (const LinkLocalServiceID&)> onServiceRemoved;
};
diff --git a/Swiften/LinkLocal/DNSSDPublishQuery.cpp b/Swiften/LinkLocal/DNSSDPublishQuery.cpp
new file mode 100644
index 0000000..cf3fd25
--- /dev/null
+++ b/Swiften/LinkLocal/DNSSDPublishQuery.cpp
@@ -0,0 +1,8 @@
+#include "Swiften/LinkLocal/DNSSDPublishQuery.h"
+
+namespace Swift {
+
+DNSSDPublishQuery::~DNSSDPublishQuery() {
+}
+
+}
diff --git a/Swiften/LinkLocal/DNSSDPublishQuery.h b/Swiften/LinkLocal/DNSSDPublishQuery.h
new file mode 100644
index 0000000..48c86dc
--- /dev/null
+++ b/Swiften/LinkLocal/DNSSDPublishQuery.h
@@ -0,0 +1,17 @@
+#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/Makefile.inc b/Swiften/LinkLocal/Makefile.inc
index b43a7e4..093ac70 100644
--- a/Swiften/LinkLocal/Makefile.inc
+++ b/Swiften/LinkLocal/Makefile.inc
@@ -1,6 +1,7 @@
SWIFTEN_SOURCES += \
Swiften/LinkLocal/BonjourQuery.cpp \
Swiften/LinkLocal/DNSSDBrowseQuery.cpp \
+ Swiften/LinkLocal/DNSSDPublishQuery.cpp \
Swiften/LinkLocal/DNSSDServiceFactory.cpp \
Swiften/LinkLocal/BonjourQuerier.cpp \
Swiften/LinkLocal/PlatformDNSSDServiceFactory.cpp \