Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mpd
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Иван Мажукин
mpd
Commits
2d8ecd56
Commit
2d8ecd56
authored
Feb 24, 2021
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
zeroconf: return a publisher object
parent
2059195a
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
101 additions
and
47 deletions
+101
-47
Main.cxx
src/Main.cxx
+7
-2
Glue.cxx
src/zeroconf/Glue.cxx
+10
-31
Glue.hxx
src/zeroconf/Glue.hxx
+5
-14
Helper.cxx
src/zeroconf/Helper.cxx
+30
-0
Helper.hxx
src/zeroconf/Helper.hxx
+47
-0
meson.build
src/zeroconf/meson.build
+2
-0
No files found.
src/Main.cxx
View file @
2d8ecd56
...
...
@@ -476,12 +476,15 @@ MainConfigured(const struct options &options, const ConfigData &raw_config)
};
#endif
#ifdef HAVE_ZEROCONF
std
::
unique_ptr
<
ZeroconfHelper
>
zeroconf
;
try
{
ZeroconfInit
(
raw_config
,
instance
.
event_loop
);
zeroconf
=
ZeroconfInit
(
raw_config
,
instance
.
event_loop
);
}
catch
(...)
{
LogError
(
std
::
current_exception
(),
"Zeroconf initialization failed"
);
}
#endif
#ifdef ENABLE_DATABASE
if
(
create_db
)
{
...
...
@@ -543,7 +546,9 @@ MainConfigured(const struct options &options, const ConfigData &raw_config)
instance
.
BeginShutdownUpdate
();
ZeroconfDeinit
();
#ifdef HAVE_ZEROCONF
zeroconf
.
reset
();
#endif
instance
.
BeginShutdownPartitions
();
}
...
...
src/zeroconf/Glue.cxx
View file @
2d8ecd56
...
...
@@ -18,6 +18,7 @@
*/
#include "Glue.hxx"
#include "Helper.hxx"
#include "config/Data.hxx"
#include "config/Option.hxx"
#include "Listen.hxx"
...
...
@@ -53,31 +54,19 @@ static constexpr Domain zeroconf_domain("zeroconf");
#define DEFAULT_ZEROCONF_ENABLED 1
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
void
std
::
unique_ptr
<
ZeroconfHelper
>
ZeroconfInit
(
const
ConfigData
&
config
,
[[
maybe_unused
]]
EventLoop
&
loop
)
{
const
char
*
serviceName
;
zeroconfEnabled
=
config
.
GetBool
(
ConfigOption
::
ZEROCONF_ENABLED
,
DEFAULT_ZEROCONF_ENABLED
);
if
(
!
zeroconfEnabled
)
return
;
if
(
!
config
.
GetBool
(
ConfigOption
::
ZEROCONF_ENABLED
,
DEFAULT_ZEROCONF_ENABLED
))
return
nullptr
;
if
(
listen_port
<=
0
)
{
LogWarning
(
zeroconf_domain
,
"No global port, disabling zeroconf"
);
zeroconfEnabled
=
false
;
return
;
return
nullptr
;
}
serviceName
=
config
.
GetString
(
ConfigOption
::
ZEROCONF_NAME
,
...
...
@@ -96,22 +85,12 @@ ZeroconfInit(const ConfigData &config, [[maybe_unused]] EventLoop &loop)
}
#ifdef HAVE_AVAHI
avahi_helper
=
AvahiInit
(
loop
,
serviceName
,
listen_port
);
#endif
#ifdef HAVE_BONJOUR
bonjour_helper
=
BonjourInit
(
loop
,
serviceName
,
listen_port
);
#endif
}
void
ZeroconfDeinit
()
noexcept
{
#ifdef HAVE_AVAHI
avahi_helper
.
reset
();
return
std
::
make_unique
<
ZeroconfHelper
>
(
AvahiInit
(
loop
,
serviceName
,
listen_port
));
#endif
#ifdef HAVE_BONJOUR
bonjour_helper
.
reset
();
return
std
::
make_unique
<
ZeroconfHelper
>
(
BonjourInit
(
loop
,
serviceName
,
listen_port
));
#endif
}
src/zeroconf/Glue.hxx
View file @
2d8ecd56
...
...
@@ -20,32 +20,23 @@
#ifndef MPD_ZEROCONF_GLUE_HXX
#define MPD_ZEROCONF_GLUE_HXX
#include "Helper.hxx"
#include "config.h"
#include <memory>
struct
ConfigData
;
class
EventLoop
;
class
ZeroconfHelper
;
#ifdef HAVE_ZEROCONF
/**
* Throws on error.
*/
void
std
::
unique_ptr
<
ZeroconfHelper
>
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
src/zeroconf/Helper.cxx
0 → 100644
View file @
2d8ecd56
/*
* 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
;
src/zeroconf/Helper.hxx
0 → 100644
View file @
2d8ecd56
/*
* 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
src/zeroconf/meson.build
View file @
2d8ecd56
...
...
@@ -36,6 +36,7 @@ if zeroconf_option == 'bonjour'
zeroconf = static_library(
'zeroconf_bonjour',
'Glue.cxx',
'Helper.cxx',
'Bonjour.cxx',
include_directories: inc,
dependencies: [
...
...
@@ -60,6 +61,7 @@ else
zeroconf = static_library(
'zeroconf_bonjour',
'Glue.cxx',
'Helper.cxx',
include_directories: inc,
dependencies: [
avahi_dep,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment