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
8351543c
Commit
8351543c
authored
Jan 10, 2014
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
db/upnp: move lazy Open() call to new class LazyDatabase
Generic approach for the workaround.
parent
8add78ed
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
182 additions
and
29 deletions
+182
-29
Makefile.am
Makefile.am
+1
-0
LazyDatabase.cxx
src/db/LazyDatabase.cxx
+103
-0
LazyDatabase.hxx
src/db/LazyDatabase.hxx
+69
-0
UpnpDatabasePlugin.cxx
src/db/UpnpDatabasePlugin.cxx
+9
-29
No files found.
Makefile.am
View file @
8351543c
...
...
@@ -397,6 +397,7 @@ libfs_a_SOURCES = \
libdb_plugins_a_SOURCES
=
\
src/DatabaseRegistry.cxx src/DatabaseRegistry.hxx
\
src/DatabaseHelpers.cxx src/DatabaseHelpers.hxx
\
src/db/LazyDatabase.cxx src/db/LazyDatabase.hxx
\
src/db/SimpleDatabasePlugin.cxx src/db/SimpleDatabasePlugin.hxx
if
HAVE_LIBMPDCLIENT
...
...
src/db/LazyDatabase.cxx
0 → 100644
View file @
8351543c
/*
* Copyright (C) 2003-2013 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 "config.h"
#include "LazyDatabase.hxx"
#include <assert.h>
LazyDatabase
::~
LazyDatabase
()
{
assert
(
!
open
);
delete
db
;
}
bool
LazyDatabase
::
EnsureOpen
(
Error
&
error
)
const
{
if
(
open
)
return
true
;
if
(
!
db
->
Open
(
error
))
return
false
;
open
=
true
;
return
true
;
}
void
LazyDatabase
::
Close
()
{
if
(
open
)
{
open
=
false
;
db
->
Close
();
}
}
Song
*
LazyDatabase
::
GetSong
(
const
char
*
uri
,
Error
&
error
)
const
{
return
EnsureOpen
(
error
)
?
db
->
GetSong
(
uri
,
error
)
:
nullptr
;
}
void
LazyDatabase
::
ReturnSong
(
Song
*
song
)
const
{
assert
(
open
);
db
->
ReturnSong
(
song
);
}
bool
LazyDatabase
::
Visit
(
const
DatabaseSelection
&
selection
,
VisitDirectory
visit_directory
,
VisitSong
visit_song
,
VisitPlaylist
visit_playlist
,
Error
&
error
)
const
{
return
EnsureOpen
(
error
)
&&
db
->
Visit
(
selection
,
visit_directory
,
visit_song
,
visit_playlist
,
error
);
}
bool
LazyDatabase
::
VisitUniqueTags
(
const
DatabaseSelection
&
selection
,
TagType
tag_type
,
VisitString
visit_string
,
Error
&
error
)
const
{
return
EnsureOpen
(
error
)
&&
db
->
VisitUniqueTags
(
selection
,
tag_type
,
visit_string
,
error
);
}
bool
LazyDatabase
::
GetStats
(
const
DatabaseSelection
&
selection
,
DatabaseStats
&
stats
,
Error
&
error
)
const
{
return
EnsureOpen
(
error
)
&&
db
->
GetStats
(
selection
,
stats
,
error
);
}
time_t
LazyDatabase
::
GetUpdateStamp
()
const
{
return
open
?
db
->
GetUpdateStamp
()
:
0
;
}
src/db/LazyDatabase.hxx
0 → 100644
View file @
8351543c
/*
* Copyright (C) 2003-2013 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_LAZY_DATABASE_PLUGIN_HXX
#define MPD_LAZY_DATABASE_PLUGIN_HXX
#include "DatabasePlugin.hxx"
/**
* A wrapper for a #Database object that gets opened on the first
* database access. This works around daemonization problems with
* some plugins.
*/
class
LazyDatabase
final
:
public
Database
{
Database
*
const
db
;
mutable
bool
open
;
public
:
gcc_nonnull_all
LazyDatabase
(
Database
*
_db
)
:
db
(
_db
),
open
(
false
)
{}
virtual
~
LazyDatabase
();
virtual
void
Close
()
override
;
virtual
Song
*
GetSong
(
const
char
*
uri_utf8
,
Error
&
error
)
const
override
;
virtual
void
ReturnSong
(
Song
*
song
)
const
;
virtual
bool
Visit
(
const
DatabaseSelection
&
selection
,
VisitDirectory
visit_directory
,
VisitSong
visit_song
,
VisitPlaylist
visit_playlist
,
Error
&
error
)
const
override
;
virtual
bool
VisitUniqueTags
(
const
DatabaseSelection
&
selection
,
TagType
tag_type
,
VisitString
visit_string
,
Error
&
error
)
const
override
;
virtual
bool
GetStats
(
const
DatabaseSelection
&
selection
,
DatabaseStats
&
stats
,
Error
&
error
)
const
override
;
virtual
time_t
GetUpdateStamp
()
const
override
;
private
:
bool
EnsureOpen
(
Error
&
error
)
const
;
};
#endif
src/db/UpnpDatabasePlugin.cxx
View file @
8351543c
...
...
@@ -24,6 +24,7 @@
#include "upnp/Discovery.hxx"
#include "upnp/ContentDirectoryService.hxx"
#include "upnp/Directory.hxx"
#include "LazyDatabase.hxx"
#include "DatabasePlugin.hxx"
#include "DatabaseSelection.hxx"
#include "DatabaseError.hxx"
...
...
@@ -99,7 +100,6 @@ protected:
bool
Configure
(
const
config_param
&
param
,
Error
&
error
);
private
:
bool
reallyOpen
(
Error
&
error
);
bool
VisitServer
(
ContentDirectoryService
*
server
,
const
std
::
vector
<
std
::
string
>
&
vpath
,
const
DatabaseSelection
&
selection
,
...
...
@@ -188,11 +188,15 @@ UpnpDatabase::Create(gcc_unused EventLoop &loop,
const
config_param
&
param
,
Error
&
error
)
{
UpnpDatabase
*
db
=
new
UpnpDatabase
();
if
(
db
&&
!
db
->
Configure
(
param
,
error
))
{
if
(
!
db
->
Configure
(
param
,
error
))
{
delete
db
;
db
=
nullptr
;
return
nullptr
;
}
return
db
;
/* libupnp loses its ability to receive multicast messages
apparently due to daemonization; using the LazyDatabase
wrapper works around this problem */
return
new
LazyDatabase
(
db
);
}
bool
...
...
@@ -201,23 +205,8 @@ UpnpDatabase::Configure(const config_param &, Error &)
return
true
;
}
// Open is called before mpd daemonizes, and daemonizing messes with
// the UpNP lib (it loses its ability to receive mcast messages
// apparently).
// So we delay actual opening until the first client call.
//
// Unfortunately the servers may take a few seconds to answer the
// first search on the network, so we would either have to sleep for a
// relatively long time (maybe 5S), or accept that the directory may
// not be complete on the first client call. There is no simple
// solution to this issue, we would need a call from mpd after daemonizing.
bool
UpnpDatabase
::
Open
(
Error
&
)
{
return
true
;
}
bool
UpnpDatabase
::
reallyOpen
(
Error
&
error
)
UpnpDatabase
::
Open
(
Error
&
error
)
{
if
(
m_root
)
return
true
;
...
...
@@ -320,9 +309,6 @@ upnpItemToSong(const UPnPDirObject &dirent, const char *uri)
Song
*
UpnpDatabase
::
GetSong
(
const
char
*
uri
,
Error
&
error
)
const
{
if
(
!
const_cast
<
UpnpDatabase
*>
(
this
)
->
reallyOpen
(
error
))
return
nullptr
;
if
(
!
m_superdir
||
!
m_superdir
->
ok
())
{
error
.
Set
(
upnp_domain
,
"UpnpDatabase::GetSong() superdir is sick"
);
...
...
@@ -813,9 +799,6 @@ UpnpDatabase::Visit(const DatabaseSelection &selection,
VisitPlaylist
visit_playlist
,
Error
&
error
)
const
{
if
(
!
const_cast
<
UpnpDatabase
*>
(
this
)
->
reallyOpen
(
error
))
return
false
;
std
::
vector
<
ContentDirectoryService
>
servers
;
if
(
!
m_superdir
||
!
m_superdir
->
ok
()
||
!
m_superdir
->
getDirServices
(
servers
))
{
...
...
@@ -873,9 +856,6 @@ UpnpDatabase::VisitUniqueTags(const DatabaseSelection &selection,
VisitString
visit_string
,
Error
&
error
)
const
{
if
(
!
const_cast
<
UpnpDatabase
*>
(
this
)
->
reallyOpen
(
error
))
return
false
;
if
(
!
visit_string
)
return
true
;
...
...
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