+ return factory ? factory->component_classes->len : -1;
+}
+
+struct bt_component_class *bt_component_factory_get_component_class_index(
+ struct bt_component_factory *factory, int index)
+{
+ struct bt_component_class *component_class = NULL;
+
+ if (!factory || index < 0 || index >= factory->component_classes->len) {
+ goto end;
+ }
+
+ component_class = bt_get(g_ptr_array_index(
+ factory->component_classes, index));
+end:
+ return component_class;
+}
+
+struct bt_component_class *bt_component_factory_get_component_class(
+ struct bt_component_factory *factory,
+ const char *plugin_name, enum bt_component_type type,
+ const char *component_name)
+{
+ size_t i;
+ struct bt_component_class *component_class = NULL;
+
+ if (!factory || (!plugin_name && !component_name &&
+ type == BT_COMPONENT_TYPE_UNKNOWN)) {
+ /* At least one criterion must be provided. */
+ goto no_match;
+ }
+
+ for (i = 0; i < factory->component_classes->len; i++) {
+ struct bt_plugin *plugin = NULL;
+
+ component_class = g_ptr_array_index(factory->component_classes,
+ i);
+ plugin = bt_component_class_get_plugin(component_class);
+ assert(plugin);
+
+ if (type != BT_COMPONENT_TYPE_UNKNOWN) {
+ if (type != bt_component_class_get_type(
+ component_class)) {
+ continue;
+ }
+ }
+
+ if (plugin_name) {
+ const char *cur_plugin_name = bt_plugin_get_name(
+ plugin);
+
+ assert(cur_plugin_name);
+ if (strcmp(plugin_name, cur_plugin_name)) {
+ continue;
+ }
+ }
+
+ if (component_name) {
+ const char *cur_cc_name = bt_component_class_get_name(
+ component_class);
+
+ assert(cur_cc_name);
+ if (strcmp(component_name, cur_cc_name)) {
+ continue;
+ }
+ }
+
+ /* All criteria met. */
+ goto match;
+ }
+
+no_match: