summaryrefslogtreecommitdiffstats
path: root/lib/4a-hal-utilities/4a-hal-utilities-data.c
diff options
context:
space:
mode:
authorJonathan Aillet <jonathan.aillet@iot.bzh>2019-04-18 11:42:41 +0200
committerJonathan Aillet <jonathan.aillet@iot.bzh>2019-05-24 16:35:06 +0200
commit95a00389d224939e809f651cb095c3ecbf594c56 (patch)
tree6013a33a0cf17c89b5e7b6a3ce95ee6cdd266e14 /lib/4a-hal-utilities/4a-hal-utilities-data.c
parentfc650808aef4b161490d0997be621f17377be684 (diff)
Add function to handle probed audio device list
Add function to handle probed audio device list. This list will be used to store incoming 'haldependencies' section data. It will also be used to store audio card information resulting from probing requested audio devices specified in 'haldependencies' section. BUG-AGL: SPEC-2329 Change-Id: Iaa9aaba7a01263ca2d17be01c32803702568d614 Signed-off-by: Jonathan Aillet <jonathan.aillet@iot.bzh>
Diffstat (limited to 'lib/4a-hal-utilities/4a-hal-utilities-data.c')
-rw-r--r--lib/4a-hal-utilities/4a-hal-utilities-data.c195
1 files changed, 195 insertions, 0 deletions
diff --git a/lib/4a-hal-utilities/4a-hal-utilities-data.c b/lib/4a-hal-utilities/4a-hal-utilities-data.c
index 10fdf27..5bd6b27 100644
--- a/lib/4a-hal-utilities/4a-hal-utilities-data.c
+++ b/lib/4a-hal-utilities/4a-hal-utilities-data.c
@@ -28,6 +28,199 @@
#include "4a-hal-utilities-alsa-data.h"
/*******************************************************************************
+ * Internal Hal - Probed devices structure handling functions *
+ ******************************************************************************/
+
+enum ProbedDeviceClasses HalUtlGetProbedDeviceClassFromString(char *probedDeviceString)
+{
+ if(! probedDeviceString)
+ return INVALID_PROBED_DEVICE;
+
+ if(! strcasecmp("static", probedDeviceString))
+ return STATIC_PROBED_DEVICE;
+
+ if(! strcasecmp("dynamic", probedDeviceString))
+ return DYNAMIC_PROBED_DEVICE;
+
+ if(! strcasecmp("mandatory", probedDeviceString))
+ return MANDATORY_PROBED_DEVICE;
+
+ return INVALID_PROBED_DEVICE;
+}
+
+struct InternalHalProbedDevice *HalUtlAddProbedDeviceToProbedDeviceList(struct InternalHalProbedDevice **probedDevicesList)
+{
+ struct InternalHalProbedDevice *currentProbedDevice;
+
+ if(! probedDevicesList)
+ return NULL;
+
+ currentProbedDevice = *probedDevicesList;
+ if(! currentProbedDevice) {
+ currentProbedDevice = (struct InternalHalProbedDevice *) calloc(1, sizeof(struct InternalHalProbedDevice));
+ if(! currentProbedDevice)
+ return NULL;
+
+ *probedDevicesList = currentProbedDevice;
+ }
+ else {
+ while(currentProbedDevice->next)
+ currentProbedDevice = currentProbedDevice->next;
+
+ currentProbedDevice->next = calloc(1, sizeof(struct InternalHalProbedDevice));
+ if(! currentProbedDevice->next)
+ return NULL;
+
+ currentProbedDevice = currentProbedDevice->next;
+ }
+
+ return currentProbedDevice;
+}
+
+int HalUtlRemoveSelectedProbedDeviceFromList(struct InternalHalProbedDevice **probedDevicesList, struct InternalHalProbedDevice *probedDeviceToRemove)
+{
+ struct InternalHalProbedDevice *currentProbedDevice, *matchingProbedDevice;
+
+ if(! probedDevicesList || ! *probedDevicesList || ! probedDeviceToRemove)
+ return -1;
+
+ currentProbedDevice = *probedDevicesList;
+ if(currentProbedDevice == probedDeviceToRemove) {
+ *probedDevicesList = currentProbedDevice->next;
+ matchingProbedDevice = currentProbedDevice;
+ }
+ else {
+ while(currentProbedDevice && currentProbedDevice->next != probedDeviceToRemove)
+ currentProbedDevice = currentProbedDevice->next;
+
+ if(currentProbedDevice) {
+ matchingProbedDevice = currentProbedDevice->next;
+ currentProbedDevice->next = currentProbedDevice->next->next;
+ }
+ else {
+ return -2;
+ }
+ }
+
+ free(matchingProbedDevice->uid);
+
+ if(matchingProbedDevice->deviceData) {
+ free(matchingProbedDevice->deviceData->extendedCardNb);
+ free(matchingProbedDevice->deviceData->cardId);
+ free(matchingProbedDevice->deviceData->cardShortName);
+ free(matchingProbedDevice->deviceData->cardLongName);
+ free(matchingProbedDevice->deviceData->cardDriver);
+ free(matchingProbedDevice->deviceData->cardMixerName);
+ free(matchingProbedDevice->deviceData->cardComponents);
+ free(matchingProbedDevice->deviceData->playbackDeviceId);
+ free(matchingProbedDevice->deviceData->playbackDeviceName);
+
+ free(matchingProbedDevice->deviceData);
+ }
+
+ if(matchingProbedDevice->requestedDeviceJ)
+ json_object_put(matchingProbedDevice->requestedDeviceJ);
+
+ free(matchingProbedDevice);
+
+ return 0;
+}
+
+int HalUtlRemoveAllProbedDevicesFromList(struct InternalHalProbedDevice **probedDevicesList)
+{
+ int probedDevicesRemoved = 0;
+
+ if(! probedDevicesList)
+ return -1;
+
+ if(! *probedDevicesList)
+ return 0;
+
+ while(*probedDevicesList) {
+ if(HalUtlRemoveSelectedProbedDeviceFromList(probedDevicesList, *probedDevicesList))
+ return -2;
+
+ probedDevicesRemoved++;
+ }
+
+ return probedDevicesRemoved;
+}
+
+int HalUtlGetNumberOfProbedDevicesInList(struct InternalHalProbedDevice **probedDevicesList)
+{
+ int numberOfProbedDevices = 0;
+ struct InternalHalProbedDevice *currentProbedDevice;
+
+ if(! probedDevicesList)
+ return -1;
+
+ currentProbedDevice = *probedDevicesList;
+ while(currentProbedDevice) {
+ currentProbedDevice = currentProbedDevice->next;
+ numberOfProbedDevices++;
+ }
+
+ return numberOfProbedDevices;
+}
+
+struct InternalHalProbedDevice *HalUtlSearchProbedDeviceDataById(struct InternalHalProbedDevice **probedDevicesList, char *uid)
+{
+ struct InternalHalProbedDevice *currentProbedDevice;
+
+ if(! probedDevicesList || ! *probedDevicesList || ! uid)
+ return NULL;
+
+ currentProbedDevice = *probedDevicesList;
+ while(currentProbedDevice) {
+ if(! strcmp(uid, currentProbedDevice->uid))
+ return currentProbedDevice;
+
+ currentProbedDevice = currentProbedDevice->next;
+ }
+
+ return NULL;
+}
+
+struct InternalHalDeviceData *HalUtlAllocateAndFillProbedDeviceDataUsingInfoGetResponse(json_object *responseJ)
+{
+ struct InternalHalDeviceData *currentProbedDeviceData;
+
+ if(! responseJ)
+ return NULL;
+
+ currentProbedDeviceData = calloc(1, sizeof(struct InternalHalDeviceData));
+ if(! currentProbedDeviceData)
+ return NULL;
+
+ currentProbedDeviceData->cardNb = HAL_UNKNOWN_DEVICE;
+ currentProbedDeviceData->playbackDeviceNb = HAL_UNKNOWN_DEVICE;
+
+ if(wrap_json_unpack(responseJ, "{s:i, s:s, s:s, s:s, s:s, s:s, s:s, s?:i, s?:s, s?:s !}",
+ "cardNb", &currentProbedDeviceData->cardNb,
+ "cardId", &currentProbedDeviceData->cardId,
+ "cardShortName", &currentProbedDeviceData->cardShortName,
+ "cardLongName", &currentProbedDeviceData->cardLongName,
+ "cardDriver", &currentProbedDeviceData->cardDriver,
+ "cardMixerName", &currentProbedDeviceData->cardMixerName,
+ "cardComponents", &currentProbedDeviceData->cardComponents,
+ "playbackDeviceNb", &currentProbedDeviceData->playbackDeviceNb,
+ "playbackDeviceId", &currentProbedDeviceData->playbackDeviceId,
+ "playbackDeviceName", &currentProbedDeviceData->playbackDeviceName) ||
+ currentProbedDeviceData->cardNb == HAL_UNKNOWN_DEVICE ||
+ (currentProbedDeviceData->playbackDeviceNb == HAL_UNKNOWN_DEVICE &&
+ asprintf(&currentProbedDeviceData->extendedCardNb, "hw:%i", currentProbedDeviceData->cardNb) < 0) ||
+ (currentProbedDeviceData->playbackDeviceNb != HAL_UNKNOWN_DEVICE &&
+ asprintf(&currentProbedDeviceData->extendedCardNb, "hw:%i,%i",
+ currentProbedDeviceData->cardNb,
+ currentProbedDeviceData->playbackDeviceNb) < 0)) {
+ free(currentProbedDeviceData);
+ return NULL;
+ }
+
+ return currentProbedDeviceData;
+}
+
+/*******************************************************************************
* Internal Hal - Streams data handling functions *
******************************************************************************/
@@ -217,6 +410,8 @@ int HalUtlRemoveSelectedHalFromList(struct HalData **halDataList, struct HalData
if(matchingHal->internal) {
free(matchingHal->internalHalData->mixerApiName);
free(matchingHal->internalHalData->prefix);
+
+ HalUtlRemoveAllProbedDevicesFromList(&matchingHal->internalHalData->probedDevicesList);
HalUtlRemoveAllMixerData(&matchingHal->internalHalData->streamsData);