1
0
mirror of https://github.com/clementine-player/Clementine synced 2025-02-06 06:03:23 +01:00

Add mDNS service publishing on Mac.

This commit is contained in:
John Maguire 2013-01-16 15:26:35 +01:00
parent 0e226cc34b
commit 7d09548243
4 changed files with 99 additions and 0 deletions

View File

@ -843,6 +843,7 @@ optional_source(APPLE
core/mac_startup.mm
core/scoped_nsautorelease_pool.mm
devices/macdevicelister.mm
networkremote/bonjour.mm
ui/globalshortcutgrabber.mm
ui/macscreensaver.cpp
ui/macsystemtrayicon.mm

View File

@ -0,0 +1,26 @@
#ifndef BONJOUR_H
#define BONJOUR_H
#include "zeroconf.h"
#ifdef __OBJC__
@class NetServicePublicationDelegate;
#else
class NetServicePublicationDelegate;
#endif // __OBJC__
class Bonjour : public Zeroconf {
public:
Bonjour();
virtual ~Bonjour();
virtual void Publish(
const QString& domain,
const QString& type,
const QString& name,
quint16 port);
private:
NetServicePublicationDelegate* delegate_;
};
#endif // BONJOUR_H

View File

@ -0,0 +1,65 @@
#include "bonjour.h"
#import <Foundation/NSNetServices.h>
#import <Foundation/NSString.h>
#include "core/logging.h"
@interface NetServicePublicationDelegate : NSObject<NSNetServiceDelegate> {
}
- (void)netServiceWillPublish:(NSNetService*)netService;
- (void)netService:(NSNetService*)netService
didNotPublish:(NSDictionary*)errorDict;
- (void)netServiceDidStop:(NSNetService*)netService;
@end
@implementation NetServicePublicationDelegate
- (void)netServiceWillPublish: (NSNetService*)netService {
qLog(Debug) << "Publishing:" << [[netService name] UTF8String];
}
- (void)netService: (NSNetService*)netServie didNotPublish: (NSDictionary*)errorDict {
qLog(Debug) << "Failed to publish remote service with Bonjour";
NSLog(@"%@", errorDict);
}
- (void)netServiceDidStop: (NSNetService*)netService {
qLog(Debug) << "Unpublished:" << [[netService name] UTF8String];
}
@end
namespace {
NSString* NSStringFromQString(const QString& s) {
return [[NSString alloc] initWithUTF8String: s.toUtf8().constData()];
}
}
Bonjour::Bonjour()
: delegate_([[NetServicePublicationDelegate alloc] init]) {
}
Bonjour::~Bonjour() {
[delegate_ release];
}
void Bonjour::Publish(
const QString& domain,
const QString& type,
const QString& name,
quint16 port) {
NSNetService* service = [[NSNetService alloc]
initWithDomain: NSStringFromQString(domain)
type: NSStringFromQString(type)
name: NSStringFromQString(name)
port: port];
if (service) {
[service setDelegate: delegate_];
[service publish];
}
}

View File

@ -6,6 +6,10 @@
#include "avahi.h"
#endif
#ifdef Q_OS_DARWIN
#include "bonjour.h"
#endif
Zeroconf* Zeroconf::sInstance = NULL;
Zeroconf::~Zeroconf() {
@ -17,6 +21,9 @@ Zeroconf* Zeroconf::GetZeroconf() {
#ifdef HAVE_DBUS
sInstance = new Avahi;
#endif // HAVE_DBUS
#ifdef Q_OS_DARWIN
sInstance = new Bonjour;
#endif
}
return sInstance;