1
0
Fork 0
mirror of https://github.com/polybar/polybar.git synced 2024-11-03 04:33:30 -05:00

fix(mpd): Avoid nullptrs

This commit is contained in:
Michael Carlberg 2016-06-01 16:29:17 +02:00
parent 78effb28b8
commit 89a476e94c
2 changed files with 19 additions and 10 deletions

View file

@ -122,15 +122,15 @@ namespace mpd
bool mpd_idle = false;
int mpd_fd;
void check_connection() throw(ClientError);
void check_connection();
void check_prerequisites();
void check_prerequisites_commands_list();
void check_errors() throw(ClientError, ServerError);
void check_errors();
public:
static std::shared_ptr<Connection> &get();
void connect() throw (ClientError);
void connect();
void disconnect();
bool connected();
bool retry_connection(int interval = 1);

View file

@ -21,7 +21,7 @@ namespace mpd
// Base
void Connection::connect() throw (ClientError)
void Connection::connect()
{
assert(!this->connection);
@ -40,7 +40,7 @@ namespace mpd
this->check_errors();
} catch(ClientError &e) {
this->disconnect();
throw e;
throw &e;
}
}
@ -97,7 +97,7 @@ namespace mpd
return flags;
}
void Connection::check_connection() throw(ClientError)
void Connection::check_connection()
{
if (!this->connection)
throw ClientError("Not connected to MPD server", MPD_ERROR_STATE, false);
@ -116,7 +116,7 @@ namespace mpd
this->check_prerequisites();
}
void Connection::check_errors() throw(ClientError, ServerError)
void Connection::check_errors()
{
auto connection = this->connection.get();
mpd_error code = mpd_connection_get_error(connection);
@ -367,19 +367,28 @@ namespace mpd
std::string Song::get_artist()
{
assert(this->song);
return mpd_song_get_tag(this->song.get(), MPD_TAG_ARTIST, 0);
auto tag = mpd_song_get_tag(this->song.get(), MPD_TAG_ARTIST, 0);
if (tag == nullptr)
return "";
return std::string(tag);
}
std::string Song::get_album()
{
assert(this->song);
return mpd_song_get_tag(this->song.get(), MPD_TAG_ALBUM, 0);
auto tag = mpd_song_get_tag(this->song.get(), MPD_TAG_ALBUM, 0);
if (tag == nullptr)
return "";
return std::string(tag);
}
std::string Song::get_title()
{
assert(this->song);
return mpd_song_get_tag(this->song.get(), MPD_TAG_TITLE, 0);
auto tag = mpd_song_get_tag(this->song.get(), MPD_TAG_TITLE, 0);
if (tag == nullptr)
return "";
return std::string(tag);
}
unsigned Song::get_duration()