summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJonathan Aillet <jonathan.aillet@iot.bzh>2019-06-14 17:59:20 +0200
committerJonathan Aillet <jonathan.aillet@iot.bzh>2019-06-18 11:34:34 +0200
commit66f27bce6355cc7df978a9d7a6bc725542057a01 (patch)
treebed31fbbd60ec80a2f6f57f8182c326ae048d5b7
parent870d396127c2e5e247cb85a7921143e78ee81ce4 (diff)
Refactoring 'probed devices' linked list
Refactoring 'probed devices' linked list code using liburcu. BUG-AGL: SPEC-2329 Change-Id: I4d0255bc020733b1abbea1f3e6195c73cf8da8f6 Signed-off-by: Jonathan Aillet <jonathan.aillet@iot.bzh>
-rw-r--r--conf.d/cmake/config.cmake2
-rw-r--r--lib/4a-hal-utilities/4a-hal-utilities-data.c264
-rw-r--r--lib/4a-hal-utilities/4a-hal-utilities-data.h27
-rw-r--r--src/4a-hal-manager/4a-hal-manager-cb.c2
-rw-r--r--src/4a-internals-hal/4a-internals-hal-api-loader.c2
-rw-r--r--src/4a-internals-hal/4a-internals-hal-cb.c29
-rw-r--r--src/4a-internals-hal/4a-internals-hal-mixer-link.c2
7 files changed, 181 insertions, 147 deletions
diff --git a/conf.d/cmake/config.cmake b/conf.d/cmake/config.cmake
index 4dda489..75879f4 100644
--- a/conf.d/cmake/config.cmake
+++ b/conf.d/cmake/config.cmake
@@ -68,11 +68,11 @@ set (gcc_minimal_version 4.9)
set (PKG_REQUIRED_LIST
json-c
libsystemd>=222
-# afb-daemon>=6.0 # Goal
afb-daemon>=4.0
libmicrohttpd>=0.9.55
uuid
alsa>=1.1.2
+ liburcu
afb-helpers
ctl-utilities
)
diff --git a/lib/4a-hal-utilities/4a-hal-utilities-data.c b/lib/4a-hal-utilities/4a-hal-utilities-data.c
index 6f85565..f3f4229 100644
--- a/lib/4a-hal-utilities/4a-hal-utilities-data.c
+++ b/lib/4a-hal-utilities/4a-hal-utilities-data.c
@@ -28,6 +28,108 @@
#include "4a-hal-utilities-alsa-data.h"
/*******************************************************************************
+ * Internal Hal - Linked list cleaning function declaration *
+ ******************************************************************************/
+
+void HalUtlFreeSelectedProbedDeviceAllocation(struct InternalHalProbedDevice *probedDeviceToFree);
+
+/*******************************************************************************
+ * Internal Hal - Generic function for linked list *
+ ******************************************************************************/
+
+void *HalUtlAddNodeInList(struct cds_list_head *listHead, enum LinkedListType listType)
+{
+ void *returned = NULL;
+ struct cds_list_head *nodeToAdd;
+
+ if(! listHead)
+ return NULL;
+
+ switch(listType) {
+ case LINKED_LIST_FOR_DEPENDENCIES_DATA:
+ returned = calloc(1, sizeof(struct InternalHalProbedDevice));
+ if(! returned)
+ return NULL;
+ nodeToAdd = &((struct InternalHalProbedDevice *) returned)->node;
+ break;
+
+
+ default:
+ return NULL;
+ }
+
+ cds_list_add_tail(nodeToAdd, listHead);
+
+ return returned;
+}
+
+int HalUtlRemoveNodeFromList(struct cds_list_head *listHead, void *dataToRemove, enum LinkedListType listType)
+{
+ if(! listHead || cds_list_empty(listHead) || ! dataToRemove)
+ return -1;
+
+ switch(listType) {
+ case LINKED_LIST_FOR_DEPENDENCIES_DATA:
+ cds_list_del(&((struct InternalHalProbedDevice *) dataToRemove)->node);
+
+ HalUtlFreeSelectedProbedDeviceAllocation((struct InternalHalProbedDevice *) dataToRemove);
+ break;
+
+ default:
+ return -2;
+ }
+
+ return 0;
+}
+
+int HalUtlRemoveAllNodeFromList(struct cds_list_head *listHead, enum LinkedListType listType)
+{
+ int nodesRemoved = 0;
+
+ struct cds_list_head *nodeToRemove, *savedNode;
+
+ if(! listHead)
+ return -1;
+
+ if(cds_list_empty(listHead))
+ return 0;
+
+ cds_list_for_each_safe(nodeToRemove, savedNode, listHead) {
+ switch(listType) {
+ case LINKED_LIST_FOR_DEPENDENCIES_DATA:
+ if(HalUtlRemoveSelectedProbedDeviceFromList(listHead,
+ cds_list_entry(nodeToRemove, struct InternalHalProbedDevice, node)))
+ return -2;
+ break;
+
+ default:
+ return -3;
+ }
+
+ nodesRemoved++;
+ }
+
+ return nodesRemoved;
+}
+
+int HalUtlGetNumberOfNodesInList(struct cds_list_head *listHead)
+{
+ int numberOfNodes = 0;
+ struct cds_list_head *listNode;
+
+ if(! listHead)
+ return -1;
+
+ if(cds_list_empty(listHead))
+ return 0;
+
+ cds_list_for_each(listNode, listHead)
+ numberOfNodes++;
+
+ return numberOfNodes;
+}
+
+/*******************************************************************************
* Internal Hal - Probed devices structure handling functions *
******************************************************************************/
@@ -97,136 +199,65 @@ int HalUtlIsDependencySelected(struct InternalHalProbedDevice *probedDevice, enu
}
}
-struct InternalHalProbedDevice *HalUtlAddProbedDeviceToProbedDeviceList(struct InternalHalProbedDevice **probedDevicesList)
+void HalUtlFreeSelectedProbedDeviceAllocation(struct InternalHalProbedDevice *probedDeviceToFree)
{
- struct InternalHalProbedDevice *currentProbedDevice;
+ if(! probedDeviceToFree)
+ return;
- if(! probedDevicesList)
- return NULL;
+ free(probedDeviceToFree->uid);
- currentProbedDevice = *probedDevicesList;
- if(! currentProbedDevice) {
- currentProbedDevice = (struct InternalHalProbedDevice *) calloc(1, sizeof(struct InternalHalProbedDevice));
- if(! currentProbedDevice)
- return NULL;
+ if(probedDeviceToFree->deviceData) {
+ free(probedDeviceToFree->deviceData->extendedCardNb);
+ free(probedDeviceToFree->deviceData->cardId);
+ free(probedDeviceToFree->deviceData->cardShortName);
+ free(probedDeviceToFree->deviceData->cardLongName);
+ free(probedDeviceToFree->deviceData->cardDriver);
+ free(probedDeviceToFree->deviceData->cardMixerName);
+ free(probedDeviceToFree->deviceData->cardComponents);
+ free(probedDeviceToFree->deviceData->playbackDeviceId);
+ free(probedDeviceToFree->deviceData->playbackDeviceName);
- *probedDevicesList = currentProbedDevice;
+ free(probedDeviceToFree->deviceData);
}
- else {
- while(currentProbedDevice->next)
- currentProbedDevice = currentProbedDevice->next;
- currentProbedDevice->next = calloc(1, sizeof(struct InternalHalProbedDevice));
- if(! currentProbedDevice->next)
- return NULL;
+ if(probedDeviceToFree->requestedDeviceJ)
+ json_object_put(probedDeviceToFree->requestedDeviceJ);
- currentProbedDevice = currentProbedDevice->next;
- }
+ free(probedDeviceToFree);
+}
- return currentProbedDevice;
+struct InternalHalProbedDevice *HalUtlAddProbedDeviceToProbedDeviceList(struct cds_list_head *probedDevicesListHead)
+{
+ return (struct InternalHalProbedDevice *) HalUtlAddNodeInList(probedDevicesListHead, LINKED_LIST_FOR_DEPENDENCIES_DATA);
}
-int HalUtlRemoveSelectedProbedDeviceFromList(struct InternalHalProbedDevice **probedDevicesList,
+int HalUtlRemoveSelectedProbedDeviceFromList(struct cds_list_head *probedDevicesListHead,
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;
+ return HalUtlRemoveNodeFromList(probedDevicesListHead, (void *) probedDeviceToRemove, LINKED_LIST_FOR_DEPENDENCIES_DATA);
}
-int HalUtlRemoveAllProbedDevicesFromList(struct InternalHalProbedDevice **probedDevicesList)
+int HalUtlRemoveAllProbedDevicesFromList(struct cds_list_head *probedDevicesListHead)
{
- int probedDevicesRemoved = 0;
-
- if(! probedDevicesList)
- return -1;
-
- if(! *probedDevicesList)
- return 0;
-
- while(*probedDevicesList) {
- if(HalUtlRemoveSelectedProbedDeviceFromList(probedDevicesList, *probedDevicesList))
- return -2;
-
- probedDevicesRemoved++;
- }
-
- return probedDevicesRemoved;
+ return HalUtlRemoveAllNodeFromList(probedDevicesListHead, LINKED_LIST_FOR_DEPENDENCIES_DATA);
}
-int HalUtlGetNumberOfProbedDevicesInList(struct InternalHalProbedDevice **probedDevicesList)
+int HalUtlGetNumberOfProbedDevicesInList(struct cds_list_head *probedDevicesListHead)
{
- int numberOfProbedDevices = 0;
- struct InternalHalProbedDevice *currentProbedDevice;
-
- if(! probedDevicesList)
- return -1;
-
- currentProbedDevice = *probedDevicesList;
- while(currentProbedDevice) {
- currentProbedDevice = currentProbedDevice->next;
- numberOfProbedDevices++;
- }
-
- return numberOfProbedDevices;
+ return HalUtlGetNumberOfNodesInList(probedDevicesListHead);
}
-struct InternalHalProbedDevice *HalUtlSearchProbedDeviceDataById(struct InternalHalProbedDevice **probedDevicesList,
+struct InternalHalProbedDevice *HalUtlSearchProbedDeviceDataById(struct cds_list_head *probedDevicesListHead,
char *uid)
{
struct InternalHalProbedDevice *currentProbedDevice;
- if(! probedDevicesList || ! *probedDevicesList || ! uid)
+ if(! probedDevicesListHead || cds_list_empty(probedDevicesListHead) || ! uid)
return NULL;
- currentProbedDevice = *probedDevicesList;
- while(currentProbedDevice) {
+ cds_list_for_each_entry(currentProbedDevice, probedDevicesListHead, node) {
if(! strcmp(uid, currentProbedDevice->uid))
return currentProbedDevice;
-
- currentProbedDevice = currentProbedDevice->next;
}
return NULL;
@@ -428,7 +459,7 @@ json_object *HalUtlGetJsonForSpecificDependencies(afb_api_t apiHandle,
}
json_object *HalUtlGetJsonForSpecificDependenciesUsingUid(afb_api_t apiHandle,
- struct InternalHalProbedDevice **probedDevicesList,
+ struct cds_list_head *probedDevicesListHead,
char *uid,
enum DependencyInfoJsonFormat jsonFormat)
{
@@ -441,7 +472,7 @@ json_object *HalUtlGetJsonForSpecificDependenciesUsingUid(afb_api_t apiHandle,
return NULL;
}
- if(! probedDevicesList || ! *probedDevicesList) {
+ if(! probedDevicesListHead || cds_list_empty(probedDevicesListHead)) {
AFB_API_ERROR(apiHandle, "Probed device list is empty");
return NULL;
}
@@ -451,7 +482,7 @@ json_object *HalUtlGetJsonForSpecificDependenciesUsingUid(afb_api_t apiHandle,
return NULL;
}
- requestedProbedDevice = HalUtlSearchProbedDeviceDataById(probedDevicesList, uid);
+ requestedProbedDevice = HalUtlSearchProbedDeviceDataById(probedDevicesListHead, uid);
if(! requestedProbedDevice) {
AFB_API_ERROR(apiHandle,
"Requested dependency uid ('%s) was not found in probed device list",
@@ -471,7 +502,7 @@ json_object *HalUtlGetJsonForSpecificDependenciesUsingUid(afb_api_t apiHandle,
}
json_object *HalUtlGetJsonArrayForSelectedDependencies(afb_api_t apiHandle,
- struct InternalHalProbedDevice **probedDevicesList,
+ struct cds_list_head *probedDevicesListHead,
enum DependencyInfoJsonFormat jsonFormat,
enum DependencyStatus requestedStatus)
{
@@ -484,7 +515,7 @@ json_object *HalUtlGetJsonArrayForSelectedDependencies(afb_api_t apiHandle,
return NULL;
}
- if(! probedDevicesList || ! *probedDevicesList) {
+ if(! probedDevicesListHead || cds_list_empty(probedDevicesListHead)) {
AFB_API_ERROR(apiHandle, "Probed device list is empty");
return NULL;
}
@@ -495,8 +526,7 @@ json_object *HalUtlGetJsonArrayForSelectedDependencies(afb_api_t apiHandle,
return NULL;
}
- currentProbedDevice = *probedDevicesList;
- while(currentProbedDevice) {
+ cds_list_for_each_entry(currentProbedDevice, probedDevicesListHead, node) {
requestedProbedDeviceJ = NULL;
if(HalUtlIsDependencySelected(currentProbedDevice, requestedStatus)) {
@@ -514,15 +544,13 @@ json_object *HalUtlGetJsonArrayForSelectedDependencies(afb_api_t apiHandle,
if(requestedProbedDeviceJ)
json_object_array_add(requestedDependenciesInfoJ, requestedProbedDeviceJ);
-
- currentProbedDevice = currentProbedDevice->next;
}
return requestedDependenciesInfoJ;
}
json_object *HalUtlGetJsonArrayForAvailableDependencies(afb_api_t apiHandle,
- struct InternalHalProbedDevice **probedDevicesList,
+ struct cds_list_head *probedDevicesListHead,
enum DependencyInfoJsonFormat jsonFormat)
{
json_object *requestedDependenciesInfoJ;
@@ -532,13 +560,13 @@ json_object *HalUtlGetJsonArrayForAvailableDependencies(afb_api_t apiHandle,
return NULL;
}
- if(! probedDevicesList || ! *probedDevicesList) {
+ if(! probedDevicesListHead || cds_list_empty(probedDevicesListHead)) {
AFB_API_ERROR(apiHandle, "Probed device list is empty");
return NULL;
}
requestedDependenciesInfoJ = HalUtlGetJsonArrayForSelectedDependencies(apiHandle,
- probedDevicesList,
+ probedDevicesListHead,
jsonFormat,
AVAILABLE_DEPENDENCY);
if(! requestedDependenciesInfoJ) {
@@ -550,7 +578,7 @@ json_object *HalUtlGetJsonArrayForAvailableDependencies(afb_api_t apiHandle,
}
json_object *HalUtlGetJsonArrayForAllDependencies(afb_api_t apiHandle,
- struct InternalHalProbedDevice **probedDevicesList,
+ struct cds_list_head *probedDevicesListHead,
enum DependencyInfoJsonFormat jsonFormat)
{
json_object *requestedDependenciesInfoJ;
@@ -560,13 +588,13 @@ json_object *HalUtlGetJsonArrayForAllDependencies(afb_api_t apiHandle,
return NULL;
}
- if(! probedDevicesList || ! *probedDevicesList) {
+ if(! probedDevicesListHead || cds_list_empty(probedDevicesListHead)) {
AFB_API_ERROR(apiHandle, "Probed device list is empty");
return NULL;
}
requestedDependenciesInfoJ = HalUtlGetJsonArrayForSelectedDependencies(apiHandle,
- probedDevicesList,
+ probedDevicesListHead,
jsonFormat,
ALL_DEPENDENCY);
if(! requestedDependenciesInfoJ) {
@@ -834,7 +862,7 @@ int HalUtlRemoveSelectedHalFromList(struct HalData **halDataList, struct HalData
free(matchingHal->internalHalData->mixerApiName);
free(matchingHal->internalHalData->prefix);
- HalUtlRemoveAllProbedDevicesFromList(&matchingHal->internalHalData->probedDevicesList);
+ HalUtlRemoveAllProbedDevicesFromList(&matchingHal->internalHalData->probedDevicesListHead);
HalUtlRemoveAllMixerData(&matchingHal->internalHalData->streamsData);
diff --git a/lib/4a-hal-utilities/4a-hal-utilities-data.h b/lib/4a-hal-utilities/4a-hal-utilities-data.h
index c051373..8ac4c25 100644
--- a/lib/4a-hal-utilities/4a-hal-utilities-data.h
+++ b/lib/4a-hal-utilities/4a-hal-utilities-data.h
@@ -20,6 +20,8 @@
#include <stdio.h>
+#include <urcu/list.h>
+
#include <wrap-json.h>
#include <afb/afb-binding.h>
@@ -32,6 +34,11 @@
#define HAL_STREAM_UPDATES_EVENT_NAME "stream-updates"
+// Enum for linked list type
+enum LinkedListType {
+ LINKED_LIST_FOR_DEPENDENCIES_DATA = 0
+};
+
// Enum for hal status
enum HalStatus {
HAL_STATUS_UNAVAILABLE = 0,
@@ -83,7 +90,7 @@ struct InternalHalProbedDevice {
struct InternalHalDeviceData *deviceData;
- struct InternalHalProbedDevice *next;
+ struct cds_list_head node;
};
// Structure to store stream data
@@ -102,7 +109,7 @@ struct InternalHalData {
char *prefix;
json_object *halMixerJ;
- struct InternalHalProbedDevice *probedDevicesList;
+ struct cds_list_head probedDevicesListHead;
struct InternalHalMixerData *streamsData;
afb_event_t streamUpdates;
@@ -146,26 +153,26 @@ struct HalMgrData {
// Internal Hal - Probed devices structure handling functions
enum ProbedDeviceClasses HalUtlGetProbedDeviceClassFromString(char *probedDeviceString);
char *HalUtlGetProbedDeviceClassString(enum ProbedDeviceClasses deviceClass);
-struct InternalHalProbedDevice *HalUtlAddProbedDeviceToProbedDeviceList(struct InternalHalProbedDevice **probedDevicesList);
-int HalUtlRemoveSelectedProbedDeviceFromList(struct InternalHalProbedDevice **probedDevicesList,
+struct InternalHalProbedDevice *HalUtlAddProbedDeviceToProbedDeviceList(struct cds_list_head *probedDevicesListHead);
+int HalUtlRemoveSelectedProbedDeviceFromList(struct cds_list_head *probedDevicesListHead,
struct InternalHalProbedDevice *probedDeviceToRemove);
-int HalUtlRemoveAllProbedDevicesFromList(struct InternalHalProbedDevice **probedDevicesList);
-int HalUtlGetNumberOfProbedDevicesInList(struct InternalHalProbedDevice **probedDevicesList);
-struct InternalHalProbedDevice *HalUtlSearchProbedDeviceDataById(struct InternalHalProbedDevice **probedDevicesList,
+int HalUtlRemoveAllProbedDevicesFromList(struct cds_list_head *probedDevicesListHead);
+int HalUtlGetNumberOfProbedDevicesInList(struct cds_list_head *probedDevicesListHead);
+struct InternalHalProbedDevice *HalUtlSearchProbedDeviceDataById(struct cds_list_head *probedDevicesListHead,
char *uid);
struct InternalHalDeviceData *HalUtlAllocateAndFillProbedDeviceDataUsingInfoGetResponse(json_object *responseJ);
json_object *HalUtlGetJsonForSpecificDependencies(afb_api_t apiHandle,
struct InternalHalProbedDevice *requestedProbedDevice,
enum DependencyInfoJsonFormat jsonFormat);
json_object *HalUtlGetJsonForSpecificDependenciesUsingUid(afb_api_t apiHandle,
- struct InternalHalProbedDevice **probedDevicesList,
+ struct cds_list_head *probedDevicesListHead,
char *uid,
enum DependencyInfoJsonFormat jsonFormat);
json_object *HalUtlGetJsonArrayForAvailableDependencies(afb_api_t apiHandle,
- struct InternalHalProbedDevice **probedDevicesList,
+ struct cds_list_head *probedDevicesListHead,
enum DependencyInfoJsonFormat jsonFormat);
json_object *HalUtlGetJsonArrayForAllDependencies(afb_api_t apiHandle,
- struct InternalHalProbedDevice **probedDevicesList,
+ struct cds_list_head *probedDevicesListHead,
enum DependencyInfoJsonFormat jsonFormat);
// Internal Hal - Streams data handling functions
diff --git a/src/4a-hal-manager/4a-hal-manager-cb.c b/src/4a-hal-manager/4a-hal-manager-cb.c
index 396bab2..843066b 100644
--- a/src/4a-hal-manager/4a-hal-manager-cb.c
+++ b/src/4a-hal-manager/4a-hal-manager-cb.c
@@ -117,7 +117,7 @@ void HalMgrLoaded(afb_req_t request)
snprintf(cardIdString, sizeof(cardIdString), "not-found");
dependenciesJ = HalUtlGetJsonArrayForAllDependencies(apiHandle,
- &currentHalData->internalHalData->probedDevicesList,
+ &currentHalData->internalHalData->probedDevicesListHead,
DEPENDENCY_COMPACT_JSON);
if(! dependenciesJ)
AFB_REQ_WARNING(request, "Didn't succeed to generate all dependencies compact json array");
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 f18f651..7a82a46 100644
--- a/src/4a-internals-hal/4a-internals-hal-api-loader.c
+++ b/src/4a-internals-hal/4a-internals-hal-api-loader.c
@@ -211,6 +211,8 @@ int InternalHalCreateApi(afb_api_t apiHandle, char *path, struct HalMgrData *hal
return -5;
}
+ CDS_INIT_LIST_HEAD(&currentHalData->internalHalData->probedDevicesListHead);
+
// Create one API
if(! afb_api_new_api(apiHandle, ctrlConfig->api, ctrlConfig->info, 1, InternalHalLoadOneApi, ctrlConfig)) {
AFB_API_ERROR(apiHandle, "An error occurred at '%s' internal hal api creation", ctrlConfig->api);
diff --git a/src/4a-internals-hal/4a-internals-hal-cb.c b/src/4a-internals-hal/4a-internals-hal-cb.c
index ef24cc4..07bad11 100644
--- a/src/4a-internals-hal/4a-internals-hal-cb.c
+++ b/src/4a-internals-hal/4a-internals-hal-cb.c
@@ -732,7 +732,7 @@ int InternalHalProcessOneHalDependency(afb_api_t apiHandle, json_object *Depende
return 0;
}
-int InternalHalProcessAllHalDependencies(afb_api_t apiHandle, json_object *DependenciesJ, struct InternalHalProbedDevice **halDevicesToProbeList)
+int InternalHalProcessAllHalDependencies(afb_api_t apiHandle, json_object *DependenciesJ, struct cds_list_head *halDevicesToProbeListHead)
{
int idx, dependenciesCount, ret;
@@ -741,7 +741,7 @@ int InternalHalProcessAllHalDependencies(afb_api_t apiHandle, json_object *Depen
json_type dependenciesJType;
json_object *currentDependencyJ;
- if(! apiHandle || ! DependenciesJ || ! halDevicesToProbeList) {
+ if(! apiHandle || ! DependenciesJ || ! halDevicesToProbeListHead) {
AFB_API_ERROR(apiHandle, "Invalid argument(s)");
return -1;
}
@@ -774,14 +774,14 @@ int InternalHalProcessAllHalDependencies(afb_api_t apiHandle, json_object *Depen
"Dependency ('%s') is not an object, section is malformed, won't be able to handle it ('haldependencies' : '%s')",
json_object_get_string(currentDependencyJ),
json_object_get_string(DependenciesJ));
- HalUtlRemoveAllProbedDevicesFromList(halDevicesToProbeList);
+ HalUtlRemoveAllProbedDevicesFromList(halDevicesToProbeListHead);
return -3;
}
- currentDeviceToProbe = HalUtlAddProbedDeviceToProbedDeviceList(halDevicesToProbeList);
+ currentDeviceToProbe = HalUtlAddProbedDeviceToProbedDeviceList(halDevicesToProbeListHead);
if(! currentDeviceToProbe) {
AFB_API_ERROR(apiHandle, "Error when tried to add a device to probe into device to probe list");
- HalUtlRemoveAllProbedDevicesFromList(halDevicesToProbeList);
+ HalUtlRemoveAllProbedDevicesFromList(halDevicesToProbeListHead);
return -4;
}
@@ -791,7 +791,7 @@ int InternalHalProcessAllHalDependencies(afb_api_t apiHandle, json_object *Depen
"Error %i returned when tried to process '%s' dependency",
ret,
json_object_get_string(currentDependencyJ));
- HalUtlRemoveAllProbedDevicesFromList(halDevicesToProbeList);
+ HalUtlRemoveAllProbedDevicesFromList(halDevicesToProbeListHead);
return -5;
}
}
@@ -939,24 +939,23 @@ int InternalHalHandleOneHalDependencies(afb_api_t apiHandle, struct InternalHalP
return 0;
}
-int InternalHalHandleAllHalDependencies(afb_api_t apiHandle, struct InternalHalProbedDevice **halDevicesToProbeList)
+int InternalHalHandleAllHalDependencies(afb_api_t apiHandle, struct cds_list_head *halDevicesToProbeListHead)
{
int ret;
struct InternalHalProbedDevice *halCurrentDeviceToProbe;
- if(! apiHandle || ! halDevicesToProbeList) {
+ if(! apiHandle || ! halDevicesToProbeListHead) {
AFB_API_ERROR(apiHandle, "Invalid argument(s)");
return -1;
}
- halCurrentDeviceToProbe = *halDevicesToProbeList;
- if(! halCurrentDeviceToProbe) {
+ if(cds_list_empty(halDevicesToProbeListHead)) {
AFB_API_WARNING(apiHandle, "No device to probe in list, 'haldependencies' handling skipped");
return 0;
}
- while(halCurrentDeviceToProbe) {
+ cds_list_for_each_entry(halCurrentDeviceToProbe, halDevicesToProbeListHead, node) {
ret = InternalHalHandleOneHalDependencies(apiHandle, &halCurrentDeviceToProbe);
if(ret < 0) {
AFB_API_ERROR(apiHandle,
@@ -975,8 +974,6 @@ int InternalHalHandleAllHalDependencies(afb_api_t apiHandle, struct InternalHalP
json_object_get_string(halCurrentDeviceToProbe->requestedDeviceJ));
return -3;
}
-
- halCurrentDeviceToProbe = halCurrentDeviceToProbe->next;
}
return 0;
@@ -996,12 +993,12 @@ int InternalHalHalDependenciesConfig(afb_api_t apiHandle, CtlSectionT *section,
return -2;
if(DependenciesJ &&
- InternalHalProcessAllHalDependencies(apiHandle, DependenciesJ, &currentHalData->internalHalData->probedDevicesList)) {
+ InternalHalProcessAllHalDependencies(apiHandle, DependenciesJ, &currentHalData->internalHalData->probedDevicesListHead)) {
AFB_API_ERROR(apiHandle, "Failed to process 'haldependencies' section");
return -3;
}
else if(! DependenciesJ &&
- (InternalHalHandleAllHalDependencies(apiHandle, &currentHalData->internalHalData->probedDevicesList)) < 0) {
+ (InternalHalHandleAllHalDependencies(apiHandle, &currentHalData->internalHalData->probedDevicesListHead)) < 0) {
AFB_API_ERROR(apiHandle, "Failed to handle 'haldependencies' section");
return -4;
}
@@ -1074,7 +1071,7 @@ void InternalHalInfo(afb_req_t request)
}
dependenciesArray = HalUtlGetJsonArrayForAvailableDependencies(apiHandle,
- &currentHalData->internalHalData->probedDevicesList,
+ &currentHalData->internalHalData->probedDevicesListHead,
DEPENDENCY_FULL_JSON);
if(! dependenciesArray) {
afb_req_fail(request, "dependencies_data", "Didn't succeed to generate dependencies data array");
diff --git a/src/4a-internals-hal/4a-internals-hal-mixer-link.c b/src/4a-internals-hal/4a-internals-hal-mixer-link.c
index 985de96..879ab3e 100644
--- a/src/4a-internals-hal/4a-internals-hal-mixer-link.c
+++ b/src/4a-internals-hal/4a-internals-hal-mixer-link.c
@@ -201,7 +201,7 @@ int InternalHalAttachToMixer(afb_api_t apiHandle)
}
dependencyJ = HalUtlGetJsonArrayForAvailableDependencies(apiHandle,
- &currentHalData->internalHalData->probedDevicesList,
+ &currentHalData->internalHalData->probedDevicesListHead,
DEPENDENCY_COMPACT_JSON);
if(! dependencyJ) {
AFB_API_ERROR(apiHandle, "Didn't succeed to generate available dependencies compact json array");