From 87f8fa282d76da55fe61651a5ee49a29632e9d7c Mon Sep 17 00:00:00 2001 From: Andriy Tryshnivskyy Date: Mon, 7 Jun 2021 13:56:05 +0300 Subject: binding iiodevices: Change subscribe to scan all devices. It fixes a problem when there are several devices with the same event, but not all devices are available on system. Previously, service did not check all devices and returned error on first not available device. Bug-AGL: SPEC-3865 Change-Id: I91e38dc31824c3956829180569ad819b27da6b6c Signed-off-by: Andriy Tryshnivskyy --- binding/iiodevices-binding.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/binding/iiodevices-binding.c b/binding/iiodevices-binding.c index 000191e..d2d1ae4 100644 --- a/binding/iiodevices-binding.c +++ b/binding/iiodevices-binding.c @@ -550,10 +550,11 @@ static void subscribe(afb_req_t request) AFB_API_INFO(afbBindingV3root, "subscription with: value=%s, s_iioelts=%s, freq=%s", value, s_iioelts, freq); - bool found = false; + bool found_event = false; + bool found_device = false; for(int i = 0; i < sizeof(iio_infos)/sizeof(iio_infos[0]); i++) { if(!strcasecmp(value, iio_infos[i].id)) { - found = true; + found_event = true; uint64_t u_period = get_period(freq); enum iio_elements iioelts = (int)treat_iio_elts(s_iioelts); @@ -568,9 +569,8 @@ static void subscribe(afb_req_t request) client = add_new_client(&iio_infos[i], iioelts, u_period); init_dev(client); if(!client->dev) { - afb_req_fail_f(request, "failed", "No %s device found", client->infos->dev_name); deinit_client_sub(client); - return; + continue; } init_channel(client, iioelts); if(!client->channels) { @@ -581,6 +581,7 @@ static void subscribe(afb_req_t request) } else { init_dev(client); } + found_device = true; //stored client in order to be get in unsubscription afb_req_context_set(request, client, NULL); @@ -592,12 +593,17 @@ static void subscribe(afb_req_t request) afb_req_fail(request, "failed", "subscription failed"); return; } + break; } } - if(!found) { + if(!found_event) { afb_req_fail(request, "failed", "Invalid event"); return; } + if(!found_device) { + afb_req_fail(request, "failed", "No device found"); + return; + } afb_req_success(request, NULL, NULL); } -- cgit 1.2.3-korg