From 888b03b281397f2569af50b33d3a7de3c93e0fd9 Mon Sep 17 00:00:00 2001 From: Sakari Ailus Date: Sat, 14 Jan 2012 21:33:36 +0200 Subject: libmediactl: Implement MEDIA_ENT_ID_FLAG_NEXT in media_get_entity_by_id() Signed-off-by: Sakari Ailus [laurent.pinchart@ideasonboard Clarify documentation] Signed-off-by: Laurent Pinchart --- src/mediactl.c | 7 ++++++- src/mediactl.h | 6 +++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/mediactl.c b/src/mediactl.c index bc6a713..14cff30 100644 --- a/src/mediactl.c +++ b/src/mediactl.c @@ -26,6 +26,7 @@ #include #include +#include #include #include #include @@ -83,12 +84,16 @@ struct media_entity *media_get_entity_by_name(struct media_device *media, struct media_entity *media_get_entity_by_id(struct media_device *media, __u32 id) { + bool next = id & MEDIA_ENT_ID_FLAG_NEXT; unsigned int i; + id &= ~MEDIA_ENT_ID_FLAG_NEXT; + for (i = 0; i < media->entities_count; ++i) { struct media_entity *entity = &media->entities[i]; - if (entity->info.id == id) + if ((entity->info.id == id && !next) || + (entity->info.id > id && next)) return entity; } diff --git a/src/mediactl.h b/src/mediactl.h index 1b47b7e..2296fe2 100644 --- a/src/mediactl.h +++ b/src/mediactl.h @@ -164,7 +164,11 @@ struct media_entity *media_get_entity_by_name(struct media_device *media, * @param media - media device. * @param id - entity ID. * - * Search for an entity with an ID equal to @a id. + * This function searches for an entity based on its ID using an exact match or + * next ID method based on the given @a id. If @a id is ORed with + * MEDIA_ENT_ID_FLAG_NEXT, the function will return the entity with the smallest + * ID larger than @a id. Otherwise it will return the entity with an ID equal to + * @a id. * * @return A pointer to the entity if found, or NULL otherwise. */ -- cgit v1.2.3