aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJonathan Aillet <jonathan.aillet@iot.bzh>2019-04-18 11:52:44 +0200
committerJonathan Aillet <jonathan.aillet@iot.bzh>2019-05-24 16:35:06 +0200
commit95e6e5e48296b9fc5e5ded973db125ca34d673c8 (patch)
treedd282ec726f3c36705c269eaa59a6243ef22ce53
parent907e2005ef3c7dcb5cf39c2f157d59fdf8685708 (diff)
Add functions to handle 'haldependencies'
Add functions to handle new 'haldependencies' section. This new section will be used to probe for multiple audio device using only one hal. Each probed device could be 'mandatory', 'dynamic' (optional but periodically probed), or 'static' (optional and probed only at startup). The result of handling this section will be used by softmixer and in 'halmap' section. BUG-AGL: SPEC-2329 Change-Id: Ib763b86c0f306abba7a886f5a348d5414ab5e88d Signed-off-by: Jonathan Aillet <jonathan.aillet@iot.bzh>
-rw-r--r--src/4a-internals-hal/4a-internals-hal-cb.c182
1 files changed, 182 insertions, 0 deletions
diff --git a/src/4a-internals-hal/4a-internals-hal-cb.c b/src/4a-internals-hal/4a-internals-hal-cb.c
index d0e4909..f0becf5 100644
--- a/src/4a-internals-hal/4a-internals-hal-cb.c
+++ b/src/4a-internals-hal/4a-internals-hal-cb.c
@@ -773,6 +773,188 @@ int InternalHalProcessAllHalDependencies(afb_api_t apiHandle, json_object *Depen
return 0;
}
+int InternalHalHandleInfoGetResponse(afb_api_t apiHandle, json_object *currentResponseJ, struct InternalHalDeviceData **halDeviceDataToFill)
+{
+ int idx, arraySize, ret = 0;
+
+ struct InternalHalDeviceData *currentProbedDeviceData, *previouslyObtainedDevice;
+
+ if(! apiHandle || ! currentResponseJ || ! halDeviceDataToFill) {
+ AFB_API_ERROR(apiHandle, "Invalid argument(s)");
+ return -1;
+ }
+
+ switch(json_object_get_type(currentResponseJ)) {
+ case json_type_object:
+ currentProbedDeviceData = HalUtlAllocateAndFillProbedDeviceDataUsingInfoGetResponse(currentResponseJ);
+ if(! currentProbedDeviceData) {
+ AFB_API_ERROR(apiHandle, "Unable to decode info get response object");
+ return -2;
+ }
+
+ if(! *halDeviceDataToFill) {
+ *halDeviceDataToFill = currentProbedDeviceData;
+ break;
+ }
+
+ previouslyObtainedDevice = *halDeviceDataToFill;
+
+ if(previouslyObtainedDevice->cardNb != currentProbedDeviceData->cardNb ||
+ previouslyObtainedDevice->playbackDeviceNb != currentProbedDeviceData->playbackDeviceNb) {
+ AFB_API_WARNING(apiHandle, "Different audio devices was returned by info get call");
+ free(previouslyObtainedDevice);
+ ret = 1;
+ }
+
+ free(currentProbedDeviceData);
+ break;
+
+ case json_type_array:
+ arraySize = (int) json_object_array_length(currentResponseJ);
+ for(idx = 0; idx < arraySize; idx++) {
+ ret = InternalHalHandleInfoGetResponse(apiHandle,
+ json_object_array_get_idx(currentResponseJ, idx),
+ halDeviceDataToFill);
+ if(ret < 0) {
+ AFB_API_ERROR(apiHandle,
+ "Error %i while handling object %i of array ('%s') when handling info get response",
+ ret,
+ idx,
+ json_object_get_string(currentResponseJ));
+ ret = -3;
+ }
+
+ if(ret)
+ break;
+ }
+ break;
+
+ case json_type_string:
+ if(strcmp(json_object_get_string(currentResponseJ), "sndcard-not-found")) {
+ AFB_API_ERROR(apiHandle,
+ "Unrecognized string '%s' sent back by info get call",
+ json_object_get_string(currentResponseJ));
+ return -4;
+ }
+ break;
+
+ default:
+ AFB_API_ERROR(apiHandle, "Unrecognized info get response format");
+ return -5;
+ }
+
+ return ret;
+}
+
+int InternalHalHandleOneHalDependencies(afb_api_t apiHandle, struct InternalHalProbedDevice **halDeviceToProbe)
+{
+ int ret;
+
+ struct InternalHalProbedDevice *currentDeviceToProbe;
+
+ json_object *probedDeviceGetInfoResponseJ;
+
+ if(! apiHandle || ! halDeviceToProbe || ! *halDeviceToProbe) {
+ AFB_API_ERROR(apiHandle, "Invalid argument(s)");
+ return -1;
+ }
+
+ currentDeviceToProbe = *halDeviceToProbe;
+
+ if(! currentDeviceToProbe->uid ||
+ ! currentDeviceToProbe->requestedDeviceJ) {
+ AFB_API_ERROR(apiHandle, "Specified device to probe is not valid (uid or request is not specified)");
+ return -2;
+ }
+
+ if(! json_object_is_type(currentDeviceToProbe->requestedDeviceJ, json_type_array)) {
+ AFB_API_ERROR(apiHandle, "Device to probe request is not an array");
+ return -3;
+ }
+
+ ret = InternalHalGetCardInfo(apiHandle, json_object_get(currentDeviceToProbe->requestedDeviceJ), &probedDeviceGetInfoResponseJ);
+ if(ret) {
+ AFB_API_ERROR(apiHandle,
+ "Error %i happened when tried to get card information for dependency with uid '%s' (using request : '%s')",
+ ret,
+ currentDeviceToProbe->uid,
+ json_object_get_string(currentDeviceToProbe->requestedDeviceJ));
+ return -4;
+ }
+
+ ret = InternalHalHandleInfoGetResponse(apiHandle, probedDeviceGetInfoResponseJ, &currentDeviceToProbe->deviceData);
+ if(ret < 0) {
+ AFB_API_ERROR(apiHandle,
+ "Error %i happened when tried to handle card get info response for dependency with uid '%s' (using response : '%s')",
+ ret,
+ currentDeviceToProbe->uid,
+ json_object_get_string(probedDeviceGetInfoResponseJ));
+ return -5;
+ }
+
+ if(ret > 0) {
+ AFB_API_WARNING(apiHandle,
+ "Multiple card was found for dependency with uid '%s'(request : '%s', response : '%s')",
+ currentDeviceToProbe->uid,
+ json_object_get_string(currentDeviceToProbe->requestedDeviceJ),
+ json_object_get_string(probedDeviceGetInfoResponseJ));
+ return 1;
+ }
+ else if(! currentDeviceToProbe->deviceData) {
+ AFB_API_INFO(apiHandle,
+ "No card was found for dependency with uid '%s'(request : '%s', response : '%s')",
+ currentDeviceToProbe->uid,
+ json_object_get_string(currentDeviceToProbe->requestedDeviceJ),
+ json_object_get_string(probedDeviceGetInfoResponseJ));
+ return 2;
+ }
+
+ return 0;
+}
+
+int InternalHalHandleAllHalDependencies(afb_api_t apiHandle, struct InternalHalProbedDevice **halDevicesToProbeList)
+{
+ int ret;
+
+ struct InternalHalProbedDevice *halCurrentDeviceToProbe;
+
+ if(! apiHandle || ! halDevicesToProbeList) {
+ AFB_API_ERROR(apiHandle, "Invalid argument(s)");
+ return -1;
+ }
+
+ halCurrentDeviceToProbe = *halDevicesToProbeList;
+ if(! halCurrentDeviceToProbe) {
+ AFB_API_WARNING(apiHandle, "No device to probe in list, 'haldependencies' handling skipped");
+ return 0;
+ }
+
+ while(halCurrentDeviceToProbe) {
+ ret = InternalHalHandleOneHalDependencies(apiHandle, &halCurrentDeviceToProbe);
+ if(ret < 0) {
+ AFB_API_ERROR(apiHandle,
+ "Error %i happened when tried to handle device to probe with uid:'%s' and request:'%s'",
+ ret,
+ halCurrentDeviceToProbe->uid,
+ json_object_get_string(halCurrentDeviceToProbe->requestedDeviceJ));
+ return -2;
+ }
+
+ if(halCurrentDeviceToProbe->deviceClass == MANDATORY_PROBED_DEVICE &&
+ ! halCurrentDeviceToProbe->deviceData) {
+ AFB_API_WARNING(apiHandle,
+ "Mandatory device to probe not found, uid:'%s' and request:'%s'",
+ halCurrentDeviceToProbe->uid,
+ json_object_get_string(halCurrentDeviceToProbe->requestedDeviceJ));
+ return -3;
+ }
+
+ halCurrentDeviceToProbe = halCurrentDeviceToProbe->next;
+ }
+
+ return 0;
+}
+
/*******************************************************************************
* Internals HAL verbs functions *
******************************************************************************/