aboutsummaryrefslogtreecommitdiffstats
path: root/src/input
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2014-05-11 16:59:19 +0200
committerMax Kellermann <max@duempel.org>2014-05-11 17:12:50 +0200
commit82337dec44347017ca04fe975e85e6d9e4edb635 (patch)
tree308036d4a7abbd2bb04ed472dc1fbacdc2587871 /src/input
parentf1d07002521a4a98acf130127cf42aef20a5e258 (diff)
downloadmpd-82337dec44347017ca04fe975e85e6d9e4edb635.tar.gz
mpd-82337dec44347017ca04fe975e85e6d9e4edb635.tar.xz
mpd-82337dec44347017ca04fe975e85e6d9e4edb635.zip
InputStream: add virtual destructor
Replaces the method Close().
Diffstat (limited to 'src/input')
-rw-r--r--src/input/InputPlugin.hxx1
-rw-r--r--src/input/InputStream.cxx13
-rw-r--r--src/input/InputStream.hxx14
-rw-r--r--src/input/ThreadInputStream.cxx31
-rw-r--r--src/input/ThreadInputStream.hxx2
-rw-r--r--src/input/plugins/AlsaInputPlugin.cxx8
-rw-r--r--src/input/plugins/ArchiveInputPlugin.cxx1
-rw-r--r--src/input/plugins/CdioParanoiaInputPlugin.cxx9
-rw-r--r--src/input/plugins/CurlInputPlugin.cxx9
-rw-r--r--src/input/plugins/DespotifyInputPlugin.cxx20
-rw-r--r--src/input/plugins/FfmpegInputPlugin.cxx9
-rw-r--r--src/input/plugins/FileInputPlugin.cxx9
-rw-r--r--src/input/plugins/MmsInputPlugin.cxx1
-rw-r--r--src/input/plugins/NfsInputPlugin.cxx8
-rw-r--r--src/input/plugins/RewindInputPlugin.cxx11
-rw-r--r--src/input/plugins/SmbclientInputPlugin.cxx8
16 files changed, 29 insertions, 125 deletions
diff --git a/src/input/InputPlugin.hxx b/src/input/InputPlugin.hxx
index 412ca4cf9..449604434 100644
--- a/src/input/InputPlugin.hxx
+++ b/src/input/InputPlugin.hxx
@@ -82,7 +82,6 @@ struct InputPlugin {
InputStream *(*open)(const char *uri,
Mutex &mutex, Cond &cond,
Error &error);
- void (*close)(InputStream *is);
/**
* Check for errors that may have occurred in the I/O thread.
diff --git a/src/input/InputStream.cxx b/src/input/InputStream.cxx
index d54eca643..2e0df6856 100644
--- a/src/input/InputStream.cxx
+++ b/src/input/InputStream.cxx
@@ -31,6 +31,10 @@
static constexpr Domain input_domain("input");
+InputStream::~InputStream()
+{
+}
+
InputStream *
InputStream::Open(const char *url,
Mutex &mutex, Cond &cond,
@@ -41,7 +45,6 @@ InputStream::Open(const char *url,
is = plugin->open(url, mutex, cond, error);
if (is != nullptr) {
- assert(is->plugin.close != nullptr);
assert(is->plugin.read != nullptr);
assert(is->plugin.eof != nullptr);
assert(!is->seekable || is->plugin.seek != nullptr);
@@ -72,7 +75,7 @@ InputStream::OpenReady(const char *uri,
mutex.unlock();
if (!success) {
- is->Close();
+ delete is;
is = nullptr;
}
@@ -202,12 +205,6 @@ InputStream::LockRead(void *ptr, size_t _size, Error &error)
return Read(ptr, _size, error);
}
-void
-InputStream::Close()
-{
- plugin.close(this);
-}
-
bool
InputStream::IsEOF()
{
diff --git a/src/input/InputStream.hxx b/src/input/InputStream.hxx
index 65840ba27..4a9d7832a 100644
--- a/src/input/InputStream.hxx
+++ b/src/input/InputStream.hxx
@@ -109,6 +109,13 @@ public:
}
/**
+ * Close the input stream and free resources.
+ *
+ * The caller must not lock the mutex.
+ */
+ virtual ~InputStream();
+
+ /**
* Opens a new input stream. You may not access it until the "ready"
* flag is set.
*
@@ -133,13 +140,6 @@ public:
Mutex &mutex, Cond &cond,
Error &error);
- /**
- * Close the input stream and free resources.
- *
- * The caller must not lock the mutex.
- */
- void Close();
-
const InputPlugin &GetPlugin() const {
return plugin;
}
diff --git a/src/input/ThreadInputStream.cxx b/src/input/ThreadInputStream.cxx
index 0f503be3f..408b757f9 100644
--- a/src/input/ThreadInputStream.cxx
+++ b/src/input/ThreadInputStream.cxx
@@ -29,6 +29,15 @@
ThreadInputStream::~ThreadInputStream()
{
+ Lock();
+ close = true;
+ wake_cond.signal();
+ Unlock();
+
+ Cancel();
+
+ thread.Join();
+
if (buffer != nullptr) {
buffer->Clear();
HugeFree(buffer->Write().data, buffer_size);
@@ -172,28 +181,6 @@ ThreadInputStream::Read(InputStream *is, void *ptr, size_t size,
return tis.Read2(ptr, size, error);
}
-inline void
-ThreadInputStream::Close2()
-{
- Lock();
- close = true;
- wake_cond.signal();
- Unlock();
-
- Cancel();
-
- thread.Join();
-
- delete this;
-}
-
-void
-ThreadInputStream::Close(InputStream *is)
-{
- ThreadInputStream &tis = *(ThreadInputStream *)is;
- tis.Close2();
-}
-
inline bool
ThreadInputStream::IsEOF2()
{
diff --git a/src/input/ThreadInputStream.hxx b/src/input/ThreadInputStream.hxx
index 63cdd5003..2354000f6 100644
--- a/src/input/ThreadInputStream.hxx
+++ b/src/input/ThreadInputStream.hxx
@@ -134,7 +134,6 @@ private:
bool Check2(Error &error);
bool Available2();
size_t Read2(void *ptr, size_t size, Error &error);
- void Close2();
bool IsEOF2();
public:
@@ -143,7 +142,6 @@ public:
static bool Available(InputStream *is);
static size_t Read(InputStream *is, void *ptr, size_t size,
Error &error);
- static void Close(InputStream *is);
static bool IsEOF(InputStream *is);
};
diff --git a/src/input/plugins/AlsaInputPlugin.cxx b/src/input/plugins/AlsaInputPlugin.cxx
index c1ff41d55..2049c5635 100644
--- a/src/input/plugins/AlsaInputPlugin.cxx
+++ b/src/input/plugins/AlsaInputPlugin.cxx
@@ -373,13 +373,6 @@ alsa_input_open(const char *uri, Mutex &mutex, Cond &cond, Error &error)
return AlsaInputStream::Create(uri, mutex, cond, error);
}
-static void
-alsa_input_close(InputStream *is)
-{
- AlsaInputStream *ais = (AlsaInputStream *)is;
- delete ais;
-}
-
static bool
alsa_input_available(InputStream *is)
{
@@ -406,7 +399,6 @@ const struct InputPlugin input_plugin_alsa = {
nullptr,
nullptr,
alsa_input_open,
- alsa_input_close,
nullptr,
nullptr,
nullptr,
diff --git a/src/input/plugins/ArchiveInputPlugin.cxx b/src/input/plugins/ArchiveInputPlugin.cxx
index f49669674..8a8be5b2f 100644
--- a/src/input/plugins/ArchiveInputPlugin.cxx
+++ b/src/input/plugins/ArchiveInputPlugin.cxx
@@ -96,5 +96,4 @@ const InputPlugin input_plugin_archive = {
nullptr,
nullptr,
nullptr,
- nullptr,
};
diff --git a/src/input/plugins/CdioParanoiaInputPlugin.cxx b/src/input/plugins/CdioParanoiaInputPlugin.cxx
index 8e1762427..c5b238320 100644
--- a/src/input/plugins/CdioParanoiaInputPlugin.cxx
+++ b/src/input/plugins/CdioParanoiaInputPlugin.cxx
@@ -105,14 +105,6 @@ input_cdio_init(const config_param &param, Error &error)
return InputPlugin::InitResult::SUCCESS;
}
-static void
-input_cdio_close(InputStream *is)
-{
- CdioParanoiaInputStream *i = (CdioParanoiaInputStream *)is;
-
- delete i;
-}
-
struct cdio_uri {
char device[64];
int track;
@@ -394,7 +386,6 @@ const InputPlugin input_plugin_cdio_paranoia = {
input_cdio_init,
nullptr,
input_cdio_open,
- input_cdio_close,
nullptr,
nullptr,
nullptr,
diff --git a/src/input/plugins/CurlInputPlugin.cxx b/src/input/plugins/CurlInputPlugin.cxx
index 63fb84190..fa93a1d7e 100644
--- a/src/input/plugins/CurlInputPlugin.cxx
+++ b/src/input/plugins/CurlInputPlugin.cxx
@@ -805,14 +805,6 @@ input_curl_read(InputStream *is, void *ptr, size_t size,
return c.Read(ptr, size, error);
}
-static void
-input_curl_close(InputStream *is)
-{
- CurlInputStream *c = (CurlInputStream *)is;
-
- delete c;
-}
-
static bool
input_curl_eof(gcc_unused InputStream *is)
{
@@ -1144,7 +1136,6 @@ const struct InputPlugin input_plugin_curl = {
input_curl_init,
input_curl_finish,
input_curl_open,
- input_curl_close,
input_curl_check,
nullptr,
input_curl_tag,
diff --git a/src/input/plugins/DespotifyInputPlugin.cxx b/src/input/plugins/DespotifyInputPlugin.cxx
index 16ef07f0d..86fbbbad3 100644
--- a/src/input/plugins/DespotifyInputPlugin.cxx
+++ b/src/input/plugins/DespotifyInputPlugin.cxx
@@ -61,9 +61,7 @@ class DespotifyInputStream final : public InputStream {
}
public:
- ~DespotifyInputStream() {
- despotify_free_track(track);
- }
+ ~DespotifyInputStream();
static InputStream *Open(const char *url, Mutex &mutex, Cond &cond,
Error &error);
@@ -146,6 +144,12 @@ static void callback(gcc_unused struct despotify_session* ds,
ctx->Callback(sig);
}
+DespotifyInputStream::~DespotifyInputStream()
+{
+ mpd_despotify_unregister_callback(callback);
+ despotify_free_track(track);
+}
+
inline InputStream *
DespotifyInputStream::Open(const char *url,
Mutex &mutex, Cond &cond,
@@ -220,15 +224,6 @@ input_despotify_read(InputStream *is, void *ptr, size_t size, Error &error)
return ctx->Read(ptr, size, error);
}
-static void
-input_despotify_close(InputStream *is)
-{
- DespotifyInputStream *ctx = (DespotifyInputStream *)is;
-
- mpd_despotify_unregister_callback(callback);
- delete ctx;
-}
-
static bool
input_despotify_eof(InputStream *is)
{
@@ -250,7 +245,6 @@ const InputPlugin input_plugin_despotify = {
nullptr,
nullptr,
input_despotify_open,
- input_despotify_close,
nullptr,
nullptr,
input_despotify_tag,
diff --git a/src/input/plugins/FfmpegInputPlugin.cxx b/src/input/plugins/FfmpegInputPlugin.cxx
index affd76718..366a99f46 100644
--- a/src/input/plugins/FfmpegInputPlugin.cxx
+++ b/src/input/plugins/FfmpegInputPlugin.cxx
@@ -125,14 +125,6 @@ input_ffmpeg_read(InputStream *is, void *ptr, size_t size,
return (size_t)ret;
}
-static void
-input_ffmpeg_close(InputStream *is)
-{
- FfmpegInputStream *i = (FfmpegInputStream *)is;
-
- delete i;
-}
-
static bool
input_ffmpeg_eof(InputStream *is)
{
@@ -163,7 +155,6 @@ const InputPlugin input_plugin_ffmpeg = {
input_ffmpeg_init,
nullptr,
input_ffmpeg_open,
- input_ffmpeg_close,
nullptr,
nullptr,
nullptr,
diff --git a/src/input/plugins/FileInputPlugin.cxx b/src/input/plugins/FileInputPlugin.cxx
index 932db2150..e96347c6e 100644
--- a/src/input/plugins/FileInputPlugin.cxx
+++ b/src/input/plugins/FileInputPlugin.cxx
@@ -123,14 +123,6 @@ input_file_read(InputStream *is, void *ptr, size_t size,
return (size_t)nbytes;
}
-static void
-input_file_close(InputStream *is)
-{
- FileInputStream *fis = (FileInputStream *)is;
-
- delete fis;
-}
-
static bool
input_file_eof(InputStream *is)
{
@@ -142,7 +134,6 @@ const InputPlugin input_plugin_file = {
nullptr,
nullptr,
input_file_open,
- input_file_close,
nullptr,
nullptr,
nullptr,
diff --git a/src/input/plugins/MmsInputPlugin.cxx b/src/input/plugins/MmsInputPlugin.cxx
index d4095b2cb..a5d4bc09d 100644
--- a/src/input/plugins/MmsInputPlugin.cxx
+++ b/src/input/plugins/MmsInputPlugin.cxx
@@ -106,7 +106,6 @@ const InputPlugin input_plugin_mms = {
nullptr,
nullptr,
input_mms_open,
- ThreadInputStream::Close,
ThreadInputStream::Check,
nullptr,
nullptr,
diff --git a/src/input/plugins/NfsInputPlugin.cxx b/src/input/plugins/NfsInputPlugin.cxx
index 9b5ca5959..19eda0605 100644
--- a/src/input/plugins/NfsInputPlugin.cxx
+++ b/src/input/plugins/NfsInputPlugin.cxx
@@ -156,13 +156,6 @@ input_nfs_read(InputStream *is, void *ptr, size_t size,
return s.Read(ptr, size, error);
}
-static void
-input_nfs_close(InputStream *is)
-{
- NfsInputStream *s = (NfsInputStream *)is;
- delete s;
-}
-
static bool
input_nfs_eof(InputStream *is)
{
@@ -184,7 +177,6 @@ const InputPlugin input_plugin_nfs = {
nullptr,
nullptr,
input_nfs_open,
- input_nfs_close,
nullptr,
nullptr,
nullptr,
diff --git a/src/input/plugins/RewindInputPlugin.cxx b/src/input/plugins/RewindInputPlugin.cxx
index 9665615f8..b1ec3ab62 100644
--- a/src/input/plugins/RewindInputPlugin.cxx
+++ b/src/input/plugins/RewindInputPlugin.cxx
@@ -60,7 +60,7 @@ public:
}
~RewindInputStream() {
- input->Close();
+ delete input;
}
bool Check(Error &error) {
@@ -121,14 +121,6 @@ private:
}
};
-static void
-input_rewind_close(InputStream *is)
-{
- RewindInputStream *r = (RewindInputStream *)is;
-
- delete r;
-}
-
static bool
input_rewind_check(InputStream *is, Error &error)
{
@@ -263,7 +255,6 @@ const InputPlugin rewind_input_plugin = {
nullptr,
nullptr,
nullptr,
- input_rewind_close,
input_rewind_check,
input_rewind_update,
input_rewind_tag,
diff --git a/src/input/plugins/SmbclientInputPlugin.cxx b/src/input/plugins/SmbclientInputPlugin.cxx
index c291f0608..07ffb83c4 100644
--- a/src/input/plugins/SmbclientInputPlugin.cxx
+++ b/src/input/plugins/SmbclientInputPlugin.cxx
@@ -149,13 +149,6 @@ input_smbclient_read(InputStream *is, void *ptr, size_t size,
return s.Read(ptr, size, error);
}
-static void
-input_smbclient_close(InputStream *is)
-{
- SmbclientInputStream *s = (SmbclientInputStream *)is;
- delete s;
-}
-
static bool
input_smbclient_eof(InputStream *is)
{
@@ -177,7 +170,6 @@ const InputPlugin input_plugin_smbclient = {
input_smbclient_init,
nullptr,
input_smbclient_open,
- input_smbclient_close,
nullptr,
nullptr,
nullptr,