Commit 77de2331 authored by Max Kellermann's avatar Max Kellermann

Playlist{Any,Registry,Mapper}: move functions to PlaylistStream.cxx

parent 02b67eda
......@@ -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 \
......
......@@ -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)
......
......@@ -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.
*/
......
......@@ -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;
}
......@@ -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
/*
* 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);
}
/*
* 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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment