changeset 3682:84bc78954db5

Start working on exporting all public functions via a vtable. The API version will be bumped to 7 once I am done and -Wl,-export-dynamic is removed.
author William Pitcock <nenolod@atheme.org>
date Mon, 01 Oct 2007 23:00:46 -0500
parents 7865f8395437
children 4284187479d7
files src/audacious/plugin.h src/audacious/pluginenum.c
diffstat 2 files changed, 108 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/audacious/plugin.h	Mon Oct 01 14:16:52 2007 -0500
+++ b/src/audacious/plugin.h	Mon Oct 01 23:00:46 2007 -0500
@@ -121,11 +121,87 @@
 
 #define PLUGIN_MAGIC 0x8EAC8DE2
 
+/* define the public API here */
+/* add new functions to the bottom of this list!!!! --nenolod */
+struct _AudaciousFuncVTable1 {
+
+    /* VFS */
+    VFSFile *(*vfs_fopen)(const gchar *uri, const gchar *mode);
+    gint (*vfs_fclose)(VFSFile *fd);
+    VFSFile *(*vfs_dup)(VFSFile *in);
+    size_t (*vfs_fread)(gpointer ptr,
+                 size_t size,
+                 size_t nmemb,
+                 VFSFile * file);
+    size_t (*vfs_fwrite)(gconstpointer ptr,
+                  size_t size,
+                  size_t nmemb,
+                  VFSFile *file);
+
+    gint (*vfs_getc)(VFSFile *stream);
+    gint (*vfs_ungetc)(gint c,
+                       VFSFile *stream);
+    gchar *(*vfs_fgets)(gchar *s,
+                        gint n,
+                        VFSFile *stream);
+
+    gint (*vfs_fseek)(VFSFile * file,
+                      glong offset,
+                      gint whence);
+    void (*vfs_rewind)(VFSFile * file);
+    glong (*vfs_ftell)(VFSFile * file);
+    gboolean (*vfs_feof)(VFSFile * file);
+
+    gboolean (*vfs_file_test)(const gchar * path,
+                              GFileTest test);
+
+    gboolean (*vfs_is_writeable)(const gchar * path);
+    gboolean (*vfs_truncate)(VFSFile * file, glong length);
+    off_t (*vfs_fsize)(VFSFile * file);
+    gchar *(*vfs_get_metadata)(VFSFile * file, const gchar * field);
+
+    int (*vfs_fprintf)(VFSFile *stream, gchar const *format, ...)
+        __attribute__ ((__format__ (__printf__, 2, 3)));
+
+    gboolean (*vfs_register_transport)(VFSConstructor *vtable);
+    void (*vfs_file_get_contents)(const gchar *filename, gchar **buf, gsize *size);
+    gboolean (*vfs_is_remote)(const gchar * path);
+    gboolean (*vfs_is_streaming)(VFSFile *file);
+
+};
+
+/* Convenience macros for accessing the public API. */
+/*	public name			vtable mapping      */
+#define aud_vfs_fopen			_audvt->vfs_fopen
+#define aud_vfs_fclose			_audvt->vfs_fclose
+#define aud_vfs_dup			_audvt->vfs_dup
+#define aud_vfs_fread			_audvt->vfs_fread
+#define aud_vfs_fwrite			_audvt->vfs_fwrite
+#define aud_vfs_getc			_audvt->vfs_getc
+#define aud_vfs_ungetc			_audvt->vfs_ungetc
+#define aud_vfs_fgets			_audvt->vfs_fgets
+#define aud_vfs_fseek			_audvt->vfs_fseek
+#define aud_vfs_rewind			_audvt->vfs_rewind
+#define aud_vfs_ftell			_audvt->vfs_ftell
+#define aud_vfs_feof			_audvt->vfs_feof
+#define aud_vfs_file_test		_audvt->vfs_file_test
+#define aud_vfs_is_writeable		_audvt->vfs_is_writeable
+#define aud_vfs_truncate		_audvt->vfs_truncate
+#define aud_vfs_fsize			_audvt->vfs_fsize
+#define aud_vfs_get_metadata		_audvt->vfs_get_metadata
+#define aud_vfs_fprintf			_audvt->vfs_fprintf
+#define aud_vfs_register_transport	_audvt->vfs_register_transport
+#define aud_vfs_file_get_contents	_audvt->vfs_file_get_contents
+#define aud_vfs_is_remote		_audvt->vfs_is_remote
+#define aud_vfs_is_streaming		_audvt->vfs_is_streaming
+
 #define DECLARE_PLUGIN(name, init, fini, ...) \
 	G_BEGIN_DECLS \
 	static PluginHeader _pluginInfo = { PLUGIN_MAGIC, __AUDACIOUS_PLUGIN_API__, \
 		(gchar *)#name, init, fini, NULL, __VA_ARGS__ }; \
-	G_MODULE_EXPORT PluginHeader *get_plugin_info(void) { \
+	static struct _AudaciousFuncVTable1 *_audvt = NULL; \
+	G_MODULE_EXPORT PluginHeader *get_plugin_info(struct _AudaciousFuncVTable1 *_vt) { \
+		_audvt = _vt; \
 		return &_pluginInfo; \
 	} \
 	G_END_DECLS
--- a/src/audacious/pluginenum.c	Mon Oct 01 14:16:52 2007 -0500
+++ b/src/audacious/pluginenum.c	Mon Oct 01 23:00:46 2007 -0500
@@ -57,6 +57,35 @@
     NULL
 };
 
+/*****************************************************************/
+
+static struct _AudaciousFuncTableV1 _aud_papi_v1 = {
+    .vfs_fopen = vfs_fopen,
+    .vfs_fclose = vfs_fclose,
+    .vfs_dup = vfs_dup,
+    .vfs_fread = vfs_fread,
+    .vfs_fwrite = vfs_fwrite,
+    .vfs_getc = vfs_getc,
+    .vfs_ungetc = vfs_ungetc,
+    .vfs_fgets = vfs_fgets,
+    .vfs_fseek = vfs_fseek,
+    .vfs_rewind = vfs_rewind,
+    .vfs_ftell = vfs_ftell,
+    .vfs_feof = vfs_feof,
+    .vfs_file_test = vfs_file_test,
+    .vfs_is_writeable = vfs_is_writeable,
+    .vfs_truncate = vfs_truncate,
+    .vfs_fsize = vfs_fsize,
+    .vfs_get_metadata = vfs_get_metadata,
+    .vfs_fprintf = vfs_fprintf,
+    .vfs_register_transport = vfs_register_transport,
+    .vfs_file_get_contents = vfs_file_get_contents,
+    .vfs_is_remote = vfs_is_remote,
+    .vfs_is_streaming = vfs_is_streaming,
+}
+
+/*****************************************************************/
+
 GList *lowlevel_list = NULL;
 extern GList *vfs_transports;
 
@@ -371,11 +400,11 @@
     /* v2 plugin loading */
     if (g_module_symbol(module, "get_plugin_info", &func))
     {
-        PluginHeader *(*header_func_p)() = func;
+        PluginHeader *(*header_func_p)(struct _AudaciousFuncTableV1 *) = func;
         PluginHeader *header;
 
         /* this should never happen. */
-        g_return_if_fail((header = header_func_p()) != NULL);
+        g_return_if_fail((header = header_func_p(&_aud_papi_v1)) != NULL);
 
         plugin2_process(header, module, filename);
         return;