diff options
author | Max Kellermann <max@duempel.org> | 2009-12-30 23:27:37 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2010-01-01 17:25:07 +0100 |
commit | d3b763a48c09a60a0c0b5ccb6cccd9376875c470 (patch) | |
tree | 83b8794f78ef8941806cf5757888d8abf2eaa126 /src/input_stream.c | |
parent | 816b6ad4a71c3ade95e62b62396f2b0415c03f20 (diff) | |
download | mpd-d3b763a48c09a60a0c0b5ccb6cccd9376875c470.tar.gz mpd-d3b763a48c09a60a0c0b5ccb6cccd9376875c470.tar.xz mpd-d3b763a48c09a60a0c0b5ccb6cccd9376875c470.zip |
input_stream: return allocated input_stream objects
Major API redesign: don't let the caller allocate the input_stream
object. Let each input plugin allocate its own (derived/extended)
input_stream pointer. The "data" attribute can now be removed, and
all input plugins simply cast the input_stream pointer to their own
structure (with an "struct input_stream base" as the first attribute).
Diffstat (limited to '')
-rw-r--r-- | src/input_stream.c | 24 |
1 files changed, 10 insertions, 14 deletions
diff --git a/src/input_stream.c b/src/input_stream.c index 0cf0558d6..96c692176 100644 --- a/src/input_stream.c +++ b/src/input_stream.c @@ -32,38 +32,34 @@ input_quark(void) return g_quark_from_static_string("input"); } -bool -input_stream_open(struct input_stream *is, const char *url, GError **error_r) +struct input_stream * +input_stream_open(const char *url, GError **error_r) { GError *error = NULL; assert(error_r == NULL || *error_r == NULL); - is->seekable = false; - is->ready = false; - is->offset = 0; - is->size = -1; - is->mime = NULL; - for (unsigned i = 0; input_plugins[i] != NULL; ++i) { const struct input_plugin *plugin = input_plugins[i]; + struct input_stream *is; if (!input_plugins_enabled[i]) continue; - if (plugin->open(is, url, &error)) { + is = plugin->open(url, &error); + if (is != NULL) { assert(is->plugin != NULL); assert(is->plugin->close != NULL); assert(is->plugin->read != NULL); assert(is->plugin->eof != NULL); assert(!is->seekable || is->plugin->seek != NULL); - input_rewind_open(is); + is = input_rewind_open(is); - return true; + return is; } else if (error != NULL) { g_propagate_error(error_r, error); - return false; + return NULL; } } @@ -103,9 +99,9 @@ input_stream_read(struct input_stream *is, void *ptr, size_t size, void input_stream_close(struct input_stream *is) { - is->plugin->close(is); - g_free(is->mime); + + is->plugin->close(is); } bool input_stream_eof(struct input_stream *is) |