diff options
author | Max Kellermann <max@duempel.org> | 2008-10-26 20:38:44 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2008-10-26 20:38:44 +0100 |
commit | f08041f0eb8512304584b583073508629a934c88 (patch) | |
tree | 6a0d548ac1ee174b5505abe621fcb6f67afc688b /src/input_stream.c | |
parent | dbc7e9ba2f57c71a9b73cd6d035ba2906190be72 (diff) | |
download | mpd-f08041f0eb8512304584b583073508629a934c88.tar.gz mpd-f08041f0eb8512304584b583073508629a934c88.tar.xz mpd-f08041f0eb8512304584b583073508629a934c88.zip |
input_stream: added struct input_plugin
Instead of managing a set of method pointers in each input_stream
struct, move these into the new input_plugin struct. Each
input_stream has only a pointer to the plugin struct. Pointers to all
implementations are kept in the array "input_plugins".
Diffstat (limited to 'src/input_stream.c')
-rw-r--r-- | src/input_stream.c | 33 |
1 files changed, 22 insertions, 11 deletions
diff --git a/src/input_stream.c b/src/input_stream.c index db51cbd4c..a5c55fa54 100644 --- a/src/input_stream.c +++ b/src/input_stream.c @@ -27,6 +27,16 @@ #include <stdlib.h> +static const struct input_plugin *const input_plugins[] = { + &input_plugin_file, +#ifdef HAVE_CURL + &input_plugin_curl, +#endif +}; + +static const unsigned num_input_plugins = + sizeof(input_plugins) / sizeof(input_plugins[0]); + void input_stream_global_init(void) { #ifdef HAVE_CURL @@ -52,26 +62,27 @@ int input_stream_open(struct input_stream *is, char *url) is->meta_name = NULL; is->meta_title = NULL; - if (input_file_open(is, url) == 0) - return 0; + for (unsigned i = 0; i < num_input_plugins; ++i) { + const struct input_plugin *plugin = input_plugins[i]; -#ifdef HAVE_CURL - if (input_curl_open(is, url)) - return 0; -#endif + if (plugin->open(is, url)) { + is->plugin = plugin; + return 0; + } + } return -1; } int input_stream_seek(struct input_stream *is, long offset, int whence) { - return is->seekFunc(is, offset, whence); + return is->plugin->seek(is, offset, whence); } size_t input_stream_read(struct input_stream *is, void *ptr, size_t size) { - return is->readFunc(is, ptr, size); + return is->plugin->read(is, ptr, size); } int input_stream_close(struct input_stream *is) @@ -83,15 +94,15 @@ int input_stream_close(struct input_stream *is) if (is->meta_title) free(is->meta_title); - return is->closeFunc(is); + return is->plugin->close(is); } int input_stream_eof(struct input_stream *is) { - return is->atEOFFunc(is); + return is->plugin->eof(is); } int input_stream_buffer(struct input_stream *is) { - return is->bufferFunc(is); + return is->plugin->buffer(is); } |