[farsight2/master] Add API to list plugins
Olivier Crête
olivier.crete at collabora.co.uk
Tue Dec 23 15:26:00 PST 2008
---
docs/libs/farsight2-libs-sections.txt | 1 +
gst-libs/gst/farsight/fs-plugin.c | 90 +++++++++++++++++++++++++++++++++
gst-libs/gst/farsight/fs-plugin.h | 2 +
tests/check/transmitter/rawudp.c | 18 +++++++
4 files changed, 111 insertions(+), 0 deletions(-)
diff --git a/docs/libs/farsight2-libs-sections.txt b/docs/libs/farsight2-libs-sections.txt
index 5007407..76f0175 100644
--- a/docs/libs/farsight2-libs-sections.txt
+++ b/docs/libs/farsight2-libs-sections.txt
@@ -201,6 +201,7 @@ FsPlugin
fs_plugin_create_valist
fs_plugin_create
FS_INIT_PLUGIN
+fs_plugin_list_available
<SUBSECTION Standard>
FsPluginClass
FS_IS_PLUGIN
diff --git a/gst-libs/gst/farsight/fs-plugin.c b/gst-libs/gst/farsight/fs-plugin.c
index 7cdd011..b24ea62 100644
--- a/gst-libs/gst/farsight/fs-plugin.c
+++ b/gst-libs/gst/farsight/fs-plugin.c
@@ -322,3 +322,93 @@ fs_plugin_create (const gchar *name, const gchar *type_suffix,
return obj;
}
+
+/**
+ * fs_plugin_list_available:
+ * @type_suffix: Get list of plugins with this type suffix
+ *
+ * Gets the list of all available plugins of a certain type
+ *
+ * Returns: a newly allocated NULL terminated array of strings or %NULL if no
+ * strings were found
+ */
+
+gchar **
+fs_plugin_list_available (const gchar *type_suffix)
+{
+ GPtrArray *list = g_ptr_array_new ();
+ gchar **retval = NULL;
+ gchar **search_path = NULL;
+ GRegex *matcher;
+ GError *error = NULL;
+ gchar *tmp1, *tmp2, *tmp3;
+
+ fs_plugin_search_path_init ();
+
+ tmp1 = g_strdup_printf ("(.+)-%s", type_suffix);
+ tmp2 = g_module_build_path ("", tmp1);
+ tmp3 = g_strconcat ("^", tmp2, NULL);
+ matcher = g_regex_new (tmp3, 0, 0, NULL);
+ g_free (tmp1);
+ g_free (tmp2);
+ g_free (tmp3);
+
+
+ for (search_path = search_paths; *search_path; search_path++)
+ {
+ GDir *dir = NULL;
+ const gchar *entry;
+
+ dir = g_dir_open (*search_path, 0, &error);
+ if (!dir)
+ {
+ GST_WARNING ("Could not open path %s to look for plugins: %s",
+ search_path, error ? error->message : "Unknown error");
+ g_clear_error (&error);
+ continue;
+ }
+
+ while ((entry = g_dir_read_name (dir)))
+ {
+ gchar **matches = NULL;
+
+ matches = g_regex_split (matcher, entry, 0);
+
+ if (matches && g_strv_length (matches) == 3)
+ {
+ gint i;
+ gboolean found = FALSE;
+
+ for (i = 0; i < list->len; i++)
+ {
+ if (!strcmp (matches[1], g_ptr_array_index (list, i)))
+ {
+ found = TRUE;
+ break;
+ }
+ }
+ if (!found)
+ g_ptr_array_add (list, g_strdup (matches[1]));
+ }
+
+ g_strfreev (matches);
+ }
+
+ g_dir_close (dir);
+ }
+
+ g_regex_unref (matcher);
+
+ if (list->len)
+ {
+ g_ptr_array_add (list, NULL);
+ retval = (gchar**) list->pdata;
+ g_ptr_array_free (list, FALSE);
+ }
+ else
+ {
+ g_ptr_array_free (list, TRUE);
+ }
+
+ return retval;
+}
diff --git a/gst-libs/gst/farsight/fs-plugin.h b/gst-libs/gst/farsight/fs-plugin.h
index 1051639..c405886 100644
--- a/gst-libs/gst/farsight/fs-plugin.h
+++ b/gst-libs/gst/farsight/fs-plugin.h
@@ -102,6 +102,8 @@ GObject *fs_plugin_create (const gchar *name,
GError **error,
const gchar *first_property_name, ...);
+gchar **fs_plugin_list_available (const gchar *type_suffix);
+
/**
* FS_INIT_PLUGIN:
* @type_register_func: A function that register a #GType and returns it
diff --git a/tests/check/transmitter/rawudp.c b/tests/check/transmitter/rawudp.c
index e620b93..fd1017d 100644
--- a/tests/check/transmitter/rawudp.c
+++ b/tests/check/transmitter/rawudp.c
@@ -26,6 +26,8 @@
#include <gst/farsight/fs-transmitter.h>
#include <gst/farsight/fs-conference-iface.h>
+#include <gst/farsight/fs-plugin.h>
+
#include <arpa/inet.h>
#include <netdb.h>
@@ -62,6 +64,22 @@ GST_START_TEST (test_rawudptransmitter_new)
FsTransmitter *trans;
GstElement *pipeline;
GstElement *trans_sink, *trans_src;
+ gchar **transmitters;
+ gint i;
+ gboolean found_it = FALSE;
+
+ transmitters = fs_plugin_list_available ("transmitter");
+ for (i=0; transmitters[i]; i++)
+ {
+ if (!strcmp ("rawudp", transmitters[i]))
+ {
+ found_it = TRUE;
+ break;
+ }
+ }
+ g_strfreev (transmitters);
+
+ ts_fail_unless (found_it, "Did not find rawudp transmitter");
trans = fs_transmitter_new ("rawudp", 2, &error);
--
1.5.6.5
More information about the farsight-commits
mailing list