zeroconf/{bonjour,avahi}: pass service_type as parameter
This commit is contained in:
parent
9d6bf7e720
commit
29b49dd630
|
@ -18,7 +18,6 @@
|
|||
*/
|
||||
|
||||
#include "Bonjour.hxx"
|
||||
#include "Internal.hxx"
|
||||
#include "util/Domain.hxx"
|
||||
#include "Log.hxx"
|
||||
#include "util/Compiler.h"
|
||||
|
@ -53,8 +52,9 @@ RegisterBonjour(const char *name, const char *type, unsigned port,
|
|||
return ref;
|
||||
}
|
||||
|
||||
BonjourHelper::BonjourHelper(EventLoop &_loop, const char *name, unsigned port)
|
||||
:service_ref(RegisterBonjour(name, SERVICE_TYPE, port,
|
||||
BonjourHelper::BonjourHelper(EventLoop &_loop, const char *name,
|
||||
const char *service_type, unsigned port)
|
||||
:service_ref(RegisterBonjour(name, service_type, port,
|
||||
Callback, this)),
|
||||
socket_event(_loop,
|
||||
BIND_THIS_METHOD(OnSocketReady),
|
||||
|
@ -86,7 +86,8 @@ BonjourHelper::Callback([[maybe_unused]] DNSServiceRef sdRef,
|
|||
}
|
||||
|
||||
std::unique_ptr<BonjourHelper>
|
||||
BonjourInit(EventLoop &loop, const char *service_name, unsigned port)
|
||||
BonjourInit(EventLoop &loop, const char *name,
|
||||
const char *service_type, unsigned port)
|
||||
{
|
||||
return std::make_unique<BonjourHelper>(loop, service_name, port);
|
||||
return std::make_unique<BonjourHelper>(loop, name, service_type, port);
|
||||
}
|
||||
|
|
|
@ -34,7 +34,8 @@ class BonjourHelper final {
|
|||
SocketEvent socket_event;
|
||||
|
||||
public:
|
||||
BonjourHelper(EventLoop &_loop, const char *name, unsigned port);
|
||||
BonjourHelper(EventLoop &_loop, const char *name,
|
||||
const char *service_name, unsigned port);
|
||||
|
||||
~BonjourHelper() noexcept {
|
||||
DNSServiceRefDeallocate(service_ref);
|
||||
|
@ -64,6 +65,7 @@ private:
|
|||
* Throws on error.
|
||||
*/
|
||||
std::unique_ptr<BonjourHelper>
|
||||
BonjourInit(EventLoop &loop, const char *service_name, unsigned port);
|
||||
BonjourInit(EventLoop &loop, const char *name,
|
||||
const char *service_type, unsigned port);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -52,6 +52,9 @@ static constexpr Domain zeroconf_domain("zeroconf");
|
|||
*/
|
||||
#define SERVICE_NAME "Music Player @ %h"
|
||||
|
||||
/* The dns-sd service type qualifier to publish */
|
||||
#define SERVICE_TYPE "_mpd._tcp"
|
||||
|
||||
#define DEFAULT_ZEROCONF_ENABLED 1
|
||||
|
||||
std::unique_ptr<ZeroconfHelper>
|
||||
|
@ -84,5 +87,6 @@ ZeroconfInit(const ConfigData &config, [[maybe_unused]] EventLoop &loop)
|
|||
}
|
||||
}
|
||||
|
||||
return std::make_unique<ZeroconfHelper>(loop, serviceName, listen_port);
|
||||
return std::make_unique<ZeroconfHelper>(loop, serviceName,
|
||||
SERVICE_TYPE, listen_port);
|
||||
}
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
#endif
|
||||
|
||||
ZeroconfHelper::ZeroconfHelper(EventLoop &event_loop, const char *name,
|
||||
unsigned port)
|
||||
:helper(CreateHelper(event_loop, name, port)) {}
|
||||
const char *service_type, unsigned port)
|
||||
:helper(CreateHelper(event_loop, name, service_type, port)) {}
|
||||
|
||||
ZeroconfHelper::~ZeroconfHelper() noexcept = default;
|
||||
|
|
|
@ -39,7 +39,7 @@ class ZeroconfHelper final {
|
|||
|
||||
public:
|
||||
ZeroconfHelper(EventLoop &event_loop, const char *name,
|
||||
unsigned port);
|
||||
const char *service_type, unsigned port);
|
||||
|
||||
~ZeroconfHelper() noexcept;
|
||||
};
|
||||
|
|
|
@ -1,26 +0,0 @@
|
|||
/*
|
||||
* 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 ZEROCONF_INTERNAL_HXX
|
||||
#define ZEROCONF_INTERNAL_HXX
|
||||
|
||||
/* The dns-sd service type qualifier to publish */
|
||||
#define SERVICE_TYPE "_mpd._tcp"
|
||||
|
||||
#endif
|
|
@ -22,7 +22,6 @@
|
|||
#include "ErrorHandler.hxx"
|
||||
#include "Publisher.hxx"
|
||||
#include "Service.hxx"
|
||||
#include "../Internal.hxx"
|
||||
#include "util/RuntimeError.hxx"
|
||||
#include "Log.hxx"
|
||||
|
||||
|
@ -53,7 +52,8 @@ AvahiHelper::AvahiHelper(std::shared_ptr<SharedAvahiClient> _client,
|
|||
AvahiHelper::~AvahiHelper() noexcept = default;
|
||||
|
||||
std::unique_ptr<AvahiHelper>
|
||||
AvahiInit(EventLoop &event_loop, const char *service_name, unsigned port)
|
||||
AvahiInit(EventLoop &event_loop, const char *service_name,
|
||||
const char *service_type, unsigned port)
|
||||
{
|
||||
if (!avahi_is_valid_service_name(service_name))
|
||||
throw FormatRuntimeError("Invalid zeroconf_name \"%s\"",
|
||||
|
@ -67,7 +67,7 @@ AvahiInit(EventLoop &event_loop, const char *service_name, unsigned port)
|
|||
std::forward_list<Avahi::Service> services;
|
||||
services.emplace_front(AVAHI_IF_UNSPEC,
|
||||
AVAHI_PROTO_UNSPEC,
|
||||
SERVICE_TYPE, port);
|
||||
service_type, port);
|
||||
|
||||
auto publisher = std::make_unique<Avahi::Publisher>(client->client,
|
||||
service_name,
|
||||
|
|
|
@ -38,6 +38,7 @@ public:
|
|||
};
|
||||
|
||||
std::unique_ptr<AvahiHelper>
|
||||
AvahiInit(EventLoop &event_loop, const char *service_name, unsigned port);
|
||||
AvahiInit(EventLoop &event_loop, const char *service_name,
|
||||
const char *service_type, unsigned port);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -29,7 +29,7 @@ main([[maybe_unused]] int argc, [[maybe_unused]] char **argv)
|
|||
EventLoop event_loop;
|
||||
const ShutdownHandler shutdown_handler(event_loop);
|
||||
|
||||
const ZeroconfHelper helper(event_loop, "test", 1234);
|
||||
const ZeroconfHelper helper(event_loop, "test", "_mpd._tcp", 1234);
|
||||
|
||||
event_loop.Run();
|
||||
|
||||
|
|
Loading…
Reference in New Issue