configure.ac: Move the encoders before the audio outputs.
[mpd-mk.git] / src / zeroconf-bonjour.c
blob76b96eaf59f937c1c8591a69ce27ac53ae31045d
1 /*
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.
20 #include "config.h"
21 #include "zeroconf-internal.h"
22 #include "listen.h"
24 #include <glib.h>
26 #include <dns_sd.h>
28 #undef G_LOG_DOMAIN
29 #define G_LOG_DOMAIN "bonjour"
31 static DNSServiceRef dnsReference;
32 static GIOChannel *bonjour_channel;
34 static void
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.");
45 bonjour_finish();
46 } else {
47 g_debug("Registered zeroconf service with name '%s'", name);
51 static gboolean
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,
64 0, 0, serviceName,
65 SERVICE_TYPE, NULL, NULL,
66 htons(listen_port), 0,
67 NULL,
68 dnsRegisterCallback,
69 NULL);
71 if (error != kDNSServiceErr_NoError) {
72 g_warning("Failed to register zeroconf service.");
74 if (dnsReference) {
75 DNSServiceRefDeallocate(dnsReference);
76 dnsReference = NULL;
78 return;
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);
94 dnsReference = NULL;
95 g_debug("Deregistered Zeroconf service.");