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