From aab7f562b05bc8383b61ce40d8e198c85ea35786 Mon Sep 17 00:00:00 2001 From: Jonathan Aillet Date: Fri, 11 Oct 2019 11:30:09 +0200 Subject: Improve json dependency list generation function Add function to generate json dependency list while indicating which dependency is handled (using dependency 'uid'). Will be useful for mixer calls. BUG-AGL: SPEC-2886 Change-Id: I2d23845af00796d73ce641e8c33a0e880f50c8b3 Signed-off-by: Jonathan Aillet --- lib/4a-hal-utilities/4a-hal-utilities-data.c | 58 ++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) (limited to 'lib/4a-hal-utilities/4a-hal-utilities-data.c') diff --git a/lib/4a-hal-utilities/4a-hal-utilities-data.c b/lib/4a-hal-utilities/4a-hal-utilities-data.c index 888516f..865bebb 100644 --- a/lib/4a-hal-utilities/4a-hal-utilities-data.c +++ b/lib/4a-hal-utilities/4a-hal-utilities-data.c @@ -792,6 +792,64 @@ json_object *HalUtlGetJsonArrayForAllDependencies(afb_api_t apiHandle, return requestedDependenciesInfoJ; } +json_object *HalUtlGetJsonArrayForAllDependenciesInfoWithHandledDependency(afb_api_t apiHandle, + struct cds_list_head *probedDevicesListHead, + enum DependencyInfoJsonFormat jsonFormat, + char *handledProbedDeviceUid) +{ + int err; + size_t idx, dependencyNb; + char *currentDependencyObjectUidString = NULL; + + json_object *requestedDependenciesInfoJ, *currentDependencyObject; + + if(! apiHandle) { + AFB_API_ERROR(apiHandle, "Api handle is not valid"); + return NULL; + } + + if(! probedDevicesListHead) { + AFB_API_ERROR(apiHandle, "Probed device list is not valid"); + return NULL; + } + + if(cds_list_empty(probedDevicesListHead)) { + AFB_API_INFO(apiHandle, "Probed device list is empty"); + return NULL; + } + + if(! handledProbedDeviceUid) { + AFB_API_ERROR(apiHandle, "Probed device uid is not valid"); + return NULL; + } + + requestedDependenciesInfoJ = HalUtlGetJsonArrayForAllDependencies(apiHandle, + probedDevicesListHead, + jsonFormat); + if(! requestedDependenciesInfoJ) { + AFB_API_ERROR(apiHandle, "Didn't succeed get all devices (dependencies) info"); + return NULL; + } + + dependencyNb = json_object_array_length(requestedDependenciesInfoJ); + for(idx = 0; idx < dependencyNb; idx++) { + currentDependencyObject = json_object_array_get_idx(requestedDependenciesInfoJ, idx); + + err = wrap_json_unpack(currentDependencyObject, "{s:s}", "uid", ¤tDependencyObjectUidString); + if(err) { + AFB_API_ERROR(apiHandle, "Dependency object is malformed (no uid key)"); + return NULL; + } + + if(! strcmp(handledProbedDeviceUid, currentDependencyObjectUidString)) + json_object_object_add(currentDependencyObject, "handled", json_object_new_boolean(1)); + else + json_object_object_add(currentDependencyObject, "handled", json_object_new_boolean(0)); + } + + return requestedDependenciesInfoJ; +} + /******************************************************************************* * Internal Hal - Streams data handling functions * ******************************************************************************/ -- cgit 1.2.3-korg