Fix: notif-iter.c: handle single/implicit SC/EC correctly
[babeltrace.git] / lib / plugin / plugin.c
CommitLineData
33b34c43 1/*
33b34c43
PP
2 * Copyright 2016 Jérémie Galarneau <jeremie.galarneau@efficios.com>
3 * Copyright 2017 Philippe Proulx <pproulx@efficios.com>
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
6fbd4105 29#include <babeltrace/babeltrace-internal.h>
3d9990ac 30#include <babeltrace/compiler-internal.h>
65300d60 31#include <babeltrace/object.h>
1670bffd 32#include <babeltrace/common-internal.h>
33b34c43 33#include <babeltrace/plugin/plugin-internal.h>
55bb57e0 34#include <babeltrace/plugin/plugin-so-internal.h>
8c1a3187
PP
35#include <babeltrace/graph/component-class.h>
36#include <babeltrace/graph/component-class-internal.h>
c55a9f58 37#include <babeltrace/types.h>
f6ccaed9 38#include <babeltrace/assert-internal.h>
d94d92ac 39#include <babeltrace/assert-pre-internal.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 58static
a8ff38ef 59struct 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
62static
63void init_python_plugin_provider(void) {}
6fbd4105
PP
64#else /* BT_BUILT_IN_PYTHON_PLUGIN_SUPPORT */
65static GModule *python_plugin_provider_module;
66static
a8ff38ef 67struct bt_plugin_set *(*bt_plugin_python_create_all_from_file_sym)(const char *path);
33b34c43 68
95ef44ce 69static
6fbd4105 70void 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
99void 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 113uint64_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
d94d92ac
PP
119struct bt_plugin *bt_plugin_set_borrow_plugin_by_index(
120 struct bt_plugin_set *plugin_set,
9ac68eb1 121 uint64_t index)
a8ff38ef 122{
d94d92ac
PP
123 BT_ASSERT_PRE_NON_NULL(plugin_set, "Plugin set");
124 BT_ASSERT_PRE_VALID_INDEX(index, plugin_set->plugins->len);
125 return g_ptr_array_index(plugin_set->plugins, index);
a8ff38ef
PP
126}
127
128struct bt_plugin_set *bt_plugin_create_all_from_static(void)
6ba0b073 129{
8c1a3187 130 /* bt_plugin_so_create_all_from_static() logs errors */
55bb57e0 131 return bt_plugin_so_create_all_from_static();
6ba0b073
PP
132}
133
a8ff38ef 134struct bt_plugin_set *bt_plugin_create_all_from_file(const char *path)
33b34c43 135{
a8ff38ef 136 struct bt_plugin_set *plugin_set = NULL;
33b34c43 137
d94d92ac 138 BT_ASSERT_PRE_NON_NULL(path, "Path");
8c1a3187 139 BT_LOGD("Creating plugins from file: path=\"%s\"", path);
6ba0b073 140
55bb57e0 141 /* Try shared object plugins */
a8ff38ef
PP
142 plugin_set = bt_plugin_so_create_all_from_file(path);
143 if (plugin_set) {
6ba0b073
PP
144 goto end;
145 }
146
6fbd4105 147 /* Try Python plugins if support is available */
95ef44ce 148 init_python_plugin_provider();
6fbd4105 149 if (bt_plugin_python_create_all_from_file_sym) {
a8ff38ef
PP
150 plugin_set = bt_plugin_python_create_all_from_file_sym(path);
151 if (plugin_set) {
6fbd4105
PP
152 goto end;
153 }
6ba0b073
PP
154 }
155
33b34c43 156end:
8c1a3187
PP
157 if (plugin_set) {
158 BT_LOGD("Created %u plugins from file: "
159 "path=\"%s\", count=%u, plugin-set-addr=%p",
160 plugin_set->plugins->len, path,
161 plugin_set->plugins->len, plugin_set);
162 } else {
163 BT_LOGD("Found no plugins in file: path=\"%s\"", path);
164 }
165
a8ff38ef 166 return plugin_set;
33b34c43
PP
167}
168
1670bffd
PP
169static void destroy_gstring(void *data)
170{
171 g_string_free(data, TRUE);
172}
173
2b43acf9 174struct bt_plugin *bt_plugin_find(const char *plugin_name)
1670bffd
PP
175{
176 const char *system_plugin_dir;
177 char *home_plugin_dir = NULL;
178 const char *envvar;
179 struct bt_plugin *plugin = NULL;
a8ff38ef 180 struct bt_plugin_set *plugin_set = NULL;
1670bffd
PP
181 GPtrArray *dirs = NULL;
182 int ret;
a8ff38ef 183 size_t i, j;
1670bffd 184
d94d92ac 185 BT_ASSERT_PRE_NON_NULL(plugin_name, "Name");
8c1a3187
PP
186 BT_LOGD("Finding named plugin in standard directories and built-in plugins: "
187 "name=\"%s\"", plugin_name);
1670bffd
PP
188 dirs = g_ptr_array_new_with_free_func((GDestroyNotify) destroy_gstring);
189 if (!dirs) {
8c1a3187 190 BT_LOGE_STR("Failed to allocate a GPtrArray.");
1670bffd
PP
191 goto end;
192 }
193
194 /*
195 * Search order is:
196 *
197 * 1. BABELTRACE_PLUGIN_PATH environment variable
198 * (colon-separated list of directories)
199 * 2. ~/.local/lib/babeltrace/plugins
200 * 3. Default system directory for Babeltrace plugins, usually
201 * /usr/lib/babeltrace/plugins or
202 * /usr/local/lib/babeltrace/plugins if installed
203 * locally
204 * 4. Built-in plugins (static)
205 *
206 * Directories are searched non-recursively.
207 */
208 envvar = getenv("BABELTRACE_PLUGIN_PATH");
209 if (envvar) {
210 ret = bt_common_append_plugin_path_dirs(envvar, dirs);
211 if (ret) {
8c1a3187 212 BT_LOGE_STR("Failed to append plugin path to array of directories.");
1670bffd
PP
213 goto end;
214 }
215 }
216
217 home_plugin_dir = bt_common_get_home_plugin_path();
218 if (home_plugin_dir) {
219 GString *home_plugin_dir_str =
220 g_string_new(home_plugin_dir);
221
222 if (!home_plugin_dir_str) {
8c1a3187 223 BT_LOGE_STR("Failed to allocate a GString.");
1670bffd
PP
224 goto end;
225 }
226
227 g_ptr_array_add(dirs, home_plugin_dir_str);
228 }
229
230 system_plugin_dir = bt_common_get_system_plugin_path();
231 if (system_plugin_dir) {
232 GString *system_plugin_dir_str =
233 g_string_new(system_plugin_dir);
234
235 if (!system_plugin_dir_str) {
8c1a3187 236 BT_LOGE_STR("Failed to allocate a GString.");
1670bffd
PP
237 goto end;
238 }
239
240 g_ptr_array_add(dirs, system_plugin_dir_str);
241 }
242
243 for (i = 0; i < dirs->len; i++) {
244 GString *dir = g_ptr_array_index(dirs, i);
245
65300d60 246 BT_OBJECT_PUT_REF_AND_RESET(plugin_set);
8c1a3187 247
50ad9320
PP
248 /*
249 * Skip this if the directory does not exist because
250 * bt_plugin_create_all_from_dir() would log a warning.
251 */
252 if (!g_file_test(dir->str, G_FILE_TEST_IS_DIR)) {
253 BT_LOGV("Skipping nonexistent directory path: "
254 "path=\"%s\"", dir->str);
255 continue;
256 }
257
8c1a3187 258 /* bt_plugin_create_all_from_dir() logs details/errors */
c55a9f58 259 plugin_set = bt_plugin_create_all_from_dir(dir->str, BT_FALSE);
a8ff38ef 260 if (!plugin_set) {
8c1a3187
PP
261 BT_LOGD("No plugins found in directory: path=\"%s\"",
262 dir->str);
1670bffd
PP
263 continue;
264 }
265
a8ff38ef
PP
266 for (j = 0; j < plugin_set->plugins->len; j++) {
267 struct bt_plugin *candidate_plugin =
268 g_ptr_array_index(plugin_set->plugins, j);
1670bffd 269
a8ff38ef
PP
270 if (strcmp(bt_plugin_get_name(candidate_plugin),
271 plugin_name) == 0) {
8c1a3187
PP
272 BT_LOGD("Plugin found in directory: name=\"%s\", path=\"%s\"",
273 plugin_name, dir->str);
398454ed
PP
274 plugin = candidate_plugin;
275 bt_object_get_no_null_check(plugin);
1670bffd
PP
276 goto end;
277 }
1670bffd 278 }
8c1a3187
PP
279
280 BT_LOGD("Plugin not found in directory: name=\"%s\", path=\"%s\"",
281 plugin_name, dir->str);
1670bffd
PP
282 }
283
65300d60 284 bt_object_put_ref(plugin_set);
a8ff38ef 285 plugin_set = bt_plugin_create_all_from_static();
8c1a3187
PP
286 if (plugin_set) {
287 for (j = 0; j < plugin_set->plugins->len; j++) {
288 struct bt_plugin *candidate_plugin =
289 g_ptr_array_index(plugin_set->plugins, j);
a8ff38ef 290
8c1a3187
PP
291 if (strcmp(bt_plugin_get_name(candidate_plugin),
292 plugin_name) == 0) {
293 BT_LOGD("Plugin found in built-in plugins: "
294 "name=\"%s\"", plugin_name);
398454ed
PP
295 plugin = candidate_plugin;
296 bt_object_get_no_null_check(plugin);
8c1a3187
PP
297 goto end;
298 }
1670bffd 299 }
1670bffd
PP
300 }
301
302end:
303 free(home_plugin_dir);
65300d60 304 bt_object_put_ref(plugin_set);
1670bffd
PP
305
306 if (dirs) {
307 g_ptr_array_free(dirs, TRUE);
308 }
309
8c1a3187 310 if (plugin) {
d94d92ac
PP
311 BT_LIB_LOGD("Found plugin in standard directories and built-in plugins: "
312 "%!+l", plugin);
8c1a3187
PP
313 } else {
314 BT_LOGD("No plugin found in standard directories and built-in plugins: "
315 "name=\"%s\"", plugin_name);
316 }
317
1670bffd
PP
318 return plugin;
319}
320
e1f4c4f7
MJ
321static struct {
322 pthread_mutex_t lock;
323 struct bt_plugin_set *plugin_set;
d94d92ac 324 bool recurse;
e1f4c4f7
MJ
325} append_all_from_dir_info = {
326 .lock = PTHREAD_MUTEX_INITIALIZER
327};
328
33b34c43 329static
e1f4c4f7
MJ
330int nftw_append_all_from_dir(const char *file, const struct stat *sb, int flag,
331 struct FTW *s)
33b34c43 332{
e1f4c4f7
MJ
333 int ret = 0;
334 const char *name = file + s->base;
335
336 /* Check for recursion */
337 if (!append_all_from_dir_info.recurse && s->level > 1) {
338 goto end;
339 }
340
341 switch (flag) {
342 case FTW_F:
52238017
MJ
343 {
344 struct bt_plugin_set *plugins_from_file;
345
e1f4c4f7
MJ
346 if (name[0] == '.') {
347 /* Skip hidden files */
348 BT_LOGV("Skipping hidden file: path=\"%s\"", file);
349 goto end;
350 }
52238017
MJ
351
352 plugins_from_file = bt_plugin_create_all_from_file(file);
e1f4c4f7
MJ
353
354 if (plugins_from_file) {
355 size_t j;
356
357 for (j = 0; j < plugins_from_file->plugins->len; j++) {
358 struct bt_plugin *plugin =
359 g_ptr_array_index(plugins_from_file->plugins, j);
360
d94d92ac
PP
361 BT_LIB_LOGD("Adding plugin to plugin set: "
362 "plugin-path=\"%s\", %![plugin-]+l",
363 file, plugin);
e1f4c4f7
MJ
364 bt_plugin_set_add_plugin(append_all_from_dir_info.plugin_set, plugin);
365 }
33b34c43 366
65300d60 367 bt_object_put_ref(plugins_from_file);
e1f4c4f7
MJ
368 }
369 break;
52238017 370 }
e1f4c4f7
MJ
371 case FTW_DNR:
372 /* Continue to next file / directory. */
373 BT_LOGW("Cannot enter directory: continuing: path=\"%s\"", file);
374 break;
375 case FTW_NS:
376 /* Continue to next file / directory. */
377 BT_LOGD("Cannot get file information: continuing: path=\"%s\"", file);
378 break;
33b34c43 379 }
e1f4c4f7
MJ
380
381end:
382 return ret;
33b34c43
PP
383}
384
385static
386enum bt_plugin_status bt_plugin_create_append_all_from_dir(
a8ff38ef 387 struct bt_plugin_set *plugin_set, const char *path,
c55a9f58 388 bt_bool recurse)
33b34c43 389{
e1f4c4f7 390 int nftw_flags = FTW_PHYS;
33b34c43
PP
391 enum bt_plugin_status ret = BT_PLUGIN_STATUS_OK;
392
d94d92ac
PP
393 BT_ASSERT(plugin_set);
394 BT_ASSERT(path);
395 BT_ASSERT(strlen(path) < PATH_MAX);
e1f4c4f7 396 pthread_mutex_lock(&append_all_from_dir_info.lock);
e1f4c4f7
MJ
397 append_all_from_dir_info.plugin_set = plugin_set;
398 append_all_from_dir_info.recurse = recurse;
399 ret = nftw(path, nftw_append_all_from_dir,
400 APPEND_ALL_FROM_DIR_NFDOPEN_MAX, nftw_flags);
e1f4c4f7 401 pthread_mutex_unlock(&append_all_from_dir_info.lock);
e1f4c4f7 402 if (ret != 0) {
d94d92ac 403 BT_LOGW_ERRNO("Cannot open directory", ": path=\"%s\"", path);
33b34c43 404 ret = BT_PLUGIN_STATUS_ERROR;
33b34c43 405 }
8c1a3187 406
33b34c43
PP
407 return ret;
408}
409
a8ff38ef 410struct bt_plugin_set *bt_plugin_create_all_from_dir(const char *path,
c55a9f58 411 bt_bool recurse)
33b34c43 412{
a8ff38ef 413 struct bt_plugin_set *plugin_set;
33b34c43
PP
414 enum bt_plugin_status status;
415
8c1a3187
PP
416 BT_LOGD("Creating all plugins in directory: path=\"%s\", recurse=%d",
417 path, recurse);
a8ff38ef
PP
418 plugin_set = bt_plugin_set_create();
419 if (!plugin_set) {
8c1a3187 420 BT_LOGE_STR("Cannot create empty plugin set.");
a8ff38ef
PP
421 goto error;
422 }
423
33b34c43 424 /* Append found plugins to array */
a8ff38ef 425 status = bt_plugin_create_append_all_from_dir(plugin_set, path,
33b34c43
PP
426 recurse);
427 if (status < 0) {
8c1a3187 428 BT_LOGW("Cannot append plugins found in directory: "
dbd7f7e9
PP
429 "path=\"%s\", status=%s",
430 path, bt_plugin_status_string(status));
33b34c43
PP
431 goto error;
432 }
433
8c1a3187
PP
434 BT_LOGD("Created %u plugins from directory: count=%u, path=\"%s\"",
435 plugin_set->plugins->len, plugin_set->plugins->len, path);
33b34c43
PP
436 goto end;
437
438error:
65300d60 439 BT_OBJECT_PUT_REF_AND_RESET(plugin_set);
33b34c43
PP
440
441end:
a8ff38ef 442 return plugin_set;
33b34c43
PP
443}
444
33b34c43
PP
445const char *bt_plugin_get_name(struct bt_plugin *plugin)
446{
d94d92ac
PP
447 BT_ASSERT_PRE_NON_NULL(plugin, "Plugin");
448 return plugin->info.name_set ? plugin->info.name->str : NULL;
33b34c43
PP
449}
450
451const char *bt_plugin_get_author(struct bt_plugin *plugin)
452{
d94d92ac
PP
453 BT_ASSERT_PRE_NON_NULL(plugin, "Plugin");
454 return plugin->info.author_set ? plugin->info.author->str : NULL;
33b34c43
PP
455}
456
457const char *bt_plugin_get_license(struct bt_plugin *plugin)
458{
d94d92ac
PP
459 BT_ASSERT_PRE_NON_NULL(plugin, "Plugin");
460 return plugin->info.license_set ? plugin->info.license->str : NULL;
33b34c43
PP
461}
462
463const char *bt_plugin_get_path(struct bt_plugin *plugin)
464{
d94d92ac
PP
465 BT_ASSERT_PRE_NON_NULL(plugin, "Plugin");
466 return plugin->info.path_set ? plugin->info.path->str : NULL;
33b34c43
PP
467}
468
469const char *bt_plugin_get_description(struct bt_plugin *plugin)
470{
d94d92ac
PP
471 BT_ASSERT_PRE_NON_NULL(plugin, "Plugin");
472 return plugin->info.description_set ?
473 plugin->info.description->str : NULL;
33b34c43
PP
474}
475
d94d92ac 476enum bt_property_availability bt_plugin_get_version(struct bt_plugin *plugin,
b6de043b
PP
477 unsigned int *major, unsigned int *minor, unsigned int *patch,
478 const char **extra)
479{
d94d92ac
PP
480 enum bt_property_availability avail =
481 BT_PROPERTY_AVAILABILITY_AVAILABLE;
b6de043b 482
d94d92ac 483 BT_ASSERT_PRE_NON_NULL(plugin, "Plugin");
8c1a3187
PP
484
485 if (!plugin->info.version_set) {
d94d92ac
PP
486 BT_LIB_LOGV("Plugin's version is not set: %!+l", plugin);
487 avail = BT_PROPERTY_AVAILABILITY_NOT_AVAILABLE;
b6de043b
PP
488 goto end;
489 }
490
491 if (major) {
55bb57e0 492 *major = plugin->info.version.major;
b6de043b
PP
493 }
494
495 if (minor) {
55bb57e0 496 *minor = plugin->info.version.minor;
b6de043b
PP
497 }
498
499 if (patch) {
55bb57e0 500 *patch = plugin->info.version.patch;
b6de043b
PP
501 }
502
503 if (extra) {
55bb57e0 504 *extra = plugin->info.version.extra->str;
b6de043b
PP
505 }
506
507end:
d94d92ac 508 return avail;
b6de043b
PP
509}
510
d94d92ac 511uint64_t bt_plugin_get_source_component_class_count(struct bt_plugin *plugin)
33b34c43 512{
d94d92ac
PP
513 BT_ASSERT_PRE_NON_NULL(plugin, "Plugin");
514 return (uint64_t) plugin->src_comp_classes->len;
33b34c43
PP
515}
516
d94d92ac 517uint64_t bt_plugin_get_filter_component_class_count(struct bt_plugin *plugin)
33b34c43 518{
d94d92ac
PP
519 BT_ASSERT_PRE_NON_NULL(plugin, "Plugin");
520 return (uint64_t) plugin->flt_comp_classes->len;
521}
33b34c43 522
d94d92ac
PP
523uint64_t bt_plugin_get_sink_component_class_count(struct bt_plugin *plugin)
524{
525 BT_ASSERT_PRE_NON_NULL(plugin, "Plugin");
526 return (uint64_t) plugin->sink_comp_classes->len;
527}
8c1a3187 528
d94d92ac
PP
529static inline
530struct bt_component_class *borrow_component_class_by_index(
531 struct bt_plugin *plugin, GPtrArray *comp_classes,
532 uint64_t index)
533{
534 BT_ASSERT_PRE_NON_NULL(plugin, "Plugin");
535 BT_ASSERT_PRE_VALID_INDEX(index, comp_classes->len);
536 return g_ptr_array_index(comp_classes, index);
537}
33b34c43 538
33b34c43 539
d94d92ac
PP
540struct bt_component_class_source *
541bt_plugin_borrow_source_component_class_by_index(
542 struct bt_plugin *plugin, uint64_t index)
543{
544 return (void *) borrow_component_class_by_index(plugin,
545 plugin->src_comp_classes, index);
546}
33b34c43 547
d94d92ac
PP
548struct bt_component_class_filter *
549bt_plugin_borrow_filter_component_class_by_index(
550 struct bt_plugin *plugin, uint64_t index)
551{
552 return (void *) borrow_component_class_by_index(plugin,
553 plugin->flt_comp_classes, index);
554}
555
556struct bt_component_class_sink *
557bt_plugin_borrow_sink_component_class_by_index(
558 struct bt_plugin *plugin, uint64_t index)
559{
560 return (void *) borrow_component_class_by_index(plugin,
561 plugin->sink_comp_classes, index);
33b34c43
PP
562}
563
d94d92ac
PP
564static inline
565struct bt_component_class *borrow_component_class_by_name(
566 struct bt_plugin *plugin, GPtrArray *comp_classes,
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
d94d92ac
PP
592struct bt_component_class_source *
593bt_plugin_borrow_source_component_class_by_name(struct bt_plugin *plugin,
594 const char *name)
33b34c43 595{
d94d92ac
PP
596 return (void *) borrow_component_class_by_name(plugin,
597 plugin->src_comp_classes, name);
598}
33b34c43 599
d94d92ac
PP
600struct bt_component_class_filter *
601bt_plugin_borrow_filter_component_class_by_name(struct bt_plugin *plugin,
602 const char *name)
603{
604 return (void *) borrow_component_class_by_name(plugin,
605 plugin->flt_comp_classes, name);
606}
33b34c43 607
d94d92ac
PP
608struct bt_component_class_sink *
609bt_plugin_borrow_sink_component_class_by_name(struct bt_plugin *plugin,
610 const char *name)
611{
612 return (void *) borrow_component_class_by_name(plugin,
613 plugin->sink_comp_classes, name);
33b34c43 614}
This page took 0.066189 seconds and 4 git commands to generate.