Add bt_plugin_find_component_class()
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Thu, 6 Apr 2017 20:19:57 +0000 (16:19 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Sun, 28 May 2017 16:57:41 +0000 (12:57 -0400)
This patch also renames bt_plugin_create_from_name() to bt_plugin_find()
which seems more intuitive. bt_plugin_find_component_class() simply
calls bt_plugin_find() and then gets one of its component classes.

Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
include/babeltrace/plugin/plugin.h
lib/plugin/plugin.c
tests/lib/test_plugin.c

index 1d172540806f5a76696b30b637381249757b9917..31baf57665d08fbda0cf5b916e46426f322f36fc 100644 (file)
@@ -51,7 +51,11 @@ enum bt_plugin_status {
        BT_PLUGIN_STATUS_NOMEM =        -4,
 };
 
-extern struct bt_plugin *bt_plugin_create_from_name(const char *plugin_name);
+extern struct bt_plugin *bt_plugin_find(const char *plugin_name);
+
+extern struct bt_component_class *bt_plugin_find_component_class(
+               const char *plugin_name, const char *component_class_name,
+               enum bt_component_class_type component_class_type);
 
 extern struct bt_plugin **bt_plugin_create_all_from_file(const char *path);
 
index 90f77cb5a7e7c475e9b82ba1b04ffe8211687c70..0651ae72f328c477c7a83cefa37f2ec741dfa784 100644 (file)
@@ -131,7 +131,7 @@ void free_plugins(struct bt_plugin **plugins) {
        }
 }
 
-struct bt_plugin *bt_plugin_create_from_name(const char *plugin_name)
+struct bt_plugin *bt_plugin_find(const char *plugin_name)
 {
        const char *system_plugin_dir;
        char *home_plugin_dir = NULL;
@@ -246,6 +246,30 @@ end:
        return plugin;
 }
 
+struct bt_component_class *bt_plugin_find_component_class(
+               const char *plugin_name, const char *comp_cls_name,
+               enum bt_component_class_type comp_cls_type)
+{
+       struct bt_plugin *plugin = NULL;
+       struct bt_component_class *comp_cls = NULL;
+
+       if (!plugin_name || !comp_cls_name) {
+               goto end;
+       }
+
+       plugin = bt_plugin_find(plugin_name);
+       if (!plugin) {
+               goto end;
+       }
+
+       comp_cls = bt_plugin_get_component_class_by_name_and_type(
+               plugin, comp_cls_name, comp_cls_type);
+
+end:
+       bt_put(plugin);
+       return comp_cls;
+}
+
 /* Allocate dirent as recommended by READDIR(3), NOTES on readdir_r */
 static
 struct dirent *alloc_dirent(const char *path)
index 1b576104c09339e7a3ca3b17d88413fbf22022e8..fdc16c5bbdb3b623141f2b853f37c0d5fb3a66de 100644 (file)
@@ -32,7 +32,7 @@
 #include "tap/tap.h"
 #include "common.h"
 
-#define NR_TESTS               51
+#define NR_TESTS               58
 #define NON_EXISTING_PATH      "/this/hopefully/does/not/exist/5bc75f8d-0dba-4043-a509-d7984b97e42b.so"
 
 /* Those symbols are written to by some test plugins */
@@ -217,15 +217,15 @@ static void test_sfs(const char *plugin_dir)
 
        diag("> putting the plugin object here");
        BT_PUT(plugin);
-       sink_component = bt_component_create(sink_comp_class, NULL, bt_value_null);
+       sink_component = bt_component_create(sink_comp_class, NULL, NULL);
        ok(sink_component, "bt_component_create() still works after the plugin object is destroyed");
        BT_PUT(sink_component);
        BT_PUT(source_comp_class);
-       sink_component = bt_component_create(sink_comp_class, NULL, bt_value_null);
+       sink_component = bt_component_create(sink_comp_class, NULL, NULL);
        ok(sink_component, "bt_component_create() still works after the source component class object is destroyed");
        BT_PUT(sink_component);
        BT_PUT(filter_comp_class);
-       sink_component = bt_component_create(sink_comp_class, NULL, bt_value_null);
+       sink_component = bt_component_create(sink_comp_class, NULL, NULL);
        ok(sink_component, "bt_component_create() still works after the filter component class object is destroyed");
        BT_PUT(sink_comp_class);
        BT_PUT(sink_component);
@@ -265,26 +265,49 @@ static void test_create_all_from_dir(const char *plugin_dir)
        free(plugins);
 }
 
-static void test_create_from_name(const char *plugin_dir)
+static void test_find(const char *plugin_dir)
 {
        struct bt_plugin *plugin;
+       struct bt_component_class *comp_cls_sink;
+       struct bt_component_class *comp_cls_source;
        char *plugin_path;
 
-       ok(!bt_plugin_create_from_name(NULL),
-               "bt_plugin_create_from_name() handles NULL");
-       ok(!bt_plugin_create_from_name(NON_EXISTING_PATH),
-               "bt_plugin_create_from_name() returns NULL with an unknown plugin name");
+       ok(!bt_plugin_find(NULL),
+               "bt_plugin_find() handles NULL");
+       ok(!bt_plugin_find(NON_EXISTING_PATH),
+               "bt_plugin_find() returns NULL with an unknown plugin name");
        plugin_path = malloc(PATH_MAX * 5);
        assert(plugin_path);
        sprintf(plugin_path, "%s:/ec1d09e5-696c-442e-b1c3-f9c6cf7f5958:::%s:8db46494-a398-466a-9649-c765ae077629:",
                NON_EXISTING_PATH, plugin_dir);
        setenv("BABELTRACE_PLUGIN_PATH", plugin_path, 1);
-       plugin = bt_plugin_create_from_name("test_minimal");
+       plugin = bt_plugin_find("test_minimal");
        ok(plugin,
-               "bt_plugin_create_from_name() succeeds with a plugin name it can find");
+               "bt_plugin_find() succeeds with a plugin name it can find");
        ok(strcmp(bt_plugin_get_author(plugin), "Janine Sutto") == 0,
-               "bt_plugin_create_from_name() finds the correct plugin for a given name");
+               "bt_plugin_find() finds the correct plugin for a given name");
        BT_PUT(plugin);
+       comp_cls_sink = bt_plugin_find_component_class(NULL, "sink",
+               BT_COMPONENT_CLASS_TYPE_SINK);
+       ok(!comp_cls_sink, "bt_plugin_find_component_class() handles NULL (plugin name)");
+       comp_cls_sink = bt_plugin_find_component_class("test_sfs", NULL,
+               BT_COMPONENT_CLASS_TYPE_SINK);
+       ok(!comp_cls_sink, "bt_plugin_find_component_class() handles NULL (component class name)");
+       comp_cls_sink = bt_plugin_find_component_class("test_sfs", "sink2",
+               BT_COMPONENT_CLASS_TYPE_SINK);
+       ok(!comp_cls_sink, "bt_plugin_find_component_class() fails with an unknown component class name");
+       comp_cls_sink = bt_plugin_find_component_class("test_sfs", "sink",
+               BT_COMPONENT_CLASS_TYPE_SINK);
+       ok(comp_cls_sink, "bt_plugin_find_component_class() succeeds with valid parameters");
+       ok(strcmp(bt_component_class_get_name(comp_cls_sink), "sink") == 0,
+               "bt_plugin_find_component_class() returns the appropriate component class (sink)");
+       comp_cls_source = bt_plugin_find_component_class("test_sfs", "source",
+               BT_COMPONENT_CLASS_TYPE_SOURCE);
+       ok(comp_cls_sink, "bt_plugin_find_component_class() succeeds with another component class name (same plugin)");
+       ok(strcmp(bt_component_class_get_name(comp_cls_source), "source") == 0,
+               "bt_plugin_find_component_class() returns the appropriate component class (source)");
+       BT_PUT(comp_cls_sink);
+       BT_PUT(comp_cls_source);
        free(plugin_path);
 }
 
@@ -305,7 +328,7 @@ int main(int argc, char **argv)
        test_minimal(plugin_dir);
        test_sfs(plugin_dir);
        test_create_all_from_dir(plugin_dir);
-       test_create_from_name(plugin_dir);
+       test_find(plugin_dir);
        ret = exit_status();
 end:
        return ret;
This page took 0.028751 seconds and 4 git commands to generate.