diff options
author | 2018-12-19 12:06:02 +0100 | |
---|---|---|
committer | 2018-12-20 15:18:36 +0100 | |
commit | 5b607a175a5c8ddbbab12b384a6ea9fd02ab0485 (patch) | |
tree | a2428694280780393a2cdf36e58c47dd9c14c7e2 | |
parent | 6426836055fac0e9bcfcfa074a71247215752eae (diff) |
Send back control current values if no request json
Return current ALSA control values if no request json is specified
when calling halmap verbs.
Bug-AGL: SPEC-1313
Change-Id: I74cc03cdcbe975979be4ad2d353ee44cf8cc13ed
Signed-off-by: Jonathan Aillet <jonathan.aillet@iot.bzh>
-rw-r--r-- | 4a-hal/4a-hal-controllers/4a-hal-controllers-alsacore-link.c | 35 |
1 files changed, 31 insertions, 4 deletions
diff --git a/4a-hal/4a-hal-controllers/4a-hal-controllers-alsacore-link.c b/4a-hal/4a-hal-controllers/4a-hal-controllers-alsacore-link.c index e5e2f78..a6ff2c6 100644 --- a/4a-hal/4a-hal-controllers/4a-hal-controllers-alsacore-link.c +++ b/4a-hal/4a-hal-controllers/4a-hal-controllers-alsacore-link.c @@ -488,7 +488,10 @@ void HalCtlsActionOnAlsaCtl(AFB_ReqT request) json_object *requestJson, *valueJ, - *convertedJ; + *convertedJ, + *answerJ, + *previousControlValuesJ, + *normalizedPreviousControlValuesJ; apiHandle = (AFB_ApiT) afb_request_get_dynapi(request); if(! apiHandle) { @@ -524,19 +527,43 @@ void HalCtlsActionOnAlsaCtl(AFB_ReqT request) return; } + snprintf(cardIdString, 6, "hw:%i", currentCtlHalData->sndCardId); + + if(HalCtlsGetAlsaCtlValues(apiHandle, cardIdString, ¤tAlsaCtl->ctl, &previousControlValuesJ)) { + AFB_ReqFailF(request, "previous_values", "Error when trying to get unchanged alsa control values"); + return; + } + else if(HalCtlsConvertJsonValues(apiHandle, + ¤tAlsaCtl->ctl.alsaCtlProperties, + previousControlValuesJ, + &normalizedPreviousControlValuesJ, + CONVERSION_ALSACORE_TO_NORMALIZED)) { + AFB_ReqFailF(request, + "request_json", + "Error when trying to normalize unchanged alsa control values json '%s'", + json_object_get_string(previousControlValuesJ)); + json_object_put(previousControlValuesJ); + return; + } + requestJson = AFB_ReqJson(request); if(! requestJson) { - AFB_ReqFail(request, "request_json", "Can't get request json"); + wrap_json_pack(&answerJ, + "{s:o}", + "current", normalizedPreviousControlValuesJ); + AFB_ReqSuccess(request, answerJ, "Current controls values"); + json_object_put(previousControlValuesJ); return; } + json_object_put(previousControlValuesJ); + json_object_put(normalizedPreviousControlValuesJ); + if(! json_object_is_type(requestJson, json_type_object)) { AFB_ReqFailF(request, "request_json", "Request json is not valid '%s'", json_object_get_string(requestJson)); return; } - snprintf(cardIdString, 6, "hw:%i", currentCtlHalData->sndCardId); - if(wrap_json_unpack(requestJson, "{s:o}", "value", &valueJ)) { AFB_ReqFailF(request, "request_json", "Error when trying to get request value object inside request '%s'", |