summaryrefslogtreecommitdiffstats
path: root/4a-hal-utilities
diff options
context:
space:
mode:
authorJonathan Aillet <jonathan.aillet@iot.bzh>2019-03-05 15:47:38 +0100
committerJonathan Aillet <jonathan.aillet@iot.bzh>2019-05-22 16:31:59 +0200
commit196e723e79a1f5eae41cf4a8b1450df0679a4af8 (patch)
tree6f2a37c49e1a4211d6b34a1e1efa586276b68cb1 /4a-hal-utilities
parentbea6bdb2e661b1de821a65e338f57f9e7d2f5c0a (diff)
Clarify use of linked list
Clarify use of linked list by renaming some variables and functions. BUG-AGL: SPEC-2329 Change-Id: I21ada0b2914c99dfeecfcb6b55c8976dee1a0cd7 Signed-off-by: Jonathan Aillet <jonathan.aillet@iot.bzh>
Diffstat (limited to '4a-hal-utilities')
-rw-r--r--4a-hal-utilities/4a-hal-utilities-data.c101
-rw-r--r--4a-hal-utilities/4a-hal-utilities-data.h24
2 files changed, 64 insertions, 61 deletions
diff --git a/4a-hal-utilities/4a-hal-utilities-data.c b/4a-hal-utilities/4a-hal-utilities-data.c
index 51e751f..0790ed3 100644
--- a/4a-hal-utilities/4a-hal-utilities-data.c
+++ b/4a-hal-utilities/4a-hal-utilities-data.c
@@ -28,31 +28,30 @@
#include "4a-hal-utilities-alsa-data.h"
/*******************************************************************************
- * Specfic Hal controller streams data handling functions *
+ * Specfic Hal controller streams data handling functions *
******************************************************************************/
-struct CtlHalMixerData *HalUtlAddMixerDataToMixerDataList(struct CtlHalMixerData **firstMixerData)
+struct CtlHalMixerData *HalUtlAddMixerDataToMixerDataList(struct CtlHalMixerData **mixerDataList)
{
struct CtlHalMixerData *currentMixerData;
- if(! firstMixerData)
+ if(! mixerDataList)
return NULL;
- currentMixerData = *firstMixerData;
-
+ currentMixerData = *mixerDataList;
if(! currentMixerData) {
currentMixerData = (struct CtlHalMixerData *) calloc(1, sizeof(struct CtlHalMixerData));
if(! currentMixerData)
return NULL;
- *firstMixerData = currentMixerData;
+ *mixerDataList = currentMixerData;
}
else {
while(currentMixerData->next)
currentMixerData = currentMixerData->next;
currentMixerData->next = calloc(1, sizeof(struct CtlHalMixerData));
- if(! currentMixerData)
+ if(! currentMixerData->next)
return NULL;
currentMixerData = currentMixerData->next;
@@ -61,17 +60,16 @@ struct CtlHalMixerData *HalUtlAddMixerDataToMixerDataList(struct CtlHalMixerData
return currentMixerData;
}
-int8_t HalUtlRemoveSelectedMixerData(struct CtlHalMixerData **firstMixerData, struct CtlHalMixerData *mixerDataToRemove)
+int8_t HalUtlRemoveSelectedMixerData(struct CtlHalMixerData **mixerDataList, struct CtlHalMixerData *mixerDataToRemove)
{
struct CtlHalMixerData *currentMixerData, *matchingMixerData;
- if(! firstMixerData || ! mixerDataToRemove)
+ if(! mixerDataList || ! *mixerDataList || ! mixerDataToRemove)
return -1;
- currentMixerData = *firstMixerData;
-
+ currentMixerData = *mixerDataList;
if(currentMixerData == mixerDataToRemove) {
- *firstMixerData = currentMixerData->next;
+ *mixerDataList = currentMixerData->next;
matchingMixerData = currentMixerData;
}
else {
@@ -96,13 +94,16 @@ int8_t HalUtlRemoveSelectedMixerData(struct CtlHalMixerData **firstMixerData, st
return 0;
}
-int64_t HalUtlRemoveAllMixerData(struct CtlHalMixerData **firstMixerData)
+int64_t HalUtlRemoveAllMixerData(struct CtlHalMixerData **mixerDataList)
{
int8_t ret;
int64_t mixerDataRemoved = 0;
- while(*firstMixerData) {
- ret = HalUtlRemoveSelectedMixerData(firstMixerData, *firstMixerData);
+ if(! mixerDataList)
+ return -1;
+
+ while(*mixerDataList) {
+ ret = HalUtlRemoveSelectedMixerData(mixerDataList, *mixerDataList);
if(ret)
return (int64_t) ret;
@@ -112,15 +113,15 @@ int64_t HalUtlRemoveAllMixerData(struct CtlHalMixerData **firstMixerData)
return mixerDataRemoved;
}
-int64_t HalUtlGetNumberOfMixerDataInList(struct CtlHalMixerData **firstMixerData)
+int64_t HalUtlGetNumberOfMixerDataInList(struct CtlHalMixerData **mixerDataList)
{
int64_t numberOfMixerData = 0;
struct CtlHalMixerData *currentMixerData;
- if(! firstMixerData)
+ if(! mixerDataList)
return -1;
- currentMixerData = *firstMixerData;
+ currentMixerData = *mixerDataList;
while(currentMixerData) {
currentMixerData = currentMixerData->next;
@@ -130,14 +131,14 @@ int64_t HalUtlGetNumberOfMixerDataInList(struct CtlHalMixerData **firstMixerData
return numberOfMixerData;
}
-struct CtlHalMixerData *HalUtlSearchMixerDataByProperties(struct CtlHalMixerData **firstMixerData, char *verb, char *verbToCall, char *streamCardId)
+struct CtlHalMixerData *HalUtlSearchMixerDataByProperties(struct CtlHalMixerData **mixerDataList, char *verb, char *verbToCall, char *streamCardId)
{
struct CtlHalMixerData *currentMixerData;
- if(! firstMixerData || ! verb)
+ if(! mixerDataList || ! verb)
return NULL;
- currentMixerData = *firstMixerData;
+ currentMixerData = *mixerDataList;
while(currentMixerData) {
if((! strcmp(verb, currentMixerData->verb)) &&
@@ -152,31 +153,30 @@ struct CtlHalMixerData *HalUtlSearchMixerDataByProperties(struct CtlHalMixerData
}
/*******************************************************************************
- * Specfic Hal data handling functions *
+ * Specfic Hal data handling functions *
******************************************************************************/
-struct SpecificHalData *HalUtlAddHalApiToHalList(struct SpecificHalData **firstHalData)
+struct SpecificHalData *HalUtlAddHalApiToHalList(struct SpecificHalData **halDataList)
{
struct SpecificHalData *currentApi;
- if(! firstHalData)
+ if(! halDataList)
return NULL;
- currentApi = *firstHalData;
-
+ currentApi = *halDataList;
if(! currentApi) {
currentApi = (struct SpecificHalData *) calloc(1, sizeof(struct SpecificHalData));
if(! currentApi)
return NULL;
- *firstHalData = currentApi;
+ *halDataList = currentApi;
}
else {
while(currentApi->next)
currentApi = currentApi->next;
currentApi->next = calloc(1, sizeof(struct SpecificHalData));
- if(! currentApi)
+ if(! currentApi->next)
return NULL;
currentApi = currentApi->next;
@@ -185,17 +185,16 @@ struct SpecificHalData *HalUtlAddHalApiToHalList(struct SpecificHalData **firstH
return currentApi;
}
-int8_t HalUtlRemoveSelectedHalFromList(struct SpecificHalData **firstHalData, struct SpecificHalData *apiToRemove)
+int8_t HalUtlRemoveSelectedHalFromList(struct SpecificHalData **halDataList, struct SpecificHalData *apiToRemove)
{
struct SpecificHalData *currentApi, *matchingApi;
- if(! firstHalData || ! apiToRemove)
+ if(! halDataList || ! *halDataList || ! apiToRemove)
return -1;
- currentApi = *firstHalData;
-
+ currentApi = *halDataList;
if(currentApi == apiToRemove) {
- *firstHalData = currentApi->next;
+ *halDataList = currentApi->next;
matchingApi = currentApi;
}
else {
@@ -233,13 +232,16 @@ int8_t HalUtlRemoveSelectedHalFromList(struct SpecificHalData **firstHalData, st
return 0;
}
-int64_t HalUtlRemoveAllHalFromList(struct SpecificHalData **firstHalData)
+int64_t HalUtlRemoveAllHalFromList(struct SpecificHalData **halDataList)
{
int8_t ret;
int64_t CtlHalApiRemoved = 0;
- while(*firstHalData) {
- ret = HalUtlRemoveSelectedHalFromList(firstHalData, *firstHalData);
+ if(! halDataList)
+ return -1;
+
+ while(*halDataList) {
+ ret = HalUtlRemoveSelectedHalFromList(halDataList, *halDataList);
if(ret)
return (int64_t) ret;
@@ -249,15 +251,15 @@ int64_t HalUtlRemoveAllHalFromList(struct SpecificHalData **firstHalData)
return CtlHalApiRemoved;
}
-int64_t HalUtlGetNumberOfHalInList(struct SpecificHalData **firstHalData)
+int64_t HalUtlGetNumberOfHalInList(struct SpecificHalData **halDataList)
{
int64_t numberOfCtlHal = 0;
struct SpecificHalData *currentApi;
- if(! firstHalData)
+ if(! halDataList)
return -1;
- currentApi = *firstHalData;
+ currentApi = *halDataList;
while(currentApi) {
currentApi = currentApi->next;
@@ -267,14 +269,14 @@ int64_t HalUtlGetNumberOfHalInList(struct SpecificHalData **firstHalData)
return numberOfCtlHal;
}
-struct SpecificHalData *HalUtlSearchHalDataByApiName(struct SpecificHalData **firstHalData, char *apiName)
+struct SpecificHalData *HalUtlSearchHalDataByApiName(struct SpecificHalData **halDataList, char *apiName)
{
struct SpecificHalData *currentApi;
- if(! firstHalData || ! apiName)
+ if(! halDataList || ! *halDataList || ! apiName)
return NULL;
- currentApi = *firstHalData;
+ currentApi = *halDataList;
while(currentApi) {
if(! strcmp(apiName, currentApi->apiName))
@@ -286,14 +288,15 @@ struct SpecificHalData *HalUtlSearchHalDataByApiName(struct SpecificHalData **fi
return NULL;
}
-struct SpecificHalData *HalUtlSearchReadyHalDataByCardId(struct SpecificHalData **firstHalData, int cardId)
+struct SpecificHalData *HalUtlSearchReadyHalDataByCardId(struct SpecificHalData **halDataList, int cardId)
{
struct SpecificHalData *currentApi;
- if(! firstHalData)
+ if(! halDataList || ! *halDataList)
return NULL;
- currentApi = *firstHalData;
+ currentApi = *halDataList;
+
while(currentApi) {
if(currentApi->status == HAL_STATUS_READY && currentApi->sndCardId == cardId)
return currentApi;
@@ -305,7 +308,7 @@ struct SpecificHalData *HalUtlSearchReadyHalDataByCardId(struct SpecificHalData
}
/*******************************************************************************
- * Hal Manager data handling functions *
+ * Hal Manager data handling functions *
******************************************************************************/
uint8_t HalUtlInitializeHalMgrData(afb_api_t apiHandle, struct HalMgrData *HalMgrGlobalData, char *apiName, char *info)
@@ -319,7 +322,7 @@ uint8_t HalUtlInitializeHalMgrData(afb_api_t apiHandle, struct HalMgrData *HalMg
return -2;
HalMgrGlobalData->info = strdup(info);
- if(! HalMgrGlobalData->apiName)
+ if(! HalMgrGlobalData->info)
return -3;
HalMgrGlobalData->apiHandle = apiHandle;
@@ -332,8 +335,8 @@ void HalUtlRemoveHalMgrData(struct HalMgrData *HalMgrGlobalData)
if(! HalMgrGlobalData)
return;
- if(HalMgrGlobalData->first)
- HalUtlRemoveAllHalFromList(&HalMgrGlobalData->first);
+ if(HalMgrGlobalData->halDataList)
+ HalUtlRemoveAllHalFromList(&HalMgrGlobalData->halDataList);
free(HalMgrGlobalData->apiName);
free(HalMgrGlobalData->info);
diff --git a/4a-hal-utilities/4a-hal-utilities-data.h b/4a-hal-utilities/4a-hal-utilities-data.h
index 5dd7bea..1389aa6 100644
--- a/4a-hal-utilities/4a-hal-utilities-data.h
+++ b/4a-hal-utilities/4a-hal-utilities-data.h
@@ -91,23 +91,23 @@ struct HalMgrData {
afb_api_t apiHandle;
- struct SpecificHalData *first;
+ struct SpecificHalData *halDataList;
};
// Specfic Hal controller streams data handling functions
-struct CtlHalMixerData *HalUtlAddMixerDataToMixerDataList(struct CtlHalMixerData **firstMixerData);
-int8_t HalUtlRemoveSelectedMixerData(struct CtlHalMixerData **firstMixerData, struct CtlHalMixerData *mixerDataToRemove);
-int64_t HalUtlRemoveAllMixerData(struct CtlHalMixerData **firstMixerData);
-int64_t HalUtlGetNumberOfMixerDataInList(struct CtlHalMixerData **firstMixerData);
-struct CtlHalMixerData *HalUtlSearchMixerDataByProperties(struct CtlHalMixerData **firstMixerData, char *verb, char *verbToCall, char *streamCardId);
+struct CtlHalMixerData *HalUtlAddMixerDataToMixerDataList(struct CtlHalMixerData **mixerDataList);
+int8_t HalUtlRemoveSelectedMixerData(struct CtlHalMixerData **mixerDataList, struct CtlHalMixerData *mixerDataToRemove);
+int64_t HalUtlRemoveAllMixerData(struct CtlHalMixerData **mixerDataList);
+int64_t HalUtlGetNumberOfMixerDataInList(struct CtlHalMixerData **mixerDataList);
+struct CtlHalMixerData *HalUtlSearchMixerDataByProperties(struct CtlHalMixerData **mixerDataList, char *verb, char *verbToCall, char *streamCardId);
// Exported verbs for 'struct SpecificHalData' handling
-struct SpecificHalData *HalUtlAddHalApiToHalList(struct SpecificHalData **firstHalData);
-int8_t HalUtlRemoveSelectedHalFromList(struct SpecificHalData **firstHalData, struct SpecificHalData *ApiToRemove);
-int64_t HalUtlRemoveAllHalFromList(struct SpecificHalData **firstHalData);
-int64_t HalUtlGetNumberOfHalInList(struct SpecificHalData **firstHalData);
-struct SpecificHalData *HalUtlSearchHalDataByApiName(struct SpecificHalData **firstHalData, char *apiName);
-struct SpecificHalData *HalUtlSearchReadyHalDataByCardId(struct SpecificHalData **firstHalData, int cardId);
+struct SpecificHalData *HalUtlAddHalApiToHalList(struct SpecificHalData **halDataList);
+int8_t HalUtlRemoveSelectedHalFromList(struct SpecificHalData **halDataList, struct SpecificHalData *ApiToRemove);
+int64_t HalUtlRemoveAllHalFromList(struct SpecificHalData **halDataList);
+int64_t HalUtlGetNumberOfHalInList(struct SpecificHalData **halDataList);
+struct SpecificHalData *HalUtlSearchHalDataByApiName(struct SpecificHalData **halDataList, char *apiName);
+struct SpecificHalData *HalUtlSearchReadyHalDataByCardId(struct SpecificHalData **halDataList, int cardId);
// Exported verbs for 'struct HalMgrData' handling
uint8_t HalUtlInitializeHalMgrData(afb_api_t apiHandle, struct HalMgrData *HalMgrGlobalData, char *apiName, char *info);