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 "lib/graph/component-class.h"
37 #include <babeltrace2/types.h>
48 #include "plugin-so.h"
50 #define PYTHON_PLUGIN_PROVIDER_FILENAME "libbabeltrace2-python-plugin-provider." G_MODULE_SUFFIX
51 #define PYTHON_PLUGIN_PROVIDER_SYM_NAME bt_plugin_python_create_all_from_file
52 #define PYTHON_PLUGIN_PROVIDER_SYM_NAME_STR G_STRINGIFY(PYTHON_PLUGIN_PROVIDER_SYM_NAME)
54 #define APPEND_ALL_FROM_DIR_NFDOPEN_MAX 8
56 #ifdef BT_BUILT_IN_PYTHON_PLUGIN_SUPPORT
57 #include <plugin/python-plugin-provider.h>
60 enum bt_plugin_status (*bt_plugin_python_create_all_from_file_sym
)(
61 const char *path
, bool fail_on_load_error
,
62 struct bt_plugin_set
**plugin_set_out
) =
63 bt_plugin_python_create_all_from_file
;
66 void init_python_plugin_provider(void)
69 #else /* BT_BUILT_IN_PYTHON_PLUGIN_SUPPORT */
70 static GModule
*python_plugin_provider_module
;
73 enum bt_plugin_status (*bt_plugin_python_create_all_from_file_sym
)(
74 const char *path
, bool fail_on_load_error
,
75 struct bt_plugin_set
**plugin_set_out
);
78 void init_python_plugin_provider(void) {
79 if (bt_plugin_python_create_all_from_file_sym
!= NULL
) {
83 BT_LOGI_STR("Loading Python plugin provider module.");
84 python_plugin_provider_module
=
85 g_module_open(PYTHON_PLUGIN_PROVIDER_FILENAME
, 0);
86 if (!python_plugin_provider_module
) {
88 * This is not an error. The whole point of having an
89 * external Python plugin provider is that it can be
90 * missing and the Babeltrace library still works.
92 BT_LOGI("Cannot open `%s`: %s: continuing without Python plugin support.",
93 PYTHON_PLUGIN_PROVIDER_FILENAME
, g_module_error());
97 if (!g_module_symbol(python_plugin_provider_module
,
98 PYTHON_PLUGIN_PROVIDER_SYM_NAME_STR
,
99 (gpointer
) &bt_plugin_python_create_all_from_file_sym
)) {
101 * This is an error because, since we found the Python
102 * plugin provider shared object, we expect this symbol
105 BT_LOGE("Cannot find the Python plugin provider loading symbol: "
106 "%s: continuing without Python plugin support: "
107 "file=\"%s\", symbol=\"%s\"",
109 PYTHON_PLUGIN_PROVIDER_FILENAME
,
110 PYTHON_PLUGIN_PROVIDER_SYM_NAME_STR
);
114 BT_LOGI("Loaded Python plugin provider module: addr=%p",
115 python_plugin_provider_module
);
118 __attribute__((destructor
)) static
119 void fini_python_plugin_provider(void) {
120 if (python_plugin_provider_module
) {
121 BT_LOGI("Unloading Python plugin provider module.");
123 if (!g_module_close(python_plugin_provider_module
)) {
124 BT_LOGE("Failed to close the Python plugin provider module: %s.",
128 python_plugin_provider_module
= NULL
;
133 uint64_t bt_plugin_set_get_plugin_count(struct bt_plugin_set
*plugin_set
)
135 BT_ASSERT_PRE_NON_NULL(plugin_set
, "Plugin set");
136 return (uint64_t) plugin_set
->plugins
->len
;
139 const struct bt_plugin
*bt_plugin_set_borrow_plugin_by_index_const(
140 const struct bt_plugin_set
*plugin_set
, uint64_t index
)
142 BT_ASSERT_PRE_NON_NULL(plugin_set
, "Plugin set");
143 BT_ASSERT_PRE_VALID_INDEX(index
, plugin_set
->plugins
->len
);
144 return g_ptr_array_index(plugin_set
->plugins
, index
);
147 enum bt_plugin_status
bt_plugin_find_all_from_static(
148 bt_bool fail_on_load_error
,
149 const struct bt_plugin_set
**plugin_set_out
)
151 /* bt_plugin_so_create_all_from_static() logs errors */
152 return bt_plugin_so_create_all_from_static(fail_on_load_error
,
153 (void *) plugin_set_out
);
156 enum bt_plugin_status
bt_plugin_find_all_from_file(const char *path
,
157 bt_bool fail_on_load_error
,
158 const struct bt_plugin_set
**plugin_set_out
)
160 enum bt_plugin_status status
;
162 BT_ASSERT_PRE_NON_NULL(path
, "Path");
163 BT_ASSERT_PRE_NON_NULL(path
, "Plugin set (output)");
164 BT_LOGI("Creating plugins from file: path=\"%s\"", path
);
166 /* Try shared object plugins */
167 status
= bt_plugin_so_create_all_from_file(path
, fail_on_load_error
,
168 (void *) plugin_set_out
);
169 if (status
== BT_PLUGIN_STATUS_OK
) {
170 BT_ASSERT(*plugin_set_out
);
171 BT_ASSERT((*plugin_set_out
)->plugins
->len
> 0);
173 } else if (status
< 0) {
174 BT_ASSERT(!*plugin_set_out
);
178 BT_ASSERT(status
== BT_PLUGIN_STATUS_NOT_FOUND
);
179 BT_ASSERT(!*plugin_set_out
);
181 /* Try Python plugins if support is available */
182 init_python_plugin_provider();
183 if (bt_plugin_python_create_all_from_file_sym
) {
184 status
= bt_plugin_python_create_all_from_file_sym(path
,
185 fail_on_load_error
, (void *) plugin_set_out
);
186 if (status
== BT_PLUGIN_STATUS_OK
) {
187 BT_ASSERT(*plugin_set_out
);
188 BT_ASSERT((*plugin_set_out
)->plugins
->len
> 0);
190 } else if (status
< 0) {
191 BT_ASSERT(!*plugin_set_out
);
195 BT_ASSERT(status
== BT_PLUGIN_STATUS_NOT_FOUND
);
196 BT_ASSERT(!*plugin_set_out
);
200 if (status
== BT_PLUGIN_STATUS_OK
) {
201 BT_LOGI("Created %u plugins from file: "
202 "path=\"%s\", count=%u, plugin-set-addr=%p",
203 (*plugin_set_out
)->plugins
->len
, path
,
204 (*plugin_set_out
)->plugins
->len
,
206 } else if (status
== BT_PLUGIN_STATUS_NOT_FOUND
) {
207 BT_LOGI("Found no plugins in file: path=\"%s\"", path
);
213 static void destroy_gstring(void *data
)
215 g_string_free(data
, TRUE
);
218 enum bt_plugin_status
bt_plugin_find(const char *plugin_name
,
219 bt_bool fail_on_load_error
, const struct bt_plugin
**plugin_out
)
221 const char *system_plugin_dir
;
222 char *home_plugin_dir
= NULL
;
224 const struct bt_plugin
*plugin
= NULL
;
225 const struct bt_plugin_set
*plugin_set
= NULL
;
226 GPtrArray
*dirs
= NULL
;
228 enum bt_plugin_status status
= BT_PLUGIN_STATUS_OK
;
231 BT_ASSERT_PRE_NON_NULL(plugin_name
, "Name");
232 BT_ASSERT_PRE_NON_NULL(plugin_out
, "Plugin (output)");
233 BT_LOGI("Finding named plugin in standard directories and built-in plugins: "
234 "name=\"%s\"", plugin_name
);
235 dirs
= g_ptr_array_new_with_free_func((GDestroyNotify
) destroy_gstring
);
237 BT_LOGE_STR("Failed to allocate a GPtrArray.");
238 status
= BT_PLUGIN_STATUS_NOMEM
;
245 * 1. BABELTRACE_PLUGIN_PATH environment variable
246 * (colon-separated list of directories)
247 * 2. ~/.local/lib/babeltrace2/plugins
248 * 3. Default system directory for Babeltrace plugins, usually
249 * /usr/lib/babeltrace2/plugins or
250 * /usr/local/lib/babeltrace2/plugins if installed
252 * 4. Built-in plugins (static)
254 * Directories are searched non-recursively.
256 envvar
= getenv("BABELTRACE_PLUGIN_PATH");
258 ret
= bt_common_append_plugin_path_dirs(envvar
, dirs
);
260 BT_LOGE_STR("Failed to append plugin path to array of directories.");
261 status
= BT_PLUGIN_STATUS_NOMEM
;
266 home_plugin_dir
= bt_common_get_home_plugin_path(BT_LOG_OUTPUT_LEVEL
);
267 if (home_plugin_dir
) {
268 GString
*home_plugin_dir_str
= g_string_new(home_plugin_dir
);
270 if (!home_plugin_dir_str
) {
271 BT_LOGE_STR("Failed to allocate a GString.");
272 status
= BT_PLUGIN_STATUS_NOMEM
;
276 g_ptr_array_add(dirs
, home_plugin_dir_str
);
279 system_plugin_dir
= bt_common_get_system_plugin_path();
280 if (system_plugin_dir
) {
281 GString
*system_plugin_dir_str
=
282 g_string_new(system_plugin_dir
);
284 if (!system_plugin_dir_str
) {
285 BT_LOGE_STR("Failed to allocate a GString.");
286 status
= BT_PLUGIN_STATUS_NOMEM
;
290 g_ptr_array_add(dirs
, system_plugin_dir_str
);
293 for (i
= 0; i
< dirs
->len
; i
++) {
294 GString
*dir
= g_ptr_array_index(dirs
, i
);
296 BT_OBJECT_PUT_REF_AND_RESET(plugin_set
);
299 * Skip this if the directory does not exist because
300 * bt_plugin_find_all_from_dir() would log a warning.
302 if (!g_file_test(dir
->str
, G_FILE_TEST_IS_DIR
)) {
303 BT_LOGI("Skipping nonexistent directory path: "
304 "path=\"%s\"", dir
->str
);
308 /* bt_plugin_find_all_from_dir() logs details/errors */
309 status
= bt_plugin_find_all_from_dir(dir
->str
, BT_FALSE
,
310 fail_on_load_error
, &plugin_set
);
312 BT_ASSERT(!plugin_set
);
314 } else if (status
== BT_PLUGIN_STATUS_NOT_FOUND
) {
315 BT_ASSERT(!plugin_set
);
316 BT_LOGI("No plugins found in directory: path=\"%s\"",
321 BT_ASSERT(status
== BT_PLUGIN_STATUS_OK
);
322 BT_ASSERT(plugin_set
);
324 for (j
= 0; j
< plugin_set
->plugins
->len
; j
++) {
325 const struct bt_plugin
*candidate_plugin
=
326 g_ptr_array_index(plugin_set
->plugins
, j
);
328 if (strcmp(bt_plugin_get_name(candidate_plugin
),
330 BT_LOGI("Plugin found in directory: name=\"%s\", path=\"%s\"",
331 plugin_name
, dir
->str
);
332 *plugin_out
= candidate_plugin
;
333 bt_object_get_no_null_check(*plugin_out
);
338 BT_LOGI("Plugin not found in directory: name=\"%s\", path=\"%s\"",
339 plugin_name
, dir
->str
);
342 BT_OBJECT_PUT_REF_AND_RESET(plugin_set
);
343 status
= bt_plugin_find_all_from_static(fail_on_load_error
,
346 BT_ASSERT(!plugin_set
);
350 if (status
== BT_PLUGIN_STATUS_NOT_FOUND
) {
351 BT_ASSERT(!plugin_set
);
352 BT_LOGI_STR("No plugins found in built-in plugins.");
356 BT_ASSERT(status
== BT_PLUGIN_STATUS_OK
);
357 BT_ASSERT(plugin_set
);
359 for (j
= 0; j
< plugin_set
->plugins
->len
; j
++) {
360 const struct bt_plugin
*candidate_plugin
=
361 g_ptr_array_index(plugin_set
->plugins
, j
);
363 if (strcmp(bt_plugin_get_name(candidate_plugin
),
365 BT_LOGI("Plugin found in built-in plugins: "
366 "name=\"%s\"", plugin_name
);
367 *plugin_out
= candidate_plugin
;
368 bt_object_get_no_null_check(*plugin_out
);
373 status
= BT_PLUGIN_STATUS_NOT_FOUND
;
376 free(home_plugin_dir
);
377 bt_object_put_ref(plugin_set
);
380 g_ptr_array_free(dirs
, TRUE
);
383 if (status
== BT_PLUGIN_STATUS_OK
) {
384 BT_LIB_LOGI("Found plugin in standard directories and built-in plugins: "
386 } else if (status
== BT_PLUGIN_STATUS_NOT_FOUND
) {
387 BT_LOGI("No plugin found in standard directories and built-in plugins: "
388 "name=\"%s\"", plugin_name
);
395 pthread_mutex_t lock
;
396 struct bt_plugin_set
*plugin_set
;
398 bool fail_on_load_error
;
399 enum bt_plugin_status status
;
400 } append_all_from_dir_info
= {
401 .lock
= PTHREAD_MUTEX_INITIALIZER
405 int nftw_append_all_from_dir(const char *file
,
406 const struct stat
*sb
, int flag
, struct FTW
*s
)
409 const char *name
= file
+ s
->base
;
411 /* Check for recursion */
412 if (!append_all_from_dir_info
.recurse
&& s
->level
> 1) {
419 const struct bt_plugin_set
*plugins_from_file
= NULL
;
421 if (name
[0] == '.') {
422 /* Skip hidden files */
423 BT_LOGI("Skipping hidden file: path=\"%s\"", file
);
427 append_all_from_dir_info
.status
=
428 bt_plugin_find_all_from_file(file
,
429 append_all_from_dir_info
.fail_on_load_error
,
431 if (append_all_from_dir_info
.status
== BT_PLUGIN_STATUS_OK
) {
434 BT_ASSERT(plugins_from_file
);
436 for (j
= 0; j
< plugins_from_file
->plugins
->len
; j
++) {
437 struct bt_plugin
*plugin
=
438 g_ptr_array_index(plugins_from_file
->plugins
, j
);
440 BT_LIB_LOGI("Adding plugin to plugin set: "
441 "plugin-path=\"%s\", %![plugin-]+l",
443 bt_plugin_set_add_plugin(
444 append_all_from_dir_info
.plugin_set
,
448 bt_object_put_ref(plugins_from_file
);
450 } else if (append_all_from_dir_info
.status
< 0) {
451 /* bt_plugin_find_all_from_file() logs errors */
452 BT_ASSERT(!plugins_from_file
);
458 * Not found in this file: this is no an error; continue
459 * walking the directories.
461 BT_ASSERT(!plugins_from_file
);
462 BT_ASSERT(append_all_from_dir_info
.status
==
463 BT_PLUGIN_STATUS_NOT_FOUND
);
467 /* Continue to next file / directory. */
468 BT_LOGI("Cannot enter directory: continuing: path=\"%s\"", file
);
471 /* Continue to next file / directory. */
472 BT_LOGI("Cannot get file information: continuing: path=\"%s\"", file
);
481 enum bt_plugin_status
bt_plugin_create_append_all_from_dir(
482 struct bt_plugin_set
*plugin_set
, const char *path
,
483 bt_bool recurse
, bt_bool fail_on_load_error
)
485 int nftw_flags
= FTW_PHYS
;
487 enum bt_plugin_status status
;
490 BT_ASSERT(plugin_set
);
492 BT_ASSERT(strlen(path
) < PATH_MAX
);
495 * Make sure that path exists and is accessible.
496 * This is necessary since Cygwin implementation of nftw() is not POSIX
497 * compliant. Cygwin nftw() implementation does not fail on non-existent
498 * path with ENOENT. Instead, it flags the directory as FTW_NS. FTW_NS during
499 * nftw_append_all_from_dir is not treated as an error since we are
500 * traversing the tree for plugin discovery.
502 if (stat(path
, &sb
)) {
503 BT_LOGW_ERRNO("Cannot open directory",
504 ": path=\"%s\", recurse=%d",
506 status
= BT_PLUGIN_STATUS_ERROR
;
510 pthread_mutex_lock(&append_all_from_dir_info
.lock
);
511 append_all_from_dir_info
.plugin_set
= plugin_set
;
512 append_all_from_dir_info
.recurse
= recurse
;
513 append_all_from_dir_info
.status
= BT_PLUGIN_STATUS_OK
;
514 append_all_from_dir_info
.fail_on_load_error
= fail_on_load_error
;
515 ret
= nftw(path
, nftw_append_all_from_dir
,
516 APPEND_ALL_FROM_DIR_NFDOPEN_MAX
, nftw_flags
);
517 append_all_from_dir_info
.plugin_set
= NULL
;
518 status
= append_all_from_dir_info
.status
;
519 pthread_mutex_unlock(&append_all_from_dir_info
.lock
);
521 BT_LOGW_ERRNO("Failed to walk directory",
522 ": path=\"%s\", recurse=%d",
524 status
= BT_PLUGIN_STATUS_ERROR
;
528 if (status
== BT_PLUGIN_STATUS_NOT_FOUND
) {
530 * We're just appending in this function; even if
531 * nothing was found, it's still okay from the caller's
534 status
= BT_PLUGIN_STATUS_OK
;
541 enum bt_plugin_status
bt_plugin_find_all_from_dir(const char *path
,
542 bt_bool recurse
, bt_bool fail_on_load_error
,
543 const struct bt_plugin_set
**plugin_set_out
)
545 enum bt_plugin_status status
= BT_PLUGIN_STATUS_OK
;
547 BT_ASSERT_PRE_NON_NULL(plugin_set_out
, "Plugin set (output)");
548 BT_LOGI("Creating all plugins in directory: path=\"%s\", recurse=%d",
550 *plugin_set_out
= bt_plugin_set_create();
551 if (!*plugin_set_out
) {
552 BT_LOGE_STR("Cannot create empty plugin set.");
553 status
= BT_PLUGIN_STATUS_NOMEM
;
558 * Append found plugins to array (never returns
559 * `BT_PLUGIN_STATUS_NOT_FOUND`)
561 status
= bt_plugin_create_append_all_from_dir((void *) *plugin_set_out
,
562 path
, recurse
, fail_on_load_error
);
565 * bt_plugin_create_append_all_from_dir() handles
566 * `fail_on_load_error`, so this is a "real" error.
568 BT_LOGW("Cannot append plugins found in directory: "
569 "path=\"%s\", status=%s",
570 path
, bt_plugin_status_string(status
));
574 BT_ASSERT(status
== BT_PLUGIN_STATUS_OK
);
576 if ((*plugin_set_out
)->plugins
->len
== 0) {
577 /* Nothing was appended: not found */
578 BT_LOGI("No plugins found in directory: path=\"%s\"", path
);
579 status
= BT_PLUGIN_STATUS_NOT_FOUND
;
583 BT_LOGI("Created %u plugins from directory: count=%u, path=\"%s\"",
584 (*plugin_set_out
)->plugins
->len
,
585 (*plugin_set_out
)->plugins
->len
, path
);
589 BT_ASSERT(status
!= BT_PLUGIN_STATUS_OK
);
590 BT_OBJECT_PUT_REF_AND_RESET(*plugin_set_out
);
596 const char *bt_plugin_get_name(const struct bt_plugin
*plugin
)
598 BT_ASSERT_PRE_NON_NULL(plugin
, "Plugin");
599 return plugin
->info
.name_set
? plugin
->info
.name
->str
: NULL
;
602 const char *bt_plugin_get_author(const struct bt_plugin
*plugin
)
604 BT_ASSERT_PRE_NON_NULL(plugin
, "Plugin");
605 return plugin
->info
.author_set
? plugin
->info
.author
->str
: NULL
;
608 const char *bt_plugin_get_license(const struct bt_plugin
*plugin
)
610 BT_ASSERT_PRE_NON_NULL(plugin
, "Plugin");
611 return plugin
->info
.license_set
? plugin
->info
.license
->str
: NULL
;
614 const char *bt_plugin_get_path(const struct bt_plugin
*plugin
)
616 BT_ASSERT_PRE_NON_NULL(plugin
, "Plugin");
617 return plugin
->info
.path_set
? plugin
->info
.path
->str
: NULL
;
620 const char *bt_plugin_get_description(const struct bt_plugin
*plugin
)
622 BT_ASSERT_PRE_NON_NULL(plugin
, "Plugin");
623 return plugin
->info
.description_set
?
624 plugin
->info
.description
->str
: NULL
;
627 enum bt_property_availability
bt_plugin_get_version(const struct bt_plugin
*plugin
,
628 unsigned int *major
, unsigned int *minor
, unsigned int *patch
,
631 enum bt_property_availability avail
=
632 BT_PROPERTY_AVAILABILITY_AVAILABLE
;
634 BT_ASSERT_PRE_NON_NULL(plugin
, "Plugin");
636 if (!plugin
->info
.version_set
) {
637 BT_LIB_LOGD("Plugin's version is not set: %!+l", plugin
);
638 avail
= BT_PROPERTY_AVAILABILITY_NOT_AVAILABLE
;
643 *major
= plugin
->info
.version
.major
;
647 *minor
= plugin
->info
.version
.minor
;
651 *patch
= plugin
->info
.version
.patch
;
655 *extra
= plugin
->info
.version
.extra
->str
;
662 uint64_t bt_plugin_get_source_component_class_count(const struct bt_plugin
*plugin
)
664 BT_ASSERT_PRE_NON_NULL(plugin
, "Plugin");
665 return (uint64_t) plugin
->src_comp_classes
->len
;
668 uint64_t bt_plugin_get_filter_component_class_count(const struct bt_plugin
*plugin
)
670 BT_ASSERT_PRE_NON_NULL(plugin
, "Plugin");
671 return (uint64_t) plugin
->flt_comp_classes
->len
;
674 uint64_t bt_plugin_get_sink_component_class_count(const struct bt_plugin
*plugin
)
676 BT_ASSERT_PRE_NON_NULL(plugin
, "Plugin");
677 return (uint64_t) plugin
->sink_comp_classes
->len
;
681 struct bt_component_class
*borrow_component_class_by_index(
682 const struct bt_plugin
*plugin
, GPtrArray
*comp_classes
,
685 BT_ASSERT_PRE_NON_NULL(plugin
, "Plugin");
686 BT_ASSERT_PRE_VALID_INDEX(index
, comp_classes
->len
);
687 return g_ptr_array_index(comp_classes
, index
);
690 const struct bt_component_class_source
*
691 bt_plugin_borrow_source_component_class_by_index_const(
692 const struct bt_plugin
*plugin
, uint64_t index
)
694 return (const void *) borrow_component_class_by_index(plugin
,
695 plugin
->src_comp_classes
, index
);
698 const struct bt_component_class_filter
*
699 bt_plugin_borrow_filter_component_class_by_index_const(
700 const struct bt_plugin
*plugin
, uint64_t index
)
702 return (const void *) borrow_component_class_by_index(plugin
,
703 plugin
->flt_comp_classes
, index
);
706 const struct bt_component_class_sink
*
707 bt_plugin_borrow_sink_component_class_by_index_const(
708 const struct bt_plugin
*plugin
, uint64_t index
)
710 return (const void *) borrow_component_class_by_index(plugin
,
711 plugin
->sink_comp_classes
, index
);
715 struct bt_component_class
*borrow_component_class_by_name(
716 const struct bt_plugin
*plugin
, GPtrArray
*comp_classes
,
719 struct bt_component_class
*comp_class
= NULL
;
722 BT_ASSERT_PRE_NON_NULL(plugin
, "Plugin");
723 BT_ASSERT_PRE_NON_NULL(name
, "Name");
725 for (i
= 0; i
< comp_classes
->len
; i
++) {
726 struct bt_component_class
*comp_class_candidate
=
727 g_ptr_array_index(comp_classes
, i
);
728 const char *comp_class_cand_name
=
729 bt_component_class_get_name(comp_class_candidate
);
731 BT_ASSERT(comp_class_cand_name
);
733 if (strcmp(name
, comp_class_cand_name
) == 0) {
734 comp_class
= comp_class_candidate
;
742 const struct bt_component_class_source
*
743 bt_plugin_borrow_source_component_class_by_name_const(
744 const struct bt_plugin
*plugin
, const char *name
)
746 return (const void *) borrow_component_class_by_name(plugin
,
747 plugin
->src_comp_classes
, name
);
750 const struct bt_component_class_filter
*
751 bt_plugin_borrow_filter_component_class_by_name_const(
752 const struct bt_plugin
*plugin
, const char *name
)
754 return (const void *) borrow_component_class_by_name(plugin
,
755 plugin
->flt_comp_classes
, name
);
758 const struct bt_component_class_sink
*
759 bt_plugin_borrow_sink_component_class_by_name_const(
760 const struct bt_plugin
*plugin
, const char *name
)
762 return (const void *) borrow_component_class_by_name(plugin
,
763 plugin
->sink_comp_classes
, name
);
766 void bt_plugin_get_ref(const struct bt_plugin
*plugin
)
768 bt_object_get_ref(plugin
);
771 void bt_plugin_put_ref(const struct bt_plugin
*plugin
)
773 bt_object_put_ref(plugin
);
776 void bt_plugin_set_get_ref(const struct bt_plugin_set
*plugin_set
)
778 bt_object_get_ref(plugin_set
);
781 void bt_plugin_set_put_ref(const struct bt_plugin_set
*plugin_set
)
783 bt_object_put_ref(plugin_set
);