From 49567f1f3eab7ac04e4c3c818212e4e3cb437e0f Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Fri, 25 Jan 2013 22:43:01 +0100 Subject: input_{internal,plugin}: convert to C++ --- src/CommandLine.cxx | 2 +- src/InputInit.cxx | 2 +- src/InputInternal.cxx | 73 ++++++++++++++++++++++++++++ src/InputInternal.hxx | 43 +++++++++++++++++ src/InputPlugin.hxx | 88 ++++++++++++++++++++++++++++++++++ src/InputStream.cxx | 2 +- src/archive/Bzip2ArchivePlugin.cxx | 4 +- src/archive/Iso9660ArchivePlugin.cxx | 4 +- src/archive/ZzipArchivePlugin.cxx | 4 +- src/input/ArchiveInputPlugin.cxx | 2 +- src/input/CdioParanoiaInputPlugin.cxx | 4 +- src/input/CurlInputPlugin.cxx | 4 +- src/input/DespotifyInputPlugin.cxx | 4 +- src/input/FfmpegInputPlugin.cxx | 4 +- src/input/FileInputPlugin.cxx | 4 +- src/input/MmsInputPlugin.cxx | 4 +- src/input/RewindInputPlugin.cxx | 4 +- src/input/SoupInputPlugin.cxx | 4 +- src/input_internal.c | 73 ---------------------------- src/input_internal.h | 51 -------------------- src/input_plugin.h | 89 ----------------------------------- 21 files changed, 230 insertions(+), 239 deletions(-) create mode 100644 src/InputInternal.cxx create mode 100644 src/InputInternal.hxx create mode 100644 src/InputPlugin.hxx delete mode 100644 src/input_internal.c delete mode 100644 src/input_internal.h delete mode 100644 src/input_plugin.h (limited to 'src') diff --git a/src/CommandLine.cxx b/src/CommandLine.cxx index 732e3eb60..6b7a8b1ca 100644 --- a/src/CommandLine.cxx +++ b/src/CommandLine.cxx @@ -27,7 +27,7 @@ #include "OutputList.hxx" #include "output_plugin.h" #include "InputRegistry.hxx" -#include "input_plugin.h" +#include "InputPlugin.hxx" #include "playlist_list.h" #include "playlist_plugin.h" #include "mpd_error.h" diff --git a/src/InputInit.cxx b/src/InputInit.cxx index 6714cc727..64cdfc7af 100644 --- a/src/InputInit.cxx +++ b/src/InputInit.cxx @@ -20,7 +20,7 @@ #include "config.h" #include "InputInit.hxx" #include "InputRegistry.hxx" -#include "input_plugin.h" +#include "InputPlugin.hxx" #include "conf.h" #include diff --git a/src/InputInternal.cxx b/src/InputInternal.cxx new file mode 100644 index 000000000..a5e5ecd59 --- /dev/null +++ b/src/InputInternal.cxx @@ -0,0 +1,73 @@ +/* + * Copyright (C) 2003-2013 The Music Player Daemon Project + * http://www.musicpd.org + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include "config.h" +#include "InputInternal.hxx" +#include "input_stream.h" + +#include + +void +input_stream_init(struct input_stream *is, const struct input_plugin *plugin, + const char *uri, GMutex *mutex, GCond *cond) +{ + assert(is != NULL); + assert(plugin != NULL); + assert(uri != NULL); + + is->plugin = plugin; + is->uri = g_strdup(uri); + is->mutex = mutex; + is->cond = cond; + is->ready = false; + is->seekable = false; + is->size = -1; + is->offset = 0; + is->mime = NULL; +} + +void +input_stream_deinit(struct input_stream *is) +{ + assert(is != NULL); + assert(is->plugin != NULL); + + g_free(is->uri); + g_free(is->mime); +} + +void +input_stream_signal_client(struct input_stream *is) +{ + if (is->cond != NULL) + g_cond_broadcast(is->cond); +} + +void +input_stream_set_ready(struct input_stream *is) +{ + g_mutex_lock(is->mutex); + + if (!is->ready) { + is->ready = true; + input_stream_signal_client(is); + } + + g_mutex_unlock(is->mutex); +} diff --git a/src/InputInternal.hxx b/src/InputInternal.hxx new file mode 100644 index 000000000..33e010daf --- /dev/null +++ b/src/InputInternal.hxx @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2003-2013 The Music Player Daemon Project + * http://www.musicpd.org + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#ifndef MPD_INPUT_INTERNAL_HXX +#define MPD_INPUT_INTERNAL_HXX + +#include "check.h" + +#include + +struct input_stream; +struct input_plugin; + +void +input_stream_init(struct input_stream *is, const struct input_plugin *plugin, + const char *uri, GMutex *mutex, GCond *cond); + +void +input_stream_deinit(struct input_stream *is); + +void +input_stream_signal_client(struct input_stream *is); + +void +input_stream_set_ready(struct input_stream *is); + +#endif diff --git a/src/InputPlugin.hxx b/src/InputPlugin.hxx new file mode 100644 index 000000000..abbd74ff0 --- /dev/null +++ b/src/InputPlugin.hxx @@ -0,0 +1,88 @@ +/* + * Copyright (C) 2003-2013 The Music Player Daemon Project + * http://www.musicpd.org + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#ifndef MPD_INPUT_PLUGIN_HXX +#define MPD_INPUT_PLUGIN_HXX + +#include "input_stream.h" + +#include +#include + +struct config_param; +struct input_stream; + +struct input_plugin { + const char *name; + + /** + * Global initialization. This method is called when MPD starts. + * + * @param error_r location to store the error occurring, or + * NULL to ignore errors + * @return true on success, false if the plugin should be + * disabled + */ + bool (*init)(const struct config_param *param, GError **error_r); + + /** + * Global deinitialization. Called once before MPD shuts + * down (only if init() has returned true). + */ + void (*finish)(void); + + struct input_stream *(*open)(const char *uri, + GMutex *mutex, GCond *cond, + GError **error_r); + void (*close)(struct input_stream *is); + + /** + * Check for errors that may have occurred in the I/O thread. + * May be unimplemented for synchronous plugins. + * + * @return false on error + */ + bool (*check)(struct input_stream *is, GError **error_r); + + /** + * 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); + + /** + * Returns true if the next read operation will not block: + * either data is available, or end-of-stream has been + * reached, or an error has occurred. + * + * If this method is unimplemented, then it is assumed that + * reading will never block. + */ + bool (*available)(struct input_stream *is); + + size_t (*read)(struct input_stream *is, void *ptr, size_t size, + GError **error_r); + bool (*eof)(struct input_stream *is); + bool (*seek)(struct input_stream *is, goffset offset, int whence, + GError **error_r); +}; + +#endif diff --git a/src/InputStream.cxx b/src/InputStream.cxx index c81181b6e..a39af2bd6 100644 --- a/src/InputStream.cxx +++ b/src/InputStream.cxx @@ -20,7 +20,7 @@ #include "config.h" #include "input_stream.h" #include "InputRegistry.hxx" -#include "input_plugin.h" +#include "InputPlugin.hxx" #include "input/RewindInputPlugin.hxx" extern "C" { diff --git a/src/archive/Bzip2ArchivePlugin.cxx b/src/archive/Bzip2ArchivePlugin.cxx index 31adb98af..1e7c0c80e 100644 --- a/src/archive/Bzip2ArchivePlugin.cxx +++ b/src/archive/Bzip2ArchivePlugin.cxx @@ -25,8 +25,8 @@ #include "Bzip2ArchivePlugin.hxx" #include "ArchiveInternal.hxx" #include "ArchivePlugin.hxx" -#include "input_internal.h" -#include "input_plugin.h" +#include "InputInternal.hxx" +#include "InputPlugin.hxx" #include "refcount.h" #include diff --git a/src/archive/Iso9660ArchivePlugin.cxx b/src/archive/Iso9660ArchivePlugin.cxx index 3f12912a5..a3bf600a0 100644 --- a/src/archive/Iso9660ArchivePlugin.cxx +++ b/src/archive/Iso9660ArchivePlugin.cxx @@ -25,8 +25,8 @@ #include "Iso9660ArchivePlugin.hxx" #include "ArchiveInternal.hxx" #include "ArchivePlugin.hxx" -#include "input_internal.h" -#include "input_plugin.h" +#include "InputInternal.hxx" +#include "InputPlugin.hxx" #include "refcount.h" #include diff --git a/src/archive/ZzipArchivePlugin.cxx b/src/archive/ZzipArchivePlugin.cxx index 00e689fbd..ea6ec4e75 100644 --- a/src/archive/ZzipArchivePlugin.cxx +++ b/src/archive/ZzipArchivePlugin.cxx @@ -25,8 +25,8 @@ #include "ZzipArchivePlugin.hxx" #include "ArchiveInternal.hxx" #include "ArchivePlugin.hxx" -#include "input_internal.h" -#include "input_plugin.h" +#include "InputInternal.hxx" +#include "InputPlugin.hxx" #include "refcount.h" #include diff --git a/src/input/ArchiveInputPlugin.cxx b/src/input/ArchiveInputPlugin.cxx index 560c65843..dd4956f7b 100644 --- a/src/input/ArchiveInputPlugin.cxx +++ b/src/input/ArchiveInputPlugin.cxx @@ -22,7 +22,7 @@ #include "ArchiveLookup.hxx" #include "ArchiveList.hxx" #include "ArchivePlugin.hxx" -#include "input_plugin.h" +#include "InputPlugin.hxx" #include diff --git a/src/input/CdioParanoiaInputPlugin.cxx b/src/input/CdioParanoiaInputPlugin.cxx index bf4ddc7f5..e8dabd88f 100644 --- a/src/input/CdioParanoiaInputPlugin.cxx +++ b/src/input/CdioParanoiaInputPlugin.cxx @@ -23,8 +23,8 @@ #include "config.h" #include "CdioParanoiaInputPlugin.hxx" -#include "input_internal.h" -#include "input_plugin.h" +#include "InputInternal.hxx" +#include "InputPlugin.hxx" #include "refcount.h" #include diff --git a/src/input/CurlInputPlugin.cxx b/src/input/CurlInputPlugin.cxx index cc9987a19..ed70de072 100644 --- a/src/input/CurlInputPlugin.cxx +++ b/src/input/CurlInputPlugin.cxx @@ -19,12 +19,12 @@ #include "config.h" #include "CurlInputPlugin.hxx" -#include "input_plugin.h" +#include "InputPlugin.hxx" #include "conf.h" #include "tag.h" #include "IcyMetaDataParser.hxx" #include "event/MultiSocketMonitor.hxx" -#include "input_internal.h" +#include "InputInternal.hxx" #include "event/Loop.hxx" #include "IOThread.hxx" #include "glib_compat.h" diff --git a/src/input/DespotifyInputPlugin.cxx b/src/input/DespotifyInputPlugin.cxx index b42979e3b..af550cab5 100644 --- a/src/input/DespotifyInputPlugin.cxx +++ b/src/input/DespotifyInputPlugin.cxx @@ -20,8 +20,8 @@ #include "config.h" #include "DespotifyInputPlugin.hxx" #include "DespotifyUtils.hxx" -#include "input_internal.h" -#include "input_plugin.h" +#include "InputInternal.hxx" +#include "InputPlugin.hxx" #include "tag.h" extern "C" { diff --git a/src/input/FfmpegInputPlugin.cxx b/src/input/FfmpegInputPlugin.cxx index 53e67ef17..3e59bca9c 100644 --- a/src/input/FfmpegInputPlugin.cxx +++ b/src/input/FfmpegInputPlugin.cxx @@ -22,8 +22,8 @@ #include "config.h" #include "FfmpegInputPlugin.hxx" -#include "input_internal.h" -#include "input_plugin.h" +#include "InputInternal.hxx" +#include "InputPlugin.hxx" extern "C" { #include diff --git a/src/input/FileInputPlugin.cxx b/src/input/FileInputPlugin.cxx index edf96e500..8d3ef7510 100644 --- a/src/input/FileInputPlugin.cxx +++ b/src/input/FileInputPlugin.cxx @@ -19,8 +19,8 @@ #include "config.h" /* must be first for large file support */ #include "FileInputPlugin.hxx" -#include "input_internal.h" -#include "input_plugin.h" +#include "InputInternal.hxx" +#include "InputPlugin.hxx" #include "fd_util.h" #include "open.h" #include "io_error.h" diff --git a/src/input/MmsInputPlugin.cxx b/src/input/MmsInputPlugin.cxx index 45cdd072c..719aca29d 100644 --- a/src/input/MmsInputPlugin.cxx +++ b/src/input/MmsInputPlugin.cxx @@ -19,8 +19,8 @@ #include "config.h" #include "MmsInputPlugin.hxx" -#include "input_internal.h" -#include "input_plugin.h" +#include "InputInternal.hxx" +#include "InputPlugin.hxx" #include #include diff --git a/src/input/RewindInputPlugin.cxx b/src/input/RewindInputPlugin.cxx index 6890a8eed..241a5fb5a 100644 --- a/src/input/RewindInputPlugin.cxx +++ b/src/input/RewindInputPlugin.cxx @@ -19,8 +19,8 @@ #include "config.h" #include "RewindInputPlugin.hxx" -#include "input_internal.h" -#include "input_plugin.h" +#include "InputInternal.hxx" +#include "InputPlugin.hxx" #include "tag.h" #include diff --git a/src/input/SoupInputPlugin.cxx b/src/input/SoupInputPlugin.cxx index fb446136c..44c26be5a 100644 --- a/src/input/SoupInputPlugin.cxx +++ b/src/input/SoupInputPlugin.cxx @@ -19,8 +19,8 @@ #include "config.h" #include "SoupInputPlugin.hxx" -#include "input_plugin.h" -#include "input_internal.h" +#include "InputPlugin.hxx" +#include "InputInternal.hxx" #include "IOThread.hxx" #include "event/Loop.hxx" #include "conf.h" diff --git a/src/input_internal.c b/src/input_internal.c deleted file mode 100644 index 92a71856e..000000000 --- a/src/input_internal.c +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright (C) 2003-2011 The Music Player Daemon Project - * http://www.musicpd.org - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#include "config.h" -#include "input_internal.h" -#include "input_stream.h" - -#include - -void -input_stream_init(struct input_stream *is, const struct input_plugin *plugin, - const char *uri, GMutex *mutex, GCond *cond) -{ - assert(is != NULL); - assert(plugin != NULL); - assert(uri != NULL); - - is->plugin = plugin; - is->uri = g_strdup(uri); - is->mutex = mutex; - is->cond = cond; - is->ready = false; - is->seekable = false; - is->size = -1; - is->offset = 0; - is->mime = NULL; -} - -void -input_stream_deinit(struct input_stream *is) -{ - assert(is != NULL); - assert(is->plugin != NULL); - - g_free(is->uri); - g_free(is->mime); -} - -void -input_stream_signal_client(struct input_stream *is) -{ - if (is->cond != NULL) - g_cond_broadcast(is->cond); -} - -void -input_stream_set_ready(struct input_stream *is) -{ - g_mutex_lock(is->mutex); - - if (!is->ready) { - is->ready = true; - input_stream_signal_client(is); - } - - g_mutex_unlock(is->mutex); -} diff --git a/src/input_internal.h b/src/input_internal.h deleted file mode 100644 index 688afaa6e..000000000 --- a/src/input_internal.h +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (C) 2003-2011 The Music Player Daemon Project - * http://www.musicpd.org - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#ifndef MPD_INPUT_INTERNAL_H -#define MPD_INPUT_INTERNAL_H - -#include "check.h" - -#include - -struct input_stream; -struct input_plugin; - -#ifdef __cplusplus -extern "C" { -#endif - -void -input_stream_init(struct input_stream *is, const struct input_plugin *plugin, - const char *uri, GMutex *mutex, GCond *cond); - -void -input_stream_deinit(struct input_stream *is); - -void -input_stream_signal_client(struct input_stream *is); - -void -input_stream_set_ready(struct input_stream *is); - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/src/input_plugin.h b/src/input_plugin.h deleted file mode 100644 index 6b0c77c85..000000000 --- a/src/input_plugin.h +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright (C) 2003-2011 The Music Player Daemon Project - * http://www.musicpd.org - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along - * with this program; if not, write to the Free Software Foundation, Inc., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#ifndef MPD_INPUT_PLUGIN_H -#define MPD_INPUT_PLUGIN_H - -#include "input_stream.h" - -#include -#include -#include - -struct config_param; -struct input_stream; - -struct input_plugin { - const char *name; - - /** - * Global initialization. This method is called when MPD starts. - * - * @param error_r location to store the error occurring, or - * NULL to ignore errors - * @return true on success, false if the plugin should be - * disabled - */ - bool (*init)(const struct config_param *param, GError **error_r); - - /** - * Global deinitialization. Called once before MPD shuts - * down (only if init() has returned true). - */ - void (*finish)(void); - - struct input_stream *(*open)(const char *uri, - GMutex *mutex, GCond *cond, - GError **error_r); - void (*close)(struct input_stream *is); - - /** - * Check for errors that may have occurred in the I/O thread. - * May be unimplemented for synchronous plugins. - * - * @return false on error - */ - bool (*check)(struct input_stream *is, GError **error_r); - - /** - * 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); - - /** - * Returns true if the next read operation will not block: - * either data is available, or end-of-stream has been - * reached, or an error has occurred. - * - * If this method is unimplemented, then it is assumed that - * reading will never block. - */ - bool (*available)(struct input_stream *is); - - size_t (*read)(struct input_stream *is, void *ptr, size_t size, - GError **error_r); - bool (*eof)(struct input_stream *is); - bool (*seek)(struct input_stream *is, goffset offset, int whence, - GError **error_r); -}; - -#endif -- cgit v1.2.3