Add mDNS service publishing on Mac.
This commit is contained in:
parent
0e226cc34b
commit
7d09548243
@ -843,6 +843,7 @@ optional_source(APPLE
|
|||||||
core/mac_startup.mm
|
core/mac_startup.mm
|
||||||
core/scoped_nsautorelease_pool.mm
|
core/scoped_nsautorelease_pool.mm
|
||||||
devices/macdevicelister.mm
|
devices/macdevicelister.mm
|
||||||
|
networkremote/bonjour.mm
|
||||||
ui/globalshortcutgrabber.mm
|
ui/globalshortcutgrabber.mm
|
||||||
ui/macscreensaver.cpp
|
ui/macscreensaver.cpp
|
||||||
ui/macsystemtrayicon.mm
|
ui/macsystemtrayicon.mm
|
||||||
|
26
src/networkremote/bonjour.h
Normal file
26
src/networkremote/bonjour.h
Normal 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
|
65
src/networkremote/bonjour.mm
Normal file
65
src/networkremote/bonjour.mm
Normal 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];
|
||||||
|
}
|
||||||
|
}
|
@ -6,6 +6,10 @@
|
|||||||
#include "avahi.h"
|
#include "avahi.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef Q_OS_DARWIN
|
||||||
|
#include "bonjour.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
Zeroconf* Zeroconf::sInstance = NULL;
|
Zeroconf* Zeroconf::sInstance = NULL;
|
||||||
|
|
||||||
Zeroconf::~Zeroconf() {
|
Zeroconf::~Zeroconf() {
|
||||||
@ -17,6 +21,9 @@ Zeroconf* Zeroconf::GetZeroconf() {
|
|||||||
#ifdef HAVE_DBUS
|
#ifdef HAVE_DBUS
|
||||||
sInstance = new Avahi;
|
sInstance = new Avahi;
|
||||||
#endif // HAVE_DBUS
|
#endif // HAVE_DBUS
|
||||||
|
#ifdef Q_OS_DARWIN
|
||||||
|
sInstance = new Bonjour;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
return sInstance;
|
return sInstance;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user