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
;
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
;
162 const struct bt_plugin
*bt_plugin_set_borrow_plugin_by_index_const(
163 const struct bt_plugin_set
*plugin_set
, uint64_t index
)
165 BT_ASSERT_PRE_DEV_PLUGIN_SET_NON_NULL(plugin_set
);
166 BT_ASSERT_PRE_DEV_VALID_INDEX(index
, plugin_set
->plugins
->len
);
167 return g_ptr_array_index(plugin_set
->plugins
, index
);
170 enum bt_plugin_find_all_from_static_status
bt_plugin_find_all_from_static(
171 bt_bool fail_on_load_error
,
172 const struct bt_plugin_set
**plugin_set_out
)
174 BT_ASSERT_PRE_NO_ERROR();
176 /* bt_plugin_so_create_all_from_static() logs errors */
177 return bt_plugin_so_create_all_from_static(fail_on_load_error
,
178 (void *) plugin_set_out
);
181 enum bt_plugin_find_all_from_file_status
bt_plugin_find_all_from_file(
182 const char *path
, bt_bool fail_on_load_error
,
183 const struct bt_plugin_set
**plugin_set_out
)
185 enum bt_plugin_find_all_from_file_status status
;
187 BT_ASSERT_PRE_NO_ERROR();
188 BT_ASSERT_PRE_NON_NULL("path", path
, "Path");
189 BT_ASSERT_PRE_PLUGIN_SET_OUT_NON_NULL(path
);
190 BT_LOGI("Creating plugins from file: path=\"%s\"", path
);
192 /* Try shared object plugins */
193 status
= bt_plugin_so_create_all_from_file(path
, fail_on_load_error
,
194 (void *) plugin_set_out
);
195 if (status
== BT_FUNC_STATUS_OK
) {
196 BT_ASSERT(*plugin_set_out
);
197 BT_ASSERT((*plugin_set_out
)->plugins
->len
> 0);
199 } else if (status
< 0) {
200 BT_ASSERT(!*plugin_set_out
);
204 BT_ASSERT(status
== BT_FUNC_STATUS_NOT_FOUND
);
205 BT_ASSERT(!*plugin_set_out
);
207 /* Try Python plugins if support is available */
208 status
= init_python_plugin_provider();
210 /* init_python_plugin_provider() logs errors */
214 BT_ASSERT(status
== BT_FUNC_STATUS_OK
);
215 status
= BT_FUNC_STATUS_NOT_FOUND
;
217 if (bt_plugin_python_create_all_from_file_sym
) {
218 /* Python plugin provider exists */
219 status
= bt_plugin_python_create_all_from_file_sym(path
,
220 fail_on_load_error
, (void *) plugin_set_out
);
221 if (status
== BT_FUNC_STATUS_OK
) {
222 BT_ASSERT(*plugin_set_out
);
223 BT_ASSERT((*plugin_set_out
)->plugins
->len
> 0);
225 } else if (status
< 0) {
227 * bt_plugin_python_create_all_from_file_sym()
228 * handles `fail_on_load_error` itself, so this
231 BT_ASSERT(!*plugin_set_out
);
235 BT_ASSERT(status
== BT_FUNC_STATUS_NOT_FOUND
);
236 BT_ASSERT(!*plugin_set_out
);
240 if (status
== BT_FUNC_STATUS_OK
) {
241 BT_LOGI("Created %u plugins from file: "
242 "path=\"%s\", count=%u, plugin-set-addr=%p",
243 (*plugin_set_out
)->plugins
->len
, path
,
244 (*plugin_set_out
)->plugins
->len
,
246 } else if (status
== BT_FUNC_STATUS_NOT_FOUND
) {
247 BT_LOGI("Found no plugins in file: path=\"%s\"", path
);
254 void destroy_gstring(void *data
)
256 g_string_free(data
, TRUE
);
259 enum bt_plugin_find_all_status
bt_plugin_find_all(bt_bool find_in_std_env_var
,
260 bt_bool find_in_user_dir
, bt_bool find_in_sys_dir
,
261 bt_bool find_in_static
, bt_bool fail_on_load_error
,
262 const struct bt_plugin_set
**plugin_set_out
)
264 char *home_plugin_dir
= NULL
;
265 const struct bt_plugin_set
*plugin_set
= NULL
;
266 GPtrArray
*dirs
= NULL
;
268 int status
= BT_FUNC_STATUS_OK
;
269 uint64_t dir_i
, plugin_i
;
271 BT_ASSERT_PRE_NO_ERROR();
272 BT_ASSERT_PRE_PLUGIN_SET_OUT_NON_NULL(plugin_set_out
);
273 BT_LOGI("Finding all plugins in standard directories and built-in plugins: "
274 "find-in-std-env-var=%d, find-in-user-dir=%d, "
275 "find-in-sys-dir=%d, find-in-static=%d",
276 find_in_std_env_var
, find_in_user_dir
, find_in_sys_dir
,
278 dirs
= g_ptr_array_new_with_free_func((GDestroyNotify
) destroy_gstring
);
280 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GPtrArray.");
281 status
= BT_FUNC_STATUS_MEMORY_ERROR
;
285 *plugin_set_out
= bt_plugin_set_create();
286 if (!*plugin_set_out
) {
287 BT_LIB_LOGE_APPEND_CAUSE("Cannot create empty plugin set.");
288 status
= BT_FUNC_STATUS_MEMORY_ERROR
;
295 * 1. `BABELTRACE_PLUGIN_PATH` environment variable
296 * (colon-separated list of directories)
297 * 2. `~/.local/lib/babeltrace2/plugins`
298 * 3. Default system directory for Babeltrace plugins, usually
299 * `/usr/lib/babeltrace2/plugins` or
300 * `/usr/local/lib/babeltrace2/plugins` if installed locally
301 * 4. Built-in plugins (static)
303 * Directories are searched non-recursively.
305 if (find_in_std_env_var
) {
306 const char *envvar
= getenv("BABELTRACE_PLUGIN_PATH");
309 ret
= bt_common_append_plugin_path_dirs(envvar
, dirs
);
311 BT_LIB_LOGE_APPEND_CAUSE(
312 "Failed to append plugin path to array of directories.");
313 status
= BT_FUNC_STATUS_MEMORY_ERROR
;
319 if (find_in_user_dir
) {
320 home_plugin_dir
= bt_common_get_home_plugin_path(
321 BT_LOG_OUTPUT_LEVEL
);
322 if (home_plugin_dir
) {
323 GString
*home_plugin_dir_str
= g_string_new(
326 if (!home_plugin_dir_str
) {
327 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GString.");
328 status
= BT_FUNC_STATUS_MEMORY_ERROR
;
332 g_ptr_array_add(dirs
, home_plugin_dir_str
);
336 if (find_in_sys_dir
) {
337 const char *system_plugin_dir
=
338 bt_common_get_system_plugin_path();
340 if (system_plugin_dir
) {
341 GString
*system_plugin_dir_str
=
342 g_string_new(system_plugin_dir
);
344 if (!system_plugin_dir_str
) {
345 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GString.");
346 status
= BT_FUNC_STATUS_MEMORY_ERROR
;
350 g_ptr_array_add(dirs
, system_plugin_dir_str
);
354 for (dir_i
= 0; dir_i
< dirs
->len
; dir_i
++) {
355 GString
*dir
= dirs
->pdata
[dir_i
];
357 BT_OBJECT_PUT_REF_AND_RESET(plugin_set
);
360 * Skip this if the directory does not exist because
361 * bt_plugin_find_all_from_dir() would log a warning.
363 if (!g_file_test(dir
->str
, G_FILE_TEST_IS_DIR
)) {
364 BT_LOGI("Skipping nonexistent directory path: "
365 "path=\"%s\"", dir
->str
);
369 /* bt_plugin_find_all_from_dir() logs details/errors */
370 status
= bt_plugin_find_all_from_dir(dir
->str
, BT_FALSE
,
371 fail_on_load_error
, &plugin_set
);
373 BT_ASSERT(!plugin_set
);
375 } else if (status
== BT_FUNC_STATUS_NOT_FOUND
) {
376 BT_ASSERT(!plugin_set
);
377 BT_LOGI("No plugins found in directory: path=\"%s\"",
382 BT_ASSERT(status
== BT_FUNC_STATUS_OK
);
383 BT_ASSERT(plugin_set
);
384 BT_LOGI("Found plugins in directory: path=\"%s\", count=%u",
385 dir
->str
, plugin_set
->plugins
->len
);
387 for (plugin_i
= 0; plugin_i
< plugin_set
->plugins
->len
;
389 bt_plugin_set_add_plugin((void *) *plugin_set_out
,
390 plugin_set
->plugins
->pdata
[plugin_i
]);
394 if (find_in_static
) {
395 BT_OBJECT_PUT_REF_AND_RESET(plugin_set
);
396 status
= bt_plugin_find_all_from_static(fail_on_load_error
,
399 BT_ASSERT(!plugin_set
);
401 } else if (status
== BT_FUNC_STATUS_NOT_FOUND
) {
402 BT_ASSERT(!plugin_set
);
403 BT_LOGI_STR("No plugins found in built-in plugins.");
407 BT_ASSERT(status
== BT_FUNC_STATUS_OK
);
408 BT_ASSERT(plugin_set
);
409 BT_LOGI("Found built-in plugins: count=%u",
410 plugin_set
->plugins
->len
);
412 for (plugin_i
= 0; plugin_i
< plugin_set
->plugins
->len
;
414 bt_plugin_set_add_plugin((void *) *plugin_set_out
,
415 plugin_set
->plugins
->pdata
[plugin_i
]);
420 free(home_plugin_dir
);
421 bt_object_put_ref(plugin_set
);
424 g_ptr_array_free(dirs
, TRUE
);
428 BT_OBJECT_PUT_REF_AND_RESET(*plugin_set_out
);
430 BT_ASSERT(*plugin_set_out
);
432 if ((*plugin_set_out
)->plugins
->len
> 0) {
433 BT_LOGI("Found plugins in standard directories and built-in plugins: "
434 "count=%u", (*plugin_set_out
)->plugins
->len
);
435 status
= BT_FUNC_STATUS_OK
;
437 BT_LOGI_STR("No plugins found in standard directories and built-in plugins.");
438 status
= BT_FUNC_STATUS_NOT_FOUND
;
439 BT_OBJECT_PUT_REF_AND_RESET(*plugin_set_out
);
446 enum bt_plugin_find_status
bt_plugin_find(const char *plugin_name
,
447 bt_bool find_in_std_env_var
, bt_bool find_in_user_dir
,
448 bt_bool find_in_sys_dir
, bt_bool find_in_static
,
449 bt_bool fail_on_load_error
, const struct bt_plugin
**plugin_out
)
451 enum bt_plugin_find_status status
;
452 const struct bt_plugin_set
*plugin_set
= NULL
;
455 BT_ASSERT_PRE_NO_ERROR();
456 BT_ASSERT_PRE_NAME_NON_NULL(plugin_name
);
457 BT_ASSERT_PRE_PLUGIN_OUT_NON_NULL(plugin_out
);
458 BT_LOGI("Finding named plugin in standard directories and built-in plugins: "
459 "name=\"%s\", find-in-std-env-var=%d, find-in-user-dir=%d, "
460 "find-in-sys-dir=%d, find-in-static=%d",
461 plugin_name
, find_in_std_env_var
, find_in_user_dir
,
462 find_in_sys_dir
, find_in_static
);
463 status
= (enum bt_plugin_find_status
) bt_plugin_find_all(find_in_std_env_var
, find_in_user_dir
,
464 find_in_sys_dir
, find_in_static
, fail_on_load_error
,
466 if (status
!= BT_FUNC_STATUS_OK
) {
467 BT_ASSERT(!plugin_set
);
471 BT_ASSERT(plugin_set
);
473 for (i
= 0; i
< plugin_set
->plugins
->len
; i
++) {
474 const struct bt_plugin
*plugin
= plugin_set
->plugins
->pdata
[i
];
476 if (strcmp(plugin
->info
.name
->str
, plugin_name
) == 0) {
477 *plugin_out
= plugin
;
478 bt_object_get_ref_no_null_check(*plugin_out
);
483 status
= BT_FUNC_STATUS_NOT_FOUND
;
486 if (status
== BT_FUNC_STATUS_OK
) {
487 BT_ASSERT(*plugin_out
);
488 BT_LIB_LOGI("Found plugin in standard directories and built-in plugins: "
489 "%!+l", *plugin_out
);
490 } else if (status
== BT_FUNC_STATUS_NOT_FOUND
) {
491 BT_LOGI("No plugin found in standard directories and built-in plugins: "
492 "name=\"%s\"", plugin_name
);
495 bt_plugin_set_put_ref(plugin_set
);
501 pthread_mutex_t lock
;
502 struct bt_plugin_set
*plugin_set
;
504 bool fail_on_load_error
;
506 } append_all_from_dir_info
= {
507 .lock
= PTHREAD_MUTEX_INITIALIZER
511 int nftw_append_all_from_dir(const char *file
,
512 const struct stat
*sb
, int flag
, struct FTW
*s
)
515 const char *name
= file
+ s
->base
;
517 /* Check for recursion */
518 if (!append_all_from_dir_info
.recurse
&& s
->level
> 1) {
525 const struct bt_plugin_set
*plugins_from_file
= NULL
;
527 if (name
[0] == '.') {
528 /* Skip hidden files */
529 BT_LOGI("Skipping hidden file: path=\"%s\"", file
);
533 append_all_from_dir_info
.status
=
534 bt_plugin_find_all_from_file(file
,
535 append_all_from_dir_info
.fail_on_load_error
,
537 if (append_all_from_dir_info
.status
== BT_FUNC_STATUS_OK
) {
540 BT_ASSERT(plugins_from_file
);
542 for (j
= 0; j
< plugins_from_file
->plugins
->len
; j
++) {
543 struct bt_plugin
*plugin
=
544 g_ptr_array_index(plugins_from_file
->plugins
, j
);
546 BT_LIB_LOGI("Adding plugin to plugin set: "
547 "plugin-path=\"%s\", %![plugin-]+l",
549 bt_plugin_set_add_plugin(
550 append_all_from_dir_info
.plugin_set
,
554 bt_object_put_ref(plugins_from_file
);
556 } else if (append_all_from_dir_info
.status
< 0) {
557 /* bt_plugin_find_all_from_file() logs errors */
558 BT_ASSERT(!plugins_from_file
);
564 * Not found in this file: this is no an error; continue
565 * walking the directories.
567 BT_ASSERT(!plugins_from_file
);
568 BT_ASSERT(append_all_from_dir_info
.status
==
569 BT_FUNC_STATUS_NOT_FOUND
);
573 /* Continue to next file / directory. */
574 BT_LOGI("Cannot enter directory: continuing: path=\"%s\"", file
);
577 /* Continue to next file / directory. */
578 BT_LOGI("Cannot get file information: continuing: path=\"%s\"", file
);
587 int bt_plugin_create_append_all_from_dir(struct bt_plugin_set
*plugin_set
,
588 const char *path
, bt_bool recurse
, bt_bool fail_on_load_error
)
590 int nftw_flags
= FTW_PHYS
;
595 BT_ASSERT(plugin_set
);
597 BT_ASSERT(strlen(path
) < PATH_MAX
);
600 * Make sure that path exists and is accessible.
601 * This is necessary since Cygwin implementation of nftw() is not POSIX
602 * compliant. Cygwin nftw() implementation does not fail on non-existent
603 * path with ENOENT. Instead, it flags the directory as FTW_NS. FTW_NS during
604 * nftw_append_all_from_dir is not treated as an error since we are
605 * traversing the tree for plugin discovery.
607 if (stat(path
, &sb
)) {
608 BT_LOGW_ERRNO("Cannot open directory",
609 ": path=\"%s\", recurse=%d",
611 (void) BT_CURRENT_THREAD_ERROR_APPEND_CAUSE_FROM_UNKNOWN(
612 BT_LIB_LOG_LIBBABELTRACE2_NAME
,
613 "Cannot open directory: path=\"%s\", recurse=%d",
615 status
= BT_FUNC_STATUS_ERROR
;
619 pthread_mutex_lock(&append_all_from_dir_info
.lock
);
620 append_all_from_dir_info
.plugin_set
= plugin_set
;
621 append_all_from_dir_info
.recurse
= recurse
;
622 append_all_from_dir_info
.status
= BT_FUNC_STATUS_OK
;
623 append_all_from_dir_info
.fail_on_load_error
= fail_on_load_error
;
624 ret
= nftw(path
, nftw_append_all_from_dir
,
625 APPEND_ALL_FROM_DIR_NFDOPEN_MAX
, nftw_flags
);
626 append_all_from_dir_info
.plugin_set
= NULL
;
627 status
= append_all_from_dir_info
.status
;
628 pthread_mutex_unlock(&append_all_from_dir_info
.lock
);
630 BT_LIB_LOGW_APPEND_CAUSE("Failed to walk directory",
631 ": path=\"%s\", recurse=%d",
633 status
= BT_FUNC_STATUS_ERROR
;
637 if (status
== BT_FUNC_STATUS_NOT_FOUND
) {
639 * We're just appending in this function; even if
640 * nothing was found, it's still okay from the caller's
643 status
= BT_FUNC_STATUS_OK
;
650 enum bt_plugin_find_all_from_dir_status
bt_plugin_find_all_from_dir(
651 const char *path
, bt_bool recurse
, bt_bool fail_on_load_error
,
652 const struct bt_plugin_set
**plugin_set_out
)
654 enum bt_plugin_find_all_from_dir_status status
=
657 BT_ASSERT_PRE_NO_ERROR();
658 BT_ASSERT_PRE_PLUGIN_SET_OUT_NON_NULL(plugin_set_out
);
659 BT_LOGI("Creating all plugins in directory: path=\"%s\", recurse=%d",
661 *plugin_set_out
= bt_plugin_set_create();
662 if (!*plugin_set_out
) {
663 BT_LIB_LOGE_APPEND_CAUSE("Cannot create empty plugin set.");
664 status
= BT_FUNC_STATUS_MEMORY_ERROR
;
669 * Append found plugins to array (never returns
670 * `BT_FUNC_STATUS_NOT_FOUND`)
672 status
= bt_plugin_create_append_all_from_dir((void *) *plugin_set_out
,
673 path
, recurse
, fail_on_load_error
);
676 * bt_plugin_create_append_all_from_dir() handles
677 * `fail_on_load_error`, so this is a "real" error.
679 BT_LIB_LOGE_APPEND_CAUSE(
680 "Cannot append plugins found in directory: "
681 "path=\"%s\", status=%s",
682 path
, bt_common_func_status_string(status
));
686 BT_ASSERT(status
== BT_FUNC_STATUS_OK
);
688 if ((*plugin_set_out
)->plugins
->len
== 0) {
689 /* Nothing was appended: not found */
690 BT_LOGI("No plugins found in directory: path=\"%s\"", path
);
691 status
= BT_FUNC_STATUS_NOT_FOUND
;
695 BT_LOGI("Created %u plugins from directory: count=%u, path=\"%s\"",
696 (*plugin_set_out
)->plugins
->len
,
697 (*plugin_set_out
)->plugins
->len
, path
);
701 BT_ASSERT(status
!= BT_FUNC_STATUS_OK
);
702 BT_OBJECT_PUT_REF_AND_RESET(*plugin_set_out
);
708 const char *bt_plugin_get_name(const struct bt_plugin
*plugin
)
710 BT_ASSERT_PRE_DEV_PLUGIN_NON_NULL(plugin
);
711 return plugin
->info
.name_set
? plugin
->info
.name
->str
: NULL
;
714 const char *bt_plugin_get_author(const struct bt_plugin
*plugin
)
716 BT_ASSERT_PRE_DEV_PLUGIN_NON_NULL(plugin
);
717 return plugin
->info
.author_set
? plugin
->info
.author
->str
: NULL
;
720 const char *bt_plugin_get_license(const struct bt_plugin
*plugin
)
722 BT_ASSERT_PRE_DEV_PLUGIN_NON_NULL(plugin
);
723 return plugin
->info
.license_set
? plugin
->info
.license
->str
: NULL
;
726 const char *bt_plugin_get_path(const struct bt_plugin
*plugin
)
728 BT_ASSERT_PRE_DEV_PLUGIN_NON_NULL(plugin
);
729 return plugin
->info
.path_set
? plugin
->info
.path
->str
: NULL
;
732 const char *bt_plugin_get_description(const struct bt_plugin
*plugin
)
734 BT_ASSERT_PRE_DEV_PLUGIN_NON_NULL(plugin
);
735 return plugin
->info
.description_set
?
736 plugin
->info
.description
->str
: NULL
;
739 enum bt_property_availability
bt_plugin_get_version(const struct bt_plugin
*plugin
,
740 unsigned int *major
, unsigned int *minor
, unsigned int *patch
,
743 enum bt_property_availability avail
=
744 BT_PROPERTY_AVAILABILITY_AVAILABLE
;
746 BT_ASSERT_PRE_DEV_PLUGIN_NON_NULL(plugin
);
748 if (!plugin
->info
.version_set
) {
749 BT_LIB_LOGD("Plugin's version is not set: %!+l", plugin
);
750 avail
= BT_PROPERTY_AVAILABILITY_NOT_AVAILABLE
;
755 *major
= plugin
->info
.version
.major
;
759 *minor
= plugin
->info
.version
.minor
;
763 *patch
= plugin
->info
.version
.patch
;
767 *extra
= plugin
->info
.version
.extra
->str
;
774 uint64_t bt_plugin_get_source_component_class_count(const struct bt_plugin
*plugin
)
776 BT_ASSERT_PRE_DEV_PLUGIN_NON_NULL(plugin
);
777 return (uint64_t) plugin
->src_comp_classes
->len
;
780 uint64_t bt_plugin_get_filter_component_class_count(const struct bt_plugin
*plugin
)
782 BT_ASSERT_PRE_DEV_PLUGIN_NON_NULL(plugin
);
783 return (uint64_t) plugin
->flt_comp_classes
->len
;
786 uint64_t bt_plugin_get_sink_component_class_count(const struct bt_plugin
*plugin
)
788 BT_ASSERT_PRE_DEV_PLUGIN_NON_NULL(plugin
);
789 return (uint64_t) plugin
->sink_comp_classes
->len
;
793 struct bt_component_class
*borrow_component_class_by_index(
794 const struct bt_plugin
*plugin
, GPtrArray
*comp_classes
,
797 BT_ASSERT_PRE_DEV_PLUGIN_NON_NULL(plugin
);
798 BT_ASSERT_PRE_DEV_VALID_INDEX(index
, comp_classes
->len
);
799 return g_ptr_array_index(comp_classes
, index
);
802 const struct bt_component_class_source
*
803 bt_plugin_borrow_source_component_class_by_index_const(
804 const struct bt_plugin
*plugin
, uint64_t index
)
806 return (const void *) borrow_component_class_by_index(plugin
,
807 plugin
->src_comp_classes
, index
);
810 const struct bt_component_class_filter
*
811 bt_plugin_borrow_filter_component_class_by_index_const(
812 const struct bt_plugin
*plugin
, uint64_t index
)
814 return (const void *) borrow_component_class_by_index(plugin
,
815 plugin
->flt_comp_classes
, index
);
818 const struct bt_component_class_sink
*
819 bt_plugin_borrow_sink_component_class_by_index_const(
820 const struct bt_plugin
*plugin
, uint64_t index
)
822 return (const void *) borrow_component_class_by_index(plugin
,
823 plugin
->sink_comp_classes
, index
);
827 struct bt_component_class
*borrow_component_class_by_name(
828 const struct bt_plugin
*plugin
, GPtrArray
*comp_classes
,
831 struct bt_component_class
*comp_class
= NULL
;
834 BT_ASSERT_PRE_DEV_PLUGIN_NON_NULL(plugin
);
835 BT_ASSERT_PRE_DEV_NAME_NON_NULL(name
);
837 for (i
= 0; i
< comp_classes
->len
; i
++) {
838 struct bt_component_class
*comp_class_candidate
=
839 g_ptr_array_index(comp_classes
, i
);
840 const char *comp_class_cand_name
=
841 bt_component_class_get_name(comp_class_candidate
);
843 BT_ASSERT_DBG(comp_class_cand_name
);
845 if (strcmp(name
, comp_class_cand_name
) == 0) {
846 comp_class
= comp_class_candidate
;
854 const struct bt_component_class_source
*
855 bt_plugin_borrow_source_component_class_by_name_const(
856 const struct bt_plugin
*plugin
, const char *name
)
858 return (const void *) borrow_component_class_by_name(plugin
,
859 plugin
->src_comp_classes
, name
);
862 const struct bt_component_class_filter
*
863 bt_plugin_borrow_filter_component_class_by_name_const(
864 const struct bt_plugin
*plugin
, const char *name
)
866 return (const void *) borrow_component_class_by_name(plugin
,
867 plugin
->flt_comp_classes
, name
);
870 const struct bt_component_class_sink
*
871 bt_plugin_borrow_sink_component_class_by_name_const(
872 const struct bt_plugin
*plugin
, const char *name
)
874 return (const void *) borrow_component_class_by_name(plugin
,
875 plugin
->sink_comp_classes
, name
);
878 void bt_plugin_get_ref(const struct bt_plugin
*plugin
)
880 bt_object_get_ref(plugin
);
883 void bt_plugin_put_ref(const struct bt_plugin
*plugin
)
885 bt_object_put_ref(plugin
);
888 void bt_plugin_set_get_ref(const struct bt_plugin_set
*plugin_set
)
890 bt_object_get_ref(plugin_set
);
893 void bt_plugin_set_put_ref(const struct bt_plugin_set
*plugin_set
)
895 bt_object_put_ref(plugin_set
);