2 * Copyright (C) 2003-2010 The Music Player Daemon Project
3 * http://www.musicpd.org
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 #include "zeroconf-internal.h"
29 #define G_LOG_DOMAIN "bonjour"
31 static DNSServiceRef dnsReference
;
32 static GIOChannel
*bonjour_channel
;
35 dnsRegisterCallback(G_GNUC_UNUSED DNSServiceRef sdRef
,
36 G_GNUC_UNUSED DNSServiceFlags flags
,
37 DNSServiceErrorType errorCode
, const char *name
,
38 G_GNUC_UNUSED
const char *regtype
,
39 G_GNUC_UNUSED
const char *domain
,
40 G_GNUC_UNUSED
void *context
)
42 if (errorCode
!= kDNSServiceErr_NoError
) {
43 g_warning("Failed to register zeroconf service.");
47 g_debug("Registered zeroconf service with name '%s'", name
);
52 bonjour_channel_event(G_GNUC_UNUSED GIOChannel
*source
,
53 G_GNUC_UNUSED GIOCondition condition
,
54 G_GNUC_UNUSED gpointer data
)
56 DNSServiceProcessResult(dnsReference
);
58 return dnsReference
!= NULL
;
61 void init_zeroconf_osx(const char *serviceName
)
63 DNSServiceErrorType error
= DNSServiceRegister(&dnsReference
,
65 SERVICE_TYPE
, NULL
, NULL
,
66 htons(listen_port
), 0,
71 if (error
!= kDNSServiceErr_NoError
) {
72 g_warning("Failed to register zeroconf service.");
75 DNSServiceRefDeallocate(dnsReference
);
81 bonjour_channel
= g_io_channel_unix_new(DNSServiceRefSockFD(dnsReference
));
82 g_io_add_watch(bonjour_channel
, G_IO_IN
, bonjour_channel_event
, NULL
);
85 void bonjour_finish(void)
87 if (bonjour_channel
!= NULL
) {
88 g_io_channel_unref(bonjour_channel
);
89 bonjour_channel
= NULL
;
92 if (dnsReference
!= NULL
) {
93 DNSServiceRefDeallocate(dnsReference
);
95 g_debug("Deregistered Zeroconf service.");