2 * Copyright 2017-2018 Philippe Proulx <pproulx@efficios.com>
3 * Copyright 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com>
5 * Author: Jérémie Galarneau <jeremie.galarneau@efficios.com>
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the "Software"), to deal
9 * in the Software without restriction, including without limitation the rights
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 * copies of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26 #define BT_LOG_TAG "LIB/PLUGIN"
27 #include "lib/logging.h"
29 #include "common/assert.h"
30 #include "lib/assert-pre.h"
31 #include "common/macros.h"
32 #include "compat/compiler.h"
33 #include "common/common.h"
34 #include <babeltrace2/plugin/plugin-const.h>
35 #include <babeltrace2/graph/component-class-const.h>
36 #include <babeltrace2/current-thread.h>
37 #include "lib/graph/component-class.h"
38 #include <babeltrace2/types.h>
49 #include "plugin-so.h"
50 #include "lib/func-status.h"
52 #define PYTHON_PLUGIN_PROVIDER_FILENAME "libbabeltrace2-python-plugin-provider." G_MODULE_SUFFIX
53 #define PYTHON_PLUGIN_PROVIDER_SYM_NAME bt_plugin_python_create_all_from_file
54 #define PYTHON_PLUGIN_PROVIDER_SYM_NAME_STR G_STRINGIFY(PYTHON_PLUGIN_PROVIDER_SYM_NAME)
56 #define APPEND_ALL_FROM_DIR_NFDOPEN_MAX 8
58 #ifdef BT_BUILT_IN_PYTHON_PLUGIN_SUPPORT
59 #include <plugin/python-plugin-provider.h>
62 int (*bt_plugin_python_create_all_from_file_sym
)(
63 const char *path
, bool fail_on_load_error
,
64 struct bt_plugin_set
**plugin_set_out
) =
65 bt_plugin_python_create_all_from_file
;
68 enum bt_plugin_status
init_python_plugin_provider(void)
71 #else /* BT_BUILT_IN_PYTHON_PLUGIN_SUPPORT */
72 static GModule
*python_plugin_provider_module
;
75 int (*bt_plugin_python_create_all_from_file_sym
)(
76 const char *path
, bool fail_on_load_error
,
77 struct bt_plugin_set
**plugin_set_out
);
80 int init_python_plugin_provider(void) {
81 int status
= BT_FUNC_STATUS_OK
;
83 if (bt_plugin_python_create_all_from_file_sym
!= NULL
) {
87 BT_LOGI_STR("Loading Python plugin provider module.");
88 python_plugin_provider_module
=
89 g_module_open(PYTHON_PLUGIN_PROVIDER_FILENAME
, 0);
90 if (!python_plugin_provider_module
) {
92 * This is not an error. The whole point of having an
93 * external Python plugin provider is that it can be
94 * missing and the Babeltrace library still works.
96 BT_LOGI("Cannot open `%s`: %s: continuing without Python plugin support.",
97 PYTHON_PLUGIN_PROVIDER_FILENAME
, g_module_error());
101 if (!g_module_symbol(python_plugin_provider_module
,
102 PYTHON_PLUGIN_PROVIDER_SYM_NAME_STR
,
103 (gpointer
) &bt_plugin_python_create_all_from_file_sym
)) {
105 * This is an error because, since we found the Python
106 * plugin provider shared object, we expect this symbol
109 BT_LIB_LOGE_APPEND_CAUSE(
110 "Cannot find the Python plugin provider loading symbol: "
111 "%s: continuing without Python plugin support: "
112 "file=\"%s\", symbol=\"%s\"",
114 PYTHON_PLUGIN_PROVIDER_FILENAME
,
115 PYTHON_PLUGIN_PROVIDER_SYM_NAME_STR
);
116 status
= BT_FUNC_STATUS_ERROR
;
120 BT_LOGI("Loaded Python plugin provider module: addr=%p",
121 python_plugin_provider_module
);
127 __attribute__((destructor
)) static
128 void fini_python_plugin_provider(void) {
129 if (python_plugin_provider_module
) {
130 BT_LOGI("Unloading Python plugin provider module.");
132 if (!g_module_close(python_plugin_provider_module
)) {
134 * This occurs when the library is finalized: do
135 * NOT append an error cause.
137 BT_LOGE("Failed to close the Python plugin provider module: %s.",
141 python_plugin_provider_module
= NULL
;
146 uint64_t bt_plugin_set_get_plugin_count(struct bt_plugin_set
*plugin_set
)
148 BT_ASSERT_PRE_DEV_NON_NULL(plugin_set
, "Plugin set");
149 return (uint64_t) plugin_set
->plugins
->len
;
152 const struct bt_plugin
*bt_plugin_set_borrow_plugin_by_index_const(
153 const struct bt_plugin_set
*plugin_set
, uint64_t index
)
155 BT_ASSERT_PRE_DEV_NON_NULL(plugin_set
, "Plugin set");
156 BT_ASSERT_PRE_DEV_VALID_INDEX(index
, plugin_set
->plugins
->len
);
157 return g_ptr_array_index(plugin_set
->plugins
, index
);
160 enum bt_plugin_find_all_from_static_status
bt_plugin_find_all_from_static(
161 bt_bool fail_on_load_error
,
162 const struct bt_plugin_set
**plugin_set_out
)
164 /* bt_plugin_so_create_all_from_static() logs errors */
165 return bt_plugin_so_create_all_from_static(fail_on_load_error
,
166 (void *) plugin_set_out
);
169 enum bt_plugin_find_all_from_file_status
bt_plugin_find_all_from_file(
170 const char *path
, bt_bool fail_on_load_error
,
171 const struct bt_plugin_set
**plugin_set_out
)
173 enum bt_plugin_find_all_from_file_status status
;
175 BT_ASSERT_PRE_NON_NULL(path
, "Path");
176 BT_ASSERT_PRE_NON_NULL(path
, "Plugin set (output)");
177 BT_LOGI("Creating plugins from file: path=\"%s\"", path
);
179 /* Try shared object plugins */
180 status
= bt_plugin_so_create_all_from_file(path
, fail_on_load_error
,
181 (void *) plugin_set_out
);
182 if (status
== BT_FUNC_STATUS_OK
) {
183 BT_ASSERT(*plugin_set_out
);
184 BT_ASSERT((*plugin_set_out
)->plugins
->len
> 0);
186 } else if (status
< 0) {
187 BT_ASSERT(!*plugin_set_out
);
191 BT_ASSERT(status
== BT_FUNC_STATUS_NOT_FOUND
);
192 BT_ASSERT(!*plugin_set_out
);
194 /* Try Python plugins if support is available */
195 status
= init_python_plugin_provider();
197 /* init_python_plugin_provider() logs errors */
201 BT_ASSERT(status
== BT_FUNC_STATUS_OK
);
202 status
= BT_FUNC_STATUS_NOT_FOUND
;
204 if (bt_plugin_python_create_all_from_file_sym
) {
205 /* Python plugin provider exists */
206 status
= bt_plugin_python_create_all_from_file_sym(path
,
207 fail_on_load_error
, (void *) plugin_set_out
);
208 if (status
== BT_FUNC_STATUS_OK
) {
209 BT_ASSERT(*plugin_set_out
);
210 BT_ASSERT((*plugin_set_out
)->plugins
->len
> 0);
212 } else if (status
< 0) {
214 * bt_plugin_python_create_all_from_file_sym()
215 * handles `fail_on_load_error` itself, so this
218 BT_ASSERT(!*plugin_set_out
);
222 BT_ASSERT(status
== BT_FUNC_STATUS_NOT_FOUND
);
223 BT_ASSERT(!*plugin_set_out
);
227 if (status
== BT_FUNC_STATUS_OK
) {
228 BT_LOGI("Created %u plugins from file: "
229 "path=\"%s\", count=%u, plugin-set-addr=%p",
230 (*plugin_set_out
)->plugins
->len
, path
,
231 (*plugin_set_out
)->plugins
->len
,
233 } else if (status
== BT_FUNC_STATUS_NOT_FOUND
) {
234 BT_LOGI("Found no plugins in file: path=\"%s\"", path
);
240 static void destroy_gstring(void *data
)
242 g_string_free(data
, TRUE
);
245 enum bt_plugin_find_status
bt_plugin_find(const char *plugin_name
,
246 bt_bool fail_on_load_error
, const struct bt_plugin
**plugin_out
)
248 const char *system_plugin_dir
;
249 char *home_plugin_dir
= NULL
;
251 const struct bt_plugin
*plugin
= NULL
;
252 const struct bt_plugin_set
*plugin_set
= NULL
;
253 GPtrArray
*dirs
= NULL
;
255 int status
= BT_FUNC_STATUS_OK
;
258 BT_ASSERT_PRE_NON_NULL(plugin_name
, "Name");
259 BT_ASSERT_PRE_NON_NULL(plugin_out
, "Plugin (output)");
260 BT_LOGI("Finding named plugin in standard directories and built-in plugins: "
261 "name=\"%s\"", plugin_name
);
262 dirs
= g_ptr_array_new_with_free_func((GDestroyNotify
) destroy_gstring
);
264 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GPtrArray.");
265 status
= BT_FUNC_STATUS_MEMORY_ERROR
;
272 * 1. BABELTRACE_PLUGIN_PATH environment variable
273 * (colon-separated list of directories)
274 * 2. ~/.local/lib/babeltrace2/plugins
275 * 3. Default system directory for Babeltrace plugins, usually
276 * /usr/lib/babeltrace2/plugins or
277 * /usr/local/lib/babeltrace2/plugins if installed
279 * 4. Built-in plugins (static)
281 * Directories are searched non-recursively.
283 envvar
= getenv("BABELTRACE_PLUGIN_PATH");
285 ret
= bt_common_append_plugin_path_dirs(envvar
, dirs
);
287 BT_LIB_LOGE_APPEND_CAUSE(
288 "Failed to append plugin path to array of directories.");
289 status
= BT_FUNC_STATUS_MEMORY_ERROR
;
294 home_plugin_dir
= bt_common_get_home_plugin_path(BT_LOG_OUTPUT_LEVEL
);
295 if (home_plugin_dir
) {
296 GString
*home_plugin_dir_str
= g_string_new(home_plugin_dir
);
298 if (!home_plugin_dir_str
) {
299 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GString.");
300 status
= BT_FUNC_STATUS_MEMORY_ERROR
;
304 g_ptr_array_add(dirs
, home_plugin_dir_str
);
307 system_plugin_dir
= bt_common_get_system_plugin_path();
308 if (system_plugin_dir
) {
309 GString
*system_plugin_dir_str
=
310 g_string_new(system_plugin_dir
);
312 if (!system_plugin_dir_str
) {
313 BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GString.");
314 status
= BT_FUNC_STATUS_MEMORY_ERROR
;
318 g_ptr_array_add(dirs
, system_plugin_dir_str
);
321 for (i
= 0; i
< dirs
->len
; i
++) {
322 GString
*dir
= g_ptr_array_index(dirs
, i
);
324 BT_OBJECT_PUT_REF_AND_RESET(plugin_set
);
327 * Skip this if the directory does not exist because
328 * bt_plugin_find_all_from_dir() would log a warning.
330 if (!g_file_test(dir
->str
, G_FILE_TEST_IS_DIR
)) {
331 BT_LOGI("Skipping nonexistent directory path: "
332 "path=\"%s\"", dir
->str
);
336 /* bt_plugin_find_all_from_dir() logs details/errors */
337 status
= bt_plugin_find_all_from_dir(dir
->str
, BT_FALSE
,
338 fail_on_load_error
, &plugin_set
);
340 BT_ASSERT(!plugin_set
);
342 } else if (status
== BT_FUNC_STATUS_NOT_FOUND
) {
343 BT_ASSERT(!plugin_set
);
344 BT_LOGI("No plugins found in directory: path=\"%s\"",
349 BT_ASSERT(status
== BT_FUNC_STATUS_OK
);
350 BT_ASSERT(plugin_set
);
352 for (j
= 0; j
< plugin_set
->plugins
->len
; j
++) {
353 const struct bt_plugin
*candidate_plugin
=
354 g_ptr_array_index(plugin_set
->plugins
, j
);
356 if (strcmp(bt_plugin_get_name(candidate_plugin
),
358 BT_LOGI("Plugin found in directory: name=\"%s\", path=\"%s\"",
359 plugin_name
, dir
->str
);
360 *plugin_out
= candidate_plugin
;
361 bt_object_get_no_null_check(*plugin_out
);
366 BT_LOGI("Plugin not found in directory: name=\"%s\", path=\"%s\"",
367 plugin_name
, dir
->str
);
370 BT_OBJECT_PUT_REF_AND_RESET(plugin_set
);
371 status
= bt_plugin_find_all_from_static(fail_on_load_error
,
374 BT_ASSERT(!plugin_set
);
376 } else if (status
== BT_FUNC_STATUS_NOT_FOUND
) {
377 BT_ASSERT(!plugin_set
);
378 BT_LOGI_STR("No plugins found in built-in plugins.");
382 BT_ASSERT(status
== BT_FUNC_STATUS_OK
);
383 BT_ASSERT(plugin_set
);
385 for (j
= 0; j
< plugin_set
->plugins
->len
; j
++) {
386 const struct bt_plugin
*candidate_plugin
=
387 g_ptr_array_index(plugin_set
->plugins
, j
);
389 if (strcmp(bt_plugin_get_name(candidate_plugin
),
391 BT_LOGI("Plugin found in built-in plugins: "
392 "name=\"%s\"", plugin_name
);
393 *plugin_out
= candidate_plugin
;
394 bt_object_get_no_null_check(*plugin_out
);
399 status
= BT_FUNC_STATUS_NOT_FOUND
;
402 free(home_plugin_dir
);
403 bt_object_put_ref(plugin_set
);
406 g_ptr_array_free(dirs
, TRUE
);
409 if (status
== BT_FUNC_STATUS_OK
) {
410 BT_LIB_LOGI("Found plugin in standard directories and built-in plugins: "
412 } else if (status
== BT_FUNC_STATUS_NOT_FOUND
) {
413 BT_LOGI("No plugin found in standard directories and built-in plugins: "
414 "name=\"%s\"", plugin_name
);
421 pthread_mutex_t lock
;
422 struct bt_plugin_set
*plugin_set
;
424 bool fail_on_load_error
;
426 } append_all_from_dir_info
= {
427 .lock
= PTHREAD_MUTEX_INITIALIZER
431 int nftw_append_all_from_dir(const char *file
,
432 const struct stat
*sb
, int flag
, struct FTW
*s
)
435 const char *name
= file
+ s
->base
;
437 /* Check for recursion */
438 if (!append_all_from_dir_info
.recurse
&& s
->level
> 1) {
445 const struct bt_plugin_set
*plugins_from_file
= NULL
;
447 if (name
[0] == '.') {
448 /* Skip hidden files */
449 BT_LOGI("Skipping hidden file: path=\"%s\"", file
);
453 append_all_from_dir_info
.status
=
454 bt_plugin_find_all_from_file(file
,
455 append_all_from_dir_info
.fail_on_load_error
,
457 if (append_all_from_dir_info
.status
== BT_FUNC_STATUS_OK
) {
460 BT_ASSERT(plugins_from_file
);
462 for (j
= 0; j
< plugins_from_file
->plugins
->len
; j
++) {
463 struct bt_plugin
*plugin
=
464 g_ptr_array_index(plugins_from_file
->plugins
, j
);
466 BT_LIB_LOGI("Adding plugin to plugin set: "
467 "plugin-path=\"%s\", %![plugin-]+l",
469 bt_plugin_set_add_plugin(
470 append_all_from_dir_info
.plugin_set
,
474 bt_object_put_ref(plugins_from_file
);
476 } else if (append_all_from_dir_info
.status
< 0) {
477 /* bt_plugin_find_all_from_file() logs errors */
478 BT_ASSERT(!plugins_from_file
);
484 * Not found in this file: this is no an error; continue
485 * walking the directories.
487 BT_ASSERT(!plugins_from_file
);
488 BT_ASSERT(append_all_from_dir_info
.status
==
489 BT_FUNC_STATUS_NOT_FOUND
);
493 /* Continue to next file / directory. */
494 BT_LOGI("Cannot enter directory: continuing: path=\"%s\"", file
);
497 /* Continue to next file / directory. */
498 BT_LOGI("Cannot get file information: continuing: path=\"%s\"", file
);
507 int bt_plugin_create_append_all_from_dir(struct bt_plugin_set
*plugin_set
,
508 const char *path
, bt_bool recurse
, bt_bool fail_on_load_error
)
510 int nftw_flags
= FTW_PHYS
;
515 BT_ASSERT(plugin_set
);
517 BT_ASSERT(strlen(path
) < PATH_MAX
);
520 * Make sure that path exists and is accessible.
521 * This is necessary since Cygwin implementation of nftw() is not POSIX
522 * compliant. Cygwin nftw() implementation does not fail on non-existent
523 * path with ENOENT. Instead, it flags the directory as FTW_NS. FTW_NS during
524 * nftw_append_all_from_dir is not treated as an error since we are
525 * traversing the tree for plugin discovery.
527 if (stat(path
, &sb
)) {
528 BT_LOGW_ERRNO("Cannot open directory",
529 ": path=\"%s\", recurse=%d",
531 (void) BT_CURRENT_THREAD_ERROR_APPEND_CAUSE_FROM_UNKNOWN(
532 "Babeltrace library",
533 "Cannot open directory: path=\"%s\", recurse=%d",
535 status
= BT_FUNC_STATUS_ERROR
;
539 pthread_mutex_lock(&append_all_from_dir_info
.lock
);
540 append_all_from_dir_info
.plugin_set
= plugin_set
;
541 append_all_from_dir_info
.recurse
= recurse
;
542 append_all_from_dir_info
.status
= BT_FUNC_STATUS_OK
;
543 append_all_from_dir_info
.fail_on_load_error
= fail_on_load_error
;
544 ret
= nftw(path
, nftw_append_all_from_dir
,
545 APPEND_ALL_FROM_DIR_NFDOPEN_MAX
, nftw_flags
);
546 append_all_from_dir_info
.plugin_set
= NULL
;
547 status
= append_all_from_dir_info
.status
;
548 pthread_mutex_unlock(&append_all_from_dir_info
.lock
);
550 BT_LIB_LOGW_APPEND_CAUSE("Failed to walk directory",
551 ": path=\"%s\", recurse=%d",
553 status
= BT_FUNC_STATUS_ERROR
;
557 if (status
== BT_FUNC_STATUS_NOT_FOUND
) {
559 * We're just appending in this function; even if
560 * nothing was found, it's still okay from the caller's
563 status
= BT_FUNC_STATUS_OK
;
570 enum bt_plugin_find_all_from_dir_status
bt_plugin_find_all_from_dir(
571 const char *path
, bt_bool recurse
, bt_bool fail_on_load_error
,
572 const struct bt_plugin_set
**plugin_set_out
)
574 enum bt_plugin_find_all_from_dir_status status
=
577 BT_ASSERT_PRE_NON_NULL(plugin_set_out
, "Plugin set (output)");
578 BT_LOGI("Creating all plugins in directory: path=\"%s\", recurse=%d",
580 *plugin_set_out
= bt_plugin_set_create();
581 if (!*plugin_set_out
) {
582 BT_LIB_LOGE_APPEND_CAUSE("Cannot create empty plugin set.");
583 status
= BT_FUNC_STATUS_MEMORY_ERROR
;
588 * Append found plugins to array (never returns
589 * `BT_FUNC_STATUS_NOT_FOUND`)
591 status
= bt_plugin_create_append_all_from_dir((void *) *plugin_set_out
,
592 path
, recurse
, fail_on_load_error
);
595 * bt_plugin_create_append_all_from_dir() handles
596 * `fail_on_load_error`, so this is a "real" error.
598 BT_LIB_LOGE_APPEND_CAUSE(
599 "Cannot append plugins found in directory: "
600 "path=\"%s\", status=%s",
601 path
, bt_common_func_status_string(status
));
605 BT_ASSERT(status
== BT_FUNC_STATUS_OK
);
607 if ((*plugin_set_out
)->plugins
->len
== 0) {
608 /* Nothing was appended: not found */
609 BT_LOGI("No plugins found in directory: path=\"%s\"", path
);
610 status
= BT_FUNC_STATUS_NOT_FOUND
;
614 BT_LOGI("Created %u plugins from directory: count=%u, path=\"%s\"",
615 (*plugin_set_out
)->plugins
->len
,
616 (*plugin_set_out
)->plugins
->len
, path
);
620 BT_ASSERT(status
!= BT_FUNC_STATUS_OK
);
621 BT_OBJECT_PUT_REF_AND_RESET(*plugin_set_out
);
627 const char *bt_plugin_get_name(const struct bt_plugin
*plugin
)
629 BT_ASSERT_PRE_DEV_NON_NULL(plugin
, "Plugin");
630 return plugin
->info
.name_set
? plugin
->info
.name
->str
: NULL
;
633 const char *bt_plugin_get_author(const struct bt_plugin
*plugin
)
635 BT_ASSERT_PRE_DEV_NON_NULL(plugin
, "Plugin");
636 return plugin
->info
.author_set
? plugin
->info
.author
->str
: NULL
;
639 const char *bt_plugin_get_license(const struct bt_plugin
*plugin
)
641 BT_ASSERT_PRE_DEV_NON_NULL(plugin
, "Plugin");
642 return plugin
->info
.license_set
? plugin
->info
.license
->str
: NULL
;
645 const char *bt_plugin_get_path(const struct bt_plugin
*plugin
)
647 BT_ASSERT_PRE_DEV_NON_NULL(plugin
, "Plugin");
648 return plugin
->info
.path_set
? plugin
->info
.path
->str
: NULL
;
651 const char *bt_plugin_get_description(const struct bt_plugin
*plugin
)
653 BT_ASSERT_PRE_DEV_NON_NULL(plugin
, "Plugin");
654 return plugin
->info
.description_set
?
655 plugin
->info
.description
->str
: NULL
;
658 enum bt_property_availability
bt_plugin_get_version(const struct bt_plugin
*plugin
,
659 unsigned int *major
, unsigned int *minor
, unsigned int *patch
,
662 enum bt_property_availability avail
=
663 BT_PROPERTY_AVAILABILITY_AVAILABLE
;
665 BT_ASSERT_PRE_DEV_NON_NULL(plugin
, "Plugin");
667 if (!plugin
->info
.version_set
) {
668 BT_LIB_LOGD("Plugin's version is not set: %!+l", plugin
);
669 avail
= BT_PROPERTY_AVAILABILITY_NOT_AVAILABLE
;
674 *major
= plugin
->info
.version
.major
;
678 *minor
= plugin
->info
.version
.minor
;
682 *patch
= plugin
->info
.version
.patch
;
686 *extra
= plugin
->info
.version
.extra
->str
;
693 uint64_t bt_plugin_get_source_component_class_count(const struct bt_plugin
*plugin
)
695 BT_ASSERT_PRE_DEV_NON_NULL(plugin
, "Plugin");
696 return (uint64_t) plugin
->src_comp_classes
->len
;
699 uint64_t bt_plugin_get_filter_component_class_count(const struct bt_plugin
*plugin
)
701 BT_ASSERT_PRE_DEV_NON_NULL(plugin
, "Plugin");
702 return (uint64_t) plugin
->flt_comp_classes
->len
;
705 uint64_t bt_plugin_get_sink_component_class_count(const struct bt_plugin
*plugin
)
707 BT_ASSERT_PRE_DEV_NON_NULL(plugin
, "Plugin");
708 return (uint64_t) plugin
->sink_comp_classes
->len
;
712 struct bt_component_class
*borrow_component_class_by_index(
713 const struct bt_plugin
*plugin
, GPtrArray
*comp_classes
,
716 BT_ASSERT_PRE_DEV_NON_NULL(plugin
, "Plugin");
717 BT_ASSERT_PRE_DEV_VALID_INDEX(index
, comp_classes
->len
);
718 return g_ptr_array_index(comp_classes
, index
);
721 const struct bt_component_class_source
*
722 bt_plugin_borrow_source_component_class_by_index_const(
723 const struct bt_plugin
*plugin
, uint64_t index
)
725 return (const void *) borrow_component_class_by_index(plugin
,
726 plugin
->src_comp_classes
, index
);
729 const struct bt_component_class_filter
*
730 bt_plugin_borrow_filter_component_class_by_index_const(
731 const struct bt_plugin
*plugin
, uint64_t index
)
733 return (const void *) borrow_component_class_by_index(plugin
,
734 plugin
->flt_comp_classes
, index
);
737 const struct bt_component_class_sink
*
738 bt_plugin_borrow_sink_component_class_by_index_const(
739 const struct bt_plugin
*plugin
, uint64_t index
)
741 return (const void *) borrow_component_class_by_index(plugin
,
742 plugin
->sink_comp_classes
, index
);
746 struct bt_component_class
*borrow_component_class_by_name(
747 const struct bt_plugin
*plugin
, GPtrArray
*comp_classes
,
750 struct bt_component_class
*comp_class
= NULL
;
753 BT_ASSERT_PRE_DEV_NON_NULL(plugin
, "Plugin");
754 BT_ASSERT_PRE_DEV_NON_NULL(name
, "Name");
756 for (i
= 0; i
< comp_classes
->len
; i
++) {
757 struct bt_component_class
*comp_class_candidate
=
758 g_ptr_array_index(comp_classes
, i
);
759 const char *comp_class_cand_name
=
760 bt_component_class_get_name(comp_class_candidate
);
762 BT_ASSERT(comp_class_cand_name
);
764 if (strcmp(name
, comp_class_cand_name
) == 0) {
765 comp_class
= comp_class_candidate
;
773 const struct bt_component_class_source
*
774 bt_plugin_borrow_source_component_class_by_name_const(
775 const struct bt_plugin
*plugin
, const char *name
)
777 return (const void *) borrow_component_class_by_name(plugin
,
778 plugin
->src_comp_classes
, name
);
781 const struct bt_component_class_filter
*
782 bt_plugin_borrow_filter_component_class_by_name_const(
783 const struct bt_plugin
*plugin
, const char *name
)
785 return (const void *) borrow_component_class_by_name(plugin
,
786 plugin
->flt_comp_classes
, name
);
789 const struct bt_component_class_sink
*
790 bt_plugin_borrow_sink_component_class_by_name_const(
791 const struct bt_plugin
*plugin
, const char *name
)
793 return (const void *) borrow_component_class_by_name(plugin
,
794 plugin
->sink_comp_classes
, name
);
797 void bt_plugin_get_ref(const struct bt_plugin
*plugin
)
799 bt_object_get_ref(plugin
);
802 void bt_plugin_put_ref(const struct bt_plugin
*plugin
)
804 bt_object_put_ref(plugin
);
807 void bt_plugin_set_get_ref(const struct bt_plugin_set
*plugin_set
)
809 bt_object_get_ref(plugin_set
);
812 void bt_plugin_set_put_ref(const struct bt_plugin_set
*plugin_set
)
814 bt_object_put_ref(plugin_set
);