From d3b763a48c09a60a0c0b5ccb6cccd9376875c470 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Wed, 30 Dec 2009 23:27:37 +0100 Subject: 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). --- src/input_stream.h | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) (limited to 'src/input_stream.h') diff --git a/src/input_stream.h b/src/input_stream.h index 069a9f58..e48f7eb2 100644 --- a/src/input_stream.h +++ b/src/input_stream.h @@ -38,11 +38,6 @@ struct input_stream { */ const struct input_plugin *plugin; - /** - * an opaque pointer managed by the plugin - */ - void *data; - /** * indicates whether the stream is ready for reading and * whether the other attributes in this struct are valid @@ -70,20 +65,28 @@ struct input_stream { char *mime; }; +static inline void +input_stream_init(struct input_stream *is, const struct input_plugin *plugin) +{ + is->plugin = plugin; + is->ready = false; + is->seekable = false; + is->size = -1; + is->offset = 0; + is->mime = NULL; +} + /** * Opens a new input stream. You may not access it until the "ready" * flag is set. * - * @param is the input_stream object allocated by the caller - * @return true on success + * @return an #input_stream object on success, NULL on error */ -bool -input_stream_open(struct input_stream *is, const char *url, GError **error_r); +struct input_stream * +input_stream_open(const char *uri, GError **error_r); /** - * Closes the input stream and free resources. This does not free the - * input_stream pointer itself, because it is assumed to be allocated - * by the caller. + * Close the input stream and free resources. */ void input_stream_close(struct input_stream *is); -- cgit v1.2.3