diff options
Diffstat (limited to 'lib/4a-hal-utilities/4a-hal-utilities-data.c')
-rw-r--r-- | lib/4a-hal-utilities/4a-hal-utilities-data.c | 171 |
1 files changed, 52 insertions, 119 deletions
diff --git a/lib/4a-hal-utilities/4a-hal-utilities-data.c b/lib/4a-hal-utilities/4a-hal-utilities-data.c index 98e3fa0..979f46d 100644 --- a/lib/4a-hal-utilities/4a-hal-utilities-data.c +++ b/lib/4a-hal-utilities/4a-hal-utilities-data.c @@ -33,6 +33,7 @@ void HalUtlFreeSelectedProbedDeviceAllocation(struct InternalHalProbedDevice *probedDeviceToFree); void HalUtlFreeSelectedMixerDataAllocation(struct InternalHalMixerData *mixerDataToFree); +void HalUtlFreeSelectedHalAllocation(struct HalData *halDataToFree); /******************************************************************************* * Internal Hal - Generic function for linked list * @@ -61,6 +62,13 @@ void *HalUtlAddNodeInList(struct cds_list_head *listHead, enum LinkedListType li nodeToAdd = &((struct InternalHalMixerData *) returned)->node; break; + case LINKED_LIST_FOR_HAL_DATA: + returned = calloc(1, sizeof(struct HalData)); + if(! returned) + return NULL; + nodeToAdd = &((struct HalData *) returned)->node; + break; + default: return NULL; } @@ -88,6 +96,12 @@ int HalUtlRemoveNodeFromList(struct cds_list_head *listHead, void *dataToRemove, HalUtlFreeSelectedMixerDataAllocation((struct InternalHalMixerData *) dataToRemove); break; + case LINKED_LIST_FOR_HAL_DATA: + cds_list_del(&((struct HalData *) dataToRemove)->node); + + HalUtlFreeSelectedHalAllocation((struct HalData *) dataToRemove); + break; + default: return -2; } @@ -121,8 +135,14 @@ int HalUtlRemoveAllNodeFromList(struct cds_list_head *listHead, enum LinkedListT return -3; break; + case LINKED_LIST_FOR_HAL_DATA: + if(HalUtlRemoveSelectedHalFromList(listHead, + cds_list_entry(nodeToRemove, struct HalData, node))) + return -4; + break; + default: - return -4; + return -5; } nodesRemoved++; @@ -745,150 +765,64 @@ json_object *HalUtlGetJsonArrayForAllMixersData(afb_api_t apiHandle, struct cds_ * Hal data handling functions * ******************************************************************************/ -struct HalData *HalUtlAddHalToHalList(struct HalData **halDataList) +void HalUtlFreeSelectedHalAllocation(struct HalData *halDataToFree) { - struct HalData *currentHalData; + if(! halDataToFree) + return; - if(! halDataList) - return NULL; + free(halDataToFree->apiName); + free(halDataToFree->sndCardPath); + free(halDataToFree->info); + free(halDataToFree->author); + free(halDataToFree->version); + free(halDataToFree->date); - currentHalData = *halDataList; - if(! currentHalData) { - currentHalData = (struct HalData *) calloc(1, sizeof(struct HalData)); - if(! currentHalData) - return NULL; + if(halDataToFree->internal) { + free(halDataToFree->internalHalData->mixerApiName); + free(halDataToFree->internalHalData->prefix); - *halDataList = currentHalData; - } - else { - while(currentHalData->next) - currentHalData = currentHalData->next; + HalUtlRemoveAllProbedDevicesFromList(&halDataToFree->internalHalData->probedDevicesListHead); - currentHalData->next = calloc(1, sizeof(struct HalData)); - if(! currentHalData->next) - return NULL; + HalUtlRemoveAllMixerData(&halDataToFree->internalHalData->streamsDataListHead); - currentHalData = currentHalData->next; + HalUtlFreeAlsaCtlsMap(halDataToFree->internalHalData->alsaMapT); + + free(halDataToFree->internalHalData); } - return currentHalData; + free(halDataToFree); } -int HalUtlRemoveSelectedHalFromList(struct HalData **halDataList, struct HalData *halToRemove) +struct HalData *HalUtlAddHalToHalList(struct cds_list_head *halDataListHead) { - struct HalData *currentHalData, *matchingHal; - - if(! halDataList || ! *halDataList || ! halToRemove) - return -1; - - currentHalData = *halDataList; - if(currentHalData == halToRemove) { - *halDataList = currentHalData->next; - matchingHal = currentHalData; - } - else { - while(currentHalData && currentHalData->next != halToRemove) - currentHalData = currentHalData->next; - - if(currentHalData) { - matchingHal = currentHalData->next; - currentHalData->next = currentHalData->next->next; - } - else { - return -2; - } - } - - free(matchingHal->apiName); - free(matchingHal->sndCardPath); - free(matchingHal->info); - free(matchingHal->author); - free(matchingHal->version); - free(matchingHal->date); - - if(matchingHal->internal) { - free(matchingHal->internalHalData->mixerApiName); - free(matchingHal->internalHalData->prefix); - - HalUtlRemoveAllProbedDevicesFromList(&matchingHal->internalHalData->probedDevicesListHead); - - HalUtlRemoveAllMixerData(&matchingHal->internalHalData->streamsDataListHead); - - HalUtlFreeAlsaCtlsMap(matchingHal->internalHalData->alsaMapT); - - free(matchingHal->internalHalData); - } - - free(matchingHal); - - return 0; + return (struct HalData *) HalUtlAddNodeInList(halDataListHead, LINKED_LIST_FOR_HAL_DATA); } -int HalUtlRemoveAllHalFromList(struct HalData **halDataList) +int HalUtlRemoveSelectedHalFromList(struct cds_list_head *halDataListHead, struct HalData *halToRemove) { - int halRemoved = 0; - - if(! halDataList) - return -1; - - while(*halDataList) { - if(HalUtlRemoveSelectedHalFromList(halDataList, *halDataList)) - return -2; - - halRemoved++; - } - - return halRemoved; + return HalUtlRemoveNodeFromList(halDataListHead, (void *) halToRemove, LINKED_LIST_FOR_HAL_DATA); } -int HalUtlGetNumberOfHalInList(struct HalData **halDataList) +int HalUtlRemoveAllHalFromList(struct cds_list_head *halDataListHead) { - int numberOfHal = 0; - struct HalData *currentHalData; - - if(! halDataList) - return -1; - - currentHalData = *halDataList; - while(currentHalData) { - currentHalData = currentHalData->next; - numberOfHal++; - } - - return numberOfHal; + return HalUtlRemoveAllNodeFromList(halDataListHead, LINKED_LIST_FOR_HAL_DATA); } -struct HalData *HalUtlSearchHalDataByApiName(struct HalData **halDataList, char *apiName) +int HalUtlGetNumberOfHalInList(struct cds_list_head *halDataListHead) { - struct HalData *currentHalData; - - if(! halDataList || ! *halDataList || ! apiName) - return NULL; - - currentHalData = *halDataList; - while(currentHalData) { - if(! strcmp(apiName, currentHalData->apiName)) - return currentHalData; - - currentHalData = currentHalData->next; - } - - return NULL; + return HalUtlGetNumberOfNodesInList(halDataListHead); } -struct HalData *HalUtlSearchReadyHalDataByCardId(struct HalData **halDataList, int cardId) +struct HalData *HalUtlSearchHalDataByApiName(struct cds_list_head *halDataListHead, char *apiName) { struct HalData *currentHalData; - if(! halDataList || ! *halDataList) + if(! halDataListHead || cds_list_empty(halDataListHead) || ! apiName) return NULL; - currentHalData = *halDataList; - while(currentHalData) { - if(currentHalData->status == HAL_STATUS_READY && currentHalData->sndCardId == cardId) + cds_list_for_each_entry(currentHalData, halDataListHead, node) { + if(! strcmp(apiName, currentHalData->apiName)) return currentHalData; - - currentHalData = currentHalData->next; } return NULL; @@ -922,8 +856,7 @@ void HalUtlRemoveHalMgrData(struct HalMgrData *halMgrData) if(! halMgrData) return; - if(halMgrData->halDataList) - HalUtlRemoveAllHalFromList(&halMgrData->halDataList); + HalUtlRemoveAllHalFromList(&halMgrData->halDataListHead); free(halMgrData->apiName); free(halMgrData->info); |