summaryrefslogtreecommitdiffstats
path: root/lib/4a-hal-utilities
diff options
context:
space:
mode:
authorJonathan Aillet <jonathan.aillet@iot.bzh>2019-08-05 18:15:53 +0200
committerJonathan Aillet <jonathan.aillet@iot.bzh>2019-08-12 12:23:11 +0200
commit8c08ae193531b6f9c86f58764af598016b696260 (patch)
tree50fd8538d722c264523b515f59f967ecc59e3a05 /lib/4a-hal-utilities
parent660e714874277031d74ee81c802e4a948cbd0981 (diff)
Optimize hal 'info' response json allocation
Optimize hal 'info' response json allocation by removing empty objects/arrays from response. BUG-AGL: SPEC-2733 Change-Id: I521626b67076b603ab1caa974b697246c8fff759 Signed-off-by: Jonathan Aillet <jonathan.aillet@iot.bzh>
Diffstat (limited to 'lib/4a-hal-utilities')
-rw-r--r--lib/4a-hal-utilities/4a-hal-utilities-data.c66
-rw-r--r--lib/4a-hal-utilities/4a-hal-utilities-data.h4
2 files changed, 59 insertions, 11 deletions
diff --git a/lib/4a-hal-utilities/4a-hal-utilities-data.c b/lib/4a-hal-utilities/4a-hal-utilities-data.c
index b6d8abb..6d1afd0 100644
--- a/lib/4a-hal-utilities/4a-hal-utilities-data.c
+++ b/lib/4a-hal-utilities/4a-hal-utilities-data.c
@@ -611,8 +611,13 @@ json_object *HalUtlGetJsonForSpecificDependenciesUsingUid(afb_api_t apiHandle,
return NULL;
}
- if(! probedDevicesListHead || cds_list_empty(probedDevicesListHead)) {
- AFB_API_ERROR(apiHandle, "Probed device list is empty");
+ if(! probedDevicesListHead) {
+ AFB_API_ERROR(apiHandle, "Probed device list is not valid");
+ return NULL;
+ }
+
+ if(cds_list_empty(probedDevicesListHead)) {
+ AFB_API_INFO(apiHandle, "Probed device list is empty");
return NULL;
}
@@ -655,7 +660,7 @@ json_object *HalUtlGetJsonArrayForSelectedDependencies(afb_api_t apiHandle,
}
if(! probedDevicesListHead || cds_list_empty(probedDevicesListHead)) {
- AFB_API_ERROR(apiHandle, "Probed device list is empty");
+ AFB_API_ERROR(apiHandle, "Probed device list is not valid or empty");
return NULL;
}
@@ -699,8 +704,13 @@ json_object *HalUtlGetJsonArrayForAvailableDependencies(afb_api_t apiHandle,
return NULL;
}
- if(! probedDevicesListHead || cds_list_empty(probedDevicesListHead)) {
- AFB_API_ERROR(apiHandle, "Probed device list is empty");
+ if(! probedDevicesListHead) {
+ AFB_API_ERROR(apiHandle, "Probed device list is not valid");
+ return NULL;
+ }
+
+ if(cds_list_empty(probedDevicesListHead)) {
+ AFB_API_INFO(apiHandle, "Probed device list is empty");
return NULL;
}
@@ -713,6 +723,12 @@ json_object *HalUtlGetJsonArrayForAvailableDependencies(afb_api_t apiHandle,
return NULL;
}
+ if(! json_object_array_length(requestedDependenciesInfoJ)) {
+ AFB_API_INFO(apiHandle, "No available devices (dependencies) in list");
+ json_object_put(requestedDependenciesInfoJ);
+ return NULL;
+ }
+
return requestedDependenciesInfoJ;
}
@@ -727,8 +743,13 @@ json_object *HalUtlGetJsonArrayForAllDependencies(afb_api_t apiHandle,
return NULL;
}
- if(! probedDevicesListHead || cds_list_empty(probedDevicesListHead)) {
- AFB_API_ERROR(apiHandle, "Probed device list is empty");
+ if(! probedDevicesListHead) {
+ AFB_API_ERROR(apiHandle, "Probed device list is not valid");
+ return NULL;
+ }
+
+ if(cds_list_empty(probedDevicesListHead)) {
+ AFB_API_INFO(apiHandle, "Probed device list is empty");
return NULL;
}
@@ -737,7 +758,13 @@ json_object *HalUtlGetJsonArrayForAllDependencies(afb_api_t apiHandle,
jsonFormat,
ALL_DEPENDENCY);
if(! requestedDependenciesInfoJ) {
- AFB_API_ERROR(apiHandle, "Didn't succeed get available devices (dependencies) info");
+ AFB_API_ERROR(apiHandle, "Didn't succeed get all devices (dependencies) info");
+ return NULL;
+ }
+
+ if(! json_object_array_length(requestedDependenciesInfoJ)) {
+ AFB_API_ERROR(apiHandle, "No devices (dependencies) info returned but list is not empty");
+ json_object_put(requestedDependenciesInfoJ);
return NULL;
}
@@ -842,7 +869,7 @@ json_object *HalUtlGetJsonArrayForAllMixersData(afb_api_t apiHandle, struct cds_
}
if(cds_list_empty(mixerDataListHead)) {
- AFB_API_ERROR(apiHandle, "Mixer data list is empty");
+ AFB_API_INFO(apiHandle, "Mixer data list is empty");
return NULL;
}
@@ -863,6 +890,12 @@ json_object *HalUtlGetJsonArrayForAllMixersData(afb_api_t apiHandle, struct cds_
json_object_array_add(mixerDataArrayJ, currentMixerDataJ);
}
+ if(! json_object_array_length(mixerDataArrayJ)) {
+ AFB_API_ERROR(apiHandle, "No mixer info returned but list is not empty");
+ json_object_put(mixerDataArrayJ);
+ return NULL;
+ }
+
return mixerDataArrayJ;
}
@@ -992,8 +1025,13 @@ json_object *HalUtGetJsonArrayForAllHalMapControls(afb_api_t apiHandle, struct c
return NULL;
}
- if(! halMapListHead || cds_list_empty(halMapListHead)) {
- AFB_API_ERROR(apiHandle, "HalMap data list is empty");
+ if(! halMapListHead) {
+ AFB_API_ERROR(apiHandle, "HalMap data list is not valid");
+ return NULL;
+ }
+
+ if(cds_list_empty(halMapListHead)) {
+ AFB_API_INFO(apiHandle, "HalMap data list is empty");
return NULL;
}
@@ -1014,6 +1052,12 @@ json_object *HalUtGetJsonArrayForAllHalMapControls(afb_api_t apiHandle, struct c
json_object_array_add(halMapDataArrayJ, currentHalMapDataJ);
}
+ if(! json_object_array_length(halMapDataArrayJ)) {
+ AFB_API_ERROR(apiHandle, "No HalMap info returned but list is not empty");
+ json_object_put(halMapDataArrayJ);
+ return NULL;
+ }
+
return halMapDataArrayJ;
}
diff --git a/lib/4a-hal-utilities/4a-hal-utilities-data.h b/lib/4a-hal-utilities/4a-hal-utilities-data.h
index 5677dac..fe55495 100644
--- a/lib/4a-hal-utilities/4a-hal-utilities-data.h
+++ b/lib/4a-hal-utilities/4a-hal-utilities-data.h
@@ -194,6 +194,10 @@ int HalUtlRemoveSelectedHalMapData(struct cds_list_head *halMapListHead,
struct InternalHalAlsaMap *halMapDataToRemove);
int HalUtlRemoveAllHalMapData(struct cds_list_head *halMapListHead);
int HalUtlGetNumberOfHalMapDataInList(struct cds_list_head *halMapListHead);
+json_object *HalUtlGetJsonForSpecificDependenciesUsingUid(afb_api_t apiHandle,
+ struct cds_list_head *probedDevicesListHead,
+ char *uid,
+ enum DependencyInfoJsonFormat jsonFormat);
json_object *HalUtGetJsonArrayForSpecificHalMapControl(afb_api_t apiHandle,
struct InternalHalAlsaMap *currentHalMapData);
json_object *HalUtGetJsonArrayForAllHalMapControls(afb_api_t apiHandle, struct cds_list_head *halMapListHead);