lib: make plugin API const-correct
authorPhilippe Proulx <eeppeliteloop@gmail.com>
Tue, 4 Dec 2018 22:03:22 +0000 (17:03 -0500)
committerFrancis Deslauriers <francis.deslauriers@efficios.com>
Thu, 2 May 2019 20:50:15 +0000 (20:50 +0000)
Signed-off-by: Philippe Proulx <eeppeliteloop@gmail.com>
16 files changed:
cli/babeltrace.c
include/Makefile.am
include/babeltrace/babeltrace.h
include/babeltrace/lib-logging-internal.h
include/babeltrace/plugin/plugin-const.h [new file with mode: 0644]
include/babeltrace/plugin/plugin-dev.h
include/babeltrace/plugin/plugin-internal.h
include/babeltrace/plugin/plugin-set-const.h [new file with mode: 0644]
include/babeltrace/plugin/plugin-set.h [deleted file]
include/babeltrace/plugin/plugin.h [deleted file]
include/babeltrace/plugin/python-plugin-provider-internal.h
lib/lib-logging.c
lib/plugin/plugin.c
python-plugin-provider/python-plugin-provider.c
tests/lib/test-plugin-plugins/minimal.c
tests/lib/test_plugin.c

index 06f124615dd0621e2c4871c1946a13b109e138fe..a8b5b372ce481f2d3ccd00ed7186539134daf0cf 100644 (file)
@@ -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);
        }
index bc272807688634d9d59ba2c83b9fcd42c901c20c..7a716590a0187428ea06b3d7fcb9b0b714099bf4 100644 (file)
@@ -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"
index 67e2fac93bf90e34996fa8edca1c8701b80ea4c0..1a2f58313285817abe1734f6e8090c6d4e2f69ac 100644 (file)
@@ -89,9 +89,9 @@
 #include <babeltrace/trace-ir/trace.h>
 
 /* Plugin and plugin development API */
+#include <babeltrace/plugin/plugin-const.h>
 #include <babeltrace/plugin/plugin-dev.h>
-#include <babeltrace/plugin/plugin-set.h>
-#include <babeltrace/plugin/plugin.h>
+#include <babeltrace/plugin/plugin-set-const.h>
 
 /* Graph, component, and notification API */
 #include <babeltrace/graph/component-class-filter.h>
index 4ca610997df6bf31a38f6080493eddd443b25f0a..f7c20586930b8897157174ed50f08b4c9b6f7cad 100644 (file)
@@ -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 (file)
index 0000000..906bf06
--- /dev/null
@@ -0,0 +1,128 @@
+#ifndef BABELTRACE_PLUGIN_PLUGIN_CONST_H
+#define BABELTRACE_PLUGIN_PLUGIN_CONST_H
+
+/*
+ * Copyright 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com>
+ * Copyright 2017 Philippe Proulx <pproulx@efficios.com>
+ *
+ * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#include <stdint.h>
+#include <stddef.h>
+
+/* For bt_bool */
+#include <babeltrace/types.h>
+
+/* For enum bt_component_class_type */
+#include <babeltrace/graph/component-class.h>
+
+/* For enum bt_component_class_source */
+#include <babeltrace/graph/component-class-source.h>
+
+/* For enum bt_component_class_filter */
+#include <babeltrace/graph/component-class-filter.h>
+
+/* For enum bt_component_class_sink */
+#include <babeltrace/graph/component-class-sink.h>
+
+/* For enum bt_property_availability */
+#include <babeltrace/property.h>
+
+#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 */
index 8cbc665e318a8e61e16bd887b06b793d604ab1ae..60fa36e486f885534a125c3f2d987d06b1c708b5 100644 (file)
@@ -32,7 +32,7 @@
 #include <stdint.h>
 
 /* For enum bt_plugin_status */
-#include <babeltrace/plugin/plugin.h>
+#include <babeltrace/plugin/plugin-const.h>
 
 /* For private component class method type definitions */
 #include <babeltrace/graph/private-component-class-source.h>
@@ -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);
index 7ca57ba9a34a6e0446952e36302e174862c20a53..bd1876eb422ae4f44af332a55449db1008563800 100644 (file)
@@ -27,7 +27,7 @@
 
 #include <babeltrace/babeltrace-internal.h>
 #include <babeltrace/graph/component-class-internal.h>
-#include <babeltrace/plugin/plugin.h>
+#include <babeltrace/plugin/plugin-const.h>
 #include <babeltrace/plugin/plugin-dev.h>
 #include <babeltrace/plugin/plugin-so-internal.h>
 #include <babeltrace/object-internal.h>
