diff options
author | Jonathan Aillet <jonathan.aillet@iot.bzh> | 2018-05-27 18:25:02 +0200 |
---|---|---|
committer | Jonathan Aillet <jonathan.aillet@iot.bzh> | 2018-10-08 15:51:00 +0200 |
commit | 7ab7a36a9efb931d6864e5cd4bc30fe500740164 (patch) | |
tree | c78f801956278561353b4cfc473c871828fd7dac | |
parent | 6461482c417cff509531e278e89f4c2310ac6007 (diff) |
Implementation of 'list' verb for controller hal
Implementation of function allowing to list streams and
controls of a controller hal.
Change-Id: Ic347dd89dbbf36056b0fc3c5fe25bd111a85f627
Signed-off-by: Jonathan Aillet <jonathan.aillet@iot.bzh>
-rw-r--r-- | 4a-hal/4a-hal-controllers/4a-hal-controllers-cb.c | 61 |
1 files changed, 58 insertions, 3 deletions
diff --git a/4a-hal/4a-hal-controllers/4a-hal-controllers-cb.c b/4a-hal/4a-hal-controllers/4a-hal-controllers-cb.c index 860de62..317f0b3 100644 --- a/4a-hal/4a-hal-controllers/4a-hal-controllers-cb.c +++ b/4a-hal/4a-hal-controllers/4a-hal-controllers-cb.c @@ -195,12 +195,67 @@ void HalCtlsActionOnStream(afb_request *request) } } -// TODO JAI : to implement void HalCtlsListVerbs(afb_request *request) { - AFB_REQUEST_WARNING(request, "JAI :%s not implemented yet", __func__); + unsigned int idx; + + afb_dynapi *apiHandle; + CtlConfigT *ctrlConfig; + + struct SpecificHalData *currentCtlHalData; + + json_object *requestJson, *requestAnswer, *streamsArray, *currentStream; + + apiHandle = (afb_dynapi *) afb_request_get_dynapi(request); + if(! apiHandle) { + afb_request_fail(request, "api_handle", "Can't get current hal controller api handle"); + return; + } + + ctrlConfig = (CtlConfigT *) afb_dynapi_get_userdata(apiHandle); + if(! ctrlConfig) { + afb_request_fail(request, "hal_controller_config", "Can't get current hal controller config"); + return; + } + + currentCtlHalData = ctrlConfig->external; + if(! currentCtlHalData) { + afb_request_fail(request, "hal_controller_data", "Can't get current hal controller data"); + return; + } + + if(! currentCtlHalData->ctlHalSpecificData->ctlHalStreamsData.count) { + afb_request_fail(request, "no_data", "Won't be able to respond, no streams ofound"); + return; + } + + requestJson = afb_request_json(request); + if(! requestJson) { + afb_request_fail(request, "request_json", "Can't get request json"); + return; + } + + streamsArray = json_object_new_array(); + if(! streamsArray) { + afb_request_fail(request, "json_answer", "Can't generate par of json answer"); + return; + } + + for(idx = 0; idx < currentCtlHalData->ctlHalSpecificData->ctlHalStreamsData.count; idx++) { + wrap_json_pack(¤tStream, + "{s:s s:s}", + "name", currentCtlHalData->ctlHalSpecificData->ctlHalStreamsData.data[idx].name, + "cardId", currentCtlHalData->ctlHalSpecificData->ctlHalStreamsData.data[idx].cardId ? + currentCtlHalData->ctlHalSpecificData->ctlHalStreamsData.data[idx].cardId : + ""); + json_object_array_add(streamsArray, currentStream); + } + + // TODO JAI : Check if there is some halmap config controls and add them to the reponse + + wrap_json_pack(&requestAnswer, "{s:o}", "streams", streamsArray); - afb_request_success(request, json_object_new_boolean(false), NULL); + afb_request_success(request, requestAnswer, "Requested data"); } void HalCtlsInitMixer(afb_request *request) |