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
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
48 additions
and
25 deletions
+48
-25
ProxyDatabasePlugin.cxx
src/db/plugins/ProxyDatabasePlugin.cxx
+48
-25
No files found.
src/db/plugins/ProxyDatabasePlugin.cxx
View file @
2539f294
...
...
@@ -227,12 +227,10 @@ Convert(TagType tag_type)
return
MPD_TAG_COUNT
;
}
static
bool
Check
Error
(
struct
mpd_connection
*
connection
,
Error
&
error
)
static
void
Make
Error
(
struct
mpd_connection
*
connection
,
Error
&
error
)
{
const
auto
code
=
mpd_connection_get_error
(
connection
);
if
(
code
==
MPD_ERROR_SUCCESS
)
return
true
;
AtScopeExit
(
connection
)
{
mpd_connection_clear_error
(
connection
);
...
...
@@ -249,7 +247,16 @@ CheckError(struct mpd_connection *connection, Error &error)
error
.
Set
(
libmpdclient_domain
,
(
int
)
code
,
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
;
}
...
...
@@ -488,7 +495,7 @@ ProxyDatabase::OnIdle()
if
(
!
mpd_send_idle_mask
(
connection
,
MPD_IDLE_DATABASE
))
{
Error
error
;
if
(
!
CheckError
(
connection
,
error
))
MakeError
(
connection
,
error
);
LogError
(
error
);
SocketMonitor
::
Steal
();
...
...
@@ -509,15 +516,15 @@ ProxyDatabase::GetSong(const char *uri, Error &error) const
return
nullptr
;
if
(
!
mpd_send_list_meta
(
connection
,
uri
))
{
Check
Error
(
connection
,
error
);
Make
Error
(
connection
,
error
);
return
nullptr
;
}
struct
mpd_song
*
song
=
mpd_recv_song
(
connection
);
if
(
!
mpd_response_finish
(
connection
)
&&
!
CheckError
(
connection
,
error
))
{
if
(
!
mpd_response_finish
(
connection
))
{
if
(
song
!=
nullptr
)
mpd_song_free
(
song
);
MakeError
(
connection
,
error
);
return
nullptr
;
}
...
...
@@ -646,8 +653,10 @@ Visit(struct mpd_connection *connection, const char *uri,
VisitDirectory
visit_directory
,
VisitSong
visit_song
,
VisitPlaylist
visit_playlist
,
Error
&
error
)
{
if
(
!
mpd_send_list_meta
(
connection
,
uri
))
return
CheckError
(
connection
,
error
);
if
(
!
mpd_send_list_meta
(
connection
,
uri
))
{
MakeError
(
connection
,
error
);
return
false
;
}
std
::
list
<
ProxyEntity
>
entities
(
ReceiveEntities
(
connection
));
if
(
!
CheckError
(
connection
,
error
))
...
...
@@ -698,8 +707,10 @@ SearchSongs(struct mpd_connection *connection,
if
(
!
mpd_search_db_songs
(
connection
,
exact
)
||
!
SendConstraints
(
connection
,
selection
)
||
!
mpd_search_commit
(
connection
))
return
CheckError
(
connection
,
error
);
!
mpd_search_commit
(
connection
))
{
MakeError
(
connection
,
error
);
return
false
;
}
bool
result
=
true
;
struct
mpd_song
*
song
;
...
...
@@ -710,8 +721,12 @@ SearchSongs(struct mpd_connection *connection,
visit_song
(
song2
,
error
);
}
mpd_response_finish
(
connection
);
return
result
&&
CheckError
(
connection
,
error
);
if
(
!
mpd_response_finish
(
connection
)
&&
result
)
{
MakeError
(
connection
,
error
);
result
=
false
;
}
return
result
;
}
/**
...
...
@@ -774,16 +789,18 @@ ProxyDatabase::VisitUniqueTags(const DatabaseSelection &selection,
return
false
;
}
if
(
!
mpd_search_db_tags
(
connection
,
tag_type2
)
)
return
CheckError
(
connection
,
error
);
if
(
!
SendConstraints
(
connection
,
selection
))
return
CheckError
(
connection
,
error
);
if
(
!
mpd_search_db_tags
(
connection
,
tag_type2
)
||
!
SendConstraints
(
connection
,
selection
))
{
MakeError
(
connection
,
error
);
return
false
;
}
// TODO: use group_mask
if
(
!
mpd_search_commit
(
connection
))
return
CheckError
(
connection
,
error
);
if
(
!
mpd_search_commit
(
connection
))
{
MakeError
(
connection
,
error
);
return
false
;
}
bool
result
=
true
;
...
...
@@ -808,8 +825,12 @@ ProxyDatabase::VisitUniqueTags(const DatabaseSelection &selection,
result
=
visit_tag
(
tag
.
Commit
(),
error
);
}
mpd_response_finish
(
connection
);
return
result
&&
CheckError
(
connection
,
error
);
if
(
!
mpd_response_finish
(
connection
)
&&
result
)
{
MakeError
(
connection
,
error
);
result
=
false
;
}
return
result
;
}
bool
...
...
@@ -825,8 +846,10 @@ ProxyDatabase::GetStats(const DatabaseSelection &selection,
struct
mpd_stats
*
stats2
=
mpd_run_stats
(
connection
);
if
(
stats2
==
nullptr
)
return
CheckError
(
connection
,
error
);
if
(
stats2
==
nullptr
)
{
MakeError
(
connection
,
error
);
return
false
;
}
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