aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJonathan Aillet <jonathan.aillet@iot.bzh>2018-06-19 16:24:24 +0200
committerJonathan Aillet <jonathan.aillet@iot.bzh>2018-10-08 15:53:53 +0200
commit5bfa3c8ed61c724388b1b3e802cc8fe97b0709de (patch)
treeb8168d37b7e824e87c02194e3d6af961d0f88984
parent8bbfce60e809f867c502f836c49ef70b9c4a0c63 (diff)
Correct handling of incomming json messages
Correct handling of incomming json messages. An error occured when a received json object was an array containing only one item. Change-Id: I2c6f27f0fd87e11c356b8d4e6bd02d472bc3d60b Signed-off-by: Jonathan Aillet <jonathan.aillet@iot.bzh>
-rw-r--r--4a-hal/4a-hal-controllers/4a-hal-controllers-cb.c7
-rw-r--r--4a-hal/4a-hal-controllers/4a-hal-controllers-mixer-link.c6
-rw-r--r--4a-hal/4a-hal-controllers/4a-hal-controllers-value-handler.c6
3 files changed, 13 insertions, 6 deletions
diff --git a/4a-hal/4a-hal-controllers/4a-hal-controllers-cb.c b/4a-hal/4a-hal-controllers/4a-hal-controllers-cb.c
index 474ea70..07ec9cc 100644
--- a/4a-hal/4a-hal-controllers/4a-hal-controllers-cb.c
+++ b/4a-hal/4a-hal-controllers/4a-hal-controllers-cb.c
@@ -286,7 +286,10 @@ int HalCtlsProcessAllHalMap(AFB_ApiT apiHandle, json_object *AlsaMapJ, struct Ct
struct CtlHalAlsaMap *ctlMaps;
- switch(json_object_get_type(AlsaMapJ)) {
+ json_type alsaMapType;
+
+ alsaMapType = json_object_get_type(AlsaMapJ);
+ switch(alsaMapType) {
case json_type_array:
currentCtlHalAlsaMapT->ctlsCount = (unsigned int) json_object_array_length(AlsaMapJ);
break;
@@ -305,7 +308,7 @@ int HalCtlsProcessAllHalMap(AFB_ApiT apiHandle, json_object *AlsaMapJ, struct Ct
ctlMaps = calloc(currentCtlHalAlsaMapT->ctlsCount, sizeof(struct CtlHalAlsaMap));
for(idx = 0; idx < currentCtlHalAlsaMapT->ctlsCount; idx++)
- err += HalCtlsProcessOneHalMapObject(apiHandle, &ctlMaps[idx], currentCtlHalAlsaMapT->ctlsCount == 1 ? AlsaMapJ : json_object_array_get_idx(AlsaMapJ, idx));
+ err += HalCtlsProcessOneHalMapObject(apiHandle, &ctlMaps[idx], alsaMapType == json_type_array ? json_object_array_get_idx(AlsaMapJ, idx) : AlsaMapJ);
currentCtlHalAlsaMapT->ctls = ctlMaps;
diff --git a/4a-hal/4a-hal-controllers/4a-hal-controllers-mixer-link.c b/4a-hal/4a-hal-controllers/4a-hal-controllers-mixer-link.c
index 346c93a..082de3a 100644
--- a/4a-hal/4a-hal-controllers/4a-hal-controllers-mixer-link.c
+++ b/4a-hal/4a-hal-controllers/4a-hal-controllers-mixer-link.c
@@ -43,9 +43,11 @@ int HalCtlsHandleMixerData(AFB_ApiT apiHandle, struct CtlHalMixerDataT *currentM
char *currentDataVerbName, *currentStreamCardId;
+ json_type currentDataType;
json_object *currentJ;
- switch(json_object_get_type(currentDataJ)) {
+ currentDataType = json_object_get_type(currentDataJ);
+ switch(currentDataType) {
case json_type_object:
currentMixerDataT->count = 1;
break;
@@ -61,7 +63,7 @@ int HalCtlsHandleMixerData(AFB_ApiT apiHandle, struct CtlHalMixerDataT *currentM
currentMixerDataT->data = (struct CtlHalMixerData *) calloc(currentMixerDataT->count, sizeof(struct CtlHalMixerData));
for(idx = 0; idx < currentMixerDataT->count; idx++) {
- if(currentMixerDataT->count > 1)
+ if(currentDataType == json_type_array)
currentJ = json_object_array_get_idx(currentDataJ, (int) idx);
else
currentJ = currentDataJ;
diff --git a/4a-hal/4a-hal-controllers/4a-hal-controllers-value-handler.c b/4a-hal/4a-hal-controllers/4a-hal-controllers-value-handler.c
index 7c493b6..b027333 100644
--- a/4a-hal/4a-hal-controllers/4a-hal-controllers-value-handler.c
+++ b/4a-hal/4a-hal-controllers/4a-hal-controllers-value-handler.c
@@ -65,9 +65,11 @@ int HalCtlsNormalizeJsonValues(AFB_ApiT apiHandle, struct CtlHalAlsaCtlPropertie
{
int err = 0, idx, count, initialValue, convertedValue;
+ json_type toConvertType;
json_object *toConvertObjectJ, *convertedValueJ, *convertedArrayJ;
- switch(json_object_get_type(toConvertJ)) {
+ toConvertType = json_object_get_type(toConvertJ);
+ switch(toConvertType) {
case json_type_array:
count = (int) json_object_array_length(toConvertJ);
break;
@@ -87,7 +89,7 @@ int HalCtlsNormalizeJsonValues(AFB_ApiT apiHandle, struct CtlHalAlsaCtlPropertie
convertedArrayJ = json_object_new_array();
for(idx = 0; idx < count; idx++) {
- if(count > 1)
+ if(toConvertType == json_type_array)
toConvertObjectJ = json_object_array_get_idx(toConvertJ, idx);
else
toConvertObjectJ = toConvertJ;