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
bbdf2dcf
Commit
bbdf2dcf
authored
May 21, 2019
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
db/simple/Song: wrap in std::unique_ptr<>
parent
02bb47dd
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
65 additions
and
41 deletions
+65
-41
SongUpdate.cxx
src/SongUpdate.cxx
+6
-10
Directory.cxx
src/db/plugins/simple/Directory.cxx
+2
-2
Directory.hxx
src/db/plugins/simple/Directory.hxx
+2
-1
DirectorySave.cxx
src/db/plugins/simple/DirectorySave.cxx
+1
-1
Ptr.hxx
src/db/plugins/simple/Ptr.hxx
+29
-0
Song.cxx
src/db/plugins/simple/Song.cxx
+9
-8
Song.hxx
src/db/plugins/simple/Song.hxx
+8
-10
Archive.cxx
src/db/update/Archive.cxx
+3
-3
Container.cxx
src/db/update/Container.cxx
+2
-3
UpdateSong.cxx
src/db/update/UpdateSong.cxx
+3
-3
No files found.
src/SongUpdate.cxx
View file @
bbdf2dcf
...
@@ -41,18 +41,16 @@
...
@@ -41,18 +41,16 @@
#ifdef ENABLE_DATABASE
#ifdef ENABLE_DATABASE
Song
*
Song
Ptr
Song
::
LoadFile
(
Storage
&
storage
,
const
char
*
path_utf8
,
Song
::
LoadFile
(
Storage
&
storage
,
const
char
*
path_utf8
,
Directory
&
parent
)
noexcept
Directory
&
parent
)
noexcept
{
{
assert
(
!
uri_has_scheme
(
path_utf8
));
assert
(
!
uri_has_scheme
(
path_utf8
));
assert
(
strchr
(
path_utf8
,
'\n'
)
==
nullptr
);
assert
(
strchr
(
path_utf8
,
'\n'
)
==
nullptr
);
Song
*
song
=
NewFile
(
path_utf8
,
parent
);
auto
song
=
NewFile
(
path_utf8
,
parent
);
if
(
!
song
->
UpdateFile
(
storage
))
{
if
(
!
song
->
UpdateFile
(
storage
))
song
->
Free
();
return
nullptr
;
return
nullptr
;
}
return
song
;
return
song
;
}
}
...
@@ -102,19 +100,17 @@ Song::UpdateFile(Storage &storage) noexcept
...
@@ -102,19 +100,17 @@ Song::UpdateFile(Storage &storage) noexcept
#ifdef ENABLE_ARCHIVE
#ifdef ENABLE_ARCHIVE
Song
*
Song
Ptr
Song
::
LoadFromArchive
(
ArchiveFile
&
archive
,
const
char
*
name_utf8
,
Song
::
LoadFromArchive
(
ArchiveFile
&
archive
,
const
char
*
name_utf8
,
Directory
&
parent
)
noexcept
Directory
&
parent
)
noexcept
{
{
assert
(
!
uri_has_scheme
(
name_utf8
));
assert
(
!
uri_has_scheme
(
name_utf8
));
assert
(
strchr
(
name_utf8
,
'\n'
)
==
nullptr
);
assert
(
strchr
(
name_utf8
,
'\n'
)
==
nullptr
);
Song
*
song
=
NewFile
(
name_utf8
,
parent
);
auto
song
=
NewFile
(
name_utf8
,
parent
);
if
(
!
song
->
UpdateFileInArchive
(
archive
))
{
if
(
!
song
->
UpdateFileInArchive
(
archive
))
song
->
Free
();
return
nullptr
;
return
nullptr
;
}
return
song
;
return
song
;
}
}
...
...
src/db/plugins/simple/Directory.cxx
View file @
bbdf2dcf
...
@@ -164,13 +164,13 @@ Directory::LookupDirectory(const char *uri) noexcept
...
@@ -164,13 +164,13 @@ Directory::LookupDirectory(const char *uri) noexcept
}
}
void
void
Directory
::
AddSong
(
Song
*
song
)
noexcept
Directory
::
AddSong
(
Song
Ptr
song
)
noexcept
{
{
assert
(
holding_db_lock
());
assert
(
holding_db_lock
());
assert
(
song
!=
nullptr
);
assert
(
song
!=
nullptr
);
assert
(
song
->
parent
==
this
);
assert
(
song
->
parent
==
this
);
songs
.
push_back
(
*
song
);
songs
.
push_back
(
*
song
.
release
()
);
}
}
void
void
...
...
src/db/plugins/simple/Directory.hxx
View file @
bbdf2dcf
...
@@ -20,6 +20,7 @@
...
@@ -20,6 +20,7 @@
#ifndef MPD_DIRECTORY_HXX
#ifndef MPD_DIRECTORY_HXX
#define MPD_DIRECTORY_HXX
#define MPD_DIRECTORY_HXX
#include "Ptr.hxx"
#include "util/Compiler.h"
#include "util/Compiler.h"
#include "db/Visitor.hxx"
#include "db/Visitor.hxx"
#include "db/PlaylistVector.hxx"
#include "db/PlaylistVector.hxx"
...
@@ -242,7 +243,7 @@ public:
...
@@ -242,7 +243,7 @@ public:
* Add a song object to this directory. Its "parent" attribute must
* Add a song object to this directory. Its "parent" attribute must
* be set already.
* be set already.
*/
*/
void
AddSong
(
Song
*
song
)
noexcept
;
void
AddSong
(
Song
Ptr
song
)
noexcept
;
/**
/**
* Remove a song object from this directory (which effectively
* Remove a song object from this directory (which effectively
...
...
src/db/plugins/simple/DirectorySave.cxx
View file @
bbdf2dcf
...
@@ -168,7 +168,7 @@ directory_load(TextFile &file, Directory &directory)
...
@@ -168,7 +168,7 @@ directory_load(TextFile &file, Directory &directory)
directory
);
directory
);
song
->
audio_format
=
audio_format
;
song
->
audio_format
=
audio_format
;
directory
.
AddSong
(
s
ong
);
directory
.
AddSong
(
s
td
::
move
(
song
)
);
}
else
if
((
p
=
StringAfterPrefix
(
line
,
PLAYLIST_META_BEGIN
)))
{
}
else
if
((
p
=
StringAfterPrefix
(
line
,
PLAYLIST_META_BEGIN
)))
{
const
char
*
name
=
p
;
const
char
*
name
=
p
;
playlist_metadata_load
(
file
,
directory
.
playlists
,
name
);
playlist_metadata_load
(
file
,
directory
.
playlists
,
name
);
...
...
src/db/plugins/simple/Ptr.hxx
0 → 100644
View file @
bbdf2dcf
/*
* Copyright 2003-2019 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_SONG_PTR_HXX
#define MPD_SONG_PTR_HXX
#include "Disposer.hxx"
#include <memory>
using
SongPtr
=
std
::
unique_ptr
<
Song
,
SongDisposer
>
;
#endif
src/db/plugins/simple/Song.cxx
View file @
bbdf2dcf
...
@@ -40,7 +40,7 @@ Song::~Song() noexcept
...
@@ -40,7 +40,7 @@ Song::~Song() noexcept
{
{
}
}
static
Song
*
static
Song
Ptr
song_alloc
(
const
char
*
uri
,
Directory
&
parent
)
noexcept
song_alloc
(
const
char
*
uri
,
Directory
&
parent
)
noexcept
{
{
size_t
uri_length
;
size_t
uri_length
;
...
@@ -49,15 +49,16 @@ song_alloc(const char *uri, Directory &parent) noexcept
...
@@ -49,15 +49,16 @@ song_alloc(const char *uri, Directory &parent) noexcept
uri_length
=
strlen
(
uri
);
uri_length
=
strlen
(
uri
);
assert
(
uri_length
);
assert
(
uri_length
);
return
NewVarSize
<
Song
>
(
sizeof
(
Song
::
uri
),
auto
*
song
=
NewVarSize
<
Song
>
(
sizeof
(
Song
::
uri
),
uri_length
+
1
,
uri_length
+
1
,
uri
,
uri_length
,
parent
);
uri
,
uri_length
,
parent
);
return
SongPtr
(
song
);
}
}
Song
*
Song
Ptr
Song
::
NewFrom
(
DetachedSong
&&
other
,
Directory
&
parent
)
noexcept
Song
::
NewFrom
(
DetachedSong
&&
other
,
Directory
&
parent
)
noexcept
{
{
Song
*
song
=
song_alloc
(
other
.
GetURI
(),
parent
);
Song
Ptr
song
(
song_alloc
(
other
.
GetURI
(),
parent
)
);
song
->
tag
=
std
::
move
(
other
.
WritableTag
());
song
->
tag
=
std
::
move
(
other
.
WritableTag
());
song
->
mtime
=
other
.
GetLastModified
();
song
->
mtime
=
other
.
GetLastModified
();
song
->
start_time
=
other
.
GetStartTime
();
song
->
start_time
=
other
.
GetStartTime
();
...
@@ -65,10 +66,10 @@ Song::NewFrom(DetachedSong &&other, Directory &parent) noexcept
...
@@ -65,10 +66,10 @@ Song::NewFrom(DetachedSong &&other, Directory &parent) noexcept
return
song
;
return
song
;
}
}
Song
*
Song
Ptr
Song
::
NewFile
(
const
char
*
path
,
Directory
&
parent
)
noexcept
Song
::
NewFile
(
const
char
*
path
,
Directory
&
parent
)
noexcept
{
{
return
song_alloc
(
path
,
parent
);
return
SongPtr
(
song_alloc
(
path
,
parent
)
);
}
}
void
void
...
...
src/db/plugins/simple/Song.hxx
View file @
bbdf2dcf
...
@@ -20,6 +20,7 @@
...
@@ -20,6 +20,7 @@
#ifndef MPD_SONG_HXX
#ifndef MPD_SONG_HXX
#define MPD_SONG_HXX
#define MPD_SONG_HXX
#include "Ptr.hxx"
#include "Chrono.hxx"
#include "Chrono.hxx"
#include "tag/Tag.hxx"
#include "tag/Tag.hxx"
#include "AudioFormat.hxx"
#include "AudioFormat.hxx"
...
@@ -95,30 +96,27 @@ struct Song {
...
@@ -95,30 +96,27 @@ struct Song {
Song
(
const
char
*
_uri
,
size_t
uri_length
,
Directory
&
parent
)
noexcept
;
Song
(
const
char
*
_uri
,
size_t
uri_length
,
Directory
&
parent
)
noexcept
;
~
Song
()
noexcept
;
~
Song
()
noexcept
;
gcc_malloc
gcc_returns_nonnull
static
SongPtr
NewFrom
(
DetachedSong
&&
other
,
Directory
&
parent
)
noexcept
;
static
Song
*
NewFrom
(
DetachedSong
&&
other
,
Directory
&
parent
)
noexcept
;
/** allocate a new song with a local file name */
/** allocate a new song with a local file name */
gcc_malloc
gcc_returns_nonnull
static
SongPtr
NewFile
(
const
char
*
path_utf8
,
Directory
&
parent
)
noexcept
;
static
Song
*
NewFile
(
const
char
*
path_utf8
,
Directory
&
parent
)
noexcept
;
/**
/**
* allocate a new song structure with a local file name and attempt to
* allocate a new song structure with a local file name and attempt to
* load its metadata. If all decoder plugin fail to read its meta
* load its metadata. If all decoder plugin fail to read its meta
* data, nullptr is returned.
* data, nullptr is returned.
*/
*/
gcc_malloc
static
SongPtr
LoadFile
(
Storage
&
storage
,
const
char
*
name_utf8
,
static
Song
*
LoadFile
(
Storage
&
storage
,
const
char
*
name_utf8
,
Directory
&
parent
)
noexcept
;
Directory
&
parent
)
noexcept
;
void
Free
()
noexcept
;
void
Free
()
noexcept
;
bool
UpdateFile
(
Storage
&
storage
)
noexcept
;
bool
UpdateFile
(
Storage
&
storage
)
noexcept
;
#ifdef ENABLE_ARCHIVE
#ifdef ENABLE_ARCHIVE
static
Song
*
LoadFromArchive
(
ArchiveFile
&
archive
,
static
Song
Ptr
LoadFromArchive
(
ArchiveFile
&
archive
,
const
char
*
name_utf8
,
const
char
*
name_utf8
,
Directory
&
parent
)
noexcept
;
Directory
&
parent
)
noexcept
;
bool
UpdateFileInArchive
(
ArchiveFile
&
archive
)
noexcept
;
bool
UpdateFileInArchive
(
ArchiveFile
&
archive
)
noexcept
;
#endif
#endif
...
...
src/db/update/Archive.cxx
View file @
bbdf2dcf
...
@@ -82,11 +82,11 @@ UpdateWalk::UpdateArchiveTree(ArchiveFile &archive, Directory &directory,
...
@@ -82,11 +82,11 @@ UpdateWalk::UpdateArchiveTree(ArchiveFile &archive, Directory &directory,
//add file
//add file
Song
*
song
=
LockFindSong
(
directory
,
name
);
Song
*
song
=
LockFindSong
(
directory
,
name
);
if
(
song
==
nullptr
)
{
if
(
song
==
nullptr
)
{
song
=
Song
::
LoadFromArchive
(
archive
,
name
,
directory
);
auto
new_
song
=
Song
::
LoadFromArchive
(
archive
,
name
,
directory
);
if
(
song
!=
nullptr
)
{
if
(
!
new_song
)
{
{
{
const
ScopeDatabaseLock
protect
;
const
ScopeDatabaseLock
protect
;
directory
.
AddSong
(
s
ong
);
directory
.
AddSong
(
s
td
::
move
(
new_song
)
);
}
}
modified
=
true
;
modified
=
true
;
...
...
src/db/update/Container.cxx
View file @
bbdf2dcf
...
@@ -102,8 +102,7 @@ UpdateWalk::UpdateContainerFile(Directory &directory,
...
@@ -102,8 +102,7 @@ UpdateWalk::UpdateContainerFile(Directory &directory,
}
}
for
(
auto
&
vtrack
:
v
)
{
for
(
auto
&
vtrack
:
v
)
{
Song
*
song
=
Song
::
NewFrom
(
std
::
move
(
vtrack
),
auto
song
=
Song
::
NewFrom
(
std
::
move
(
vtrack
),
*
contdir
);
*
contdir
);
// shouldn't be necessary but it's there..
// shouldn't be necessary but it's there..
song
->
mtime
=
info
.
mtime
;
song
->
mtime
=
info
.
mtime
;
...
@@ -113,7 +112,7 @@ UpdateWalk::UpdateContainerFile(Directory &directory,
...
@@ -113,7 +112,7 @@ UpdateWalk::UpdateContainerFile(Directory &directory,
{
{
const
ScopeDatabaseLock
protect
;
const
ScopeDatabaseLock
protect
;
contdir
->
AddSong
(
s
ong
);
contdir
->
AddSong
(
s
td
::
move
(
song
)
);
}
}
modified
=
true
;
modified
=
true
;
...
...
src/db/update/UpdateSong.cxx
View file @
bbdf2dcf
...
@@ -61,8 +61,8 @@ UpdateWalk::UpdateSongFile2(Directory &directory,
...
@@ -61,8 +61,8 @@ UpdateWalk::UpdateSongFile2(Directory &directory,
if
(
song
==
nullptr
)
{
if
(
song
==
nullptr
)
{
FormatDebug
(
update_domain
,
"reading %s/%s"
,
FormatDebug
(
update_domain
,
"reading %s/%s"
,
directory
.
GetPath
(),
name
);
directory
.
GetPath
(),
name
);
song
=
Song
::
LoadFile
(
storage
,
name
,
directory
);
auto
new_
song
=
Song
::
LoadFile
(
storage
,
name
,
directory
);
if
(
song
==
nullptr
)
{
if
(
!
new_song
)
{
FormatDebug
(
update_domain
,
FormatDebug
(
update_domain
,
"ignoring unrecognized file %s/%s"
,
"ignoring unrecognized file %s/%s"
,
directory
.
GetPath
(),
name
);
directory
.
GetPath
(),
name
);
...
@@ -71,7 +71,7 @@ UpdateWalk::UpdateSongFile2(Directory &directory,
...
@@ -71,7 +71,7 @@ UpdateWalk::UpdateSongFile2(Directory &directory,
{
{
const
ScopeDatabaseLock
protect
;
const
ScopeDatabaseLock
protect
;
directory
.
AddSong
(
s
ong
);
directory
.
AddSong
(
s
td
::
move
(
new_song
)
);
}
}
modified
=
true
;
modified
=
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