2 * Copyright 2017-2018 Philippe Proulx <pproulx@efficios.com>
3 * Copyright 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com>
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the "Software"), to deal
9 * in the Software without restriction, including without limitation the rights
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 * copies of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26 #define BT_LOG_TAG "LIB/PLUGIN"
27 #include "lib/logging.h"
29 #include "common/assert.h"
30 #include "lib/assert-pre.h"
31 #include "common/macros.h"
32 #include "compat/compiler.h"
33 #include "common/common.h"
34 #include <babeltrace2/plugin/plugin-const.h>
35 #include <babeltrace2/graph/component-class-const.h>
36 #include <babeltrace2/current-thread.h>
37 #include "lib/graph/component-class.h"
38 #include <babeltrace2/types.h>
49 #include "plugin-so.h"
50 #include "lib/func-status.h"
52 #define PYTHON_PLUGIN_PROVIDER_FILENAME "babeltrace2-python-plugin-provider." G_MODULE_SUFFIX
53 #define PYTHON_PLUGIN_PROVIDER_DIR BABELTRACE_PLUGIN_PROVIDERS_DIR
54 #define PYTHON_PLUGIN_PROVIDER_SYM_NAME bt_plugin_python_create_all_from_file
55 #define PYTHON_PLUGIN_PROVIDER_SYM_NAME_STR G_STRINGIFY(PYTHON_PLUGIN_PROVIDER_SYM_NAME)
57 #define APPEND_ALL_FROM_DIR_NFDOPEN_MAX 8
59 #ifdef BT_BUILT_IN_PYTHON_PLUGIN_SUPPORT
60 #include <plugin/python-plugin-provider.h>
63 int (*bt_plugin_python_create_all_from_file_sym
)(
64 const char *path
, bool fail_on_load_error
,
65 struct bt_plugin_set
**plugin_set_out
) =
66 bt_plugin_python_create_all_from_file
;
69 enum bt_plugin_status
init_python_plugin_provider(void)
72 #else /* BT_BUILT_IN_PYTHON_PLUGIN_SUPPORT */
73 static GModule
*python_plugin_provider_module
;
76 int (*bt_plugin_python_create_all_from_file_sym
)(
77 const char *path
, bool fail_on_load_error
,
78 struct bt_plugin_set
**plugin_set_out
);
81 int init_python_plugin_provider(void) {
82 int status
= BT_FUNC_STATUS_OK
;
83 const char *provider_dir_envvar
;
84 static const char * const provider_dir_envvar_name
= "LIBBABELTRACE2_PLUGIN_PROVIDER_DIR";
85 char *provider_path
= NULL
;
87 if (bt_plugin_python_create_all_from_file_sym
!= NULL
) {
91 BT_LOGI_STR("Loading Python plugin provider module.");
93 provider_dir_envvar
= getenv(provider_dir_envvar_name
);
94 if (provider_dir_envvar
) {
95 provider_path
= g_build_filename(provider_dir_envvar
,
96 PYTHON_PLUGIN_PROVIDER_FILENAME
, NULL
);
97 BT_LOGI("Using `%s` environment variable to find the Python "
98 "plugin provider: path=\"%s\"", provider_dir_envvar_name
,
101 provider_path
= g_build_filename(PYTHON_PLUGIN_PROVIDER_DIR
,
102 PYTHON_PLUGIN_PROVIDER_FILENAME
, NULL
);
103 BT_LOGI("Using default path (`%s` environment variable is not "
104 "set) to find the Python plugin provider: path=\"%s\"",
105 provider_dir_envvar_name
, provider_path
);
108 python_plugin_provider_module
= g_module_open(provider_path
, 0);
109 if (!python_plugin_provider_module
) {
111 * This is not an error. The whole point of having an
112 * external Python plugin provider is that it can be
113 * missing and the Babeltrace library still works.
115 BT_LOGI("Cannot open `%s`: %s: continuing without Python plugin support.",
116 provider_path
, g_module_error());
120 if (!g_module_symbol(python_plugin_provider_module
,
121 PYTHON_PLUGIN_PROVIDER_SYM_NAME_STR
,
122 (gpointer
) &bt_plugin_python_create_all_from_file_sym
)) {
124 * This is an error because, since we found the Python
125 * plugin provider shared object, we expect this symbol
128 BT_LIB_LOGE_APPEND_CAUSE(
129 "Cannot find the Python plugin provider loading symbol: "
130 "%s: continuing without Python plugin support: "
131 "file=\"%s\", symbol=\"%s\"",
134 PYTHON_PLUGIN_PROVIDER_SYM_NAME_STR
);
135 status
= BT_FUNC_STATUS_ERROR
;
139 BT_LOGI("Loaded Python plugin provider module: addr=%p",
140 python_plugin_provider_module
);
143 g_free(provider_path
);
148 __attribute__((destructor
)) static
149 void fini_python_plugin_provider(void) {
150 if (python_plugin_provider_module
) {
151 BT_LOGI("Unloading Python plugin provider module.");
153 if (!g_module_close(python_plugin_provider_module
)) {
155 * This occurs when the library is finalized: do
156 * NOT append an error cause.
158 BT_LOGE("Failed to close the Python plugin provider module: %s.",
162 python_plugin_provider_module
= NULL
;
167 uint64_t bt_plugin_set_get_plugin_count(const struct bt_plugin_set
*plugin_set
)
169 BT_ASSERT_PRE_DEV_NON_NULL(plugin_set
, "Plugin set");
170 return (uint64_t) plugin_set
->plugins
->len
;
173 const struct bt_plugin
*bt_plugin_set_borrow_plugin_by_index_const(
174 const struct bt_plugin_set
*plugin_set
, uint64_t index
)
176 BT_ASSERT_PRE_DEV_NON_NULL(plugin_set
, "Plugin set");
177 BT_ASSERT_PRE_DEV_VALID_INDEX(index
, plugin_set
->plugins
->len
);
178 return g_ptr_array_index(plugin_set
->plugins
, index
);
181 enum bt_plugin_find_all_from_static_status
bt_plugin_find_all_from_static(
182 bt_bool fail_on_load_error
,
183 const struct bt_plugin_set
**plugin_set_out
)
185 /* bt_plugin_so_create_all_from_static() logs errors */
186 return bt_plugin_so_create_all_from_static(fail_on_load_error
,
187 (void *) plugin_set_out
);
190 enum bt_plugin_find_all_from_file_status
bt_plugin_find_all_from_file(
191 const char *path
, bt_bool fail_on_load_error
,
192 const struct bt_plugin_set
**plugin_set_out
)
194 enum bt_plugin_find_all_from_file_status status
;
196 BT_ASSERT_PRE_NON_NULL(path
, "Path");
197 BT_ASSERT_PRE_NON_NULL(path
, "Plugin set (output)");
198 BT_LOGI("Creating plugins from file: path=\"%s\"", path
);
200 /* Try shared object plugins */
201 status
= bt_plugin_so_create_all_from_file(path
, fail_on_load_error
,
202 (void *) plugin_set_out
);
203 if (status
== BT_FUNC_STATUS_OK
) {
204 BT_ASSERT(*plugin_set_out
);
205 BT_ASSERT((*plugin_set_out
)->plugins
->len
> 0);
207 } else if (status
< 0) {
208 BT_ASSERT(!*plugin_set_out
);
212 BT_ASSERT(status
== BT_FUNC_STATUS_NOT_FOUND
);
213 BT_ASSERT(!*plugin_set_out
);
215 /* Try Python plugins if support is available */
216 status
= init_python_plugin_provider();
218 /* init_python_plugin_provider() logs errors */
222 BT_ASSERT(status
== BT_FUNC_STATUS_OK
);
223 status
= BT_FUNC_STATUS_NOT_FOUND
;
225 if (bt_plugin_python_create_all_from_file_sym
) {
226 /* Python plugin provider exists */
227 status
= bt_plugin_python_create_all_from_file_sym(path
,
228 fail_on_load_error
, (void *) plugin_set_out
);
229 if (status
== BT_FUNC_STATUS_OK
) {
230 BT_ASSERT(*plugin_set_out
);
231 BT_ASSERT((*plugin_set_out
)->plugins
->len
> 0);
233 } else if (status
< 0) {
235 * bt_plugin_python_create_all_from_file_sym()
236 * handles `fail_on_load_error` itself, so this
239 BT_ASSERT(!*plugin_set_out
);
243 BT_ASSERT(status
== BT_FUNC_STATUS_NOT_FOUND
);
244 BT_ASSERT(!*plugin_set_out
);
248 if (status
== BT_FUNC_STATUS_OK
) {
249 BT_LOGI("Created %u plugins from file: "
250 "path=\"%s\", count=%u, plugin-set-addr=%p",
251 (*plugin_set_out
)->plugins
->len
, path
,
252 (*plugin_set_out
)->plugins
->len
,
254 } else if (status
== BT_FUNC_STATUS_NOT_FOUND
) {
255 BT_LOGI("Found no plugins in file: path=\"%s\"", path
);
261 static void destroy_gstring(void *data
)
263 g_string_free(data
, TRUE
);
266 enum bt_plugin_find_status
bt_plugin_find(const char *plugin_name
,
267 bt_bool fail_on_load_error
, const struct bt_plugin
**plugin_out
)
269 const char *system_plugin_dir
;
270 char *home_plugin_dir
= NULL
;
272 const struct bt_plugin
*plugin
= NULL
;
273 const struct bt_plugin_set
*plugin_set
= NULL
;
274 GPtrArray
*dirs
= NULL
;
276 int status
= BT_FUNC_STATUS_OK
;
279 BT_ASSERT_PRE_NON_NULL(plugin_name
, "Name");
280 BT_ASSERT_PRE_NON_NULL(plugin_out
, "Plugin (output)");
281 BT_LOGI("Finding named plugin in standard directories and built-in plugins: "
282 "name=\"%s\"", plugin_name
);
283 dirs
= g_ptr_array_new_with_free_func((GDestroyNotify
) destroy_gstring
);
285 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GPtrArray.");
286 status
= BT_FUNC_STATUS_MEMORY_ERROR
;
293 * 1. BABELTRACE_PLUGIN_PATH environment variable
294 * (colon-separated list of directories)
295 * 2. ~/.local/lib/babeltrace2/plugins
296 * 3. Default system directory for Babeltrace plugins, usually
297 * /usr/lib/babeltrace2/plugins or
298 * /usr/local/lib/babeltrace2/plugins if installed
300 * 4. Built-in plugins (static)
302 * Directories are searched non-recursively.
304 envvar
= getenv("BABELTRACE_PLUGIN_PATH");
306 ret
= bt_common_append_plugin_path_dirs(envvar
, dirs
);
308 BT_LIB_LOGE_APPEND_CAUSE(
309 "Failed to append plugin path to array of directories.");
310 status
= BT_FUNC_STATUS_MEMORY_ERROR
;
315 home_plugin_dir
= bt_common_get_home_plugin_path(BT_LOG_OUTPUT_LEVEL
);
316 if (home_plugin_dir
) {
317 GString
*home_plugin_dir_str
= g_string_new(home_plugin_dir
);
319 if (!home_plugin_dir_str
) {
320 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GString.");
321 status
= BT_FUNC_STATUS_MEMORY_ERROR
;
325 g_ptr_array_add(dirs
, home_plugin_dir_str
);
328 system_plugin_dir
= bt_common_get_system_plugin_path();
329 if (system_plugin_dir
) {
330 GString
*system_plugin_dir_str
=
331 g_string_new(system_plugin_dir
);
333 if (!system_plugin_dir_str
) {
334 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GString.");
335 status
= BT_FUNC_STATUS_MEMORY_ERROR
;
339 g_ptr_array_add(dirs
, system_plugin_dir_str
);
342 for (i
= 0; i
< dirs
->len
; i
++) {
343 GString
*dir
= g_ptr_array_index(dirs
, i
);
345 BT_OBJECT_PUT_REF_AND_RESET(plugin_set
);
348 * Skip this if the directory does not exist because
349 * bt_plugin_find_all_from_dir() would log a warning.
351 if (!g_file_test(dir
->str
, G_FILE_TEST_IS_DIR
)) {
352 BT_LOGI("Skipping nonexistent directory path: "
353 "path=\"%s\"", dir
->str
);
357 /* bt_plugin_find_all_from_dir() logs details/errors */
358 status
= bt_plugin_find_all_from_dir(dir
->str
, BT_FALSE
,
359 fail_on_load_error
, &plugin_set
);
361 BT_ASSERT(!plugin_set
);
363 } else if (status
== BT_FUNC_STATUS_NOT_FOUND
) {
364 BT_ASSERT(!plugin_set
);
365 BT_LOGI("No plugins found in directory: path=\"%s\"",
370 BT_ASSERT(status
== BT_FUNC_STATUS_OK
);
371 BT_ASSERT(plugin_set
);
373 for (j
= 0; j
< plugin_set
->plugins
->len
; j
++) {
374 const struct bt_plugin
*candidate_plugin
=
375 g_ptr_array_index(plugin_set
->plugins
, j
);
377 if (strcmp(bt_plugin_get_name(candidate_plugin
),
379 BT_LOGI("Plugin found in directory: name=\"%s\", path=\"%s\"",
380 plugin_name
, dir
->str
);
381 *plugin_out
= candidate_plugin
;
382 bt_object_get_no_null_check(*plugin_out
);
387 BT_LOGI("Plugin not found in directory: name=\"%s\", path=\"%s\"",
388 plugin_name
, dir
->str
);
391 BT_OBJECT_PUT_REF_AND_RESET(plugin_set
);
392 status
= bt_plugin_find_all_from_static(fail_on_load_error
,
395 BT_ASSERT(!plugin_set
);
397 } else if (status
== BT_FUNC_STATUS_NOT_FOUND
) {
398 BT_ASSERT(!plugin_set
);
399 BT_LOGI_STR("No plugins found in built-in plugins.");
403 BT_ASSERT(status
== BT_FUNC_STATUS_OK
);
404 BT_ASSERT(plugin_set
);
406 for (j
= 0; j
< plugin_set
->plugins
->len
; j
++) {
407 const struct bt_plugin
*candidate_plugin
=
408 g_ptr_array_index(plugin_set
->plugins
, j
);
410 if (strcmp(bt_plugin_get_name(candidate_plugin
),
412 BT_LOGI("Plugin found in built-in plugins: "
413 "name=\"%s\"", plugin_name
);
414 *plugin_out
= candidate_plugin
;
415 bt_object_get_no_null_check(*plugin_out
);
420 status
= BT_FUNC_STATUS_NOT_FOUND
;
423 free(home_plugin_dir
);
424 bt_object_put_ref(plugin_set
);
427 g_ptr_array_free(dirs
, TRUE
);
430 if (status
== BT_FUNC_STATUS_OK
) {
431 BT_LIB_LOGI("Found plugin in standard directories and built-in plugins: "
433 } else if (status
== BT_FUNC_STATUS_NOT_FOUND
) {
434 BT_LOGI("No plugin found in standard directories and built-in plugins: "
435 "name=\"%s\"", plugin_name
);
442 pthread_mutex_t lock
;
443 struct bt_plugin_set
*plugin_set
;
445 bool fail_on_load_error
;
447 } append_all_from_dir_info
= {
448 .lock
= PTHREAD_MUTEX_INITIALIZER
452 int nftw_append_all_from_dir(const char *file
,
453 const struct stat
*sb
, int flag
, struct FTW
*s
)
456 const char *name
= file
+ s
->base
;
458 /* Check for recursion */
459 if (!append_all_from_dir_info
.recurse
&& s
->level
> 1) {
466 const struct bt_plugin_set
*plugins_from_file
= NULL
;
468 if (name
[0] == '.') {
469 /* Skip hidden files */
470 BT_LOGI("Skipping hidden file: path=\"%s\"", file
);
474 append_all_from_dir_info
.status
=
475 bt_plugin_find_all_from_file(file
,
476 append_all_from_dir_info
.fail_on_load_error
,
478 if (append_all_from_dir_info
.status
== BT_FUNC_STATUS_OK
) {
481 BT_ASSERT(plugins_from_file
);
483 for (j
= 0; j
< plugins_from_file
->plugins
->len
; j
++) {
484 struct bt_plugin
*plugin
=
485 g_ptr_array_index(plugins_from_file
->plugins
, j
);
487 BT_LIB_LOGI("Adding plugin to plugin set: "
488 "plugin-path=\"%s\", %![plugin-]+l",
490 bt_plugin_set_add_plugin(
491 append_all_from_dir_info
.plugin_set
,
495 bt_object_put_ref(plugins_from_file
);
497 } else if (append_all_from_dir_info
.status
< 0) {
498 /* bt_plugin_find_all_from_file() logs errors */
499 BT_ASSERT(!plugins_from_file
);
505 * Not found in this file: this is no an error; continue
506 * walking the directories.
508 BT_ASSERT(!plugins_from_file
);
509 BT_ASSERT(append_all_from_dir_info
.status
==
510 BT_FUNC_STATUS_NOT_FOUND
);
514 /* Continue to next file / directory. */
515 BT_LOGI("Cannot enter directory: continuing: path=\"%s\"", file
);
518 /* Continue to next file / directory. */
519 BT_LOGI("Cannot get file information: continuing: path=\"%s\"", file
);
528 int bt_plugin_create_append_all_from_dir(struct bt_plugin_set
*plugin_set
,
529 const char *path
, bt_bool recurse
, bt_bool fail_on_load_error
)
531 int nftw_flags
= FTW_PHYS
;
536 BT_ASSERT(plugin_set
);
538 BT_ASSERT(strlen(path
) < PATH_MAX
);
541 * Make sure that path exists and is accessible.
542 * This is necessary since Cygwin implementation of nftw() is not POSIX
543 * compliant. Cygwin nftw() implementation does not fail on non-existent
544 * path with ENOENT. Instead, it flags the directory as FTW_NS. FTW_NS during
545 * nftw_append_all_from_dir is not treated as an error since we are
546 * traversing the tree for plugin discovery.
548 if (stat(path
, &sb
)) {
549 BT_LOGW_ERRNO("Cannot open directory",
550 ": path=\"%s\", recurse=%d",
552 (void) BT_CURRENT_THREAD_ERROR_APPEND_CAUSE_FROM_UNKNOWN(
553 "Babeltrace library",
554 "Cannot open directory: path=\"%s\", recurse=%d",
556 status
= BT_FUNC_STATUS_ERROR
;
560 pthread_mutex_lock(&append_all_from_dir_info
.lock
);
561 append_all_from_dir_info
.plugin_set
= plugin_set
;
562 append_all_from_dir_info
.recurse
= recurse
;
563 append_all_from_dir_info
.status
= BT_FUNC_STATUS_OK
;
564 append_all_from_dir_info
.fail_on_load_error
= fail_on_load_error
;
565 ret
= nftw(path
, nftw_append_all_from_dir
,
566 APPEND_ALL_FROM_DIR_NFDOPEN_MAX
, nftw_flags
);
567 append_all_from_dir_info
.plugin_set
= NULL
;
568 status
= append_all_from_dir_info
.status
;
569 pthread_mutex_unlock(&append_all_from_dir_info
.lock
);
571 BT_LIB_LOGW_APPEND_CAUSE("Failed to walk directory",
572 ": path=\"%s\", recurse=%d",
574 status
= BT_FUNC_STATUS_ERROR
;
578 if (status
== BT_FUNC_STATUS_NOT_FOUND
) {
580 * We're just appending in this function; even if
581 * nothing was found, it's still okay from the caller's
584 status
= BT_FUNC_STATUS_OK
;
591 enum bt_plugin_find_all_from_dir_status
bt_plugin_find_all_from_dir(
592 const char *path
, bt_bool recurse
, bt_bool fail_on_load_error
,
593 const struct bt_plugin_set
**plugin_set_out
)
595 enum bt_plugin_find_all_from_dir_status status
=
598 BT_ASSERT_PRE_NON_NULL(plugin_set_out
, "Plugin set (output)");
599 BT_LOGI("Creating all plugins in directory: path=\"%s\", recurse=%d",
601 *plugin_set_out
= bt_plugin_set_create();
602 if (!*plugin_set_out
) {
603 BT_LIB_LOGE_APPEND_CAUSE("Cannot create empty plugin set.");
604 status
= BT_FUNC_STATUS_MEMORY_ERROR
;
609 * Append found plugins to array (never returns
610 * `BT_FUNC_STATUS_NOT_FOUND`)
612 status
= bt_plugin_create_append_all_from_dir((void *) *plugin_set_out
,
613 path
, recurse
, fail_on_load_error
);
616 * bt_plugin_create_append_all_from_dir() handles
617 * `fail_on_load_error`, so this is a "real" error.
619 BT_LIB_LOGE_APPEND_CAUSE(
620 "Cannot append plugins found in directory: "
621 "path=\"%s\", status=%s",
622 path
, bt_common_func_status_string(status
));
626 BT_ASSERT(status
== BT_FUNC_STATUS_OK
);
628 if ((*plugin_set_out
)->plugins
->len
== 0) {
629 /* Nothing was appended: not found */
630 BT_LOGI("No plugins found in directory: path=\"%s\"", path
);
631 status
= BT_FUNC_STATUS_NOT_FOUND
;
635 BT_LOGI("Created %u plugins from directory: count=%u, path=\"%s\"",
636 (*plugin_set_out
)->plugins
->len
,
637 (*plugin_set_out
)->plugins
->len
, path
);
641 BT_ASSERT(status
!= BT_FUNC_STATUS_OK
);
642 BT_OBJECT_PUT_REF_AND_RESET(*plugin_set_out
);
648 const char *bt_plugin_get_name(const struct bt_plugin
*plugin
)
650 BT_ASSERT_PRE_DEV_NON_NULL(plugin
, "Plugin");
651 return plugin
->info
.name_set
? plugin
->info
.name
->str
: NULL
;
654 const char *bt_plugin_get_author(const struct bt_plugin
*plugin
)
656 BT_ASSERT_PRE_DEV_NON_NULL(plugin
, "Plugin");
657 return plugin
->info
.author_set
? plugin
->info
.author
->str
: NULL
;
660 const char *bt_plugin_get_license(const struct bt_plugin
*plugin
)
662 BT_ASSERT_PRE_DEV_NON_NULL(plugin
, "Plugin");
663 return plugin
->info
.license_set
? plugin
->info
.license
->str
: NULL
;
666 const char *bt_plugin_get_path(const struct bt_plugin
*plugin
)
668 BT_ASSERT_PRE_DEV_NON_NULL(plugin
, "Plugin");
669 return plugin
->info
.path_set
? plugin
->info
.path
->str
: NULL
;
672 const char *bt_plugin_get_description(const struct bt_plugin
*plugin
)
674 BT_ASSERT_PRE_DEV_NON_NULL(plugin
, "Plugin");
675 return plugin
->info
.description_set
?
676 plugin
->info
.description
->str
: NULL
;
679 enum bt_property_availability
bt_plugin_get_version(const struct bt_plugin
*plugin
,
680 unsigned int *major
, unsigned int *minor
, unsigned int *patch
,
683 enum bt_property_availability avail
=
684 BT_PROPERTY_AVAILABILITY_AVAILABLE
;
686 BT_ASSERT_PRE_DEV_NON_NULL(plugin
, "Plugin");
688 if (!plugin
->info
.version_set
) {
689 BT_LIB_LOGD("Plugin's version is not set: %!+l", plugin
);
690 avail
= BT_PROPERTY_AVAILABILITY_NOT_AVAILABLE
;
695 *major
= plugin
->info
.version
.major
;
699 *minor
= plugin
->info
.version
.minor
;
703 *patch
= plugin
->info
.version
.patch
;
707 *extra
= plugin
->info
.version
.extra
->str
;
714 uint64_t bt_plugin_get_source_component_class_count(const struct bt_plugin
*plugin
)
716 BT_ASSERT_PRE_DEV_NON_NULL(plugin
, "Plugin");
717 return (uint64_t) plugin
->src_comp_classes
->len
;
720 uint64_t bt_plugin_get_filter_component_class_count(const struct bt_plugin
*plugin
)
722 BT_ASSERT_PRE_DEV_NON_NULL(plugin
, "Plugin");
723 return (uint64_t) plugin
->flt_comp_classes
->len
;
726 uint64_t bt_plugin_get_sink_component_class_count(const struct bt_plugin
*plugin
)
728 BT_ASSERT_PRE_DEV_NON_NULL(plugin
, "Plugin");
729 return (uint64_t) plugin
->sink_comp_classes
->len
;
733 struct bt_component_class
*borrow_component_class_by_index(
734 const struct bt_plugin
*plugin
, GPtrArray
*comp_classes
,
737 BT_ASSERT_PRE_DEV_NON_NULL(plugin
, "Plugin");
738 BT_ASSERT_PRE_DEV_VALID_INDEX(index
, comp_classes
->len
);
739 return g_ptr_array_index(comp_classes
, index
);
742 const struct bt_component_class_source
*
743 bt_plugin_borrow_source_component_class_by_index_const(
744 const struct bt_plugin
*plugin
, uint64_t index
)
746 return (const void *) borrow_component_class_by_index(plugin
,
747 plugin
->src_comp_classes
, index
);
750 const struct bt_component_class_filter
*
751 bt_plugin_borrow_filter_component_class_by_index_const(
752 const struct bt_plugin
*plugin
, uint64_t index
)
754 return (const void *) borrow_component_class_by_index(plugin
,
755 plugin
->flt_comp_classes
, index
);
758 const struct bt_component_class_sink
*
759 bt_plugin_borrow_sink_component_class_by_index_const(
760 const struct bt_plugin
*plugin
, uint64_t index
)
762 return (const void *) borrow_component_class_by_index(plugin
,
763 plugin
->sink_comp_classes
, index
);
767 struct bt_component_class
*borrow_component_class_by_name(
768 const struct bt_plugin
*plugin
, GPtrArray
*comp_classes
,
771 struct bt_component_class
*comp_class
= NULL
;
774 BT_ASSERT_PRE_DEV_NON_NULL(plugin
, "Plugin");
775 BT_ASSERT_PRE_DEV_NON_NULL(name
, "Name");
777 for (i
= 0; i
< comp_classes
->len
; i
++) {
778 struct bt_component_class
*comp_class_candidate
=
779 g_ptr_array_index(comp_classes
, i
);
780 const char *comp_class_cand_name
=
781 bt_component_class_get_name(comp_class_candidate
);
783 BT_ASSERT(comp_class_cand_name
);
785 if (strcmp(name
, comp_class_cand_name
) == 0) {
786 comp_class
= comp_class_candidate
;
794 const struct bt_component_class_source
*
795 bt_plugin_borrow_source_component_class_by_name_const(
796 const struct bt_plugin
*plugin
, const char *name
)
798 return (const void *) borrow_component_class_by_name(plugin
,
799 plugin
->src_comp_classes
, name
);
802 const struct bt_component_class_filter
*
803 bt_plugin_borrow_filter_component_class_by_name_const(
804 const struct bt_plugin
*plugin
, const char *name
)
806 return (const void *) borrow_component_class_by_name(plugin
,
807 plugin
->flt_comp_classes
, name
);
810 const struct bt_component_class_sink
*
811 bt_plugin_borrow_sink_component_class_by_name_const(
812 const struct bt_plugin
*plugin
, const char *name
)
814 return (const void *) borrow_component_class_by_name(plugin
,
815 plugin
->sink_comp_classes
, name
);
818 void bt_plugin_get_ref(const struct bt_plugin
*plugin
)
820 bt_object_get_ref(plugin
);
823 void bt_plugin_put_ref(const struct bt_plugin
*plugin
)
825 bt_object_put_ref(plugin
);
828 void bt_plugin_set_get_ref(const struct bt_plugin_set
*plugin_set
)
830 bt_object_get_ref(plugin_set
);
833 void bt_plugin_set_put_ref(const struct bt_plugin_set
*plugin_set
)
835 bt_object_put_ref(plugin_set
);