aboutsummaryrefslogtreecommitdiffstats
path: root/src/PlayerControl.cxx
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2013-09-27 09:20:53 +0200
committerMax Kellermann <max@duempel.org>2013-09-27 09:30:19 +0200
commita10f3a8aeca0993a1d0c69ebfde9dbacbd16888c (patch)
tree9511884a82f673b91299920f45325c564119dd85 /src/PlayerControl.cxx
parentef663810a2128eb26e701f4962f6683e2c28c052 (diff)
downloadmpd-a10f3a8aeca0993a1d0c69ebfde9dbacbd16888c.tar.gz
mpd-a10f3a8aeca0993a1d0c69ebfde9dbacbd16888c.tar.xz
mpd-a10f3a8aeca0993a1d0c69ebfde9dbacbd16888c.zip
PlayerControl: convert functions to methods
Diffstat (limited to 'src/PlayerControl.cxx')
-rw-r--r--src/PlayerControl.cxx81
1 files changed, 18 insertions, 63 deletions
diff --git a/src/PlayerControl.cxx b/src/PlayerControl.cxx
index 3fd09a8d1..9d5f7eaca 100644
--- a/src/PlayerControl.cxx
+++ b/src/PlayerControl.cxx
@@ -22,15 +22,10 @@
#include "Idle.hxx"
#include "Song.hxx"
#include "DecoderControl.hxx"
-#include "Main.hxx"
#include <cmath>
#include <assert.h>
-#include <stdio.h>
-
-static void
-pc_enqueue_song_locked(struct player_control *pc, Song *song);
player_control::player_control(unsigned _buffer_chunks,
unsigned _buffered_before_play)
@@ -61,31 +56,6 @@ player_control::~player_control()
next_song->Free();
}
-static void
-player_command_wait_locked(struct player_control *pc)
-{
- while (pc->command != PLAYER_COMMAND_NONE)
- pc->ClientWait();
-}
-
-static void
-player_command_locked(struct player_control *pc, enum player_command cmd)
-{
- assert(pc->command == PLAYER_COMMAND_NONE);
-
- pc->command = cmd;
- pc->Signal();
- player_command_wait_locked(pc);
-}
-
-static void
-player_command(struct player_control *pc, enum player_command cmd)
-{
- pc->Lock();
- player_command_locked(pc, cmd);
- pc->Unlock();
-}
-
void
player_control::Play(Song *song)
{
@@ -94,11 +64,11 @@ player_control::Play(Song *song)
Lock();
if (state != PLAYER_STATE_STOP)
- player_command_locked(this, PLAYER_COMMAND_STOP);
+ SynchronousCommand(PLAYER_COMMAND_STOP);
assert(next_song == nullptr);
- pc_enqueue_song_locked(this, song);
+ EnqueueSongLocked(song);
assert(next_song == nullptr);
@@ -108,14 +78,14 @@ player_control::Play(Song *song)
void
player_control::Cancel()
{
- player_command(this, PLAYER_COMMAND_CANCEL);
+ LockSynchronousCommand(PLAYER_COMMAND_CANCEL);
assert(next_song == NULL);
}
void
player_control::Stop()
{
- player_command(this, PLAYER_COMMAND_CLOSE_AUDIO);
+ LockSynchronousCommand(PLAYER_COMMAND_CLOSE_AUDIO);
assert(next_song == nullptr);
idle_add(IDLE_PLAYER);
@@ -124,7 +94,7 @@ player_control::Stop()
void
player_control::UpdateAudio()
{
- player_command(this, PLAYER_COMMAND_UPDATE_AUDIO);
+ LockSynchronousCommand(PLAYER_COMMAND_UPDATE_AUDIO);
}
void
@@ -132,7 +102,7 @@ player_control::Kill()
{
assert(thread != NULL);
- player_command(this, PLAYER_COMMAND_EXIT);
+ LockSynchronousCommand(PLAYER_COMMAND_EXIT);
g_thread_join(thread);
thread = NULL;
@@ -140,25 +110,20 @@ player_control::Kill()
}
void
-player_control::Pause()
+player_control::PauseLocked()
{
- Lock();
-
if (state != PLAYER_STATE_STOP) {
- player_command_locked(this, PLAYER_COMMAND_PAUSE);
+ SynchronousCommand(PLAYER_COMMAND_PAUSE);
idle_add(IDLE_PLAYER);
}
-
- Unlock();
}
-static void
-pc_pause_locked(struct player_control *pc)
+void
+player_control::Pause()
{
- if (pc->state != PLAYER_STATE_STOP) {
- player_command_locked(pc, PLAYER_COMMAND_PAUSE);
- idle_add(IDLE_PLAYER);
- }
+ Lock();
+ PauseLocked();
+ Unlock();
}
void
@@ -172,12 +137,12 @@ player_control::SetPause(bool pause_flag)
case PLAYER_STATE_PLAY:
if (pause_flag)
- pc_pause_locked(this);
+ PauseLocked();
break;
case PLAYER_STATE_PAUSE:
if (!pause_flag)
- pc_pause_locked(this);
+ PauseLocked();
break;
}
@@ -198,7 +163,7 @@ player_control::GetStatus()
player_status status;
Lock();
- player_command_locked(this, PLAYER_COMMAND_REFRESH);
+ SynchronousCommand(PLAYER_COMMAND_REFRESH);
status.state = state;
@@ -248,23 +213,13 @@ player_control::GetErrorMessage() const
return message;
}
-static void
-pc_enqueue_song_locked(struct player_control *pc, Song *song)
-{
- assert(song != NULL);
- assert(pc->next_song == NULL);
-
- pc->next_song = song;
- player_command_locked(pc, PLAYER_COMMAND_QUEUE);
-}
-
void
player_control::EnqueueSong(Song *song)
{
assert(song != NULL);
Lock();
- pc_enqueue_song_locked(this, song);
+ EnqueueSongLocked(song);
Unlock();
}
@@ -280,7 +235,7 @@ player_control::Seek(Song *song, float seek_time)
next_song = song;
seek_where = seek_time;
- player_command_locked(this, PLAYER_COMMAND_SEEK);
+ SynchronousCommand(PLAYER_COMMAND_SEEK);
Unlock();
assert(next_song == nullptr);