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
2539f294
Commit
2539f294
authored
Mar 18, 2016
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
db/proxy: move code to MakeError()
Use this function instead of CheckError() when we already know an error has occurred.
parent
b6a3ce93
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
49 additions
and
26 deletions
+49
-26
ProxyDatabasePlugin.cxx
src/db/plugins/ProxyDatabasePlugin.cxx
+49
-26
No files found.
src/db/plugins/ProxyDatabasePlugin.cxx
View file @
2539f294
...
@@ -227,12 +227,10 @@ Convert(TagType tag_type)
...
@@ -227,12 +227,10 @@ Convert(TagType tag_type)
return
MPD_TAG_COUNT
;
return
MPD_TAG_COUNT
;
}
}
static
bool
static
void
Check
Error
(
struct
mpd_connection
*
connection
,
Error
&
error
)
Make
Error
(
struct
mpd_connection
*
connection
,
Error
&
error
)
{
{
const
auto
code
=
mpd_connection_get_error
(
connection
);
const
auto
code
=
mpd_connection_get_error
(
connection
);
if
(
code
==
MPD_ERROR_SUCCESS
)
return
true
;
AtScopeExit
(
connection
)
{
AtScopeExit
(
connection
)
{
mpd_connection_clear_error
(
connection
);
mpd_connection_clear_error
(
connection
);
...
@@ -249,7 +247,16 @@ CheckError(struct mpd_connection *connection, Error &error)
...
@@ -249,7 +247,16 @@ CheckError(struct mpd_connection *connection, Error &error)
error
.
Set
(
libmpdclient_domain
,
(
int
)
code
,
error
.
Set
(
libmpdclient_domain
,
(
int
)
code
,
mpd_connection_get_error_message
(
connection
));
mpd_connection_get_error_message
(
connection
));
}
}
}
static
bool
CheckError
(
struct
mpd_connection
*
connection
,
Error
&
error
)
{
const
auto
code
=
mpd_connection_get_error
(
connection
);
if
(
code
==
MPD_ERROR_SUCCESS
)
return
true
;
MakeError
(
connection
,
error
);
return
false
;
return
false
;
}
}
...
@@ -488,8 +495,8 @@ ProxyDatabase::OnIdle()
...
@@ -488,8 +495,8 @@ ProxyDatabase::OnIdle()
if
(
!
mpd_send_idle_mask
(
connection
,
MPD_IDLE_DATABASE
))
{
if
(
!
mpd_send_idle_mask
(
connection
,
MPD_IDLE_DATABASE
))
{
Error
error
;
Error
error
;
if
(
!
CheckError
(
connection
,
error
))
MakeError
(
connection
,
error
);
LogError
(
error
);
LogError
(
error
);
SocketMonitor
::
Steal
();
SocketMonitor
::
Steal
();
mpd_connection_free
(
connection
);
mpd_connection_free
(
connection
);
...
@@ -509,15 +516,15 @@ ProxyDatabase::GetSong(const char *uri, Error &error) const
...
@@ -509,15 +516,15 @@ ProxyDatabase::GetSong(const char *uri, Error &error) const
return
nullptr
;
return
nullptr
;
if
(
!
mpd_send_list_meta
(
connection
,
uri
))
{
if
(
!
mpd_send_list_meta
(
connection
,
uri
))
{
Check
Error
(
connection
,
error
);
Make
Error
(
connection
,
error
);
return
nullptr
;
return
nullptr
;
}
}
struct
mpd_song
*
song
=
mpd_recv_song
(
connection
);
struct
mpd_song
*
song
=
mpd_recv_song
(
connection
);
if
(
!
mpd_response_finish
(
connection
)
&&
if
(
!
mpd_response_finish
(
connection
))
{
!
CheckError
(
connection
,
error
))
{
if
(
song
!=
nullptr
)
if
(
song
!=
nullptr
)
mpd_song_free
(
song
);
mpd_song_free
(
song
);
MakeError
(
connection
,
error
);
return
nullptr
;
return
nullptr
;
}
}
...
@@ -646,8 +653,10 @@ Visit(struct mpd_connection *connection, const char *uri,
...
@@ -646,8 +653,10 @@ Visit(struct mpd_connection *connection, const char *uri,
VisitDirectory
visit_directory
,
VisitSong
visit_song
,
VisitDirectory
visit_directory
,
VisitSong
visit_song
,
VisitPlaylist
visit_playlist
,
Error
&
error
)
VisitPlaylist
visit_playlist
,
Error
&
error
)
{
{
if
(
!
mpd_send_list_meta
(
connection
,
uri
))
if
(
!
mpd_send_list_meta
(
connection
,
uri
))
{
return
CheckError
(
connection
,
error
);
MakeError
(
connection
,
error
);
return
false
;
}
std
::
list
<
ProxyEntity
>
entities
(
ReceiveEntities
(
connection
));
std
::
list
<
ProxyEntity
>
entities
(
ReceiveEntities
(
connection
));
if
(
!
CheckError
(
connection
,
error
))
if
(
!
CheckError
(
connection
,
error
))
...
@@ -698,8 +707,10 @@ SearchSongs(struct mpd_connection *connection,
...
@@ -698,8 +707,10 @@ SearchSongs(struct mpd_connection *connection,
if
(
!
mpd_search_db_songs
(
connection
,
exact
)
||
if
(
!
mpd_search_db_songs
(
connection
,
exact
)
||
!
SendConstraints
(
connection
,
selection
)
||
!
SendConstraints
(
connection
,
selection
)
||
!
mpd_search_commit
(
connection
))
!
mpd_search_commit
(
connection
))
{
return
CheckError
(
connection
,
error
);
MakeError
(
connection
,
error
);
return
false
;
}
bool
result
=
true
;
bool
result
=
true
;
struct
mpd_song
*
song
;
struct
mpd_song
*
song
;
...
@@ -710,8 +721,12 @@ SearchSongs(struct mpd_connection *connection,
...
@@ -710,8 +721,12 @@ SearchSongs(struct mpd_connection *connection,
visit_song
(
song2
,
error
);
visit_song
(
song2
,
error
);
}
}
mpd_response_finish
(
connection
);
if
(
!
mpd_response_finish
(
connection
)
&&
result
)
{
return
result
&&
CheckError
(
connection
,
error
);
MakeError
(
connection
,
error
);
result
=
false
;
}
return
result
;
}
}
/**
/**
...
@@ -774,16 +789,18 @@ ProxyDatabase::VisitUniqueTags(const DatabaseSelection &selection,
...
@@ -774,16 +789,18 @@ ProxyDatabase::VisitUniqueTags(const DatabaseSelection &selection,
return
false
;
return
false
;
}
}
if
(
!
mpd_search_db_tags
(
connection
,
tag_type2
)
)
if
(
!
mpd_search_db_tags
(
connection
,
tag_type2
)
||
return
CheckError
(
connection
,
error
);
!
SendConstraints
(
connection
,
selection
))
{
MakeError
(
connection
,
error
);
if
(
!
SendConstraints
(
connection
,
selection
))
return
false
;
return
CheckError
(
connection
,
error
);
}
// TODO: use group_mask
// TODO: use group_mask
if
(
!
mpd_search_commit
(
connection
))
if
(
!
mpd_search_commit
(
connection
))
{
return
CheckError
(
connection
,
error
);
MakeError
(
connection
,
error
);
return
false
;
}
bool
result
=
true
;
bool
result
=
true
;
...
@@ -808,8 +825,12 @@ ProxyDatabase::VisitUniqueTags(const DatabaseSelection &selection,
...
@@ -808,8 +825,12 @@ ProxyDatabase::VisitUniqueTags(const DatabaseSelection &selection,
result
=
visit_tag
(
tag
.
Commit
(),
error
);
result
=
visit_tag
(
tag
.
Commit
(),
error
);
}
}
mpd_response_finish
(
connection
);
if
(
!
mpd_response_finish
(
connection
)
&&
result
)
{
return
result
&&
CheckError
(
connection
,
error
);
MakeError
(
connection
,
error
);
result
=
false
;
}
return
result
;
}
}
bool
bool
...
@@ -825,8 +846,10 @@ ProxyDatabase::GetStats(const DatabaseSelection &selection,
...
@@ -825,8 +846,10 @@ ProxyDatabase::GetStats(const DatabaseSelection &selection,
struct
mpd_stats
*
stats2
=
struct
mpd_stats
*
stats2
=
mpd_run_stats
(
connection
);
mpd_run_stats
(
connection
);
if
(
stats2
==
nullptr
)
if
(
stats2
==
nullptr
)
{
return
CheckError
(
connection
,
error
);
MakeError
(
connection
,
error
);
return
false
;
}
update_stamp
=
(
time_t
)
mpd_stats_get_db_update_time
(
stats2
);
update_stamp
=
(
time_t
)
mpd_stats_get_db_update_time
(
stats2
);
...
...
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