Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

[WIN32] fixed: receive response from the bonjour daemon if one is ava…

…ilable. for easier maintenance we only talk via one connection to the daemon now.
  • Loading branch information...
commit a642a6e17631a2a352f38f59d4c52edee9865b62 1 parent bdbe452
@wsoltys wsoltys authored committed
View
2  xbmc/network/Zeroconf.h
@@ -77,6 +77,8 @@ class CZeroconf
static void ReleaseInstance();
// returns false if ReleaseInstance() was called befores
static bool IsInstantiated() { return smp_instance != 0; }
+ // win32: process results from the bonjour daemon
+ virtual void ProcessResults() {}
protected:
//methods to implement for concrete implementations
View
66 xbmc/network/windows/ZeroconfWIN.cpp
@@ -27,11 +27,15 @@
#include <utils/log.h>
#include "dialogs/GUIDialogKaiToast.h"
#include "guilib/LocalizeStrings.h"
+#include "win32/WIN32Util.h"
#pragma comment(lib, "dnssd.lib")
+extern HWND g_hWnd;
+
CZeroconfWIN::CZeroconfWIN()
{
+ m_service = NULL;
}
CZeroconfWIN::~CZeroconfWIN()
@@ -63,8 +67,22 @@ bool CZeroconfWIN::doPublishService(const std::string& fcr_identifier,
{
DNSServiceRef netService = NULL;
TXTRecordRef txtRecord;
+ DNSServiceErrorType err;
TXTRecordCreate(&txtRecord, 0, NULL);
+ if(m_service == NULL)
+ {
+ err = DNSServiceCreateConnection(&m_service);
+ if (err != kDNSServiceErr_NoError)
+ {
+ CLog::Log(LOGERROR, "ZeroconfWIN: DNSServiceCreateConnection failed with error = %ld", (int) err);
+ return false;
+ }
+ err = WSAAsyncSelect( (SOCKET) DNSServiceRefSockFD( m_service ), g_hWnd, BONJOUR_EVENT, FD_READ | FD_CLOSE );
+ if (err != kDNSServiceErr_NoError)
+ CLog::Log(LOGERROR, "ZeroconfWIN: WSAAsyncSelect failed with error = %ld", (int) err);
+ }
+
CLog::Log(LOGDEBUG, "ZeroconfWIN: identifier: %s type: %s name:%s port:%i", fcr_identifier.c_str(), fcr_type.c_str(), fcr_name.c_str(), f_port);
//add txt records
@@ -78,8 +96,12 @@ bool CZeroconfWIN::doPublishService(const std::string& fcr_identifier,
}
}
- DNSServiceErrorType err = DNSServiceRegister(&netService, 0, 0, fcr_name.c_str(), fcr_type.c_str(), NULL, NULL, htons(f_port), TXTRecordGetLength(&txtRecord), TXTRecordGetBytesPtr(&txtRecord), registerCallback, NULL);
-
+ {
+ CSingleLock lock(m_data_guard);
+ netService = m_service;
+ err = DNSServiceRegister(&netService, kDNSServiceFlagsShareConnection, 0, fcr_name.c_str(), fcr_type.c_str(), NULL, NULL, htons(f_port), TXTRecordGetLength(&txtRecord), TXTRecordGetBytesPtr(&txtRecord), registerCallback, NULL);
+ }
+
if (err != kDNSServiceErr_NoError)
{
// Something went wrong so lets clean up.
@@ -87,14 +109,9 @@ bool CZeroconfWIN::doPublishService(const std::string& fcr_identifier,
DNSServiceRefDeallocate(netService);
CLog::Log(LOGERROR, "ZeroconfWIN: DNSServiceRegister returned (error = %ld)", (int) err);
- }
+ }
else
{
- err = DNSServiceProcessResult(netService);
-
- if (err != kDNSServiceErr_NoError)
- CLog::Log(LOGERROR, "ZeroconfWIN: DNSServiceProcessResult returned (error = %ld)", (int) err);
-
CSingleLock lock(m_data_guard);
m_services.insert(make_pair(fcr_identifier, netService));
}
@@ -112,19 +129,31 @@ bool CZeroconfWIN::doRemoveService(const std::string& fcr_ident)
{
DNSServiceRefDeallocate(it->second);
m_services.erase(it);
+ CLog::Log(LOGDEBUG, "ZeroconfWIN: Removed service %s", fcr_ident.c_str());
return true;
- }
+ }
else
return false;
}
void CZeroconfWIN::doStop()
{
- CSingleLock lock(m_data_guard);
- CLog::Log(LOGDEBUG, "ZeroconfWIN: Shutdown services");
- for(tServiceMap::iterator it = m_services.begin(); it != m_services.end(); ++it)
- DNSServiceRefDeallocate(it->second);
- m_services.clear();
+ {
+ CSingleLock lock(m_data_guard);
+ CLog::Log(LOGDEBUG, "ZeroconfWIN: Shutdown services");
+ for(tServiceMap::iterator it = m_services.begin(); it != m_services.end(); ++it)
+ {
+ DNSServiceRefDeallocate(it->second);
+ CLog::Log(LOGDEBUG, "ZeroconfWIN: Removed service %s", it->first.c_str());
+ }
+ m_services.clear();
+ }
+ {
+ CSingleLock lock(m_data_guard);
+ WSAAsyncSelect( (SOCKET) DNSServiceRefSockFD( m_service ), g_hWnd, BONJOUR_EVENT, 0 );
+ DNSServiceRefDeallocate(m_service);
+ m_service = NULL;
+ }
}
void DNSSD_API CZeroconfWIN::registerCallback(DNSServiceRef sdref, const DNSServiceFlags flags, DNSServiceErrorType errorCode, const char *name, const char *regtype, const char *domain, void *context)
@@ -144,5 +173,12 @@ void DNSSD_API CZeroconfWIN::registerCallback(DNSServiceRef sdref, const DNSServ
CLog::Log(LOGDEBUG, "ZeroconfWIN: %s.%s%s Name in use, please choose another", name, regtype, domain);
else
CLog::Log(LOGDEBUG, "ZeroconfWIN: %s.%s%s error code %d", name, regtype, domain, errorCode);
-
}
+
+void CZeroconfWIN::ProcessResults()
+{
+ CSingleLock lock(m_data_guard);
+ DNSServiceErrorType err = DNSServiceProcessResult(m_service);
+ if (err != kDNSServiceErr_NoError)
+ CLog::Log(LOGERROR, "ZeroconfWIN: DNSServiceProcessResult returned (error = %ld)", (int) err);
+}
View
11 xbmc/network/windows/ZeroconfWIN.h
@@ -45,13 +45,22 @@ class CZeroconfWIN : public CZeroconf
bool IsZCdaemonRunning();
+ void ProcessResults();
+
private:
- static void DNSSD_API registerCallback(DNSServiceRef sdref, const DNSServiceFlags flags, DNSServiceErrorType errorCode, const char *name, const char *regtype, const char *domain, void *context);
+ static void DNSSD_API registerCallback(DNSServiceRef sdref,
+ const DNSServiceFlags flags,
+ DNSServiceErrorType errorCode,
+ const char *name,
+ const char *regtype,
+ const char *domain,
+ void *context);
//lock + data (accessed from runloop(main thread) + the rest)
CCriticalSection m_data_guard;
typedef std::map<std::string, DNSServiceRef> tServiceMap;
tServiceMap m_services;
+ DNSServiceRef m_service;
};
View
1  xbmc/win32/WIN32Util.h
@@ -38,6 +38,7 @@ enum Drive_Types
DVD_DRIVES
};
+#define BONJOUR_EVENT ( WM_USER + 0x100 ) // Message sent to the Window when a Bonjour event occurs.
class CWIN32Util
{
View
4 xbmc/windowing/windows/WinEventsWin32.cpp
@@ -43,6 +43,7 @@
#include "settings/AdvancedSettings.h"
#include "peripherals/Peripherals.h"
#include "utils/JobManager.h"
+#include "network/Zeroconf.h"
#ifdef _WIN32
@@ -704,6 +705,9 @@ LRESULT CALLBACK CWinEventsWin32::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, L
//some other app has painted over our window, mark everything as dirty
g_windowManager.MarkDirty();
break;
+ case BONJOUR_EVENT:
+ CZeroconf::GetInstance()->ProcessResults();
+ break;
}
return(DefWindowProc(hWnd, uMsg, wParam, lParam));
}
Please sign in to comment.
Something went wrong with that request. Please try again.