summaryrefslogtreecommitdiffstats
path: root/lib/4a-hal-utilities/4a-hal-utilities-data.c
diff options
context:
space:
mode:
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);