|
6 | 6 |
|
7 | 7 | import collections |
8 | 8 | import errno |
| 9 | +from collections.abc import Iterable |
| 10 | +from pathlib import Path |
9 | 11 |
|
10 | 12 | from linuxpy.ctypes import POINTER, cast, cvoidp |
11 | | -from linuxpy.device import BaseDevice |
| 13 | +from linuxpy.device import BaseDevice, iter_device_files |
12 | 14 | from linuxpy.ioctl import ioctl |
| 15 | +from linuxpy.types import PathLike |
| 16 | +from linuxpy.util import make_find |
13 | 17 |
|
14 | 18 | from . import raw |
15 | 19 |
|
|
26 | 30 | PadDesc = collections.namedtuple("PadDesc", "entity_id flags index") |
27 | 31 | LinkDesc = collections.namedtuple("LinkDesc", "source sink flags") |
28 | 32 |
|
| 33 | +EntityFunction = raw.EntityFunction |
| 34 | + |
29 | 35 |
|
30 | 36 | def entity_has_flags(version: int): |
31 | 37 | return (version) >= ((4 << 16) | (19 << 8) | 0) |
@@ -139,10 +145,11 @@ def iter_entities(fd): |
139 | 145 | ) |
140 | 146 | for link in links.links[: raw_entity_desc.links] |
141 | 147 | ] |
| 148 | + func = raw_entity_desc.type |
142 | 149 | yield EntityDesc( |
143 | 150 | raw_entity_desc.id, |
144 | 151 | raw_entity_desc.name.decode(), |
145 | | - raw.EntityFunction(raw_entity_desc.type), |
| 152 | + EntityFunction(func) if func in EntityFunction else func, |
146 | 153 | raw.EntityFlag(raw_entity_desc.flags), |
147 | 154 | pads, |
148 | 155 | links, |
@@ -171,3 +178,16 @@ def get_topology(self): |
171 | 178 |
|
172 | 179 | def get_device_info(self): |
173 | 180 | return get_device_info(self) |
| 181 | + |
| 182 | + |
| 183 | +def iter_media_files(path: PathLike = "/dev") -> Iterable[Path]: |
| 184 | + """Returns an iterator over all media files""" |
| 185 | + return iter_device_files(path=path, pattern="media*") |
| 186 | + |
| 187 | + |
| 188 | +def iter_devices(path: PathLike = "/dev", **kwargs) -> Iterable[Device]: |
| 189 | + """Returns an iterator over all media devices""" |
| 190 | + return (Device(name, **kwargs) for name in iter_media_files(path=path)) |
| 191 | + |
| 192 | + |
| 193 | +find = make_find(iter_devices) |
0 commit comments