*/
#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"
+
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",
BT_HIDDEN
struct bt_plugin *bt_plugin_create(GModule *module)
{
- struct bt_plugin *plugin;
+ struct bt_plugin *plugin = NULL;
+
+ if (!module) {
+ goto error;
+ }
plugin = g_new0(struct bt_plugin, 1);
if (!plugin) {
- goto end;
+ goto error;
+ }
+
+ bt_object_init(plugin, bt_plugin_destroy);
+ if (!g_module_symbol(module, PLUGIN_SYMBOL_NAME,
+ (gpointer *) &plugin->name))
+ {
+ printf_error("Unable to resolve plugin symbol %s from %s",
+ PLUGIN_SYMBOL_NAME, g_module_name(module));
+ goto error;
}
- bt_ref_init(&plugin->ref, bt_plugin_destroy);
-end:
+ printf("Loaded plugin with name %s\n", plugin->name);
+ if (!g_module_symbol(module, PLUGIN_SYMBOL_LICENSE,
+ (gpointer *) &plugin->license))
+ {
+ printf_error("Unable to resolve plugin symbol %s from %s",
+ PLUGIN_SYMBOL_LICENSE, g_module_name(module));
+ goto error;
+ }
+ if (!g_module_symbol(module, PLUGIN_SYMBOL_INIT,
+ (gpointer *) &plugin->init))
+ {
+ printf_error("Unable to resolve plugin symbol %s from %s",
+ PLUGIN_SYMBOL_INIT, g_module_name(module));
+ goto error;
+ }
+
+ /* Optional symbols */
+ g_module_symbol(module, PLUGIN_SYMBOL_EXIT, (gpointer *) &plugin->exit);
+ g_module_symbol(module, PLUGIN_SYMBOL_AUTHOR,
+ (gpointer *) &plugin->author);
+
+ return plugin;
+error:
+ BT_PUT(plugin);
return plugin;
}
assert(plugin && factory);
return plugin->init(factory);
}
-
-BT_HIDDEN
-void bt_plugin_get(struct bt_plugin *plugin)
-{
- if (!plugin) {
- return;
- }
-
- bt_ref_get(&plugin->ref);
-}
-
-BT_HIDDEN
-void bt_plugin_put(struct bt_plugin *plugin)
-{
- if (!plugin) {
- return;
- }
-
- bt_ref_put(&plugin->ref);
-}