#include <babeltrace/compiler.h>
#include <babeltrace/ref.h>
#include <babeltrace/plugin/plugin-internal.h>
+#include <babeltrace/plugin/component-factory-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_REGISTER "__bt_plugin_register"
#define PLUGIN_SYMBOL_DESCRIPTION "__bt_plugin_description"
+DECLARE_PLUG_IN_SECTIONS;
+
static
void bt_plugin_destroy(struct bt_object *obj)
{
assert(obj);
plugin = container_of(obj, struct bt_plugin, base);
- if (plugin->exit) {
- plugin->exit();
- }
-
if (plugin->module) {
if (!g_module_close(plugin->module)) {
- printf_error("Module close error: %s",
+ printf_error("Module close error: %s\n",
g_module_error());
}
}
- g_string_free(plugin->path, TRUE);
+ if (plugin->path) {
+ g_string_free(plugin->path, TRUE);
+ }
g_free(plugin);
}
BT_HIDDEN
-struct bt_plugin *bt_plugin_create(GModule *module, const char *path)
+struct bt_plugin *bt_plugin_create_from_module(GModule *module,
+ const char *path)
{
struct bt_plugin *plugin = NULL;
gpointer symbol = NULL;
if (!g_module_symbol(module, PLUGIN_SYMBOL_NAME,
(gpointer *) &plugin->name)) {
- printf_error("Unable to resolve plugin symbol %s from %s",
+ printf_verbose("Unable to resolve plugin symbol %s from %s\n",
PLUGIN_SYMBOL_NAME, g_module_name(module));
goto error;
}
if (!g_module_symbol(module, PLUGIN_SYMBOL_LICENSE,
(gpointer *) &plugin->license)) {
- printf_error("Unable to resolve plugin symbol %s from %s",
+ printf_verbose("Unable to resolve plugin symbol %s from %s\n",
PLUGIN_SYMBOL_LICENSE, g_module_name(module));
goto error;
}
- 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));
+ if (!g_module_symbol(module, PLUGIN_SYMBOL_AUTHOR,
+ (gpointer *) &plugin->author)) {
+ printf_verbose("Unable to resolve plugin symbol %s from %s\n",
+ PLUGIN_SYMBOL_AUTHOR, g_module_name(module));
+ goto error;
+ }
+ if (!g_module_symbol(module, PLUGIN_SYMBOL_DESCRIPTION,
+ (gpointer *) &plugin->description)) {
+ printf_verbose("Unable to resolve plugin symbol %s from %s\n",
+ PLUGIN_SYMBOL_DESCRIPTION,
+ g_module_name(module));
+ goto error;
+ }
+ if (!g_module_symbol(module, PLUGIN_SYMBOL_REGISTER, &symbol)) {
+ printf_verbose("Unable to resolve plugin symbol %s from %s\n",
+ PLUGIN_SYMBOL_REGISTER, 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);
+ plugin->_register = *((bt_plugin_register_func *) symbol);
+ if (!plugin->_register) {
+ printf_verbose("NULL %s symbol target\n",
+ PLUGIN_SYMBOL_REGISTER);
goto error;
}
}
- /* Optional */
- if (g_module_symbol(module, PLUGIN_SYMBOL_EXIT,
- (gpointer *) &symbol)) {
- plugin->exit = *((bt_plugin_exit_func *) symbol);
+ return plugin;
+error:
+ BT_PUT(plugin);
+ return plugin;
+}
+
+BT_HIDDEN
+struct bt_plugin *bt_plugin_create_from_static(size_t i)
+{
+ struct bt_plugin *plugin = NULL;
+
+ plugin = g_new0(struct bt_plugin, 1);
+ if (!plugin) {
+ goto error;
}
- g_module_symbol(module, PLUGIN_SYMBOL_AUTHOR,
- (gpointer *) &plugin->author);
- g_module_symbol(module, PLUGIN_SYMBOL_DESCRIPTION,
- (gpointer *) &plugin->description);
+ bt_object_init(plugin, bt_plugin_destroy);
+ plugin->_register = (SECTION_BEGIN(__plugin_register_funcs))[i];
+ if (!plugin->_register) {
+ goto error;
+ }
+ plugin->name = (SECTION_BEGIN(__plugin_names))[i];
+ plugin->author = (SECTION_BEGIN(__plugin_authors))[i];
+ plugin->license = (SECTION_BEGIN(__plugin_licenses))[i];
+ plugin->description = (SECTION_BEGIN(__plugin_descriptions))[i];
return plugin;
error:
- BT_PUT(plugin);
+ BT_PUT(plugin);
return plugin;
}
struct bt_plugin *plugin, struct bt_component_factory *factory)
{
assert(plugin && factory);
- return plugin->init(factory);
+ return plugin->_register(factory);
}
const char *bt_plugin_get_name(struct bt_plugin *plugin)
const char *bt_plugin_get_path(struct bt_plugin *plugin)
{
- return plugin ? plugin->path->str : NULL;
+ return (plugin && plugin->path) ? plugin->path->str : NULL;
}
const char *bt_plugin_get_description(struct bt_plugin *plugin)