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
a42f9e4e
Commit
a42f9e4e
authored
Jan 22, 2014
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
LightDirectory: new struct replacing Directory in the DB API
parent
f16db6cd
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
109 additions
and
42 deletions
+109
-42
Makefile.am
Makefile.am
+1
-0
DatabasePrint.cxx
src/DatabasePrint.cxx
+7
-6
DatabaseVisitor.hxx
src/DatabaseVisitor.hxx
+3
-3
Directory.cxx
src/Directory.cxx
+9
-2
Directory.hxx
src/Directory.hxx
+3
-0
LightDirectory.hxx
src/LightDirectory.hxx
+61
-0
SongPrint.cxx
src/SongPrint.cxx
+0
-1
OtherCommands.cxx
src/command/OtherCommands.cxx
+1
-0
ProxyDatabasePlugin.cxx
src/db/ProxyDatabasePlugin.cxx
+12
-15
SimpleDatabasePlugin.cxx
src/db/SimpleDatabasePlugin.cxx
+2
-1
UpnpDatabasePlugin.cxx
src/db/UpnpDatabasePlugin.cxx
+4
-9
DumpDatabase.cxx
test/DumpDatabase.cxx
+6
-5
No files found.
Makefile.am
View file @
a42f9e4e
...
...
@@ -197,6 +197,7 @@ src_mpd_SOURCES = \
src/SignalHandlers.cxx src/SignalHandlers.hxx
\
src/DetachedSong.cxx src/DetachedSong.hxx
\
src/LightSong.cxx src/LightSong.hxx
\
src/LightDirectory.hxx
\
src/Song.cxx src/Song.hxx
\
src/SongUpdate.cxx
\
src/SongPrint.cxx src/SongPrint.hxx
\
...
...
src/DatabasePrint.cxx
View file @
a42f9e4e
...
...
@@ -23,17 +23,18 @@
#include "SongFilter.hxx"
#include "SongPrint.hxx"
#include "TimePrint.hxx"
#include "Directory.hxx"
#include "Client.hxx"
#include "tag/Tag.hxx"
#include "LightSong.hxx"
#include "LightDirectory.hxx"
#include "PlaylistInfo.hxx"
#include "DatabaseGlue.hxx"
#include "DatabasePlugin.hxx"
#include <functional>
static
bool
PrintDirectoryBrief
(
Client
&
client
,
const
Directory
&
directory
)
PrintDirectoryBrief
(
Client
&
client
,
const
Light
Directory
&
directory
)
{
if
(
!
directory
.
IsRoot
())
client_printf
(
client
,
"directory: %s
\n
"
,
directory
.
GetPath
());
...
...
@@ -42,7 +43,7 @@ PrintDirectoryBrief(Client &client, const Directory &directory)
}
static
bool
PrintDirectoryFull
(
Client
&
client
,
const
Directory
&
directory
)
PrintDirectoryFull
(
Client
&
client
,
const
Light
Directory
&
directory
)
{
if
(
!
directory
.
IsRoot
())
{
client_printf
(
client
,
"directory: %s
\n
"
,
directory
.
GetPath
());
...
...
@@ -68,7 +69,7 @@ print_playlist_in_directory(Client &client,
static
void
print_playlist_in_directory
(
Client
&
client
,
const
Directory
*
directory
,
const
Light
Directory
*
directory
,
const
char
*
name_utf8
)
{
if
(
directory
==
nullptr
||
directory
->
IsRoot
())
...
...
@@ -105,7 +106,7 @@ PrintSongFull(Client &client, const LightSong &song)
static
bool
PrintPlaylistBrief
(
Client
&
client
,
const
PlaylistInfo
&
playlist
,
const
Directory
&
directory
)
const
Light
Directory
&
directory
)
{
print_playlist_in_directory
(
client
,
&
directory
,
playlist
.
name
.
c_str
());
return
true
;
...
...
@@ -114,7 +115,7 @@ PrintPlaylistBrief(Client &client,
static
bool
PrintPlaylistFull
(
Client
&
client
,
const
PlaylistInfo
&
playlist
,
const
Directory
&
directory
)
const
Light
Directory
&
directory
)
{
print_playlist_in_directory
(
client
,
&
directory
,
playlist
.
name
.
c_str
());
...
...
src/DatabaseVisitor.hxx
View file @
a42f9e4e
...
...
@@ -22,14 +22,14 @@
#include <functional>
struct
Directory
;
struct
Light
Directory
;
struct
LightSong
;
struct
PlaylistInfo
;
class
Error
;
typedef
std
::
function
<
bool
(
const
Directory
&
,
Error
&
)
>
VisitDirectory
;
typedef
std
::
function
<
bool
(
const
Light
Directory
&
,
Error
&
)
>
VisitDirectory
;
typedef
std
::
function
<
bool
(
const
LightSong
&
,
Error
&
)
>
VisitSong
;
typedef
std
::
function
<
bool
(
const
PlaylistInfo
&
,
const
Directory
&
,
typedef
std
::
function
<
bool
(
const
PlaylistInfo
&
,
const
Light
Directory
&
,
Error
&
)
>
VisitPlaylist
;
typedef
std
::
function
<
bool
(
const
char
*
,
Error
&
)
>
VisitString
;
...
...
src/Directory.cxx
View file @
a42f9e4e
...
...
@@ -19,6 +19,7 @@
#include "config.h"
#include "Directory.hxx"
#include "LightDirectory.hxx"
#include "SongFilter.hxx"
#include "PlaylistVector.hxx"
#include "DatabaseLock.hxx"
...
...
@@ -272,14 +273,14 @@ Directory::Walk(bool recursive, const SongFilter *filter,
if
(
visit_playlist
)
{
for
(
const
PlaylistInfo
&
p
:
playlists
)
if
(
!
visit_playlist
(
p
,
*
this
,
error
))
if
(
!
visit_playlist
(
p
,
Export
()
,
error
))
return
false
;
}
Directory
*
child
;
directory_for_each_child
(
child
,
*
this
)
{
if
(
visit_directory
&&
!
visit_directory
(
*
child
,
error
))
!
visit_directory
(
child
->
Export
()
,
error
))
return
false
;
if
(
recursive
&&
...
...
@@ -291,3 +292,9 @@ Directory::Walk(bool recursive, const SongFilter *filter,
return
true
;
}
LightDirectory
Directory
::
Export
()
const
{
return
LightDirectory
(
GetPath
(),
mtime
);
}
src/Directory.hxx
View file @
a42f9e4e
...
...
@@ -234,6 +234,9 @@ public:
VisitDirectory
visit_directory
,
VisitSong
visit_song
,
VisitPlaylist
visit_playlist
,
Error
&
error
)
const
;
gcc_pure
LightDirectory
Export
()
const
;
};
static
inline
bool
...
...
src/LightDirectory.hxx
0 → 100644
View file @
a42f9e4e
/*
* Copyright (C) 2003-2014 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_LIGHT_DIRECTORY_HXX
#define MPD_LIGHT_DIRECTORY_HXX
#include "Compiler.h"
#include <string>
#include <time.h>
struct
Tag
;
/**
* A reference to a directory. Unlike the #Directory class, this one
* consists only of pointers. It is supposed to be as light as
* possible while still providing all the information MPD has about a
* directory. This class does not manage any memory, and the pointers
* become invalid quickly. Only to be used to pass around during
* well-defined situations.
*/
struct
LightDirectory
{
const
char
*
uri
;
time_t
mtime
;
constexpr
LightDirectory
(
const
char
*
_uri
,
time_t
_mtime
)
:
uri
(
_uri
),
mtime
(
_mtime
)
{}
static
constexpr
LightDirectory
Root
()
{
return
LightDirectory
(
""
,
0
);
}
bool
IsRoot
()
const
{
return
*
uri
==
0
;
}
gcc_pure
const
char
*
GetPath
()
const
{
return
uri
;
}
};
#endif
src/SongPrint.cxx
View file @
a42f9e4e
...
...
@@ -21,7 +21,6 @@
#include "SongPrint.hxx"
#include "LightSong.hxx"
#include "DetachedSong.hxx"
#include "Directory.hxx"
#include "TimePrint.hxx"
#include "TagPrint.hxx"
#include "Mapper.hxx"
...
...
src/command/OtherCommands.cxx
View file @
a42f9e4e
...
...
@@ -42,6 +42,7 @@
#include "Stats.hxx"
#include "Permission.hxx"
#include "PlaylistFile.hxx"
#include "PlaylistVector.hxx"
#include "ClientFile.hxx"
#include "Client.hxx"
#include "Idle.hxx"
...
...
src/db/ProxyDatabasePlugin.cxx
View file @
a42f9e4e
...
...
@@ -23,7 +23,8 @@
#include "DatabaseListener.hxx"
#include "DatabaseSelection.hxx"
#include "DatabaseError.hxx"
#include "Directory.hxx"
#include "PlaylistInfo.hxx"
#include "LightDirectory.hxx"
#include "LightSong.hxx"
#include "SongFilter.hxx"
#include "Compiler.h"
...
...
@@ -71,7 +72,6 @@ class ProxyDatabase final : public Database, SocketMonitor, IdleMonitor {
unsigned
port
;
struct
mpd_connection
*
connection
;
Directory
*
root
;
/* this is mutable because GetStats() must be "const" */
mutable
time_t
update_stamp
;
...
...
@@ -328,7 +328,6 @@ ProxyDatabase::Open(Error &error)
if
(
!
Connect
(
error
))
return
false
;
root
=
Directory
::
NewRoot
();
update_stamp
=
0
;
return
true
;
...
...
@@ -337,8 +336,6 @@ ProxyDatabase::Open(Error &error)
void
ProxyDatabase
::
Close
()
{
delete
root
;
if
(
connection
!=
nullptr
)
Disconnect
();
}
...
...
@@ -515,13 +512,13 @@ ProxyDatabase::ReturnSong(const LightSong *_song) const
}
static
bool
Visit
(
struct
mpd_connection
*
connection
,
Directory
&
root
,
const
char
*
uri
,
Visit
(
struct
mpd_connection
*
connection
,
const
char
*
uri
,
bool
recursive
,
const
SongFilter
*
filter
,
VisitDirectory
visit_directory
,
VisitSong
visit_song
,
VisitPlaylist
visit_playlist
,
Error
&
error
);
static
bool
Visit
(
struct
mpd_connection
*
connection
,
Directory
&
root
,
Visit
(
struct
mpd_connection
*
connection
,
bool
recursive
,
const
SongFilter
*
filter
,
const
struct
mpd_directory
*
directory
,
VisitDirectory
visit_directory
,
VisitSong
visit_song
,
...
...
@@ -530,11 +527,11 @@ Visit(struct mpd_connection *connection, Directory &root,
const
char
*
path
=
mpd_directory_get_path
(
directory
);
if
(
visit_directory
&&
!
visit_directory
(
Directory
(
path
,
&
root
),
error
))
!
visit_directory
(
LightDirectory
(
path
,
0
),
error
))
return
false
;
if
(
recursive
&&
!
Visit
(
connection
,
root
,
path
,
recursive
,
filter
,
!
Visit
(
connection
,
path
,
recursive
,
filter
,
visit_directory
,
visit_song
,
visit_playlist
,
error
))
return
false
;
...
...
@@ -561,7 +558,7 @@ Visit(const SongFilter *filter,
}
static
bool
Visit
(
const
struct
mpd_playlist
*
playlist
,
Directory
&
root
,
Visit
(
const
struct
mpd_playlist
*
playlist
,
VisitPlaylist
visit_playlist
,
Error
&
error
)
{
if
(
!
visit_playlist
)
...
...
@@ -570,7 +567,7 @@ Visit(const struct mpd_playlist *playlist, Directory &root,
PlaylistInfo
p
(
mpd_playlist_get_path
(
playlist
),
mpd_playlist_get_last_modified
(
playlist
));
return
visit_playlist
(
p
,
root
,
error
);
return
visit_playlist
(
p
,
LightDirectory
::
Root
()
,
error
);
}
class
ProxyEntity
{
...
...
@@ -612,7 +609,7 @@ ReceiveEntities(struct mpd_connection *connection)
}
static
bool
Visit
(
struct
mpd_connection
*
connection
,
Directory
&
root
,
const
char
*
uri
,
Visit
(
struct
mpd_connection
*
connection
,
const
char
*
uri
,
bool
recursive
,
const
SongFilter
*
filter
,
VisitDirectory
visit_directory
,
VisitSong
visit_song
,
VisitPlaylist
visit_playlist
,
Error
&
error
)
...
...
@@ -630,7 +627,7 @@ Visit(struct mpd_connection *connection, Directory &root, const char *uri,
break
;
case
MPD_ENTITY_TYPE_DIRECTORY
:
if
(
!
Visit
(
connection
,
r
oot
,
r
ecursive
,
filter
,
if
(
!
Visit
(
connection
,
recursive
,
filter
,
mpd_entity_get_directory
(
entity
),
visit_directory
,
visit_song
,
visit_playlist
,
error
))
...
...
@@ -645,7 +642,7 @@ Visit(struct mpd_connection *connection, Directory &root, const char *uri,
break
;
case
MPD_ENTITY_TYPE_PLAYLIST
:
if
(
!
Visit
(
mpd_entity_get_playlist
(
entity
),
root
,
if
(
!
Visit
(
mpd_entity_get_playlist
(
entity
),
visit_playlist
,
error
))
return
false
;
break
;
...
...
@@ -702,7 +699,7 @@ ProxyDatabase::Visit(const DatabaseSelection &selection,
return
::
SearchSongs
(
connection
,
selection
,
visit_song
,
error
);
/* fall back to recursive walk (slow!) */
return
::
Visit
(
connection
,
*
root
,
selection
.
uri
.
c_str
(),
return
::
Visit
(
connection
,
selection
.
uri
.
c_str
(),
selection
.
recursive
,
selection
.
filter
,
visit_directory
,
visit_song
,
visit_playlist
,
error
);
...
...
src/db/SimpleDatabasePlugin.cxx
View file @
a42f9e4e
...
...
@@ -21,6 +21,7 @@
#include "SimpleDatabasePlugin.hxx"
#include "DatabaseSelection.hxx"
#include "DatabaseHelpers.hxx"
#include "LightDirectory.hxx"
#include "Directory.hxx"
#include "Song.hxx"
#include "SongFilter.hxx"
...
...
@@ -265,7 +266,7 @@ SimpleDatabase::Visit(const DatabaseSelection &selection,
}
if
(
selection
.
recursive
&&
visit_directory
&&
!
visit_directory
(
*
directory
,
error
))
!
visit_directory
(
directory
->
Export
()
,
error
))
return
false
;
return
directory
->
Walk
(
selection
.
recursive
,
selection
.
filter
,
...
...
src/db/UpnpDatabasePlugin.cxx
View file @
a42f9e4e
...
...
@@ -29,8 +29,7 @@
#include "DatabasePlugin.hxx"
#include "DatabaseSelection.hxx"
#include "DatabaseError.hxx"
#include "PlaylistVector.hxx"
#include "Directory.hxx"
#include "LightDirectory.hxx"
#include "LightSong.hxx"
#include "ConfigData.hxx"
#include "tag/TagBuilder.hxx"
...
...
@@ -71,7 +70,6 @@ public:
class
UpnpDatabase
:
public
Database
{
LibUPnP
*
m_lib
;
UPnPDeviceDirectory
*
m_superdir
;
Directory
*
m_root
;
public
:
static
Database
*
Create
(
EventLoop
&
loop
,
DatabaseListener
&
listener
,
...
...
@@ -190,7 +188,6 @@ UpnpDatabase::Open(Error &error)
return
false
;
}
m_root
=
Directory
::
NewRoot
();
// Wait for device answers. This should be consistent with the value set
// in the lib (currently 2)
sleep
(
2
);
...
...
@@ -200,7 +197,6 @@ UpnpDatabase::Open(Error &error)
void
UpnpDatabase
::
Close
()
{
delete
m_root
;
delete
m_superdir
;
delete
m_lib
;
}
...
...
@@ -602,9 +598,8 @@ UpnpDatabase::VisitServer(ContentDirectoryService &server,
case
UPnPDirObject
:
:
Type
::
CONTAINER
:
if
(
visit_directory
)
{
Directory
d
((
selection
.
uri
+
"/"
+
dirent
.
name
).
c_str
(),
m_root
);
const
std
::
string
uri
=
selection
.
uri
+
"/"
+
dirent
.
name
;
const
LightDirectory
d
(
uri
.
c_str
(),
0
);
if
(
!
visit_directory
(
d
,
error
))
return
false
;
}
...
...
@@ -673,7 +668,7 @@ UpnpDatabase::Visit(const DatabaseSelection &selection,
// pseudo-directory from the list of servers.
if
(
visit_directory
)
{
for
(
auto
&
server
:
servers
)
{
Directory
d
(
server
.
getFriendlyName
(),
m_root
);
const
LightDirectory
d
(
server
.
getFriendlyName
(),
0
);
if
(
!
visit_directory
(
d
,
error
))
return
false
;
}
...
...
test/DumpDatabase.cxx
View file @
a42f9e4e
...
...
@@ -22,7 +22,7 @@
#include "DatabasePlugin.hxx"
#include "DatabaseSelection.hxx"
#include "DatabaseListener.hxx"
#include "Directory.hxx"
#include "
Light
Directory.hxx"
#include "LightSong.hxx"
#include "PlaylistVector.hxx"
#include "ConfigGlobal.hxx"
...
...
@@ -58,9 +58,9 @@ public:
};
static
bool
DumpDirectory
(
const
Directory
&
directory
,
Error
&
)
DumpDirectory
(
const
Light
Directory
&
directory
,
Error
&
)
{
cout
<<
"D "
<<
directory
.
path
<<
endl
;
cout
<<
"D "
<<
directory
.
GetPath
()
<<
endl
;
return
true
;
}
...
...
@@ -76,9 +76,10 @@ DumpSong(const LightSong &song, Error &)
static
bool
DumpPlaylist
(
const
PlaylistInfo
&
playlist
,
const
Directory
&
directory
,
Error
&
)
const
Light
Directory
&
directory
,
Error
&
)
{
cout
<<
"P "
<<
directory
.
path
<<
"/"
<<
playlist
.
name
.
c_str
()
<<
endl
;
cout
<<
"P "
<<
directory
.
GetPath
()
<<
"/"
<<
playlist
.
name
.
c_str
()
<<
endl
;
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