From ad37c88f800a09b75ae3174269bcdf3584406837 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Wed, 14 Sep 2011 22:25:29 +0200 Subject: input_plugin: add method update() Update the struct attributes, important for facades like the "rewind" plugin. To replace buffer(). --- src/input/rewind_input_plugin.c | 10 ++++++++++ src/input_plugin.h | 6 ++++++ src/input_stream.c | 10 ++++++++++ src/input_stream.h | 7 +++++++ 4 files changed, 33 insertions(+) diff --git a/src/input/rewind_input_plugin.c b/src/input/rewind_input_plugin.c index f4c4fa606..9d3255cfe 100644 --- a/src/input/rewind_input_plugin.c +++ b/src/input/rewind_input_plugin.c @@ -105,6 +105,15 @@ input_rewind_close(struct input_stream *is) g_free(r); } +static void +input_rewind_update(struct input_stream *is) +{ + struct input_rewind *r = (struct input_rewind *)is; + + if (!reading_from_buffer(r)) + copy_attributes(r); +} + static struct tag * input_rewind_tag(struct input_stream *is) { @@ -210,6 +219,7 @@ input_rewind_seek(struct input_stream *is, goffset offset, int whence, static const struct input_plugin rewind_input_plugin = { .close = input_rewind_close, + .update = input_rewind_update, .tag = input_rewind_tag, .buffer = input_rewind_buffer, .read = input_rewind_read, diff --git a/src/input_plugin.h b/src/input_plugin.h index 70b9155aa..3ac0bdf40 100644 --- a/src/input_plugin.h +++ b/src/input_plugin.h @@ -51,6 +51,12 @@ struct input_plugin { struct input_stream *(*open)(const char *uri, GError **error_r); void (*close)(struct input_stream *is); + /** + * Update the public attributes. Call before access. Can be + * NULL if the plugin always keeps its attributes up to date. + */ + void (*update)(struct input_stream *is); + struct tag *(*tag)(struct input_stream *is); int (*buffer)(struct input_stream *is, GError **error_r); size_t (*read)(struct input_stream *is, void *ptr, size_t size, diff --git a/src/input_stream.c b/src/input_stream.c index d207188cd..effa24798 100644 --- a/src/input_stream.c +++ b/src/input_stream.c @@ -67,6 +67,16 @@ input_stream_open(const char *url, GError **error_r) return false; } +void +input_stream_update(struct input_stream *is) +{ + assert(is != NULL); + assert(is->plugin != NULL); + + if (is->plugin->update != NULL) + is->plugin->update(is); +} + bool input_stream_seek(struct input_stream *is, goffset offset, int whence, GError **error_r) diff --git a/src/input_stream.h b/src/input_stream.h index f9cb8dbf8..529ed8762 100644 --- a/src/input_stream.h +++ b/src/input_stream.h @@ -86,6 +86,13 @@ input_stream_open(const char *uri, GError **error_r); void input_stream_close(struct input_stream *is); +/** + * Update the public attributes. Call before accessing attributes + * such as "ready" or "offset". + */ +void +input_stream_update(struct input_stream *is); + /** * Seeks to the specified position in the stream. This will most * likely fail if the "seekable" flag is false. -- cgit v1.2.3