aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorClément Bénier <clement.benier@iot.bzh>2018-10-09 11:52:39 +0200
committerClément Bénier <clement.benier@iot.bzh>2018-10-12 18:27:24 +0200
commit731d7a904db900b7dc36ed9f5f3771653e67f41b (patch)
treec93ff19de293685b42d669b8806b05751b398f0a
parente240ef90ac31d1be85c528ab26646a1f6a7543be (diff)
set_channel: no next channel when it doesn't exist
in set_channel, when channel does not exist, next_channel has to be set to NULL Change-Id: I512691126200b2a1cc5041b1d2855087b8da1895 Signed-off-by: Clément Bénier <clement.benier@iot.bzh>
-rw-r--r--binding/iiodevices-binding.c23
-rw-r--r--test/afb-test/tests/iiodevices_BasicAPITest-devices.lua3
2 files changed, 23 insertions, 3 deletions
diff --git a/binding/iiodevices-binding.c b/binding/iiodevices-binding.c
index affd4b9..9b4b60d 100644
--- a/binding/iiodevices-binding.c
+++ b/binding/iiodevices-binding.c
@@ -162,7 +162,7 @@ static void init_dev(struct client_sub *client)
static int read_infos(struct client_sub* client)
{
if(!client || !client->channels || !client->channels->chn) {
- AFB_ERROR("client=%p or client->channels=%p or client->channels->chn=%p is null", client, client->channels, client->channels->chn);
+ AFB_ERROR("client or client->channels or client->channels->chn is null");
return -1;
}
json_object *jobject = NULL;
@@ -369,6 +369,10 @@ static void init_event_io(struct client_sub *client)
AFB_ERROR("client is null");
return;
}
+ if(!client->channels) {
+ AFB_ERROR("channel is null");
+ return;
+ }
read_infos(client); //get unchanged infos
sd_event_source *source = NULL;
if(client->u_period <= 0) { //no given frequency
@@ -409,7 +413,9 @@ static struct channels* set_channel(
if(!(chn->chn = iio_device_find_channel(client->dev, chn->name, false))) {
AFB_ERROR("cannot find %s channel", chn->name);
- return NULL;
+ free(chn);
+ prev_chn->next = NULL;
+ return prev_chn;
}
iio_channel_enable(chn->chn);
return chn;
@@ -530,13 +536,26 @@ static void subscribe(struct afb_req request)
uint64_t u_period = get_period(freq);
enum iio_elements iioelts = (int)treat_iio_elts(s_iioelts);
+ if(iioelts == 0){
+ afb_req_fail(request, "failed", "wrong args");
+ return;
+ }
struct client_sub* client = is_new_client_sub_needed(&iio_infos[i],
u_period, &iioelts);
if(!client || iioelts > 0) { //no client found or new channels
if(!client)
client = add_new_client(&iio_infos[i], iioelts, u_period);
init_dev(client);
+ if(!client->dev) {
+ deinit_client_sub(client);
+ afb_req_fail_f(request, "failed", "No %s device found", client->infos->dev_name);
+ return;
+ }
init_channel(client, iioelts);
+ if(!client->channels) {
+ afb_req_fail(request, "failed", "No channels found");
+ return;
+ }
init_event_io(client);
}
//stored client in order to be get in unsubscription
diff --git a/test/afb-test/tests/iiodevices_BasicAPITest-devices.lua b/test/afb-test/tests/iiodevices_BasicAPITest-devices.lua
index e46428a..f2e9cc4 100644
--- a/test/afb-test/tests/iiodevices_BasicAPITest-devices.lua
+++ b/test/afb-test/tests/iiodevices_BasicAPITest-devices.lua
@@ -21,10 +21,11 @@
local testPrefix ="iiodevices_BasicAPITest_without_devices_"
-- This tests the 'subscribe' verb of the iiodevices API without any devices
-_AFT.testVerbStatusError(testPrefix.."subscribe-acceleration","iiodevices","subscribe", {event = "acceleration", args = "xy"})
_AFT.testVerbStatusError(testPrefix.."subscribe-compass","iiodevices","subscribe", {event = "compass", args = "xy"})
_AFT.testVerbStatusError(testPrefix.."subscribe-gyroscope","iiodevices","subscribe", {event = "gyroscope", args = "xy"})
+_AFT.testVerbStatusError(testPrefix.."subscribe-acceleration","iiodevices","subscribe", {event = "acceleration", args = "abc"})
+_AFT.testVerbStatusError(testPrefix.."subscribe-acceleration-with-wrong-argument","iiodevices","subscribe", {event = "acceleration", args = "abc"})
_AFT.testVerbStatusError(testPrefix.."subscribe-acceleration-with-wrong-argument","iiodevices","subscribe", {event = "acceleration", aaaaaaaaaaaaaaaaaaaaa = "xy"})
_AFT.testVerbStatusError(testPrefix.."subscribe-compass-with-wrong-argument","iiodevices","subscribe", {event = "compass", bbbbbbbbbbbbbbbb = "xy"})
_AFT.testVerbStatusError(testPrefix.."subscribe-gyroscope-with-wrong-argument","iiodevices","subscribe", {event = "gyroscope", cccccccccccccccccc = "xy"})