zeroconf: return a publisher object
This commit is contained in:
parent
2059195ae9
commit
2d8ecd561b
@ -476,12 +476,15 @@ MainConfigured(const struct options &options, const ConfigData &raw_config)
|
|||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef HAVE_ZEROCONF
|
||||||
|
std::unique_ptr<ZeroconfHelper> zeroconf;
|
||||||
try {
|
try {
|
||||||
ZeroconfInit(raw_config, instance.event_loop);
|
zeroconf = ZeroconfInit(raw_config, instance.event_loop);
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
LogError(std::current_exception(),
|
LogError(std::current_exception(),
|
||||||
"Zeroconf initialization failed");
|
"Zeroconf initialization failed");
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef ENABLE_DATABASE
|
#ifdef ENABLE_DATABASE
|
||||||
if (create_db) {
|
if (create_db) {
|
||||||
@ -543,7 +546,9 @@ MainConfigured(const struct options &options, const ConfigData &raw_config)
|
|||||||
|
|
||||||
instance.BeginShutdownUpdate();
|
instance.BeginShutdownUpdate();
|
||||||
|
|
||||||
ZeroconfDeinit();
|
#ifdef HAVE_ZEROCONF
|
||||||
|
zeroconf.reset();
|
||||||
|
#endif
|
||||||
|
|
||||||
instance.BeginShutdownPartitions();
|
instance.BeginShutdownPartitions();
|
||||||
}
|
}
|
||||||
|
@ -18,6 +18,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "Glue.hxx"
|
#include "Glue.hxx"
|
||||||
|
#include "Helper.hxx"
|
||||||
#include "config/Data.hxx"
|
#include "config/Data.hxx"
|
||||||
#include "config/Option.hxx"
|
#include "config/Option.hxx"
|
||||||
#include "Listen.hxx"
|
#include "Listen.hxx"
|
||||||
@ -53,31 +54,19 @@ static constexpr Domain zeroconf_domain("zeroconf");
|
|||||||
|
|
||||||
#define DEFAULT_ZEROCONF_ENABLED 1
|
#define DEFAULT_ZEROCONF_ENABLED 1
|
||||||
|
|
||||||
static int zeroconfEnabled;
|
std::unique_ptr<ZeroconfHelper>
|
||||||
|
|
||||||
#ifdef HAVE_AVAHI
|
|
||||||
static std::unique_ptr<AvahiHelper> avahi_helper;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef HAVE_BONJOUR
|
|
||||||
static std::unique_ptr<BonjourHelper> bonjour_helper;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
void
|
|
||||||
ZeroconfInit(const ConfigData &config, [[maybe_unused]] EventLoop &loop)
|
ZeroconfInit(const ConfigData &config, [[maybe_unused]] EventLoop &loop)
|
||||||
{
|
{
|
||||||
const char *serviceName;
|
const char *serviceName;
|
||||||
|
|
||||||
zeroconfEnabled = config.GetBool(ConfigOption::ZEROCONF_ENABLED,
|
if (!config.GetBool(ConfigOption::ZEROCONF_ENABLED,
|
||||||
DEFAULT_ZEROCONF_ENABLED);
|
DEFAULT_ZEROCONF_ENABLED))
|
||||||
if (!zeroconfEnabled)
|
return nullptr;
|
||||||
return;
|
|
||||||
|
|
||||||
if (listen_port <= 0) {
|
if (listen_port <= 0) {
|
||||||
LogWarning(zeroconf_domain,
|
LogWarning(zeroconf_domain,
|
||||||
"No global port, disabling zeroconf");
|
"No global port, disabling zeroconf");
|
||||||
zeroconfEnabled = false;
|
return nullptr;
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
serviceName = config.GetString(ConfigOption::ZEROCONF_NAME,
|
serviceName = config.GetString(ConfigOption::ZEROCONF_NAME,
|
||||||
@ -96,22 +85,12 @@ ZeroconfInit(const ConfigData &config, [[maybe_unused]] EventLoop &loop)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef HAVE_AVAHI
|
#ifdef HAVE_AVAHI
|
||||||
avahi_helper = AvahiInit(loop, serviceName, listen_port);
|
return std::make_unique<ZeroconfHelper>(AvahiInit(loop, serviceName,
|
||||||
|
listen_port));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef HAVE_BONJOUR
|
#ifdef HAVE_BONJOUR
|
||||||
bonjour_helper = BonjourInit(loop, serviceName, listen_port);
|
return std::make_unique<ZeroconfHelper>(BonjourInit(loop, serviceName,
|
||||||
#endif
|
listen_port));
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
ZeroconfDeinit() noexcept
|
|
||||||
{
|
|
||||||
#ifdef HAVE_AVAHI
|
|
||||||
avahi_helper.reset();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef HAVE_BONJOUR
|
|
||||||
bonjour_helper.reset();
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
@ -20,32 +20,23 @@
|
|||||||
#ifndef MPD_ZEROCONF_GLUE_HXX
|
#ifndef MPD_ZEROCONF_GLUE_HXX
|
||||||
#define MPD_ZEROCONF_GLUE_HXX
|
#define MPD_ZEROCONF_GLUE_HXX
|
||||||
|
|
||||||
|
#include "Helper.hxx"
|
||||||
#include "config.h"
|
#include "config.h"
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
struct ConfigData;
|
struct ConfigData;
|
||||||
class EventLoop;
|
class EventLoop;
|
||||||
|
class ZeroconfHelper;
|
||||||
|
|
||||||
#ifdef HAVE_ZEROCONF
|
#ifdef HAVE_ZEROCONF
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Throws on error.
|
* Throws on error.
|
||||||
*/
|
*/
|
||||||
void
|
std::unique_ptr<ZeroconfHelper>
|
||||||
ZeroconfInit(const ConfigData &config, EventLoop &loop);
|
ZeroconfInit(const ConfigData &config, EventLoop &loop);
|
||||||
|
|
||||||
void
|
|
||||||
ZeroconfDeinit() noexcept;
|
|
||||||
|
|
||||||
#else /* ! HAVE_ZEROCONF */
|
|
||||||
|
|
||||||
static inline void
|
|
||||||
ZeroconfInit(const ConfigData &, EventLoop &)
|
|
||||||
{}
|
|
||||||
|
|
||||||
static inline void
|
|
||||||
ZeroconfDeinit() noexcept
|
|
||||||
{}
|
|
||||||
|
|
||||||
#endif /* ! HAVE_ZEROCONF */
|
#endif /* ! HAVE_ZEROCONF */
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
30
src/zeroconf/Helper.cxx
Normal file
30
src/zeroconf/Helper.cxx
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2003-2021 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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "Helper.hxx"
|
||||||
|
|
||||||
|
#ifdef HAVE_AVAHI
|
||||||
|
#include "avahi/Helper.hxx"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef HAVE_BONJOUR
|
||||||
|
#include "Bonjour.hxx"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
ZeroconfHelper::~ZeroconfHelper() noexcept = default;
|
47
src/zeroconf/Helper.hxx
Normal file
47
src/zeroconf/Helper.hxx
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2003-2021 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_HELPER_HXX
|
||||||
|
#define MPD_ZEROCONF_HELPER_HXX
|
||||||
|
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
|
class AvahiHelper;
|
||||||
|
class BonjourHelper;
|
||||||
|
|
||||||
|
class ZeroconfHelper final {
|
||||||
|
#ifdef HAVE_AVAHI
|
||||||
|
std::unique_ptr<AvahiHelper> helper;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef HAVE_BONJOUR
|
||||||
|
std::unique_ptr<BonjourHelper> helper;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
public:
|
||||||
|
template<typename T>
|
||||||
|
ZeroconfHelper(T &&_helper) noexcept
|
||||||
|
:helper(std::forward<T>(_helper)) {}
|
||||||
|
|
||||||
|
~ZeroconfHelper() noexcept;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
@ -36,6 +36,7 @@ if zeroconf_option == 'bonjour'
|
|||||||
zeroconf = static_library(
|
zeroconf = static_library(
|
||||||
'zeroconf_bonjour',
|
'zeroconf_bonjour',
|
||||||
'Glue.cxx',
|
'Glue.cxx',
|
||||||
|
'Helper.cxx',
|
||||||
'Bonjour.cxx',
|
'Bonjour.cxx',
|
||||||
include_directories: inc,
|
include_directories: inc,
|
||||||
dependencies: [
|
dependencies: [
|
||||||
@ -60,6 +61,7 @@ else
|
|||||||
zeroconf = static_library(
|
zeroconf = static_library(
|
||||||
'zeroconf_bonjour',
|
'zeroconf_bonjour',
|
||||||
'Glue.cxx',
|
'Glue.cxx',
|
||||||
|
'Helper.cxx',
|
||||||
include_directories: inc,
|
include_directories: inc,
|
||||||
dependencies: [
|
dependencies: [
|
||||||
avahi_dep,
|
avahi_dep,
|
||||||
|
Loading…
Reference in New Issue
Block a user