diff --git a/include/babeltrace/plugin/plugin-set-const.h b/include/babeltrace/plugin/plugin-set-const.h
new file mode 100644 (file)
index 0000000..8a22fe5
--- /dev/null
@@ -0,0 +1,48 @@
+#ifndef BABELTRACE_PLUGIN_PLUGIN_SET_CONST_H
+#define BABELTRACE_PLUGIN_PLUGIN_SET_CONST_H
+
+/*
+ * Copyright 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com>
+ * Copyright 2017 Philippe Proulx <pproulx@efficios.com>
+ *
+ * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ */
+
+#include <stdint.h>
+
+#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 (file)
index 8ec2be1..0000000
+++ /dev/null
@@ -1,48 +0,0 @@
-#ifndef BABELTRACE_PLUGIN_PLUGIN_SET_H
-#define BABELTRACE_PLUGIN_PLUGIN_SET_H
-
-/*
- * Copyright 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com>
- * Copyright 2017 Philippe Proulx <pproulx@efficios.com>
- *
- * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com>
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-#include <stdint.h>
-
-#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 (file)
index 7aed187..0000000
+++ /dev/null
@@ -1,127 +0,0 @@
-#ifndef BABELTRACE_PLUGIN_PLUGIN_H
-#define BABELTRACE_PLUGIN_PLUGIN_H
-
-/*
- * Copyright 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com>
- * Copyright 2017 Philippe Proulx <pproulx@efficios.com>
- *
- * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com>
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in
- * all copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-
-#include <stdint.h>
-#include <stddef.h>
-
-/* For bt_bool */
-#include <babeltrace/types.h>
-
-/* For enum bt_component_class_type */
-#include <babeltrace/graph/component-class.h>
-
-/* For enum bt_component_class_source */
-#include <babeltrace/graph/component-class-source.h>
-
-/* For enum bt_component_class_filter */
-#include <babeltrace/graph/component-class-filter.h>
-
-/* For enum bt_component_class_sink */
-#include <babeltrace/graph/component-class-sink.h>
-
-/* For enum bt_property_availability */
-#include <babeltrace/property.h>
-
-#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 */
index 2f81e5793210b6cc8c47675b30e599d62d1885b3..c46fc3725ef4f8d8a61c5b4dbcd42a9e1fdf91f9 100644 (file)
@@ -23,7 +23,7 @@
  * SOFTWARE.
  */
 
-#include <babeltrace/plugin/plugin.h>
+#include <babeltrace/plugin/plugin-const.h>
 
 extern
 struct bt_plugin_set *bt_plugin_python_create_all_from_file(const char *path);
index c91198256e77a91dad5861f123c294eb717b265c..b595263cf60967d08b192e05c6db24e86fec91d9 100644 (file)
@@ -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];
 
index 70e99e4f033d7fd018c25e1efa546f48e7c3c55c..39d6e69fe94c9ec777e8a25efaa8dc93ff322f9b 100644 (file)
@@ -32,6 +32,7 @@
 #include <babeltrace/common-internal.h>
 #include <babeltrace/plugin/plugin-internal.h>
 #include <babeltrace/plugin/plugin-so-internal.h>
+#include <babeltrace/plugin/plugin-const.h>
 #include <babeltrace/graph/component-class.h>
 #include <babeltrace/graph/component-class-internal.h>
 #include <babeltrace/types.h>
@@ -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);
index 0ad6a4c30ad6182669ac88bf3ad065bd1aa0b577..11fae9329e12172c668838d112bb6ccbe3b36d8f 100644 (file)
@@ -30,7 +30,7 @@
 #include <babeltrace/babeltrace-internal.h>
 #include <babeltrace/compiler-internal.h>
 #include <babeltrace/object.h>
-#include <babeltrace/plugin/plugin.h>
+#include <babeltrace/plugin/plugin-const.h>
 #include <babeltrace/plugin/plugin-internal.h>
 #include <babeltrace/graph/component-class.h>
 #include <babeltrace/graph/component-class-internal.h>
@@ -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;
index 5cdb4e27a8e8f0171c7f2f040982ea961137387f..8611f215b2a14965b3fa1280344bd6bb3485ff7d 100644 (file)
@@ -19,7 +19,7 @@
 #include <stdlib.h>
 #include <glib.h>
 
-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;
index 4306834c7417324db8a48d596523d0b34a826245..4cc1125515312e56f622c4414a970ab095d6a0f3 100644 (file)
@@ -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),
This page took 0.042148 seconds and 4 git commands to generate.