aboutsummaryrefslogtreecommitdiffstats
path: root/codecs/codecs.c
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2013-12-02 08:30:29 +0000
committerGuy Harris <guy@alum.mit.edu>2013-12-02 08:30:29 +0000
commit0cc1545d05be6f655c950904b1da776190f3af16 (patch)
treeb82725615b527304bfb2e9e7d9f3b6dfc50ce7fd /codecs/codecs.c
parentbaf569188ac49ad38912b82d23ff241321cd654f (diff)
Move most of the plugin code from epan to wsutil and remove all
knowledge of particular types of plugins. Instead, let particular types of plugins register with the common plugin code, giving a name and a routine to recognize that type of plugin. In particular applications, only process the relevant plugin types. Add a Makefile.common to the codecs directory. svn path=/trunk/; revision=53710
Diffstat (limited to 'codecs/codecs.c')
-rw-r--r--codecs/codecs.c73
1 files changed, 73 insertions, 0 deletions
diff --git a/codecs/codecs.c b/codecs/codecs.c
index 0cb397f99b..abe3eaa714 100644
--- a/codecs/codecs.c
+++ b/codecs/codecs.c
@@ -22,9 +22,82 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
+#include "config.h"
+
#include <glib.h>
#include "codecs.h"
+#ifdef HAVE_PLUGINS
+
+#include <gmodule.h>
+
+#include <wsutil/plugins.h>
+
+/*
+ * List of codec plugins.
+ */
+typedef struct {
+ void (*register_codec_module)(void); /* routine to call to register a codec */
+} codec_plugin;
+
+static GSList *codec_plugins = NULL;
+
+/*
+ * Callback for each plugin found.
+ */
+static gboolean
+check_for_codec_plugin(GModule *handle)
+{
+ gpointer gp;
+ void (*register_codec_module)(void);
+ codec_plugin *plugin;
+
+ /*
+ * Do we have a register_codec_module routine?
+ */
+ if (!g_module_symbol(handle, "register_codec_module", &gp)) {
+ /* No, so this isn't a codec plugin. */
+ return FALSE;
+ }
+
+ /*
+ * Yes - this plugin includes one or more codecs.
+ */
+ register_codec_module = (void (*)(void))gp;
+
+ /*
+ * Add this one to the list of codec plugins.
+ */
+ plugin = (codec_plugin *)g_malloc(sizeof (codec_plugin));
+ plugin->register_codec_module = register_codec_module;
+ codec_plugins = g_slist_append(codec_plugins, plugin);
+ return TRUE;
+}
+
+void
+codec_register_plugin_types(void)
+{
+ add_plugin_type("codec", check_for_codec_plugin);
+}
+
+static void
+register_codec_plugin(gpointer data, gpointer user_data _U_)
+{
+ codec_plugin *plugin = (codec_plugin *)data;
+
+ (plugin->register_codec_module)();
+}
+
+/*
+ * For all codec plugins, call their register routines.
+ */
+void
+register_all_codecs(void)
+{
+ g_slist_foreach(codec_plugins, register_codec_plugin, NULL);
+}
+#endif /* HAVE_PLUGINS */
+
struct codec_handle {
const char *name;
codec_init_fn init_fn;