aboutsummaryrefslogtreecommitdiffstats
path: root/codecs
diff options
context:
space:
mode:
authorJoão Valverde <joao.valverde@tecnico.ulisboa.pt>2017-10-01 00:56:03 +0100
committerJoão Valverde <j@v6e.pt>2017-12-14 08:43:57 +0000
commit995812c5f1add94df1c237596939130c1704b099 (patch)
tree42542c56b9a70c7d2d231c8bc36649be35af46b4 /codecs
parenta9821caab8a1f2c6e265bd5b63a060f1f241c704 (diff)
Refactor plugin registration and loading
Put different types of plugins (libwiretap, libwireshark) in different subdirectories, give libwiretap and libwireshark init routines that load the plugins, and have them scan the appropriate subdirectories so that we don't even *try* to, for example, load libwireshark plugins in programs that only use libwiretap. Compiled plugins are stored in subfolders of the plugin folders, with the subfolder name being the Wireshark minor version number (X.Y). There is another hierarchical level for each Wireshark library (libwireshark, libwscodecs and libwiretap). The folder names are respectively plugins/X.Y/{epan,codecs,wiretap}. Currently we only distribute "epan" (libwireshark) plugins. Change-Id: I3438787a6f45820d64ba4ca91cbe3c8864708acb Reviewed-on: https://code.wireshark.org/review/23983 Petri-Dish: João Valverde <j@v6e.pt> Tested-by: Petri Dish Buildbot Reviewed-by: João Valverde <j@v6e.pt>
Diffstat (limited to 'codecs')
-rw-r--r--codecs/codecs.c75
-rw-r--r--codecs/codecs.h13
2 files changed, 34 insertions, 54 deletions
diff --git a/codecs/codecs.c b/codecs/codecs.c
index 4e7eb60edd..b109a6af2b 100644
--- a/codecs/codecs.c
+++ b/codecs/codecs.c
@@ -43,65 +43,24 @@
#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.
- */
-DIAG_OFF(pedantic)
-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_prepend(codec_plugins, plugin);
- return TRUE;
-}
-DIAG_ON(pedantic)
+static plugins_t *libwscodecs_plugins;
+static GSList *codecs_plugins = NULL;
void
-codec_register_plugin_types(void)
+codecs_register_plugin(const codecs_plugin *plug)
{
- add_plugin_type("codec", check_for_codec_plugin);
+ codecs_plugins = g_slist_prepend(codecs_plugins, (codecs_plugin *)plug);
}
static void
-register_codec_plugin(gpointer data, gpointer user_data _U_)
+call_plugin_register_codec_module(gpointer data, gpointer user_data _U_)
{
- codec_plugin *plugin = (codec_plugin *)data;
+ codecs_plugin *plug = (codecs_plugin *)data;
- (plugin->register_codec_module)();
+ if (plug->register_codec_module) {
+ plug->register_codec_module();
+ }
}
#endif /* HAVE_PLUGINS */
@@ -110,7 +69,7 @@ register_codec_plugin(gpointer data, gpointer user_data _U_)
* For all codec plugins, call their register routines.
*/
void
-register_all_codecs(void)
+codecs_init(void)
{
register_codec("g711U", codec_g711u_init, codec_g711u_release,
codec_g711u_get_channels, codec_g711u_get_frequency, codec_g711u_decode);
@@ -150,10 +109,22 @@ register_all_codecs(void)
#endif
#ifdef HAVE_PLUGINS
- g_slist_foreach(codec_plugins, register_codec_plugin, NULL);
+ libwscodecs_plugins = plugins_init("codecs");
+ g_slist_foreach(codecs_plugins, call_plugin_register_codec_module, NULL);
#endif /* HAVE_PLUGINS */
}
+void
+codecs_cleanup(void)
+{
+#ifdef HAVE_PLUGINS
+ g_slist_free(codecs_plugins);
+ codecs_plugins = NULL;
+ plugins_cleanup(libwscodecs_plugins);
+ libwscodecs_plugins = NULL;
+#endif
+}
+
struct codec_handle {
const char *name;
diff --git a/codecs/codecs.h b/codecs/codecs.h
index fabc734206..e8fe4fa12f 100644
--- a/codecs/codecs.h
+++ b/codecs/codecs.h
@@ -26,19 +26,28 @@
#include <epan/epan.h>
#include "ws_symbol_export.h"
#include "ws_attributes.h"
+#ifdef HAVE_PLUGINS
+#include "wsutil/plugins.h"
+#endif
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
#ifdef HAVE_PLUGINS
-WS_DLL_PUBLIC void codec_register_plugin_types(void);
+typedef struct {
+ void (*register_codec_module)(void); /* routine to call to register a codec */
+} codecs_plugin;
+
+WS_DLL_PUBLIC void codecs_register_plugin(const codecs_plugin *plug);
#endif
/**
* For all built-in codecs and codec plugins, call their register routines.
*/
-WS_DLL_PUBLIC void register_all_codecs(void);
+WS_DLL_PUBLIC void codecs_init(void);
+
+WS_DLL_PUBLIC void codecs_cleanup(void);
/**
* Get compile-time information for libraries used by libwscodecs.