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"
49 #include "lib/func-status.h"
51 #define PYTHON_PLUGIN_PROVIDER_FILENAME "libbabeltrace2-python-plugin-provider." G_MODULE_SUFFIX
52 #define PYTHON_PLUGIN_PROVIDER_SYM_NAME bt_plugin_python_create_all_from_file
53 #define PYTHON_PLUGIN_PROVIDER_SYM_NAME_STR G_STRINGIFY(PYTHON_PLUGIN_PROVIDER_SYM_NAME)
55 #define APPEND_ALL_FROM_DIR_NFDOPEN_MAX 8
57 #ifdef BT_BUILT_IN_PYTHON_PLUGIN_SUPPORT
58 #include <plugin/python-plugin-provider.h>
61 int (*bt_plugin_python_create_all_from_file_sym
)(
62 const char *path
, bool fail_on_load_error
,
63 struct bt_plugin_set
**plugin_set_out
) =
64 bt_plugin_python_create_all_from_file
;
67 void init_python_plugin_provider(void)
70 #else /* BT_BUILT_IN_PYTHON_PLUGIN_SUPPORT */
71 static GModule
*python_plugin_provider_module
;
74 int (*bt_plugin_python_create_all_from_file_sym
)(
75 const char *path
, bool fail_on_load_error
,
76 struct bt_plugin_set
**plugin_set_out
);
79 void init_python_plugin_provider(void) {
80 if (bt_plugin_python_create_all_from_file_sym
!= NULL
) {
84 BT_LOGI_STR("Loading Python plugin provider module.");
85 python_plugin_provider_module
=
86 g_module_open(PYTHON_PLUGIN_PROVIDER_FILENAME
, 0);
87 if (!python_plugin_provider_module
) {
89 * This is not an error. The whole point of having an
90 * external Python plugin provider is that it can be
91 * missing and the Babeltrace library still works.
93 BT_LOGI("Cannot open `%s`: %s: continuing without Python plugin support.",
94 PYTHON_PLUGIN_PROVIDER_FILENAME
, g_module_error());
98 if (!g_module_symbol(python_plugin_provider_module
,
99 PYTHON_PLUGIN_PROVIDER_SYM_NAME_STR
,
100 (gpointer
) &bt_plugin_python_create_all_from_file_sym
)) {
102 * This is an error because, since we found the Python
103 * plugin provider shared object, we expect this symbol
106 BT_LOGE("Cannot find the Python plugin provider loading symbol: "
107 "%s: continuing without Python plugin support: "
108 "file=\"%s\", symbol=\"%s\"",
110 PYTHON_PLUGIN_PROVIDER_FILENAME
,
111 PYTHON_PLUGIN_PROVIDER_SYM_NAME_STR
);
115 BT_LOGI("Loaded Python plugin provider module: addr=%p",
116 python_plugin_provider_module
);
119 __attribute__((destructor
)) static
120 void fini_python_plugin_provider(void) {
121 if (python_plugin_provider_module
) {
122 BT_LOGI("Unloading Python plugin provider module.");
124 if (!g_module_close(python_plugin_provider_module
)) {
125 BT_LOGE("Failed to close the Python plugin provider module: %s.",
129 python_plugin_provider_module
= NULL
;
134 uint64_t bt_plugin_set_get_plugin_count(struct bt_plugin_set
*plugin_set
)
136 BT_ASSERT_PRE_NON_NULL(plugin_set
, "Plugin set");
137 return (uint64_t) plugin_set
->plugins
->len
;
140 const struct bt_plugin
*bt_plugin_set_borrow_plugin_by_index_const(
141 const struct bt_plugin_set
*plugin_set
, uint64_t index
)
143 BT_ASSERT_PRE_NON_NULL(plugin_set
, "Plugin set");
144 BT_ASSERT_PRE_VALID_INDEX(index
, plugin_set
->plugins
->len
);
145 return g_ptr_array_index(plugin_set
->plugins
, index
);
148 enum bt_plugin_find_all_from_static_status
bt_plugin_find_all_from_static(
149 bt_bool fail_on_load_error
,
150 const struct bt_plugin_set
**plugin_set_out
)
152 /* bt_plugin_so_create_all_from_static() logs errors */
153 return bt_plugin_so_create_all_from_static(fail_on_load_error
,
154 (void *) plugin_set_out
);
157 enum bt_plugin_find_all_from_file_status
bt_plugin_find_all_from_file(
158 const char *path
, bt_bool fail_on_load_error
,
159 const struct bt_plugin_set
**plugin_set_out
)
161 enum bt_plugin_find_all_from_file_status status
;
163 BT_ASSERT_PRE_NON_NULL(path
, "Path");
164 BT_ASSERT_PRE_NON_NULL(path
, "Plugin set (output)");
165 BT_LOGI("Creating plugins from file: path=\"%s\"", path
);
167 /* Try shared object plugins */
168 status
= bt_plugin_so_create_all_from_file(path
, fail_on_load_error
,
169 (void *) plugin_set_out
);
170 if (status
== BT_FUNC_STATUS_OK
) {
171 BT_ASSERT(*plugin_set_out
);
172 BT_ASSERT((*plugin_set_out
)->plugins
->len
> 0);
174 } else if (status
< 0) {
175 BT_ASSERT(!*plugin_set_out
);
179 BT_ASSERT(status
== BT_FUNC_STATUS_NOT_FOUND
);
180 BT_ASSERT(!*plugin_set_out
);
182 /* Try Python plugins if support is available */
183 init_python_plugin_provider();
184 if (bt_plugin_python_create_all_from_file_sym
) {
185 status
= bt_plugin_python_create_all_from_file_sym(path
,
186 fail_on_load_error
, (void *) plugin_set_out
);
187 if (status
== BT_FUNC_STATUS_OK
) {
188 BT_ASSERT(*plugin_set_out
);
189 BT_ASSERT((*plugin_set_out
)->plugins
->len
> 0);
191 } else if (status
< 0) {
192 BT_ASSERT(!*plugin_set_out
);
196 BT_ASSERT(status
== BT_FUNC_STATUS_NOT_FOUND
);
197 BT_ASSERT(!*plugin_set_out
);
201 if (status
== BT_FUNC_STATUS_OK
) {
202 BT_LOGI("Created %u plugins from file: "
203 "path=\"%s\", count=%u, plugin-set-addr=%p",
204 (*plugin_set_out
)->plugins
->len
, path
,
205 (*plugin_set_out
)->plugins
->len
,
207 } else if (status
== BT_FUNC_STATUS_NOT_FOUND
) {
208 BT_LOGI("Found no plugins in file: path=\"%s\"", path
);
214 static void destroy_gstring(void *data
)
216 g_string_free(data
, TRUE
);
219 enum bt_plugin_find_status
bt_plugin_find(const char *plugin_name
,
220 bt_bool fail_on_load_error
, const struct bt_plugin
**plugin_out
)
222 const char *system_plugin_dir
;
223 char *home_plugin_dir
= NULL
;
225 const struct bt_plugin
*plugin
= NULL
;
226 const struct bt_plugin_set
*plugin_set
= NULL
;
227 GPtrArray
*dirs
= NULL
;
229 int status
= BT_FUNC_STATUS_OK
;
232 BT_ASSERT_PRE_NON_NULL(plugin_name
, "Name");
233 BT_ASSERT_PRE_NON_NULL(plugin_out
, "Plugin (output)");
234 BT_LOGI("Finding named plugin in standard directories and built-in plugins: "
235 "name=\"%s\"", plugin_name
);
236 dirs
= g_ptr_array_new_with_free_func((GDestroyNotify
) destroy_gstring
);
238 BT_LOGE_STR("Failed to allocate a GPtrArray.");
239 status
= BT_FUNC_STATUS_MEMORY_ERROR
;
246 * 1. BABELTRACE_PLUGIN_PATH environment variable
247 * (colon-separated list of directories)
248 * 2. ~/.local/lib/babeltrace2/plugins
249 * 3. Default system directory for Babeltrace plugins, usually
250 * /usr/lib/babeltrace2/plugins or
251 * /usr/local/lib/babeltrace2/plugins if installed
253 * 4. Built-in plugins (static)
255 * Directories are searched non-recursively.
257 envvar
= getenv("BABELTRACE_PLUGIN_PATH");
259 ret
= bt_common_append_plugin_path_dirs(envvar
, dirs
);
261 BT_LOGE_STR("Failed to append plugin path to array of directories.");
262 status
= BT_FUNC_STATUS_MEMORY_ERROR
;
267 home_plugin_dir
= bt_common_get_home_plugin_path(BT_LOG_OUTPUT_LEVEL
);
268 if (home_plugin_dir
) {
269 GString
*home_plugin_dir_str
= g_string_new(home_plugin_dir
);
271 if (!home_plugin_dir_str
) {
272 BT_LOGE_STR("Failed to allocate a GString.");
273 status
= BT_FUNC_STATUS_MEMORY_ERROR
;
277 g_ptr_array_add(dirs
, home_plugin_dir_str
);
280 system_plugin_dir
= bt_common_get_system_plugin_path();
281 if (system_plugin_dir
) {
282 GString
*system_plugin_dir_str
=
283 g_string_new(system_plugin_dir
);
285 if (!system_plugin_dir_str
) {
286 BT_LOGE_STR("Failed to allocate a GString.");
287 status
= BT_FUNC_STATUS_MEMORY_ERROR
;
291 g_ptr_array_add(dirs
, system_plugin_dir_str
);
294 for (i
= 0; i
< dirs
->len
; i
++) {
295 GString
*dir
= g_ptr_array_index(dirs
, i
);
297 BT_OBJECT_PUT_REF_AND_RESET(plugin_set
);
300 * Skip this if the directory does not exist because
301 * bt_plugin_find_all_from_dir() would log a warning.
303 if (!g_file_test(dir
->str
, G_FILE_TEST_IS_DIR
)) {
304 BT_LOGI("Skipping nonexistent directory path: "
305 "path=\"%s\"", dir
->str
);
309 /* bt_plugin_find_all_from_dir() logs details/errors */
310 status
= bt_plugin_find_all_from_dir(dir
->str
, BT_FALSE
,
311 fail_on_load_error
, &plugin_set
);
313 BT_ASSERT(!plugin_set
);
315 } else if (status
== BT_FUNC_STATUS_NOT_FOUND
) {
316 BT_ASSERT(!plugin_set
);
317 BT_LOGI("No plugins found in directory: path=\"%s\"",
322 BT_ASSERT(status
== BT_FUNC_STATUS_OK
);
323 BT_ASSERT(plugin_set
);
325 for (j
= 0; j
< plugin_set
->plugins
->len
; j
++) {
326 const struct bt_plugin
*candidate_plugin
=
327 g_ptr_array_index(plugin_set
->plugins
, j
);
329 if (strcmp(bt_plugin_get_name(candidate_plugin
),
331 BT_LOGI("Plugin found in directory: name=\"%s\", path=\"%s\"",
332 plugin_name
, dir
->str
);
333 *plugin_out
= candidate_plugin
;
334 bt_object_get_no_null_check(*plugin_out
);
339 BT_LOGI("Plugin not found in directory: name=\"%s\", path=\"%s\"",
340 plugin_name
, dir
->str
);
343 BT_OBJECT_PUT_REF_AND_RESET(plugin_set
);
344 status
= bt_plugin_find_all_from_static(fail_on_load_error
,
347 BT_ASSERT(!plugin_set
);
349 } else if (status
== BT_FUNC_STATUS_NOT_FOUND
) {
350 BT_ASSERT(!plugin_set
);
351 BT_LOGI_STR("No plugins found in built-in plugins.");
355 BT_ASSERT(status
== BT_FUNC_STATUS_OK
);
356 BT_ASSERT(plugin_set
);
358 for (j
= 0; j
< plugin_set
->plugins
->len
; j
++) {
359 const struct bt_plugin
*candidate_plugin
=
360 g_ptr_array_index(plugin_set
->plugins
, j
);
362 if (strcmp(bt_plugin_get_name(candidate_plugin
),
364 BT_LOGI("Plugin found in built-in plugins: "
365 "name=\"%s\"", plugin_name
);
366 *plugin_out
= candidate_plugin
;
367 bt_object_get_no_null_check(*plugin_out
);
372 status
= BT_FUNC_STATUS_NOT_FOUND
;
375 free(home_plugin_dir
);
376 bt_object_put_ref(plugin_set
);
379 g_ptr_array_free(dirs
, TRUE
);
382 if (status
== BT_FUNC_STATUS_OK
) {
383 BT_LIB_LOGI("Found plugin in standard directories and built-in plugins: "
385 } else if (status
== BT_FUNC_STATUS_NOT_FOUND
) {
386 BT_LOGI("No plugin found in standard directories and built-in plugins: "
387 "name=\"%s\"", plugin_name
);
394 pthread_mutex_t lock
;
395 struct bt_plugin_set
*plugin_set
;
397 bool fail_on_load_error
;
399 } append_all_from_dir_info
= {
400 .lock
= PTHREAD_MUTEX_INITIALIZER
404 int nftw_append_all_from_dir(const char *file
,
405 const struct stat
*sb
, int flag
, struct FTW
*s
)
408 const char *name
= file
+ s
->base
;
410 /* Check for recursion */
411 if (!append_all_from_dir_info
.recurse
&& s
->level
> 1) {
418 const struct bt_plugin_set
*plugins_from_file
= NULL
;
420 if (name
[0] == '.') {
421 /* Skip hidden files */
422 BT_LOGI("Skipping hidden file: path=\"%s\"", file
);
426 append_all_from_dir_info
.status
=
427 bt_plugin_find_all_from_file(file
,
428 append_all_from_dir_info
.fail_on_load_error
,
430 if (append_all_from_dir_info
.status
== BT_FUNC_STATUS_OK
) {
433 BT_ASSERT(plugins_from_file
);
435 for (j
= 0; j
< plugins_from_file
->plugins
->len
; j
++) {
436 struct bt_plugin
*plugin
=
437 g_ptr_array_index(plugins_from_file
->plugins
, j
);
439 BT_LIB_LOGI("Adding plugin to plugin set: "
440 "plugin-path=\"%s\", %![plugin-]+l",
442 bt_plugin_set_add_plugin(
443 append_all_from_dir_info
.plugin_set
,
447 bt_object_put_ref(plugins_from_file
);
449 } else if (append_all_from_dir_info
.status
< 0) {
450 /* bt_plugin_find_all_from_file() logs errors */
451 BT_ASSERT(!plugins_from_file
);
457 * Not found in this file: this is no an error; continue
458 * walking the directories.
460 BT_ASSERT(!plugins_from_file
);
461 BT_ASSERT(append_all_from_dir_info
.status
==
462 BT_FUNC_STATUS_NOT_FOUND
);
466 /* Continue to next file / directory. */
467 BT_LOGI("Cannot enter directory: continuing: path=\"%s\"", file
);
470 /* Continue to next file / directory. */
471 BT_LOGI("Cannot get file information: continuing: path=\"%s\"", file
);
480 int bt_plugin_create_append_all_from_dir(struct bt_plugin_set
*plugin_set
,
481 const char *path
, bt_bool recurse
, bt_bool fail_on_load_error
)
483 int nftw_flags
= FTW_PHYS
;
488 BT_ASSERT(plugin_set
);
490 BT_ASSERT(strlen(path
) < PATH_MAX
);
493 * Make sure that path exists and is accessible.
494 * This is necessary since Cygwin implementation of nftw() is not POSIX
495 * compliant. Cygwin nftw() implementation does not fail on non-existent
496 * path with ENOENT. Instead, it flags the directory as FTW_NS. FTW_NS during
497 * nftw_append_all_from_dir is not treated as an error since we are
498 * traversing the tree for plugin discovery.
500 if (stat(path
, &sb
)) {
501 BT_LOGW_ERRNO("Cannot open directory",
502 ": path=\"%s\", recurse=%d",
504 status
= BT_FUNC_STATUS_ERROR
;
508 pthread_mutex_lock(&append_all_from_dir_info
.lock
);
509 append_all_from_dir_info
.plugin_set
= plugin_set
;
510 append_all_from_dir_info
.recurse
= recurse
;
511 append_all_from_dir_info
.status
= BT_FUNC_STATUS_OK
;
512 append_all_from_dir_info
.fail_on_load_error
= fail_on_load_error
;
513 ret
= nftw(path
, nftw_append_all_from_dir
,
514 APPEND_ALL_FROM_DIR_NFDOPEN_MAX
, nftw_flags
);
515 append_all_from_dir_info
.plugin_set
= NULL
;
516 status
= append_all_from_dir_info
.status
;
517 pthread_mutex_unlock(&append_all_from_dir_info
.lock
);
519 BT_LOGW_ERRNO("Failed to walk directory",
520 ": path=\"%s\", recurse=%d",
522 status
= BT_FUNC_STATUS_ERROR
;
526 if (status
== BT_FUNC_STATUS_NOT_FOUND
) {
528 * We're just appending in this function; even if
529 * nothing was found, it's still okay from the caller's
532 status
= BT_FUNC_STATUS_OK
;
539 enum bt_plugin_find_all_from_dir_status
bt_plugin_find_all_from_dir(
540 const char *path
, bt_bool recurse
, bt_bool fail_on_load_error
,
541 const struct bt_plugin_set
**plugin_set_out
)
543 enum bt_plugin_find_all_from_dir_status status
=
546 BT_ASSERT_PRE_NON_NULL(plugin_set_out
, "Plugin set (output)");
547 BT_LOGI("Creating all plugins in directory: path=\"%s\", recurse=%d",
549 *plugin_set_out
= bt_plugin_set_create();
550 if (!*plugin_set_out
) {
551 BT_LOGE_STR("Cannot create empty plugin set.");
552 status
= BT_FUNC_STATUS_MEMORY_ERROR
;
557 * Append found plugins to array (never returns
558 * `BT_FUNC_STATUS_NOT_FOUND`)
560 status
= bt_plugin_create_append_all_from_dir((void *) *plugin_set_out
,
561 path
, recurse
, fail_on_load_error
);
564 * bt_plugin_create_append_all_from_dir() handles
565 * `fail_on_load_error`, so this is a "real" error.
567 BT_LOGW("Cannot append plugins found in directory: "
568 "path=\"%s\", status=%s",
569 path
, bt_common_func_status_string(status
));
573 BT_ASSERT(status
== BT_FUNC_STATUS_OK
);
575 if ((*plugin_set_out
)->plugins
->len
== 0) {
576 /* Nothing was appended: not found */
577 BT_LOGI("No plugins found in directory: path=\"%s\"", path
);
578 status
= BT_FUNC_STATUS_NOT_FOUND
;
582 BT_LOGI("Created %u plugins from directory: count=%u, path=\"%s\"",
583 (*plugin_set_out
)->plugins
->len
,
584 (*plugin_set_out
)->plugins
->len
, path
);
588 BT_ASSERT(status
!= BT_FUNC_STATUS_OK
);
589 BT_OBJECT_PUT_REF_AND_RESET(*plugin_set_out
);
595 const char *bt_plugin_get_name(const struct bt_plugin
*plugin
)
597 BT_ASSERT_PRE_NON_NULL(plugin
, "Plugin");
598 return plugin
->info
.name_set
? plugin
->info
.name
->str
: NULL
;
601 const char *bt_plugin_get_author(const struct bt_plugin
*plugin
)
603 BT_ASSERT_PRE_NON_NULL(plugin
, "Plugin");
604 return plugin
->info
.author_set
? plugin
->info
.author
->str
: NULL
;
607 const char *bt_plugin_get_license(const struct bt_plugin
*plugin
)
609 BT_ASSERT_PRE_NON_NULL(plugin
, "Plugin");
610 return plugin
->info
.license_set
? plugin
->info
.license
->str
: NULL
;
613 const char *bt_plugin_get_path(const struct bt_plugin
*plugin
)
615 BT_ASSERT_PRE_NON_NULL(plugin
, "Plugin");
616 return plugin
->info
.path_set
? plugin
->info
.path
->str
: NULL
;
619 const char *bt_plugin_get_description(const struct bt_plugin
*plugin
)
621 BT_ASSERT_PRE_NON_NULL(plugin
, "Plugin");
622 return plugin
->info
.description_set
?
623 plugin
->info
.description
->str
: NULL
;
626 enum bt_property_availability
bt_plugin_get_version(const struct bt_plugin
*plugin
,
627 unsigned int *major
, unsigned int *minor
, unsigned int *patch
,
630 enum bt_property_availability avail
=
631 BT_PROPERTY_AVAILABILITY_AVAILABLE
;
633 BT_ASSERT_PRE_NON_NULL(plugin
, "Plugin");
635 if (!plugin
->info
.version_set
) {
636 BT_LIB_LOGD("Plugin's version is not set: %!+l", plugin
);
637 avail
= BT_PROPERTY_AVAILABILITY_NOT_AVAILABLE
;
642 *major
= plugin
->info
.version
.major
;
646 *minor
= plugin
->info
.version
.minor
;
650 *patch
= plugin
->info
.version
.patch
;
654 *extra
= plugin
->info
.version
.extra
->str
;
661 uint64_t bt_plugin_get_source_component_class_count(const struct bt_plugin
*plugin
)
663 BT_ASSERT_PRE_NON_NULL(plugin
, "Plugin");
664 return (uint64_t) plugin
->src_comp_classes
->len
;
667 uint64_t bt_plugin_get_filter_component_class_count(const struct bt_plugin
*plugin
)
669 BT_ASSERT_PRE_NON_NULL(plugin
, "Plugin");
670 return (uint64_t) plugin
->flt_comp_classes
->len
;
673 uint64_t bt_plugin_get_sink_component_class_count(const struct bt_plugin
*plugin
)
675 BT_ASSERT_PRE_NON_NULL(plugin
, "Plugin");
676 return (uint64_t) plugin
->sink_comp_classes
->len
;
680 struct bt_component_class
*borrow_component_class_by_index(
681 const struct bt_plugin
*plugin
, GPtrArray
*comp_classes
,
684 BT_ASSERT_PRE_NON_NULL(plugin
, "Plugin");
685 BT_ASSERT_PRE_VALID_INDEX(index
, comp_classes
->len
);
686 return g_ptr_array_index(comp_classes
, index
);
689 const struct bt_component_class_source
*
690 bt_plugin_borrow_source_component_class_by_index_const(
691 const struct bt_plugin
*plugin
, uint64_t index
)
693 return (const void *) borrow_component_class_by_index(plugin
,
694 plugin
->src_comp_classes
, index
);
697 const struct bt_component_class_filter
*
698 bt_plugin_borrow_filter_component_class_by_index_const(
699 const struct bt_plugin
*plugin
, uint64_t index
)
701 return (const void *) borrow_component_class_by_index(plugin
,
702 plugin
->flt_comp_classes
, index
);
705 const struct bt_component_class_sink
*
706 bt_plugin_borrow_sink_component_class_by_index_const(
707 const struct bt_plugin
*plugin
, uint64_t index
)
709 return (const void *) borrow_component_class_by_index(plugin
,
710 plugin
->sink_comp_classes
, index
);
714 struct bt_component_class
*borrow_component_class_by_name(
715 const struct bt_plugin
*plugin
, GPtrArray
*comp_classes
,
718 struct bt_component_class
*comp_class
= NULL
;
721 BT_ASSERT_PRE_NON_NULL(plugin
, "Plugin");
722 BT_ASSERT_PRE_NON_NULL(name
, "Name");
724 for (i
= 0; i
< comp_classes
->len
; i
++) {
725 struct bt_component_class
*comp_class_candidate
=
726 g_ptr_array_index(comp_classes
, i
);
727 const char *comp_class_cand_name
=
728 bt_component_class_get_name(comp_class_candidate
);
730 BT_ASSERT(comp_class_cand_name
);
732 if (strcmp(name
, comp_class_cand_name
) == 0) {
733 comp_class
= comp_class_candidate
;
741 const struct bt_component_class_source
*
742 bt_plugin_borrow_source_component_class_by_name_const(
743 const struct bt_plugin
*plugin
, const char *name
)
745 return (const void *) borrow_component_class_by_name(plugin
,
746 plugin
->src_comp_classes
, name
);
749 const struct bt_component_class_filter
*
750 bt_plugin_borrow_filter_component_class_by_name_const(
751 const struct bt_plugin
*plugin
, const char *name
)
753 return (const void *) borrow_component_class_by_name(plugin
,
754 plugin
->flt_comp_classes
, name
);
757 const struct bt_component_class_sink
*
758 bt_plugin_borrow_sink_component_class_by_name_const(
759 const struct bt_plugin
*plugin
, const char *name
)
761 return (const void *) borrow_component_class_by_name(plugin
,
762 plugin
->sink_comp_classes
, name
);
765 void bt_plugin_get_ref(const struct bt_plugin
*plugin
)
767 bt_object_get_ref(plugin
);
770 void bt_plugin_put_ref(const struct bt_plugin
*plugin
)
772 bt_object_put_ref(plugin
);
775 void bt_plugin_set_get_ref(const struct bt_plugin_set
*plugin_set
)
777 bt_object_get_ref(plugin_set
);
780 void bt_plugin_set_put_ref(const struct bt_plugin_set
*plugin_set
)
782 bt_object_put_ref(plugin_set
);