+class _PluginComponentClassesIterator(collections.abc.Iterator):
+ def __init__(self, plugin_comp_cls):
+ self._plugin_comp_cls = plugin_comp_cls
+ self._at = 0
+
+ def __next__(self):
+ plugin_ptr = self._plugin_comp_cls._plugin._ptr
+ comp_cls_type = self._plugin_comp_cls._comp_cls_type
+ total = native_bt.plugin_get_component_class_count(plugin_ptr)
+
+ while True:
+ if self._at == total:
+ raise StopIteration
+
+ comp_cls_ptr = native_bt.plugin_get_component_class_by_index(plugin_ptr,
+ self._at)
+ assert(comp_cls_ptr)
+ cc_type = native_bt.component_class_get_type(comp_cls_ptr)
+ self._at += 1
+
+ if cc_type == comp_cls_type:
+ break
+
+ native_bt.put(comp_cls_ptr)
+
+ name = native_bt.component_class_get_name(comp_cls_ptr)
+ native_bt.put(comp_cls_ptr)
+ assert(name is not None)
+ return name
+
+
+class _PluginComponentClasses(collections.abc.Mapping):
+ def __init__(self, plugin, comp_cls_type):
+ self._plugin = plugin
+ self._comp_cls_type = comp_cls_type
+
+ def __getitem__(self, key):
+ utils._check_str(key)
+ cc_ptr = native_bt.plugin_get_component_class_by_name_and_type(self._plugin._ptr,
+ key,
+ self._comp_cls_type)
+
+ if cc_ptr is None:
+ raise KeyError(key)
+
+ return bt2.component._create_generic_component_class_from_ptr(cc_ptr)
+
+ def __len__(self):
+ count = 0
+ total = native_bt.plugin_get_component_class_count(self._plugin._ptr)
+
+ for at in range(total):
+ comp_cls_ptr = native_bt.plugin_get_component_class_by_index(self._plugin._ptr,
+ at)
+ assert(comp_cls_ptr)
+ cc_type = native_bt.component_class_get_type(comp_cls_ptr)
+
+ if cc_type == self._comp_cls_type:
+ count += 1
+
+ native_bt.put(comp_cls_ptr)
+
+ return count
+
+ def __iter__(self):
+ return _PluginComponentClassesIterator(self)
+
+
+class _Plugin(object._Object):