Strip babeltrace.c
[babeltrace.git] / plugins / plugin.c
index 3505677760659fc751a9c2b3855cbaddfe558d75..f3d23268f7c83f326de6bb12a0d907df7a27f6fc 100644 (file)
  */
 
 #include <babeltrace/compiler.h>
+#include <babeltrace/ref.h>
 #include <babeltrace/plugin/plugin-internal.h>
 #include <glib.h>
 
-#define PLUGIN_SYMBOL_NAME     "__bt_plugin_name"
-#define PLUGIN_SYMBOL_AUTHOR   "__bt_plugin_author"
-#define PLUGIN_SYMBOL_LICENSE  "__bt_plugin_license"
-#define PLUGIN_SYMBOL_INIT     "__bt_plugin_init"
-#define PLUGIN_SYMBOL_EXIT     "__bt_plugin_exit"
+#define PLUGIN_SYMBOL_NAME             "__bt_plugin_name"
+#define PLUGIN_SYMBOL_AUTHOR           "__bt_plugin_author"
+#define PLUGIN_SYMBOL_LICENSE          "__bt_plugin_license"
+#define PLUGIN_SYMBOL_INIT             "__bt_plugin_init"
+#define PLUGIN_SYMBOL_EXIT             "__bt_plugin_exit"
+#define PLUGIN_SYMBOL_DESCRIPTION      "__bt_plugin_description"
 
 static
-void bt_plugin_destroy(struct bt_ref *ref)
+void bt_plugin_destroy(struct bt_object *obj)
 {
        struct bt_plugin *plugin;
 
-       assert(ref);
-       plugin = container_of(ref, struct bt_plugin, ref);
+       assert(obj);
+       plugin = container_of(obj, struct bt_plugin, base);
+
        if (plugin->module) {
                if (!g_module_close(plugin->module)) {
-                       printf_error("Module close error: %s",
-                               g_module_error());
-
+                               printf_error("Module close error: %s",
+                                       g_module_error());
                }
        }
+
+       if (plugin->exit) {
+               plugin->exit();
+       }
+       g_string_free(plugin->path, TRUE);
        g_free(plugin);
 }
 
 BT_HIDDEN
-struct bt_plugin *bt_plugin_create(GModule *module)
+struct bt_plugin *bt_plugin_create(GModule *module, const char *path)
 {
        struct bt_plugin *plugin = NULL;
+       gpointer symbol = NULL;
 
-       if (!module) {
+       if (!module || !path) {
                goto error;
        }
 
@@ -67,38 +75,52 @@ struct bt_plugin *bt_plugin_create(GModule *module)
                goto error;
        }
 
-       bt_ref_init(&plugin->ref, bt_plugin_destroy);
+       bt_object_init(plugin, bt_plugin_destroy);
+       plugin->path = g_string_new(path);
+       if (!plugin->path) {
+               goto error;
+       }
+
        if (!g_module_symbol(module, PLUGIN_SYMBOL_NAME,
-               (gpointer *) &plugin->name))
-       {
+                       (gpointer *) &plugin->name)) {
                printf_error("Unable to resolve plugin symbol %s from %s",
-                       PLUGIN_SYMBOL_NAME, g_module_name(module));
+                               PLUGIN_SYMBOL_NAME, g_module_name(module));
                goto error;
        }
+
        if (!g_module_symbol(module, PLUGIN_SYMBOL_LICENSE,
-               (gpointer *) &plugin->license))
-       {
+                       (gpointer *) &plugin->license)) {
                printf_error("Unable to resolve plugin symbol %s from %s",
-                       PLUGIN_SYMBOL_LICENSE, g_module_name(module));
+                               PLUGIN_SYMBOL_LICENSE, g_module_name(module));
                goto error;
        }
-       if (!g_module_symbol(module, PLUGIN_SYMBOL_INIT,
-               (gpointer *) &plugin->init))
-       {
+       if (!g_module_symbol(module, PLUGIN_SYMBOL_INIT, &symbol)) {
                printf_error("Unable to resolve plugin symbol %s from %s",
-                       PLUGIN_SYMBOL_INIT, g_module_name(module));
+                               PLUGIN_SYMBOL_INIT, g_module_name(module));
                goto error;
+       } else {
+               plugin->init = *((bt_plugin_init_func *) symbol);
+               if (!plugin->init) {
+                       printf_error("NULL %s symbol target",
+                                       PLUGIN_SYMBOL_INIT);
+                       goto error;
+               }
        }
 
-       /* Optional symbols */
-       g_module_symbol(module, PLUGIN_SYMBOL_EXIT, (gpointer *) &plugin->exit);
+       /* Optional */
+       if (g_module_symbol(module, PLUGIN_SYMBOL_EXIT,
+                       (gpointer *) &symbol)) {
+               plugin->exit = *((bt_plugin_exit_func *) symbol);
+       }
        g_module_symbol(module, PLUGIN_SYMBOL_AUTHOR,
-               (gpointer *) &plugin->author);
+                       (gpointer *) &plugin->author);
+       g_module_symbol(module, PLUGIN_SYMBOL_DESCRIPTION,
+                       (gpointer *) &plugin->description);
 
        return plugin;
 error:
-       bt_plugin_put(plugin);
-       return NULL;
+        BT_PUT(plugin);
+       return plugin;
 }
 
 BT_HIDDEN
@@ -109,22 +131,27 @@ enum bt_component_status bt_plugin_register_component_classes(
        return plugin->init(factory);
 }
 
-BT_HIDDEN
-void bt_plugin_get(struct bt_plugin *plugin)
+const char *bt_plugin_get_name(struct bt_plugin *plugin)
 {
-       if (!plugin) {
-               return;
-       }
+       return plugin ? plugin->name : NULL;
+}
 
-       bt_ref_get(&plugin->ref);
+const char *bt_plugin_get_author(struct bt_plugin *plugin)
+{
+       return plugin ? plugin->author : NULL;
 }
 
-BT_HIDDEN
-void bt_plugin_put(struct bt_plugin *plugin)
+const char *bt_plugin_get_license(struct bt_plugin *plugin)
 {
-       if (!plugin) {
-               return;
-       }
+       return plugin ? plugin->license : NULL;
+}
+
+const char *bt_plugin_get_path(struct bt_plugin *plugin)
+{
+       return plugin ? plugin->path->str : NULL;
+}
 
-       bt_ref_put(&plugin->ref);
+const char *bt_plugin_get_description(struct bt_plugin *plugin)
+{
+       return plugin ? plugin->description : NULL;
 }
This page took 0.02521 seconds and 4 git commands to generate.