Commit 95c3f57b authored by Max Kellermann's avatar Max Kellermann

zeroconf: convert to C++

parent 068f191c
......@@ -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
......
......@@ -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;
......
/*
* 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");
......
......@@ -17,21 +17,13 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifndef MPD_ZEROCONF_H
#define MPD_ZEROCONF_H
#ifndef MPD_ZEROCONF_AVAHI_HXX
#define MPD_ZEROCONF_AVAHI_HXX
#include "check.h"
void
AvahiInit(const char *service_name);
#ifdef HAVE_ZEROCONF
void initZeroconf(void);
void finishZeroconf(void);
#else /* ! HAVE_ZEROCONF */
static void initZeroconf(void) { }
static void finishZeroconf(void) { }
#endif /* ! HAVE_ZEROCONF */
void
AvahiDeinit();
#endif
/*
* 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);
......
/*
* 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
......@@ -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
}
/*
* 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_GLUE_HXX
#define MPD_ZEROCONF_GLUE_HXX
#include "check.h"
#ifdef HAVE_ZEROCONF
void
ZeroconfInit();
void
ZeroconfDeinit();
#else /* ! HAVE_ZEROCONF */
static inline void
ZeroconfInit()
{}
static inline void
ZeroconfDeinit()
{}
#endif /* ! HAVE_ZEROCONF */
#endif
......@@ -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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment