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