From a8b75dc4df3bf3ba9a1554249cf6d07527184864 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Tue, 29 Jan 2013 18:56:35 +0100 Subject: playlist/{asx,rss,soundcloud,xspf}: merge code to MemoryPlaylistProvider --- src/playlist/PlsPlaylistPlugin.cxx | 53 +++++--------------------------------- 1 file changed, 7 insertions(+), 46 deletions(-) (limited to 'src/playlist/PlsPlaylistPlugin.cxx') diff --git a/src/playlist/PlsPlaylistPlugin.cxx b/src/playlist/PlsPlaylistPlugin.cxx index 8cb8b4f1d..cecabc88e 100644 --- a/src/playlist/PlsPlaylistPlugin.cxx +++ b/src/playlist/PlsPlaylistPlugin.cxx @@ -19,7 +19,7 @@ #include "config.h" #include "PlsPlaylistPlugin.hxx" -#include "PlaylistPlugin.hxx" +#include "MemoryPlaylistProvider.hxx" #include "input_stream.h" #include "uri.h" #include "song.h" @@ -28,8 +28,6 @@ #include struct PlsPlaylist { - struct playlist_provider base; - GSList *songs; }; @@ -112,7 +110,6 @@ pls_open_stream(struct input_stream *is) char buffer[1024]; bool success; GKeyFile *keyfile; - PlsPlaylist *playlist; GString *kf_data = g_string_new(""); do { @@ -153,49 +150,13 @@ pls_open_stream(struct input_stream *is) return NULL; } - playlist = g_new(PlsPlaylist, 1); - playlist_provider_init(&playlist->base, &pls_playlist_plugin); - playlist->songs = NULL; - - pls_parser(keyfile, playlist); + PlsPlaylist playlist; + playlist.songs = nullptr; + pls_parser(keyfile, &playlist); g_key_file_free(keyfile); - return &playlist->base; -} - - -static void -song_free_callback(gpointer data, G_GNUC_UNUSED gpointer user_data) -{ - struct song *song = (struct song *)data; - song_free(song); -} - -static void -pls_close(struct playlist_provider *_playlist) -{ - PlsPlaylist *playlist = (PlsPlaylist *)_playlist; - - g_slist_foreach(playlist->songs, song_free_callback, NULL); - g_slist_free(playlist->songs); - - g_free(playlist); - -} - -static struct song * -pls_read(struct playlist_provider *_playlist) -{ - PlsPlaylist *playlist = (PlsPlaylist *)_playlist; - - if (playlist->songs == NULL) - return NULL; - - struct song *song = (struct song *)playlist->songs->data; - playlist->songs = g_slist_remove(playlist->songs, song); - - return song; + return new MemoryPlaylistProvider(g_slist_reverse(playlist.songs)); } static const char *const pls_suffixes[] = { @@ -215,8 +176,8 @@ const struct playlist_plugin pls_playlist_plugin = { nullptr, nullptr, pls_open_stream, - pls_close, - pls_read, + nullptr, + nullptr, nullptr, pls_suffixes, -- cgit v1.2.3