diff options
-rw-r--r-- | lib/4a-hal-utilities/4a-hal-utilities-data.c | 171 | ||||
-rw-r--r-- | lib/4a-hal-utilities/4a-hal-utilities-data.h | 18 | ||||
-rw-r--r-- | src/4a-hal-manager/4a-hal-manager-cb.c | 25 | ||||
-rw-r--r-- | src/4a-hal-manager/4a-hal-manager.c | 7 | ||||
-rw-r--r-- | src/4a-internals-hal/4a-internals-hal-api-loader.c | 2 |
5 files changed, 76 insertions, 147 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); diff --git a/lib/4a-hal-utilities/4a-hal-utilities-data.h b/lib/4a-hal-utilities/4a-hal-utilities-data.h index 8bddbbb..48420cd 100644 --- a/lib/4a-hal-utilities/4a-hal-utilities-data.h +++ b/lib/4a-hal-utilities/4a-hal-utilities-data.h @@ -37,7 +37,8 @@ // Enum for linked list type enum LinkedListType { LINKED_LIST_FOR_DEPENDENCIES_DATA = 0, - LINKED_LIST_FOR_MIXER_DATA = 1 + LINKED_LIST_FOR_MIXER_DATA = 1, + LINKED_LIST_FOR_HAL_DATA = 2 }; // Enum for hal status @@ -138,7 +139,7 @@ struct HalData { struct InternalHalData *internalHalData; // Can be NULL if external api - struct HalData *next; + struct cds_list_head node; }; // Structure to store hal manager data @@ -148,7 +149,7 @@ struct HalMgrData { afb_api_t apiHandle; - struct HalData *halDataList; + struct cds_list_head halDataListHead; }; // Internal Hal - Probed devices structure handling functions @@ -190,12 +191,11 @@ json_object *HalUtlGetJsonArrayForSpecificMixerData(afb_api_t apiHandle, struct json_object *HalUtlGetJsonArrayForAllMixersData(afb_api_t apiHandle, struct cds_list_head *mixerDataListHead); // Hal data handling functions -struct HalData *HalUtlAddHalToHalList(struct HalData **halDataList); -int HalUtlRemoveSelectedHalFromList(struct HalData **halDataList, struct HalData *halToRemove); -int HalUtlRemoveAllHalFromList(struct HalData **halDataList); -int HalUtlGetNumberOfHalInList(struct HalData **halDataList); -struct HalData *HalUtlSearchHalDataByApiName(struct HalData **halDataList, char *apiName); -struct HalData *HalUtlSearchReadyHalDataByCardId(struct HalData **halDataList, int cardId); +struct HalData *HalUtlAddHalToHalList(struct cds_list_head *halDataListHead); +int HalUtlRemoveSelectedHalFromList(struct cds_list_head *halDataListHead, struct HalData *halToRemove); +int HalUtlRemoveAllHalFromList(struct cds_list_head *halDataListHead); +int HalUtlGetNumberOfHalInList(struct cds_list_head *halDataListHead); +struct HalData *HalUtlSearchHalDataByApiName(struct cds_list_head *halDataListHead, char *apiName); // Hal Manager data handling functions int HalUtlInitializeHalMgrData(afb_api_t apiHandle, struct HalMgrData *halMgrData, char *apiName, char *info); diff --git a/src/4a-hal-manager/4a-hal-manager-cb.c b/src/4a-hal-manager/4a-hal-manager-cb.c index 843066b..a726d05 100644 --- a/src/4a-hal-manager/4a-hal-manager-cb.c +++ b/src/4a-hal-manager/4a-hal-manager-cb.c @@ -87,8 +87,7 @@ void HalMgrLoaded(afb_req_t request) return; } - currentHalData = halMgrData->halDataList; - if(! currentHalData) { + if(cds_list_empty(&halMgrData->halDataListHead)) { afb_req_success(request, NULL, "No Hal Api loaded"); return; } @@ -107,7 +106,7 @@ void HalMgrLoaded(afb_req_t request) else requestJsonErr = wrap_json_unpack(requestJson, "{s?:b s?:b}", "all", &allHal, "verbose", &verbose); - while(currentHalData) { + cds_list_for_each_entry(currentHalData, &halMgrData->halDataListHead, node) { if(allHal || currentHalData->status == HAL_STATUS_READY) { // Case if request key is 'verbose' and value is bigger than 0 if(! requestJsonErr && verbose) { @@ -151,8 +150,6 @@ void HalMgrLoaded(afb_req_t request) json_object_array_add(requestAnswer, apiRequestedInfoJ); } - - currentHalData = currentHalData->next; } afb_req_success(request, requestAnswer, "Requested data"); @@ -206,7 +203,7 @@ void HalMgrLoad(afb_req_t request) return; } - addedHal = HalUtlAddHalToHalList(&halMgrData->halDataList); + addedHal = HalUtlAddHalToHalList(&halMgrData->halDataListHead); addedHal->internal = 0; // TBD JAI : initialize external to unavailable once event from external hal will be handled @@ -217,7 +214,7 @@ void HalMgrLoad(afb_req_t request) afb_req_fail(request, "apiname_string_allocation", "Didn't succeed to store (allocate) 'apiName' string"); - HalUtlRemoveSelectedHalFromList(&halMgrData->halDataList, addedHal); + HalUtlRemoveSelectedHalFromList(&halMgrData->halDataListHead, addedHal); return; } @@ -226,7 +223,7 @@ void HalMgrLoad(afb_req_t request) afb_req_fail(request, "sndcardpath_string_allocation", "Didn't succeed to store (allocate) 'sndCardPath' string"); - HalUtlRemoveSelectedHalFromList(&halMgrData->halDataList, addedHal); + HalUtlRemoveSelectedHalFromList(&halMgrData->halDataListHead, addedHal); return; } @@ -236,7 +233,7 @@ void HalMgrLoad(afb_req_t request) afb_req_fail(request, "info_string_allocation", "Didn't succeed to store (allocate) 'info' string"); - HalUtlRemoveSelectedHalFromList(&halMgrData->halDataList, addedHal); + HalUtlRemoveSelectedHalFromList(&halMgrData->halDataListHead, addedHal); return; } } @@ -247,7 +244,7 @@ void HalMgrLoad(afb_req_t request) afb_req_fail(request, "author_string_allocation", "Didn't succeed to store (allocate) 'author' string"); - HalUtlRemoveSelectedHalFromList(&halMgrData->halDataList, addedHal); + HalUtlRemoveSelectedHalFromList(&halMgrData->halDataListHead, addedHal); return; } } @@ -258,7 +255,7 @@ void HalMgrLoad(afb_req_t request) afb_req_fail(request, "version_string_allocation", "Didn't succeed to store (allocate) 'version' string"); - HalUtlRemoveSelectedHalFromList(&halMgrData->halDataList, addedHal); + HalUtlRemoveSelectedHalFromList(&halMgrData->halDataListHead, addedHal); return; } } @@ -269,7 +266,7 @@ void HalMgrLoad(afb_req_t request) afb_req_fail(request, "date_string_allocation", "Didn't succeed to store (allocate) 'date' string"); - HalUtlRemoveSelectedHalFromList(&halMgrData->halDataList, addedHal); + HalUtlRemoveSelectedHalFromList(&halMgrData->halDataListHead, addedHal); return; } } @@ -314,7 +311,7 @@ void HalMgrUnload(afb_req_t request) return; } - halToRemove = HalUtlSearchHalDataByApiName(&halMgrData->halDataList, apiName); + halToRemove = HalUtlSearchHalDataByApiName(&halMgrData->halDataListHead, apiName); if(! halToRemove) { afb_req_fail(request, "requested_api", "Can't find api to remove"); return; @@ -325,7 +322,7 @@ void HalMgrUnload(afb_req_t request) return; } - if(HalUtlRemoveSelectedHalFromList(&halMgrData->halDataList, halToRemove)) { + if(HalUtlRemoveSelectedHalFromList(&halMgrData->halDataListHead, halToRemove)) { afb_req_fail(request, "unregister_error", "Didn't succeed to remove specified api"); return; } diff --git a/src/4a-hal-manager/4a-hal-manager.c b/src/4a-hal-manager/4a-hal-manager.c index cd6f981..383b920 100644 --- a/src/4a-hal-manager/4a-hal-manager.c +++ b/src/4a-hal-manager/4a-hal-manager.c @@ -66,14 +66,11 @@ static int HalMgrInitApi(afb_api_t apiHandle) if(HalUtlInitializeHalMgrData(apiHandle, halMgrData, HAL_MANAGER_API_NAME, HAL_MANAGER_API_INFO)) return -3; - currentHalData = halMgrData->halDataList; - while(currentHalData) { + cds_list_for_each_entry(currentHalData, &halMgrData->halDataListHead, node) { if(! currentHalData->apiName) return -4; else if(afb_api_require_api(apiHandle, currentHalData->apiName, 1)) return -5; - - currentHalData = currentHalData->next; } return 0; @@ -134,6 +131,8 @@ int afbBindingEntry(afb_api_t apiHandle) if(! halMgrData) return -2; + CDS_INIT_LIST_HEAD(&halMgrData->halDataListHead); + // Load Hal-Manager using Api v3 if(HalMgrCreateApi(apiHandle, halMgrData)) return -3; diff --git a/src/4a-internals-hal/4a-internals-hal-api-loader.c b/src/4a-internals-hal/4a-internals-hal-api-loader.c index bbe4936..6f09d4a 100644 --- a/src/4a-internals-hal/4a-internals-hal-api-loader.c +++ b/src/4a-internals-hal/4a-internals-hal-api-loader.c @@ -193,7 +193,7 @@ int InternalHalCreateApi(afb_api_t apiHandle, char *path, struct HalMgrData *hal } // Allocation of current internal hal data - currentHalData = HalUtlAddHalToHalList(&halMgrData->halDataList); + currentHalData = HalUtlAddHalToHalList(&halMgrData->halDataListHead); if(! currentHalData) { AFB_API_ERROR(apiHandle, "Didn't succeed to add hal to hal list"); return -4; |