From: Philippe Proulx Date: Tue, 4 Dec 2018 22:03:22 +0000 (-0500) Subject: lib: make plugin API const-correct X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=commitdiff_plain;h=92fed4e1f98f18e4edbfdf5adfe57741a3260b5d lib: make plugin API const-correct Signed-off-by: Philippe Proulx --- diff --git a/cli/babeltrace.c b/cli/babeltrace.c index 06f12461..a8b5b372 100644 --- a/cli/babeltrace.c +++ b/cli/babeltrace.c @@ -262,10 +262,10 @@ end: } static -struct bt_plugin *find_plugin(const char *name) +const struct bt_plugin *find_plugin(const char *name) { int i; - struct bt_plugin *plugin = NULL; + const struct bt_plugin *plugin = NULL; BT_ASSERT(name); BT_LOGD("Finding plugin: name=\"%s\"", name); @@ -292,7 +292,7 @@ struct bt_plugin *find_plugin(const char *name) return plugin; } -typedef void *(*plugin_borrow_comp_cls_func_t)(struct bt_plugin *, +typedef void *(*plugin_borrow_comp_cls_func_t)(const struct bt_plugin *, const char *); static @@ -301,7 +301,7 @@ void *find_component_class_from_plugin(const char *plugin_name, plugin_borrow_comp_cls_func_t plugin_borrow_comp_cls_func) { void *comp_class = NULL; - struct bt_plugin *plugin; + const struct bt_plugin *plugin; BT_LOGD("Finding component class: plugin-name=\"%s\", " "comp-cls-name=\"%s\"", plugin_name, comp_class_name); @@ -335,7 +335,7 @@ struct bt_component_class_source *find_source_component_class( return (void *) find_component_class_from_plugin(plugin_name, comp_class_name, (plugin_borrow_comp_cls_func_t) - bt_plugin_borrow_source_component_class_by_name); + bt_plugin_borrow_source_component_class_by_name_const); } static @@ -345,7 +345,7 @@ struct bt_component_class_filter *find_filter_component_class( return (void *) find_component_class_from_plugin(plugin_name, comp_class_name, (plugin_borrow_comp_cls_func_t) - bt_plugin_borrow_filter_component_class_by_name); + bt_plugin_borrow_filter_component_class_by_name_const); } static @@ -355,7 +355,7 @@ struct bt_component_class_sink *find_sink_component_class( return (void *) find_component_class_from_plugin(plugin_name, comp_class_name, (plugin_borrow_comp_cls_func_t) - bt_plugin_borrow_sink_component_class_by_name); + bt_plugin_borrow_sink_component_class_by_name_const); } static @@ -761,7 +761,7 @@ void print_cfg(struct bt_config *cfg) } static -void add_to_loaded_plugins(struct bt_plugin_set *plugin_set) +void add_to_loaded_plugins(const struct bt_plugin_set *plugin_set) { int64_t i; int64_t count; @@ -770,9 +770,9 @@ void add_to_loaded_plugins(struct bt_plugin_set *plugin_set) BT_ASSERT(count >= 0); for (i = 0; i < count; i++) { - struct bt_plugin *plugin = - bt_plugin_set_borrow_plugin_by_index(plugin_set, i); - struct bt_plugin *loaded_plugin = + const struct bt_plugin *plugin = + bt_plugin_set_borrow_plugin_by_index_const(plugin_set, i); + const struct bt_plugin *loaded_plugin = find_plugin(bt_plugin_get_name(plugin)); BT_ASSERT(plugin); @@ -790,7 +790,7 @@ void add_to_loaded_plugins(struct bt_plugin_set *plugin_set) BT_LOGD("Adding plugin to loaded plugins: plugin-path=\"%s\"", bt_plugin_get_name(plugin)); bt_object_get_ref(plugin); - g_ptr_array_add(loaded_plugins, plugin); + g_ptr_array_add(loaded_plugins, (void *) plugin); } } } @@ -812,7 +812,7 @@ int load_dynamic_plugins(const struct bt_value *plugin_paths) for (i = 0; i < nr_paths; i++) { const struct bt_value *plugin_path_value = NULL; const char *plugin_path; - struct bt_plugin_set *plugin_set; + const struct bt_plugin_set *plugin_set; plugin_path_value = bt_value_array_borrow_element_by_index_const( @@ -848,7 +848,7 @@ static int load_static_plugins(void) { int ret = 0; - struct bt_plugin_set *plugin_set; + const struct bt_plugin_set *plugin_set; BT_LOGI("Loading static plugins."); plugin_set = bt_plugin_create_all_from_static(); @@ -886,7 +886,7 @@ end: } static -void print_plugin_info(struct bt_plugin *plugin) +void print_plugin_info(const struct bt_plugin *plugin) { unsigned int major, minor, patch; const char *extra; @@ -1035,7 +1035,7 @@ static int cmd_help(struct bt_config *cfg) { int ret = 0; - struct bt_plugin *plugin = NULL; + const struct bt_plugin *plugin = NULL; struct bt_component_class *needed_comp_cls = NULL; plugin = find_plugin(cfg->cmd_data.help.cfg_component->plugin_name->str); @@ -1104,12 +1104,12 @@ end: return ret; } -typedef void *(* plugin_borrow_comp_cls_by_index_func_t)(struct bt_plugin *, +typedef void *(* plugin_borrow_comp_cls_by_index_func_t)(const struct bt_plugin *, uint64_t); typedef struct bt_component_class *(* spec_comp_cls_borrow_comp_cls_func_t)( void *); -void cmd_list_plugins_print_component_classes(struct bt_plugin *plugin, +void cmd_list_plugins_print_component_classes(const struct bt_plugin *plugin, const char *cc_type_name, uint64_t count, plugin_borrow_comp_cls_by_index_func_t borrow_comp_cls_by_index_func, spec_comp_cls_borrow_comp_cls_func_t spec_comp_cls_borrow_comp_cls_func) @@ -1170,7 +1170,7 @@ int cmd_list_plugins(struct bt_config *cfg) } for (i = 0; i < plugins_count; i++) { - struct bt_plugin *plugin = g_ptr_array_index(loaded_plugins, i); + const struct bt_plugin *plugin = g_ptr_array_index(loaded_plugins, i); component_classes_count += bt_plugin_get_source_component_class_count(plugin) + @@ -1187,26 +1187,26 @@ int cmd_list_plugins(struct bt_config *cfg) bt_common_color_reset()); for (i = 0; i < plugins_count; i++) { - struct bt_plugin *plugin = g_ptr_array_index(loaded_plugins, i); + const struct bt_plugin *plugin = g_ptr_array_index(loaded_plugins, i); printf("\n"); print_plugin_info(plugin); cmd_list_plugins_print_component_classes(plugin, "Source", bt_plugin_get_source_component_class_count(plugin), (plugin_borrow_comp_cls_by_index_func_t) - bt_plugin_borrow_source_component_class_by_name, + bt_plugin_borrow_source_component_class_by_name_const, (spec_comp_cls_borrow_comp_cls_func_t) bt_component_class_source_as_component_class); cmd_list_plugins_print_component_classes(plugin, "Filter", bt_plugin_get_filter_component_class_count(plugin), (plugin_borrow_comp_cls_by_index_func_t) - bt_plugin_borrow_filter_component_class_by_name, + bt_plugin_borrow_filter_component_class_by_name_const, (spec_comp_cls_borrow_comp_cls_func_t) bt_component_class_filter_as_component_class); cmd_list_plugins_print_component_classes(plugin, "Sink", bt_plugin_get_sink_component_class_count(plugin), (plugin_borrow_comp_cls_by_index_func_t) - bt_plugin_borrow_sink_component_class_by_name, + bt_plugin_borrow_sink_component_class_by_name_const, (spec_comp_cls_borrow_comp_cls_func_t) bt_component_class_sink_as_component_class); } diff --git a/include/Makefile.am b/include/Makefile.am index bc272807..7a716590 100644 --- a/include/Makefile.am +++ b/include/Makefile.am @@ -146,8 +146,8 @@ babeltracetraceirinclude_HEADERS = \ babeltracepluginincludedir = "$(includedir)/babeltrace/plugin" babeltraceplugininclude_HEADERS = \ babeltrace/plugin/plugin-dev.h \ - babeltrace/plugin/plugin.h \ - babeltrace/plugin/plugin-set.h + babeltrace/plugin/plugin-const.h \ + babeltrace/plugin/plugin-set-const.h # Graph, component, and notification API babeltracegraphincludedir = "$(includedir)/babeltrace/graph" diff --git a/include/babeltrace/babeltrace.h b/include/babeltrace/babeltrace.h index 67e2fac9..1a2f5831 100644 --- a/include/babeltrace/babeltrace.h +++ b/include/babeltrace/babeltrace.h @@ -89,9 +89,9 @@ #include /* Plugin and plugin development API */ +#include #include -#include -#include +#include /* Graph, component, and notification API */ #include diff --git a/include/babeltrace/lib-logging-internal.h b/include/babeltrace/lib-logging-internal.h index 4ca61099..f7c20586 100644 --- a/include/babeltrace/lib-logging-internal.h +++ b/include/babeltrace/lib-logging-internal.h @@ -141,7 +141,7 @@ int bt_lib_log_level; * Graph. The parameter type is `struct bt_graph *`. * * `l`: - * Plugin. The parameter type is `struct bt_plugin *`. + * Plugin. The parameter type is `const struct bt_plugin *`. * * `o`: * Object pool. The parameter type is `struct bt_object_pool *`. diff --git a/include/babeltrace/plugin/plugin-const.h b/include/babeltrace/plugin/plugin-const.h new file mode 100644 index 00000000..906bf062 --- /dev/null +++ b/include/babeltrace/plugin/plugin-const.h @@ -0,0 +1,128 @@ +#ifndef BABELTRACE_PLUGIN_PLUGIN_CONST_H +#define BABELTRACE_PLUGIN_PLUGIN_CONST_H + +/* + * Copyright 2016 Jérémie Galarneau + * Copyright 2017 Philippe Proulx + * + * 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 + +/* For bt_bool */ +#include + +/* For enum bt_component_class_type */ +#include + +/* For enum bt_component_class_source */ +#include + +/* For enum bt_component_class_filter */ +#include + +/* For enum bt_component_class_sink */ +#include + +/* For enum bt_property_availability */ +#include + +#ifdef __cplusplus +extern "C" { +#endif + +struct bt_plugin; +struct bt_plugin_set; +struct bt_component_class; +struct bt_component_class_source; +struct bt_component_class_filter; +struct bt_component_class_sink; + +enum bt_plugin_status { + BT_PLUGIN_STATUS_OK = 0, + BT_PLUGIN_STATUS_ERROR = -1, + BT_PLUGIN_STATUS_NOMEM = -12, +}; + +extern const struct bt_plugin *bt_plugin_find(const char *plugin_name); + +extern const struct bt_plugin_set *bt_plugin_create_all_from_file( + const char *path); + +extern const struct bt_plugin_set *bt_plugin_create_all_from_dir( + const char *path, bt_bool recurse); + +extern const struct bt_plugin_set *bt_plugin_create_all_from_static(void); + +extern const char *bt_plugin_get_name(const struct bt_plugin *plugin); + +extern const char *bt_plugin_get_author(const struct bt_plugin *plugin); + +extern const char *bt_plugin_get_license(const struct bt_plugin *plugin); + +extern const char *bt_plugin_get_description(const struct bt_plugin *plugin); + +extern const char *bt_plugin_get_path(const struct bt_plugin *plugin); + +extern enum bt_property_availability bt_plugin_get_version( + const struct bt_plugin *plugin, unsigned int *major, + unsigned int *minor, unsigned int *patch, const char **extra); + +extern uint64_t bt_plugin_get_source_component_class_count( + const struct bt_plugin *plugin); + +extern uint64_t bt_plugin_get_filter_component_class_count( + const struct bt_plugin *plugin); + +extern uint64_t bt_plugin_get_sink_component_class_count( + const struct bt_plugin *plugin); + +extern struct bt_component_class_source * +bt_plugin_borrow_source_component_class_by_index_const_const( + const struct bt_plugin *plugin, uint64_t index); + +extern struct bt_component_class_filter * +bt_plugin_borrow_filter_component_class_by_index_const( + const struct bt_plugin *plugin, uint64_t index); + +extern struct bt_component_class_sink * +bt_plugin_borrow_sink_component_class_by_index_const( + const struct bt_plugin *plugin, uint64_t index); + +extern struct bt_component_class_source * +bt_plugin_borrow_source_component_class_by_name_const(const struct bt_plugin *plugin, + const char *name); + +extern struct bt_component_class_filter * +bt_plugin_borrow_filter_component_class_by_name_const(const struct bt_plugin *plugin, + const char *name); + +extern struct bt_component_class_sink * +bt_plugin_borrow_sink_component_class_by_name_const(const struct bt_plugin *plugin, + const char *name); + +#ifdef __cplusplus +} +#endif + +#endif /* BABELTRACE_PLUGIN_PLUGIN_CONST_H */ diff --git a/include/babeltrace/plugin/plugin-dev.h b/include/babeltrace/plugin/plugin-dev.h index 8cbc665e..60fa36e4 100644 --- a/include/babeltrace/plugin/plugin-dev.h +++ b/include/babeltrace/plugin/plugin-dev.h @@ -32,7 +32,7 @@ #include /* For enum bt_plugin_status */ -#include +#include /* For private component class method type definitions */ #include @@ -63,7 +63,7 @@ extern "C" { /* Plugin initialization function type */ typedef enum bt_plugin_status (*bt_plugin_init_func)( - struct bt_plugin *plugin); + const struct bt_plugin *plugin); /* Plugin exit function type */ typedef enum bt_plugin_status (*bt_plugin_exit_func)(void); diff --git a/include/babeltrace/plugin/plugin-internal.h b/include/babeltrace/plugin/plugin-internal.h index 7ca57ba9..bd1876eb 100644 --- a/include/babeltrace/plugin/plugin-internal.h +++ b/include/babeltrace/plugin/plugin-internal.h @@ -27,7 +27,7 @@ #include #include -#include +#include #include #include #include diff --git a/include/babeltrace/plugin/plugin-set-const.h b/include/babeltrace/plugin/plugin-set-const.h new file mode 100644 index 00000000..8a22fe50 --- /dev/null +++ b/include/babeltrace/plugin/plugin-set-const.h @@ -0,0 +1,48 @@ +#ifndef BABELTRACE_PLUGIN_PLUGIN_SET_CONST_H +#define BABELTRACE_PLUGIN_PLUGIN_SET_CONST_H + +/* + * Copyright 2016 Jérémie Galarneau + * Copyright 2017 Philippe Proulx + * + * 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 + +#ifdef __cplusplus +extern "C" { +#endif + +struct bt_plugin; +struct bt_plugin_set; + +extern uint64_t bt_plugin_set_get_plugin_count( + const struct bt_plugin_set *plugin_set); + +extern const struct bt_plugin *bt_plugin_set_borrow_plugin_by_index_const( + const struct bt_plugin_set *plugin_set, uint64_t index); + +#ifdef __cplusplus +} +#endif + +#endif /* BABELTRACE_PLUGIN_PLUGIN_SET_CONST_H */ diff --git a/include/babeltrace/plugin/plugin-set.h b/include/babeltrace/plugin/plugin-set.h deleted file mode 100644 index 8ec2be12..00000000 --- a/include/babeltrace/plugin/plugin-set.h +++ /dev/null @@ -1,48 +0,0 @@ -#ifndef BABELTRACE_PLUGIN_PLUGIN_SET_H -#define BABELTRACE_PLUGIN_PLUGIN_SET_H - -/* - * Copyright 2016 Jérémie Galarneau - * Copyright 2017 Philippe Proulx - * - * 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 - -#ifdef __cplusplus -extern "C" { -#endif - -struct bt_plugin; -struct bt_plugin_set; - -extern uint64_t bt_plugin_set_get_plugin_count( - struct bt_plugin_set *plugin_set); - -extern struct bt_plugin *bt_plugin_set_borrow_plugin_by_index( - struct bt_plugin_set *plugin_set, uint64_t index); - -#ifdef __cplusplus -} -#endif - -#endif /* BABELTRACE_PLUGIN_PLUGIN_SET_H */ diff --git a/include/babeltrace/plugin/plugin.h b/include/babeltrace/plugin/plugin.h deleted file mode 100644 index 7aed1877..00000000 --- a/include/babeltrace/plugin/plugin.h +++ /dev/null @@ -1,127 +0,0 @@ -#ifndef BABELTRACE_PLUGIN_PLUGIN_H -#define BABELTRACE_PLUGIN_PLUGIN_H - -/* - * Copyright 2016 Jérémie Galarneau - * Copyright 2017 Philippe Proulx - * - * 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 - -/* For bt_bool */ -#include - -/* For enum bt_component_class_type */ -#include - -/* For enum bt_component_class_source */ -#include - -/* For enum bt_component_class_filter */ -#include - -/* For enum bt_component_class_sink */ -#include - -/* For enum bt_property_availability */ -#include - -#ifdef __cplusplus -extern "C" { -#endif - -struct bt_plugin; -struct bt_plugin_set; -struct bt_component_class; -struct bt_component_class_source; -struct bt_component_class_filter; -struct bt_component_class_sink; - -enum bt_plugin_status { - BT_PLUGIN_STATUS_OK = 0, - BT_PLUGIN_STATUS_ERROR = -1, - BT_PLUGIN_STATUS_NOMEM = -12, -}; - -extern struct bt_plugin *bt_plugin_find(const char *plugin_name); - -extern struct bt_plugin_set *bt_plugin_create_all_from_file(const char *path); - -extern struct bt_plugin_set *bt_plugin_create_all_from_dir(const char *path, - bt_bool recurse); - -extern struct bt_plugin_set *bt_plugin_create_all_from_static(void); - -extern const char *bt_plugin_get_name(struct bt_plugin *plugin); - -extern const char *bt_plugin_get_author(struct bt_plugin *plugin); - -extern const char *bt_plugin_get_license(struct bt_plugin *plugin); - -extern const char *bt_plugin_get_description(struct bt_plugin *plugin); - -extern const char *bt_plugin_get_path(struct bt_plugin *plugin); - -extern enum bt_property_availability bt_plugin_get_version( - struct bt_plugin *plugin, unsigned int *major, - unsigned int *minor, unsigned int *patch, const char **extra); - -extern uint64_t bt_plugin_get_source_component_class_count( - struct bt_plugin *plugin); - -extern uint64_t bt_plugin_get_filter_component_class_count( - struct bt_plugin *plugin); - -extern uint64_t bt_plugin_get_sink_component_class_count( - struct bt_plugin *plugin); - -extern struct bt_component_class_source * -bt_plugin_borrow_source_component_class_by_index( - struct bt_plugin *plugin, uint64_t index); - -extern struct bt_component_class_filter * -bt_plugin_borrow_filter_component_class_by_index( - struct bt_plugin *plugin, uint64_t index); - -extern struct bt_component_class_sink * -bt_plugin_borrow_sink_component_class_by_index( - struct bt_plugin *plugin, uint64_t index); - -extern struct bt_component_class_source * -bt_plugin_borrow_source_component_class_by_name(struct bt_plugin *plugin, - const char *name); - -extern struct bt_component_class_filter * -bt_plugin_borrow_filter_component_class_by_name(struct bt_plugin *plugin, - const char *name); - -extern struct bt_component_class_sink * -bt_plugin_borrow_sink_component_class_by_name(struct bt_plugin *plugin, - const char *name); - -#ifdef __cplusplus -} -#endif - -#endif /* BABELTRACE_PLUGIN_PLUGIN_H */ diff --git a/include/babeltrace/plugin/python-plugin-provider-internal.h b/include/babeltrace/plugin/python-plugin-provider-internal.h index 2f81e579..c46fc372 100644 --- a/include/babeltrace/plugin/python-plugin-provider-internal.h +++ b/include/babeltrace/plugin/python-plugin-provider-internal.h @@ -23,7 +23,7 @@ * SOFTWARE. */ -#include +#include extern struct bt_plugin_set *bt_plugin_python_create_all_from_file(const char *path); diff --git a/lib/lib-logging.c b/lib/lib-logging.c index c9119825..b595263c 100644 --- a/lib/lib-logging.c +++ b/lib/lib-logging.c @@ -1141,7 +1141,7 @@ static inline void format_notification_iterator(char **buf_ch, } static inline void format_plugin(char **buf_ch, bool extended, - const char *prefix, struct bt_plugin *plugin) + const char *prefix, const struct bt_plugin *plugin) { char tmp_prefix[64]; diff --git a/lib/plugin/plugin.c b/lib/plugin/plugin.c index 70e99e4f..39d6e69f 100644 --- a/lib/plugin/plugin.c +++ b/lib/plugin/plugin.c @@ -32,6 +32,7 @@ #include #include #include +#include #include #include #include @@ -116,22 +117,21 @@ uint64_t bt_plugin_set_get_plugin_count(struct bt_plugin_set *plugin_set) return (uint64_t) plugin_set->plugins->len; } -struct bt_plugin *bt_plugin_set_borrow_plugin_by_index( - struct bt_plugin_set *plugin_set, - uint64_t index) +const struct bt_plugin *bt_plugin_set_borrow_plugin_by_index_const( + const struct bt_plugin_set *plugin_set, uint64_t index) { BT_ASSERT_PRE_NON_NULL(plugin_set, "Plugin set"); BT_ASSERT_PRE_VALID_INDEX(index, plugin_set->plugins->len); return g_ptr_array_index(plugin_set->plugins, index); } -struct bt_plugin_set *bt_plugin_create_all_from_static(void) +const struct bt_plugin_set *bt_plugin_create_all_from_static(void) { /* bt_plugin_so_create_all_from_static() logs errors */ return bt_plugin_so_create_all_from_static(); } -struct bt_plugin_set *bt_plugin_create_all_from_file(const char *path) +const struct bt_plugin_set *bt_plugin_create_all_from_file(const char *path) { struct bt_plugin_set *plugin_set = NULL; @@ -171,13 +171,13 @@ static void destroy_gstring(void *data) g_string_free(data, TRUE); } -struct bt_plugin *bt_plugin_find(const char *plugin_name) +const struct bt_plugin *bt_plugin_find(const char *plugin_name) { const char *system_plugin_dir; char *home_plugin_dir = NULL; const char *envvar; - struct bt_plugin *plugin = NULL; - struct bt_plugin_set *plugin_set = NULL; + const struct bt_plugin *plugin = NULL; + const struct bt_plugin_set *plugin_set = NULL; GPtrArray *dirs = NULL; int ret; size_t i, j; @@ -264,7 +264,7 @@ struct bt_plugin *bt_plugin_find(const char *plugin_name) } for (j = 0; j < plugin_set->plugins->len; j++) { - struct bt_plugin *candidate_plugin = + const struct bt_plugin *candidate_plugin = g_ptr_array_index(plugin_set->plugins, j); if (strcmp(bt_plugin_get_name(candidate_plugin), @@ -285,7 +285,7 @@ struct bt_plugin *bt_plugin_find(const char *plugin_name) plugin_set = bt_plugin_create_all_from_static(); if (plugin_set) { for (j = 0; j < plugin_set->plugins->len; j++) { - struct bt_plugin *candidate_plugin = + const struct bt_plugin *candidate_plugin = g_ptr_array_index(plugin_set->plugins, j); if (strcmp(bt_plugin_get_name(candidate_plugin), @@ -341,7 +341,7 @@ int nftw_append_all_from_dir(const char *file, const struct stat *sb, int flag, switch (flag) { case FTW_F: { - struct bt_plugin_set *plugins_from_file; + const struct bt_plugin_set *plugins_from_file; if (name[0] == '.') { /* Skip hidden files */ @@ -361,7 +361,9 @@ int nftw_append_all_from_dir(const char *file, const struct stat *sb, int flag, BT_LIB_LOGD("Adding plugin to plugin set: " "plugin-path=\"%s\", %![plugin-]+l", file, plugin); - bt_plugin_set_add_plugin(append_all_from_dir_info.plugin_set, plugin); + bt_plugin_set_add_plugin( + append_all_from_dir_info.plugin_set, + plugin); } bt_object_put_ref(plugins_from_file); @@ -407,7 +409,7 @@ enum bt_plugin_status bt_plugin_create_append_all_from_dir( return ret; } -struct bt_plugin_set *bt_plugin_create_all_from_dir(const char *path, +const struct bt_plugin_set *bt_plugin_create_all_from_dir(const char *path, bt_bool recurse) { struct bt_plugin_set *plugin_set; @@ -442,38 +444,38 @@ end: return plugin_set; } -const char *bt_plugin_get_name(struct bt_plugin *plugin) +const char *bt_plugin_get_name(const struct bt_plugin *plugin) { BT_ASSERT_PRE_NON_NULL(plugin, "Plugin"); return plugin->info.name_set ? plugin->info.name->str : NULL; } -const char *bt_plugin_get_author(struct bt_plugin *plugin) +const char *bt_plugin_get_author(const struct bt_plugin *plugin) { BT_ASSERT_PRE_NON_NULL(plugin, "Plugin"); return plugin->info.author_set ? plugin->info.author->str : NULL; } -const char *bt_plugin_get_license(struct bt_plugin *plugin) +const char *bt_plugin_get_license(const struct bt_plugin *plugin) { BT_ASSERT_PRE_NON_NULL(plugin, "Plugin"); return plugin->info.license_set ? plugin->info.license->str : NULL; } -const char *bt_plugin_get_path(struct bt_plugin *plugin) +const char *bt_plugin_get_path(const struct bt_plugin *plugin) { BT_ASSERT_PRE_NON_NULL(plugin, "Plugin"); return plugin->info.path_set ? plugin->info.path->str : NULL; } -const char *bt_plugin_get_description(struct bt_plugin *plugin) +const char *bt_plugin_get_description(const struct bt_plugin *plugin) { BT_ASSERT_PRE_NON_NULL(plugin, "Plugin"); return plugin->info.description_set ? plugin->info.description->str : NULL; } -enum bt_property_availability bt_plugin_get_version(struct bt_plugin *plugin, +enum bt_property_availability bt_plugin_get_version(const struct bt_plugin *plugin, unsigned int *major, unsigned int *minor, unsigned int *patch, const char **extra) { @@ -508,19 +510,19 @@ end: return avail; } -uint64_t bt_plugin_get_source_component_class_count(struct bt_plugin *plugin) +uint64_t bt_plugin_get_source_component_class_count(const struct bt_plugin *plugin) { BT_ASSERT_PRE_NON_NULL(plugin, "Plugin"); return (uint64_t) plugin->src_comp_classes->len; } -uint64_t bt_plugin_get_filter_component_class_count(struct bt_plugin *plugin) +uint64_t bt_plugin_get_filter_component_class_count(const struct bt_plugin *plugin) { BT_ASSERT_PRE_NON_NULL(plugin, "Plugin"); return (uint64_t) plugin->flt_comp_classes->len; } -uint64_t bt_plugin_get_sink_component_class_count(struct bt_plugin *plugin) +uint64_t bt_plugin_get_sink_component_class_count(const struct bt_plugin *plugin) { BT_ASSERT_PRE_NON_NULL(plugin, "Plugin"); return (uint64_t) plugin->sink_comp_classes->len; @@ -528,7 +530,7 @@ uint64_t bt_plugin_get_sink_component_class_count(struct bt_plugin *plugin) static inline struct bt_component_class *borrow_component_class_by_index( - struct bt_plugin *plugin, GPtrArray *comp_classes, + const struct bt_plugin *plugin, GPtrArray *comp_classes, uint64_t index) { BT_ASSERT_PRE_NON_NULL(plugin, "Plugin"); @@ -538,24 +540,24 @@ struct bt_component_class *borrow_component_class_by_index( struct bt_component_class_source * -bt_plugin_borrow_source_component_class_by_index( - struct bt_plugin *plugin, uint64_t index) +bt_plugin_borrow_source_component_class_by_index_const_const( + const struct bt_plugin *plugin, uint64_t index) { return (void *) borrow_component_class_by_index(plugin, plugin->src_comp_classes, index); } struct bt_component_class_filter * -bt_plugin_borrow_filter_component_class_by_index( - struct bt_plugin *plugin, uint64_t index) +bt_plugin_borrow_filter_component_class_by_index_const( + const struct bt_plugin *plugin, uint64_t index) { return (void *) borrow_component_class_by_index(plugin, plugin->flt_comp_classes, index); } struct bt_component_class_sink * -bt_plugin_borrow_sink_component_class_by_index( - struct bt_plugin *plugin, uint64_t index) +bt_plugin_borrow_sink_component_class_by_index_const( + const struct bt_plugin *plugin, uint64_t index) { return (void *) borrow_component_class_by_index(plugin, plugin->sink_comp_classes, index); @@ -563,7 +565,7 @@ bt_plugin_borrow_sink_component_class_by_index( static inline struct bt_component_class *borrow_component_class_by_name( - struct bt_plugin *plugin, GPtrArray *comp_classes, + const struct bt_plugin *plugin, GPtrArray *comp_classes, const char *name) { struct bt_component_class *comp_class = NULL; @@ -590,24 +592,24 @@ struct bt_component_class *borrow_component_class_by_name( } struct bt_component_class_source * -bt_plugin_borrow_source_component_class_by_name(struct bt_plugin *plugin, - const char *name) +bt_plugin_borrow_source_component_class_by_name_const( + const struct bt_plugin *plugin, const char *name) { return (void *) borrow_component_class_by_name(plugin, plugin->src_comp_classes, name); } struct bt_component_class_filter * -bt_plugin_borrow_filter_component_class_by_name(struct bt_plugin *plugin, - const char *name) +bt_plugin_borrow_filter_component_class_by_name_const( + const struct bt_plugin *plugin, const char *name) { return (void *) borrow_component_class_by_name(plugin, plugin->flt_comp_classes, name); } struct bt_component_class_sink * -bt_plugin_borrow_sink_component_class_by_name(struct bt_plugin *plugin, - const char *name) +bt_plugin_borrow_sink_component_class_by_name_const( + const struct bt_plugin *plugin, const char *name) { return (void *) borrow_component_class_by_name(plugin, plugin->sink_comp_classes, name); diff --git a/python-plugin-provider/python-plugin-provider.c b/python-plugin-provider/python-plugin-provider.c index 0ad6a4c3..11fae932 100644 --- a/python-plugin-provider/python-plugin-provider.c +++ b/python-plugin-provider/python-plugin-provider.c @@ -30,7 +30,7 @@ #include #include #include -#include +#include #include #include #include @@ -158,9 +158,9 @@ void fini_python(void) { } static -struct bt_plugin *bt_plugin_from_python_plugin_info(PyObject *plugin_info) +const struct bt_plugin *bt_plugin_from_python_plugin_info(PyObject *plugin_info) { - struct bt_plugin *plugin = NULL; + const struct bt_plugin *plugin = NULL; PyObject *py_name = NULL; PyObject *py_author = NULL; PyObject *py_description = NULL; @@ -391,7 +391,7 @@ G_MODULE_EXPORT struct bt_plugin_set *bt_plugin_python_create_all_from_file(const char *path) { struct bt_plugin_set *plugin_set = NULL; - struct bt_plugin *plugin = NULL; + const struct bt_plugin *plugin = NULL; PyObject *py_plugin_info = NULL; gchar *basename = NULL; size_t path_len; diff --git a/tests/lib/test-plugin-plugins/minimal.c b/tests/lib/test-plugin-plugins/minimal.c index 5cdb4e27..8611f215 100644 --- a/tests/lib/test-plugin-plugins/minimal.c +++ b/tests/lib/test-plugin-plugins/minimal.c @@ -19,7 +19,7 @@ #include #include -static enum bt_plugin_status plugin_init(struct bt_plugin *plugin) +static enum bt_plugin_status plugin_init(const struct bt_plugin *plugin) { g_setenv("BT_TEST_PLUGIN_INIT_CALLED", "1", 1); return BT_PLUGIN_STATUS_OK; diff --git a/tests/lib/test_plugin.c b/tests/lib/test_plugin.c index 4306834c..4cc11255 100644 --- a/tests/lib/test_plugin.c +++ b/tests/lib/test_plugin.c @@ -64,8 +64,8 @@ static char *get_test_plugin_path(const char *plugin_dir, static void test_minimal(const char *plugin_dir) { - struct bt_plugin_set *plugin_set; - struct bt_plugin *plugin; + const struct bt_plugin_set *plugin_set; + const struct bt_plugin *plugin; char *minimal_path = get_test_plugin_path(plugin_dir, "minimal"); BT_ASSERT(minimal_path); @@ -79,7 +79,7 @@ static void test_minimal(const char *plugin_dir) "plugin's initialization function is called during bt_plugin_create_all_from_file()"); ok(bt_plugin_set_get_plugin_count(plugin_set) == 1, "bt_plugin_create_all_from_file() returns the expected number of plugins"); - plugin = bt_plugin_set_borrow_plugin_by_index(plugin_set, 0); + plugin = bt_plugin_set_borrow_plugin_by_index_const(plugin_set, 0); ok(strcmp(bt_plugin_get_name(plugin), "test_minimal") == 0, "bt_plugin_get_name() returns the expected name"); ok(strcmp(bt_plugin_get_description(plugin), @@ -109,8 +109,8 @@ static void test_minimal(const char *plugin_dir) static void test_sfs(const char *plugin_dir) { - struct bt_plugin_set *plugin_set; - struct bt_plugin *plugin; + const struct bt_plugin_set *plugin_set; + const struct bt_plugin *plugin; struct bt_component_class_sink *sink_comp_class; struct bt_component_class_source *source_comp_class; struct bt_component_class_filter *filter_comp_class; @@ -135,7 +135,7 @@ static void test_sfs(const char *plugin_dir) plugin_set = bt_plugin_create_all_from_file(sfs_path); BT_ASSERT(plugin_set && bt_plugin_set_get_plugin_count(plugin_set) == 1); - plugin = bt_plugin_set_borrow_plugin_by_index(plugin_set, 0); + plugin = bt_plugin_set_borrow_plugin_by_index_const(plugin_set, 0); ok(bt_plugin_get_version(plugin, &major, &minor, &patch, &extra) == BT_PROPERTY_AVAILABILITY_AVAILABLE, "bt_plugin_get_version() succeeds when there's a version"); @@ -154,15 +154,15 @@ static void test_sfs(const char *plugin_dir) ok(bt_plugin_get_sink_component_class_count(plugin) == 1, "bt_plugin_get_sink_component_class_count() returns the expected value"); - source_comp_class = bt_plugin_borrow_source_component_class_by_name( + source_comp_class = bt_plugin_borrow_source_component_class_by_name_const( plugin, "source"); ok(source_comp_class, - "bt_plugin_borrow_source_component_class_by_name() finds a source component class"); + "bt_plugin_borrow_source_component_class_by_name_const() finds a source component class"); - sink_comp_class = bt_plugin_borrow_sink_component_class_by_name( + sink_comp_class = bt_plugin_borrow_sink_component_class_by_name_const( plugin, "sink"); ok(sink_comp_class, - "bt_plugin_borrow_sink_component_class_by_name() finds a sink component class"); + "bt_plugin_borrow_sink_component_class_by_name_const() finds a sink component class"); ok(strcmp(bt_component_class_get_help( bt_component_class_sink_as_component_class(sink_comp_class)), "Bacon ipsum dolor amet strip steak cupim pastrami venison shoulder.\n" @@ -171,10 +171,10 @@ static void test_sfs(const char *plugin_dir) "ground round brisket salami cupim pork bresaola turkey bacon boudin.\n") == 0, "bt_component_class_get_help() returns the expected help text"); - filter_comp_class = bt_plugin_borrow_filter_component_class_by_name( + filter_comp_class = bt_plugin_borrow_filter_component_class_by_name_const( plugin, "filter"); ok(filter_comp_class, - "bt_plugin_borrow_filter_component_class_by_name() finds a filter component class"); + "bt_plugin_borrow_filter_component_class_by_name_const() finds a filter component class"); params = bt_value_integer_create_init(23); BT_ASSERT(params); ret = bt_private_query_executor_query(query_exec, @@ -212,7 +212,7 @@ static void test_sfs(const char *plugin_dir) static void test_create_all_from_dir(const char *plugin_dir) { - struct bt_plugin_set *plugin_set; + const struct bt_plugin_set *plugin_set; diag("create from all test below"); @@ -234,7 +234,7 @@ static void test_create_all_from_dir(const char *plugin_dir) static void test_find(const char *plugin_dir) { int ret; - struct bt_plugin *plugin; + const struct bt_plugin *plugin; char *plugin_path; ok(!bt_plugin_find(NON_EXISTING_PATH),