Skip to content

Commit

Permalink
Enhance iio_context_find_device() to use labels
Browse files Browse the repository at this point in the history
Make iio_context_find_device() able to search not only by ID and name,
but also by label.

Signed-off-by: Paul Cercueil <[email protected]>
  • Loading branch information
pcercuei committed Apr 9, 2021
1 parent 4dfe323 commit bdd9c45
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
3 changes: 2 additions & 1 deletion context.c
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,8 @@ struct iio_device * iio_context_find_device(const struct iio_context *ctx,
for (i = 0; i < ctx->nb_devices; i++) {
struct iio_device *dev = ctx->devices[i];
if (!strcmp(dev->id, name) ||
(dev->name && !strcmp(dev->name, name)))
(dev->label && !strcmp(dev->label, name)) ||
(dev->name && !strcmp(dev->name, name)))
return dev;
}
return NULL;
Expand Down
10 changes: 5 additions & 5 deletions iio.h
Original file line number Diff line number Diff line change
Expand Up @@ -541,13 +541,13 @@ __api __check_ret __pure struct iio_device * iio_context_get_device(
const struct iio_context *ctx, unsigned int index);


/** @brief Try to find a device structure by its name of ID
/** @brief Try to find a device structure by its ID, label or name
* @param ctx A pointer to an iio_context structure
* @param name A NULL-terminated string corresponding to the name or the ID of
* the device to search for
* @param name A NULL-terminated string corresponding to the ID, label or name
* of the device to search for
* @return On success, a pointer to an iio_device structure
* @return If the name or ID does not correspond to any known device, NULL is
* returned */
* @return If the parameter does not correspond to the ID, label or name of
* any known device, NULL is returned */
__api __check_ret __pure struct iio_device * iio_context_find_device(
const struct iio_context *ctx, const char *name);

Expand Down

0 comments on commit bdd9c45

Please sign in to comment.