zeroconf/avahi/Init: return a std::unique_ptr<AvahiHelper>

This commit is contained in:
Max Kellermann
2021-02-24 14:27:05 +01:00
parent b01ef1b9a6
commit 975d5be046
5 changed files with 64 additions and 42 deletions

View File

@@ -18,7 +18,6 @@
*/
#include "Glue.hxx"
#include "avahi/Init.hxx"
#include "config/Data.hxx"
#include "config/Option.hxx"
#include "Listen.hxx"
@@ -26,6 +25,10 @@
#include "Log.hxx"
#include "util/Compiler.h"
#ifdef HAVE_AVAHI
#include "avahi/Helper.hxx"
#endif
#ifdef HAVE_BONJOUR
#include "Bonjour.hxx"
#endif
@@ -52,6 +55,10 @@ static constexpr Domain zeroconf_domain("zeroconf");
static int zeroconfEnabled;
#ifdef HAVE_AVAHI
static std::unique_ptr<AvahiHelper> avahi_helper;
#endif
#ifdef HAVE_BONJOUR
static std::unique_ptr<BonjourHelper> bonjour_helper;
#endif
@@ -89,7 +96,7 @@ ZeroconfInit(const ConfigData &config, [[maybe_unused]] EventLoop &loop)
}
#ifdef HAVE_AVAHI
AvahiInit(loop, serviceName, listen_port);
avahi_helper = AvahiInit(loop, serviceName, listen_port);
#endif
#ifdef HAVE_BONJOUR
@@ -100,14 +107,11 @@ ZeroconfInit(const ConfigData &config, [[maybe_unused]] EventLoop &loop)
void
ZeroconfDeinit() noexcept
{
#ifdef HAVE_AVAHI
avahi_helper.reset();
#endif
#ifdef HAVE_BONJOUR
bonjour_helper.reset();
#endif
if (!zeroconfEnabled)
return;
#ifdef HAVE_AVAHI
AvahiDeinit();
#endif /* HAVE_AVAHI */
}