From 590cbbe469a7f276efa22d925c6d5bcfb7a9a06f Mon Sep 17 00:00:00 2001 From: Bob van Loosen Date: Thu, 20 Dec 2012 19:28:27 +0100 Subject: [PATCH] refactor --- src/mpdclient.cpp | 14 ++++++++++++-- src/mpdclient.h | 1 + 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/mpdclient.cpp b/src/mpdclient.cpp index bbb47ae..d4bbd99 100644 --- a/src/mpdclient.cpp +++ b/src/mpdclient.cpp @@ -27,14 +27,14 @@ void CMpdClient::Process() { if (!OpenSocket()) { - m_currentsong.clear(); + ClearCurrentSong(); continue; } } if (!GetCurrentSong()) { - m_currentsong.clear(); + ClearCurrentSong(); m_socket.Close(); } @@ -120,6 +120,16 @@ bool CMpdClient::GetCurrentSong() return false; } +void CMpdClient::ClearCurrentSong() +{ + CLock lock(m_condition); + if (!m_currentsong.empty()) + { + m_currentsong.clear(); + m_songchanged = true; + } +} + bool CMpdClient::CurrentSong(std::string& song) { CLock lock(m_condition); diff --git a/src/mpdclient.h b/src/mpdclient.h index 9481fb1..46062ee 100644 --- a/src/mpdclient.h +++ b/src/mpdclient.h @@ -20,6 +20,7 @@ class CMpdClient : public CThread private: bool OpenSocket(); bool GetCurrentSong(); + void ClearCurrentSong(); int m_port; std::string m_address;