summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndriy Tryshnivskyy <andriy.tryshnivskyy@opensynergy.com>2021-06-07 13:56:05 +0300
committerJan-Simon Moeller <jsmoeller@linuxfoundation.org>2021-09-21 15:20:57 +0000
commitf28d172b3b26194f3ea4c5e4482d233f302e1cd3 (patch)
treeea6d52652b390b0b4a45bc1dd3942e0bb30b3c5e
parenta6406ff3b28a897f84fc9057106856ee034230d0 (diff)
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 <andriy.tryshnivskyy@opensynergy.com> (cherry picked from commit 87f8fa282d76da55fe61651a5ee49a29632e9d7c)
-rw-r--r--binding/iiodevices-binding.c16
1 files 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);
}