babeltrace/mmap-align.h \
babeltrace/plugin/component-factory-internal.h \
babeltrace/plugin/component-internal.h \
+ babeltrace/plugin/component-class-internal.h \
+ babeltrace/plugin/plugin-internal.h \
babeltrace/plugin/filter-internal.h \
babeltrace/plugin/sink-internal.h \
babeltrace/plugin/source-internal.h \
--- /dev/null
+#ifndef BABELTRACE_PLUGIN_COMPONENT_CLASS_INTERNAL_H
+#define BABELTRACE_PLUGIN_COMPONENT_CLASS_INTERNAL_H
+
+/*
+ * BabelTrace - Component Class Internal
+ *
+ * Copyright 2015 Jérémie Galarneau <jeremie.galarneau@efficios.com>
+ *
+ * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#include <babeltrace/babeltrace-internal.h>
+#include <babeltrace/ref-internal.h>
+#include <babeltrace/plugin/component-factory-internal.h>
+#include <babeltrace/plugin/plugin-internal.h>
+
+struct bt_component_class {
+ struct bt_ref ref;
+ enum bt_component_type type;
+ GString *name;
+ struct bt_plugin *plugin;
+};
+
+BT_HIDDEN
+struct bt_component_class *bt_component_class_create(
+ enum bt_component_type type, const char *name,
+ struct bt_plugin *plugin);
+
+BT_HIDDEN
+void bt_component_class_get(struct bt_component_class *class);
+
+BT_HIDDEN
+void bt_component_class_put(struct bt_component_class *class);
+
+#endif /* BABELTRACE_PLUGIN_COMPONENT_CLASS_INTERNAL_H */
*/
#include <babeltrace/babeltrace-internal.h>
+#include <babeltrace/ref-internal.h>
#include <babeltrace/plugin/component-factory.h>
#include <babeltrace/plugin/component.h>
+#include <babeltrace/plugin/component-class-internal.h>
#include <babeltrace/plugin/plugin-system.h>
#include <babeltrace/plugin/plugin.h>
#include <glib.h>
-#include <gmodule.h>
-
-struct component_class {
- enum bt_component_type type;
- GString *name;
-};
-
-struct source_component_class {
- struct component_class parent;
- bt_component_source_init_cb init;
-
-};
-
-struct sink_component_class {
- struct component_class parent;
- bt_component_sink_init_cb init;
-};
-
-struct plugin {
- const char *name;
- const char *author;
- const char *license;
- bt_plugin_init_func init;
- bt_plugin_init_func exit;
- GModule *module;
- /** Array of pointers to struct component_class */
- GPtrArray *components;
-};
struct bt_component_factory {
/** Array of pointers to struct plugin */
GPtrArray *plugins;
+ /** Array of pointers to struct bt_component_class */
+ GPtrArray *components;
};
#endif /* BABELTRACE_PLUGIN_COMPONENT_FACTORY_INTERNAL_H */
*/
enum bt_component_factory_status {
/** General error. */
- BT_COMPONENT_FACTORY_STATUS_ERROR = -128,
+ BT_COMPONENT_FACTORY_STATUS_ERROR = -128,
+
+ /** Invalid plugin. */
+ BT_COMPONENT_FACTORY_STATUS_INVAL_PLUGIN = -6,
/** Invalid arguments. */
- /* -22 for compatibility with -EINVAL */
- BT_COMPONENT_FACTORY_STATUS_INVAL = -22,
+ BT_COMPONENT_FACTORY_STATUS_INVAL = -5,
/** Memory allocation failure. */
- /* -12 for compatibility with -ENOMEM */
- BT_COMPONENT_FACTORY_STATUS_NOMEM = -12,
+ BT_COMPONENT_FACTORY_STATUS_NOMEM = -4,
/** I/O error. */
- /* -5 for compatibility with -EIO */
- BT_COMPONENT_FACTORY_STATUS_IO = -5,
+ BT_COMPONENT_FACTORY_STATUS_IO = -3,
/** No such file or directory. */
- /* -2 for compatibility with -ENOENT */
- BT_COMPONENT_FACTORY_STATUS_NOENT = -2,
+ BT_COMPONENT_FACTORY_STATUS_NOENT = -2,
/** Operation not permitted. */
- /* -1 for compatibility with -EPERM */
- BT_COMPONENT_FACTORY_STATUS_PERM = -1,
+ BT_COMPONENT_FACTORY_STATUS_PERM = -1,
/** No error, okay. */
- BT_COMPONENT_FACTORY_STATUS_OK = 0,
+ BT_COMPONENT_FACTORY_STATUS_OK = 0,
};
struct bt_component_factory;
extern
struct bt_component_factory *bt_component_factory_create(void);
+/**
+ * Get the list of components registered to this factory.
+ */
+extern
+struct bt_object *bt_component_factory_get_components(
+ struct bt_component_factory *factory);
+
/**
* Recursively load and register Babeltrace plugins under a given path.
*
extern
enum bt_component_factory_status
bt_component_factory_register_source_component_class(
- struct bt_component_factory *factory, const char *name,
- bt_component_source_init_cb init);
+ struct bt_component_factory *factory, const char *name,
+ bt_component_source_init_cb init);
extern
enum bt_component_factory_status bt_component_factory_register_sink_component_class(
- struct bt_component_factory *factory, const char *name,
- bt_component_sink_init_cb init);
+ struct bt_component_factory *factory, const char *name,
+ bt_component_sink_init_cb init);
extern
void bt_component_factory_destroy(struct bt_component_factory *factory);
#include <babeltrace/babeltrace-internal.h>
#include <babeltrace/plugin/plugin-system.h>
#include <babeltrace/plugin/component.h>
-#include <babeltrace/ctf-writer/ref-internal.h>
+#include <babeltrace/plugin/component-class-internal.h>
+#include <babeltrace/ref-internal.h>
#include <glib.h>
#include <stdio.h>
struct bt_component {
- struct bt_ctf_ref ref_count;
+ struct bt_ref ref;
+ struct bt_component_class *class;
GString *name;
- enum bt_component_type type;
/** No ownership taken */
FILE *error_stream;
/** source, sink or filter destroy */
BT_HIDDEN
enum bt_component_status bt_component_init(struct bt_component *component,
- const char *name, enum bt_component_type component_type,
+ struct bt_component_class *class, const char *name,
bt_component_destroy_cb destroy);
#endif /* BABELTRACE_PLUGIN_COMPONENT_INTERNAL_H */
#include <babeltrace/babeltrace-internal.h>
#include <babeltrace/plugin/plugin-system.h>
-#include <babeltrace/ctf-writer/ref-internal.h>
+#include <babeltrace/ref-internal.h>
struct bt_notification_iterator {
- struct bt_ctf_ref ref_count;
+ struct bt_ref ref;
bt_notification_iterator_get_cb get;
bt_notification_iterator_next_cb next;
void *user_data;
#endif
struct bt_notification {
- struct bt_ctf_ref ref_count;
+ struct bt_ctf_ref ref;
enum bt_notification_type type;
};
--- /dev/null
+#ifndef BABELTRACE_PLUGIN_INTERNAL_H
+#define BABELTRACE_PLUGIN__INTERNAL_H
+
+/*
+ * BabelTrace - Plug-in Internal
+ *
+ * Copyright 2015 Jérémie Galarneau <jeremie.galarneau@efficios.com>
+ *
+ * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#include <babeltrace/babeltrace-internal.h>
+#include <babeltrace/ref-internal.h>
+#include <babeltrace/plugin/component.h>
+#include <babeltrace/plugin/plugin.h>
+#include <gmodule.h>
+
+/**
+ * Plug-ins are owned by bt_component_factory and the bt_component_class-es
+ * it provides. This means that its lifetime bound by either the component
+ * factory's, or the concrete components' lifetime which may be in use and which
+ * have hold a reference to their bt_component_class which, in turn, have a
+ * reference to their plugin.
+ *
+ * This ensures that a plugin's library is not closed while it is being used
+ * even if the bt_component_factory which created its components is destroyed.
+ */
+struct bt_plugin {
+ struct bt_ref ref;
+ const char *name;
+ const char *author;
+ const char *license;
+ bt_plugin_init_func init;
+ bt_plugin_exit_func exit;
+ GModule *module;
+};
+
+BT_HIDDEN
+struct bt_plugin *bt_plugin_create(GModule *module);
+
+BT_HIDDEN
+enum bt_component_status bt_plugin_register_component_classes(
+ struct bt_plugin *plugin, struct bt_component_factory *factory);
+
+BT_HIDDEN
+void bt_plugin_get(struct bt_plugin *plugin);
+
+BT_HIDDEN
+void bt_plugin_put(struct bt_plugin *plugin);
+
+#endif /* BABELTRACE_PLUGIN_COMPONENT_CLASS_INTERNAL_H */
#include <babeltrace/babeltrace-internal.h>
#include <babeltrace/plugin/component-internal.h>
+#include <babeltrace/plugin/component-class-internal.h>
#include <babeltrace/plugin/plugin-system.h>
+struct bt_component_sink_class {
+ struct bt_component_class parent;
+ bt_component_sink_init_cb init;
+};
+
struct bt_component_sink {
struct bt_component parent;
/**
* Allocate a sink component.
*
+ * @param class Component class
* @param name Component instance name (will be copied)
* @returns A sink component instance
*/
BT_HIDDEN
-extern struct bt_component *bt_component_sink_create(const char *name);
+extern struct bt_component *bt_component_sink_create(
+ struct bt_component_class *class, const char *name);
#endif /* BABELTRACE_PLUGIN_SINK_INTERNAL_H */
#include <babeltrace/babeltrace-internal.h>
#include <babeltrace/plugin/component-internal.h>
+#include <babeltrace/plugin/component-class-internal.h>
#include <babeltrace/plugin/plugin-system.h>
+struct bt_component_source_class {
+ struct bt_component_class parent;
+ bt_component_source_init_cb init;
+};
+
struct bt_component_source {
struct bt_component parent;
/**
* Allocate a source component.
*
+ * @param class Component class
* @param name Component instance name (will be copied)
* @returns A source component instance
*/
BT_HIDDEN
-extern struct bt_component *bt_component_source_create(const char *name);
+extern struct bt_component *bt_component_source_create(
+ struct bt_component_class *class, const char *name);
#endif /* BABELTRACE_PLUGIN_SOURCE_INTERNAL_H */
# Plug-in system library
libbabeltrace_plugin_la_SOURCES = \
component.c \
+ component-class.c \
component-factory.c \
+ plugin.c \
source.c \
sink.c \
iterator.c
--- /dev/null
+/*
+ * component-class.c
+ *
+ * Babeltrace Plugin Component Class
+ *
+ * Copyright 2015 Jérémie Galarneau <jeremie.galarneau@efficios.com>
+ *
+ * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#include <babeltrace/compiler.h>
+#include <babeltrace/plugin/component-class-internal.h>
+#include <glib.h>
+
+static
+void bt_component_class_destroy(struct bt_ref *ref)
+{
+ struct bt_component_class *class;
+
+ assert(ref);
+ class = container_of(ref, struct bt_component_class, ref);
+ if (class->name) {
+ g_string_free(class->name, TRUE);
+ }
+ bt_plugin_put(class->plugin);
+ g_free(class);
+}
+
+BT_HIDDEN
+struct bt_component_class *bt_component_class_create(
+ enum bt_component_type type, const char *name,
+ struct bt_plugin *plugin)
+{
+ struct bt_component_class *class;
+
+ class = g_new0(struct bt_component_class, 1);
+ if (!class) {
+ goto end;
+ }
+
+ bt_ref_init(&class->ref, bt_component_class_destroy);
+ class->type = type;
+ class->name = g_string_new(name);
+ if (!class->name) {
+ bt_component_class_put(class);
+ class = NULL;
+ goto end;
+ }
+ bt_plugin_get(plugin);
+ class->plugin = plugin;
+end:
+ return class;
+}
+
+BT_HIDDEN
+void bt_component_class_get(struct bt_component_class *class)
+{
+ if (!class) {
+ return;
+ }
+
+ bt_ref_get(&class->ref);
+}
+
+BT_HIDDEN
+void bt_component_class_put(struct bt_component_class *class)
+{
+ if (!class) {
+ return;
+ }
+
+ bt_ref_put(&class->ref);
+}
#include <unistd.h>
#include <stdlib.h>
#include <sys/stat.h>
+#include <gmodule.h>
#define NATIVE_PLUGIN_SUFFIX ".so"
#define NATIVE_PLUGIN_SUFFIX_LEN sizeof(NATIVE_PLUGIN_SUFFIX)
#define PLUGIN_SUFFIX_LEN max_t(size_t, sizeof(NATIVE_PLUGIN_SUFFIX), \
sizeof(LIBTOOL_PLUGIN_SUFFIX))
-static
-void component_destroy(gpointer data)
-{
- g_free(data);
-}
-
-static
-void plugin_destroy(gpointer data)
-{
- struct plugin *plugin = data;
-
- if (plugin->module && g_module_close(plugin->module)) {
- printf_error("Failed to close plugin");
- }
-
- if (plugin->components) {
- g_ptr_array_free(plugin->components, TRUE);
- }
-
- g_free(plugin);
-}
-
-static
-struct plugin *plugin_create(void)
-{
- struct plugin *plugin = g_new0(struct plugin, 1);
-
- if (!plugin) {
- goto end;
- }
-
- plugin->components = g_ptr_array_new_with_free_func(component_destroy);
- if (!plugin->components) {
- g_free(plugin);
- plugin = NULL;
- goto end;
- }
-end:
- return plugin;
-}
-
/* Allocate dirent as recommended by READDIR(3), NOTES on readdir_r */
static
struct dirent *alloc_dirent(const char *path)
return entry;
}
-static
-struct plugin *load_plugin(GModule *module)
-{
- return NULL;
-}
-
static
enum bt_component_factory_status
bt_component_factory_load_file(struct bt_component_factory *factory,
const char *path)
{
enum bt_component_factory_status ret = BT_COMPONENT_FACTORY_STATUS_OK;
+ enum bt_component_status component_status;
size_t path_len;
GModule *module;
- struct plugin *plugin;
+ struct bt_plugin *plugin;
if (!factory || !path) {
ret = BT_COMPONENT_FACTORY_STATUS_INVAL;
goto end;
}
- /* Check if the module defines the appropriate entry points */
- plugin = load_plugin(module);
+ /* Load plugin and make sure it defines the required entry points */
+ plugin = bt_plugin_create(module);
if (!plugin) {
- /* Not a Babeltrace plugin */
- ret = BT_COMPONENT_FACTORY_STATUS_INVAL;
+ ret = BT_COMPONENT_FACTORY_STATUS_INVAL_PLUGIN;
if (!g_module_close(module)) {
printf_error("Module close error: %s",
- g_module_error());
+ g_module_error());
+ }
+ goto end;
+ }
+
+ component_status = bt_plugin_register_component_classes(plugin,
+ factory);
+ if (component_status != BT_COMPONENT_STATUS_OK) {
+ switch (component_status) {
+ case BT_COMPONENT_STATUS_NOMEM:
+ ret = BT_COMPONENT_FACTORY_STATUS_NOMEM;
+ break;
+ default:
+ ret = BT_COMPONENT_FACTORY_STATUS_ERROR;
+ break;
}
+ bt_plugin_put(plugin);
+ plugin = NULL;
goto end;
}
+ g_ptr_array_add(factory->plugins, plugin);
end:
return ret;
}
return;
}
+ if (factory->plugins) {
+ g_ptr_array_free(factory->plugins, TRUE);
+ }
+ if (factory->components) {
+ g_ptr_array_free(factory->components, TRUE);
+ }
g_free(factory);
}
goto end;
}
- factory->plugins = g_ptr_array_new_with_free_func(plugin_destroy);
+ factory->plugins = g_ptr_array_new_with_free_func(
+ (GDestroyNotify) bt_plugin_put);
if (!factory->plugins) {
goto error;
}
+ factory->components = g_ptr_array_new_with_free_func(
+ (GDestroyNotify) bt_component_put);
+ if (!factory->components) {
+ goto error;
+ }
end:
return factory;
error:
#include <babeltrace/babeltrace-internal.h>
#include <babeltrace/compiler.h>
-static void bt_component_destroy(struct bt_ctf_ref *ref);
+static void bt_component_destroy(struct bt_ref *ref);
const char *bt_component_get_name(struct bt_component *component)
{
goto end;
}
- type = component->type;
+ type = component->class->type;
end:
return type;
}
return;
}
- bt_ctf_ref_get(&component->ref_count);
+ bt_ref_get(&component->ref);
}
void bt_component_put(struct bt_component *component)
return;
}
- bt_ctf_ref_put(&component->ref_count, bt_component_destroy);
+ bt_ref_put(&component->ref);
}
BT_HIDDEN
enum bt_component_status bt_component_init(struct bt_component *component,
- const char *name, enum bt_component_type component_type,
+ struct bt_component_class *class, const char *name,
bt_component_destroy_cb destroy)
{
enum bt_component_status ret = BT_COMPONENT_STATUS_OK;
- if (!component || !name || name[0] == '\0' || destroy) {
+ if (!component || !class || !name || name[0] == '\0' || destroy) {
ret = BT_COMPONENT_STATUS_INVAL;
goto end;
}
- bt_ctf_ref_init(&component->ref_count);
- component->type = component_type;
+ bt_ref_init(&component->ref, bt_component_destroy);
+ bt_component_class_get(class);
+ component->class = class;
component->name = g_string_new(name);
if (!component->name) {
ret = BT_COMPONENT_STATUS_NOMEM;
}
static
-void bt_component_destroy(struct bt_ctf_ref *ref)
+void bt_component_destroy(struct bt_ref *ref)
{
struct bt_component *component = NULL;
return;
}
- component = container_of(ref, struct bt_component, ref_count);
+ component = container_of(ref, struct bt_component, ref);
/**
* User data is destroyed first, followed by the concrete component
assert(component->destroy);
component->destroy(component);
+ bt_component_class_put(component->class);
}
#include <babeltrace/plugin/notification/iterator-internal.h>
static
-void bt_notification_iterator_destroy(struct bt_ctf_ref *ref)
+void bt_notification_iterator_destroy(struct bt_ref *ref)
{
struct bt_notification_iterator *iterator;
}
iterator = container_of(ref, struct bt_notification_iterator,
- ref_count);
+ ref);
assert(iterator->user_destroy || !iterator->user_data);
iterator->user_destroy(iterator);
g_free(iterator);
goto end;
}
- bt_ctf_ref_init(&iterator->ref_count);
+ bt_ref_init(&iterator->ref, bt_notification_iterator_destroy);
end:
return iterator;
}
return;
}
- bt_ctf_ref_get(&iterator->ref_count);
+ bt_ref_get(&iterator->ref);
}
void bt_notification_iterator_put(struct bt_notification_iterator *iterator)
return;
}
- bt_ctf_ref_put(&iterator->ref_count, bt_notification_iterator_destroy);
+ bt_ref_put(&iterator->ref);
}
enum bt_notification_iterator_status bt_notification_iterator_set_get_cb(
--- /dev/null
+/*
+ * plugin.c
+ *
+ * Babeltrace Plugin
+ *
+ * Copyright 2015 Jérémie Galarneau <jeremie.galarneau@efficios.com>
+ *
+ * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#include <babeltrace/compiler.h>
+#include <babeltrace/plugin/plugin-internal.h>
+#include <glib.h>
+
+static
+void bt_plugin_destroy(struct bt_ref *ref)
+{
+ struct bt_plugin *plugin;
+
+ assert(ref);
+ plugin = container_of(ref, struct bt_plugin, ref);
+ if (plugin->module) {
+ if (!g_module_close(plugin->module)) {
+ printf_error("Module close error: %s",
+ g_module_error());
+
+ }
+ }
+ g_free(plugin);
+}
+
+BT_HIDDEN
+struct bt_plugin *bt_plugin_create(GModule *module)
+{
+ struct bt_plugin *plugin;
+
+ plugin = g_new0(struct bt_plugin, 1);
+ if (!plugin) {
+ goto end;
+ }
+
+ bt_ref_init(&plugin->ref, bt_plugin_destroy);
+end:
+ return plugin;
+}
+
+BT_HIDDEN
+enum bt_component_status bt_plugin_register_component_classes(
+ struct bt_plugin *plugin, struct bt_component_factory *factory)
+{
+ 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);
+}
}
BT_HIDDEN
-struct bt_component *bt_component_sink_create(const char *name)
+struct bt_component *bt_component_sink_create(
+ struct bt_component_class *class, const char *name)
{
struct bt_component_sink *sink = NULL;
enum bt_component_status ret;
goto end;
}
- ret = bt_component_init(&sink->parent, name, BT_COMPONENT_TYPE_SINK,
+ ret = bt_component_init(&sink->parent, class, name,
bt_component_sink_destroy);
if (ret != BT_COMPONENT_STATUS_OK) {
g_free(sink);
}
BT_HIDDEN
-struct bt_component *bt_component_source_create(const char *name)
+struct bt_component *bt_component_source_create(
+ struct bt_component_class *class, const char *name)
{
struct bt_component_source *source = NULL;
enum bt_component_status ret;
goto end;
}
- ret = bt_component_init(&source->parent, name,
- BT_COMPONENT_TYPE_SOURCE, bt_component_source_destroy);
+ ret = bt_component_init(&source->parent, class, name,
+ bt_component_source_destroy);
if (ret != BT_COMPONENT_STATUS_OK) {
g_free(source);
source = NULL;