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 "common/common.h"
16 #include <babeltrace2/plugin/plugin-loading.h>
17 #include <babeltrace2/graph/component-class.h>
18 #include <babeltrace2/error-reporting.h>
19 #include "lib/graph/component-class.h"
20 #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
;
155 uint64_t bt_plugin_set_get_plugin_count(const struct bt_plugin_set
*plugin_set
)
157 BT_ASSERT_PRE_DEV_NON_NULL(plugin_set
, "Plugin set");
158 return (uint64_t) plugin_set
->plugins
->len
;
161 const struct bt_plugin
*bt_plugin_set_borrow_plugin_by_index_const(
162 const struct bt_plugin_set
*plugin_set
, uint64_t index
)
164 BT_ASSERT_PRE_DEV_NON_NULL(plugin_set
, "Plugin set");
165 BT_ASSERT_PRE_DEV_VALID_INDEX(index
, plugin_set
->plugins
->len
);
166 return g_ptr_array_index(plugin_set
->plugins
, index
);
169 enum bt_plugin_find_all_from_static_status
bt_plugin_find_all_from_static(
170 bt_bool fail_on_load_error
,
171 const struct bt_plugin_set
**plugin_set_out
)
173 BT_ASSERT_PRE_NO_ERROR();
175 /* bt_plugin_so_create_all_from_static() logs errors */
176 return bt_plugin_so_create_all_from_static(fail_on_load_error
,
177 (void *) plugin_set_out
);
180 enum bt_plugin_find_all_from_file_status
bt_plugin_find_all_from_file(
181 const char *path
, bt_bool fail_on_load_error
,
182 const struct bt_plugin_set
**plugin_set_out
)
184 enum bt_plugin_find_all_from_file_status status
;
186 BT_ASSERT_PRE_NO_ERROR();
187 BT_ASSERT_PRE_NON_NULL(path
, "Path");
188 BT_ASSERT_PRE_NON_NULL(path
, "Plugin set (output)");
189 BT_LOGI("Creating plugins from file: path=\"%s\"", path
);
191 /* Try shared object plugins */
192 status
= bt_plugin_so_create_all_from_file(path
, fail_on_load_error
,
193 (void *) plugin_set_out
);
194 if (status
== BT_FUNC_STATUS_OK
) {
195 BT_ASSERT(*plugin_set_out
);
196 BT_ASSERT((*plugin_set_out
)->plugins
->len
> 0);
198 } else if (status
< 0) {
199 BT_ASSERT(!*plugin_set_out
);
203 BT_ASSERT(status
== BT_FUNC_STATUS_NOT_FOUND
);
204 BT_ASSERT(!*plugin_set_out
);
206 /* Try Python plugins if support is available */
207 status
= init_python_plugin_provider();
209 /* init_python_plugin_provider() logs errors */
213 BT_ASSERT(status
== BT_FUNC_STATUS_OK
);
214 status
= BT_FUNC_STATUS_NOT_FOUND
;
216 if (bt_plugin_python_create_all_from_file_sym
) {
217 /* Python plugin provider exists */
218 status
= bt_plugin_python_create_all_from_file_sym(path
,
219 fail_on_load_error
, (void *) plugin_set_out
);
220 if (status
== BT_FUNC_STATUS_OK
) {
221 BT_ASSERT(*plugin_set_out
);
222 BT_ASSERT((*plugin_set_out
)->plugins
->len
> 0);
224 } else if (status
< 0) {
226 * bt_plugin_python_create_all_from_file_sym()
227 * handles `fail_on_load_error` itself, so this
230 BT_ASSERT(!*plugin_set_out
);
234 BT_ASSERT(status
== BT_FUNC_STATUS_NOT_FOUND
);
235 BT_ASSERT(!*plugin_set_out
);
239 if (status
== BT_FUNC_STATUS_OK
) {
240 BT_LOGI("Created %u plugins from file: "
241 "path=\"%s\", count=%u, plugin-set-addr=%p",
242 (*plugin_set_out
)->plugins
->len
, path
,
243 (*plugin_set_out
)->plugins
->len
,
245 } else if (status
== BT_FUNC_STATUS_NOT_FOUND
) {
246 BT_LOGI("Found no plugins in file: path=\"%s\"", path
);
253 void destroy_gstring(void *data
)
255 g_string_free(data
, TRUE
);
258 enum bt_plugin_find_all_status
bt_plugin_find_all(bt_bool find_in_std_env_var
,
259 bt_bool find_in_user_dir
, bt_bool find_in_sys_dir
,
260 bt_bool find_in_static
, bt_bool fail_on_load_error
,
261 const struct bt_plugin_set
**plugin_set_out
)
263 char *home_plugin_dir
= NULL
;
264 const struct bt_plugin_set
*plugin_set
= NULL
;
265 GPtrArray
*dirs
= NULL
;
267 int status
= BT_FUNC_STATUS_OK
;
268 uint64_t dir_i
, plugin_i
;
270 BT_ASSERT_PRE_NO_ERROR();
271 BT_ASSERT_PRE_NON_NULL(plugin_set_out
, "Plugin set (output)");
272 BT_LOGI("Finding all plugins in standard directories and built-in plugins: "
273 "find-in-std-env-var=%d, find-in-user-dir=%d, "
274 "find-in-sys-dir=%d, find-in-static=%d",
275 find_in_std_env_var
, find_in_user_dir
, find_in_sys_dir
,
277 dirs
= g_ptr_array_new_with_free_func((GDestroyNotify
) destroy_gstring
);
279 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GPtrArray.");
280 status
= BT_FUNC_STATUS_MEMORY_ERROR
;
284 *plugin_set_out
= bt_plugin_set_create();
285 if (!*plugin_set_out
) {
286 BT_LIB_LOGE_APPEND_CAUSE("Cannot create empty plugin set.");
287 status
= BT_FUNC_STATUS_MEMORY_ERROR
;
294 * 1. `BABELTRACE_PLUGIN_PATH` environment variable
295 * (colon-separated list of directories)
296 * 2. `~/.local/lib/babeltrace2/plugins`
297 * 3. Default system directory for Babeltrace plugins, usually
298 * `/usr/lib/babeltrace2/plugins` or
299 * `/usr/local/lib/babeltrace2/plugins` if installed locally
300 * 4. Built-in plugins (static)
302 * Directories are searched non-recursively.
304 if (find_in_std_env_var
) {
305 const char *envvar
= getenv("BABELTRACE_PLUGIN_PATH");
308 ret
= bt_common_append_plugin_path_dirs(envvar
, dirs
);
310 BT_LIB_LOGE_APPEND_CAUSE(
311 "Failed to append plugin path to array of directories.");
312 status
= BT_FUNC_STATUS_MEMORY_ERROR
;
318 if (find_in_user_dir
) {
319 home_plugin_dir
= bt_common_get_home_plugin_path(
320 BT_LOG_OUTPUT_LEVEL
);
321 if (home_plugin_dir
) {
322 GString
*home_plugin_dir_str
= g_string_new(
325 if (!home_plugin_dir_str
) {
326 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GString.");
327 status
= BT_FUNC_STATUS_MEMORY_ERROR
;
331 g_ptr_array_add(dirs
, home_plugin_dir_str
);
335 if (find_in_sys_dir
) {
336 const char *system_plugin_dir
=
337 bt_common_get_system_plugin_path();
339 if (system_plugin_dir
) {
340 GString
*system_plugin_dir_str
=
341 g_string_new(system_plugin_dir
);
343 if (!system_plugin_dir_str
) {
344 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GString.");
345 status
= BT_FUNC_STATUS_MEMORY_ERROR
;
349 g_ptr_array_add(dirs
, system_plugin_dir_str
);
353 for (dir_i
= 0; dir_i
< dirs
->len
; dir_i
++) {
354 GString
*dir
= dirs
->pdata
[dir_i
];
356 BT_OBJECT_PUT_REF_AND_RESET(plugin_set
);
359 * Skip this if the directory does not exist because
360 * bt_plugin_find_all_from_dir() would log a warning.
362 if (!g_file_test(dir
->str
, G_FILE_TEST_IS_DIR
)) {
363 BT_LOGI("Skipping nonexistent directory path: "
364 "path=\"%s\"", dir
->str
);
368 /* bt_plugin_find_all_from_dir() logs details/errors */
369 status
= bt_plugin_find_all_from_dir(dir
->str
, BT_FALSE
,
370 fail_on_load_error
, &plugin_set
);
372 BT_ASSERT(!plugin_set
);
374 } else if (status
== BT_FUNC_STATUS_NOT_FOUND
) {
375 BT_ASSERT(!plugin_set
);
376 BT_LOGI("No plugins found in directory: path=\"%s\"",
381 BT_ASSERT(status
== BT_FUNC_STATUS_OK
);
382 BT_ASSERT(plugin_set
);
383 BT_LOGI("Found plugins in directory: path=\"%s\", count=%u",
384 dir
->str
, plugin_set
->plugins
->len
);
386 for (plugin_i
= 0; plugin_i
< plugin_set
->plugins
->len
;
388 bt_plugin_set_add_plugin((void *) *plugin_set_out
,
389 plugin_set
->plugins
->pdata
[plugin_i
]);
393 if (find_in_static
) {
394 BT_OBJECT_PUT_REF_AND_RESET(plugin_set
);
395 status
= bt_plugin_find_all_from_static(fail_on_load_error
,
398 BT_ASSERT(!plugin_set
);
400 } else if (status
== BT_FUNC_STATUS_NOT_FOUND
) {
401 BT_ASSERT(!plugin_set
);
402 BT_LOGI_STR("No plugins found in built-in plugins.");
406 BT_ASSERT(status
== BT_FUNC_STATUS_OK
);
407 BT_ASSERT(plugin_set
);
408 BT_LOGI("Found built-in plugins: count=%u",
409 plugin_set
->plugins
->len
);
411 for (plugin_i
= 0; plugin_i
< plugin_set
->plugins
->len
;
413 bt_plugin_set_add_plugin((void *) *plugin_set_out
,
414 plugin_set
->plugins
->pdata
[plugin_i
]);
419 free(home_plugin_dir
);
420 bt_object_put_ref(plugin_set
);
423 g_ptr_array_free(dirs
, TRUE
);
427 BT_OBJECT_PUT_REF_AND_RESET(*plugin_set_out
);
429 BT_ASSERT(*plugin_set_out
);
431 if ((*plugin_set_out
)->plugins
->len
> 0) {
432 BT_LOGI("Found plugins in standard directories and built-in plugins: "
433 "count=%u", (*plugin_set_out
)->plugins
->len
);
434 status
= BT_FUNC_STATUS_OK
;
436 BT_LOGI_STR("No plugins found in standard directories and built-in plugins.");
437 status
= BT_FUNC_STATUS_NOT_FOUND
;
438 BT_OBJECT_PUT_REF_AND_RESET(*plugin_set_out
);
445 enum bt_plugin_find_status
bt_plugin_find(const char *plugin_name
,
446 bt_bool find_in_std_env_var
, bt_bool find_in_user_dir
,
447 bt_bool find_in_sys_dir
, bt_bool find_in_static
,
448 bt_bool fail_on_load_error
, const struct bt_plugin
**plugin_out
)
450 enum bt_plugin_find_status status
;
451 const struct bt_plugin_set
*plugin_set
= NULL
;
454 BT_ASSERT_PRE_NO_ERROR();
455 BT_ASSERT_PRE_NON_NULL(plugin_name
, "Name");
456 BT_ASSERT_PRE_NON_NULL(plugin_out
, "Plugin (output)");
457 BT_LOGI("Finding named plugin in standard directories and built-in plugins: "
458 "name=\"%s\", find-in-std-env-var=%d, find-in-user-dir=%d, "
459 "find-in-sys-dir=%d, find-in-static=%d",
460 plugin_name
, find_in_std_env_var
, find_in_user_dir
,
461 find_in_sys_dir
, find_in_static
);
462 status
= (enum bt_plugin_find_status
) bt_plugin_find_all(find_in_std_env_var
, find_in_user_dir
,
463 find_in_sys_dir
, find_in_static
, fail_on_load_error
,
465 if (status
!= BT_FUNC_STATUS_OK
) {
466 BT_ASSERT(!plugin_set
);
470 BT_ASSERT(plugin_set
);
472 for (i
= 0; i
< plugin_set
->plugins
->len
; i
++) {
473 const struct bt_plugin
*plugin
= plugin_set
->plugins
->pdata
[i
];
475 if (strcmp(plugin
->info
.name
->str
, plugin_name
) == 0) {
476 *plugin_out
= plugin
;
477 bt_object_get_ref_no_null_check(*plugin_out
);
482 status
= BT_FUNC_STATUS_NOT_FOUND
;
485 if (status
== BT_FUNC_STATUS_OK
) {
486 BT_ASSERT(*plugin_out
);
487 BT_LIB_LOGI("Found plugin in standard directories and built-in plugins: "
488 "%!+l", *plugin_out
);
489 } else if (status
== BT_FUNC_STATUS_NOT_FOUND
) {
490 BT_LOGI("No plugin found in standard directories and built-in plugins: "
491 "name=\"%s\"", plugin_name
);
494 bt_plugin_set_put_ref(plugin_set
);
500 pthread_mutex_t lock
;
501 struct bt_plugin_set
*plugin_set
;
503 bool fail_on_load_error
;
505 } append_all_from_dir_info
= {
506 .lock
= PTHREAD_MUTEX_INITIALIZER
510 int nftw_append_all_from_dir(const char *file
,
511 const struct stat
*sb
, int flag
, struct FTW
*s
)
514 const char *name
= file
+ s
->base
;
516 /* Check for recursion */
517 if (!append_all_from_dir_info
.recurse
&& s
->level
> 1) {
524 const struct bt_plugin_set
*plugins_from_file
= NULL
;
526 if (name
[0] == '.') {
527 /* Skip hidden files */
528 BT_LOGI("Skipping hidden file: path=\"%s\"", file
);
532 append_all_from_dir_info
.status
=
533 bt_plugin_find_all_from_file(file
,
534 append_all_from_dir_info
.fail_on_load_error
,
536 if (append_all_from_dir_info
.status
== BT_FUNC_STATUS_OK
) {
539 BT_ASSERT(plugins_from_file
);
541 for (j
= 0; j
< plugins_from_file
->plugins
->len
; j
++) {
542 struct bt_plugin
*plugin
=
543 g_ptr_array_index(plugins_from_file
->plugins
, j
);
545 BT_LIB_LOGI("Adding plugin to plugin set: "
546 "plugin-path=\"%s\", %![plugin-]+l",
548 bt_plugin_set_add_plugin(
549 append_all_from_dir_info
.plugin_set
,
553 bt_object_put_ref(plugins_from_file
);
555 } else if (append_all_from_dir_info
.status
< 0) {
556 /* bt_plugin_find_all_from_file() logs errors */
557 BT_ASSERT(!plugins_from_file
);
563 * Not found in this file: this is no an error; continue
564 * walking the directories.
566 BT_ASSERT(!plugins_from_file
);
567 BT_ASSERT(append_all_from_dir_info
.status
==
568 BT_FUNC_STATUS_NOT_FOUND
);
572 /* Continue to next file / directory. */
573 BT_LOGI("Cannot enter directory: continuing: path=\"%s\"", file
);
576 /* Continue to next file / directory. */
577 BT_LOGI("Cannot get file information: continuing: path=\"%s\"", file
);
586 int bt_plugin_create_append_all_from_dir(struct bt_plugin_set
*plugin_set
,
587 const char *path
, bt_bool recurse
, bt_bool fail_on_load_error
)
589 int nftw_flags
= FTW_PHYS
;
594 BT_ASSERT(plugin_set
);
596 BT_ASSERT(strlen(path
) < PATH_MAX
);
599 * Make sure that path exists and is accessible.
600 * This is necessary since Cygwin implementation of nftw() is not POSIX
601 * compliant. Cygwin nftw() implementation does not fail on non-existent
602 * path with ENOENT. Instead, it flags the directory as FTW_NS. FTW_NS during
603 * nftw_append_all_from_dir is not treated as an error since we are
604 * traversing the tree for plugin discovery.
606 if (stat(path
, &sb
)) {
607 BT_LOGW_ERRNO("Cannot open directory",
608 ": path=\"%s\", recurse=%d",
610 (void) BT_CURRENT_THREAD_ERROR_APPEND_CAUSE_FROM_UNKNOWN(
611 BT_LIB_LOG_LIBBABELTRACE2_NAME
,
612 "Cannot open directory: path=\"%s\", recurse=%d",
614 status
= BT_FUNC_STATUS_ERROR
;
618 pthread_mutex_lock(&append_all_from_dir_info
.lock
);
619 append_all_from_dir_info
.plugin_set
= plugin_set
;
620 append_all_from_dir_info
.recurse
= recurse
;
621 append_all_from_dir_info
.status
= BT_FUNC_STATUS_OK
;
622 append_all_from_dir_info
.fail_on_load_error
= fail_on_load_error
;
623 ret
= nftw(path
, nftw_append_all_from_dir
,
624 APPEND_ALL_FROM_DIR_NFDOPEN_MAX
, nftw_flags
);
625 append_all_from_dir_info
.plugin_set
= NULL
;
626 status
= append_all_from_dir_info
.status
;
627 pthread_mutex_unlock(&append_all_from_dir_info
.lock
);
629 BT_LIB_LOGW_APPEND_CAUSE("Failed to walk directory",
630 ": path=\"%s\", recurse=%d",
632 status
= BT_FUNC_STATUS_ERROR
;
636 if (status
== BT_FUNC_STATUS_NOT_FOUND
) {
638 * We're just appending in this function; even if
639 * nothing was found, it's still okay from the caller's
642 status
= BT_FUNC_STATUS_OK
;
649 enum bt_plugin_find_all_from_dir_status
bt_plugin_find_all_from_dir(
650 const char *path
, bt_bool recurse
, bt_bool fail_on_load_error
,
651 const struct bt_plugin_set
**plugin_set_out
)
653 enum bt_plugin_find_all_from_dir_status status
=
656 BT_ASSERT_PRE_NO_ERROR();
657 BT_ASSERT_PRE_NON_NULL(plugin_set_out
, "Plugin set (output)");
658 BT_LOGI("Creating all plugins in directory: path=\"%s\", recurse=%d",
660 *plugin_set_out
= bt_plugin_set_create();
661 if (!*plugin_set_out
) {
662 BT_LIB_LOGE_APPEND_CAUSE("Cannot create empty plugin set.");
663 status
= BT_FUNC_STATUS_MEMORY_ERROR
;
668 * Append found plugins to array (never returns
669 * `BT_FUNC_STATUS_NOT_FOUND`)
671 status
= bt_plugin_create_append_all_from_dir((void *) *plugin_set_out
,
672 path
, recurse
, fail_on_load_error
);
675 * bt_plugin_create_append_all_from_dir() handles
676 * `fail_on_load_error`, so this is a "real" error.
678 BT_LIB_LOGE_APPEND_CAUSE(
679 "Cannot append plugins found in directory: "
680 "path=\"%s\", status=%s",
681 path
, bt_common_func_status_string(status
));
685 BT_ASSERT(status
== BT_FUNC_STATUS_OK
);
687 if ((*plugin_set_out
)->plugins
->len
== 0) {
688 /* Nothing was appended: not found */
689 BT_LOGI("No plugins found in directory: path=\"%s\"", path
);
690 status
= BT_FUNC_STATUS_NOT_FOUND
;
694 BT_LOGI("Created %u plugins from directory: count=%u, path=\"%s\"",
695 (*plugin_set_out
)->plugins
->len
,
696 (*plugin_set_out
)->plugins
->len
, path
);
700 BT_ASSERT(status
!= BT_FUNC_STATUS_OK
);
701 BT_OBJECT_PUT_REF_AND_RESET(*plugin_set_out
);
707 const char *bt_plugin_get_name(const struct bt_plugin
*plugin
)
709 BT_ASSERT_PRE_DEV_NON_NULL(plugin
, "Plugin");
710 return plugin
->info
.name_set
? plugin
->info
.name
->str
: NULL
;
713 const char *bt_plugin_get_author(const struct bt_plugin
*plugin
)
715 BT_ASSERT_PRE_DEV_NON_NULL(plugin
, "Plugin");
716 return plugin
->info
.author_set
? plugin
->info
.author
->str
: NULL
;
719 const char *bt_plugin_get_license(const struct bt_plugin
*plugin
)
721 BT_ASSERT_PRE_DEV_NON_NULL(plugin
, "Plugin");
722 return plugin
->info
.license_set
? plugin
->info
.license
->str
: NULL
;
725 const char *bt_plugin_get_path(const struct bt_plugin
*plugin
)
727 BT_ASSERT_PRE_DEV_NON_NULL(plugin
, "Plugin");
728 return plugin
->info
.path_set
? plugin
->info
.path
->str
: NULL
;
731 const char *bt_plugin_get_description(const struct bt_plugin
*plugin
)
733 BT_ASSERT_PRE_DEV_NON_NULL(plugin
, "Plugin");
734 return plugin
->info
.description_set
?
735 plugin
->info
.description
->str
: NULL
;
738 enum bt_property_availability
bt_plugin_get_version(const struct bt_plugin
*plugin
,
739 unsigned int *major
, unsigned int *minor
, unsigned int *patch
,
742 enum bt_property_availability avail
=
743 BT_PROPERTY_AVAILABILITY_AVAILABLE
;
745 BT_ASSERT_PRE_DEV_NON_NULL(plugin
, "Plugin");
747 if (!plugin
->info
.version_set
) {
748 BT_LIB_LOGD("Plugin's version is not set: %!+l", plugin
);
749 avail
= BT_PROPERTY_AVAILABILITY_NOT_AVAILABLE
;
754 *major
= plugin
->info
.version
.major
;
758 *minor
= plugin
->info
.version
.minor
;
762 *patch
= plugin
->info
.version
.patch
;
766 *extra
= plugin
->info
.version
.extra
->str
;
773 uint64_t bt_plugin_get_source_component_class_count(const struct bt_plugin
*plugin
)
775 BT_ASSERT_PRE_DEV_NON_NULL(plugin
, "Plugin");
776 return (uint64_t) plugin
->src_comp_classes
->len
;
779 uint64_t bt_plugin_get_filter_component_class_count(const struct bt_plugin
*plugin
)
781 BT_ASSERT_PRE_DEV_NON_NULL(plugin
, "Plugin");
782 return (uint64_t) plugin
->flt_comp_classes
->len
;
785 uint64_t bt_plugin_get_sink_component_class_count(const struct bt_plugin
*plugin
)
787 BT_ASSERT_PRE_DEV_NON_NULL(plugin
, "Plugin");
788 return (uint64_t) plugin
->sink_comp_classes
->len
;
792 struct bt_component_class
*borrow_component_class_by_index(
793 const struct bt_plugin
*plugin
, GPtrArray
*comp_classes
,
796 BT_ASSERT_PRE_DEV_NON_NULL(plugin
, "Plugin");
797 BT_ASSERT_PRE_DEV_VALID_INDEX(index
, comp_classes
->len
);
798 return g_ptr_array_index(comp_classes
, index
);
801 const struct bt_component_class_source
*
802 bt_plugin_borrow_source_component_class_by_index_const(
803 const struct bt_plugin
*plugin
, uint64_t index
)
805 return (const void *) borrow_component_class_by_index(plugin
,
806 plugin
->src_comp_classes
, index
);
809 const struct bt_component_class_filter
*
810 bt_plugin_borrow_filter_component_class_by_index_const(
811 const struct bt_plugin
*plugin
, uint64_t index
)
813 return (const void *) borrow_component_class_by_index(plugin
,
814 plugin
->flt_comp_classes
, index
);
817 const struct bt_component_class_sink
*
818 bt_plugin_borrow_sink_component_class_by_index_const(
819 const struct bt_plugin
*plugin
, uint64_t index
)
821 return (const void *) borrow_component_class_by_index(plugin
,
822 plugin
->sink_comp_classes
, index
);
826 struct bt_component_class
*borrow_component_class_by_name(
827 const struct bt_plugin
*plugin
, GPtrArray
*comp_classes
,
830 struct bt_component_class
*comp_class
= NULL
;
833 BT_ASSERT_PRE_DEV_NON_NULL(plugin
, "Plugin");
834 BT_ASSERT_PRE_DEV_NON_NULL(name
, "Name");
836 for (i
= 0; i
< comp_classes
->len
; i
++) {
837 struct bt_component_class
*comp_class_candidate
=
838 g_ptr_array_index(comp_classes
, i
);
839 const char *comp_class_cand_name
=
840 bt_component_class_get_name(comp_class_candidate
);
842 BT_ASSERT_DBG(comp_class_cand_name
);
844 if (strcmp(name
, comp_class_cand_name
) == 0) {
845 comp_class
= comp_class_candidate
;
853 const struct bt_component_class_source
*
854 bt_plugin_borrow_source_component_class_by_name_const(
855 const struct bt_plugin
*plugin
, const char *name
)
857 return (const void *) borrow_component_class_by_name(plugin
,
858 plugin
->src_comp_classes
, name
);
861 const struct bt_component_class_filter
*
862 bt_plugin_borrow_filter_component_class_by_name_const(
863 const struct bt_plugin
*plugin
, const char *name
)
865 return (const void *) borrow_component_class_by_name(plugin
,
866 plugin
->flt_comp_classes
, name
);
869 const struct bt_component_class_sink
*
870 bt_plugin_borrow_sink_component_class_by_name_const(
871 const struct bt_plugin
*plugin
, const char *name
)
873 return (const void *) borrow_component_class_by_name(plugin
,
874 plugin
->sink_comp_classes
, name
);
877 void bt_plugin_get_ref(const struct bt_plugin
*plugin
)
879 bt_object_get_ref(plugin
);
882 void bt_plugin_put_ref(const struct bt_plugin
*plugin
)
884 bt_object_put_ref(plugin
);
887 void bt_plugin_set_get_ref(const struct bt_plugin_set
*plugin_set
)
889 bt_object_get_ref(plugin_set
);
892 void bt_plugin_set_put_ref(const struct bt_plugin_set
*plugin_set
)
894 bt_object_put_ref(plugin_set
);