From 48566a4a32585d80e9f5f09be7e10b075d9d1e27 Mon Sep 17 00:00:00 2001 From: Jonathan Aillet Date: Tue, 29 May 2018 14:20:16 +0200 Subject: Handle stream calls to transfer to mixer api Implementation of the function that transfer hal streams calls to mixer api. Change-Id: Icded7e160a1cfbe794c5fa2695bf0f9f54c80a06 Signed-off-by: Jonathan Aillet --- 4a-hal/4a-hal-controllers/4a-hal-controllers-cb.c | 70 ++++++++++++++++++++++- 4a-hal/4a-hal-controllers/4a-hal-controllers-cb.h | 3 +- 2 files changed, 70 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 d74abf0..9e74f8c 100644 --- a/4a-hal/4a-hal-controllers/4a-hal-controllers-cb.c +++ b/4a-hal/4a-hal-controllers/4a-hal-controllers-cb.c @@ -119,9 +119,75 @@ int HalCtlsHalMixerConfig(afb_dynapi *apiHandle, CtlSectionT *section, json_obje // TODO JAI : to implement void HalCtlsActionOnStream(afb_request *request) { - AFB_REQUEST_WARNING(request, "JAI :%s not implemented yet", __func__); + int verbToCallSize; - afb_request_success(request, json_object_new_boolean(false), NULL); + char *apiToCall, *verbToCall; + + afb_dynapi *apiHandle; + CtlConfigT *ctrlConfig; + + struct SpecificHalData *currentCtlHalData; + + json_object *requestJson, *returnJ, *toReturnJ; + + 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; + } + + requestJson = afb_request_json(request); + if(! requestJson) { + afb_request_fail(request, "request_json", "Can't get request json"); + return; + } + + apiToCall = currentCtlHalData->ctlHalSpecificData->mixerApiName; + if(! apiToCall) { + afb_request_fail(request, "mixer_api", "Can't get mixer api"); + return; + } + + // TODO JAI: check status of hal before doing anything + + // TODO JAI : remove action prefix, streams should be created as verb by mixer + verbToCallSize = (int) strlen(API_STREAM_PREFIX) + (int) strlen(request->verb) + 2; + verbToCall = (char *) alloca(verbToCallSize * sizeof(char)); + verbToCall[0] = '\0'; + verbToCall[verbToCallSize - 1] = '\0'; + + strcat(verbToCall, API_STREAM_PREFIX); + strcat(verbToCall, "/"); + strcat(verbToCall, request->verb); + + if(afb_dynapi_call_sync(apiHandle, apiToCall, verbToCall, json_object_get(requestJson), &returnJ)) { + afb_request_fail_f(request, "action", "Action %s seemingly not correctly transfered to %s", + verbToCall, + apiToCall); + + } + else if(json_object_object_get_ex(returnJ, "response", &toReturnJ)){ + afb_request_success_f(request, toReturnJ, "Action %s correctly transfered to %s, and successfull", + verbToCall, + apiToCall); + } + else { + afb_request_fail_f(request, "invalid_response", "Action %s correctly transfered to %s, but response is not valid", + verbToCall, + apiToCall); + } } // TODO JAI : to implement diff --git a/4a-hal/4a-hal-controllers/4a-hal-controllers-cb.h b/4a-hal/4a-hal-controllers/4a-hal-controllers-cb.h index 472b643..648c4df 100644 --- a/4a-hal/4a-hal-controllers/4a-hal-controllers-cb.h +++ b/4a-hal/4a-hal-controllers/4a-hal-controllers-cb.h @@ -25,7 +25,8 @@ #include -#define ACTION_API_NAME "4a-softmixer" +// TODO JAI: remove this define +#define API_STREAM_PREFIX "simple_mixer" // HAL controllers sections parsing functions int HalCtlsHalMixerConfig(afb_dynapi *apiHandle, CtlSectionT *section, json_object *MixerJ); -- cgit 1.2.3-korg