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 | ||
8c1a3187 PP |
26 | #define BT_LOG_TAG "PLUGIN" |
27 | #include <babeltrace/lib-logging-internal.h> | |
28 | ||
c5b9b441 PP |
29 | #include <babeltrace/assert-internal.h> |
30 | #include <babeltrace/assert-pre-internal.h> | |
6fbd4105 | 31 | #include <babeltrace/babeltrace-internal.h> |
3d9990ac | 32 | #include <babeltrace/compiler-internal.h> |
1670bffd | 33 | #include <babeltrace/common-internal.h> |
33b34c43 | 34 | #include <babeltrace/plugin/plugin-internal.h> |
55bb57e0 | 35 | #include <babeltrace/plugin/plugin-so-internal.h> |
92fed4e1 | 36 | #include <babeltrace/plugin/plugin-const.h> |
0d72b8c3 | 37 | #include <babeltrace/graph/component-class-const.h> |
8c1a3187 | 38 | #include <babeltrace/graph/component-class-internal.h> |
c55a9f58 | 39 | #include <babeltrace/types.h> |
33b34c43 | 40 | #include <glib.h> |
33b34c43 PP |
41 | #include <unistd.h> |
42 | #include <stdlib.h> | |
9ac68eb1 | 43 | #include <stdint.h> |
8c1a3187 | 44 | #include <inttypes.h> |
33b34c43 | 45 | #include <sys/stat.h> |
e1f4c4f7 MJ |
46 | #include <ftw.h> |
47 | #include <pthread.h> | |
33b34c43 | 48 | |
6fbd4105 PP |
49 | #define PYTHON_PLUGIN_PROVIDER_FILENAME "libbabeltrace-python-plugin-provider." G_MODULE_SUFFIX |
50 | #define PYTHON_PLUGIN_PROVIDER_SYM_NAME bt_plugin_python_create_all_from_file | |
51 | #define PYTHON_PLUGIN_PROVIDER_SYM_NAME_STR TOSTRING(PYTHON_PLUGIN_PROVIDER_SYM_NAME) | |
33b34c43 | 52 | |
e1f4c4f7 MJ |
53 | #define APPEND_ALL_FROM_DIR_NFDOPEN_MAX 8 |
54 | ||
6fbd4105 PP |
55 | #ifdef BT_BUILT_IN_PYTHON_PLUGIN_SUPPORT |
56 | #include <babeltrace/plugin/python-plugin-provider-internal.h> | |
e1f4c4f7 | 57 | |
33b34c43 | 58 | static |
a8ff38ef | 59 | struct bt_plugin_set *(*bt_plugin_python_create_all_from_file_sym)(const char *path) = |
6fbd4105 | 60 | bt_plugin_python_create_all_from_file; |
95ef44ce MJ |
61 | |
62 | static | |
63 | void init_python_plugin_provider(void) {} | |
6fbd4105 PP |
64 | #else /* BT_BUILT_IN_PYTHON_PLUGIN_SUPPORT */ |
65 | static GModule *python_plugin_provider_module; | |
66 | static | |
a8ff38ef | 67 | struct bt_plugin_set *(*bt_plugin_python_create_all_from_file_sym)(const char *path); |
33b34c43 | 68 | |
95ef44ce | 69 | static |
6fbd4105 | 70 | void init_python_plugin_provider(void) { |
95ef44ce MJ |
71 | if (bt_plugin_python_create_all_from_file_sym != NULL) { |
72 | return; | |
73 | } | |
74 | ||
8c1a3187 | 75 | BT_LOGD_STR("Loading Python plugin provider module."); |
6fbd4105 | 76 | python_plugin_provider_module = |
c92fb666 | 77 | g_module_open(PYTHON_PLUGIN_PROVIDER_FILENAME, 0); |
6fbd4105 | 78 | if (!python_plugin_provider_module) { |
a77aed14 PP |
79 | BT_LOGI("Cannot open `%s`: %s: continuing without Python plugin support.", |
80 | PYTHON_PLUGIN_PROVIDER_FILENAME, g_module_error()); | |
6fbd4105 | 81 | return; |
33b34c43 PP |
82 | } |
83 | ||
6fbd4105 PP |
84 | if (!g_module_symbol(python_plugin_provider_module, |
85 | PYTHON_PLUGIN_PROVIDER_SYM_NAME_STR, | |
86 | (gpointer) &bt_plugin_python_create_all_from_file_sym)) { | |
8c1a3187 PP |
87 | BT_LOGI("Cannot find the Python plugin provider loading symbol: continuing without Python plugin support: " |
88 | "file=\"%s\", symbol=\"%s\"", | |
89 | PYTHON_PLUGIN_PROVIDER_FILENAME, | |
90 | PYTHON_PLUGIN_PROVIDER_SYM_NAME_STR); | |
91 | return; | |
33b34c43 | 92 | } |
8c1a3187 | 93 | |
9e0bf9b0 | 94 | BT_LOGI("Loaded Python plugin provider module: addr=%p", |
8c1a3187 | 95 | python_plugin_provider_module); |
33b34c43 PP |
96 | } |
97 | ||
6fbd4105 PP |
98 | __attribute__((destructor)) static |
99 | void fini_python_plugin_provider(void) { | |
100 | if (python_plugin_provider_module) { | |
8c1a3187 PP |
101 | BT_LOGD("Unloading Python plugin provider module."); |
102 | ||
103 | if (!g_module_close(python_plugin_provider_module)) { | |
104 | BT_LOGE("Failed to close the Python plugin provider module: %s.", | |
105 | g_module_error()); | |
106 | } | |
107 | ||
6fbd4105 | 108 | python_plugin_provider_module = NULL; |
6ba0b073 | 109 | } |
6ba0b073 | 110 | } |
6fbd4105 | 111 | #endif |
6ba0b073 | 112 | |
d94d92ac | 113 | uint64_t bt_plugin_set_get_plugin_count(struct bt_plugin_set *plugin_set) |
a8ff38ef | 114 | { |
d94d92ac PP |
115 | BT_ASSERT_PRE_NON_NULL(plugin_set, "Plugin set"); |
116 | return (uint64_t) plugin_set->plugins->len; | |
a8ff38ef PP |
117 | } |
118 | ||
92fed4e1 PP |
119 | const struct bt_plugin *bt_plugin_set_borrow_plugin_by_index_const( |
120 | const struct bt_plugin_set *plugin_set, uint64_t index) | |
a8ff38ef | 121 | { |
d94d92ac PP |
122 | BT_ASSERT_PRE_NON_NULL(plugin_set, "Plugin set"); |
123 | BT_ASSERT_PRE_VALID_INDEX(index, plugin_set->plugins->len); | |
124 | return g_ptr_array_index(plugin_set->plugins, index); | |
a8ff38ef PP |
125 | } |
126 | ||
c8db3219 | 127 | const struct bt_plugin_set *bt_plugin_find_all_from_static(void) |
6ba0b073 | 128 | { |
8c1a3187 | 129 | /* bt_plugin_so_create_all_from_static() logs errors */ |
55bb57e0 | 130 | return bt_plugin_so_create_all_from_static(); |
6ba0b073 PP |
131 | } |
132 | ||
c8db3219 | 133 | const struct bt_plugin_set *bt_plugin_find_all_from_file(const char *path) |
33b34c43 | 134 | { |
a8ff38ef | 135 | struct bt_plugin_set *plugin_set = NULL; |
33b34c43 | 136 | |
d94d92ac | 137 | BT_ASSERT_PRE_NON_NULL(path, "Path"); |
8c1a3187 | 138 | BT_LOGD("Creating plugins from file: path=\"%s\"", path); |
6ba0b073 | 139 | |
55bb57e0 | 140 | /* Try shared object plugins */ |
a8ff38ef PP |
141 | plugin_set = bt_plugin_so_create_all_from_file(path); |
142 | if (plugin_set) { | |
6ba0b073 PP |
143 | goto end; |
144 | } | |
145 | ||
6fbd4105 | 146 | /* Try Python plugins if support is available */ |
95ef44ce | 147 | init_python_plugin_provider(); |
6fbd4105 | 148 | if (bt_plugin_python_create_all_from_file_sym) { |
a8ff38ef PP |
149 | plugin_set = bt_plugin_python_create_all_from_file_sym(path); |
150 | if (plugin_set) { | |
6fbd4105 PP |
151 | goto end; |
152 | } | |
6ba0b073 PP |
153 | } |
154 | ||
33b34c43 | 155 | end: |
8c1a3187 PP |
156 | if (plugin_set) { |
157 | BT_LOGD("Created %u plugins from file: " | |
158 | "path=\"%s\", count=%u, plugin-set-addr=%p", | |
159 | plugin_set->plugins->len, path, | |
160 | plugin_set->plugins->len, plugin_set); | |
161 | } else { | |
162 | BT_LOGD("Found no plugins in file: path=\"%s\"", path); | |
163 | } | |
164 | ||
a8ff38ef | 165 | return plugin_set; |
33b34c43 PP |
166 | } |
167 | ||
1670bffd PP |
168 | static void destroy_gstring(void *data) |
169 | { | |
170 | g_string_free(data, TRUE); | |
171 | } | |
172 | ||
92fed4e1 | 173 | const struct bt_plugin *bt_plugin_find(const char *plugin_name) |
1670bffd PP |
174 | { |
175 | const char *system_plugin_dir; | |
176 | char *home_plugin_dir = NULL; | |
177 | const char *envvar; | |
92fed4e1 PP |
178 | const struct bt_plugin *plugin = NULL; |
179 | const struct bt_plugin_set *plugin_set = NULL; | |
1670bffd PP |
180 | GPtrArray *dirs = NULL; |
181 | int ret; | |
a8ff38ef | 182 | size_t i, j; |
1670bffd | 183 | |
d94d92ac | 184 | BT_ASSERT_PRE_NON_NULL(plugin_name, "Name"); |
8c1a3187 PP |
185 | BT_LOGD("Finding named plugin in standard directories and built-in plugins: " |
186 | "name=\"%s\"", plugin_name); | |
1670bffd PP |
187 | dirs = g_ptr_array_new_with_free_func((GDestroyNotify) destroy_gstring); |
188 | if (!dirs) { | |
8c1a3187 | 189 | BT_LOGE_STR("Failed to allocate a GPtrArray."); |
1670bffd PP |
190 | goto end; |
191 | } | |
192 | ||
193 | /* | |
194 | * Search order is: | |
195 | * | |
196 | * 1. BABELTRACE_PLUGIN_PATH environment variable | |
197 | * (colon-separated list of directories) | |
198 | * 2. ~/.local/lib/babeltrace/plugins | |
199 | * 3. Default system directory for Babeltrace plugins, usually | |
200 | * /usr/lib/babeltrace/plugins or | |
201 | * /usr/local/lib/babeltrace/plugins if installed | |
202 | * locally | |
203 | * 4. Built-in plugins (static) | |
204 | * | |
205 | * Directories are searched non-recursively. | |
206 | */ | |
207 | envvar = getenv("BABELTRACE_PLUGIN_PATH"); | |
208 | if (envvar) { | |
209 | ret = bt_common_append_plugin_path_dirs(envvar, dirs); | |
210 | if (ret) { | |
8c1a3187 | 211 | BT_LOGE_STR("Failed to append plugin path to array of directories."); |
1670bffd PP |
212 | goto end; |
213 | } | |
214 | } | |
215 | ||
216 | home_plugin_dir = bt_common_get_home_plugin_path(); | |
217 | if (home_plugin_dir) { | |
218 | GString *home_plugin_dir_str = | |
219 | g_string_new(home_plugin_dir); | |
220 | ||
221 | if (!home_plugin_dir_str) { | |
8c1a3187 | 222 | BT_LOGE_STR("Failed to allocate a GString."); |
1670bffd PP |
223 | goto end; |
224 | } | |
225 | ||
226 | g_ptr_array_add(dirs, home_plugin_dir_str); | |
227 | } | |
228 | ||
229 | system_plugin_dir = bt_common_get_system_plugin_path(); | |
230 | if (system_plugin_dir) { | |
231 | GString *system_plugin_dir_str = | |
232 | g_string_new(system_plugin_dir); | |
233 | ||
234 | if (!system_plugin_dir_str) { | |
8c1a3187 | 235 | BT_LOGE_STR("Failed to allocate a GString."); |
1670bffd PP |
236 | goto end; |
237 | } | |
238 | ||
239 | g_ptr_array_add(dirs, system_plugin_dir_str); | |
240 | } | |
241 | ||
242 | for (i = 0; i < dirs->len; i++) { | |
243 | GString *dir = g_ptr_array_index(dirs, i); | |
244 | ||
65300d60 | 245 | BT_OBJECT_PUT_REF_AND_RESET(plugin_set); |
8c1a3187 | 246 | |
50ad9320 PP |
247 | /* |
248 | * Skip this if the directory does not exist because | |
c8db3219 | 249 | * bt_plugin_find_all_from_dir() would log a warning. |
50ad9320 PP |
250 | */ |
251 | if (!g_file_test(dir->str, G_FILE_TEST_IS_DIR)) { | |
252 | BT_LOGV("Skipping nonexistent directory path: " | |
253 | "path=\"%s\"", dir->str); | |
254 | continue; | |
255 | } | |
256 | ||
c8db3219 PP |
257 | /* bt_plugin_find_all_from_dir() logs details/errors */ |
258 | plugin_set = bt_plugin_find_all_from_dir(dir->str, BT_FALSE); | |
a8ff38ef | 259 | if (!plugin_set) { |
8c1a3187 PP |
260 | BT_LOGD("No plugins found in directory: path=\"%s\"", |
261 | dir->str); | |
1670bffd PP |
262 | continue; |
263 | } | |
264 | ||
a8ff38ef | 265 | for (j = 0; j < plugin_set->plugins->len; j++) { |
92fed4e1 | 266 | const struct bt_plugin *candidate_plugin = |
a8ff38ef | 267 | g_ptr_array_index(plugin_set->plugins, j); |
1670bffd | 268 | |
a8ff38ef PP |
269 | if (strcmp(bt_plugin_get_name(candidate_plugin), |
270 | plugin_name) == 0) { | |
8c1a3187 PP |
271 | BT_LOGD("Plugin found in directory: name=\"%s\", path=\"%s\"", |
272 | plugin_name, dir->str); | |
398454ed PP |
273 | plugin = candidate_plugin; |
274 | bt_object_get_no_null_check(plugin); | |
1670bffd PP |
275 | goto end; |
276 | } | |
1670bffd | 277 | } |
8c1a3187 PP |
278 | |
279 | BT_LOGD("Plugin not found in directory: name=\"%s\", path=\"%s\"", | |
280 | plugin_name, dir->str); | |
1670bffd PP |
281 | } |
282 | ||
65300d60 | 283 | bt_object_put_ref(plugin_set); |
c8db3219 | 284 | plugin_set = bt_plugin_find_all_from_static(); |
8c1a3187 PP |
285 | if (plugin_set) { |
286 | for (j = 0; j < plugin_set->plugins->len; j++) { | |
92fed4e1 | 287 | const struct bt_plugin *candidate_plugin = |
8c1a3187 | 288 | g_ptr_array_index(plugin_set->plugins, j); |
a8ff38ef | 289 | |
8c1a3187 PP |
290 | if (strcmp(bt_plugin_get_name(candidate_plugin), |
291 | plugin_name) == 0) { | |
292 | BT_LOGD("Plugin found in built-in plugins: " | |
293 | "name=\"%s\"", plugin_name); | |
398454ed PP |
294 | plugin = candidate_plugin; |
295 | bt_object_get_no_null_check(plugin); | |
8c1a3187 PP |
296 | goto end; |
297 | } | |
1670bffd | 298 | } |
1670bffd PP |
299 | } |
300 | ||
301 | end: | |
302 | free(home_plugin_dir); | |
65300d60 | 303 | bt_object_put_ref(plugin_set); |
1670bffd PP |
304 | |
305 | if (dirs) { | |
306 | g_ptr_array_free(dirs, TRUE); | |
307 | } | |
308 | ||
8c1a3187 | 309 | if (plugin) { |
d94d92ac PP |
310 | BT_LIB_LOGD("Found plugin in standard directories and built-in plugins: " |
311 | "%!+l", plugin); | |
8c1a3187 PP |
312 | } else { |
313 | BT_LOGD("No plugin found in standard directories and built-in plugins: " | |
314 | "name=\"%s\"", plugin_name); | |
315 | } | |
316 | ||
1670bffd PP |
317 | return plugin; |
318 | } | |
319 | ||
e1f4c4f7 MJ |
320 | static struct { |
321 | pthread_mutex_t lock; | |
322 | struct bt_plugin_set *plugin_set; | |
d94d92ac | 323 | bool recurse; |
e1f4c4f7 MJ |
324 | } append_all_from_dir_info = { |
325 | .lock = PTHREAD_MUTEX_INITIALIZER | |
326 | }; | |
327 | ||
33b34c43 | 328 | static |
e1f4c4f7 MJ |
329 | int nftw_append_all_from_dir(const char *file, const struct stat *sb, int flag, |
330 | struct FTW *s) | |
33b34c43 | 331 | { |
e1f4c4f7 MJ |
332 | int ret = 0; |
333 | const char *name = file + s->base; | |
334 | ||
335 | /* Check for recursion */ | |
336 | if (!append_all_from_dir_info.recurse && s->level > 1) { | |
337 | goto end; | |
338 | } | |
339 | ||
340 | switch (flag) { | |
341 | case FTW_F: | |
52238017 | 342 | { |
92fed4e1 | 343 | const struct bt_plugin_set *plugins_from_file; |
52238017 | 344 | |
e1f4c4f7 MJ |
345 | if (name[0] == '.') { |
346 | /* Skip hidden files */ | |
347 | BT_LOGV("Skipping hidden file: path=\"%s\"", file); | |
348 | goto end; | |
349 | } | |
52238017 | 350 | |
c8db3219 | 351 | plugins_from_file = bt_plugin_find_all_from_file(file); |
e1f4c4f7 MJ |
352 | |
353 | if (plugins_from_file) { | |
354 | size_t j; | |
355 | ||
356 | for (j = 0; j < plugins_from_file->plugins->len; j++) { | |
357 | struct bt_plugin *plugin = | |
358 | g_ptr_array_index(plugins_from_file->plugins, j); | |
359 | ||
d94d92ac PP |
360 | BT_LIB_LOGD("Adding plugin to plugin set: " |
361 | "plugin-path=\"%s\", %![plugin-]+l", | |
362 | file, plugin); | |
92fed4e1 PP |
363 | bt_plugin_set_add_plugin( |
364 | append_all_from_dir_info.plugin_set, | |
365 | plugin); | |
e1f4c4f7 | 366 | } |
33b34c43 | 367 | |
65300d60 | 368 | bt_object_put_ref(plugins_from_file); |
e1f4c4f7 MJ |
369 | } |
370 | break; | |
52238017 | 371 | } |
e1f4c4f7 MJ |
372 | case FTW_DNR: |
373 | /* Continue to next file / directory. */ | |
374 | BT_LOGW("Cannot enter directory: continuing: path=\"%s\"", file); | |
375 | break; | |
376 | case FTW_NS: | |
377 | /* Continue to next file / directory. */ | |
378 | BT_LOGD("Cannot get file information: continuing: path=\"%s\"", file); | |
379 | break; | |
33b34c43 | 380 | } |
e1f4c4f7 MJ |
381 | |
382 | end: | |
383 | return ret; | |
33b34c43 PP |
384 | } |
385 | ||
386 | static | |
387 | enum bt_plugin_status bt_plugin_create_append_all_from_dir( | |
a8ff38ef | 388 | struct bt_plugin_set *plugin_set, const char *path, |
c55a9f58 | 389 | bt_bool recurse) |
33b34c43 | 390 | { |
e1f4c4f7 | 391 | int nftw_flags = FTW_PHYS; |
33b34c43 PP |
392 | enum bt_plugin_status ret = BT_PLUGIN_STATUS_OK; |
393 | ||
d94d92ac PP |
394 | BT_ASSERT(plugin_set); |
395 | BT_ASSERT(path); | |
396 | BT_ASSERT(strlen(path) < PATH_MAX); | |
e1f4c4f7 | 397 | pthread_mutex_lock(&append_all_from_dir_info.lock); |
e1f4c4f7 MJ |
398 | append_all_from_dir_info.plugin_set = plugin_set; |
399 | append_all_from_dir_info.recurse = recurse; | |
400 | ret = nftw(path, nftw_append_all_from_dir, | |
401 | APPEND_ALL_FROM_DIR_NFDOPEN_MAX, nftw_flags); | |
e1f4c4f7 | 402 | pthread_mutex_unlock(&append_all_from_dir_info.lock); |
e1f4c4f7 | 403 | if (ret != 0) { |
d94d92ac | 404 | BT_LOGW_ERRNO("Cannot open directory", ": path=\"%s\"", path); |
33b34c43 | 405 | ret = BT_PLUGIN_STATUS_ERROR; |
33b34c43 | 406 | } |
8c1a3187 | 407 | |
33b34c43 PP |
408 | return ret; |
409 | } | |
410 | ||
c8db3219 | 411 | const struct bt_plugin_set *bt_plugin_find_all_from_dir(const char *path, |
c55a9f58 | 412 | bt_bool recurse) |
33b34c43 | 413 | { |
a8ff38ef | 414 | struct bt_plugin_set *plugin_set; |
33b34c43 PP |
415 | enum bt_plugin_status status; |
416 | ||
8c1a3187 PP |
417 | BT_LOGD("Creating all plugins in directory: path=\"%s\", recurse=%d", |
418 | path, recurse); | |
a8ff38ef PP |
419 | plugin_set = bt_plugin_set_create(); |
420 | if (!plugin_set) { | |
8c1a3187 | 421 | BT_LOGE_STR("Cannot create empty plugin set."); |
a8ff38ef PP |
422 | goto error; |
423 | } | |
424 | ||
33b34c43 | 425 | /* Append found plugins to array */ |
a8ff38ef | 426 | status = bt_plugin_create_append_all_from_dir(plugin_set, path, |
33b34c43 PP |
427 | recurse); |
428 | if (status < 0) { | |
8c1a3187 | 429 | BT_LOGW("Cannot append plugins found in directory: " |
dbd7f7e9 PP |
430 | "path=\"%s\", status=%s", |
431 | path, bt_plugin_status_string(status)); | |
33b34c43 PP |
432 | goto error; |
433 | } | |
434 | ||
8c1a3187 PP |
435 | BT_LOGD("Created %u plugins from directory: count=%u, path=\"%s\"", |
436 | plugin_set->plugins->len, plugin_set->plugins->len, path); | |
33b34c43 PP |
437 | goto end; |
438 | ||
439 | error: | |
65300d60 | 440 | BT_OBJECT_PUT_REF_AND_RESET(plugin_set); |
33b34c43 PP |
441 | |
442 | end: | |
a8ff38ef | 443 | return plugin_set; |
33b34c43 PP |
444 | } |
445 | ||
92fed4e1 | 446 | const char *bt_plugin_get_name(const struct bt_plugin *plugin) |
33b34c43 | 447 | { |
d94d92ac PP |
448 | BT_ASSERT_PRE_NON_NULL(plugin, "Plugin"); |
449 | return plugin->info.name_set ? plugin->info.name->str : NULL; | |
33b34c43 PP |
450 | } |
451 | ||
92fed4e1 | 452 | const char *bt_plugin_get_author(const struct bt_plugin *plugin) |
33b34c43 | 453 | { |
d94d92ac PP |
454 | BT_ASSERT_PRE_NON_NULL(plugin, "Plugin"); |
455 | return plugin->info.author_set ? plugin->info.author->str : NULL; | |
33b34c43 PP |
456 | } |
457 | ||
92fed4e1 | 458 | const char *bt_plugin_get_license(const struct bt_plugin *plugin) |
33b34c43 | 459 | { |
d94d92ac PP |
460 | BT_ASSERT_PRE_NON_NULL(plugin, "Plugin"); |
461 | return plugin->info.license_set ? plugin->info.license->str : NULL; | |
33b34c43 PP |
462 | } |
463 | ||
92fed4e1 | 464 | const char *bt_plugin_get_path(const struct bt_plugin *plugin) |
33b34c43 | 465 | { |
d94d92ac PP |
466 | BT_ASSERT_PRE_NON_NULL(plugin, "Plugin"); |
467 | return plugin->info.path_set ? plugin->info.path->str : NULL; | |
33b34c43 PP |
468 | } |
469 | ||
92fed4e1 | 470 | const char *bt_plugin_get_description(const struct bt_plugin *plugin) |
33b34c43 | 471 | { |
d94d92ac PP |
472 | BT_ASSERT_PRE_NON_NULL(plugin, "Plugin"); |
473 | return plugin->info.description_set ? | |
474 | plugin->info.description->str : NULL; | |
33b34c43 PP |
475 | } |
476 | ||
92fed4e1 | 477 | enum bt_property_availability bt_plugin_get_version(const struct bt_plugin *plugin, |
b6de043b PP |
478 | unsigned int *major, unsigned int *minor, unsigned int *patch, |
479 | const char **extra) | |
480 | { | |
d94d92ac PP |
481 | enum bt_property_availability avail = |
482 | BT_PROPERTY_AVAILABILITY_AVAILABLE; | |
b6de043b | 483 | |
d94d92ac | 484 | BT_ASSERT_PRE_NON_NULL(plugin, "Plugin"); |
8c1a3187 PP |
485 | |
486 | if (!plugin->info.version_set) { | |
d94d92ac PP |
487 | BT_LIB_LOGV("Plugin's version is not set: %!+l", plugin); |
488 | avail = BT_PROPERTY_AVAILABILITY_NOT_AVAILABLE; | |
b6de043b PP |
489 | goto end; |
490 | } | |
491 | ||
492 | if (major) { | |
55bb57e0 | 493 | *major = plugin->info.version.major; |
b6de043b PP |
494 | } |
495 | ||
496 | if (minor) { | |
55bb57e0 | 497 | *minor = plugin->info.version.minor; |
b6de043b PP |
498 | } |
499 | ||
500 | if (patch) { | |
55bb57e0 | 501 | *patch = plugin->info.version.patch; |
b6de043b PP |
502 | } |
503 | ||
504 | if (extra) { | |
55bb57e0 | 505 | *extra = plugin->info.version.extra->str; |
b6de043b PP |
506 | } |
507 | ||
508 | end: | |
d94d92ac | 509 | return avail; |
b6de043b PP |
510 | } |
511 | ||
92fed4e1 | 512 | uint64_t bt_plugin_get_source_component_class_count(const struct bt_plugin *plugin) |
33b34c43 | 513 | { |
d94d92ac PP |
514 | BT_ASSERT_PRE_NON_NULL(plugin, "Plugin"); |
515 | return (uint64_t) plugin->src_comp_classes->len; | |
33b34c43 PP |
516 | } |
517 | ||
92fed4e1 | 518 | uint64_t bt_plugin_get_filter_component_class_count(const struct bt_plugin *plugin) |
33b34c43 | 519 | { |
d94d92ac PP |
520 | BT_ASSERT_PRE_NON_NULL(plugin, "Plugin"); |
521 | return (uint64_t) plugin->flt_comp_classes->len; | |
522 | } | |
33b34c43 | 523 | |
92fed4e1 | 524 | uint64_t bt_plugin_get_sink_component_class_count(const struct bt_plugin *plugin) |
d94d92ac PP |
525 | { |
526 | BT_ASSERT_PRE_NON_NULL(plugin, "Plugin"); | |
527 | return (uint64_t) plugin->sink_comp_classes->len; | |
528 | } | |
8c1a3187 | 529 | |
d94d92ac PP |
530 | static inline |
531 | struct bt_component_class *borrow_component_class_by_index( | |
92fed4e1 | 532 | const struct bt_plugin *plugin, GPtrArray *comp_classes, |
d94d92ac PP |
533 | uint64_t index) |
534 | { | |
535 | BT_ASSERT_PRE_NON_NULL(plugin, "Plugin"); | |
536 | BT_ASSERT_PRE_VALID_INDEX(index, comp_classes->len); | |
537 | return g_ptr_array_index(comp_classes, index); | |
538 | } | |
33b34c43 | 539 | |
0d72b8c3 | 540 | const struct bt_component_class_source * |
3f79b5cf | 541 | bt_plugin_borrow_source_component_class_by_index_const( |
92fed4e1 | 542 | const struct bt_plugin *plugin, uint64_t index) |
d94d92ac | 543 | { |
0d72b8c3 | 544 | return (const void *) borrow_component_class_by_index(plugin, |
d94d92ac PP |
545 | plugin->src_comp_classes, index); |
546 | } | |
33b34c43 | 547 | |
0d72b8c3 | 548 | const struct bt_component_class_filter * |
92fed4e1 PP |
549 | bt_plugin_borrow_filter_component_class_by_index_const( |
550 | const struct bt_plugin *plugin, uint64_t index) | |
d94d92ac | 551 | { |
0d72b8c3 | 552 | return (const void *) borrow_component_class_by_index(plugin, |
d94d92ac PP |
553 | plugin->flt_comp_classes, index); |
554 | } | |
555 | ||
0d72b8c3 | 556 | const struct bt_component_class_sink * |
92fed4e1 PP |
557 | bt_plugin_borrow_sink_component_class_by_index_const( |
558 | const struct bt_plugin *plugin, uint64_t index) | |
d94d92ac | 559 | { |
0d72b8c3 | 560 | return (const void *) borrow_component_class_by_index(plugin, |
d94d92ac | 561 | plugin->sink_comp_classes, index); |
33b34c43 PP |
562 | } |
563 | ||
d94d92ac PP |
564 | static inline |
565 | struct bt_component_class *borrow_component_class_by_name( | |
92fed4e1 | 566 | const struct bt_plugin *plugin, GPtrArray *comp_classes, |
d94d92ac | 567 | const char *name) |
33b34c43 PP |
568 | { |
569 | struct bt_component_class *comp_class = NULL; | |
570 | size_t i; | |
571 | ||
d94d92ac PP |
572 | BT_ASSERT_PRE_NON_NULL(plugin, "Plugin"); |
573 | BT_ASSERT_PRE_NON_NULL(name, "Name"); | |
33b34c43 | 574 | |
d94d92ac | 575 | for (i = 0; i < comp_classes->len; i++) { |
33b34c43 | 576 | struct bt_component_class *comp_class_candidate = |
d94d92ac | 577 | g_ptr_array_index(comp_classes, i); |
33b34c43 PP |
578 | const char *comp_class_cand_name = |
579 | bt_component_class_get_name(comp_class_candidate); | |
33b34c43 | 580 | |
f6ccaed9 | 581 | BT_ASSERT(comp_class_cand_name); |
33b34c43 | 582 | |
d94d92ac PP |
583 | if (strcmp(name, comp_class_cand_name) == 0) { |
584 | comp_class = comp_class_candidate; | |
33b34c43 PP |
585 | break; |
586 | } | |
587 | } | |
588 | ||
33b34c43 PP |
589 | return comp_class; |
590 | } | |
591 | ||
0d72b8c3 | 592 | const struct bt_component_class_source * |
92fed4e1 PP |
593 | bt_plugin_borrow_source_component_class_by_name_const( |
594 | const struct bt_plugin *plugin, const char *name) | |
33b34c43 | 595 | { |
0d72b8c3 | 596 | return (const void *) borrow_component_class_by_name(plugin, |
d94d92ac PP |
597 | plugin->src_comp_classes, name); |
598 | } | |
33b34c43 | 599 | |
0d72b8c3 | 600 | const struct bt_component_class_filter * |
92fed4e1 PP |
601 | bt_plugin_borrow_filter_component_class_by_name_const( |
602 | const struct bt_plugin *plugin, const char *name) | |
d94d92ac | 603 | { |
0d72b8c3 | 604 | return (const void *) borrow_component_class_by_name(plugin, |
d94d92ac PP |
605 | plugin->flt_comp_classes, name); |
606 | } | |
33b34c43 | 607 | |
0d72b8c3 | 608 | const struct bt_component_class_sink * |
92fed4e1 PP |
609 | bt_plugin_borrow_sink_component_class_by_name_const( |
610 | const struct bt_plugin *plugin, const char *name) | |
d94d92ac | 611 | { |
0d72b8c3 | 612 | return (const void *) borrow_component_class_by_name(plugin, |
d94d92ac | 613 | plugin->sink_comp_classes, name); |
33b34c43 | 614 | } |
c5b9b441 PP |
615 | |
616 | void bt_plugin_get_ref(const struct bt_plugin *plugin) | |
617 | { | |
618 | bt_object_get_ref(plugin); | |
619 | } | |
620 | ||
621 | void bt_plugin_put_ref(const struct bt_plugin *plugin) | |
622 | { | |
623 | bt_object_put_ref(plugin); | |
624 | } | |
625 | ||
626 | void bt_plugin_set_get_ref(const struct bt_plugin_set *plugin_set) | |
627 | { | |
628 | bt_object_get_ref(plugin_set); | |
629 | } | |
630 | ||
631 | void bt_plugin_set_put_ref(const struct bt_plugin_set *plugin_set) | |
632 | { | |
633 | bt_object_put_ref(plugin_set); | |
634 | } |