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
b01ef1b9
Commit
b01ef1b9
authored
Feb 24, 2021
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
zeroconf/Bonjour: return a std::unique_ptr<BonjourHelper>
parent
ceb76b6a
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
54 additions
and
53 deletions
+54
-53
Bonjour.cxx
src/zeroconf/Bonjour.cxx
+2
-43
Bonjour.hxx
src/zeroconf/Bonjour.hxx
+39
-4
Glue.cxx
src/zeroconf/Glue.cxx
+13
-6
No files found.
src/zeroconf/Bonjour.cxx
View file @
b01ef1b9
...
...
@@ -19,7 +19,6 @@
#include "Bonjour.hxx"
#include "Internal.hxx"
#include "event/SocketEvent.hxx"
#include "util/Domain.hxx"
#include "Log.hxx"
#include "util/Compiler.h"
...
...
@@ -32,38 +31,6 @@
static
constexpr
Domain
bonjour_domain
(
"bonjour"
);
class
BonjourHelper
final
{
const
DNSServiceRef
service_ref
;
SocketEvent
socket_event
;
public
:
BonjourHelper
(
EventLoop
&
_loop
,
const
char
*
name
,
unsigned
port
);
~
BonjourHelper
()
{
DNSServiceRefDeallocate
(
service_ref
);
}
BonjourHelper
(
const
BonjourHelper
&
)
=
delete
;
BonjourHelper
&
operator
=
(
const
BonjourHelper
&
)
=
delete
;
void
Cancel
()
noexcept
{
socket_event
.
Cancel
();
}
static
void
Callback
(
DNSServiceRef
sdRef
,
DNSServiceFlags
flags
,
DNSServiceErrorType
errorCode
,
const
char
*
name
,
const
char
*
regtype
,
const
char
*
domain
,
void
*
context
)
noexcept
;
protected
:
/* virtual methods from class SocketMonitor */
void
OnSocketReady
([[
maybe_unused
]]
unsigned
flags
)
noexcept
{
DNSServiceProcessResult
(
service_ref
);
}
};
/**
* A wrapper for DNSServiceRegister() which returns the DNSServiceRef
* and throws on error.
...
...
@@ -96,8 +63,6 @@ BonjourHelper::BonjourHelper(EventLoop &_loop, const char *name, unsigned port)
socket_event
.
ScheduleRead
();
}
static
BonjourHelper
*
bonjour_monitor
;
void
BonjourHelper
::
Callback
([[
maybe_unused
]]
DNSServiceRef
sdRef
,
[[
maybe_unused
]]
DNSServiceFlags
flags
,
...
...
@@ -120,14 +85,8 @@ BonjourHelper::Callback([[maybe_unused]] DNSServiceRef sdRef,
}
}
void
std
::
unique_ptr
<
BonjourHelper
>
BonjourInit
(
EventLoop
&
loop
,
const
char
*
service_name
,
unsigned
port
)
{
bonjour_monitor
=
new
BonjourHelper
(
loop
,
service_name
,
port
);
}
void
BonjourDeinit
()
{
delete
bonjour_monitor
;
return
std
::
make_unique
<
BonjourHelper
>
(
loop
,
service_name
,
port
);
}
src/zeroconf/Bonjour.hxx
View file @
b01ef1b9
...
...
@@ -20,15 +20,50 @@
#ifndef MPD_ZEROCONF_BONJOUR_HXX
#define MPD_ZEROCONF_BONJOUR_HXX
#include "event/SocketEvent.hxx"
#include <dns_sd.h>
#include <memory>
class
EventLoop
;
class
BonjourHelper
final
{
const
DNSServiceRef
service_ref
;
SocketEvent
socket_event
;
public
:
BonjourHelper
(
EventLoop
&
_loop
,
const
char
*
name
,
unsigned
port
);
~
BonjourHelper
()
noexcept
{
DNSServiceRefDeallocate
(
service_ref
);
}
BonjourHelper
(
const
BonjourHelper
&
)
=
delete
;
BonjourHelper
&
operator
=
(
const
BonjourHelper
&
)
=
delete
;
private
:
void
Cancel
()
noexcept
{
socket_event
.
Cancel
();
}
static
void
Callback
(
DNSServiceRef
sdRef
,
DNSServiceFlags
flags
,
DNSServiceErrorType
errorCode
,
const
char
*
name
,
const
char
*
regtype
,
const
char
*
domain
,
void
*
context
)
noexcept
;
/* virtual methods from class SocketMonitor */
void
OnSocketReady
([[
maybe_unused
]]
unsigned
flags
)
noexcept
{
DNSServiceProcessResult
(
service_ref
);
}
};
/**
* Throws on error.
*/
void
std
::
unique_ptr
<
BonjourHelper
>
BonjourInit
(
EventLoop
&
loop
,
const
char
*
service_name
,
unsigned
port
);
void
BonjourDeinit
();
#endif
src/zeroconf/Glue.cxx
View file @
b01ef1b9
...
...
@@ -19,7 +19,6 @@
#include "Glue.hxx"
#include "avahi/Init.hxx"
#include "Bonjour.hxx"
#include "config/Data.hxx"
#include "config/Option.hxx"
#include "Listen.hxx"
...
...
@@ -27,6 +26,10 @@
#include "Log.hxx"
#include "util/Compiler.h"
#ifdef HAVE_BONJOUR
#include "Bonjour.hxx"
#endif
#include <climits>
#include <string.h>
...
...
@@ -49,6 +52,10 @@ static constexpr Domain zeroconf_domain("zeroconf");
static
int
zeroconfEnabled
;
#ifdef HAVE_BONJOUR
static
std
::
unique_ptr
<
BonjourHelper
>
bonjour_helper
;
#endif
void
ZeroconfInit
(
const
ConfigData
&
config
,
[[
maybe_unused
]]
EventLoop
&
loop
)
{
...
...
@@ -86,21 +93,21 @@ ZeroconfInit(const ConfigData &config, [[maybe_unused]] EventLoop &loop)
#endif
#ifdef HAVE_BONJOUR
BonjourInit
(
loop
,
serviceName
,
listen_port
);
bonjour_helper
=
BonjourInit
(
loop
,
serviceName
,
listen_port
);
#endif
}
void
ZeroconfDeinit
()
noexcept
{
#ifdef HAVE_BONJOUR
bonjour_helper
.
reset
();
#endif
if
(
!
zeroconfEnabled
)
return
;
#ifdef HAVE_AVAHI
AvahiDeinit
();
#endif
/* HAVE_AVAHI */
#ifdef HAVE_BONJOUR
BonjourDeinit
();
#endif
}
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