X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=src%2Flib%2Fplugin%2Fplugin.c;h=8f2f6da347cb38792b108ed1c8ee3d6cb8c75dbf;hb=b14c7bf11ddef302870c4d1abf86d3a98f74cb08;hp=74b3eb51d3b1fd1a9d68de5f5d834fc8ed03f5f8;hpb=870631a2db01676b476dbee615aade0a22926bcd;p=babeltrace.git diff --git a/src/lib/plugin/plugin.c b/src/lib/plugin/plugin.c index 74b3eb51..8f2f6da3 100644 --- a/src/lib/plugin/plugin.c +++ b/src/lib/plugin/plugin.c @@ -49,7 +49,8 @@ #include "plugin-so.h" #include "lib/func-status.h" -#define PYTHON_PLUGIN_PROVIDER_FILENAME "libbabeltrace2-python-plugin-provider." G_MODULE_SUFFIX +#define PYTHON_PLUGIN_PROVIDER_FILENAME "babeltrace2-python-plugin-provider." G_MODULE_SUFFIX +#define PYTHON_PLUGIN_PROVIDER_DIR BABELTRACE_PLUGIN_PROVIDERS_DIR #define PYTHON_PLUGIN_PROVIDER_SYM_NAME bt_plugin_python_create_all_from_file #define PYTHON_PLUGIN_PROVIDER_SYM_NAME_STR G_STRINGIFY(PYTHON_PLUGIN_PROVIDER_SYM_NAME) @@ -79,14 +80,32 @@ int (*bt_plugin_python_create_all_from_file_sym)( static int init_python_plugin_provider(void) { int status = BT_FUNC_STATUS_OK; + const char *provider_dir_envvar; + static const char * const provider_dir_envvar_name = "LIBBABELTRACE2_PLUGIN_PROVIDER_DIR"; + char *provider_path = NULL; if (bt_plugin_python_create_all_from_file_sym != NULL) { goto end; } BT_LOGI_STR("Loading Python plugin provider module."); - python_plugin_provider_module = - g_module_open(PYTHON_PLUGIN_PROVIDER_FILENAME, 0); + + provider_dir_envvar = getenv(provider_dir_envvar_name); + if (provider_dir_envvar) { + provider_path = g_build_filename(provider_dir_envvar, + PYTHON_PLUGIN_PROVIDER_FILENAME, NULL); + BT_LOGI("Using `%s` environment variable to find the Python " + "plugin provider: path=\"%s\"", provider_dir_envvar_name, + provider_path); + } else { + provider_path = g_build_filename(PYTHON_PLUGIN_PROVIDER_DIR, + PYTHON_PLUGIN_PROVIDER_FILENAME, NULL); + BT_LOGI("Using default path (`%s` environment variable is not " + "set) to find the Python plugin provider: path=\"%s\"", + provider_dir_envvar_name, provider_path); + } + + python_plugin_provider_module = g_module_open(provider_path, 0); if (!python_plugin_provider_module) { /* * This is not an error. The whole point of having an @@ -94,7 +113,7 @@ int init_python_plugin_provider(void) { * missing and the Babeltrace library still works. */ BT_LOGI("Cannot open `%s`: %s: continuing without Python plugin support.", - PYTHON_PLUGIN_PROVIDER_FILENAME, g_module_error()); + provider_path, g_module_error()); goto end; } @@ -111,7 +130,7 @@ int init_python_plugin_provider(void) { "%s: continuing without Python plugin support: " "file=\"%s\", symbol=\"%s\"", g_module_error(), - PYTHON_PLUGIN_PROVIDER_FILENAME, + provider_path, PYTHON_PLUGIN_PROVIDER_SYM_NAME_STR); status = BT_FUNC_STATUS_ERROR; goto end; @@ -121,6 +140,8 @@ int init_python_plugin_provider(void) { python_plugin_provider_module); end: + g_free(provider_path); + return status; } @@ -143,17 +164,17 @@ void fini_python_plugin_provider(void) { } #endif -uint64_t bt_plugin_set_get_plugin_count(struct bt_plugin_set *plugin_set) +uint64_t bt_plugin_set_get_plugin_count(const struct bt_plugin_set *plugin_set) { - BT_ASSERT_PRE_NON_NULL(plugin_set, "Plugin set"); + BT_ASSERT_PRE_DEV_NON_NULL(plugin_set, "Plugin set"); return (uint64_t) plugin_set->plugins->len; } 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); + BT_ASSERT_PRE_DEV_NON_NULL(plugin_set, "Plugin set"); + BT_ASSERT_PRE_DEV_VALID_INDEX(index, plugin_set->plugins->len); return g_ptr_array_index(plugin_set->plugins, index); } @@ -626,31 +647,31 @@ end: const char *bt_plugin_get_name(const struct bt_plugin *plugin) { - BT_ASSERT_PRE_NON_NULL(plugin, "Plugin"); + BT_ASSERT_PRE_DEV_NON_NULL(plugin, "Plugin"); return plugin->info.name_set ? plugin->info.name->str : NULL; } const char *bt_plugin_get_author(const struct bt_plugin *plugin) { - BT_ASSERT_PRE_NON_NULL(plugin, "Plugin"); + BT_ASSERT_PRE_DEV_NON_NULL(plugin, "Plugin"); return plugin->info.author_set ? plugin->info.author->str : NULL; } const char *bt_plugin_get_license(const struct bt_plugin *plugin) { - BT_ASSERT_PRE_NON_NULL(plugin, "Plugin"); + BT_ASSERT_PRE_DEV_NON_NULL(plugin, "Plugin"); return plugin->info.license_set ? plugin->info.license->str : NULL; } const char *bt_plugin_get_path(const struct bt_plugin *plugin) { - BT_ASSERT_PRE_NON_NULL(plugin, "Plugin"); + BT_ASSERT_PRE_DEV_NON_NULL(plugin, "Plugin"); return plugin->info.path_set ? plugin->info.path->str : NULL; } const char *bt_plugin_get_description(const struct bt_plugin *plugin) { - BT_ASSERT_PRE_NON_NULL(plugin, "Plugin"); + BT_ASSERT_PRE_DEV_NON_NULL(plugin, "Plugin"); return plugin->info.description_set ? plugin->info.description->str : NULL; } @@ -662,7 +683,7 @@ enum bt_property_availability bt_plugin_get_version(const struct bt_plugin *plug enum bt_property_availability avail = BT_PROPERTY_AVAILABILITY_AVAILABLE; - BT_ASSERT_PRE_NON_NULL(plugin, "Plugin"); + BT_ASSERT_PRE_DEV_NON_NULL(plugin, "Plugin"); if (!plugin->info.version_set) { BT_LIB_LOGD("Plugin's version is not set: %!+l", plugin); @@ -692,19 +713,19 @@ end: uint64_t bt_plugin_get_source_component_class_count(const struct bt_plugin *plugin) { - BT_ASSERT_PRE_NON_NULL(plugin, "Plugin"); + BT_ASSERT_PRE_DEV_NON_NULL(plugin, "Plugin"); return (uint64_t) plugin->src_comp_classes->len; } uint64_t bt_plugin_get_filter_component_class_count(const struct bt_plugin *plugin) { - BT_ASSERT_PRE_NON_NULL(plugin, "Plugin"); + BT_ASSERT_PRE_DEV_NON_NULL(plugin, "Plugin"); return (uint64_t) plugin->flt_comp_classes->len; } uint64_t bt_plugin_get_sink_component_class_count(const struct bt_plugin *plugin) { - BT_ASSERT_PRE_NON_NULL(plugin, "Plugin"); + BT_ASSERT_PRE_DEV_NON_NULL(plugin, "Plugin"); return (uint64_t) plugin->sink_comp_classes->len; } @@ -713,8 +734,8 @@ struct bt_component_class *borrow_component_class_by_index( const struct bt_plugin *plugin, GPtrArray *comp_classes, uint64_t index) { - BT_ASSERT_PRE_NON_NULL(plugin, "Plugin"); - BT_ASSERT_PRE_VALID_INDEX(index, comp_classes->len); + BT_ASSERT_PRE_DEV_NON_NULL(plugin, "Plugin"); + BT_ASSERT_PRE_DEV_VALID_INDEX(index, comp_classes->len); return g_ptr_array_index(comp_classes, index); } @@ -750,8 +771,8 @@ struct bt_component_class *borrow_component_class_by_name( struct bt_component_class *comp_class = NULL; size_t i; - BT_ASSERT_PRE_NON_NULL(plugin, "Plugin"); - BT_ASSERT_PRE_NON_NULL(name, "Name"); + BT_ASSERT_PRE_DEV_NON_NULL(plugin, "Plugin"); + BT_ASSERT_PRE_DEV_NON_NULL(name, "Name"); for (i = 0; i < comp_classes->len; i++) { struct bt_component_class *comp_class_candidate =