Skip to content

Commit

Permalink
examples: Check the encoded error in returned iio structures
Browse files Browse the repository at this point in the history
Signed-off-by: Dan Nechita <[email protected]>
  • Loading branch information
dNechita committed Jan 9, 2025
1 parent cdc81a9 commit 90bebae
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 10 deletions.
8 changes: 6 additions & 2 deletions examples/ad9361-iiostream.c
Original file line number Diff line number Diff line change
Expand Up @@ -225,10 +225,14 @@ int main (int argc, char **argv)

printf("* Acquiring IIO context\n");
if (argc == 1) {
IIO_ENSURE((ctx = iio_create_context(NULL, NULL)) && "No context");
ctx = iio_create_context(NULL, NULL);
err = iio_err(ctx);
IIO_ENSURE(!err && "No context");
}
else if (argc == 2) {
IIO_ENSURE((ctx = iio_create_context(NULL, argv[1])) && "No context");
ctx = iio_create_context(NULL, argv[1]);
err = iio_err(ctx);
IIO_ENSURE(!err && "No context");
}
IIO_ENSURE(iio_context_get_devices_count(ctx) > 0 && "No devices");

Expand Down
5 changes: 4 additions & 1 deletion examples/ad9371-iiostream.c
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,10 @@ int main (__notused int argc, __notused char **argv)
txcfg.lo_hz = GHZ(2.5); // 2.5 GHz rf frequency

printf("* Acquiring IIO context\n");
IIO_ENSURE((ctx = iio_create_context(NULL, NULL)) && "No context");

ctx = iio_create_context(NULL, NULL);
err = iio_err(ctx);
IIO_ENSURE(!err && "No context");
IIO_ENSURE(iio_context_get_devices_count(ctx) > 0 && "No devices");

printf("* Acquiring AD9371 streaming devices\n");
Expand Down
4 changes: 3 additions & 1 deletion examples/adrv9002-iiostream.c
Original file line number Diff line number Diff line change
Expand Up @@ -226,12 +226,14 @@ int main(void)
struct iio_device *rx;
size_t tx_sample_sz, rx_sample_sz;
int ret = EXIT_FAILURE;
int err;

if (register_signals() < 0)
return EXIT_FAILURE;

ctx = iio_create_context(NULL, NULL);
if (!ctx) {
err = iio_err(ctx);
if (ret) {
error("Could not create IIO context\n");
return EXIT_FAILURE;
}
Expand Down
4 changes: 3 additions & 1 deletion examples/adrv9009-iiostream.c
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,9 @@ int main (__notused int argc, __notused char **argv)
trxcfg.lo_hz = GHZ(2.5);

printf("* Acquiring IIO context\n");
IIO_ENSURE((ctx = iio_create_context(NULL, NULL)) && "No context");
ctx = iio_create_context(NULL, NULL);
err = iio_err(ctx);
IIO_ENSURE(!err && "No context");
IIO_ENSURE(iio_context_get_devices_count(ctx) > 0 && "No devices");

printf("* Acquiring ADRV9009 streaming devices\n");
Expand Down
4 changes: 3 additions & 1 deletion examples/dummy-iiostream.c
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,9 @@ int main (int argc, char **argv)
has_repeat = ((major * 10000) + minor) >= 8 ? true : false;

printf("* Acquiring IIO context\n");
IIO_ENSURE((ctx = iio_create_context(NULL, NULL)) && "No context");
ctx = iio_create_context(NULL, NULL);
err = iio_err(ctx);
IIO_ENSURE(!err && "No context");
IIO_ENSURE(iio_context_get_devices_count(ctx) > 0 && "No devices");

printf("* Acquiring device %s\n", name);
Expand Down
10 changes: 6 additions & 4 deletions examples/iio-monitor.c
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ static struct iio_context *show_contexts_screen(void)
int i;
bool free_uri;
char **items;
int ret;
int ret, err;

screen = initCDKScreen(win);
if (!screen) {
Expand All @@ -261,7 +261,8 @@ static struct iio_context *show_contexts_screen(void)

do {
scan_ctx = iio_scan(NULL, NULL);
if (!scan_ctx)
err = iio_err(scan_ctx);
if (err)
break;

num_contexts = iio_scan_get_results_count(scan_ctx);
Expand Down Expand Up @@ -311,7 +312,8 @@ static struct iio_context *show_contexts_screen(void)

if (uri) {
ctx = iio_create_context(NULL, uri);
if (ctx == NULL) {
err = iio_err(ctx);
if (err) {
char *msg[] = { "</16>Failed to create IIO context.<!16>" };
popupLabel(screen, (CDK_CSTRING2)msg, 1);
}
Expand All @@ -326,7 +328,7 @@ static struct iio_context *show_contexts_screen(void)
free(items[i]);
free(items);

} while (!ctx && ret >= 0);
} while (err && ret >= 0);

destroyCDKScreen(screen);

Expand Down

0 comments on commit 90bebae

Please sign in to comment.