From: Philippe Proulx Date: Wed, 24 Feb 2016 06:23:56 +0000 (-0500) Subject: Move plugin system sources to lib/plugin-system X-Git-Tag: v2.0.0-pre1~832 X-Git-Url: http://git.efficios.com/?a=commitdiff_plain;h=3b37d46561d6c6edba3b729f48a0f72699dcdc20;hp=7f26a816352f7e5645a395e5e09baeb5629e3391;p=babeltrace.git Move plugin system sources to lib/plugin-system Signed-off-by: Jérémie Galarneau --- diff --git a/configure.ac b/configure.ac index d5aa005b..c4045cd7 100644 --- a/configure.ac +++ b/configure.ac @@ -357,6 +357,7 @@ AC_CONFIG_FILES([ doc/images/Makefile lib/Makefile lib/prio_heap/Makefile + lib/plugin-system/Makefile include/Makefile bindings/Makefile bindings/python/Makefile diff --git a/converter/Makefile.am b/converter/Makefile.am index 789ff58c..b7e12645 100644 --- a/converter/Makefile.am +++ b/converter/Makefile.am @@ -17,8 +17,7 @@ babeltrace_LDADD = \ $(top_builddir)/formats/ctf-text/libbabeltrace-ctf-text.la \ $(top_builddir)/formats/ctf-metadata/libbabeltrace-ctf-metadata.la \ $(top_builddir)/formats/bt-dummy/libbabeltrace-dummy.la \ - $(top_builddir)/formats/lttng-live/libbabeltrace-lttng-live.la \ - $(top_builddir)/plugins/libbabeltrace-plugin.la + $(top_builddir)/formats/lttng-live/libbabeltrace-lttng-live.la if ENABLE_DEBUG_INFO babeltrace_LDADD += $(top_builddir)/lib/libdebug-info.la diff --git a/lib/Makefile.am b/lib/Makefile.am index 8096d789..9e14ea51 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -1,4 +1,4 @@ -SUBDIRS = prio_heap . +SUBDIRS = prio_heap plugin-system . AM_CFLAGS = $(PACKAGE_CFLAGS) -I$(top_srcdir)/include @@ -30,4 +30,5 @@ endif libbabeltrace_la_LIBADD = \ prio_heap/libprio_heap.la \ $(top_builddir)/types/libbabeltrace_types.la \ - $(top_builddir)/compat/libcompat.la + $(top_builddir)/compat/libcompat.la \ + plugin-system/libplugin-system.la diff --git a/lib/plugin-system/Makefile.am b/lib/plugin-system/Makefile.am new file mode 100644 index 00000000..9fa9d933 --- /dev/null +++ b/lib/plugin-system/Makefile.am @@ -0,0 +1,13 @@ +AM_CFLAGS = $(PACKAGE_CFLAGS) -I$(top_srcdir)/include + +noinst_LTLIBRARIES = libplugin-system.la + +# Plug-in system library +libplugin_system_la_SOURCES = \ + component.c \ + component-class.c \ + component-factory.c \ + plugin.c \ + source.c \ + sink.c \ + iterator.c diff --git a/lib/plugin-system/component-class.c b/lib/plugin-system/component-class.c new file mode 100644 index 00000000..e0e2e0bf --- /dev/null +++ b/lib/plugin-system/component-class.c @@ -0,0 +1,103 @@ +/* + * component-class.c + * + * Babeltrace Plugin Component Class + * + * Copyright 2015 Jérémie Galarneau + * + * Author: Jérémie Galarneau + * + * 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 +#include +#include +#include + +static +void bt_component_class_destroy(struct bt_object *obj) +{ + struct bt_component_class *class; + + assert(obj); + class = container_of(obj, struct bt_component_class, base); + if (class->name) { + g_string_free(class->name, TRUE); + } + if (class->description) { + g_string_free(class->description, TRUE); + } + + bt_put(class->plugin); + g_free(class); +} + +BT_HIDDEN +struct bt_component_class *bt_component_class_create( + enum bt_component_type type, const char *name, + const char *description, struct bt_plugin *plugin) +{ + struct bt_component_class *class; + + class = g_new0(struct bt_component_class, 1); + if (!class) { + goto end; + } + + bt_object_init(class, bt_component_class_destroy); + class->type = type; + class->name = g_string_new(name); + class->description = g_string_new(description); + if (!class->name || !class->description) { + BT_PUT(class); + goto end; + } + + class->plugin = bt_get(plugin); +end: + return class; +} + +const char *bt_component_class_get_name( + struct bt_component_class *component_class) +{ + return component_class ? component_class->name->str : NULL; +} + +enum bt_component_type bt_component_class_get_type( + struct bt_component_class *component_class) +{ + return component_class ? component_class->type : + BT_COMPONENT_TYPE_UNKNOWN; +} + +struct bt_plugin *bt_component_class_get_plugin( + struct bt_component_class *component_class) +{ + return component_class ? bt_get(component_class->plugin) : + NULL; +} + +const char *bt_component_class_get_description( + struct bt_component_class *component_class) +{ + return component_class ? component_class->description->str : NULL; +} + diff --git a/lib/plugin-system/component-factory.c b/lib/plugin-system/component-factory.c new file mode 100644 index 00000000..65840d4c --- /dev/null +++ b/lib/plugin-system/component-factory.c @@ -0,0 +1,420 @@ +/* + * component-factory.c + * + * Babeltrace Plugin Component Factory + * + * Copyright 2015 Jérémie Galarneau + * + * Author: Jérémie Galarneau + * + * 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 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define NATIVE_PLUGIN_SUFFIX ".so" +#define NATIVE_PLUGIN_SUFFIX_LEN sizeof(NATIVE_PLUGIN_SUFFIX) +#define LIBTOOL_PLUGIN_SUFFIX ".la" +#define LIBTOOL_PLUGIN_SUFFIX_LEN sizeof(LIBTOOL_PLUGIN_SUFFIX) +#define PLUGIN_SUFFIX_LEN max_t(size_t, sizeof(NATIVE_PLUGIN_SUFFIX), \ + sizeof(LIBTOOL_PLUGIN_SUFFIX)) + +/* Allocate dirent as recommended by READDIR(3), NOTES on readdir_r */ +static +struct dirent *alloc_dirent(const char *path) +{ + size_t len; + long name_max; + struct dirent *entry; + + name_max = pathconf(path, _PC_NAME_MAX); + if (name_max == -1) { + name_max = PATH_MAX; + } + len = offsetof(struct dirent, d_name) + name_max + 1; + entry = zmalloc(len); + return entry; +} + +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 bt_plugin *plugin; + bool is_libtool_wrapper = false, is_shared_object = false; + + if (!factory || !path) { + ret = BT_COMPONENT_FACTORY_STATUS_INVAL; + goto end; + } + + path_len = strlen(path); + if (path_len <= PLUGIN_SUFFIX_LEN) { + ret = BT_COMPONENT_FACTORY_STATUS_INVAL; + goto end; + } + + path_len++; + /* + * Check if the file ends with a known plugin file type suffix (i.e. .so + * or .la on Linux). + */ + is_libtool_wrapper = !strncmp(LIBTOOL_PLUGIN_SUFFIX, + path + path_len - LIBTOOL_PLUGIN_SUFFIX_LEN, + LIBTOOL_PLUGIN_SUFFIX_LEN); + is_shared_object = !strncmp(NATIVE_PLUGIN_SUFFIX, + path + path_len - NATIVE_PLUGIN_SUFFIX_LEN, + NATIVE_PLUGIN_SUFFIX_LEN); + if (!is_shared_object && !is_libtool_wrapper) { + /* Name indicates that this is not a plugin file. */ + ret = BT_COMPONENT_FACTORY_STATUS_INVAL; + goto end; + } + + module = g_module_open(path, 0); + if (!module) { + printf_error("Module open error: %s", g_module_error()); + ret = BT_COMPONENT_FACTORY_STATUS_ERROR; + goto end; + } + + /* Load plugin and make sure it defines the required entry points */ + plugin = bt_plugin_create(module, path); + if (!plugin) { + ret = BT_COMPONENT_FACTORY_STATUS_INVAL_PLUGIN; + if (!g_module_close(module)) { + printf_error("Module close error: %s", + g_module_error()); + } + goto end; + } + + factory->current_plugin = plugin; + component_status = bt_plugin_register_component_classes(plugin, + factory); + factory->current_plugin = NULL; + 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_PUT(plugin); + goto end; + } +end: + return ret; +} + +static +enum bt_component_factory_status +bt_component_factory_load_dir_recursive(struct bt_component_factory *factory, + const char *path) +{ + DIR *directory = NULL; + struct dirent *entry = NULL, *result = NULL; + char *file_path = NULL; + size_t path_len = strlen(path); + enum bt_component_factory_status ret = BT_COMPONENT_FACTORY_STATUS_OK; + + if (path_len >= PATH_MAX) { + ret = BT_COMPONENT_FACTORY_STATUS_INVAL; + goto end; + } + + entry = alloc_dirent(path); + if (!entry) { + ret = BT_COMPONENT_FACTORY_STATUS_NOMEM; + goto end; + } + + file_path = zmalloc(PATH_MAX); + if (!file_path) { + ret = BT_COMPONENT_FACTORY_STATUS_NOMEM; + goto end; + } + + strncpy(file_path, path, path_len); + /* Append a trailing '/' to the path */ + if (file_path[path_len - 1] != '/') { + file_path[path_len++] = '/'; + } + + directory = opendir(file_path); + if (!directory) { + perror("Failed to open plug-in directory"); + ret = BT_COMPONENT_FACTORY_STATUS_ERROR; + goto end; + } + + /* Recursively walk directory */ + while (!readdir_r(directory, entry, &result) && result) { + struct stat st; + int stat_ret; + size_t file_name_len; + + if (result->d_name[0] == '.') { + /* Skip hidden files, . and .. */ + continue; + } + + file_name_len = strlen(result->d_name); + + if (path_len + file_name_len >= PATH_MAX) { + continue; + } + + strncpy(file_path + path_len, result->d_name, file_name_len); + file_path[path_len + file_name_len] = '\0'; + + stat_ret = stat(file_path, &st); + if (stat_ret < 0) { + /* Continue to next file / directory. */ + printf_perror("Failed to stat() plugin file"); + continue; + } + + if (S_ISDIR(st.st_mode)) { + ret = bt_component_factory_load_dir_recursive(factory, + file_path); + if (ret != BT_COMPONENT_FACTORY_STATUS_OK) { + goto end; + } + } else if (S_ISREG(st.st_mode)) { + bt_component_factory_load_file(factory, file_path); + } + } +end: + if (directory) { + if (closedir(directory)) { + /* + * We don't want to override the error since there is + * nothing could do. + */ + perror("Failed to close plug-in directory"); + } + } + free(entry); + free(file_path); + return ret; +} + +static +void bt_component_factory_destroy(struct bt_object *obj) +{ + struct bt_component_factory *factory = NULL; + + assert(obj); + factory = container_of(obj, struct bt_component_factory, base); + + if (factory->component_classes) { + g_ptr_array_free(factory->component_classes, TRUE); + } + g_free(factory); +} + +struct bt_component_factory *bt_component_factory_create(void) +{ + struct bt_component_factory *factory; + + factory = g_new0(struct bt_component_factory, 1); + if (!factory) { + goto end; + } + + bt_object_init(factory, bt_component_factory_destroy); + factory->component_classes = g_ptr_array_new_with_free_func( + (GDestroyNotify) bt_put); + if (!factory->component_classes) { + goto error; + } +end: + return factory; +error: + BT_PUT(factory); + return factory; +} + +int bt_component_factory_get_component_class_count( + struct bt_component_factory *factory) +{ + return factory ? factory->component_classes->len : -1; +} + +struct bt_component_class *bt_component_factory_get_component_class_index( + struct bt_component_factory *factory, int index) +{ + struct bt_component_class *component_class = NULL; + + if (!factory || index < 0 || index >= factory->component_classes->len) { + goto end; + } + + component_class = bt_get(g_ptr_array_index( + factory->component_classes, index)); +end: + return component_class; +} + +struct bt_component_class *bt_component_factory_get_component_class( + struct bt_component_factory *factory, + const char *plugin_name, enum bt_component_type type, + const char *component_name) +{ + size_t i; + struct bt_component_class *component_class = NULL; + + if (!factory || (!plugin_name && !component_name && + type == BT_COMPONENT_TYPE_UNKNOWN)) { + /* At least one criterion must be provided. */ + goto no_match; + } + + for (i = 0; i < factory->component_classes->len; i++) { + struct bt_plugin *plugin = NULL; + + component_class = g_ptr_array_index(factory->component_classes, + i); + plugin = bt_component_class_get_plugin(component_class); + assert(plugin); + + if (type != BT_COMPONENT_TYPE_UNKNOWN) { + if (type != bt_component_class_get_type( + component_class)) { + continue; + } + } + + if (plugin_name) { + const char *cur_plugin_name = bt_plugin_get_name( + plugin); + + assert(cur_plugin_name); + if (strcmp(plugin_name, cur_plugin_name)) { + continue; + } + } + + if (component_name) { + const char *cur_cc_name = bt_component_class_get_name( + component_class); + + assert(cur_cc_name); + if (strcmp(component_name, cur_cc_name)) { + continue; + } + } + + /* All criteria met. */ + goto match; + } + +no_match: + return NULL; +match: + return bt_get(component_class); +} + +enum bt_component_factory_status bt_component_factory_load( + struct bt_component_factory *factory, const char *path) +{ + enum bt_component_factory_status ret = BT_COMPONENT_FACTORY_STATUS_OK; + + if (!factory || !path) { + ret = BT_COMPONENT_FACTORY_STATUS_INVAL; + goto end; + } + + if (!g_file_test(path, G_FILE_TEST_EXISTS)) { + ret = BT_COMPONENT_FACTORY_STATUS_NOENT; + goto end; + } + + if (g_file_test(path, G_FILE_TEST_IS_DIR)) { + ret = bt_component_factory_load_dir_recursive(factory, path); + } else if (g_file_test(path, G_FILE_TEST_IS_REGULAR) || + g_file_test(path, G_FILE_TEST_IS_SYMLINK)) { + ret = bt_component_factory_load_file(factory, path); + } else { + ret = BT_COMPONENT_FACTORY_STATUS_INVAL; + goto end; + } +end: + return ret; +} + +static +enum bt_component_factory_status +add_component_class(struct bt_component_factory *factory, const char *name, + const char *description, bt_component_init_cb init, + enum bt_component_type type) +{ + struct bt_component_class *class; + enum bt_component_factory_status ret = BT_COMPONENT_FACTORY_STATUS_OK; + + if (!factory || !name || !init) { + ret = BT_COMPONENT_FACTORY_STATUS_INVAL; + goto end; + } + + class = bt_component_class_create(type, name, description, + factory->current_plugin); + g_ptr_array_add(factory->component_classes, class); +end: + return ret; +} + +enum bt_component_factory_status +bt_component_factory_register_source_component_class( + struct bt_component_factory *factory, const char *name, + const char *description, bt_component_init_cb init) +{ + return add_component_class(factory, name, description, init, + BT_COMPONENT_TYPE_SOURCE); +} + +enum bt_component_factory_status +bt_component_factory_register_sink_component_class( + struct bt_component_factory *factory, const char *name, + const char *description, bt_component_init_cb init) +{ + return add_component_class(factory, name, description, init, + BT_COMPONENT_TYPE_SINK); +} diff --git a/lib/plugin-system/component.c b/lib/plugin-system/component.c new file mode 100644 index 00000000..5cfbbf0e --- /dev/null +++ b/lib/plugin-system/component.c @@ -0,0 +1,212 @@ +/* + * component.c + * + * Babeltrace Plugin Component + * + * Copyright 2015 Jérémie Galarneau + * + * Author: Jérémie Galarneau + * + * 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 +#include +#include +#include +#include +#include +#include + +static +struct bt_component * (* const component_create_funcs[])( + struct bt_component_class *, struct bt_value *) = { + [BT_COMPONENT_TYPE_SOURCE] = bt_component_source_create, + [BT_COMPONENT_TYPE_SINK] = bt_component_sink_create, +}; + +static +enum bt_component_status (* const component_validation_funcs[])( + struct bt_component *) = { + [BT_COMPONENT_TYPE_SOURCE] = bt_component_source_validate, + [BT_COMPONENT_TYPE_SINK] = bt_component_sink_validate, +}; + +static +void bt_component_destroy(struct bt_object *obj) +{ + struct bt_component *component = NULL; + struct bt_component_class *component_class = NULL; + + if (!obj) { + return; + } + + component = container_of(obj, struct bt_component, base); + + assert(component->destroy); + component_class = component->class; + + /* + * User data is destroyed first, followed by the concrete component + * instance. + */ + if (component->user_destroy) { + component->user_destroy(component->user_data); + } + + component->destroy(component); + g_string_free(component->name, TRUE); + bt_put(component_class); + g_free(component); +} + +BT_HIDDEN +enum bt_component_status bt_component_init(struct bt_component *component, + bt_component_destroy_cb destroy) +{ + enum bt_component_status ret = BT_COMPONENT_STATUS_OK; + + if (!component || !destroy) { + ret = BT_COMPONENT_STATUS_INVAL; + goto end; + } + + component->destroy = destroy; +end: + return ret; +} + +BT_HIDDEN +enum bt_component_type bt_component_get_type(struct bt_component *component) +{ + return component ? component->class->type : BT_COMPONENT_TYPE_UNKNOWN; +} + +struct bt_component *bt_component_create( + struct bt_component_class *component_class, const char *name, + struct bt_value *params) +{ + int ret; + struct bt_component *component = NULL; + enum bt_component_type type; + + if (!component_class) { + goto end; + } + + type = bt_component_class_get_type(component_class); + if (type <= BT_COMPONENT_TYPE_UNKNOWN || + type >= BT_COMPONENT_TYPE_FILTER) { + /* Filter components are not supported yet. */ + goto end; + } + + component = component_create_funcs[type](component_class, params); + if (!component) { + goto end; + } + + bt_object_init(component, bt_component_destroy); + component->class = bt_get(component_class); + component->name = g_string_new(name); + if (component->name) { + BT_PUT(component); + goto end; + } + + component_class->init(component, params); + ret = component_validation_funcs[type](component); + if (ret) { + BT_PUT(component); + goto end; + } +end: + return component; +} + +const char *bt_component_get_name(struct bt_component *component) +{ + const char *ret = NULL; + + if (!component) { + goto end; + } + + ret = component->name->str; +end: + return ret; +} + +enum bt_component_status bt_component_set_name(struct bt_component *component, + const char *name) +{ + enum bt_component_status ret = BT_COMPONENT_STATUS_OK; + + if (!component || !name || name[0] == '\0') { + ret = BT_COMPONENT_STATUS_INVAL; + goto end; + } + + g_string_assign(component->name, name); +end: + return ret; +} + +struct bt_component_class *bt_component_get_class( + struct bt_component *component) +{ + return component ? bt_get(component->class) : NULL; +} + +enum bt_component_status bt_component_set_error_stream( + struct bt_component *component, FILE *stream) +{ + enum bt_component_status ret = BT_COMPONENT_STATUS_OK; + + if (!component) { + ret = BT_COMPONENT_STATUS_INVAL; + goto end; + } + + component->error_stream = stream; +end: + return ret; +} + +void *bt_component_get_private_data(struct bt_component *component) +{ + return component ? component->user_data : NULL; +} + +enum bt_component_status +bt_component_set_private_data(struct bt_component *component, + void *data) +{ + enum bt_component_status ret = BT_COMPONENT_STATUS_OK; + + if (!component) { + ret = BT_COMPONENT_STATUS_INVAL; + goto end; + } + + component->user_data = data; +end: + return ret; +} diff --git a/lib/plugin-system/iterator.c b/lib/plugin-system/iterator.c new file mode 100644 index 00000000..b2f79f20 --- /dev/null +++ b/lib/plugin-system/iterator.c @@ -0,0 +1,100 @@ +/* + * iterator.c + * + * Babeltrace Notification Iterator + * + * Copyright 2015 Jérémie Galarneau + * + * Author: Jérémie Galarneau + * + * 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 +#include +#include +#include +#include +#include + +static +void bt_notification_iterator_destroy(struct bt_object *obj) +{ + struct bt_notification_iterator *iterator; + + assert(obj); + iterator = container_of(obj, struct bt_notification_iterator, + base); + assert(iterator->user_destroy || !iterator->user_data); + iterator->user_destroy(iterator); + g_free(iterator); +} + +BT_HIDDEN +struct bt_notification_iterator *bt_notification_iterator_create( + struct bt_component *component) +{ + struct bt_notification_iterator *iterator = NULL; + + if (!component || + bt_component_get_type(component) != BT_COMPONENT_TYPE_SOURCE) { + goto end; + } + + iterator = g_new0(struct bt_notification_iterator, 1); + if (!iterator) { + goto end; + } + + bt_object_init(iterator, bt_notification_iterator_destroy); +end: + return iterator; +} + +BT_HIDDEN +enum bt_notification_iterator_status bt_notification_iterator_validate( + struct bt_notification_iterator *iterator) +{ + enum bt_notification_iterator_status ret = + BT_NOTIFICATION_ITERATOR_STATUS_OK; + + if (!iterator || !iterator->get || !iterator->next) { + ret = BT_NOTIFICATION_ITERATOR_STATUS_INVAL; + goto end; + } +end: + return ret; +} + +enum bt_notification_iterator_status bt_notification_iterator_set_get_cb( + struct bt_notification_iterator *iterator, + bt_notification_iterator_get_cb get) +{ + enum bt_notification_iterator_status ret = + BT_NOTIFICATION_ITERATOR_STATUS_OK; + + if (!iterator || !get) { + ret = BT_NOTIFICATION_ITERATOR_STATUS_INVAL; + goto end; + } + + +end: + return ret; +} diff --git a/lib/plugin-system/plugin.c b/lib/plugin-system/plugin.c new file mode 100644 index 00000000..f3d23268 --- /dev/null +++ b/lib/plugin-system/plugin.c @@ -0,0 +1,157 @@ +/* + * plugin.c + * + * Babeltrace Plugin + * + * Copyright 2015 Jérémie Galarneau + * + * Author: Jérémie Galarneau + * + * 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 +#include +#include +#include + +#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_object *obj) +{ + struct bt_plugin *plugin; + + 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()); + } + } + + if (plugin->exit) { + plugin->exit(); + } + 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 *plugin = NULL; + gpointer symbol = NULL; + + if (!module || !path) { + goto error; + } + + plugin = g_new0(struct bt_plugin, 1); + if (!plugin) { + goto error; + } + + 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)) { + printf_error("Unable to resolve plugin symbol %s from %s", + 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", + 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)); + 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 */ + 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); + g_module_symbol(module, PLUGIN_SYMBOL_DESCRIPTION, + (gpointer *) &plugin->description); + + return plugin; +error: + BT_PUT(plugin); + 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); +} + +const char *bt_plugin_get_name(struct bt_plugin *plugin) +{ + return plugin ? plugin->name : NULL; +} + +const char *bt_plugin_get_author(struct bt_plugin *plugin) +{ + return plugin ? plugin->author : NULL; +} + +const char *bt_plugin_get_license(struct bt_plugin *plugin) +{ + return plugin ? plugin->license : NULL; +} + +const char *bt_plugin_get_path(struct bt_plugin *plugin) +{ + return plugin ? plugin->path->str : NULL; +} + +const char *bt_plugin_get_description(struct bt_plugin *plugin) +{ + return plugin ? plugin->description : NULL; +} diff --git a/lib/plugin-system/sink.c b/lib/plugin-system/sink.c new file mode 100644 index 00000000..81f6cba6 --- /dev/null +++ b/lib/plugin-system/sink.c @@ -0,0 +1,89 @@ +/* + * sink.c + * + * Babeltrace Sink Component + * + * Copyright 2015 Jérémie Galarneau + * + * Author: Jérémie Galarneau + * + * 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 +#include +#include + +static +void bt_component_sink_destroy(struct bt_component *component) +{ + return; +} + +BT_HIDDEN +enum bt_component_status bt_component_sink_validate( + struct bt_component *component) +{ + return BT_COMPONENT_STATUS_OK; +} + +BT_HIDDEN +struct bt_component *bt_component_sink_create( + struct bt_component_class *class, struct bt_value *params) +{ + struct bt_component_sink *sink = NULL; + enum bt_component_status ret; + + sink = g_new0(struct bt_component_sink, 1); + if (!sink) { + goto end; + } + + ret = bt_component_init(&sink->parent, bt_component_sink_destroy); + if (ret != BT_COMPONENT_STATUS_OK) { + BT_PUT(sink); + goto end; + } +end: + return sink ? &sink->parent : NULL; +} + +enum bt_component_status bt_component_sink_handle_notification( + struct bt_component *component, + struct bt_notification *notification) +{ + enum bt_component_status ret = BT_COMPONENT_STATUS_OK; + struct bt_component_sink *sink = NULL; + + if (!component || !notification) { + ret = BT_COMPONENT_STATUS_INVAL; + goto end; + } + + if (bt_component_get_type(component) != BT_COMPONENT_TYPE_SINK) { + ret = BT_COMPONENT_STATUS_UNSUPPORTED; + goto end; + } + + sink = container_of(component, struct bt_component_sink, parent); + assert(sink->handle_notification); + ret = sink->handle_notification(component, notification); +end: + return ret; +} diff --git a/lib/plugin-system/source.c b/lib/plugin-system/source.c new file mode 100644 index 00000000..ed3b1642 --- /dev/null +++ b/lib/plugin-system/source.c @@ -0,0 +1,107 @@ +/* + * source.c + * + * Babeltrace Source Component + * + * Copyright 2015 Jérémie Galarneau + * + * Author: Jérémie Galarneau + * + * 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 +#include +#include +#include +#include +#include + +static +void bt_component_source_destroy(struct bt_component *component) +{ + return; +} + +BT_HIDDEN +enum bt_component_status bt_component_source_validate( + struct bt_component *component) +{ + return BT_COMPONENT_STATUS_OK; +} + +BT_HIDDEN +struct bt_component *bt_component_source_create( + struct bt_component_class *class, struct bt_value *params) +{ + struct bt_component_source *source = NULL; + enum bt_component_status ret; + + source = g_new0(struct bt_component_source, 1); + if (!source) { + goto end; + } + + ret = bt_component_init(&source->parent, bt_component_source_destroy); + if (ret != BT_COMPONENT_STATUS_OK) { + BT_PUT(source); + goto end; + } +end: + return source ? &source->parent : NULL; +} + +struct bt_notification_iterator *bt_component_source_create_iterator( + struct bt_component *component) +{ + enum bt_component_status ret_component; + enum bt_notification_iterator_status ret_iterator; + struct bt_component_source *source; + struct bt_notification_iterator *iterator = NULL; + + if (!component) { + goto end; + } + + if (bt_component_get_type(component) != BT_COMPONENT_TYPE_SOURCE) { + goto end; + } + + iterator = bt_notification_iterator_create(component); + if (!iterator) { + goto end; + } + + source = container_of(component, struct bt_component_source, parent); + assert(source->init_iterator); + ret_component = source->init_iterator(component, iterator); + if (ret_component != BT_COMPONENT_STATUS_OK) { + goto error; + } + + ret_iterator = bt_notification_iterator_validate(iterator); + if (ret_iterator != BT_NOTIFICATION_ITERATOR_STATUS_OK) { + goto error; + } +end: + return iterator; +error: + BT_PUT(iterator); + return iterator; +} diff --git a/plugins/Makefile.am b/plugins/Makefile.am index 28bd175d..41568098 100644 --- a/plugins/Makefile.am +++ b/plugins/Makefile.am @@ -1,22 +1 @@ -AM_CFLAGS = $(PACKAGE_CFLAGS) -I$(top_srcdir)/include - -SUBDIRS = . ctf text - -lib_LTLIBRARIES = libbabeltrace-plugin.la - -# Plug-in system library -libbabeltrace_plugin_la_SOURCES = \ - component.c \ - component-class.c \ - component-factory.c \ - plugin.c \ - source.c \ - sink.c \ - iterator.c - -# Request that the linker keeps all static library objects. -libbabeltrace_plugin_la_LDFLAGS = \ - -Wl,--no-as-needed -version-info $(BABELTRACE_LIBRARY_VERSION) - -libbabeltrace_plugin_la_LIBADD = \ - $(top_builddir)/lib/libbabeltrace.la +SUBDIRS = ctf text diff --git a/plugins/component-class.c b/plugins/component-class.c deleted file mode 100644 index e0e2e0bf..00000000 --- a/plugins/component-class.c +++ /dev/null @@ -1,103 +0,0 @@ -/* - * component-class.c - * - * Babeltrace Plugin Component Class - * - * Copyright 2015 Jérémie Galarneau - * - * Author: Jérémie Galarneau - * - * 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 -#include -#include -#include - -static -void bt_component_class_destroy(struct bt_object *obj) -{ - struct bt_component_class *class; - - assert(obj); - class = container_of(obj, struct bt_component_class, base); - if (class->name) { - g_string_free(class->name, TRUE); - } - if (class->description) { - g_string_free(class->description, TRUE); - } - - bt_put(class->plugin); - g_free(class); -} - -BT_HIDDEN -struct bt_component_class *bt_component_class_create( - enum bt_component_type type, const char *name, - const char *description, struct bt_plugin *plugin) -{ - struct bt_component_class *class; - - class = g_new0(struct bt_component_class, 1); - if (!class) { - goto end; - } - - bt_object_init(class, bt_component_class_destroy); - class->type = type; - class->name = g_string_new(name); - class->description = g_string_new(description); - if (!class->name || !class->description) { - BT_PUT(class); - goto end; - } - - class->plugin = bt_get(plugin); -end: - return class; -} - -const char *bt_component_class_get_name( - struct bt_component_class *component_class) -{ - return component_class ? component_class->name->str : NULL; -} - -enum bt_component_type bt_component_class_get_type( - struct bt_component_class *component_class) -{ - return component_class ? component_class->type : - BT_COMPONENT_TYPE_UNKNOWN; -} - -struct bt_plugin *bt_component_class_get_plugin( - struct bt_component_class *component_class) -{ - return component_class ? bt_get(component_class->plugin) : - NULL; -} - -const char *bt_component_class_get_description( - struct bt_component_class *component_class) -{ - return component_class ? component_class->description->str : NULL; -} - diff --git a/plugins/component-factory.c b/plugins/component-factory.c deleted file mode 100644 index 65840d4c..00000000 --- a/plugins/component-factory.c +++ /dev/null @@ -1,420 +0,0 @@ -/* - * component-factory.c - * - * Babeltrace Plugin Component Factory - * - * Copyright 2015 Jérémie Galarneau - * - * Author: Jérémie Galarneau - * - * 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 -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define NATIVE_PLUGIN_SUFFIX ".so" -#define NATIVE_PLUGIN_SUFFIX_LEN sizeof(NATIVE_PLUGIN_SUFFIX) -#define LIBTOOL_PLUGIN_SUFFIX ".la" -#define LIBTOOL_PLUGIN_SUFFIX_LEN sizeof(LIBTOOL_PLUGIN_SUFFIX) -#define PLUGIN_SUFFIX_LEN max_t(size_t, sizeof(NATIVE_PLUGIN_SUFFIX), \ - sizeof(LIBTOOL_PLUGIN_SUFFIX)) - -/* Allocate dirent as recommended by READDIR(3), NOTES on readdir_r */ -static -struct dirent *alloc_dirent(const char *path) -{ - size_t len; - long name_max; - struct dirent *entry; - - name_max = pathconf(path, _PC_NAME_MAX); - if (name_max == -1) { - name_max = PATH_MAX; - } - len = offsetof(struct dirent, d_name) + name_max + 1; - entry = zmalloc(len); - return entry; -} - -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 bt_plugin *plugin; - bool is_libtool_wrapper = false, is_shared_object = false; - - if (!factory || !path) { - ret = BT_COMPONENT_FACTORY_STATUS_INVAL; - goto end; - } - - path_len = strlen(path); - if (path_len <= PLUGIN_SUFFIX_LEN) { - ret = BT_COMPONENT_FACTORY_STATUS_INVAL; - goto end; - } - - path_len++; - /* - * Check if the file ends with a known plugin file type suffix (i.e. .so - * or .la on Linux). - */ - is_libtool_wrapper = !strncmp(LIBTOOL_PLUGIN_SUFFIX, - path + path_len - LIBTOOL_PLUGIN_SUFFIX_LEN, - LIBTOOL_PLUGIN_SUFFIX_LEN); - is_shared_object = !strncmp(NATIVE_PLUGIN_SUFFIX, - path + path_len - NATIVE_PLUGIN_SUFFIX_LEN, - NATIVE_PLUGIN_SUFFIX_LEN); - if (!is_shared_object && !is_libtool_wrapper) { - /* Name indicates that this is not a plugin file. */ - ret = BT_COMPONENT_FACTORY_STATUS_INVAL; - goto end; - } - - module = g_module_open(path, 0); - if (!module) { - printf_error("Module open error: %s", g_module_error()); - ret = BT_COMPONENT_FACTORY_STATUS_ERROR; - goto end; - } - - /* Load plugin and make sure it defines the required entry points */ - plugin = bt_plugin_create(module, path); - if (!plugin) { - ret = BT_COMPONENT_FACTORY_STATUS_INVAL_PLUGIN; - if (!g_module_close(module)) { - printf_error("Module close error: %s", - g_module_error()); - } - goto end; - } - - factory->current_plugin = plugin; - component_status = bt_plugin_register_component_classes(plugin, - factory); - factory->current_plugin = NULL; - 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_PUT(plugin); - goto end; - } -end: - return ret; -} - -static -enum bt_component_factory_status -bt_component_factory_load_dir_recursive(struct bt_component_factory *factory, - const char *path) -{ - DIR *directory = NULL; - struct dirent *entry = NULL, *result = NULL; - char *file_path = NULL; - size_t path_len = strlen(path); - enum bt_component_factory_status ret = BT_COMPONENT_FACTORY_STATUS_OK; - - if (path_len >= PATH_MAX) { - ret = BT_COMPONENT_FACTORY_STATUS_INVAL; - goto end; - } - - entry = alloc_dirent(path); - if (!entry) { - ret = BT_COMPONENT_FACTORY_STATUS_NOMEM; - goto end; - } - - file_path = zmalloc(PATH_MAX); - if (!file_path) { - ret = BT_COMPONENT_FACTORY_STATUS_NOMEM; - goto end; - } - - strncpy(file_path, path, path_len); - /* Append a trailing '/' to the path */ - if (file_path[path_len - 1] != '/') { - file_path[path_len++] = '/'; - } - - directory = opendir(file_path); - if (!directory) { - perror("Failed to open plug-in directory"); - ret = BT_COMPONENT_FACTORY_STATUS_ERROR; - goto end; - } - - /* Recursively walk directory */ - while (!readdir_r(directory, entry, &result) && result) { - struct stat st; - int stat_ret; - size_t file_name_len; - - if (result->d_name[0] == '.') { - /* Skip hidden files, . and .. */ - continue; - } - - file_name_len = strlen(result->d_name); - - if (path_len + file_name_len >= PATH_MAX) { - continue; - } - - strncpy(file_path + path_len, result->d_name, file_name_len); - file_path[path_len + file_name_len] = '\0'; - - stat_ret = stat(file_path, &st); - if (stat_ret < 0) { - /* Continue to next file / directory. */ - printf_perror("Failed to stat() plugin file"); - continue; - } - - if (S_ISDIR(st.st_mode)) { - ret = bt_component_factory_load_dir_recursive(factory, - file_path); - if (ret != BT_COMPONENT_FACTORY_STATUS_OK) { - goto end; - } - } else if (S_ISREG(st.st_mode)) { - bt_component_factory_load_file(factory, file_path); - } - } -end: - if (directory) { - if (closedir(directory)) { - /* - * We don't want to override the error since there is - * nothing could do. - */ - perror("Failed to close plug-in directory"); - } - } - free(entry); - free(file_path); - return ret; -} - -static -void bt_component_factory_destroy(struct bt_object *obj) -{ - struct bt_component_factory *factory = NULL; - - assert(obj); - factory = container_of(obj, struct bt_component_factory, base); - - if (factory->component_classes) { - g_ptr_array_free(factory->component_classes, TRUE); - } - g_free(factory); -} - -struct bt_component_factory *bt_component_factory_create(void) -{ - struct bt_component_factory *factory; - - factory = g_new0(struct bt_component_factory, 1); - if (!factory) { - goto end; - } - - bt_object_init(factory, bt_component_factory_destroy); - factory->component_classes = g_ptr_array_new_with_free_func( - (GDestroyNotify) bt_put); - if (!factory->component_classes) { - goto error; - } -end: - return factory; -error: - BT_PUT(factory); - return factory; -} - -int bt_component_factory_get_component_class_count( - struct bt_component_factory *factory) -{ - return factory ? factory->component_classes->len : -1; -} - -struct bt_component_class *bt_component_factory_get_component_class_index( - struct bt_component_factory *factory, int index) -{ - struct bt_component_class *component_class = NULL; - - if (!factory || index < 0 || index >= factory->component_classes->len) { - goto end; - } - - component_class = bt_get(g_ptr_array_index( - factory->component_classes, index)); -end: - return component_class; -} - -struct bt_component_class *bt_component_factory_get_component_class( - struct bt_component_factory *factory, - const char *plugin_name, enum bt_component_type type, - const char *component_name) -{ - size_t i; - struct bt_component_class *component_class = NULL; - - if (!factory || (!plugin_name && !component_name && - type == BT_COMPONENT_TYPE_UNKNOWN)) { - /* At least one criterion must be provided. */ - goto no_match; - } - - for (i = 0; i < factory->component_classes->len; i++) { - struct bt_plugin *plugin = NULL; - - component_class = g_ptr_array_index(factory->component_classes, - i); - plugin = bt_component_class_get_plugin(component_class); - assert(plugin); - - if (type != BT_COMPONENT_TYPE_UNKNOWN) { - if (type != bt_component_class_get_type( - component_class)) { - continue; - } - } - - if (plugin_name) { - const char *cur_plugin_name = bt_plugin_get_name( - plugin); - - assert(cur_plugin_name); - if (strcmp(plugin_name, cur_plugin_name)) { - continue; - } - } - - if (component_name) { - const char *cur_cc_name = bt_component_class_get_name( - component_class); - - assert(cur_cc_name); - if (strcmp(component_name, cur_cc_name)) { - continue; - } - } - - /* All criteria met. */ - goto match; - } - -no_match: - return NULL; -match: - return bt_get(component_class); -} - -enum bt_component_factory_status bt_component_factory_load( - struct bt_component_factory *factory, const char *path) -{ - enum bt_component_factory_status ret = BT_COMPONENT_FACTORY_STATUS_OK; - - if (!factory || !path) { - ret = BT_COMPONENT_FACTORY_STATUS_INVAL; - goto end; - } - - if (!g_file_test(path, G_FILE_TEST_EXISTS)) { - ret = BT_COMPONENT_FACTORY_STATUS_NOENT; - goto end; - } - - if (g_file_test(path, G_FILE_TEST_IS_DIR)) { - ret = bt_component_factory_load_dir_recursive(factory, path); - } else if (g_file_test(path, G_FILE_TEST_IS_REGULAR) || - g_file_test(path, G_FILE_TEST_IS_SYMLINK)) { - ret = bt_component_factory_load_file(factory, path); - } else { - ret = BT_COMPONENT_FACTORY_STATUS_INVAL; - goto end; - } -end: - return ret; -} - -static -enum bt_component_factory_status -add_component_class(struct bt_component_factory *factory, const char *name, - const char *description, bt_component_init_cb init, - enum bt_component_type type) -{ - struct bt_component_class *class; - enum bt_component_factory_status ret = BT_COMPONENT_FACTORY_STATUS_OK; - - if (!factory || !name || !init) { - ret = BT_COMPONENT_FACTORY_STATUS_INVAL; - goto end; - } - - class = bt_component_class_create(type, name, description, - factory->current_plugin); - g_ptr_array_add(factory->component_classes, class); -end: - return ret; -} - -enum bt_component_factory_status -bt_component_factory_register_source_component_class( - struct bt_component_factory *factory, const char *name, - const char *description, bt_component_init_cb init) -{ - return add_component_class(factory, name, description, init, - BT_COMPONENT_TYPE_SOURCE); -} - -enum bt_component_factory_status -bt_component_factory_register_sink_component_class( - struct bt_component_factory *factory, const char *name, - const char *description, bt_component_init_cb init) -{ - return add_component_class(factory, name, description, init, - BT_COMPONENT_TYPE_SINK); -} diff --git a/plugins/component.c b/plugins/component.c deleted file mode 100644 index 5cfbbf0e..00000000 --- a/plugins/component.c +++ /dev/null @@ -1,212 +0,0 @@ -/* - * component.c - * - * Babeltrace Plugin Component - * - * Copyright 2015 Jérémie Galarneau - * - * Author: Jérémie Galarneau - * - * 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 -#include -#include -#include -#include -#include -#include - -static -struct bt_component * (* const component_create_funcs[])( - struct bt_component_class *, struct bt_value *) = { - [BT_COMPONENT_TYPE_SOURCE] = bt_component_source_create, - [BT_COMPONENT_TYPE_SINK] = bt_component_sink_create, -}; - -static -enum bt_component_status (* const component_validation_funcs[])( - struct bt_component *) = { - [BT_COMPONENT_TYPE_SOURCE] = bt_component_source_validate, - [BT_COMPONENT_TYPE_SINK] = bt_component_sink_validate, -}; - -static -void bt_component_destroy(struct bt_object *obj) -{ - struct bt_component *component = NULL; - struct bt_component_class *component_class = NULL; - - if (!obj) { - return; - } - - component = container_of(obj, struct bt_component, base); - - assert(component->destroy); - component_class = component->class; - - /* - * User data is destroyed first, followed by the concrete component - * instance. - */ - if (component->user_destroy) { - component->user_destroy(component->user_data); - } - - component->destroy(component); - g_string_free(component->name, TRUE); - bt_put(component_class); - g_free(component); -} - -BT_HIDDEN -enum bt_component_status bt_component_init(struct bt_component *component, - bt_component_destroy_cb destroy) -{ - enum bt_component_status ret = BT_COMPONENT_STATUS_OK; - - if (!component || !destroy) { - ret = BT_COMPONENT_STATUS_INVAL; - goto end; - } - - component->destroy = destroy; -end: - return ret; -} - -BT_HIDDEN -enum bt_component_type bt_component_get_type(struct bt_component *component) -{ - return component ? component->class->type : BT_COMPONENT_TYPE_UNKNOWN; -} - -struct bt_component *bt_component_create( - struct bt_component_class *component_class, const char *name, - struct bt_value *params) -{ - int ret; - struct bt_component *component = NULL; - enum bt_component_type type; - - if (!component_class) { - goto end; - } - - type = bt_component_class_get_type(component_class); - if (type <= BT_COMPONENT_TYPE_UNKNOWN || - type >= BT_COMPONENT_TYPE_FILTER) { - /* Filter components are not supported yet. */ - goto end; - } - - component = component_create_funcs[type](component_class, params); - if (!component) { - goto end; - } - - bt_object_init(component, bt_component_destroy); - component->class = bt_get(component_class); - component->name = g_string_new(name); - if (component->name) { - BT_PUT(component); - goto end; - } - - component_class->init(component, params); - ret = component_validation_funcs[type](component); - if (ret) { - BT_PUT(component); - goto end; - } -end: - return component; -} - -const char *bt_component_get_name(struct bt_component *component) -{ - const char *ret = NULL; - - if (!component) { - goto end; - } - - ret = component->name->str; -end: - return ret; -} - -enum bt_component_status bt_component_set_name(struct bt_component *component, - const char *name) -{ - enum bt_component_status ret = BT_COMPONENT_STATUS_OK; - - if (!component || !name || name[0] == '\0') { - ret = BT_COMPONENT_STATUS_INVAL; - goto end; - } - - g_string_assign(component->name, name); -end: - return ret; -} - -struct bt_component_class *bt_component_get_class( - struct bt_component *component) -{ - return component ? bt_get(component->class) : NULL; -} - -enum bt_component_status bt_component_set_error_stream( - struct bt_component *component, FILE *stream) -{ - enum bt_component_status ret = BT_COMPONENT_STATUS_OK; - - if (!component) { - ret = BT_COMPONENT_STATUS_INVAL; - goto end; - } - - component->error_stream = stream; -end: - return ret; -} - -void *bt_component_get_private_data(struct bt_component *component) -{ - return component ? component->user_data : NULL; -} - -enum bt_component_status -bt_component_set_private_data(struct bt_component *component, - void *data) -{ - enum bt_component_status ret = BT_COMPONENT_STATUS_OK; - - if (!component) { - ret = BT_COMPONENT_STATUS_INVAL; - goto end; - } - - component->user_data = data; -end: - return ret; -} diff --git a/plugins/ctf/Makefile.am b/plugins/ctf/Makefile.am index e916b160..27227083 100644 --- a/plugins/ctf/Makefile.am +++ b/plugins/ctf/Makefile.am @@ -15,6 +15,5 @@ libbabeltrace_plugin_ctf_la_LDFLAGS = \ libbabeltrace_plugin_ctf_la_LIBADD = \ $(top_builddir)/lib/libbabeltrace.la \ $(top_builddir)/formats/ctf/libbabeltrace-ctf.la \ - $(top_builddir)/plugins/libbabeltrace-plugin.la \ $(top_builddir)/plugins/ctf/reader/libbabeltrace-plugin-ctf-reader.la \ $(top_builddir)/plugins/ctf/lttng-live/libbabeltrace-plugin-ctf-lttng-live.la diff --git a/plugins/ctf/lttng-live/Makefile.am b/plugins/ctf/lttng-live/Makefile.am index f1b9177f..755be6e8 100644 --- a/plugins/ctf/lttng-live/Makefile.am +++ b/plugins/ctf/lttng-live/Makefile.am @@ -5,11 +5,3 @@ libbabeltrace_plugin_ctf_lttng_live_la_SOURCES = lttng-live.c noinst_HEADERS = lttng-live-internal.h noinst_LTLIBRARIES = libbabeltrace-plugin-ctf-lttng-live.la -# Request that the linker keeps all static library objects. -libbabeltrace_plugin_ctf_lttng_live_la_LDFLAGS = \ - $(LD_NO_AS_NEEDED) - -libbabeltrace_plugin_ctf_lttng_live_la_LIBADD = \ - $(top_builddir)/lib/libbabeltrace.la \ - $(top_builddir)/formats/ctf/libbabeltrace-ctf.la \ - $(top_builddir)/plugins/libbabeltrace-plugin.la diff --git a/plugins/ctf/reader/Makefile.am b/plugins/ctf/reader/Makefile.am index 7e50953f..4233d4ae 100644 --- a/plugins/ctf/reader/Makefile.am +++ b/plugins/ctf/reader/Makefile.am @@ -6,12 +6,3 @@ noinst_LTLIBRARIES = libbabeltrace-plugin-ctf-reader.la # Plug-in system library libbabeltrace_plugin_ctf_reader_la_SOURCES = \ reader.c - -# Request that the linker keeps all static librarie objects. -libbabeltrace_plugin_ctf_reader_la_LDFLAGS = \ - -Wl,--no-as-needed - -libbabeltrace_plugin_ctf_reader_la_LIBADD = \ - $(top_builddir)/lib/libbabeltrace.la \ - $(top_builddir)/formats/ctf/libbabeltrace-ctf.la \ - $(top_builddir)/plugins/libbabeltrace-plugin.la diff --git a/plugins/iterator.c b/plugins/iterator.c deleted file mode 100644 index b2f79f20..00000000 --- a/plugins/iterator.c +++ /dev/null @@ -1,100 +0,0 @@ -/* - * iterator.c - * - * Babeltrace Notification Iterator - * - * Copyright 2015 Jérémie Galarneau - * - * Author: Jérémie Galarneau - * - * 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 -#include -#include -#include -#include -#include - -static -void bt_notification_iterator_destroy(struct bt_object *obj) -{ - struct bt_notification_iterator *iterator; - - assert(obj); - iterator = container_of(obj, struct bt_notification_iterator, - base); - assert(iterator->user_destroy || !iterator->user_data); - iterator->user_destroy(iterator); - g_free(iterator); -} - -BT_HIDDEN -struct bt_notification_iterator *bt_notification_iterator_create( - struct bt_component *component) -{ - struct bt_notification_iterator *iterator = NULL; - - if (!component || - bt_component_get_type(component) != BT_COMPONENT_TYPE_SOURCE) { - goto end; - } - - iterator = g_new0(struct bt_notification_iterator, 1); - if (!iterator) { - goto end; - } - - bt_object_init(iterator, bt_notification_iterator_destroy); -end: - return iterator; -} - -BT_HIDDEN -enum bt_notification_iterator_status bt_notification_iterator_validate( - struct bt_notification_iterator *iterator) -{ - enum bt_notification_iterator_status ret = - BT_NOTIFICATION_ITERATOR_STATUS_OK; - - if (!iterator || !iterator->get || !iterator->next) { - ret = BT_NOTIFICATION_ITERATOR_STATUS_INVAL; - goto end; - } -end: - return ret; -} - -enum bt_notification_iterator_status bt_notification_iterator_set_get_cb( - struct bt_notification_iterator *iterator, - bt_notification_iterator_get_cb get) -{ - enum bt_notification_iterator_status ret = - BT_NOTIFICATION_ITERATOR_STATUS_OK; - - if (!iterator || !get) { - ret = BT_NOTIFICATION_ITERATOR_STATUS_INVAL; - goto end; - } - - -end: - return ret; -} diff --git a/plugins/plugin.c b/plugins/plugin.c deleted file mode 100644 index f3d23268..00000000 --- a/plugins/plugin.c +++ /dev/null @@ -1,157 +0,0 @@ -/* - * plugin.c - * - * Babeltrace Plugin - * - * Copyright 2015 Jérémie Galarneau - * - * Author: Jérémie Galarneau - * - * 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 -#include -#include -#include - -#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_object *obj) -{ - struct bt_plugin *plugin; - - 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()); - } - } - - if (plugin->exit) { - plugin->exit(); - } - 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 *plugin = NULL; - gpointer symbol = NULL; - - if (!module || !path) { - goto error; - } - - plugin = g_new0(struct bt_plugin, 1); - if (!plugin) { - goto error; - } - - 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)) { - printf_error("Unable to resolve plugin symbol %s from %s", - 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", - 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)); - 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 */ - 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); - g_module_symbol(module, PLUGIN_SYMBOL_DESCRIPTION, - (gpointer *) &plugin->description); - - return plugin; -error: - BT_PUT(plugin); - 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); -} - -const char *bt_plugin_get_name(struct bt_plugin *plugin) -{ - return plugin ? plugin->name : NULL; -} - -const char *bt_plugin_get_author(struct bt_plugin *plugin) -{ - return plugin ? plugin->author : NULL; -} - -const char *bt_plugin_get_license(struct bt_plugin *plugin) -{ - return plugin ? plugin->license : NULL; -} - -const char *bt_plugin_get_path(struct bt_plugin *plugin) -{ - return plugin ? plugin->path->str : NULL; -} - -const char *bt_plugin_get_description(struct bt_plugin *plugin) -{ - return plugin ? plugin->description : NULL; -} diff --git a/plugins/sink.c b/plugins/sink.c deleted file mode 100644 index 81f6cba6..00000000 --- a/plugins/sink.c +++ /dev/null @@ -1,89 +0,0 @@ -/* - * sink.c - * - * Babeltrace Sink Component - * - * Copyright 2015 Jérémie Galarneau - * - * Author: Jérémie Galarneau - * - * 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 -#include -#include - -static -void bt_component_sink_destroy(struct bt_component *component) -{ - return; -} - -BT_HIDDEN -enum bt_component_status bt_component_sink_validate( - struct bt_component *component) -{ - return BT_COMPONENT_STATUS_OK; -} - -BT_HIDDEN -struct bt_component *bt_component_sink_create( - struct bt_component_class *class, struct bt_value *params) -{ - struct bt_component_sink *sink = NULL; - enum bt_component_status ret; - - sink = g_new0(struct bt_component_sink, 1); - if (!sink) { - goto end; - } - - ret = bt_component_init(&sink->parent, bt_component_sink_destroy); - if (ret != BT_COMPONENT_STATUS_OK) { - BT_PUT(sink); - goto end; - } -end: - return sink ? &sink->parent : NULL; -} - -enum bt_component_status bt_component_sink_handle_notification( - struct bt_component *component, - struct bt_notification *notification) -{ - enum bt_component_status ret = BT_COMPONENT_STATUS_OK; - struct bt_component_sink *sink = NULL; - - if (!component || !notification) { - ret = BT_COMPONENT_STATUS_INVAL; - goto end; - } - - if (bt_component_get_type(component) != BT_COMPONENT_TYPE_SINK) { - ret = BT_COMPONENT_STATUS_UNSUPPORTED; - goto end; - } - - sink = container_of(component, struct bt_component_sink, parent); - assert(sink->handle_notification); - ret = sink->handle_notification(component, notification); -end: - return ret; -} diff --git a/plugins/source.c b/plugins/source.c deleted file mode 100644 index ed3b1642..00000000 --- a/plugins/source.c +++ /dev/null @@ -1,107 +0,0 @@ -/* - * source.c - * - * Babeltrace Source Component - * - * Copyright 2015 Jérémie Galarneau - * - * Author: Jérémie Galarneau - * - * 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 -#include -#include -#include -#include -#include - -static -void bt_component_source_destroy(struct bt_component *component) -{ - return; -} - -BT_HIDDEN -enum bt_component_status bt_component_source_validate( - struct bt_component *component) -{ - return BT_COMPONENT_STATUS_OK; -} - -BT_HIDDEN -struct bt_component *bt_component_source_create( - struct bt_component_class *class, struct bt_value *params) -{ - struct bt_component_source *source = NULL; - enum bt_component_status ret; - - source = g_new0(struct bt_component_source, 1); - if (!source) { - goto end; - } - - ret = bt_component_init(&source->parent, bt_component_source_destroy); - if (ret != BT_COMPONENT_STATUS_OK) { - BT_PUT(source); - goto end; - } -end: - return source ? &source->parent : NULL; -} - -struct bt_notification_iterator *bt_component_source_create_iterator( - struct bt_component *component) -{ - enum bt_component_status ret_component; - enum bt_notification_iterator_status ret_iterator; - struct bt_component_source *source; - struct bt_notification_iterator *iterator = NULL; - - if (!component) { - goto end; - } - - if (bt_component_get_type(component) != BT_COMPONENT_TYPE_SOURCE) { - goto end; - } - - iterator = bt_notification_iterator_create(component); - if (!iterator) { - goto end; - } - - source = container_of(component, struct bt_component_source, parent); - assert(source->init_iterator); - ret_component = source->init_iterator(component, iterator); - if (ret_component != BT_COMPONENT_STATUS_OK) { - goto error; - } - - ret_iterator = bt_notification_iterator_validate(iterator); - if (ret_iterator != BT_NOTIFICATION_ITERATOR_STATUS_OK) { - goto error; - } -end: - return iterator; -error: - BT_PUT(iterator); - return iterator; -} diff --git a/plugins/text/Makefile.am b/plugins/text/Makefile.am index eb7cd197..55f4c8cb 100644 --- a/plugins/text/Makefile.am +++ b/plugins/text/Makefile.am @@ -10,9 +10,8 @@ libbabeltrace_plugin_ctf_text_la_SOURCES = \ # Request that the linker keeps all static library objects. libbabeltrace_plugin_ctf_text_la_LDFLAGS = \ - $(LD_NO_AS_NEEDED) -version-info $(BABELTRACE_LIBRARY_VERSION) + -version-info $(BABELTRACE_LIBRARY_VERSION) libbabeltrace_plugin_ctf_text_la_LIBADD = \ $(top_builddir)/lib/libbabeltrace.la \ - $(top_builddir)/formats/ctf/libbabeltrace-ctf.la \ - $(top_builddir)/plugins/libbabeltrace-plugin.la + $(top_builddir)/formats/ctf/libbabeltrace-ctf.la