Commit | Line | Data |
---|---|---|
33b34c43 | 1 | /* |
0235b0db MJ |
2 | * SPDX-License-Identifier: MIT |
3 | * | |
e2f7325d | 4 | * Copyright 2017-2018 Philippe Proulx <pproulx@efficios.com> |
33b34c43 | 5 | * Copyright 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com> |
33b34c43 PP |
6 | */ |
7 | ||
350ad6c1 | 8 | #define BT_LOG_TAG "LIB/PLUGIN" |
c2d9d9cf | 9 | #include "lib/logging.h" |
8c1a3187 | 10 | |
578e048b | 11 | #include "common/assert.h" |
d98421f2 | 12 | #include "lib/assert-cond.h" |
91d81473 | 13 | #include "common/macros.h" |
578e048b | 14 | #include "compat/compiler.h" |
7cbfb97d | 15 | #include "compat/limits.h" |
578e048b | 16 | #include "common/common.h" |
43c59509 PP |
17 | #include <babeltrace2/plugin/plugin-loading.h> |
18 | #include <babeltrace2/graph/component-class.h> | |
19 | #include <babeltrace2/error-reporting.h> | |
578e048b | 20 | #include "lib/graph/component-class.h" |
3fadfbc0 | 21 | #include <babeltrace2/types.h> |
33b34c43 | 22 | #include <glib.h> |
33b34c43 | 23 | #include <unistd.h> |
c4f23e30 | 24 | #include <stdbool.h> |
33b34c43 | 25 | #include <stdlib.h> |
9ac68eb1 | 26 | #include <stdint.h> |
33b34c43 | 27 | #include <sys/stat.h> |
e1f4c4f7 MJ |
28 | #include <ftw.h> |
29 | #include <pthread.h> | |
33b34c43 | 30 | |
578e048b MJ |
31 | #include "plugin.h" |
32 | #include "plugin-so.h" | |
d24d5663 | 33 | #include "lib/func-status.h" |
578e048b | 34 | |
b14c7bf1 MJ |
35 | #define PYTHON_PLUGIN_PROVIDER_FILENAME "babeltrace2-python-plugin-provider." G_MODULE_SUFFIX |
36 | #define PYTHON_PLUGIN_PROVIDER_DIR BABELTRACE_PLUGIN_PROVIDERS_DIR | |
6fbd4105 | 37 | #define PYTHON_PLUGIN_PROVIDER_SYM_NAME bt_plugin_python_create_all_from_file |
91d81473 | 38 | #define PYTHON_PLUGIN_PROVIDER_SYM_NAME_STR G_STRINGIFY(PYTHON_PLUGIN_PROVIDER_SYM_NAME) |
33b34c43 | 39 | |
e1f4c4f7 MJ |
40 | #define APPEND_ALL_FROM_DIR_NFDOPEN_MAX 8 |
41 | ||
7c7301d5 SM |
42 | /* Declare here to make sure definition in both ifdef branches are in sync. */ |
43 | static | |
44 | int init_python_plugin_provider(void); | |
45 | typedef int (*create_all_from_file_sym_type)( | |
46 | const char *path, | |
47 | bool fail_on_load_error, | |
48 | struct bt_plugin_set **plugin_set_out); | |
49 | ||
6fbd4105 | 50 | #ifdef BT_BUILT_IN_PYTHON_PLUGIN_SUPPORT |
578e048b | 51 | #include <plugin/python-plugin-provider.h> |
e1f4c4f7 | 52 | |
33b34c43 | 53 | static |
7c7301d5 SM |
54 | create_all_from_file_sym_type |
55 | bt_plugin_python_create_all_from_file_sym = | |
56 | bt_plugin_python_create_all_from_file; | |
95ef44ce MJ |
57 | |
58 | static | |
7c7301d5 | 59 | int init_python_plugin_provider(void) |
9736d991 PP |
60 | { |
61 | } | |
6fbd4105 PP |
62 | #else /* BT_BUILT_IN_PYTHON_PLUGIN_SUPPORT */ |
63 | static GModule *python_plugin_provider_module; | |
9736d991 | 64 | |
6fbd4105 | 65 | static |
7c7301d5 | 66 | create_all_from_file_sym_type bt_plugin_python_create_all_from_file_sym; |
33b34c43 | 67 | |
95ef44ce | 68 | static |
870631a2 PP |
69 | int init_python_plugin_provider(void) { |
70 | int status = BT_FUNC_STATUS_OK; | |
b14c7bf1 MJ |
71 | const char *provider_dir_envvar; |
72 | static const char * const provider_dir_envvar_name = "LIBBABELTRACE2_PLUGIN_PROVIDER_DIR"; | |
73 | char *provider_path = NULL; | |
870631a2 | 74 | |
5084732e | 75 | if (bt_plugin_python_create_all_from_file_sym) { |
870631a2 | 76 | goto end; |
95ef44ce MJ |
77 | } |
78 | ||
3f7d4d90 | 79 | BT_LOGI_STR("Loading Python plugin provider module."); |
b14c7bf1 MJ |
80 | |
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, | |
87 | provider_path); | |
88 | } else { | |
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); | |
94 | } | |
95 | ||
96 | python_plugin_provider_module = g_module_open(provider_path, 0); | |
6fbd4105 | 97 | if (!python_plugin_provider_module) { |
9736d991 PP |
98 | /* |
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. | |
102 | */ | |
a77aed14 | 103 | BT_LOGI("Cannot open `%s`: %s: continuing without Python plugin support.", |
b14c7bf1 | 104 | provider_path, g_module_error()); |
870631a2 | 105 | goto end; |
33b34c43 PP |
106 | } |
107 | ||
6fbd4105 PP |
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)) { | |
9736d991 PP |
111 | /* |
112 | * This is an error because, since we found the Python | |
113 | * plugin provider shared object, we expect this symbol | |
114 | * to exist. | |
115 | */ | |
870631a2 PP |
116 | BT_LIB_LOGE_APPEND_CAUSE( |
117 | "Cannot find the Python plugin provider loading symbol: " | |
9736d991 | 118 | "%s: continuing without Python plugin support: " |
8c1a3187 | 119 | "file=\"%s\", symbol=\"%s\"", |
9736d991 | 120 | g_module_error(), |
b14c7bf1 | 121 | provider_path, |
8c1a3187 | 122 | PYTHON_PLUGIN_PROVIDER_SYM_NAME_STR); |
870631a2 PP |
123 | status = BT_FUNC_STATUS_ERROR; |
124 | goto end; | |
33b34c43 | 125 | } |
8c1a3187 | 126 | |
9e0bf9b0 | 127 | BT_LOGI("Loaded Python plugin provider module: addr=%p", |
8c1a3187 | 128 | python_plugin_provider_module); |
870631a2 PP |
129 | |
130 | end: | |
b14c7bf1 MJ |
131 | g_free(provider_path); |
132 | ||
870631a2 | 133 | return status; |
33b34c43 PP |
134 | } |
135 | ||
6fbd4105 PP |
136 | __attribute__((destructor)) static |
137 | void fini_python_plugin_provider(void) { | |
138 | if (python_plugin_provider_module) { | |
3f7d4d90 | 139 | BT_LOGI("Unloading Python plugin provider module."); |
8c1a3187 PP |
140 | |
141 | if (!g_module_close(python_plugin_provider_module)) { | |
870631a2 PP |
142 | /* |
143 | * This occurs when the library is finalized: do | |
144 | * NOT append an error cause. | |
145 | */ | |
8c1a3187 PP |
146 | BT_LOGE("Failed to close the Python plugin provider module: %s.", |
147 | g_module_error()); | |
148 | } | |
149 | ||
6fbd4105 | 150 | python_plugin_provider_module = NULL; |
6ba0b073 | 151 | } |
6ba0b073 | 152 | } |
6fbd4105 | 153 | #endif |
6ba0b073 | 154 | |
1353b066 | 155 | BT_EXPORT |
e58aeae2 | 156 | uint64_t bt_plugin_set_get_plugin_count(const struct bt_plugin_set *plugin_set) |
a8ff38ef | 157 | { |
d5b13b9b | 158 | BT_ASSERT_PRE_DEV_PLUGIN_SET_NON_NULL(plugin_set); |
d94d92ac | 159 | return (uint64_t) plugin_set->plugins->len; |
a8ff38ef PP |
160 | } |
161 | ||
1353b066 | 162 | BT_EXPORT |
92fed4e1 PP |
163 | const struct bt_plugin *bt_plugin_set_borrow_plugin_by_index_const( |
164 | const struct bt_plugin_set *plugin_set, uint64_t index) | |
a8ff38ef | 165 | { |
d5b13b9b | 166 | BT_ASSERT_PRE_DEV_PLUGIN_SET_NON_NULL(plugin_set); |
bdb288b3 | 167 | BT_ASSERT_PRE_DEV_VALID_INDEX(index, plugin_set->plugins->len); |
d94d92ac | 168 | return g_ptr_array_index(plugin_set->plugins, index); |
a8ff38ef PP |
169 | } |
170 | ||
1353b066 | 171 | BT_EXPORT |
d24d5663 | 172 | enum bt_plugin_find_all_from_static_status bt_plugin_find_all_from_static( |
9736d991 PP |
173 | bt_bool fail_on_load_error, |
174 | const struct bt_plugin_set **plugin_set_out) | |
6ba0b073 | 175 | { |
17f3083a SM |
176 | BT_ASSERT_PRE_NO_ERROR(); |
177 | ||
8c1a3187 | 178 | /* bt_plugin_so_create_all_from_static() logs errors */ |
9736d991 PP |
179 | return bt_plugin_so_create_all_from_static(fail_on_load_error, |
180 | (void *) plugin_set_out); | |
6ba0b073 PP |
181 | } |
182 | ||
1353b066 | 183 | BT_EXPORT |
d24d5663 PP |
184 | enum bt_plugin_find_all_from_file_status bt_plugin_find_all_from_file( |
185 | const char *path, bt_bool fail_on_load_error, | |
9736d991 | 186 | const struct bt_plugin_set **plugin_set_out) |
33b34c43 | 187 | { |
d24d5663 | 188 | enum bt_plugin_find_all_from_file_status status; |
33b34c43 | 189 | |
17f3083a | 190 | BT_ASSERT_PRE_NO_ERROR(); |
1778c2a4 | 191 | BT_ASSERT_PRE_NON_NULL("path", path, "Path"); |
1d99c8c2 | 192 | BT_ASSERT_PRE_PLUGIN_SET_OUT_NON_NULL(plugin_set_out); |
3f7d4d90 | 193 | BT_LOGI("Creating plugins from file: path=\"%s\"", path); |
6ba0b073 | 194 | |
55bb57e0 | 195 | /* Try shared object plugins */ |
9736d991 PP |
196 | status = bt_plugin_so_create_all_from_file(path, fail_on_load_error, |
197 | (void *) plugin_set_out); | |
d24d5663 | 198 | if (status == BT_FUNC_STATUS_OK) { |
9736d991 PP |
199 | BT_ASSERT(*plugin_set_out); |
200 | BT_ASSERT((*plugin_set_out)->plugins->len > 0); | |
201 | goto end; | |
202 | } else if (status < 0) { | |
203 | BT_ASSERT(!*plugin_set_out); | |
6ba0b073 PP |
204 | goto end; |
205 | } | |
206 | ||
d24d5663 | 207 | BT_ASSERT(status == BT_FUNC_STATUS_NOT_FOUND); |
9736d991 PP |
208 | BT_ASSERT(!*plugin_set_out); |
209 | ||
6fbd4105 | 210 | /* Try Python plugins if support is available */ |
870631a2 PP |
211 | status = init_python_plugin_provider(); |
212 | if (status < 0) { | |
213 | /* init_python_plugin_provider() logs errors */ | |
214 | goto end; | |
215 | } | |
216 | ||
217 | BT_ASSERT(status == BT_FUNC_STATUS_OK); | |
218 | status = BT_FUNC_STATUS_NOT_FOUND; | |
219 | ||
6fbd4105 | 220 | if (bt_plugin_python_create_all_from_file_sym) { |
870631a2 | 221 | /* Python plugin provider exists */ |
9736d991 PP |
222 | status = bt_plugin_python_create_all_from_file_sym(path, |
223 | fail_on_load_error, (void *) plugin_set_out); | |
d24d5663 | 224 | if (status == BT_FUNC_STATUS_OK) { |
9736d991 PP |
225 | BT_ASSERT(*plugin_set_out); |
226 | BT_ASSERT((*plugin_set_out)->plugins->len > 0); | |
227 | goto end; | |
228 | } else if (status < 0) { | |
870631a2 PP |
229 | /* |
230 | * bt_plugin_python_create_all_from_file_sym() | |
231 | * handles `fail_on_load_error` itself, so this | |
232 | * is a "real" error. | |
233 | */ | |
9736d991 | 234 | BT_ASSERT(!*plugin_set_out); |
6fbd4105 PP |
235 | goto end; |
236 | } | |
9736d991 | 237 | |
d24d5663 | 238 | BT_ASSERT(status == BT_FUNC_STATUS_NOT_FOUND); |
9736d991 | 239 | BT_ASSERT(!*plugin_set_out); |
6ba0b073 PP |
240 | } |
241 | ||
33b34c43 | 242 | end: |
d24d5663 | 243 | if (status == BT_FUNC_STATUS_OK) { |
3f7d4d90 | 244 | BT_LOGI("Created %u plugins from file: " |
8c1a3187 | 245 | "path=\"%s\", count=%u, plugin-set-addr=%p", |
9736d991 PP |
246 | (*plugin_set_out)->plugins->len, path, |
247 | (*plugin_set_out)->plugins->len, | |
248 | *plugin_set_out); | |
d24d5663 | 249 | } else if (status == BT_FUNC_STATUS_NOT_FOUND) { |
3f7d4d90 | 250 | BT_LOGI("Found no plugins in file: path=\"%s\"", path); |
8c1a3187 PP |
251 | } |
252 | ||
9736d991 | 253 | return status; |
33b34c43 PP |
254 | } |
255 | ||
577fa92f PP |
256 | static |
257 | void destroy_gstring(void *data) | |
1670bffd PP |
258 | { |
259 | g_string_free(data, TRUE); | |
260 | } | |
261 | ||
1353b066 | 262 | BT_EXPORT |
577fa92f PP |
263 | enum bt_plugin_find_all_status bt_plugin_find_all(bt_bool find_in_std_env_var, |
264 | bt_bool find_in_user_dir, bt_bool find_in_sys_dir, | |
265 | bt_bool find_in_static, bt_bool fail_on_load_error, | |
266 | const struct bt_plugin_set **plugin_set_out) | |
1670bffd | 267 | { |
1670bffd | 268 | char *home_plugin_dir = NULL; |
92fed4e1 | 269 | const struct bt_plugin_set *plugin_set = NULL; |
1670bffd PP |
270 | GPtrArray *dirs = NULL; |
271 | int ret; | |
d24d5663 | 272 | int status = BT_FUNC_STATUS_OK; |
577fa92f PP |
273 | uint64_t dir_i, plugin_i; |
274 | ||
17f3083a | 275 | BT_ASSERT_PRE_NO_ERROR(); |
d5b13b9b | 276 | BT_ASSERT_PRE_PLUGIN_SET_OUT_NON_NULL(plugin_set_out); |
577fa92f PP |
277 | BT_LOGI("Finding all plugins in standard directories and built-in plugins: " |
278 | "find-in-std-env-var=%d, find-in-user-dir=%d, " | |
279 | "find-in-sys-dir=%d, find-in-static=%d", | |
280 | find_in_std_env_var, find_in_user_dir, find_in_sys_dir, | |
281 | find_in_static); | |
1670bffd PP |
282 | dirs = g_ptr_array_new_with_free_func((GDestroyNotify) destroy_gstring); |
283 | if (!dirs) { | |
870631a2 | 284 | BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GPtrArray."); |
d24d5663 | 285 | status = BT_FUNC_STATUS_MEMORY_ERROR; |
1670bffd PP |
286 | goto end; |
287 | } | |
288 | ||
577fa92f PP |
289 | *plugin_set_out = bt_plugin_set_create(); |
290 | if (!*plugin_set_out) { | |
291 | BT_LIB_LOGE_APPEND_CAUSE("Cannot create empty plugin set."); | |
292 | status = BT_FUNC_STATUS_MEMORY_ERROR; | |
293 | goto end; | |
294 | } | |
295 | ||
1670bffd PP |
296 | /* |
297 | * Search order is: | |
298 | * | |
577fa92f | 299 | * 1. `BABELTRACE_PLUGIN_PATH` environment variable |
1670bffd | 300 | * (colon-separated list of directories) |
577fa92f | 301 | * 2. `~/.local/lib/babeltrace2/plugins` |
1670bffd | 302 | * 3. Default system directory for Babeltrace plugins, usually |
577fa92f PP |
303 | * `/usr/lib/babeltrace2/plugins` or |
304 | * `/usr/local/lib/babeltrace2/plugins` if installed locally | |
1670bffd PP |
305 | * 4. Built-in plugins (static) |
306 | * | |
307 | * Directories are searched non-recursively. | |
308 | */ | |
577fa92f PP |
309 | if (find_in_std_env_var) { |
310 | const char *envvar = getenv("BABELTRACE_PLUGIN_PATH"); | |
311 | ||
312 | if (envvar) { | |
313 | ret = bt_common_append_plugin_path_dirs(envvar, dirs); | |
314 | if (ret) { | |
315 | BT_LIB_LOGE_APPEND_CAUSE( | |
316 | "Failed to append plugin path to array of directories."); | |
317 | status = BT_FUNC_STATUS_MEMORY_ERROR; | |
318 | goto end; | |
319 | } | |
1670bffd PP |
320 | } |
321 | } | |
322 | ||
577fa92f PP |
323 | if (find_in_user_dir) { |
324 | home_plugin_dir = bt_common_get_home_plugin_path( | |
325 | BT_LOG_OUTPUT_LEVEL); | |
326 | if (home_plugin_dir) { | |
327 | GString *home_plugin_dir_str = g_string_new( | |
328 | home_plugin_dir); | |
1670bffd | 329 | |
577fa92f PP |
330 | if (!home_plugin_dir_str) { |
331 | BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GString."); | |
332 | status = BT_FUNC_STATUS_MEMORY_ERROR; | |
333 | goto end; | |
334 | } | |
1670bffd | 335 | |
577fa92f PP |
336 | g_ptr_array_add(dirs, home_plugin_dir_str); |
337 | } | |
1670bffd PP |
338 | } |
339 | ||
577fa92f PP |
340 | if (find_in_sys_dir) { |
341 | const char *system_plugin_dir = | |
342 | bt_common_get_system_plugin_path(); | |
1670bffd | 343 | |
577fa92f PP |
344 | if (system_plugin_dir) { |
345 | GString *system_plugin_dir_str = | |
346 | g_string_new(system_plugin_dir); | |
347 | ||
348 | if (!system_plugin_dir_str) { | |
349 | BT_LIB_LOGE_APPEND_CAUSE("Failed to allocate a GString."); | |
350 | status = BT_FUNC_STATUS_MEMORY_ERROR; | |
351 | goto end; | |
352 | } | |
1670bffd | 353 | |
577fa92f PP |
354 | g_ptr_array_add(dirs, system_plugin_dir_str); |
355 | } | |
1670bffd PP |
356 | } |
357 | ||
577fa92f PP |
358 | for (dir_i = 0; dir_i < dirs->len; dir_i++) { |
359 | GString *dir = dirs->pdata[dir_i]; | |
1670bffd | 360 | |
65300d60 | 361 | BT_OBJECT_PUT_REF_AND_RESET(plugin_set); |
8c1a3187 | 362 | |
50ad9320 PP |
363 | /* |
364 | * Skip this if the directory does not exist because | |
c8db3219 | 365 | * bt_plugin_find_all_from_dir() would log a warning. |
50ad9320 PP |
366 | */ |
367 | if (!g_file_test(dir->str, G_FILE_TEST_IS_DIR)) { | |
3f7d4d90 | 368 | BT_LOGI("Skipping nonexistent directory path: " |
50ad9320 PP |
369 | "path=\"%s\"", dir->str); |
370 | continue; | |
371 | } | |
372 | ||
c8db3219 | 373 | /* bt_plugin_find_all_from_dir() logs details/errors */ |
9736d991 PP |
374 | status = bt_plugin_find_all_from_dir(dir->str, BT_FALSE, |
375 | fail_on_load_error, &plugin_set); | |
376 | if (status < 0) { | |
377 | BT_ASSERT(!plugin_set); | |
378 | goto end; | |
d24d5663 | 379 | } else if (status == BT_FUNC_STATUS_NOT_FOUND) { |
9736d991 | 380 | BT_ASSERT(!plugin_set); |
3f7d4d90 | 381 | BT_LOGI("No plugins found in directory: path=\"%s\"", |
8c1a3187 | 382 | dir->str); |
1670bffd PP |
383 | continue; |
384 | } | |
385 | ||
d24d5663 | 386 | BT_ASSERT(status == BT_FUNC_STATUS_OK); |
9736d991 | 387 | BT_ASSERT(plugin_set); |
577fa92f PP |
388 | BT_LOGI("Found plugins in directory: path=\"%s\", count=%u", |
389 | dir->str, plugin_set->plugins->len); | |
9736d991 | 390 | |
577fa92f PP |
391 | for (plugin_i = 0; plugin_i < plugin_set->plugins->len; |
392 | plugin_i++) { | |
393 | bt_plugin_set_add_plugin((void *) *plugin_set_out, | |
394 | plugin_set->plugins->pdata[plugin_i]); | |
395 | } | |
396 | } | |
1670bffd | 397 | |
577fa92f PP |
398 | if (find_in_static) { |
399 | BT_OBJECT_PUT_REF_AND_RESET(plugin_set); | |
400 | status = bt_plugin_find_all_from_static(fail_on_load_error, | |
401 | &plugin_set); | |
402 | if (status < 0) { | |
403 | BT_ASSERT(!plugin_set); | |
404 | goto end; | |
405 | } else if (status == BT_FUNC_STATUS_NOT_FOUND) { | |
406 | BT_ASSERT(!plugin_set); | |
407 | BT_LOGI_STR("No plugins found in built-in plugins."); | |
408 | goto end; | |
1670bffd | 409 | } |
8c1a3187 | 410 | |
577fa92f PP |
411 | BT_ASSERT(status == BT_FUNC_STATUS_OK); |
412 | BT_ASSERT(plugin_set); | |
413 | BT_LOGI("Found built-in plugins: count=%u", | |
414 | plugin_set->plugins->len); | |
415 | ||
416 | for (plugin_i = 0; plugin_i < plugin_set->plugins->len; | |
417 | plugin_i++) { | |
418 | bt_plugin_set_add_plugin((void *) *plugin_set_out, | |
419 | plugin_set->plugins->pdata[plugin_i]); | |
420 | } | |
421 | } | |
422 | ||
423 | end: | |
424 | free(home_plugin_dir); | |
425 | bt_object_put_ref(plugin_set); | |
426 | ||
427 | if (dirs) { | |
428 | g_ptr_array_free(dirs, TRUE); | |
1670bffd PP |
429 | } |
430 | ||
9736d991 | 431 | if (status < 0) { |
577fa92f PP |
432 | BT_OBJECT_PUT_REF_AND_RESET(*plugin_set_out); |
433 | } else { | |
434 | BT_ASSERT(*plugin_set_out); | |
435 | ||
436 | if ((*plugin_set_out)->plugins->len > 0) { | |
437 | BT_LOGI("Found plugins in standard directories and built-in plugins: " | |
438 | "count=%u", (*plugin_set_out)->plugins->len); | |
439 | status = BT_FUNC_STATUS_OK; | |
440 | } else { | |
441 | BT_LOGI_STR("No plugins found in standard directories and built-in plugins."); | |
442 | status = BT_FUNC_STATUS_NOT_FOUND; | |
443 | BT_OBJECT_PUT_REF_AND_RESET(*plugin_set_out); | |
444 | } | |
445 | } | |
446 | ||
447 | return status; | |
448 | } | |
449 | ||
1353b066 | 450 | BT_EXPORT |
577fa92f PP |
451 | enum bt_plugin_find_status bt_plugin_find(const char *plugin_name, |
452 | bt_bool find_in_std_env_var, bt_bool find_in_user_dir, | |
453 | bt_bool find_in_sys_dir, bt_bool find_in_static, | |
454 | bt_bool fail_on_load_error, const struct bt_plugin **plugin_out) | |
455 | { | |
456 | enum bt_plugin_find_status status; | |
457 | const struct bt_plugin_set *plugin_set = NULL; | |
458 | uint64_t i; | |
459 | ||
17f3083a | 460 | BT_ASSERT_PRE_NO_ERROR(); |
d5b13b9b PP |
461 | BT_ASSERT_PRE_NAME_NON_NULL(plugin_name); |
462 | BT_ASSERT_PRE_PLUGIN_OUT_NON_NULL(plugin_out); | |
577fa92f PP |
463 | BT_LOGI("Finding named plugin in standard directories and built-in plugins: " |
464 | "name=\"%s\", find-in-std-env-var=%d, find-in-user-dir=%d, " | |
465 | "find-in-sys-dir=%d, find-in-static=%d", | |
466 | plugin_name, find_in_std_env_var, find_in_user_dir, | |
467 | find_in_sys_dir, find_in_static); | |
7aa2e7df | 468 | status = (enum bt_plugin_find_status) bt_plugin_find_all(find_in_std_env_var, find_in_user_dir, |
577fa92f PP |
469 | find_in_sys_dir, find_in_static, fail_on_load_error, |
470 | &plugin_set); | |
471 | if (status != BT_FUNC_STATUS_OK) { | |
f600f713 | 472 | BT_ASSERT(!plugin_set); |
9736d991 PP |
473 | goto end; |
474 | } | |
475 | ||
9736d991 PP |
476 | BT_ASSERT(plugin_set); |
477 | ||
577fa92f PP |
478 | for (i = 0; i < plugin_set->plugins->len; i++) { |
479 | const struct bt_plugin *plugin = plugin_set->plugins->pdata[i]; | |
9736d991 | 480 | |
577fa92f PP |
481 | if (strcmp(plugin->info.name->str, plugin_name) == 0) { |
482 | *plugin_out = plugin; | |
6871026b | 483 | bt_object_get_ref_no_null_check(*plugin_out); |
9736d991 | 484 | goto end; |
1670bffd | 485 | } |
1670bffd PP |
486 | } |
487 | ||
d24d5663 | 488 | status = BT_FUNC_STATUS_NOT_FOUND; |
9736d991 | 489 | |
1670bffd | 490 | end: |
d24d5663 | 491 | if (status == BT_FUNC_STATUS_OK) { |
577fa92f | 492 | BT_ASSERT(*plugin_out); |
3f7d4d90 | 493 | BT_LIB_LOGI("Found plugin in standard directories and built-in plugins: " |
577fa92f PP |
494 | "%!+l", *plugin_out); |
495 | } else if (status == BT_FUNC_STATUS_NOT_FOUND) { | |
3f7d4d90 | 496 | BT_LOGI("No plugin found in standard directories and built-in plugins: " |
8c1a3187 PP |
497 | "name=\"%s\"", plugin_name); |
498 | } | |
499 | ||
f600f713 FD |
500 | bt_plugin_set_put_ref(plugin_set); |
501 | ||
9736d991 | 502 | return status; |
1670bffd PP |
503 | } |
504 | ||
e1f4c4f7 MJ |
505 | static struct { |
506 | pthread_mutex_t lock; | |
507 | struct bt_plugin_set *plugin_set; | |
d94d92ac | 508 | bool recurse; |
9736d991 | 509 | bool fail_on_load_error; |
d24d5663 | 510 | int status; |
e1f4c4f7 MJ |
511 | } append_all_from_dir_info = { |
512 | .lock = PTHREAD_MUTEX_INITIALIZER | |
513 | }; | |
514 | ||
33b34c43 | 515 | static |
9736d991 | 516 | int nftw_append_all_from_dir(const char *file, |
ecd7492f MJ |
517 | const struct stat *sb __attribute__((unused)), |
518 | int flag, struct FTW *s) | |
33b34c43 | 519 | { |
e1f4c4f7 MJ |
520 | int ret = 0; |
521 | const char *name = file + s->base; | |
522 | ||
523 | /* Check for recursion */ | |
524 | if (!append_all_from_dir_info.recurse && s->level > 1) { | |
525 | goto end; | |
526 | } | |
527 | ||
528 | switch (flag) { | |
529 | case FTW_F: | |
52238017 | 530 | { |
9736d991 | 531 | const struct bt_plugin_set *plugins_from_file = NULL; |
52238017 | 532 | |
e1f4c4f7 MJ |
533 | if (name[0] == '.') { |
534 | /* Skip hidden files */ | |
3f7d4d90 | 535 | BT_LOGI("Skipping hidden file: path=\"%s\"", file); |
e1f4c4f7 MJ |
536 | goto end; |
537 | } | |
52238017 | 538 | |
9736d991 PP |
539 | append_all_from_dir_info.status = |
540 | bt_plugin_find_all_from_file(file, | |
541 | append_all_from_dir_info.fail_on_load_error, | |
542 | &plugins_from_file); | |
d24d5663 | 543 | if (append_all_from_dir_info.status == BT_FUNC_STATUS_OK) { |
e1f4c4f7 MJ |
544 | size_t j; |
545 | ||
9736d991 PP |
546 | BT_ASSERT(plugins_from_file); |
547 | ||
e1f4c4f7 MJ |
548 | for (j = 0; j < plugins_from_file->plugins->len; j++) { |
549 | struct bt_plugin *plugin = | |
550 | g_ptr_array_index(plugins_from_file->plugins, j); | |
551 | ||
3f7d4d90 | 552 | BT_LIB_LOGI("Adding plugin to plugin set: " |
d94d92ac PP |
553 | "plugin-path=\"%s\", %![plugin-]+l", |
554 | file, plugin); | |
92fed4e1 PP |
555 | bt_plugin_set_add_plugin( |
556 | append_all_from_dir_info.plugin_set, | |
557 | plugin); | |
e1f4c4f7 | 558 | } |
33b34c43 | 559 | |
65300d60 | 560 | bt_object_put_ref(plugins_from_file); |
9736d991 PP |
561 | goto end; |
562 | } else if (append_all_from_dir_info.status < 0) { | |
563 | /* bt_plugin_find_all_from_file() logs errors */ | |
564 | BT_ASSERT(!plugins_from_file); | |
565 | ret = -1; | |
566 | goto end; | |
e1f4c4f7 | 567 | } |
9736d991 PP |
568 | |
569 | /* | |
570 | * Not found in this file: this is no an error; continue | |
571 | * walking the directories. | |
572 | */ | |
573 | BT_ASSERT(!plugins_from_file); | |
574 | BT_ASSERT(append_all_from_dir_info.status == | |
d24d5663 | 575 | BT_FUNC_STATUS_NOT_FOUND); |
e1f4c4f7 | 576 | break; |
52238017 | 577 | } |
e1f4c4f7 MJ |
578 | case FTW_DNR: |
579 | /* Continue to next file / directory. */ | |
9736d991 | 580 | BT_LOGI("Cannot enter directory: continuing: path=\"%s\"", file); |
e1f4c4f7 MJ |
581 | break; |
582 | case FTW_NS: | |
583 | /* Continue to next file / directory. */ | |
3f7d4d90 | 584 | BT_LOGI("Cannot get file information: continuing: path=\"%s\"", file); |
e1f4c4f7 | 585 | break; |
33b34c43 | 586 | } |
e1f4c4f7 MJ |
587 | |
588 | end: | |
589 | return ret; | |
33b34c43 PP |
590 | } |
591 | ||
592 | static | |
d24d5663 PP |
593 | int bt_plugin_create_append_all_from_dir(struct bt_plugin_set *plugin_set, |
594 | const char *path, bt_bool recurse, bt_bool fail_on_load_error) | |
33b34c43 | 595 | { |
e1f4c4f7 | 596 | int nftw_flags = FTW_PHYS; |
9736d991 | 597 | int ret; |
d24d5663 | 598 | int status; |
037cbd1a | 599 | struct stat sb; |
33b34c43 | 600 | |
d94d92ac PP |
601 | BT_ASSERT(plugin_set); |
602 | BT_ASSERT(path); | |
603 | BT_ASSERT(strlen(path) < PATH_MAX); | |
037cbd1a JR |
604 | |
605 | /* | |
606 | * Make sure that path exists and is accessible. | |
607 | * This is necessary since Cygwin implementation of nftw() is not POSIX | |
608 | * compliant. Cygwin nftw() implementation does not fail on non-existent | |
609 | * path with ENOENT. Instead, it flags the directory as FTW_NS. FTW_NS during | |
610 | * nftw_append_all_from_dir is not treated as an error since we are | |
611 | * traversing the tree for plugin discovery. | |
612 | */ | |
613 | if (stat(path, &sb)) { | |
614 | BT_LOGW_ERRNO("Cannot open directory", | |
615 | ": path=\"%s\", recurse=%d", | |
616 | path, recurse); | |
870631a2 | 617 | (void) BT_CURRENT_THREAD_ERROR_APPEND_CAUSE_FROM_UNKNOWN( |
d5becf10 | 618 | BT_LIB_LOG_LIBBABELTRACE2_NAME, |
870631a2 PP |
619 | "Cannot open directory: path=\"%s\", recurse=%d", |
620 | path, recurse); | |
d24d5663 | 621 | status = BT_FUNC_STATUS_ERROR; |
037cbd1a JR |
622 | goto end; |
623 | } | |
624 | ||
e1f4c4f7 | 625 | pthread_mutex_lock(&append_all_from_dir_info.lock); |
e1f4c4f7 MJ |
626 | append_all_from_dir_info.plugin_set = plugin_set; |
627 | append_all_from_dir_info.recurse = recurse; | |
d24d5663 | 628 | append_all_from_dir_info.status = BT_FUNC_STATUS_OK; |
9736d991 | 629 | append_all_from_dir_info.fail_on_load_error = fail_on_load_error; |
e1f4c4f7 MJ |
630 | ret = nftw(path, nftw_append_all_from_dir, |
631 | APPEND_ALL_FROM_DIR_NFDOPEN_MAX, nftw_flags); | |
9736d991 PP |
632 | append_all_from_dir_info.plugin_set = NULL; |
633 | status = append_all_from_dir_info.status; | |
e1f4c4f7 | 634 | pthread_mutex_unlock(&append_all_from_dir_info.lock); |
9736d991 | 635 | if (ret) { |
870631a2 | 636 | BT_LIB_LOGW_APPEND_CAUSE("Failed to walk directory", |
9736d991 PP |
637 | ": path=\"%s\", recurse=%d", |
638 | path, recurse); | |
d24d5663 | 639 | status = BT_FUNC_STATUS_ERROR; |
9736d991 PP |
640 | goto end; |
641 | } | |
642 | ||
d24d5663 | 643 | if (status == BT_FUNC_STATUS_NOT_FOUND) { |
9736d991 PP |
644 | /* |
645 | * We're just appending in this function; even if | |
646 | * nothing was found, it's still okay from the caller's | |
647 | * perspective. | |
648 | */ | |
d24d5663 | 649 | status = BT_FUNC_STATUS_OK; |
33b34c43 | 650 | } |
8c1a3187 | 651 | |
9736d991 | 652 | end: |
060cf347 | 653 | return status; |
33b34c43 PP |
654 | } |
655 | ||
1353b066 | 656 | BT_EXPORT |
d24d5663 PP |
657 | enum bt_plugin_find_all_from_dir_status bt_plugin_find_all_from_dir( |
658 | const char *path, bt_bool recurse, bt_bool fail_on_load_error, | |
9736d991 | 659 | const struct bt_plugin_set **plugin_set_out) |
33b34c43 | 660 | { |
d24d5663 PP |
661 | enum bt_plugin_find_all_from_dir_status status = |
662 | BT_FUNC_STATUS_OK; | |
33b34c43 | 663 | |
17f3083a | 664 | BT_ASSERT_PRE_NO_ERROR(); |
d5b13b9b | 665 | BT_ASSERT_PRE_PLUGIN_SET_OUT_NON_NULL(plugin_set_out); |
3f7d4d90 | 666 | BT_LOGI("Creating all plugins in directory: path=\"%s\", recurse=%d", |
8c1a3187 | 667 | path, recurse); |
9736d991 PP |
668 | *plugin_set_out = bt_plugin_set_create(); |
669 | if (!*plugin_set_out) { | |
870631a2 | 670 | BT_LIB_LOGE_APPEND_CAUSE("Cannot create empty plugin set."); |
d24d5663 | 671 | status = BT_FUNC_STATUS_MEMORY_ERROR; |
a8ff38ef PP |
672 | goto error; |
673 | } | |
674 | ||
9736d991 PP |
675 | /* |
676 | * Append found plugins to array (never returns | |
d24d5663 | 677 | * `BT_FUNC_STATUS_NOT_FOUND`) |
9736d991 PP |
678 | */ |
679 | status = bt_plugin_create_append_all_from_dir((void *) *plugin_set_out, | |
680 | path, recurse, fail_on_load_error); | |
33b34c43 | 681 | if (status < 0) { |
9736d991 PP |
682 | /* |
683 | * bt_plugin_create_append_all_from_dir() handles | |
684 | * `fail_on_load_error`, so this is a "real" error. | |
685 | */ | |
870631a2 PP |
686 | BT_LIB_LOGE_APPEND_CAUSE( |
687 | "Cannot append plugins found in directory: " | |
dbd7f7e9 | 688 | "path=\"%s\", status=%s", |
d24d5663 | 689 | path, bt_common_func_status_string(status)); |
33b34c43 PP |
690 | goto error; |
691 | } | |
692 | ||
d24d5663 | 693 | BT_ASSERT(status == BT_FUNC_STATUS_OK); |
9736d991 PP |
694 | |
695 | if ((*plugin_set_out)->plugins->len == 0) { | |
696 | /* Nothing was appended: not found */ | |
697 | BT_LOGI("No plugins found in directory: path=\"%s\"", path); | |
d24d5663 | 698 | status = BT_FUNC_STATUS_NOT_FOUND; |
9736d991 PP |
699 | goto error; |
700 | } | |
701 | ||
3f7d4d90 | 702 | BT_LOGI("Created %u plugins from directory: count=%u, path=\"%s\"", |
9736d991 PP |
703 | (*plugin_set_out)->plugins->len, |
704 | (*plugin_set_out)->plugins->len, path); | |
33b34c43 PP |
705 | goto end; |
706 | ||
707 | error: | |
d24d5663 | 708 | BT_ASSERT(status != BT_FUNC_STATUS_OK); |
9736d991 | 709 | BT_OBJECT_PUT_REF_AND_RESET(*plugin_set_out); |
33b34c43 PP |
710 | |
711 | end: | |
9736d991 | 712 | return status; |
33b34c43 PP |
713 | } |
714 | ||
1353b066 | 715 | BT_EXPORT |
92fed4e1 | 716 | const char *bt_plugin_get_name(const struct bt_plugin *plugin) |
33b34c43 | 717 | { |
d5b13b9b | 718 | BT_ASSERT_PRE_DEV_PLUGIN_NON_NULL(plugin); |
d94d92ac | 719 | return plugin->info.name_set ? plugin->info.name->str : NULL; |
33b34c43 PP |
720 | } |
721 | ||
1353b066 | 722 | BT_EXPORT |
92fed4e1 | 723 | const char *bt_plugin_get_author(const struct bt_plugin *plugin) |
33b34c43 | 724 | { |
d5b13b9b | 725 | BT_ASSERT_PRE_DEV_PLUGIN_NON_NULL(plugin); |
d94d92ac | 726 | return plugin->info.author_set ? plugin->info.author->str : NULL; |
33b34c43 PP |
727 | } |
728 | ||
1353b066 | 729 | BT_EXPORT |
92fed4e1 | 730 | const char *bt_plugin_get_license(const struct bt_plugin *plugin) |
33b34c43 | 731 | { |
d5b13b9b | 732 | BT_ASSERT_PRE_DEV_PLUGIN_NON_NULL(plugin); |
d94d92ac | 733 | return plugin->info.license_set ? plugin->info.license->str : NULL; |
33b34c43 PP |
734 | } |
735 | ||
1353b066 | 736 | BT_EXPORT |
92fed4e1 | 737 | const char *bt_plugin_get_path(const struct bt_plugin *plugin) |
33b34c43 | 738 | { |
d5b13b9b | 739 | BT_ASSERT_PRE_DEV_PLUGIN_NON_NULL(plugin); |
d94d92ac | 740 | return plugin->info.path_set ? plugin->info.path->str : NULL; |
33b34c43 PP |
741 | } |
742 | ||
1353b066 | 743 | BT_EXPORT |
92fed4e1 | 744 | const char *bt_plugin_get_description(const struct bt_plugin *plugin) |
33b34c43 | 745 | { |
d5b13b9b | 746 | BT_ASSERT_PRE_DEV_PLUGIN_NON_NULL(plugin); |
d94d92ac PP |
747 | return plugin->info.description_set ? |
748 | plugin->info.description->str : NULL; | |
33b34c43 PP |
749 | } |
750 | ||
1353b066 | 751 | BT_EXPORT |
92fed4e1 | 752 | enum bt_property_availability bt_plugin_get_version(const struct bt_plugin *plugin, |
b6de043b PP |
753 | unsigned int *major, unsigned int *minor, unsigned int *patch, |
754 | const char **extra) | |
755 | { | |
d94d92ac PP |
756 | enum bt_property_availability avail = |
757 | BT_PROPERTY_AVAILABILITY_AVAILABLE; | |
b6de043b | 758 | |
d5b13b9b | 759 | BT_ASSERT_PRE_DEV_PLUGIN_NON_NULL(plugin); |
8c1a3187 PP |
760 | |
761 | if (!plugin->info.version_set) { | |
3f7d4d90 | 762 | BT_LIB_LOGD("Plugin's version is not set: %!+l", plugin); |
d94d92ac | 763 | avail = BT_PROPERTY_AVAILABILITY_NOT_AVAILABLE; |
b6de043b PP |
764 | goto end; |
765 | } | |
766 | ||
767 | if (major) { | |
55bb57e0 | 768 | *major = plugin->info.version.major; |
b6de043b PP |
769 | } |
770 | ||
771 | if (minor) { | |
55bb57e0 | 772 | *minor = plugin->info.version.minor; |
b6de043b PP |
773 | } |
774 | ||
775 | if (patch) { | |
55bb57e0 | 776 | *patch = plugin->info.version.patch; |
b6de043b PP |
777 | } |
778 | ||
779 | if (extra) { | |
55bb57e0 | 780 | *extra = plugin->info.version.extra->str; |
b6de043b PP |
781 | } |
782 | ||
783 | end: | |
d94d92ac | 784 | return avail; |
b6de043b PP |
785 | } |
786 | ||
1353b066 | 787 | BT_EXPORT |
92fed4e1 | 788 | uint64_t bt_plugin_get_source_component_class_count(const struct bt_plugin *plugin) |
33b34c43 | 789 | { |
d5b13b9b | 790 | BT_ASSERT_PRE_DEV_PLUGIN_NON_NULL(plugin); |
d94d92ac | 791 | return (uint64_t) plugin->src_comp_classes->len; |
33b34c43 PP |
792 | } |
793 | ||
1353b066 | 794 | BT_EXPORT |
92fed4e1 | 795 | uint64_t bt_plugin_get_filter_component_class_count(const struct bt_plugin *plugin) |
33b34c43 | 796 | { |
d5b13b9b | 797 | BT_ASSERT_PRE_DEV_PLUGIN_NON_NULL(plugin); |
d94d92ac PP |
798 | return (uint64_t) plugin->flt_comp_classes->len; |
799 | } | |
33b34c43 | 800 | |
1353b066 | 801 | BT_EXPORT |
92fed4e1 | 802 | uint64_t bt_plugin_get_sink_component_class_count(const struct bt_plugin *plugin) |
d94d92ac | 803 | { |
d5b13b9b | 804 | BT_ASSERT_PRE_DEV_PLUGIN_NON_NULL(plugin); |
d94d92ac PP |
805 | return (uint64_t) plugin->sink_comp_classes->len; |
806 | } | |
8c1a3187 | 807 | |
d94d92ac PP |
808 | static inline |
809 | struct bt_component_class *borrow_component_class_by_index( | |
92fed4e1 | 810 | const struct bt_plugin *plugin, GPtrArray *comp_classes, |
d94d92ac PP |
811 | uint64_t index) |
812 | { | |
d5b13b9b | 813 | BT_ASSERT_PRE_DEV_PLUGIN_NON_NULL(plugin); |
bdb288b3 | 814 | BT_ASSERT_PRE_DEV_VALID_INDEX(index, comp_classes->len); |
d94d92ac PP |
815 | return g_ptr_array_index(comp_classes, index); |
816 | } | |
33b34c43 | 817 | |
1353b066 | 818 | BT_EXPORT |
0d72b8c3 | 819 | const struct bt_component_class_source * |
3f79b5cf | 820 | bt_plugin_borrow_source_component_class_by_index_const( |
92fed4e1 | 821 | const struct bt_plugin *plugin, uint64_t index) |
d94d92ac | 822 | { |
0d72b8c3 | 823 | return (const void *) borrow_component_class_by_index(plugin, |
d94d92ac PP |
824 | plugin->src_comp_classes, index); |
825 | } | |
33b34c43 | 826 | |
1353b066 | 827 | BT_EXPORT |
0d72b8c3 | 828 | const struct bt_component_class_filter * |
92fed4e1 PP |
829 | bt_plugin_borrow_filter_component_class_by_index_const( |
830 | const struct bt_plugin *plugin, uint64_t index) | |
d94d92ac | 831 | { |
0d72b8c3 | 832 | return (const void *) borrow_component_class_by_index(plugin, |
d94d92ac PP |
833 | plugin->flt_comp_classes, index); |
834 | } | |
835 | ||
1353b066 | 836 | BT_EXPORT |
0d72b8c3 | 837 | const struct bt_component_class_sink * |
92fed4e1 PP |
838 | bt_plugin_borrow_sink_component_class_by_index_const( |
839 | const struct bt_plugin *plugin, uint64_t index) | |
d94d92ac | 840 | { |
0d72b8c3 | 841 | return (const void *) borrow_component_class_by_index(plugin, |
d94d92ac | 842 | plugin->sink_comp_classes, index); |
33b34c43 PP |
843 | } |
844 | ||
d94d92ac PP |
845 | static inline |
846 | struct bt_component_class *borrow_component_class_by_name( | |
92fed4e1 | 847 | const struct bt_plugin *plugin, GPtrArray *comp_classes, |
d94d92ac | 848 | const char *name) |
33b34c43 PP |
849 | { |
850 | struct bt_component_class *comp_class = NULL; | |
851 | size_t i; | |
852 | ||
d5b13b9b PP |
853 | BT_ASSERT_PRE_DEV_PLUGIN_NON_NULL(plugin); |
854 | BT_ASSERT_PRE_DEV_NAME_NON_NULL(name); | |
33b34c43 | 855 | |
d94d92ac | 856 | for (i = 0; i < comp_classes->len; i++) { |
33b34c43 | 857 | struct bt_component_class *comp_class_candidate = |
d94d92ac | 858 | g_ptr_array_index(comp_classes, i); |
33b34c43 PP |
859 | const char *comp_class_cand_name = |
860 | bt_component_class_get_name(comp_class_candidate); | |
33b34c43 | 861 | |
98b15851 | 862 | BT_ASSERT_DBG(comp_class_cand_name); |
33b34c43 | 863 | |
d94d92ac PP |
864 | if (strcmp(name, comp_class_cand_name) == 0) { |
865 | comp_class = comp_class_candidate; | |
33b34c43 PP |
866 | break; |
867 | } | |
868 | } | |
869 | ||
33b34c43 PP |
870 | return comp_class; |
871 | } | |
872 | ||
1353b066 | 873 | BT_EXPORT |
0d72b8c3 | 874 | const struct bt_component_class_source * |
92fed4e1 PP |
875 | bt_plugin_borrow_source_component_class_by_name_const( |
876 | const struct bt_plugin *plugin, const char *name) | |
33b34c43 | 877 | { |
0d72b8c3 | 878 | return (const void *) borrow_component_class_by_name(plugin, |
d94d92ac PP |
879 | plugin->src_comp_classes, name); |
880 | } | |
33b34c43 | 881 | |
1353b066 | 882 | BT_EXPORT |
0d72b8c3 | 883 | const struct bt_component_class_filter * |
92fed4e1 PP |
884 | bt_plugin_borrow_filter_component_class_by_name_const( |
885 | const struct bt_plugin *plugin, const char *name) | |
d94d92ac | 886 | { |
0d72b8c3 | 887 | return (const void *) borrow_component_class_by_name(plugin, |
d94d92ac PP |
888 | plugin->flt_comp_classes, name); |
889 | } | |
33b34c43 | 890 | |
1353b066 | 891 | BT_EXPORT |
0d72b8c3 | 892 | const struct bt_component_class_sink * |
92fed4e1 PP |
893 | bt_plugin_borrow_sink_component_class_by_name_const( |
894 | const struct bt_plugin *plugin, const char *name) | |
d94d92ac | 895 | { |
0d72b8c3 | 896 | return (const void *) borrow_component_class_by_name(plugin, |
d94d92ac | 897 | plugin->sink_comp_classes, name); |
33b34c43 | 898 | } |
c5b9b441 | 899 | |
1353b066 | 900 | BT_EXPORT |
c5b9b441 PP |
901 | void bt_plugin_get_ref(const struct bt_plugin *plugin) |
902 | { | |
903 | bt_object_get_ref(plugin); | |
904 | } | |
905 | ||
1353b066 | 906 | BT_EXPORT |
c5b9b441 PP |
907 | void bt_plugin_put_ref(const struct bt_plugin *plugin) |
908 | { | |
909 | bt_object_put_ref(plugin); | |
910 | } | |
911 | ||
1353b066 | 912 | BT_EXPORT |
c5b9b441 PP |
913 | void bt_plugin_set_get_ref(const struct bt_plugin_set *plugin_set) |
914 | { | |
915 | bt_object_get_ref(plugin_set); | |
916 | } | |
917 | ||
1353b066 | 918 | BT_EXPORT |
c5b9b441 PP |
919 | void bt_plugin_set_put_ref(const struct bt_plugin_set *plugin_set) |
920 | { | |
921 | bt_object_put_ref(plugin_set); | |
922 | } |