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