summaryrefslogtreecommitdiffstats
path: root/binding/iiodevices-binding.c
diff options
context:
space:
mode:
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);
}