From b20b77318972cacf626910554d60f46be617d005 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Thu, 18 Jan 2024 18:43:46 +0100 Subject: [PATCH] zeroconf/avahi/Helper: embed the Avahi::Publisher without std::unique_ptr --- src/zeroconf/avahi/Helper.cxx | 16 ++++++---------- src/zeroconf/avahi/Helper.hxx | 12 ++++++------ 2 files changed, 12 insertions(+), 16 deletions(-) diff --git a/src/zeroconf/avahi/Helper.cxx b/src/zeroconf/avahi/Helper.cxx index 457c08a39..e7807f193 100644 --- a/src/zeroconf/avahi/Helper.cxx +++ b/src/zeroconf/avahi/Helper.cxx @@ -4,7 +4,6 @@ #include "Helper.hxx" #include "lib/avahi/Client.hxx" #include "lib/avahi/ErrorHandler.hxx" -#include "lib/avahi/Publisher.hxx" #include "lib/avahi/Service.hxx" #include "lib/fmt/RuntimeError.hxx" #include "Log.hxx" @@ -29,9 +28,11 @@ static std::weak_ptr shared_avahi_client; inline AvahiHelper::AvahiHelper(std::shared_ptr _client, - std::unique_ptr _publisher) + const char *service_name, + std::forward_list &&services) :client(std::move(_client)), - publisher(std::move(_publisher)) {} + publisher(client->client, service_name, + std::move(services), *client) {} AvahiHelper::~AvahiHelper() noexcept = default; @@ -53,11 +54,6 @@ AvahiInit(EventLoop &event_loop, const char *service_name, AVAHI_PROTO_UNSPEC, service_type, port); - auto publisher = std::make_unique(client->client, - service_name, - std::move(services), - *client); - - return std::make_unique(std::move(client), - std::move(publisher)); + return std::make_unique(std::move(client), service_name, + std::move(services)); } diff --git a/src/zeroconf/avahi/Helper.hxx b/src/zeroconf/avahi/Helper.hxx index 6e6ed7f06..177a4eb4d 100644 --- a/src/zeroconf/avahi/Helper.hxx +++ b/src/zeroconf/avahi/Helper.hxx @@ -1,8 +1,9 @@ // SPDX-License-Identifier: GPL-2.0-or-later // Copyright The Music Player Daemon Project -#ifndef MPD_ZEROCONF_AVAHI_HELPER_HXX -#define MPD_ZEROCONF_AVAHI_HELPER_HXX +#pragma once + +#include "lib/avahi/Publisher.hxx" #include @@ -13,16 +14,15 @@ class SharedAvahiClient; class AvahiHelper final { std::shared_ptr client; - std::unique_ptr publisher; + Avahi::Publisher publisher; public: AvahiHelper(std::shared_ptr _client, - std::unique_ptr _publisher); + const char *service_name, + std::forward_list &&services); ~AvahiHelper() noexcept; }; std::unique_ptr AvahiInit(EventLoop &event_loop, const char *service_name, const char *service_type, unsigned port); - -#endif