summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRemko Tronçon <git@el-tramo.be>2009-07-25 09:37:42 (GMT)
committerRemko Tronçon <git@el-tramo.be>2009-07-25 09:37:42 (GMT)
commit0f77a684b42f25052eb1cfa688721e321526a90d (patch)
tree226c07deff7a663f8aefdfc8814e9ecd04085999 /Swiften/LinkLocal/DNSSD/Bonjour/BonjourRegisterQuery.h
parentb33a2937fe4a3cae0017892ad7f5c27b8a6f976d (diff)
downloadswift-0f77a684b42f25052eb1cfa688721e321526a90d.zip
swift-0f77a684b42f25052eb1cfa688721e321526a90d.tar.bz2
Created DNSSD submodule for LinkLocal.
Diffstat (limited to 'Swiften/LinkLocal/DNSSD/Bonjour/BonjourRegisterQuery.h')
-rw-r--r--Swiften/LinkLocal/DNSSD/Bonjour/BonjourRegisterQuery.h50
1 files changed, 50 insertions, 0 deletions
diff --git a/Swiften/LinkLocal/DNSSD/Bonjour/BonjourRegisterQuery.h b/Swiften/LinkLocal/DNSSD/Bonjour/BonjourRegisterQuery.h
new file mode 100644
index 0000000..31e86fc
--- /dev/null
+++ b/Swiften/LinkLocal/DNSSD/Bonjour/BonjourRegisterQuery.h
@@ -0,0 +1,50 @@
+#pragma once
+
+#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"
+
+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());
+ }
+ }
+ };
+}