diff options
Diffstat (limited to '')
-rw-r--r-- | Makefile.am | 1 | ||||
-rw-r--r-- | src/playlist/PlaylistAny.cxx | 35 | ||||
-rw-r--r-- | src/playlist/PlaylistMapper.cxx | 11 | ||||
-rw-r--r-- | src/playlist/PlaylistRegistry.cxx | 32 | ||||
-rw-r--r-- | src/playlist/PlaylistRegistry.hxx | 14 | ||||
-rw-r--r-- | src/playlist/PlaylistStream.cxx | 93 | ||||
-rw-r--r-- | src/playlist/PlaylistStream.hxx | 45 |
7 files changed, 145 insertions, 86 deletions
diff --git a/Makefile.am b/Makefile.am index 19e4b255d..cb7dafa1b 100644 --- a/Makefile.am +++ b/Makefile.am @@ -153,6 +153,7 @@ src_mpd_SOURCES = \ src/PlaylistTag.cxx \ src/PlaylistPrint.cxx src/PlaylistPrint.hxx \ src/PlaylistSave.cxx src/PlaylistSave.hxx \ + src/playlist/PlaylistStream.cxx src/playlist/PlaylistStream.hxx \ src/playlist/PlaylistMapper.cxx src/playlist/PlaylistMapper.hxx \ src/playlist/PlaylistAny.cxx src/playlist/PlaylistAny.hxx \ src/playlist/PlaylistSong.cxx src/playlist/PlaylistSong.hxx \ diff --git a/src/playlist/PlaylistAny.cxx b/src/playlist/PlaylistAny.cxx index 671802e7d..457de18b3 100644 --- a/src/playlist/PlaylistAny.cxx +++ b/src/playlist/PlaylistAny.cxx @@ -19,42 +19,9 @@ #include "config.h" #include "PlaylistAny.hxx" +#include "PlaylistStream.hxx" #include "PlaylistMapper.hxx" -#include "PlaylistRegistry.hxx" -#include "CloseSongEnumerator.hxx" #include "util/UriUtil.hxx" -#include "util/Error.hxx" -#include "input/InputStream.hxx" -#include "Log.hxx" - -#include <assert.h> - -static SongEnumerator * -playlist_open_remote(const char *uri, Mutex &mutex, Cond &cond) -{ - assert(uri_has_scheme(uri)); - - SongEnumerator *playlist = playlist_list_open_uri(uri, mutex, cond); - if (playlist != nullptr) - return playlist; - - Error error; - InputStream *is = InputStream::OpenReady(uri, mutex, cond, error); - if (is == nullptr) { - if (error.IsDefined()) - FormatError(error, "Failed to open %s", uri); - - return nullptr; - } - - playlist = playlist_list_open_stream(*is, uri); - if (playlist == nullptr) { - is->Close(); - return nullptr; - } - - return new CloseSongEnumerator(playlist, is); -} SongEnumerator * playlist_open_any(const char *uri, Mutex &mutex, Cond &cond) diff --git a/src/playlist/PlaylistMapper.cxx b/src/playlist/PlaylistMapper.cxx index 1211e892c..141e0563f 100644 --- a/src/playlist/PlaylistMapper.cxx +++ b/src/playlist/PlaylistMapper.cxx @@ -20,6 +20,7 @@ #include "config.h" #include "PlaylistMapper.hxx" #include "PlaylistFile.hxx" +#include "PlaylistStream.hxx" #include "PlaylistRegistry.hxx" #include "Mapper.hxx" #include "fs/AllocatedPath.hxx" @@ -27,16 +28,6 @@ #include <assert.h> -static SongEnumerator * -playlist_open_path(const char *path_fs, Mutex &mutex, Cond &cond) -{ - auto playlist = playlist_list_open_uri(path_fs, mutex, cond); - if (playlist == nullptr) - playlist = playlist_list_open_path(path_fs, mutex, cond); - - return playlist; -} - /** * Load a playlist from the configured playlist directory. */ diff --git a/src/playlist/PlaylistRegistry.cxx b/src/playlist/PlaylistRegistry.cxx index 6b594e3c5..9439039ef 100644 --- a/src/playlist/PlaylistRegistry.cxx +++ b/src/playlist/PlaylistRegistry.cxx @@ -20,7 +20,6 @@ #include "config.h" #include "PlaylistRegistry.hxx" #include "PlaylistPlugin.hxx" -#include "CloseSongEnumerator.hxx" #include "plugins/ExtM3uPlaylistPlugin.hxx" #include "plugins/M3uPlaylistPlugin.hxx" #include "plugins/XspfPlaylistPlugin.hxx" @@ -221,7 +220,7 @@ playlist_list_open_stream_mime(InputStream &is, const char *full_mime) return playlist_list_open_stream_mime2(is, mime.c_str()); } -static SongEnumerator * +SongEnumerator * playlist_list_open_stream_suffix(InputStream &is, const char *suffix) { assert(suffix != nullptr); @@ -278,32 +277,3 @@ playlist_suffix_supported(const char *suffix) return false; } - -SongEnumerator * -playlist_list_open_path(const char *path_fs, Mutex &mutex, Cond &cond) -{ - const char *suffix; - - assert(path_fs != nullptr); - - suffix = uri_get_suffix(path_fs); - if (suffix == nullptr || !playlist_suffix_supported(suffix)) - return nullptr; - - Error error; - InputStream *is = InputStream::OpenReady(path_fs, mutex, cond, error); - if (is == nullptr) { - if (error.IsDefined()) - LogError(error); - - return nullptr; - } - - auto playlist = playlist_list_open_stream_suffix(*is, suffix); - if (playlist != nullptr) - playlist = new CloseSongEnumerator(playlist, is); - else - is->Close(); - - return playlist; -} diff --git a/src/playlist/PlaylistRegistry.hxx b/src/playlist/PlaylistRegistry.hxx index d8a24f4af..f1833b925 100644 --- a/src/playlist/PlaylistRegistry.hxx +++ b/src/playlist/PlaylistRegistry.hxx @@ -51,6 +51,9 @@ playlist_list_global_finish(void); SongEnumerator * playlist_list_open_uri(const char *uri, Mutex &mutex, Cond &cond); +SongEnumerator * +playlist_list_open_stream_suffix(InputStream &is, const char *suffix); + /** * Opens a playlist from an input stream. * @@ -68,15 +71,4 @@ playlist_list_open_stream(InputStream &is, const char *uri); bool playlist_suffix_supported(const char *suffix); -/** - * Opens a playlist from a local file. - * - * @param path_fs the path of the playlist file - * @param is_r on success, an input_stream object is returned here, - * which must be closed after the playlist_provider object is freed - * @return a playlist, or nullptr on error - */ -SongEnumerator * -playlist_list_open_path(const char *path_fs, Mutex &mutex, Cond &cond); - #endif diff --git a/src/playlist/PlaylistStream.cxx b/src/playlist/PlaylistStream.cxx new file mode 100644 index 000000000..6222a768d --- /dev/null +++ b/src/playlist/PlaylistStream.cxx @@ -0,0 +1,93 @@ +/* + * Copyright (C) 2003-2014 The Music Player Daemon Project + * http://www.musicpd.org + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include "config.h" +#include "PlaylistStream.hxx" +#include "PlaylistRegistry.hxx" +#include "CloseSongEnumerator.hxx" +#include "util/UriUtil.hxx" +#include "util/Error.hxx" +#include "input/InputStream.hxx" +#include "Log.hxx" + +#include <assert.h> + +static SongEnumerator * +playlist_open_path_suffix(const char *path_fs, Mutex &mutex, Cond &cond) +{ + assert(path_fs != nullptr); + + const char *suffix = uri_get_suffix(path_fs); + if (suffix == nullptr || !playlist_suffix_supported(suffix)) + return nullptr; + + Error error; + InputStream *is = InputStream::OpenReady(path_fs, mutex, cond, error); + if (is == nullptr) { + if (error.IsDefined()) + LogError(error); + + return nullptr; + } + + auto playlist = playlist_list_open_stream_suffix(*is, suffix); + if (playlist != nullptr) + playlist = new CloseSongEnumerator(playlist, is); + else + is->Close(); + + return playlist; +} + +SongEnumerator * +playlist_open_path(const char *path_fs, Mutex &mutex, Cond &cond) +{ + auto playlist = playlist_list_open_uri(path_fs, mutex, cond); + if (playlist == nullptr) + playlist = playlist_open_path_suffix(path_fs, mutex, cond); + + return playlist; +} + +SongEnumerator * +playlist_open_remote(const char *uri, Mutex &mutex, Cond &cond) +{ + assert(uri_has_scheme(uri)); + + SongEnumerator *playlist = playlist_list_open_uri(uri, mutex, cond); + if (playlist != nullptr) + return playlist; + + Error error; + InputStream *is = InputStream::OpenReady(uri, mutex, cond, error); + if (is == nullptr) { + if (error.IsDefined()) + FormatError(error, "Failed to open %s", uri); + + return nullptr; + } + + playlist = playlist_list_open_stream(*is, uri); + if (playlist == nullptr) { + is->Close(); + return nullptr; + } + + return new CloseSongEnumerator(playlist, is); +} diff --git a/src/playlist/PlaylistStream.hxx b/src/playlist/PlaylistStream.hxx new file mode 100644 index 000000000..02f5485ef --- /dev/null +++ b/src/playlist/PlaylistStream.hxx @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2003-2014 The Music Player Daemon Project + * http://www.musicpd.org + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#ifndef MPD_PLAYLIST_STREAM_HXX +#define MPD_PLAYLIST_STREAM_HXX + +#include "Compiler.h" + +class Mutex; +class Cond; +class SongEnumerator; + +/** + * Opens a playlist from a local file. + * + * @param path_fs the path of the playlist file + * @param is_r on success, an input_stream object is returned here, + * which must be closed after the playlist_provider object is freed + * @return a playlist, or nullptr on error + */ +gcc_nonnull_all +SongEnumerator * +playlist_open_path(const char *path_fs, Mutex &mutex, Cond &cond); + +gcc_nonnull_all +SongEnumerator * +playlist_open_remote(const char *uri, Mutex &mutex, Cond &cond); + +#endif |