diff options
Diffstat (limited to 'Swiften/LinkLocal/BonjourBrowseQuery.h')
-rw-r--r-- | Swiften/LinkLocal/BonjourBrowseQuery.h | 15 |
1 files changed, 9 insertions, 6 deletions
diff --git a/Swiften/LinkLocal/BonjourBrowseQuery.h b/Swiften/LinkLocal/BonjourBrowseQuery.h index 6a50a61..6db108d 100644 --- a/Swiften/LinkLocal/BonjourBrowseQuery.h +++ b/Swiften/LinkLocal/BonjourBrowseQuery.h @@ -2,6 +2,7 @@ #include "Swiften/LinkLocal/BonjourQuery.h" #include "Swiften/LinkLocal/DNSSDBrowseQuery.h" +#include "Swiften/EventLoop/MainEventLoop.h" namespace Swift { class BonjourQuerier; @@ -11,7 +12,7 @@ namespace Swift { BonjourBrowseQuery(boost::shared_ptr<BonjourQuerier> q) : BonjourQuery(q) { DNSServiceErrorType result = DNSServiceBrowse( &sdRef, 0, 0, "_presence._tcp", 0, - &BonjourBrowseQuery::handleServiceDiscovered, this); + &BonjourBrowseQuery::handleServiceDiscoveredStatic, this); if (result != kDNSServiceErr_NoError) { std::cout << "Error" << std::endl; // TODO @@ -28,19 +29,21 @@ namespace Swift { } private: - static void handleServiceDiscovered(DNSServiceRef, DNSServiceFlags flags, uint32_t interfaceIndex, DNSServiceErrorType errorCode, const char *name, const char *type, const char *domain, void *context) { + static void handleServiceDiscoveredStatic(DNSServiceRef, DNSServiceFlags flags, uint32_t interfaceIndex, DNSServiceErrorType errorCode, const char *name, const char *type, const char *domain, void *context) { + static_cast<BonjourBrowseQuery*>(context)->handleServiceDiscovered(flags, interfaceIndex, errorCode, name, type, domain); + } + + void handleServiceDiscovered(DNSServiceFlags flags, uint32_t interfaceIndex, DNSServiceErrorType errorCode, const char *name, const char *type, const char *domain) { if (errorCode != kDNSServiceErr_NoError) { return; } else { - BonjourBrowseQuery* query = static_cast<BonjourBrowseQuery*>(context); LinkLocalServiceID service(name, type, domain, interfaceIndex); - std::cout << "Service discovered: " << name << std::endl; if (flags & kDNSServiceFlagsAdd) { - query->onServiceAdded(service); + MainEventLoop::postEvent(boost::bind(boost::ref(onServiceAdded), service), shared_from_this()); } else { - query->onServiceRemoved(service); + MainEventLoop::postEvent(boost::bind(boost::ref(onServiceRemoved), service), shared_from_this()); } } } |