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
c13810eb
Commit
c13810eb
authored
Feb 07, 2014
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Mapper: move map_song_detach() to db/DatabaseSong.cxx
Use Storage::MapUTF8() internally, don't use global variables.
parent
19a982cf
Hide whitespace changes
Inline
Side-by-side
Showing
17 changed files
with
97 additions
and
55 deletions
+97
-55
DetachedSong.hxx
src/DetachedSong.hxx
+3
-0
Mapper.cxx
src/Mapper.cxx
+0
-15
Mapper.hxx
src/Mapper.hxx
+0
-8
PlaylistSave.cxx
src/PlaylistSave.cxx
+1
-1
SongLoader.cxx
src/SongLoader.cxx
+4
-2
SongLoader.hxx
src/SongLoader.hxx
+8
-5
StateFile.cxx
src/StateFile.cxx
+3
-2
Client.cxx
src/client/Client.cxx
+6
-0
Client.hxx
src/client/Client.hxx
+5
-0
DatabaseCommands.cxx
src/command/DatabaseCommands.cxx
+2
-1
PlaylistCommands.cxx
src/command/PlaylistCommands.cxx
+2
-1
DatabasePlaylist.cxx
src/db/DatabasePlaylist.cxx
+8
-5
DatabasePlaylist.hxx
src/db/DatabasePlaylist.hxx
+3
-2
DatabaseQueue.cxx
src/db/DatabaseQueue.cxx
+4
-3
DatabaseSong.cxx
src/db/DatabaseSong.cxx
+20
-3
DatabaseSong.hxx
src/db/DatabaseSong.hxx
+12
-1
test_translate_song.cxx
test/test_translate_song.cxx
+16
-6
No files found.
src/DetachedSong.hxx
View file @
c13810eb
...
...
@@ -30,9 +30,12 @@
#include <time.h>
struct
LightSong
;
class
Storage
;
class
DetachedSong
{
friend
DetachedSong
map_song_detach
(
const
LightSong
&
song
);
friend
DetachedSong
DatabaseDetachSong
(
const
Storage
&
db
,
const
LightSong
&
song
);
/**
* An UTF-8-encoded URI referring to the song file. This can
...
...
src/Mapper.cxx
View file @
c13810eb
...
...
@@ -234,21 +234,6 @@ map_directory_child_fs(const Directory &directory, const char *name)
return
AllocatedPath
::
Build
(
parent_fs
,
name_fs
);
}
DetachedSong
map_song_detach
(
const
LightSong
&
song
)
{
DetachedSong
detached
(
song
);
assert
(
detached
.
IsInDatabase
());
if
(
!
detached
.
HasRealURI
())
{
const
auto
uri
=
song
.
GetURI
();
detached
.
SetRealURI
(
PathTraitsUTF8
::
Build
(
music_dir_utf8
.
c_str
(),
uri
.
c_str
()));
}
return
detached
;
}
AllocatedPath
map_song_fs
(
const
Song
&
song
)
{
...
...
src/Mapper.hxx
View file @
c13810eb
...
...
@@ -92,14 +92,6 @@ AllocatedPath
map_uri_fs
(
const
char
*
uri
);
/**
* "Detach" the #Song object, i.e. convert it to a #DetachedSong
* instance.
*/
gcc_pure
DetachedSong
map_song_detach
(
const
LightSong
&
song
);
/**
* Determines the file system path of a song. This must not be a
* remote song.
*
...
...
src/PlaylistSave.cxx
View file @
c13810eb
...
...
@@ -118,7 +118,7 @@ playlist_load_spl(struct playlist &playlist, PlayerControl &pc,
if
(
end_index
>
contents
.
size
())
end_index
=
contents
.
size
();
const
SongLoader
loader
(
nullptr
);
const
SongLoader
loader
(
nullptr
,
nullptr
);
for
(
unsigned
i
=
start_index
;
i
<
end_index
;
++
i
)
{
const
auto
&
uri_utf8
=
contents
[
i
];
...
...
src/SongLoader.cxx
View file @
c13810eb
...
...
@@ -36,7 +36,8 @@
#ifdef ENABLE_DATABASE
SongLoader
::
SongLoader
(
const
Client
&
_client
)
:
client
(
&
_client
),
db
(
_client
.
GetDatabase
(
IgnoreError
()))
{}
:
client
(
&
_client
),
db
(
_client
.
GetDatabase
(
IgnoreError
())),
storage
(
_client
.
GetStorage
())
{}
#endif
...
...
@@ -100,7 +101,8 @@ SongLoader::LoadSong(const char *uri_utf8, Error &error) const
#ifdef ENABLE_DATABASE
if
(
db
!=
nullptr
)
return
DatabaseDetachSong
(
*
db
,
uri_utf8
,
error
);
return
DatabaseDetachSong
(
*
db
,
*
storage
,
uri_utf8
,
error
);
#endif
error
.
Set
(
playlist_domain
,
int
(
PlaylistResult
::
NO_SUCH_SONG
),
...
...
src/SongLoader.hxx
View file @
c13810eb
...
...
@@ -27,6 +27,7 @@
class
Client
;
class
Database
;
class
Storage
;
class
DetachedSong
;
class
Error
;
...
...
@@ -41,19 +42,21 @@ class SongLoader {
#ifdef ENABLE_DATABASE
const
Database
*
const
db
;
const
Storage
*
const
storage
;
#endif
public
:
#ifdef ENABLE_DATABASE
explicit
SongLoader
(
const
Client
&
_client
);
explicit
SongLoader
(
const
Database
*
_db
)
:
client
(
nullptr
),
db
(
_db
)
{}
explicit
SongLoader
(
const
Client
&
_client
,
const
Database
*
_db
)
:
client
(
&
_client
),
db
(
_db
)
{}
SongLoader
(
const
Database
*
_db
,
const
Storage
*
_storage
)
:
client
(
nullptr
),
db
(
_db
),
storage
(
_storage
)
{}
SongLoader
(
const
Client
&
_client
,
const
Database
*
_db
,
const
Storage
*
_storage
)
:
client
(
&
_client
),
db
(
_db
),
storage
(
_storage
)
{}
#else
explicit
SongLoader
(
const
Client
&
_client
)
:
client
(
&
_client
)
{}
explicit
SongLoader
(
std
::
nullptr_t
)
explicit
SongLoader
(
std
::
nullptr_t
,
std
::
nullptr_t
)
:
client
(
nullptr
)
{}
#endif
...
...
src/StateFile.cxx
View file @
c13810eb
...
...
@@ -99,9 +99,10 @@ StateFile::Read()
}
#ifdef ENABLE_DATABASE
const
SongLoader
song_loader
(
partition
.
instance
.
database
);
const
SongLoader
song_loader
(
partition
.
instance
.
database
,
partition
.
instance
.
storage
);
#else
const
SongLoader
song_loader
(
nullptr
);
const
SongLoader
song_loader
(
nullptr
,
nullptr
);
#endif
const
char
*
line
;
...
...
src/client/Client.cxx
View file @
c13810eb
...
...
@@ -33,4 +33,10 @@ Client::GetDatabase(Error &error) const
return
partition
.
instance
.
GetDatabase
(
error
);
}
const
Storage
*
Client
::
GetStorage
()
const
{
return
partition
.
instance
.
storage
;
}
#endif
src/client/Client.hxx
View file @
c13810eb
...
...
@@ -39,6 +39,7 @@ class EventLoop;
class
Path
;
struct
Partition
;
class
Database
;
class
Storage
;
class
Client
final
:
private
FullyBufferedSocket
,
TimeoutMonitor
{
public
:
...
...
@@ -173,8 +174,12 @@ public:
/**
* Wrapper for Instance::GetDatabase().
*/
gcc_pure
const
Database
*
GetDatabase
(
Error
&
error
)
const
;
gcc_pure
const
Storage
*
GetStorage
()
const
;
private
:
/* virtual methods from class BufferedSocket */
virtual
InputResult
OnSocketInput
(
void
*
data
,
size_t
length
)
override
;
...
...
src/command/DatabaseCommands.cxx
View file @
c13810eb
...
...
@@ -124,7 +124,8 @@ handle_searchaddpl(Client &client, int argc, char *argv[])
if
(
db
==
nullptr
)
return
print_error
(
client
,
error
);
return
search_add_to_playlist
(
*
db
,
""
,
playlist
,
&
filter
,
error
)
return
search_add_to_playlist
(
*
db
,
*
client
.
GetStorage
(),
""
,
playlist
,
&
filter
,
error
)
?
CommandResult
::
OK
:
print_error
(
client
,
error
);
}
...
...
src/command/PlaylistCommands.cxx
View file @
c13810eb
...
...
@@ -196,7 +196,8 @@ handle_playlistadd(Client &client, gcc_unused int argc, char *argv[])
if
(
db
==
nullptr
)
return
print_error
(
client
,
error
);
success
=
search_add_to_playlist
(
*
db
,
uri
,
playlist
,
nullptr
,
success
=
search_add_to_playlist
(
*
db
,
*
client
.
GetStorage
(),
uri
,
playlist
,
nullptr
,
error
);
#else
success
=
false
;
...
...
src/db/DatabasePlaylist.cxx
View file @
c13810eb
...
...
@@ -19,24 +19,26 @@
#include "config.h"
#include "DatabasePlaylist.hxx"
#include "DatabaseSong.hxx"
#include "Selection.hxx"
#include "PlaylistFile.hxx"
#include "DatabasePlugin.hxx"
#include "DetachedSong.hxx"
#include "
Mapper
.hxx"
#include "
storage/StorageInterface
.hxx"
#include <functional>
static
bool
AddSong
(
const
char
*
playlist_path_utf8
,
AddSong
(
const
Storage
&
storage
,
const
char
*
playlist_path_utf8
,
const
LightSong
&
song
,
Error
&
error
)
{
return
spl_append_song
(
playlist_path_utf8
,
map_song_detach
(
song
),
return
spl_append_song
(
playlist_path_utf8
,
DatabaseDetachSong
(
storage
,
song
),
error
);
}
bool
search_add_to_playlist
(
const
Database
&
db
,
search_add_to_playlist
(
const
Database
&
db
,
const
Storage
&
storage
,
const
char
*
uri
,
const
char
*
playlist_path_utf8
,
const
SongFilter
*
filter
,
Error
&
error
)
...
...
@@ -44,6 +46,7 @@ search_add_to_playlist(const Database &db,
const
DatabaseSelection
selection
(
uri
,
true
,
filter
);
using
namespace
std
::
placeholders
;
const
auto
f
=
std
::
bind
(
AddSong
,
playlist_path_utf8
,
_1
,
_2
);
const
auto
f
=
std
::
bind
(
AddSong
,
std
::
ref
(
storage
),
playlist_path_utf8
,
_1
,
_2
);
return
db
.
Visit
(
selection
,
f
,
error
);
}
src/db/DatabasePlaylist.hxx
View file @
c13810eb
...
...
@@ -23,12 +23,13 @@
#include "Compiler.h"
class
Database
;
class
Storage
;
class
SongFilter
;
class
Error
;
gcc_nonnull
(
2
,
3
)
gcc_nonnull
(
3
,
4
)
bool
search_add_to_playlist
(
const
Database
&
db
,
search_add_to_playlist
(
const
Database
&
db
,
const
Storage
&
storage
,
const
char
*
uri
,
const
char
*
path_utf8
,
const
SongFilter
*
filter
,
Error
&
error
);
...
...
src/db/DatabaseQueue.cxx
View file @
c13810eb
...
...
@@ -19,22 +19,23 @@
#include "config.h"
#include "DatabaseQueue.hxx"
#include "Database
Glue
.hxx"
#include "Database
Song
.hxx"
#include "DatabasePlugin.hxx"
#include "Partition.hxx"
#include "Instance.hxx"
#include "util/Error.hxx"
#include "DetachedSong.hxx"
#include "Mapper.hxx"
#include <functional>
static
bool
AddToQueue
(
Partition
&
partition
,
const
LightSong
&
song
,
Error
&
error
)
{
const
Storage
&
storage
=
*
partition
.
instance
.
storage
;
PlaylistResult
result
=
partition
.
playlist
.
AppendSong
(
partition
.
pc
,
map_song_detach
(
song
),
DatabaseDetachSong
(
storage
,
song
),
nullptr
);
if
(
result
!=
PlaylistResult
::
SUCCESS
)
{
error
.
Set
(
playlist_domain
,
int
(
result
),
"Playlist error"
);
...
...
src/db/DatabaseSong.cxx
View file @
c13810eb
...
...
@@ -19,18 +19,35 @@
#include "config.h"
#include "DatabaseSong.hxx"
#include "LightSong.hxx"
#include "DatabasePlugin.hxx"
#include "DetachedSong.hxx"
#include "Mapper.hxx"
#include "storage/StorageInterface.hxx"
DetachedSong
DatabaseDetachSong
(
const
Storage
&
storage
,
const
LightSong
&
song
)
{
DetachedSong
detached
(
song
);
assert
(
detached
.
IsInDatabase
());
if
(
!
detached
.
HasRealURI
())
{
const
auto
uri
=
song
.
GetURI
();
detached
.
SetRealURI
(
storage
.
MapUTF8
(
uri
.
c_str
()));
}
return
detached
;
}
DetachedSong
*
DatabaseDetachSong
(
const
Database
&
db
,
const
char
*
uri
,
Error
&
error
)
DatabaseDetachSong
(
const
Database
&
db
,
const
Storage
&
storage
,
const
char
*
uri
,
Error
&
error
)
{
const
LightSong
*
tmp
=
db
.
GetSong
(
uri
,
error
);
if
(
tmp
==
nullptr
)
return
nullptr
;
DetachedSong
*
song
=
new
DetachedSong
(
map_song_detach
(
*
tmp
));
DetachedSong
*
song
=
new
DetachedSong
(
DatabaseDetachSong
(
storage
,
*
tmp
));
db
.
ReturnSong
(
tmp
);
return
song
;
}
src/db/DatabaseSong.hxx
View file @
c13810eb
...
...
@@ -22,11 +22,21 @@
#include "Compiler.h"
struct
LightSong
;
class
Database
;
class
Storage
;
class
DetachedSong
;
class
Error
;
/**
* "Detach" the #Song object, i.e. convert it to a #DetachedSong
* instance.
*/
gcc_pure
DetachedSong
DatabaseDetachSong
(
const
Storage
&
storage
,
const
LightSong
&
song
);
/**
* Look up a song in the database and convert it to a #DetachedSong
* instance. The caller is responsible for freeing it.
*
...
...
@@ -34,6 +44,7 @@ class Error;
*/
gcc_malloc
gcc_nonnull_all
DetachedSong
*
DatabaseDetachSong
(
const
Database
&
db
,
const
char
*
uri
,
Error
&
error
);
DatabaseDetachSong
(
const
Database
&
db
,
const
Storage
&
storage
,
const
char
*
uri
,
Error
&
error
);
#endif
test/test_translate_song.cxx
View file @
c13810eb
...
...
@@ -117,7 +117,9 @@ static const char *uri1 = "/foo/bar.ogg";
static
const
char
*
uri2
=
"foo/bar.ogg"
;
DetachedSong
*
DatabaseDetachSong
(
gcc_unused
const
Database
&
db
,
const
char
*
uri
,
DatabaseDetachSong
(
gcc_unused
const
Database
&
db
,
gcc_unused
const
Storage
&
storage
,
const
char
*
uri
,
gcc_unused
Error
&
error
)
{
if
(
strcmp
(
uri
,
uri2
)
==
0
)
...
...
@@ -143,6 +145,12 @@ Client::GetDatabase(gcc_unused Error &error) const
return
reinterpret_cast
<
const
Database
*>
(
this
);
}
const
Storage
*
Client
::
GetStorage
()
const
{
return
reinterpret_cast
<
const
Storage
*>
(
this
);
}
bool
Client
::
AllowFile
(
gcc_unused
Path
path_fs
,
gcc_unused
Error
&
error
)
const
{
...
...
@@ -217,7 +225,7 @@ class TranslateSongTest : public CppUnit::TestFixture {
void
TestAbsoluteURI
()
{
DetachedSong
song1
(
"http://example.com/foo.ogg"
);
auto
se
=
ToString
(
song1
);
const
SongLoader
loader
(
nullptr
);
const
SongLoader
loader
(
nullptr
,
nullptr
);
CPPUNIT_ASSERT
(
playlist_check_translate_song
(
song1
,
"/ignored"
,
loader
));
CPPUNIT_ASSERT_EQUAL
(
se
,
ToString
(
song1
));
...
...
@@ -236,14 +244,15 @@ class TranslateSongTest : public CppUnit::TestFixture {
auto
s1
=
ToString
(
song1
);
auto
se
=
ToString
(
DetachedSong
(
uri1
,
MakeTag1c
()));
const
SongLoader
loader
(
nullptr
);
const
SongLoader
loader
(
nullptr
,
nullptr
);
CPPUNIT_ASSERT
(
playlist_check_translate_song
(
song1
,
"/ignored"
,
loader
));
CPPUNIT_ASSERT_EQUAL
(
se
,
ToString
(
song1
));
}
void
TestInDatabase
()
{
const
SongLoader
loader
(
reinterpret_cast
<
const
Database
*>
(
1
));
const
SongLoader
loader
(
reinterpret_cast
<
const
Database
*>
(
1
),
reinterpret_cast
<
const
Storage
*>
(
2
));
DetachedSong
song1
(
"doesntexist"
);
CPPUNIT_ASSERT
(
!
playlist_check_translate_song
(
song1
,
nullptr
,
...
...
@@ -266,9 +275,10 @@ class TranslateSongTest : public CppUnit::TestFixture {
void
TestRelative
()
{
const
Database
&
db
=
*
reinterpret_cast
<
const
Database
*>
(
1
);
const
SongLoader
secure_loader
(
&
db
);
const
Storage
&
storage
=
*
reinterpret_cast
<
const
Storage
*>
(
2
);
const
SongLoader
secure_loader
(
&
db
,
&
storage
);
const
SongLoader
insecure_loader
(
*
reinterpret_cast
<
const
Client
*>
(
1
),
&
db
);
&
db
,
&
storage
);
/* map to music_directory */
DetachedSong
song1
(
"bar.ogg"
,
MakeTag2b
());
...
...
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