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
086652dd
Commit
086652dd
authored
Oct 26, 2016
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Instance: add GetDatabaseOrThrow()
parent
6135f076
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
65 additions
and
40 deletions
+65
-40
Instance.cxx
src/Instance.cxx
+10
-0
Instance.hxx
src/Instance.hxx
+8
-0
Partition.cxx
src/Partition.cxx
+6
-0
Partition.hxx
src/Partition.hxx
+3
-0
Client.cxx
src/client/Client.cxx
+6
-0
Client.hxx
src/client/Client.hxx
+6
-0
DatabaseCommands.cxx
src/command/DatabaseCommands.cxx
+2
-4
PlaylistCommands.cxx
src/command/PlaylistCommands.cxx
+2
-4
StickerCommands.cxx
src/command/StickerCommands.cxx
+10
-12
Count.cxx
src/db/Count.cxx
+3
-5
DatabasePrint.cxx
src/db/DatabasePrint.cxx
+7
-11
DatabaseQueue.cxx
src/db/DatabaseQueue.cxx
+2
-4
No files found.
src/Instance.cxx
View file @
086652dd
...
...
@@ -44,6 +44,16 @@ Instance::GetDatabase(Error &error)
return
database
;
}
const
Database
&
Instance
::
GetDatabaseOrThrow
()
const
{
if
(
database
==
nullptr
)
throw
DatabaseError
(
DatabaseErrorCode
::
DISABLED
,
"No database"
);
return
*
database
;
}
void
Instance
::
OnDatabaseModified
()
{
...
...
src/Instance.hxx
View file @
086652dd
...
...
@@ -110,6 +110,14 @@ struct Instance final
* music_directory was configured).
*/
Database
*
GetDatabase
(
Error
&
error
);
/**
* Returns the global #Database instance. Throws
* DatabaseError if this MPD configuration has no database (no
* music_directory was configured).
*/
gcc_pure
const
Database
&
GetDatabaseOrThrow
()
const
;
#endif
private
:
...
...
src/Partition.cxx
View file @
086652dd
...
...
@@ -50,6 +50,12 @@ Partition::GetDatabase(Error &error) const
return
instance
.
GetDatabase
(
error
);
}
const
Database
&
Partition
::
GetDatabaseOrThrow
()
const
{
return
instance
.
GetDatabaseOrThrow
();
}
void
Partition
::
DatabaseModified
(
const
Database
&
db
)
{
...
...
src/Partition.hxx
View file @
086652dd
...
...
@@ -185,6 +185,9 @@ struct Partition final : QueueListener, PlayerListener, MixerListener {
*/
const
Database
*
GetDatabase
(
Error
&
error
)
const
;
gcc_pure
const
Database
&
GetDatabaseOrThrow
()
const
;
/**
* The database has been modified. Propagate the change to
* all subsystems.
...
...
src/client/Client.cxx
View file @
086652dd
...
...
@@ -33,6 +33,12 @@ Client::GetDatabase(Error &error) const
return
partition
.
instance
.
GetDatabase
(
error
);
}
const
Database
&
Client
::
GetDatabaseOrThrow
()
const
{
return
partition
.
instance
.
GetDatabaseOrThrow
();
}
const
Storage
*
Client
::
GetStorage
()
const
{
...
...
src/client/Client.hxx
View file @
086652dd
...
...
@@ -187,6 +187,12 @@ public:
gcc_pure
const
Database
*
GetDatabase
(
Error
&
error
)
const
;
/**
* Wrapper for Instance::GetDatabaseOrThrow().
*/
gcc_pure
const
Database
&
GetDatabaseOrThrow
()
const
;
gcc_pure
const
Storage
*
GetStorage
()
const
;
...
...
src/command/DatabaseCommands.cxx
View file @
086652dd
...
...
@@ -143,11 +143,9 @@ handle_searchaddpl(Client &client, Request args, Response &r)
}
Error
error
;
const
Database
*
db
=
client
.
GetDatabase
(
error
);
if
(
db
==
nullptr
)
return
print_error
(
r
,
error
);
const
Database
&
db
=
client
.
GetDatabaseOrThrow
();
return
search_add_to_playlist
(
*
db
,
*
client
.
GetStorage
(),
return
search_add_to_playlist
(
db
,
*
client
.
GetStorage
(),
""
,
playlist
,
&
filter
,
error
)
?
CommandResult
::
OK
:
print_error
(
r
,
error
);
...
...
src/command/PlaylistCommands.cxx
View file @
086652dd
...
...
@@ -168,11 +168,9 @@ handle_playlistadd(Client &client, Request args, Response &r)
success
=
spl_append_uri
(
playlist
,
loader
,
uri
,
error
);
}
else
{
#ifdef ENABLE_DATABASE
const
Database
*
db
=
client
.
GetDatabase
(
error
);
if
(
db
==
nullptr
)
return
print_error
(
r
,
error
);
const
Database
&
db
=
client
.
GetDatabaseOrThrow
();
success
=
search_add_to_playlist
(
*
db
,
*
client
.
GetStorage
(),
success
=
search_add_to_playlist
(
db
,
*
client
.
GetStorage
(),
uri
,
playlist
,
nullptr
,
error
);
#else
...
...
src/command/StickerCommands.cxx
View file @
086652dd
...
...
@@ -54,19 +54,17 @@ static CommandResult
handle_sticker_song
(
Response
&
r
,
Partition
&
partition
,
Request
args
)
{
Error
error
;
const
Database
*
db
=
partition
.
GetDatabase
(
error
);
if
(
db
==
nullptr
)
return
print_error
(
r
,
error
);
const
Database
&
db
=
partition
.
GetDatabaseOrThrow
();
const
char
*
const
cmd
=
args
.
front
();
/* get song song_id key */
if
(
args
.
size
==
4
&&
StringIsEqual
(
cmd
,
"get"
))
{
const
LightSong
*
song
=
db
->
GetSong
(
args
[
2
]);
const
LightSong
*
song
=
db
.
GetSong
(
args
[
2
]);
const
auto
value
=
sticker_song_get_value
(
*
song
,
args
[
3
],
error
);
db
->
ReturnSong
(
song
);
db
.
ReturnSong
(
song
);
if
(
value
.
empty
())
{
if
(
error
.
IsDefined
())
return
print_error
(
r
,
error
);
...
...
@@ -80,11 +78,11 @@ handle_sticker_song(Response &r, Partition &partition, Request args)
return
CommandResult
::
OK
;
/* list song song_id */
}
else
if
(
args
.
size
==
3
&&
StringIsEqual
(
cmd
,
"list"
))
{
const
LightSong
*
song
=
db
->
GetSong
(
args
[
2
]);
const
LightSong
*
song
=
db
.
GetSong
(
args
[
2
]);
assert
(
song
!=
nullptr
);
Sticker
*
sticker
=
sticker_song_get
(
*
song
,
error
);
db
->
ReturnSong
(
song
);
db
.
ReturnSong
(
song
);
if
(
sticker
)
{
sticker_print
(
r
,
*
sticker
);
sticker_free
(
sticker
);
...
...
@@ -94,12 +92,12 @@ handle_sticker_song(Response &r, Partition &partition, Request args)
return
CommandResult
::
OK
;
/* set song song_id id key */
}
else
if
(
args
.
size
==
5
&&
StringIsEqual
(
cmd
,
"set"
))
{
const
LightSong
*
song
=
db
->
GetSong
(
args
[
2
]);
const
LightSong
*
song
=
db
.
GetSong
(
args
[
2
]);
assert
(
song
!=
nullptr
);
bool
ret
=
sticker_song_set_value
(
*
song
,
args
[
3
],
args
[
4
],
error
);
db
->
ReturnSong
(
song
);
db
.
ReturnSong
(
song
);
if
(
!
ret
)
{
if
(
error
.
IsDefined
())
return
print_error
(
r
,
error
);
...
...
@@ -113,13 +111,13 @@ handle_sticker_song(Response &r, Partition &partition, Request args)
/* delete song song_id [key] */
}
else
if
((
args
.
size
==
3
||
args
.
size
==
4
)
&&
StringIsEqual
(
cmd
,
"delete"
))
{
const
LightSong
*
song
=
db
->
GetSong
(
args
[
2
]);
const
LightSong
*
song
=
db
.
GetSong
(
args
[
2
]);
assert
(
song
!=
nullptr
);
bool
ret
=
args
.
size
==
3
?
sticker_song_delete
(
*
song
,
error
)
:
sticker_song_delete_value
(
*
song
,
args
[
3
],
error
);
db
->
ReturnSong
(
song
);
db
.
ReturnSong
(
song
);
if
(
!
ret
)
{
if
(
error
.
IsDefined
())
return
print_error
(
r
,
error
);
...
...
@@ -163,7 +161,7 @@ handle_sticker_song(Response &r, Partition &partition, Request args)
args
[
3
],
};
if
(
!
sticker_song_find
(
*
db
,
base_uri
,
data
.
name
,
if
(
!
sticker_song_find
(
db
,
base_uri
,
data
.
name
,
op
,
value
,
sticker_song_find_print_cb
,
&
data
,
error
))
{
...
...
src/db/Count.cxx
View file @
086652dd
...
...
@@ -113,9 +113,7 @@ PrintSongCount(Response &r, const Partition &partition, const char *name,
TagType
group
,
Error
&
error
)
{
const
Database
*
db
=
partition
.
GetDatabase
(
error
);
if
(
db
==
nullptr
)
return
false
;
const
Database
&
db
=
partition
.
GetDatabaseOrThrow
();
const
DatabaseSelection
selection
(
name
,
true
,
filter
);
...
...
@@ -127,7 +125,7 @@ PrintSongCount(Response &r, const Partition &partition, const char *name,
using
namespace
std
::
placeholders
;
const
auto
f
=
std
::
bind
(
stats_visitor_song
,
std
::
ref
(
stats
),
_1
);
if
(
!
db
->
Visit
(
selection
,
f
,
error
))
if
(
!
db
.
Visit
(
selection
,
f
,
error
))
return
false
;
PrintSearchStats
(
r
,
stats
);
...
...
@@ -140,7 +138,7 @@ PrintSongCount(Response &r, const Partition &partition, const char *name,
using
namespace
std
::
placeholders
;
const
auto
f
=
std
::
bind
(
GroupCountVisitor
,
std
::
ref
(
map
),
group
,
_1
);
if
(
!
db
->
Visit
(
selection
,
f
,
error
))
if
(
!
db
.
Visit
(
selection
,
f
,
error
))
return
false
;
Print
(
r
,
group
,
map
);
...
...
src/db/DatabasePrint.cxx
View file @
086652dd
...
...
@@ -155,9 +155,7 @@ db_selection_print(Response &r, Partition &partition,
unsigned
window_start
,
unsigned
window_end
,
Error
&
error
)
{
const
Database
*
db
=
partition
.
GetDatabase
(
error
);
if
(
db
==
nullptr
)
return
false
;
const
Database
&
db
=
partition
.
GetDatabaseOrThrow
();
unsigned
i
=
0
;
...
...
@@ -182,7 +180,7 @@ db_selection_print(Response &r, Partition &partition,
return
!
in_window
||
s
(
song
,
error2
);
};
return
db
->
Visit
(
selection
,
d
,
s
,
p
,
error
);
return
db
.
Visit
(
selection
,
d
,
s
,
p
,
error
);
}
bool
...
...
@@ -226,9 +224,7 @@ PrintUniqueTags(Response &r, Partition &partition,
const
SongFilter
*
filter
,
Error
&
error
)
{
const
Database
*
db
=
partition
.
GetDatabase
(
error
);
if
(
db
==
nullptr
)
return
false
;
const
Database
&
db
=
partition
.
GetDatabaseOrThrow
();
const
DatabaseSelection
selection
(
""
,
true
,
filter
);
...
...
@@ -236,15 +232,15 @@ PrintUniqueTags(Response &r, Partition &partition,
using
namespace
std
::
placeholders
;
const
auto
f
=
std
::
bind
(
PrintSongURIVisitor
,
std
::
ref
(
r
),
std
::
ref
(
partition
),
_1
);
return
db
->
Visit
(
selection
,
f
,
error
);
return
db
.
Visit
(
selection
,
f
,
error
);
}
else
{
assert
(
type
<
TAG_NUM_OF_ITEM_TYPES
);
using
namespace
std
::
placeholders
;
const
auto
f
=
std
::
bind
(
PrintUniqueTag
,
std
::
ref
(
r
),
(
TagType
)
type
,
_1
);
return
db
->
VisitUniqueTags
(
selection
,
(
TagType
)
type
,
group_mask
,
f
,
error
);
return
db
.
VisitUniqueTags
(
selection
,
(
TagType
)
type
,
group_mask
,
f
,
error
);
}
}
src/db/DatabaseQueue.cxx
View file @
086652dd
...
...
@@ -41,11 +41,9 @@ bool
AddFromDatabase
(
Partition
&
partition
,
const
DatabaseSelection
&
selection
,
Error
&
error
)
{
const
Database
*
db
=
partition
.
instance
.
GetDatabase
(
error
);
if
(
db
==
nullptr
)
return
false
;
const
Database
&
db
=
partition
.
instance
.
GetDatabaseOrThrow
();
using
namespace
std
::
placeholders
;
const
auto
f
=
std
::
bind
(
AddToQueue
,
std
::
ref
(
partition
),
_1
);
return
db
->
Visit
(
selection
,
f
,
error
);
return
db
.
Visit
(
selection
,
f
,
error
);
}
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