summaryrefslogtreecommitdiffstats
path: root/lib/4a-hal-utilities/4a-hal-utilities-data.c
diff options
context:
space:
mode:
authorJonathan Aillet <jonathan.aillet@iot.bzh>2019-06-14 18:14:13 +0200
committerJonathan Aillet <jonathan.aillet@iot.bzh>2019-06-18 11:34:58 +0200
commit24046bfdb0568077a074b503d58a343a06f4234a (patch)
tree54ecdea5d0768d3d354a2ddbda1e309d574bbd14 /lib/4a-hal-utilities/4a-hal-utilities-data.c
parent66f27bce6355cc7df978a9d7a6bc725542057a01 (diff)
Refactoring 'streams data' linked list
Refactoring 'streams data' linked list code using liburcu. BUG-AGL: SPEC-2329 Change-Id: Idf9367c015d73574d96d83c82a9e8f5b7588a45d 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.c138
1 files changed, 43 insertions, 95 deletions
diff --git a/lib/4a-hal-utilities/4a-hal-utilities-data.c b/lib/4a-hal-utilities/4a-hal-utilities-data.c
index f3f4229..98e3fa0 100644
--- a/lib/4a-hal-utilities/4a-hal-utilities-data.c
+++ b/lib/4a-hal-utilities/4a-hal-utilities-data.c
@@ -32,6 +32,7 @@
******************************************************************************/
void HalUtlFreeSelectedProbedDeviceAllocation(struct InternalHalProbedDevice *probedDeviceToFree);
+void HalUtlFreeSelectedMixerDataAllocation(struct InternalHalMixerData *mixerDataToFree);
/*******************************************************************************
* Internal Hal - Generic function for linked list *
@@ -53,6 +54,12 @@ void *HalUtlAddNodeInList(struct cds_list_head *listHead, enum LinkedListType li
nodeToAdd = &((struct InternalHalProbedDevice *) returned)->node;
break;
+ case LINKED_LIST_FOR_MIXER_DATA:
+ returned = calloc(1, sizeof(struct InternalHalMixerData));
+ if(! returned)
+ return NULL;
+ nodeToAdd = &((struct InternalHalMixerData *) returned)->node;
+ break;
default:
return NULL;
@@ -75,6 +82,12 @@ int HalUtlRemoveNodeFromList(struct cds_list_head *listHead, void *dataToRemove,
HalUtlFreeSelectedProbedDeviceAllocation((struct InternalHalProbedDevice *) dataToRemove);
break;
+ case LINKED_LIST_FOR_MIXER_DATA:
+ cds_list_del(&((struct InternalHalMixerData *) dataToRemove)->node);
+
+ HalUtlFreeSelectedMixerDataAllocation((struct InternalHalMixerData *) dataToRemove);
+ break;
+
default:
return -2;
}
@@ -102,8 +115,14 @@ int HalUtlRemoveAllNodeFromList(struct cds_list_head *listHead, enum LinkedListT
return -2;
break;
+ case LINKED_LIST_FOR_MIXER_DATA:
+ if(HalUtlRemoveSelectedMixerData(listHead,
+ cds_list_entry(nodeToRemove, struct InternalHalMixerData, node)))
+ return -3;
+ break;
+
default:
- return -3;
+ return -4;
}
nodesRemoved++;
@@ -609,123 +628,55 @@ json_object *HalUtlGetJsonArrayForAllDependencies(afb_api_t apiHandle,
* Internal Hal - Streams data handling functions *
******************************************************************************/
-struct InternalHalMixerData *HalUtlAddMixerDataToMixerDataList(struct InternalHalMixerData **mixerDataList)
+void HalUtlFreeSelectedMixerDataAllocation(struct InternalHalMixerData *mixerDataToFree)
{
- struct InternalHalMixerData *currentMixerData;
-
- if(! mixerDataList)
- return NULL;
-
- currentMixerData = *mixerDataList;
- if(! currentMixerData) {
- currentMixerData = (struct InternalHalMixerData *) calloc(1, sizeof(struct InternalHalMixerData));
- if(! currentMixerData)
- return NULL;
+ if(! mixerDataToFree)
+ return;
- *mixerDataList = currentMixerData;
- }
- else {
- while(currentMixerData->next)
- currentMixerData = currentMixerData->next;
+ free(mixerDataToFree->verb);
+ free(mixerDataToFree->verbToCall);
+ free(mixerDataToFree->streamCardId);
- currentMixerData->next = calloc(1, sizeof(struct InternalHalMixerData));
- if(! currentMixerData->next)
- return NULL;
-
- currentMixerData = currentMixerData->next;
- }
+ free(mixerDataToFree);
+}
- return currentMixerData;
+struct InternalHalMixerData *HalUtlAddMixerDataToMixerDataList(struct cds_list_head *mixerDataListHead)
+{
+ return (struct InternalHalMixerData *) HalUtlAddNodeInList(mixerDataListHead, LINKED_LIST_FOR_MIXER_DATA);
}
-int HalUtlRemoveSelectedMixerData(struct InternalHalMixerData **mixerDataList,
+int HalUtlRemoveSelectedMixerData(struct cds_list_head *mixerDataListHead,
struct InternalHalMixerData *mixerDataToRemove)
{
- struct InternalHalMixerData *currentMixerData, *matchingMixerData;
-
- if(! mixerDataList || ! *mixerDataList || ! mixerDataToRemove)
- return -1;
-
- currentMixerData = *mixerDataList;
- if(currentMixerData == mixerDataToRemove) {
- *mixerDataList = currentMixerData->next;
- matchingMixerData = currentMixerData;
- }
- else {
- while(currentMixerData && currentMixerData->next != mixerDataToRemove)
- currentMixerData = currentMixerData->next;
-
- if(currentMixerData) {
- matchingMixerData = currentMixerData->next;
- currentMixerData->next = currentMixerData->next->next;
- }
- else {
- return -2;
- }
- }
-
- free(matchingMixerData->verb);
- free(matchingMixerData->verbToCall);
- free(matchingMixerData->streamCardId);
-
- free(matchingMixerData);
-
- return 0;
+ return HalUtlRemoveNodeFromList(mixerDataListHead, (void *) mixerDataToRemove, LINKED_LIST_FOR_MIXER_DATA);
}
-int HalUtlRemoveAllMixerData(struct InternalHalMixerData **mixerDataList)
+int HalUtlRemoveAllMixerData(struct cds_list_head *mixerDataListHead)
{
- int mixerDataRemoved = 0;
-
- if(! mixerDataList)
- return -1;
-
- while(*mixerDataList) {
- if(HalUtlRemoveSelectedMixerData(mixerDataList, *mixerDataList))
- return -2;
-
- mixerDataRemoved++;
- }
-
- return mixerDataRemoved;
+ return HalUtlRemoveAllNodeFromList(mixerDataListHead, LINKED_LIST_FOR_MIXER_DATA);
}
-int HalUtlGetNumberOfMixerDataInList(struct InternalHalMixerData **mixerDataList)
+int HalUtlGetNumberOfMixerDataInList(struct cds_list_head *mixerDataListHead)
{
- int numberOfMixerData = 0;
- struct InternalHalMixerData *currentMixerData;
-
- if(! mixerDataList)
- return -1;
-
- currentMixerData = *mixerDataList;
- while(currentMixerData) {
- currentMixerData = currentMixerData->next;
- numberOfMixerData++;
- }
-
- return numberOfMixerData;
+ return HalUtlGetNumberOfNodesInList(mixerDataListHead);
}
-struct InternalHalMixerData *HalUtlSearchMixerDataByProperties(struct InternalHalMixerData **mixerDataList,
+struct InternalHalMixerData *HalUtlSearchMixerDataByProperties(struct cds_list_head *mixerDataListHead,
char *verb,
char *verbToCall,
char *streamCardId)
{
struct InternalHalMixerData *currentMixerData;
- if(! mixerDataList || ! *mixerDataList || ! verb || ! verbToCall)
+ if(! mixerDataListHead || cds_list_empty(mixerDataListHead) || ! verb || ! verbToCall)
return NULL;
- currentMixerData = *mixerDataList;
- while(currentMixerData) {
+ cds_list_for_each_entry(currentMixerData, mixerDataListHead, node) {
if(! strcmp(verb, currentMixerData->verb) &&
! strcmp(verbToCall, currentMixerData->verbToCall) &&
((! streamCardId && ! currentMixerData->streamCardId) ||
(streamCardId && currentMixerData->streamCardId && ! strcmp(streamCardId, currentMixerData->streamCardId))))
return currentMixerData;
-
- currentMixerData = currentMixerData->next;
}
return NULL;
@@ -759,7 +710,7 @@ json_object *HalUtlGetJsonArrayForSpecificMixerData(afb_api_t apiHandle, struct
return currentMixerDataJ;
}
-json_object *HalUtlGetJsonArrayForAllMixersData(afb_api_t apiHandle, struct InternalHalMixerData **mixerDataList)
+json_object *HalUtlGetJsonArrayForAllMixersData(afb_api_t apiHandle, struct cds_list_head *mixerDataListHead)
{
json_object *mixerDataArrayJ, *currentMixerDataJ;
@@ -776,8 +727,7 @@ json_object *HalUtlGetJsonArrayForAllMixersData(afb_api_t apiHandle, struct Inte
return NULL;
}
- currentMixerData = *mixerDataList;
- while(currentMixerData) {
+ cds_list_for_each_entry(currentMixerData, mixerDataListHead, node) {
currentMixerDataJ = HalUtlGetJsonArrayForSpecificMixerData(apiHandle, currentMixerData);
if(! currentMixerDataJ) {
AFB_API_ERROR(apiHandle, "Didn't succeed to generate current mixer data json object");
@@ -786,8 +736,6 @@ json_object *HalUtlGetJsonArrayForAllMixersData(afb_api_t apiHandle, struct Inte
}
json_object_array_add(mixerDataArrayJ, currentMixerDataJ);
-
- currentMixerData = currentMixerData->next;
}
return mixerDataArrayJ;
@@ -864,7 +812,7 @@ int HalUtlRemoveSelectedHalFromList(struct HalData **halDataList, struct HalData
HalUtlRemoveAllProbedDevicesFromList(&matchingHal->internalHalData->probedDevicesListHead);
- HalUtlRemoveAllMixerData(&matchingHal->internalHalData->streamsData);
+ HalUtlRemoveAllMixerData(&matchingHal->internalHalData->streamsDataListHead);
HalUtlFreeAlsaCtlsMap(matchingHal->internalHalData->alsaMapT);