diff options
author | Max Kellermann <max@duempel.org> | 2014-07-30 20:58:14 +0200 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2014-07-30 22:17:01 +0200 |
commit | 9fb351a139a56fc7b1ece549894f8fc31fa887cd (patch) | |
tree | 7c9ce42a1262af587f1b9fede2b24ff39cef93fc /src/queue | |
parent | 0d0ccacdf3e154b1cc27a0840fce80ac13f9641c (diff) |
*Save, *State: use the OutputStream API instead of FILE*
Diffstat (limited to 'src/queue')
-rw-r--r-- | src/queue/PlaylistState.cxx | 47 | ||||
-rw-r--r-- | src/queue/PlaylistState.hxx | 5 | ||||
-rw-r--r-- | src/queue/QueueSave.cxx | 22 | ||||
-rw-r--r-- | src/queue/QueueSave.hxx | 5 |
4 files changed, 39 insertions, 40 deletions
diff --git a/src/queue/PlaylistState.cxx b/src/queue/PlaylistState.cxx index f5c798e3e..56adb2a9b 100644 --- a/src/queue/PlaylistState.cxx +++ b/src/queue/PlaylistState.cxx @@ -28,6 +28,7 @@ #include "Playlist.hxx" #include "queue/QueueSave.hxx" #include "fs/TextFile.hxx" +#include "fs/output/BufferedOutputStream.hxx" #include "PlayerControl.hxx" #include "config/ConfigGlobal.hxx" #include "config/ConfigOption.hxx" @@ -59,47 +60,45 @@ #define PLAYLIST_BUFFER_SIZE 2*MPD_PATH_MAX void -playlist_state_save(FILE *fp, const struct playlist &playlist, +playlist_state_save(BufferedOutputStream &os, const struct playlist &playlist, PlayerControl &pc) { const auto player_status = pc.GetStatus(); - fputs(PLAYLIST_STATE_FILE_STATE, fp); + os.Write(PLAYLIST_STATE_FILE_STATE); if (playlist.playing) { switch (player_status.state) { case PlayerState::PAUSE: - fputs(PLAYLIST_STATE_FILE_STATE_PAUSE "\n", fp); + os.Write(PLAYLIST_STATE_FILE_STATE_PAUSE "\n"); break; default: - fputs(PLAYLIST_STATE_FILE_STATE_PLAY "\n", fp); + os.Write(PLAYLIST_STATE_FILE_STATE_PLAY "\n"); } - fprintf(fp, PLAYLIST_STATE_FILE_CURRENT "%i\n", - playlist.queue.OrderToPosition(playlist.current)); - fprintf(fp, PLAYLIST_STATE_FILE_TIME "%i\n", - (int)player_status.elapsed_time); + os.Format(PLAYLIST_STATE_FILE_CURRENT "%i\n", + playlist.queue.OrderToPosition(playlist.current)); + os.Format(PLAYLIST_STATE_FILE_TIME "%i\n", + (int)player_status.elapsed_time); } else { - fputs(PLAYLIST_STATE_FILE_STATE_STOP "\n", fp); + os.Write(PLAYLIST_STATE_FILE_STATE_STOP "\n"); if (playlist.current >= 0) - fprintf(fp, PLAYLIST_STATE_FILE_CURRENT "%i\n", + os.Format(PLAYLIST_STATE_FILE_CURRENT "%i\n", playlist.queue.OrderToPosition(playlist.current)); } - fprintf(fp, PLAYLIST_STATE_FILE_RANDOM "%i\n", playlist.queue.random); - fprintf(fp, PLAYLIST_STATE_FILE_REPEAT "%i\n", playlist.queue.repeat); - fprintf(fp, PLAYLIST_STATE_FILE_SINGLE "%i\n", playlist.queue.single); - fprintf(fp, PLAYLIST_STATE_FILE_CONSUME "%i\n", - playlist.queue.consume); - fprintf(fp, PLAYLIST_STATE_FILE_CROSSFADE "%i\n", - (int)pc.GetCrossFade()); - fprintf(fp, PLAYLIST_STATE_FILE_MIXRAMPDB "%f\n", - pc.GetMixRampDb()); - fprintf(fp, PLAYLIST_STATE_FILE_MIXRAMPDELAY "%f\n", - pc.GetMixRampDelay()); - fputs(PLAYLIST_STATE_FILE_PLAYLIST_BEGIN "\n", fp); - queue_save(fp, playlist.queue); - fputs(PLAYLIST_STATE_FILE_PLAYLIST_END "\n", fp); + os.Format(PLAYLIST_STATE_FILE_RANDOM "%i\n", playlist.queue.random); + os.Format(PLAYLIST_STATE_FILE_REPEAT "%i\n", playlist.queue.repeat); + os.Format(PLAYLIST_STATE_FILE_SINGLE "%i\n", playlist.queue.single); + os.Format(PLAYLIST_STATE_FILE_CONSUME "%i\n", playlist.queue.consume); + os.Format(PLAYLIST_STATE_FILE_CROSSFADE "%i\n", + (int)pc.GetCrossFade()); + os.Format(PLAYLIST_STATE_FILE_MIXRAMPDB "%f\n", pc.GetMixRampDb()); + os.Format(PLAYLIST_STATE_FILE_MIXRAMPDELAY "%f\n", + pc.GetMixRampDelay()); + os.Write(PLAYLIST_STATE_FILE_PLAYLIST_BEGIN "\n"); + queue_save(os, playlist.queue); + os.Write(PLAYLIST_STATE_FILE_PLAYLIST_END "\n"); } static void diff --git a/src/queue/PlaylistState.hxx b/src/queue/PlaylistState.hxx index 8d3f88ae2..3211b1178 100644 --- a/src/queue/PlaylistState.hxx +++ b/src/queue/PlaylistState.hxx @@ -25,15 +25,14 @@ #ifndef MPD_PLAYLIST_STATE_HXX #define MPD_PLAYLIST_STATE_HXX -#include <stdio.h> - struct playlist; struct PlayerControl; class TextFile; +class BufferedOutputStream; class SongLoader; void -playlist_state_save(FILE *fp, const playlist &playlist, +playlist_state_save(BufferedOutputStream &os, const playlist &playlist, PlayerControl &pc); bool diff --git a/src/queue/QueueSave.cxx b/src/queue/QueueSave.cxx index 5f47a0fac..eca906421 100644 --- a/src/queue/QueueSave.cxx +++ b/src/queue/QueueSave.cxx @@ -26,6 +26,7 @@ #include "SongLoader.hxx" #include "playlist/PlaylistSong.hxx" #include "fs/TextFile.hxx" +#include "fs/output/BufferedOutputStream.hxx" #include "util/StringUtil.hxx" #include "util/Error.hxx" #include "fs/Traits.hxx" @@ -36,40 +37,41 @@ #define PRIO_LABEL "Prio: " static void -queue_save_database_song(FILE *fp, int idx, const DetachedSong &song) +queue_save_database_song(BufferedOutputStream &os, + int idx, const DetachedSong &song) { - fprintf(fp, "%i:%s\n", idx, song.GetURI()); + os.Format("%i:%s\n", idx, song.GetURI()); } static void -queue_save_full_song(FILE *fp, const DetachedSong &song) +queue_save_full_song(BufferedOutputStream &os, const DetachedSong &song) { - song_save(fp, song); + song_save(os, song); } static void -queue_save_song(FILE *fp, int idx, const DetachedSong &song) +queue_save_song(BufferedOutputStream &os, int idx, const DetachedSong &song) { if (song.IsInDatabase() && song.GetStartMS() == 0 && song.GetEndMS() == 0) /* use the brief format (just the URI) for "full" database songs */ - queue_save_database_song(fp, idx, song); + queue_save_database_song(os, idx, song); else /* use the long format (URI, range, tags) for the rest, so all metadata survives a MPD restart */ - queue_save_full_song(fp, song); + queue_save_full_song(os, song); } void -queue_save(FILE *fp, const Queue &queue) +queue_save(BufferedOutputStream &os, const Queue &queue) { for (unsigned i = 0; i < queue.GetLength(); i++) { uint8_t prio = queue.GetPriorityAtPosition(i); if (prio != 0) - fprintf(fp, PRIO_LABEL "%u\n", prio); + os.Format(PRIO_LABEL "%u\n", prio); - queue_save_song(fp, i, queue.Get(i)); + queue_save_song(os, i, queue.Get(i)); } } diff --git a/src/queue/QueueSave.hxx b/src/queue/QueueSave.hxx index 470823a24..3fb4dc1a6 100644 --- a/src/queue/QueueSave.hxx +++ b/src/queue/QueueSave.hxx @@ -25,14 +25,13 @@ #ifndef MPD_QUEUE_SAVE_HXX #define MPD_QUEUE_SAVE_HXX -#include <stdio.h> - struct Queue; +class BufferedOutputStream; class TextFile; class SongLoader; void -queue_save(FILE *fp, const Queue &queue); +queue_save(BufferedOutputStream &os, const Queue &queue); /** * Loads one song from the state file and appends it to the queue. |