aboutsummaryrefslogtreecommitdiffstats
path: root/binding/iiodevices-binding.c
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-07-27 09:19:58 +0000
commit87f8fa282d76da55fe61651a5ee49a29632e9d7c (patch)
treed85a6d2199c8400192125f4fab479c7978e1961a /binding/iiodevices-binding.c
parentf4240dafa9d5afd446aea3a70a4ea082f6ed2420 (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>
Diffstat (limited to 'binding/iiodevices-binding.c')
-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);
}