zeroconf/avahi/Helper: embed the Avahi::Publisher without std::unique_ptr

This commit is contained in:
Max Kellermann 2024-01-18 18:43:46 +01:00
parent 74125c0922
commit b20b773189
2 changed files with 12 additions and 16 deletions

View File

@ -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<SharedAvahiClient> shared_avahi_client;
inline
AvahiHelper::AvahiHelper(std::shared_ptr<SharedAvahiClient> _client,
std::unique_ptr<Avahi::Publisher> _publisher)
const char *service_name,
std::forward_list<Avahi::Service> &&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<Avahi::Publisher>(client->client,
service_name,
std::move(services),
*client);
return std::make_unique<AvahiHelper>(std::move(client),
std::move(publisher));
return std::make_unique<AvahiHelper>(std::move(client), service_name,
std::move(services));
}

View File

@ -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 <memory>
@ -13,16 +14,15 @@ class SharedAvahiClient;
class AvahiHelper final {
std::shared_ptr<SharedAvahiClient> client;
std::unique_ptr<Avahi::Publisher> publisher;
Avahi::Publisher publisher;
public:
AvahiHelper(std::shared_ptr<SharedAvahiClient> _client,
std::unique_ptr<Avahi::Publisher> _publisher);
const char *service_name,
std::forward_list<Avahi::Service> &&services);
~AvahiHelper() noexcept;
};
std::unique_ptr<AvahiHelper>
AvahiInit(EventLoop &event_loop, const char *service_name,
const char *service_type, unsigned port);
#endif