aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2013-01-27 22:18:45 +0100
committerMax Kellermann <max@duempel.org>2013-01-27 22:38:14 +0100
commit95c3f57b3027e0961a1e32036dcce0383fb5e6ee (patch)
treed9279be8c6c3bd46f95b674e8e59a84879f8de34
parent068f191c0d9459554db536ac3d7f64f9b9338381 (diff)
downloadmpd-95c3f57b3027e0961a1e32036dcce0383fb5e6ee.tar.gz
mpd-95c3f57b3027e0961a1e32036dcce0383fb5e6ee.tar.xz
mpd-95c3f57b3027e0961a1e32036dcce0383fb5e6ee.zip
zeroconf: convert to C++
Diffstat (limited to '')
-rw-r--r--Makefile.am9
-rw-r--r--src/Main.cxx6
-rw-r--r--src/ZeroconfAvahi.cxx (renamed from src/zeroconf-avahi.c)16
-rw-r--r--src/ZeroconfAvahi.hxx29
-rw-r--r--src/ZeroconfBonjour.cxx (renamed from src/zeroconf-bonjour.c)15
-rw-r--r--src/ZeroconfBonjour.hxx29
-rw-r--r--src/ZeroconfGlue.cxx (renamed from src/zeroconf.c)19
-rw-r--r--src/ZeroconfGlue.hxx (renamed from src/zeroconf.h)22
-rw-r--r--src/ZeroconfInternal.hxx (renamed from src/zeroconf-internal.h)8
9 files changed, 111 insertions, 42 deletions
diff --git a/Makefile.am b/Makefile.am
index ee57c752d..cf023a6bd 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -117,7 +117,6 @@ mpd_headers = \
src/uri.h \
src/utils.h \
src/string_util.h \
- src/zeroconf.h src/zeroconf-internal.h \
src/timer.h \
src/mpd_error.h
@@ -681,14 +680,16 @@ endif
if HAVE_ZEROCONF
-src_mpd_SOURCES += src/zeroconf.c
+src_mpd_SOURCES += \
+ src/ZeroconfInternal.hxx \
+ src/ZeroconfGlue.cxx src/ZeroconfGlue.hxx
if HAVE_AVAHI
-src_mpd_SOURCES += src/zeroconf-avahi.c
+src_mpd_SOURCES += src/ZeroconfAvahi.cxx src/ZeroconfAvahi.hxx
endif
if HAVE_BONJOUR
-src_mpd_SOURCES += src/zeroconf-bonjour.c
+src_mpd_SOURCES += src/ZeroconfBonjour.cxx src/ZeroconfBonjour.hxx
endif
endif
diff --git a/src/Main.cxx b/src/Main.cxx
index 6cf9c3457..828462019 100644
--- a/src/Main.cxx
+++ b/src/Main.cxx
@@ -49,6 +49,7 @@
#include "IOThread.hxx"
#include "fs/Path.hxx"
#include "PlaylistRegistry.hxx"
+#include "ZeroconfGlue.hxx"
extern "C" {
#include "daemon.h"
@@ -56,7 +57,6 @@ extern "C" {
#include "audio_config.h"
#include "pcm_resample.h"
#include "decoder_list.h"
-#include "zeroconf.h"
}
#include "mpd_error.h"
@@ -490,7 +490,7 @@ int mpd_main(int argc, char *argv[])
return EXIT_FAILURE;
}
- initZeroconf();
+ ZeroconfInit();
player_create(&global_partition->pc);
@@ -551,7 +551,7 @@ int mpd_main(int argc, char *argv[])
}
global_partition->pc.Kill();
- finishZeroconf();
+ ZeroconfDeinit();
listen_global_finish();
delete client_list;
diff --git a/src/zeroconf-avahi.c b/src/ZeroconfAvahi.cxx
index d2c6c084c..8fa745a69 100644
--- a/src/zeroconf-avahi.c
+++ b/src/ZeroconfAvahi.cxx
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2011 The Music Player Daemon Project
+ * Copyright (C) 2003-2013 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
@@ -18,7 +18,8 @@
*/
#include "config.h"
-#include "zeroconf-internal.h"
+#include "ZeroconfAvahi.hxx"
+#include "ZeroconfInternal.hxx"
#include "Listen.hxx"
#include "mpd_error.h"
@@ -116,7 +117,8 @@ static void avahiRegisterService(AvahiClient * c)
* if that's better. */
ret = avahi_entry_group_add_service(avahiGroup,
AVAHI_IF_UNSPEC, AVAHI_PROTO_UNSPEC,
- 0, avahiName, SERVICE_TYPE, NULL,
+ AvahiPublishFlags(0),
+ avahiName, SERVICE_TYPE, NULL,
NULL, listen_port, NULL);
if (ret < 0) {
g_warning("Failed to add service %s: %s", SERVICE_TYPE,
@@ -213,7 +215,8 @@ static void avahiClientCallback(AvahiClient * c, AvahiClientState state,
}
}
-void init_avahi(const char *serviceName)
+void
+AvahiInit(const char *serviceName)
{
int error;
g_debug("Initializing interface");
@@ -234,11 +237,12 @@ void init_avahi(const char *serviceName)
if (!avahiClient) {
g_warning("Failed to create client: %s",
avahi_strerror(error));
- avahi_finish();
+ AvahiDeinit();
}
}
-void avahi_finish(void)
+void
+AvahiDeinit(void)
{
g_debug("Shutting down interface");
diff --git a/src/ZeroconfAvahi.hxx b/src/ZeroconfAvahi.hxx
new file mode 100644
index 000000000..2db2523c3
--- /dev/null
+++ b/src/ZeroconfAvahi.hxx
@@ -0,0 +1,29 @@
+/*
+ * Copyright (C) 2003-2011 The Music Player Daemon Project
+ * http://www.musicpd.org
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef MPD_ZEROCONF_AVAHI_HXX
+#define MPD_ZEROCONF_AVAHI_HXX
+
+void
+AvahiInit(const char *service_name);
+
+void
+AvahiDeinit();
+
+#endif
diff --git a/src/zeroconf-bonjour.c b/src/ZeroconfBonjour.cxx
index f3776ca29..929ff6108 100644
--- a/src/zeroconf-bonjour.c
+++ b/src/ZeroconfBonjour.cxx
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2011 The Music Player Daemon Project
+ * Copyright (C) 2003-2013 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
@@ -18,7 +18,8 @@
*/
#include "config.h"
-#include "zeroconf-internal.h"
+#include "ZeroconfBonjour.hxx"
+#include "ZeroconfInternal.hxx"
#include "Listen.hxx"
#include <glib.h>
@@ -42,7 +43,7 @@ dnsRegisterCallback(G_GNUC_UNUSED DNSServiceRef sdRef,
if (errorCode != kDNSServiceErr_NoError) {
g_warning("Failed to register zeroconf service.");
- bonjour_finish();
+ BonjourDeinit();
} else {
g_debug("Registered zeroconf service with name '%s'", name);
}
@@ -58,10 +59,11 @@ bonjour_channel_event(G_GNUC_UNUSED GIOChannel *source,
return dnsReference != NULL;
}
-void init_zeroconf_osx(const char *serviceName)
+void
+BonjourInit(const char *service_name)
{
DNSServiceErrorType error = DNSServiceRegister(&dnsReference,
- 0, 0, serviceName,
+ 0, 0, service_name,
SERVICE_TYPE, NULL, NULL,
g_htons(listen_port), 0,
NULL,
@@ -82,7 +84,8 @@ void init_zeroconf_osx(const char *serviceName)
g_io_add_watch(bonjour_channel, G_IO_IN, bonjour_channel_event, NULL);
}
-void bonjour_finish(void)
+void
+BonjourDeinit()
{
if (bonjour_channel != NULL) {
g_io_channel_unref(bonjour_channel);
diff --git a/src/ZeroconfBonjour.hxx b/src/ZeroconfBonjour.hxx
new file mode 100644
index 000000000..5d2470eb3
--- /dev/null
+++ b/src/ZeroconfBonjour.hxx
@@ -0,0 +1,29 @@
+/*
+ * Copyright (C) 2003-2013 The Music Player Daemon Project
+ * http://www.musicpd.org
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef MPD_ZEROCONF_BONJOUR_HXX
+#define MPD_ZEROCONF_BONJOUR_HXX
+
+void
+BonjourInit(const char *service_name);
+
+void
+BonjourDeinit();
+
+#endif
diff --git a/src/zeroconf.c b/src/ZeroconfGlue.cxx
index a4611b67e..3facd5762 100644
--- a/src/zeroconf.c
+++ b/src/ZeroconfGlue.cxx
@@ -18,8 +18,9 @@
*/
#include "config.h"
-#include "zeroconf.h"
-#include "zeroconf-internal.h"
+#include "ZeroconfGlue.hxx"
+#include "ZeroconfAvahi.hxx"
+#include "ZeroconfBonjour.hxx"
#include "conf.h"
#include "Listen.hxx"
@@ -34,7 +35,8 @@
static int zeroconfEnabled;
-void initZeroconf(void)
+void
+ZeroconfInit()
{
const char *serviceName;
@@ -52,24 +54,25 @@ void initZeroconf(void)
serviceName = config_get_string(CONF_ZEROCONF_NAME, SERVICE_NAME);
#ifdef HAVE_AVAHI
- init_avahi(serviceName);
+ AvahiInit(serviceName);
#endif
#ifdef HAVE_BONJOUR
- init_zeroconf_osx(serviceName);
+ BonjourInit(serviceName);
#endif
}
-void finishZeroconf(void)
+void
+ZeroconfDeinit()
{
if (!zeroconfEnabled)
return;
#ifdef HAVE_AVAHI
- avahi_finish();
+ AvahiDeinit();
#endif /* HAVE_AVAHI */
#ifdef HAVE_BONJOUR
- bonjour_finish();
+ BonjourDeinit();
#endif
}
diff --git a/src/zeroconf.h b/src/ZeroconfGlue.hxx
index 8e33a3d89..dcd7b81c0 100644
--- a/src/zeroconf.h
+++ b/src/ZeroconfGlue.hxx
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2003-2011 The Music Player Daemon Project
+ * Copyright (C) 2003-2013 The Music Player Daemon Project
* http://www.musicpd.org
*
* This program is free software; you can redistribute it and/or modify
@@ -17,20 +17,28 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
-#ifndef MPD_ZEROCONF_H
-#define MPD_ZEROCONF_H
+#ifndef MPD_ZEROCONF_GLUE_HXX
+#define MPD_ZEROCONF_GLUE_HXX
#include "check.h"
#ifdef HAVE_ZEROCONF
-void initZeroconf(void);
-void finishZeroconf(void);
+void
+ZeroconfInit();
+
+void
+ZeroconfDeinit();
#else /* ! HAVE_ZEROCONF */
-static void initZeroconf(void) { }
-static void finishZeroconf(void) { }
+static inline void
+ZeroconfInit()
+{}
+
+static inline void
+ZeroconfDeinit()
+{}
#endif /* ! HAVE_ZEROCONF */
diff --git a/src/zeroconf-internal.h b/src/ZeroconfInternal.hxx
index 983e5c556..2eadcff6e 100644
--- a/src/zeroconf-internal.h
+++ b/src/ZeroconfInternal.hxx
@@ -23,12 +23,4 @@
/* The dns-sd service type qualifier to publish */
#define SERVICE_TYPE "_mpd._tcp"
-void init_avahi(const char *service_name);
-
-void avahi_finish(void);
-
-void init_zeroconf_osx(const char *service_name);
-
-void bonjour_finish(void);
-
#endif