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>
33 #include "plugin-so.h"
34 #include "lib/func-status.h"
36 #define PYTHON_PLUGIN_PROVIDER_FILENAME "babeltrace2-python-plugin-provider." G_MODULE_SUFFIX
37 #define PYTHON_PLUGIN_PROVIDER_DIR BABELTRACE_PLUGIN_PROVIDERS_DIR
38 #define PYTHON_PLUGIN_PROVIDER_SYM_NAME bt_plugin_python_create_all_from_file
39 #define PYTHON_PLUGIN_PROVIDER_SYM_NAME_STR G_STRINGIFY(PYTHON_PLUGIN_PROVIDER_SYM_NAME)
41 #define APPEND_ALL_FROM_DIR_NFDOPEN_MAX 8
43 /* Declare here to make sure definition in both ifdef branches are in sync. */
45 int init_python_plugin_provider(void);
46 typedef int (*create_all_from_file_sym_type
)(
48 bool fail_on_load_error
,
49 struct bt_plugin_set
**plugin_set_out
);
51 #ifdef BT_BUILT_IN_PYTHON_PLUGIN_SUPPORT
52 #include <plugin/python-plugin-provider.h>
55 create_all_from_file_sym_type
56 bt_plugin_python_create_all_from_file_sym
=
57 bt_plugin_python_create_all_from_file
;
60 int init_python_plugin_provider(void)
63 #else /* BT_BUILT_IN_PYTHON_PLUGIN_SUPPORT */
64 static GModule
*python_plugin_provider_module
;
67 create_all_from_file_sym_type bt_plugin_python_create_all_from_file_sym
;
70 int init_python_plugin_provider(void) {
71 int status
= BT_FUNC_STATUS_OK
;
72 const char *provider_dir_envvar
;
73 static const char * const provider_dir_envvar_name
= "LIBBABELTRACE2_PLUGIN_PROVIDER_DIR";
74 char *provider_path
= NULL
;
76 if (bt_plugin_python_create_all_from_file_sym
) {
80 BT_LOGI_STR("Loading Python plugin provider module.");
82 provider_dir_envvar
= getenv(provider_dir_envvar_name
);
83 if (provider_dir_envvar
) {
84 provider_path
= g_build_filename(provider_dir_envvar
,
85 PYTHON_PLUGIN_PROVIDER_FILENAME
, NULL
);
86 BT_LOGI("Using `%s` environment variable to find the Python "
87 "plugin provider: path=\"%s\"", provider_dir_envvar_name
,
90 provider_path
= g_build_filename(PYTHON_PLUGIN_PROVIDER_DIR
,
91 PYTHON_PLUGIN_PROVIDER_FILENAME
, NULL
);
92 BT_LOGI("Using default path (`%s` environment variable is not "
93 "set) to find the Python plugin provider: path=\"%s\"",
94 provider_dir_envvar_name
, provider_path
);
97 python_plugin_provider_module
= g_module_open(provider_path
, 0);
98 if (!python_plugin_provider_module
) {
100 * This is not an error. The whole point of having an
101 * external Python plugin provider is that it can be
102 * missing and the Babeltrace library still works.
104 BT_LOGI("Cannot open `%s`: %s: continuing without Python plugin support.",
105 provider_path
, g_module_error());
109 if (!g_module_symbol(python_plugin_provider_module
,
110 PYTHON_PLUGIN_PROVIDER_SYM_NAME_STR
,
111 (gpointer
) &bt_plugin_python_create_all_from_file_sym
)) {
113 * This is an error because, since we found the Python
114 * plugin provider shared object, we expect this symbol
117 BT_LIB_LOGE_APPEND_CAUSE(
118 "Cannot find the Python plugin provider loading symbol: "
119 "%s: continuing without Python plugin support: "
120 "file=\"%s\", symbol=\"%s\"",
123 PYTHON_PLUGIN_PROVIDER_SYM_NAME_STR
);
124 status
= BT_FUNC_STATUS_ERROR
;
128 BT_LOGI("Loaded Python plugin provider module: addr=%p",
129 python_plugin_provider_module
);
132 g_free(provider_path
);
137 __attribute__((destructor
)) static
138 void fini_python_plugin_provider(void) {
139 if (python_plugin_provider_module
) {
140 BT_LOGI("Unloading Python plugin provider module.");
142 if (!g_module_close(python_plugin_provider_module
)) {
144 * This occurs when the library is finalized: do
145 * NOT append an error cause.
147 BT_LOGE("Failed to close the Python plugin provider module: %s.",
151 python_plugin_provider_module
= NULL
;
157 uint64_t bt_plugin_set_get_plugin_count(const struct bt_plugin_set
*plugin_set
)
159 BT_ASSERT_PRE_DEV_PLUGIN_SET_NON_NULL(plugin_set
);
160 return (uint64_t) plugin_set
->plugins
->len
;
164 const struct bt_plugin
*bt_plugin_set_borrow_plugin_by_index_const(
165 const struct bt_plugin_set
*plugin_set
, uint64_t index
)
167 BT_ASSERT_PRE_DEV_PLUGIN_SET_NON_NULL(plugin_set
);
168 BT_ASSERT_PRE_DEV_VALID_INDEX(index
, plugin_set
->plugins
->len
);
169 return g_ptr_array_index(plugin_set
->plugins
, index
);
173 enum bt_plugin_find_all_from_static_status
bt_plugin_find_all_from_static(
174 bt_bool fail_on_load_error
,
175 const struct bt_plugin_set
**plugin_set_out
)
177 BT_ASSERT_PRE_NO_ERROR();
179 /* bt_plugin_so_create_all_from_static() logs errors */
180 return bt_plugin_so_create_all_from_static(fail_on_load_error
,
181 (void *) plugin_set_out
);
185 enum bt_plugin_find_all_from_file_status
bt_plugin_find_all_from_file(
186 const char *path
, bt_bool fail_on_load_error
,
187 const struct bt_plugin_set
**plugin_set_out
)
189 enum bt_plugin_find_all_from_file_status status
;
191 BT_ASSERT_PRE_NO_ERROR();
192 BT_ASSERT_PRE_NON_NULL("path", path
, "Path");
193 BT_ASSERT_PRE_PLUGIN_SET_OUT_NON_NULL(path
);
194 BT_LOGI("Creating plugins from file: path=\"%s\"", path
);
196 /* Try shared object plugins */
197 status
= bt_plugin_so_create_all_from_file(path
, fail_on_load_error
,
198 (void *) plugin_set_out
);
199 if (status
== BT_FUNC_STATUS_OK
) {
200 BT_ASSERT(*plugin_set_out
);
201 BT_ASSERT((*plugin_set_out
)->plugins
->len
> 0);
203 } else if (status
< 0) {
204 BT_ASSERT(!*plugin_set_out
);
208 BT_ASSERT(status
== BT_FUNC_STATUS_NOT_FOUND
);
209 BT_ASSERT(!*plugin_set_out
);
211 /* Try Python plugins if support is available */
212 status
= init_python_plugin_provider();
214 /* init_python_plugin_provider() logs errors */
218 BT_ASSERT(status
== BT_FUNC_STATUS_OK
);
219 status
= BT_FUNC_STATUS_NOT_FOUND
;
221 if (bt_plugin_python_create_all_from_file_sym
) {
222 /* Python plugin provider exists */
223 status
= bt_plugin_python_create_all_from_file_sym(path
,
224 fail_on_load_error
, (void *) plugin_set_out
);
225 if (status
== BT_FUNC_STATUS_OK
) {
226 BT_ASSERT(*plugin_set_out
);
227 BT_ASSERT((*plugin_set_out
)->plugins
->len
> 0);
229 } else if (status
< 0) {
231 * bt_plugin_python_create_all_from_file_sym()
232 * handles `fail_on_load_error` itself, so this
235 BT_ASSERT(!*plugin_set_out
);
239 BT_ASSERT(status
== BT_FUNC_STATUS_NOT_FOUND
);
240 BT_ASSERT(!*plugin_set_out
);
244 if (status
== BT_FUNC_STATUS_OK
) {
245 BT_LOGI("Created %u plugins from file: "
246 "path=\"%s\", count=%u, plugin-set-addr=%p",
247 (*plugin_set_out
)->plugins
->len
, path
,
248 (*plugin_set_out
)->plugins
->len
,
250 } else if (status
== BT_FUNC_STATUS_NOT_FOUND
) {
251 BT_LOGI("Found no plugins in file: path=\"%s\"", path
);
258 void destroy_gstring(void *data
)
260 g_string_free(data
, TRUE
);
264 enum bt_plugin_find_all_status
bt_plugin_find_all(bt_bool find_in_std_env_var
,
265 bt_bool find_in_user_dir
, bt_bool find_in_sys_dir
,
266 bt_bool find_in_static
, bt_bool fail_on_load_error
,
267 const struct bt_plugin_set
**plugin_set_out
)
269 char *home_plugin_dir
= NULL
;
270 const struct bt_plugin_set
*plugin_set
= NULL
;
271 GPtrArray
*dirs
= NULL
;
273 int status
= BT_FUNC_STATUS_OK
;
274 uint64_t dir_i
, plugin_i
;
276 BT_ASSERT_PRE_NO_ERROR();
277 BT_ASSERT_PRE_PLUGIN_SET_OUT_NON_NULL(plugin_set_out
);
278 BT_LOGI("Finding all plugins in standard directories and built-in plugins: "
279 "find-in-std-env-var=%d, find-in-user-dir=%d, "
280 "find-in-sys-dir=%d, find-in-static=%d",
281 find_in_std_env_var
, find_in_user_dir
, find_in_sys_dir
,
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
;
290 *plugin_set_out
= bt_plugin_set_create();
291 if (!*plugin_set_out
) {
292 BT_LIB_LOGE_APPEND_CAUSE("Cannot create empty plugin set.");
293 status
= BT_FUNC_STATUS_MEMORY_ERROR
;
300 * 1. `BABELTRACE_PLUGIN_PATH` environment variable
301 * (colon-separated list of directories)
302 * 2. `~/.local/lib/babeltrace2/plugins`
303 * 3. Default system directory for Babeltrace plugins, usually
304 * `/usr/lib/babeltrace2/plugins` or
305 * `/usr/local/lib/babeltrace2/plugins` if installed locally
306 * 4. Built-in plugins (static)
308 * Directories are searched non-recursively.
310 if (find_in_std_env_var
) {
311 const char *envvar
= getenv("BABELTRACE_PLUGIN_PATH");
314 ret
= bt_common_append_plugin_path_dirs(envvar
, dirs
);
316 BT_LIB_LOGE_APPEND_CAUSE(
317 "Failed to append plugin path to array of directories.");
318 status
= BT_FUNC_STATUS_MEMORY_ERROR
;
324 if (find_in_user_dir
) {
325 home_plugin_dir
= bt_common_get_home_plugin_path(
326 BT_LOG_OUTPUT_LEVEL
);
327 if (home_plugin_dir
) {
328 GString
*home_plugin_dir_str
= g_string_new(
331 if (!home_plugin_dir_str
) {
332 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GString.");
333 status
= BT_FUNC_STATUS_MEMORY_ERROR
;
337 g_ptr_array_add(dirs
, home_plugin_dir_str
);
341 if (find_in_sys_dir
) {
342 const char *system_plugin_dir
=
343 bt_common_get_system_plugin_path();
345 if (system_plugin_dir
) {
346 GString
*system_plugin_dir_str
=
347 g_string_new(system_plugin_dir
);
349 if (!system_plugin_dir_str
) {
350 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GString.");
351 status
= BT_FUNC_STATUS_MEMORY_ERROR
;
355 g_ptr_array_add(dirs
, system_plugin_dir_str
);
359 for (dir_i
= 0; dir_i
< dirs
->len
; dir_i
++) {
360 GString
*dir
= dirs
->pdata
[dir_i
];
362 BT_OBJECT_PUT_REF_AND_RESET(plugin_set
);
365 * Skip this if the directory does not exist because
366 * bt_plugin_find_all_from_dir() would log a warning.
368 if (!g_file_test(dir
->str
, G_FILE_TEST_IS_DIR
)) {
369 BT_LOGI("Skipping nonexistent directory path: "
370 "path=\"%s\"", dir
->str
);
374 /* bt_plugin_find_all_from_dir() logs details/errors */
375 status
= bt_plugin_find_all_from_dir(dir
->str
, BT_FALSE
,
376 fail_on_load_error
, &plugin_set
);
378 BT_ASSERT(!plugin_set
);
380 } else if (status
== BT_FUNC_STATUS_NOT_FOUND
) {
381 BT_ASSERT(!plugin_set
);
382 BT_LOGI("No plugins found in directory: path=\"%s\"",
387 BT_ASSERT(status
== BT_FUNC_STATUS_OK
);
388 BT_ASSERT(plugin_set
);
389 BT_LOGI("Found plugins in directory: path=\"%s\", count=%u",
390 dir
->str
, plugin_set
->plugins
->len
);
392 for (plugin_i
= 0; plugin_i
< plugin_set
->plugins
->len
;
394 bt_plugin_set_add_plugin((void *) *plugin_set_out
,
395 plugin_set
->plugins
->pdata
[plugin_i
]);
399 if (find_in_static
) {
400 BT_OBJECT_PUT_REF_AND_RESET(plugin_set
);
401 status
= bt_plugin_find_all_from_static(fail_on_load_error
,
404 BT_ASSERT(!plugin_set
);
406 } else if (status
== BT_FUNC_STATUS_NOT_FOUND
) {
407 BT_ASSERT(!plugin_set
);
408 BT_LOGI_STR("No plugins found in built-in plugins.");
412 BT_ASSERT(status
== BT_FUNC_STATUS_OK
);
413 BT_ASSERT(plugin_set
);
414 BT_LOGI("Found built-in plugins: count=%u",
415 plugin_set
->plugins
->len
);
417 for (plugin_i
= 0; plugin_i
< plugin_set
->plugins
->len
;
419 bt_plugin_set_add_plugin((void *) *plugin_set_out
,
420 plugin_set
->plugins
->pdata
[plugin_i
]);
425 free(home_plugin_dir
);
426 bt_object_put_ref(plugin_set
);
429 g_ptr_array_free(dirs
, TRUE
);
433 BT_OBJECT_PUT_REF_AND_RESET(*plugin_set_out
);
435 BT_ASSERT(*plugin_set_out
);
437 if ((*plugin_set_out
)->plugins
->len
> 0) {
438 BT_LOGI("Found plugins in standard directories and built-in plugins: "
439 "count=%u", (*plugin_set_out
)->plugins
->len
);
440 status
= BT_FUNC_STATUS_OK
;
442 BT_LOGI_STR("No plugins found in standard directories and built-in plugins.");
443 status
= BT_FUNC_STATUS_NOT_FOUND
;
444 BT_OBJECT_PUT_REF_AND_RESET(*plugin_set_out
);
452 enum bt_plugin_find_status
bt_plugin_find(const char *plugin_name
,
453 bt_bool find_in_std_env_var
, bt_bool find_in_user_dir
,
454 bt_bool find_in_sys_dir
, bt_bool find_in_static
,
455 bt_bool fail_on_load_error
, const struct bt_plugin
**plugin_out
)
457 enum bt_plugin_find_status status
;
458 const struct bt_plugin_set
*plugin_set
= NULL
;
461 BT_ASSERT_PRE_NO_ERROR();
462 BT_ASSERT_PRE_NAME_NON_NULL(plugin_name
);
463 BT_ASSERT_PRE_PLUGIN_OUT_NON_NULL(plugin_out
);
464 BT_LOGI("Finding named plugin in standard directories and built-in plugins: "
465 "name=\"%s\", find-in-std-env-var=%d, find-in-user-dir=%d, "
466 "find-in-sys-dir=%d, find-in-static=%d",
467 plugin_name
, find_in_std_env_var
, find_in_user_dir
,
468 find_in_sys_dir
, find_in_static
);
469 status
= (enum bt_plugin_find_status
) bt_plugin_find_all(find_in_std_env_var
, find_in_user_dir
,
470 find_in_sys_dir
, find_in_static
, fail_on_load_error
,
472 if (status
!= BT_FUNC_STATUS_OK
) {
473 BT_ASSERT(!plugin_set
);
477 BT_ASSERT(plugin_set
);
479 for (i
= 0; i
< plugin_set
->plugins
->len
; i
++) {
480 const struct bt_plugin
*plugin
= plugin_set
->plugins
->pdata
[i
];
482 if (strcmp(plugin
->info
.name
->str
, plugin_name
) == 0) {
483 *plugin_out
= plugin
;
484 bt_object_get_ref_no_null_check(*plugin_out
);
489 status
= BT_FUNC_STATUS_NOT_FOUND
;
492 if (status
== BT_FUNC_STATUS_OK
) {
493 BT_ASSERT(*plugin_out
);
494 BT_LIB_LOGI("Found plugin in standard directories and built-in plugins: "
495 "%!+l", *plugin_out
);
496 } else if (status
== BT_FUNC_STATUS_NOT_FOUND
) {
497 BT_LOGI("No plugin found in standard directories and built-in plugins: "
498 "name=\"%s\"", plugin_name
);
501 bt_plugin_set_put_ref(plugin_set
);
507 pthread_mutex_t lock
;
508 struct bt_plugin_set
*plugin_set
;
510 bool fail_on_load_error
;
512 } append_all_from_dir_info
= {
513 .lock
= PTHREAD_MUTEX_INITIALIZER
517 int nftw_append_all_from_dir(const char *file
,
518 const struct stat
*sb
__attribute__((unused
)),
519 int flag
, struct FTW
*s
)
522 const char *name
= file
+ s
->base
;
524 /* Check for recursion */
525 if (!append_all_from_dir_info
.recurse
&& s
->level
> 1) {
532 const struct bt_plugin_set
*plugins_from_file
= NULL
;
534 if (name
[0] == '.') {
535 /* Skip hidden files */
536 BT_LOGI("Skipping hidden file: path=\"%s\"", file
);
540 append_all_from_dir_info
.status
=
541 bt_plugin_find_all_from_file(file
,
542 append_all_from_dir_info
.fail_on_load_error
,
544 if (append_all_from_dir_info
.status
== BT_FUNC_STATUS_OK
) {
547 BT_ASSERT(plugins_from_file
);
549 for (j
= 0; j
< plugins_from_file
->plugins
->len
; j
++) {
550 struct bt_plugin
*plugin
=
551 g_ptr_array_index(plugins_from_file
->plugins
, j
);
553 BT_LIB_LOGI("Adding plugin to plugin set: "
554 "plugin-path=\"%s\", %![plugin-]+l",
556 bt_plugin_set_add_plugin(
557 append_all_from_dir_info
.plugin_set
,
561 bt_object_put_ref(plugins_from_file
);
563 } else if (append_all_from_dir_info
.status
< 0) {
564 /* bt_plugin_find_all_from_file() logs errors */
565 BT_ASSERT(!plugins_from_file
);
571 * Not found in this file: this is no an error; continue
572 * walking the directories.
574 BT_ASSERT(!plugins_from_file
);
575 BT_ASSERT(append_all_from_dir_info
.status
==
576 BT_FUNC_STATUS_NOT_FOUND
);
580 /* Continue to next file / directory. */
581 BT_LOGI("Cannot enter directory: continuing: path=\"%s\"", file
);
584 /* Continue to next file / directory. */
585 BT_LOGI("Cannot get file information: continuing: path=\"%s\"", file
);
594 int bt_plugin_create_append_all_from_dir(struct bt_plugin_set
*plugin_set
,
595 const char *path
, bt_bool recurse
, bt_bool fail_on_load_error
)
597 int nftw_flags
= FTW_PHYS
;
602 BT_ASSERT(plugin_set
);
604 BT_ASSERT(strlen(path
) < PATH_MAX
);
607 * Make sure that path exists and is accessible.
608 * This is necessary since Cygwin implementation of nftw() is not POSIX
609 * compliant. Cygwin nftw() implementation does not fail on non-existent
610 * path with ENOENT. Instead, it flags the directory as FTW_NS. FTW_NS during
611 * nftw_append_all_from_dir is not treated as an error since we are
612 * traversing the tree for plugin discovery.
614 if (stat(path
, &sb
)) {
615 BT_LOGW_ERRNO("Cannot open directory",
616 ": path=\"%s\", recurse=%d",
618 (void) BT_CURRENT_THREAD_ERROR_APPEND_CAUSE_FROM_UNKNOWN(
619 BT_LIB_LOG_LIBBABELTRACE2_NAME
,
620 "Cannot open directory: path=\"%s\", recurse=%d",
622 status
= BT_FUNC_STATUS_ERROR
;
626 pthread_mutex_lock(&append_all_from_dir_info
.lock
);
627 append_all_from_dir_info
.plugin_set
= plugin_set
;
628 append_all_from_dir_info
.recurse
= recurse
;
629 append_all_from_dir_info
.status
= BT_FUNC_STATUS_OK
;
630 append_all_from_dir_info
.fail_on_load_error
= fail_on_load_error
;
631 ret
= nftw(path
, nftw_append_all_from_dir
,
632 APPEND_ALL_FROM_DIR_NFDOPEN_MAX
, nftw_flags
);
633 append_all_from_dir_info
.plugin_set
= NULL
;
634 status
= append_all_from_dir_info
.status
;
635 pthread_mutex_unlock(&append_all_from_dir_info
.lock
);
637 BT_LIB_LOGW_APPEND_CAUSE("Failed to walk directory",
638 ": path=\"%s\", recurse=%d",
640 status
= BT_FUNC_STATUS_ERROR
;
644 if (status
== BT_FUNC_STATUS_NOT_FOUND
) {
646 * We're just appending in this function; even if
647 * nothing was found, it's still okay from the caller's
650 status
= BT_FUNC_STATUS_OK
;
658 enum bt_plugin_find_all_from_dir_status
bt_plugin_find_all_from_dir(
659 const char *path
, bt_bool recurse
, bt_bool fail_on_load_error
,
660 const struct bt_plugin_set
**plugin_set_out
)
662 enum bt_plugin_find_all_from_dir_status status
=
665 BT_ASSERT_PRE_NO_ERROR();
666 BT_ASSERT_PRE_PLUGIN_SET_OUT_NON_NULL(plugin_set_out
);
667 BT_LOGI("Creating all plugins in directory: path=\"%s\", recurse=%d",
669 *plugin_set_out
= bt_plugin_set_create();
670 if (!*plugin_set_out
) {
671 BT_LIB_LOGE_APPEND_CAUSE("Cannot create empty plugin set.");
672 status
= BT_FUNC_STATUS_MEMORY_ERROR
;
677 * Append found plugins to array (never returns
678 * `BT_FUNC_STATUS_NOT_FOUND`)
680 status
= bt_plugin_create_append_all_from_dir((void *) *plugin_set_out
,
681 path
, recurse
, fail_on_load_error
);
684 * bt_plugin_create_append_all_from_dir() handles
685 * `fail_on_load_error`, so this is a "real" error.
687 BT_LIB_LOGE_APPEND_CAUSE(
688 "Cannot append plugins found in directory: "
689 "path=\"%s\", status=%s",
690 path
, bt_common_func_status_string(status
));
694 BT_ASSERT(status
== BT_FUNC_STATUS_OK
);
696 if ((*plugin_set_out
)->plugins
->len
== 0) {
697 /* Nothing was appended: not found */
698 BT_LOGI("No plugins found in directory: path=\"%s\"", path
);
699 status
= BT_FUNC_STATUS_NOT_FOUND
;
703 BT_LOGI("Created %u plugins from directory: count=%u, path=\"%s\"",
704 (*plugin_set_out
)->plugins
->len
,
705 (*plugin_set_out
)->plugins
->len
, path
);
709 BT_ASSERT(status
!= BT_FUNC_STATUS_OK
);
710 BT_OBJECT_PUT_REF_AND_RESET(*plugin_set_out
);
717 const char *bt_plugin_get_name(const struct bt_plugin
*plugin
)
719 BT_ASSERT_PRE_DEV_PLUGIN_NON_NULL(plugin
);
720 return plugin
->info
.name_set
? plugin
->info
.name
->str
: NULL
;
724 const char *bt_plugin_get_author(const struct bt_plugin
*plugin
)
726 BT_ASSERT_PRE_DEV_PLUGIN_NON_NULL(plugin
);
727 return plugin
->info
.author_set
? plugin
->info
.author
->str
: NULL
;
731 const char *bt_plugin_get_license(const struct bt_plugin
*plugin
)
733 BT_ASSERT_PRE_DEV_PLUGIN_NON_NULL(plugin
);
734 return plugin
->info
.license_set
? plugin
->info
.license
->str
: NULL
;
738 const char *bt_plugin_get_path(const struct bt_plugin
*plugin
)
740 BT_ASSERT_PRE_DEV_PLUGIN_NON_NULL(plugin
);
741 return plugin
->info
.path_set
? plugin
->info
.path
->str
: NULL
;
745 const char *bt_plugin_get_description(const struct bt_plugin
*plugin
)
747 BT_ASSERT_PRE_DEV_PLUGIN_NON_NULL(plugin
);
748 return plugin
->info
.description_set
?
749 plugin
->info
.description
->str
: NULL
;
753 enum bt_property_availability
bt_plugin_get_version(const struct bt_plugin
*plugin
,
754 unsigned int *major
, unsigned int *minor
, unsigned int *patch
,
757 enum bt_property_availability avail
=
758 BT_PROPERTY_AVAILABILITY_AVAILABLE
;
760 BT_ASSERT_PRE_DEV_PLUGIN_NON_NULL(plugin
);
762 if (!plugin
->info
.version_set
) {
763 BT_LIB_LOGD("Plugin's version is not set: %!+l", plugin
);
764 avail
= BT_PROPERTY_AVAILABILITY_NOT_AVAILABLE
;
769 *major
= plugin
->info
.version
.major
;
773 *minor
= plugin
->info
.version
.minor
;
777 *patch
= plugin
->info
.version
.patch
;
781 *extra
= plugin
->info
.version
.extra
->str
;
789 uint64_t bt_plugin_get_source_component_class_count(const struct bt_plugin
*plugin
)
791 BT_ASSERT_PRE_DEV_PLUGIN_NON_NULL(plugin
);
792 return (uint64_t) plugin
->src_comp_classes
->len
;
796 uint64_t bt_plugin_get_filter_component_class_count(const struct bt_plugin
*plugin
)
798 BT_ASSERT_PRE_DEV_PLUGIN_NON_NULL(plugin
);
799 return (uint64_t) plugin
->flt_comp_classes
->len
;
803 uint64_t bt_plugin_get_sink_component_class_count(const struct bt_plugin
*plugin
)
805 BT_ASSERT_PRE_DEV_PLUGIN_NON_NULL(plugin
);
806 return (uint64_t) plugin
->sink_comp_classes
->len
;
810 struct bt_component_class
*borrow_component_class_by_index(
811 const struct bt_plugin
*plugin
, GPtrArray
*comp_classes
,
814 BT_ASSERT_PRE_DEV_PLUGIN_NON_NULL(plugin
);
815 BT_ASSERT_PRE_DEV_VALID_INDEX(index
, comp_classes
->len
);
816 return g_ptr_array_index(comp_classes
, index
);
820 const struct bt_component_class_source
*
821 bt_plugin_borrow_source_component_class_by_index_const(
822 const struct bt_plugin
*plugin
, uint64_t index
)
824 return (const void *) borrow_component_class_by_index(plugin
,
825 plugin
->src_comp_classes
, index
);
829 const struct bt_component_class_filter
*
830 bt_plugin_borrow_filter_component_class_by_index_const(
831 const struct bt_plugin
*plugin
, uint64_t index
)
833 return (const void *) borrow_component_class_by_index(plugin
,
834 plugin
->flt_comp_classes
, index
);
838 const struct bt_component_class_sink
*
839 bt_plugin_borrow_sink_component_class_by_index_const(
840 const struct bt_plugin
*plugin
, uint64_t index
)
842 return (const void *) borrow_component_class_by_index(plugin
,
843 plugin
->sink_comp_classes
, index
);
847 struct bt_component_class
*borrow_component_class_by_name(
848 const struct bt_plugin
*plugin
, GPtrArray
*comp_classes
,
851 struct bt_component_class
*comp_class
= NULL
;
854 BT_ASSERT_PRE_DEV_PLUGIN_NON_NULL(plugin
);
855 BT_ASSERT_PRE_DEV_NAME_NON_NULL(name
);
857 for (i
= 0; i
< comp_classes
->len
; i
++) {
858 struct bt_component_class
*comp_class_candidate
=
859 g_ptr_array_index(comp_classes
, i
);
860 const char *comp_class_cand_name
=
861 bt_component_class_get_name(comp_class_candidate
);
863 BT_ASSERT_DBG(comp_class_cand_name
);
865 if (strcmp(name
, comp_class_cand_name
) == 0) {
866 comp_class
= comp_class_candidate
;
875 const struct bt_component_class_source
*
876 bt_plugin_borrow_source_component_class_by_name_const(
877 const struct bt_plugin
*plugin
, const char *name
)
879 return (const void *) borrow_component_class_by_name(plugin
,
880 plugin
->src_comp_classes
, name
);
884 const struct bt_component_class_filter
*
885 bt_plugin_borrow_filter_component_class_by_name_const(
886 const struct bt_plugin
*plugin
, const char *name
)
888 return (const void *) borrow_component_class_by_name(plugin
,
889 plugin
->flt_comp_classes
, name
);
893 const struct bt_component_class_sink
*
894 bt_plugin_borrow_sink_component_class_by_name_const(
895 const struct bt_plugin
*plugin
, const char *name
)
897 return (const void *) borrow_component_class_by_name(plugin
,
898 plugin
->sink_comp_classes
, name
);
902 void bt_plugin_get_ref(const struct bt_plugin
*plugin
)
904 bt_object_get_ref(plugin
);
908 void bt_plugin_put_ref(const struct bt_plugin
*plugin
)
910 bt_object_put_ref(plugin
);
914 void bt_plugin_set_get_ref(const struct bt_plugin_set
*plugin_set
)
916 bt_object_get_ref(plugin_set
);
920 void bt_plugin_set_put_ref(const struct bt_plugin_set
*plugin_set
)
922 bt_object_put_ref(plugin_set
);