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