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/LinkLocal/BonjourPublishQuery.h
parent714e831bb9ea2b14cba3c2696c12e2e13b1bb9d7 (diff)
downloadswift-42e410208ca9aa8af5f27c85a6b33af488a0b6cc.zip
swift-42e410208ca9aa8af5f27c85a6b33af488a0b6cc.tar.bz2
More DNSSD framework.
Diffstat (limited to 'Swiften/LinkLocal/BonjourPublishQuery.h')
-rw-r--r--Swiften/LinkLocal/BonjourPublishQuery.h41
1 files changed, 41 insertions, 0 deletions
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)));
+ }
+ }
+ };
+}