2 * SPDX-License-Identifier: MIT
4 * Copyright 2017-2018 Philippe Proulx <pproulx@efficios.com>
5 * Copyright 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com>
8 #define BT_LOG_TAG "LIB/PLUGIN"
9 #include "lib/logging.h"
11 #include "common/assert.h"
12 #include "lib/assert-cond.h"
13 #include "common/macros.h"
14 #include "compat/compiler.h"
15 #include "compat/limits.h"
16 #include "common/common.h"
17 #include <babeltrace2/plugin/plugin-loading.h>
18 #include <babeltrace2/graph/component-class.h>
19 #include <babeltrace2/error-reporting.h>
20 #include "lib/graph/component-class.h"
21 #include <babeltrace2/types.h>
32 #include "plugin-so.h"
33 #include "lib/func-status.h"
35 #define PYTHON_PLUGIN_PROVIDER_FILENAME "babeltrace2-python-plugin-provider." G_MODULE_SUFFIX
36 #define PYTHON_PLUGIN_PROVIDER_DIR BABELTRACE_PLUGIN_PROVIDERS_DIR
37 #define PYTHON_PLUGIN_PROVIDER_SYM_NAME bt_plugin_python_create_all_from_file
38 #define PYTHON_PLUGIN_PROVIDER_SYM_NAME_STR G_STRINGIFY(PYTHON_PLUGIN_PROVIDER_SYM_NAME)
40 #define APPEND_ALL_FROM_DIR_NFDOPEN_MAX 8
42 /* Declare here to make sure definition in both ifdef branches are in sync. */
44 int init_python_plugin_provider(void);
45 typedef int (*create_all_from_file_sym_type
)(
47 bool fail_on_load_error
,
48 struct bt_plugin_set
**plugin_set_out
);
50 #ifdef BT_BUILT_IN_PYTHON_PLUGIN_SUPPORT
51 #include <plugin/python-plugin-provider.h>
54 create_all_from_file_sym_type
55 bt_plugin_python_create_all_from_file_sym
=
56 bt_plugin_python_create_all_from_file
;
59 int init_python_plugin_provider(void)
62 #else /* BT_BUILT_IN_PYTHON_PLUGIN_SUPPORT */
63 static GModule
*python_plugin_provider_module
;
66 create_all_from_file_sym_type bt_plugin_python_create_all_from_file_sym
;
69 int init_python_plugin_provider(void) {
70 int status
= BT_FUNC_STATUS_OK
;
71 const char *provider_dir_envvar
;
72 static const char * const provider_dir_envvar_name
= "LIBBABELTRACE2_PLUGIN_PROVIDER_DIR";
73 char *provider_path
= NULL
;
75 if (bt_plugin_python_create_all_from_file_sym
) {
79 BT_LOGI_STR("Loading Python plugin provider module.");
81 provider_dir_envvar
= getenv(provider_dir_envvar_name
);
82 if (provider_dir_envvar
) {
83 provider_path
= g_build_filename(provider_dir_envvar
,
84 PYTHON_PLUGIN_PROVIDER_FILENAME
, NULL
);
85 BT_LOGI("Using `%s` environment variable to find the Python "
86 "plugin provider: path=\"%s\"", provider_dir_envvar_name
,
89 provider_path
= g_build_filename(PYTHON_PLUGIN_PROVIDER_DIR
,
90 PYTHON_PLUGIN_PROVIDER_FILENAME
, NULL
);
91 BT_LOGI("Using default path (`%s` environment variable is not "
92 "set) to find the Python plugin provider: path=\"%s\"",
93 provider_dir_envvar_name
, provider_path
);
96 python_plugin_provider_module
= g_module_open(provider_path
, 0);
97 if (!python_plugin_provider_module
) {
99 * This is not an error. The whole point of having an
100 * external Python plugin provider is that it can be
101 * missing and the Babeltrace library still works.
103 BT_LOGI("Cannot open `%s`: %s: continuing without Python plugin support.",
104 provider_path
, g_module_error());
108 if (!g_module_symbol(python_plugin_provider_module
,
109 PYTHON_PLUGIN_PROVIDER_SYM_NAME_STR
,
110 (gpointer
) &bt_plugin_python_create_all_from_file_sym
)) {
112 * This is an error because, since we found the Python
113 * plugin provider shared object, we expect this symbol
116 BT_LIB_LOGE_APPEND_CAUSE(
117 "Cannot find the Python plugin provider loading symbol: "
118 "%s: continuing without Python plugin support: "
119 "file=\"%s\", symbol=\"%s\"",
122 PYTHON_PLUGIN_PROVIDER_SYM_NAME_STR
);
123 status
= BT_FUNC_STATUS_ERROR
;
127 BT_LOGI("Loaded Python plugin provider module: addr=%p",
128 python_plugin_provider_module
);
131 g_free(provider_path
);
136 __attribute__((destructor
)) static
137 void fini_python_plugin_provider(void) {
138 if (python_plugin_provider_module
) {
139 BT_LOGI("Unloading Python plugin provider module.");
141 if (!g_module_close(python_plugin_provider_module
)) {
143 * This occurs when the library is finalized: do
144 * NOT append an error cause.
146 BT_LOGE("Failed to close the Python plugin provider module: %s.",
150 python_plugin_provider_module
= NULL
;
156 uint64_t bt_plugin_set_get_plugin_count(const struct bt_plugin_set
*plugin_set
)
158 BT_ASSERT_PRE_DEV_PLUGIN_SET_NON_NULL(plugin_set
);
159 return (uint64_t) plugin_set
->plugins
->len
;
163 const struct bt_plugin
*bt_plugin_set_borrow_plugin_by_index_const(
164 const struct bt_plugin_set
*plugin_set
, uint64_t index
)
166 BT_ASSERT_PRE_DEV_PLUGIN_SET_NON_NULL(plugin_set
);
167 BT_ASSERT_PRE_DEV_VALID_INDEX(index
, plugin_set
->plugins
->len
);
168 return g_ptr_array_index(plugin_set
->plugins
, index
);
172 enum bt_plugin_find_all_from_static_status
bt_plugin_find_all_from_static(
173 bt_bool fail_on_load_error
,
174 const struct bt_plugin_set
**plugin_set_out
)
176 BT_ASSERT_PRE_NO_ERROR();
178 /* bt_plugin_so_create_all_from_static() logs errors */
179 return bt_plugin_so_create_all_from_static(fail_on_load_error
,
180 (void *) plugin_set_out
);
184 enum bt_plugin_find_all_from_file_status
bt_plugin_find_all_from_file(
185 const char *path
, bt_bool fail_on_load_error
,
186 const struct bt_plugin_set
**plugin_set_out
)
188 enum bt_plugin_find_all_from_file_status status
;
190 BT_ASSERT_PRE_NO_ERROR();
191 BT_ASSERT_PRE_NON_NULL("path", path
, "Path");
192 BT_ASSERT_PRE_PLUGIN_SET_OUT_NON_NULL(plugin_set_out
);
193 BT_LOGI("Creating plugins from file: path=\"%s\"", path
);
195 /* Try shared object plugins */
196 status
= bt_plugin_so_create_all_from_file(path
, fail_on_load_error
,
197 (void *) plugin_set_out
);
198 if (status
== BT_FUNC_STATUS_OK
) {
199 BT_ASSERT(*plugin_set_out
);
200 BT_ASSERT((*plugin_set_out
)->plugins
->len
> 0);
202 } else if (status
< 0) {
203 BT_ASSERT(!*plugin_set_out
);
207 BT_ASSERT(status
== BT_FUNC_STATUS_NOT_FOUND
);
208 BT_ASSERT(!*plugin_set_out
);
210 /* Try Python plugins if support is available */
211 status
= init_python_plugin_provider();
213 /* init_python_plugin_provider() logs errors */
217 BT_ASSERT(status
== BT_FUNC_STATUS_OK
);
218 status
= BT_FUNC_STATUS_NOT_FOUND
;
220 if (bt_plugin_python_create_all_from_file_sym
) {
221 /* Python plugin provider exists */
222 status
= bt_plugin_python_create_all_from_file_sym(path
,
223 fail_on_load_error
, (void *) plugin_set_out
);
224 if (status
== BT_FUNC_STATUS_OK
) {
225 BT_ASSERT(*plugin_set_out
);
226 BT_ASSERT((*plugin_set_out
)->plugins
->len
> 0);
228 } else if (status
< 0) {
230 * bt_plugin_python_create_all_from_file_sym()
231 * handles `fail_on_load_error` itself, so this
234 BT_ASSERT(!*plugin_set_out
);
238 BT_ASSERT(status
== BT_FUNC_STATUS_NOT_FOUND
);
239 BT_ASSERT(!*plugin_set_out
);
243 if (status
== BT_FUNC_STATUS_OK
) {
244 BT_LOGI("Created %u plugins from file: "
245 "path=\"%s\", count=%u, plugin-set-addr=%p",
246 (*plugin_set_out
)->plugins
->len
, path
,
247 (*plugin_set_out
)->plugins
->len
,
249 } else if (status
== BT_FUNC_STATUS_NOT_FOUND
) {
250 BT_LOGI("Found no plugins in file: path=\"%s\"", path
);
257 void destroy_gstring(void *data
)
259 g_string_free(data
, TRUE
);
263 enum bt_plugin_find_all_status
bt_plugin_find_all(bt_bool find_in_std_env_var
,
264 bt_bool find_in_user_dir
, bt_bool find_in_sys_dir
,
265 bt_bool find_in_static
, bt_bool fail_on_load_error
,
266 const struct bt_plugin_set
**plugin_set_out
)
268 char *home_plugin_dir
= NULL
;
269 const struct bt_plugin_set
*plugin_set
= NULL
;
270 GPtrArray
*dirs
= NULL
;
272 int status
= BT_FUNC_STATUS_OK
;
273 uint64_t dir_i
, plugin_i
;
275 BT_ASSERT_PRE_NO_ERROR();
276 BT_ASSERT_PRE_PLUGIN_SET_OUT_NON_NULL(plugin_set_out
);
277 BT_LOGI("Finding all plugins in standard directories and built-in plugins: "
278 "find-in-std-env-var=%d, find-in-user-dir=%d, "
279 "find-in-sys-dir=%d, find-in-static=%d",
280 find_in_std_env_var
, find_in_user_dir
, find_in_sys_dir
,
282 dirs
= g_ptr_array_new_with_free_func((GDestroyNotify
) destroy_gstring
);
284 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GPtrArray.");
285 status
= BT_FUNC_STATUS_MEMORY_ERROR
;
289 *plugin_set_out
= bt_plugin_set_create();
290 if (!*plugin_set_out
) {
291 BT_LIB_LOGE_APPEND_CAUSE("Cannot create empty plugin set.");
292 status
= BT_FUNC_STATUS_MEMORY_ERROR
;
299 * 1. `BABELTRACE_PLUGIN_PATH` environment variable
300 * (colon-separated list of directories)
301 * 2. `~/.local/lib/babeltrace2/plugins`
302 * 3. Default system directory for Babeltrace plugins, usually
303 * `/usr/lib/babeltrace2/plugins` or
304 * `/usr/local/lib/babeltrace2/plugins` if installed locally
305 * 4. Built-in plugins (static)
307 * Directories are searched non-recursively.
309 if (find_in_std_env_var
) {
310 const char *envvar
= getenv("BABELTRACE_PLUGIN_PATH");
313 ret
= bt_common_append_plugin_path_dirs(envvar
, dirs
);
315 BT_LIB_LOGE_APPEND_CAUSE(
316 "Failed to append plugin path to array of directories.");
317 status
= BT_FUNC_STATUS_MEMORY_ERROR
;
323 if (find_in_user_dir
) {
324 home_plugin_dir
= bt_common_get_home_plugin_path(
325 BT_LOG_OUTPUT_LEVEL
);
326 if (home_plugin_dir
) {
327 GString
*home_plugin_dir_str
= g_string_new(
330 if (!home_plugin_dir_str
) {
331 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GString.");
332 status
= BT_FUNC_STATUS_MEMORY_ERROR
;
336 g_ptr_array_add(dirs
, home_plugin_dir_str
);
340 if (find_in_sys_dir
) {
341 const char *system_plugin_dir
=
342 bt_common_get_system_plugin_path();
344 if (system_plugin_dir
) {
345 GString
*system_plugin_dir_str
=
346 g_string_new(system_plugin_dir
);
348 if (!system_plugin_dir_str
) {
349 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GString.");
350 status
= BT_FUNC_STATUS_MEMORY_ERROR
;
354 g_ptr_array_add(dirs
, system_plugin_dir_str
);
358 for (dir_i
= 0; dir_i
< dirs
->len
; dir_i
++) {
359 GString
*dir
= dirs
->pdata
[dir_i
];
361 BT_OBJECT_PUT_REF_AND_RESET(plugin_set
);
364 * Skip this if the directory does not exist because
365 * bt_plugin_find_all_from_dir() would log a warning.
367 if (!g_file_test(dir
->str
, G_FILE_TEST_IS_DIR
)) {
368 BT_LOGI("Skipping nonexistent directory path: "
369 "path=\"%s\"", dir
->str
);
373 /* bt_plugin_find_all_from_dir() logs details/errors */
374 status
= bt_plugin_find_all_from_dir(dir
->str
, BT_FALSE
,
375 fail_on_load_error
, &plugin_set
);
377 BT_ASSERT(!plugin_set
);
379 } else if (status
== BT_FUNC_STATUS_NOT_FOUND
) {
380 BT_ASSERT(!plugin_set
);
381 BT_LOGI("No plugins found in directory: path=\"%s\"",
386 BT_ASSERT(status
== BT_FUNC_STATUS_OK
);
387 BT_ASSERT(plugin_set
);
388 BT_LOGI("Found plugins in directory: path=\"%s\", count=%u",
389 dir
->str
, plugin_set
->plugins
->len
);
391 for (plugin_i
= 0; plugin_i
< plugin_set
->plugins
->len
;
393 bt_plugin_set_add_plugin((void *) *plugin_set_out
,
394 plugin_set
->plugins
->pdata
[plugin_i
]);
398 if (find_in_static
) {
399 BT_OBJECT_PUT_REF_AND_RESET(plugin_set
);
400 status
= bt_plugin_find_all_from_static(fail_on_load_error
,
403 BT_ASSERT(!plugin_set
);
405 } else if (status
== BT_FUNC_STATUS_NOT_FOUND
) {
406 BT_ASSERT(!plugin_set
);
407 BT_LOGI_STR("No plugins found in built-in plugins.");
411 BT_ASSERT(status
== BT_FUNC_STATUS_OK
);
412 BT_ASSERT(plugin_set
);
413 BT_LOGI("Found built-in plugins: count=%u",
414 plugin_set
->plugins
->len
);
416 for (plugin_i
= 0; plugin_i
< plugin_set
->plugins
->len
;
418 bt_plugin_set_add_plugin((void *) *plugin_set_out
,
419 plugin_set
->plugins
->pdata
[plugin_i
]);
424 free(home_plugin_dir
);
425 bt_object_put_ref(plugin_set
);
428 g_ptr_array_free(dirs
, TRUE
);
432 BT_OBJECT_PUT_REF_AND_RESET(*plugin_set_out
);
434 BT_ASSERT(*plugin_set_out
);
436 if ((*plugin_set_out
)->plugins
->len
> 0) {
437 BT_LOGI("Found plugins in standard directories and built-in plugins: "
438 "count=%u", (*plugin_set_out
)->plugins
->len
);
439 status
= BT_FUNC_STATUS_OK
;
441 BT_LOGI_STR("No plugins found in standard directories and built-in plugins.");
442 status
= BT_FUNC_STATUS_NOT_FOUND
;
443 BT_OBJECT_PUT_REF_AND_RESET(*plugin_set_out
);
451 enum bt_plugin_find_status
bt_plugin_find(const char *plugin_name
,
452 bt_bool find_in_std_env_var
, bt_bool find_in_user_dir
,
453 bt_bool find_in_sys_dir
, bt_bool find_in_static
,
454 bt_bool fail_on_load_error
, const struct bt_plugin
**plugin_out
)
456 enum bt_plugin_find_status status
;
457 const struct bt_plugin_set
*plugin_set
= NULL
;
460 BT_ASSERT_PRE_NO_ERROR();
461 BT_ASSERT_PRE_NAME_NON_NULL(plugin_name
);
462 BT_ASSERT_PRE_PLUGIN_OUT_NON_NULL(plugin_out
);
463 BT_LOGI("Finding named plugin in standard directories and built-in plugins: "
464 "name=\"%s\", find-in-std-env-var=%d, find-in-user-dir=%d, "
465 "find-in-sys-dir=%d, find-in-static=%d",
466 plugin_name
, find_in_std_env_var
, find_in_user_dir
,
467 find_in_sys_dir
, find_in_static
);
468 status
= (enum bt_plugin_find_status
) bt_plugin_find_all(find_in_std_env_var
, find_in_user_dir
,
469 find_in_sys_dir
, find_in_static
, fail_on_load_error
,
471 if (status
!= BT_FUNC_STATUS_OK
) {
472 BT_ASSERT(!plugin_set
);
476 BT_ASSERT(plugin_set
);
478 for (i
= 0; i
< plugin_set
->plugins
->len
; i
++) {
479 const struct bt_plugin
*plugin
= plugin_set
->plugins
->pdata
[i
];
481 if (strcmp(plugin
->info
.name
->str
, plugin_name
) == 0) {
482 *plugin_out
= plugin
;
483 bt_object_get_ref_no_null_check(*plugin_out
);
488 status
= BT_FUNC_STATUS_NOT_FOUND
;
491 if (status
== BT_FUNC_STATUS_OK
) {
492 BT_ASSERT(*plugin_out
);
493 BT_LIB_LOGI("Found plugin in standard directories and built-in plugins: "
494 "%!+l", *plugin_out
);
495 } else if (status
== BT_FUNC_STATUS_NOT_FOUND
) {
496 BT_LOGI("No plugin found in standard directories and built-in plugins: "
497 "name=\"%s\"", plugin_name
);
500 bt_plugin_set_put_ref(plugin_set
);
506 pthread_mutex_t lock
;
507 struct bt_plugin_set
*plugin_set
;
509 bool fail_on_load_error
;
511 } append_all_from_dir_info
= {
512 .lock
= PTHREAD_MUTEX_INITIALIZER
516 int nftw_append_all_from_dir(const char *file
,
517 const struct stat
*sb
__attribute__((unused
)),
518 int flag
, struct FTW
*s
)
521 const char *name
= file
+ s
->base
;
523 /* Check for recursion */
524 if (!append_all_from_dir_info
.recurse
&& s
->level
> 1) {
531 const struct bt_plugin_set
*plugins_from_file
= NULL
;
533 if (name
[0] == '.') {
534 /* Skip hidden files */
535 BT_LOGI("Skipping hidden file: path=\"%s\"", file
);
539 append_all_from_dir_info
.status
=
540 bt_plugin_find_all_from_file(file
,
541 append_all_from_dir_info
.fail_on_load_error
,
543 if (append_all_from_dir_info
.status
== BT_FUNC_STATUS_OK
) {
546 BT_ASSERT(plugins_from_file
);
548 for (j
= 0; j
< plugins_from_file
->plugins
->len
; j
++) {
549 struct bt_plugin
*plugin
=
550 g_ptr_array_index(plugins_from_file
->plugins
, j
);
552 BT_LIB_LOGI("Adding plugin to plugin set: "
553 "plugin-path=\"%s\", %![plugin-]+l",
555 bt_plugin_set_add_plugin(
556 append_all_from_dir_info
.plugin_set
,
560 bt_object_put_ref(plugins_from_file
);
562 } else if (append_all_from_dir_info
.status
< 0) {
563 /* bt_plugin_find_all_from_file() logs errors */
564 BT_ASSERT(!plugins_from_file
);
570 * Not found in this file: this is no an error; continue
571 * walking the directories.
573 BT_ASSERT(!plugins_from_file
);
574 BT_ASSERT(append_all_from_dir_info
.status
==
575 BT_FUNC_STATUS_NOT_FOUND
);
579 /* Continue to next file / directory. */
580 BT_LOGI("Cannot enter directory: continuing: path=\"%s\"", file
);
583 /* Continue to next file / directory. */
584 BT_LOGI("Cannot get file information: continuing: path=\"%s\"", file
);
593 int bt_plugin_create_append_all_from_dir(struct bt_plugin_set
*plugin_set
,
594 const char *path
, bt_bool recurse
, bt_bool fail_on_load_error
)
596 int nftw_flags
= FTW_PHYS
;
601 BT_ASSERT(plugin_set
);
603 BT_ASSERT(strlen(path
) < PATH_MAX
);
606 * Make sure that path exists and is accessible.
607 * This is necessary since Cygwin implementation of nftw() is not POSIX
608 * compliant. Cygwin nftw() implementation does not fail on non-existent
609 * path with ENOENT. Instead, it flags the directory as FTW_NS. FTW_NS during
610 * nftw_append_all_from_dir is not treated as an error since we are
611 * traversing the tree for plugin discovery.
613 if (stat(path
, &sb
)) {
614 BT_LOGW_ERRNO("Cannot open directory",
615 ": path=\"%s\", recurse=%d",
617 (void) BT_CURRENT_THREAD_ERROR_APPEND_CAUSE_FROM_UNKNOWN(
618 BT_LIB_LOG_LIBBABELTRACE2_NAME
,
619 "Cannot open directory: path=\"%s\", recurse=%d",
621 status
= BT_FUNC_STATUS_ERROR
;
625 pthread_mutex_lock(&append_all_from_dir_info
.lock
);
626 append_all_from_dir_info
.plugin_set
= plugin_set
;
627 append_all_from_dir_info
.recurse
= recurse
;
628 append_all_from_dir_info
.status
= BT_FUNC_STATUS_OK
;
629 append_all_from_dir_info
.fail_on_load_error
= fail_on_load_error
;
630 ret
= nftw(path
, nftw_append_all_from_dir
,
631 APPEND_ALL_FROM_DIR_NFDOPEN_MAX
, nftw_flags
);
632 append_all_from_dir_info
.plugin_set
= NULL
;
633 status
= append_all_from_dir_info
.status
;
634 pthread_mutex_unlock(&append_all_from_dir_info
.lock
);
636 BT_LIB_LOGW_APPEND_CAUSE("Failed to walk directory",
637 ": path=\"%s\", recurse=%d",
639 status
= BT_FUNC_STATUS_ERROR
;
643 if (status
== BT_FUNC_STATUS_NOT_FOUND
) {
645 * We're just appending in this function; even if
646 * nothing was found, it's still okay from the caller's
649 status
= BT_FUNC_STATUS_OK
;
657 enum bt_plugin_find_all_from_dir_status
bt_plugin_find_all_from_dir(
658 const char *path
, bt_bool recurse
, bt_bool fail_on_load_error
,
659 const struct bt_plugin_set
**plugin_set_out
)
661 enum bt_plugin_find_all_from_dir_status status
=
664 BT_ASSERT_PRE_NO_ERROR();
665 BT_ASSERT_PRE_PLUGIN_SET_OUT_NON_NULL(plugin_set_out
);
666 BT_LOGI("Creating all plugins in directory: path=\"%s\", recurse=%d",
668 *plugin_set_out
= bt_plugin_set_create();
669 if (!*plugin_set_out
) {
670 BT_LIB_LOGE_APPEND_CAUSE("Cannot create empty plugin set.");
671 status
= BT_FUNC_STATUS_MEMORY_ERROR
;
676 * Append found plugins to array (never returns
677 * `BT_FUNC_STATUS_NOT_FOUND`)
679 status
= bt_plugin_create_append_all_from_dir((void *) *plugin_set_out
,
680 path
, recurse
, fail_on_load_error
);
683 * bt_plugin_create_append_all_from_dir() handles
684 * `fail_on_load_error`, so this is a "real" error.
686 BT_LIB_LOGE_APPEND_CAUSE(
687 "Cannot append plugins found in directory: "
688 "path=\"%s\", status=%s",
689 path
, bt_common_func_status_string(status
));
693 BT_ASSERT(status
== BT_FUNC_STATUS_OK
);
695 if ((*plugin_set_out
)->plugins
->len
== 0) {
696 /* Nothing was appended: not found */
697 BT_LOGI("No plugins found in directory: path=\"%s\"", path
);
698 status
= BT_FUNC_STATUS_NOT_FOUND
;
702 BT_LOGI("Created %u plugins from directory: count=%u, path=\"%s\"",
703 (*plugin_set_out
)->plugins
->len
,
704 (*plugin_set_out
)->plugins
->len
, path
);
708 BT_ASSERT(status
!= BT_FUNC_STATUS_OK
);
709 BT_OBJECT_PUT_REF_AND_RESET(*plugin_set_out
);
716 const char *bt_plugin_get_name(const struct bt_plugin
*plugin
)
718 BT_ASSERT_PRE_DEV_PLUGIN_NON_NULL(plugin
);
719 return plugin
->info
.name_set
? plugin
->info
.name
->str
: NULL
;
723 const char *bt_plugin_get_author(const struct bt_plugin
*plugin
)
725 BT_ASSERT_PRE_DEV_PLUGIN_NON_NULL(plugin
);
726 return plugin
->info
.author_set
? plugin
->info
.author
->str
: NULL
;
730 const char *bt_plugin_get_license(const struct bt_plugin
*plugin
)
732 BT_ASSERT_PRE_DEV_PLUGIN_NON_NULL(plugin
);
733 return plugin
->info
.license_set
? plugin
->info
.license
->str
: NULL
;
737 const char *bt_plugin_get_path(const struct bt_plugin
*plugin
)
739 BT_ASSERT_PRE_DEV_PLUGIN_NON_NULL(plugin
);
740 return plugin
->info
.path_set
? plugin
->info
.path
->str
: NULL
;
744 const char *bt_plugin_get_description(const struct bt_plugin
*plugin
)
746 BT_ASSERT_PRE_DEV_PLUGIN_NON_NULL(plugin
);
747 return plugin
->info
.description_set
?
748 plugin
->info
.description
->str
: NULL
;
752 enum bt_property_availability
bt_plugin_get_version(const struct bt_plugin
*plugin
,
753 unsigned int *major
, unsigned int *minor
, unsigned int *patch
,
756 enum bt_property_availability avail
=
757 BT_PROPERTY_AVAILABILITY_AVAILABLE
;
759 BT_ASSERT_PRE_DEV_PLUGIN_NON_NULL(plugin
);
761 if (!plugin
->info
.version_set
) {
762 BT_LIB_LOGD("Plugin's version is not set: %!+l", plugin
);
763 avail
= BT_PROPERTY_AVAILABILITY_NOT_AVAILABLE
;
768 *major
= plugin
->info
.version
.major
;
772 *minor
= plugin
->info
.version
.minor
;
776 *patch
= plugin
->info
.version
.patch
;
780 *extra
= plugin
->info
.version
.extra
->str
;
788 uint64_t bt_plugin_get_source_component_class_count(const struct bt_plugin
*plugin
)
790 BT_ASSERT_PRE_DEV_PLUGIN_NON_NULL(plugin
);
791 return (uint64_t) plugin
->src_comp_classes
->len
;
795 uint64_t bt_plugin_get_filter_component_class_count(const struct bt_plugin
*plugin
)
797 BT_ASSERT_PRE_DEV_PLUGIN_NON_NULL(plugin
);
798 return (uint64_t) plugin
->flt_comp_classes
->len
;
802 uint64_t bt_plugin_get_sink_component_class_count(const struct bt_plugin
*plugin
)
804 BT_ASSERT_PRE_DEV_PLUGIN_NON_NULL(plugin
);
805 return (uint64_t) plugin
->sink_comp_classes
->len
;
809 struct bt_component_class
*borrow_component_class_by_index(
810 const struct bt_plugin
*plugin
, GPtrArray
*comp_classes
,
813 BT_ASSERT_PRE_DEV_PLUGIN_NON_NULL(plugin
);
814 BT_ASSERT_PRE_DEV_VALID_INDEX(index
, comp_classes
->len
);
815 return g_ptr_array_index(comp_classes
, index
);
819 const struct bt_component_class_source
*
820 bt_plugin_borrow_source_component_class_by_index_const(
821 const struct bt_plugin
*plugin
, uint64_t index
)
823 return (const void *) borrow_component_class_by_index(plugin
,
824 plugin
->src_comp_classes
, index
);
828 const struct bt_component_class_filter
*
829 bt_plugin_borrow_filter_component_class_by_index_const(
830 const struct bt_plugin
*plugin
, uint64_t index
)
832 return (const void *) borrow_component_class_by_index(plugin
,
833 plugin
->flt_comp_classes
, index
);
837 const struct bt_component_class_sink
*
838 bt_plugin_borrow_sink_component_class_by_index_const(
839 const struct bt_plugin
*plugin
, uint64_t index
)
841 return (const void *) borrow_component_class_by_index(plugin
,
842 plugin
->sink_comp_classes
, index
);
846 struct bt_component_class
*borrow_component_class_by_name(
847 const struct bt_plugin
*plugin
, GPtrArray
*comp_classes
,
850 struct bt_component_class
*comp_class
= NULL
;
853 BT_ASSERT_PRE_DEV_PLUGIN_NON_NULL(plugin
);
854 BT_ASSERT_PRE_DEV_NAME_NON_NULL(name
);
856 for (i
= 0; i
< comp_classes
->len
; i
++) {
857 struct bt_component_class
*comp_class_candidate
=
858 g_ptr_array_index(comp_classes
, i
);
859 const char *comp_class_cand_name
=
860 bt_component_class_get_name(comp_class_candidate
);
862 BT_ASSERT_DBG(comp_class_cand_name
);
864 if (strcmp(name
, comp_class_cand_name
) == 0) {
865 comp_class
= comp_class_candidate
;
874 const struct bt_component_class_source
*
875 bt_plugin_borrow_source_component_class_by_name_const(
876 const struct bt_plugin
*plugin
, const char *name
)
878 return (const void *) borrow_component_class_by_name(plugin
,
879 plugin
->src_comp_classes
, name
);
883 const struct bt_component_class_filter
*
884 bt_plugin_borrow_filter_component_class_by_name_const(
885 const struct bt_plugin
*plugin
, const char *name
)
887 return (const void *) borrow_component_class_by_name(plugin
,
888 plugin
->flt_comp_classes
, name
);
892 const struct bt_component_class_sink
*
893 bt_plugin_borrow_sink_component_class_by_name_const(
894 const struct bt_plugin
*plugin
, const char *name
)
896 return (const void *) borrow_component_class_by_name(plugin
,
897 plugin
->sink_comp_classes
, name
);
901 void bt_plugin_get_ref(const struct bt_plugin
*plugin
)
903 bt_object_get_ref(plugin
);
907 void bt_plugin_put_ref(const struct bt_plugin
*plugin
)
909 bt_object_put_ref(plugin
);
913 void bt_plugin_set_get_ref(const struct bt_plugin_set
*plugin_set
)
915 bt_object_get_ref(plugin_set
);
919 void bt_plugin_set_put_ref(const struct bt_plugin_set
*plugin_set
)
921 bt_object_put_ref(plugin_set
);