summaryrefslogtreecommitdiffstats
path: root/4a-hal/4a-hal-controllers
diff options
context:
space:
mode:
authorJonathan Aillet <jonathan.aillet@iot.bzh>2018-12-14 22:39:22 +0100
committerJonathan Aillet <jonathan.aillet@iot.bzh>2018-12-20 11:10:17 +0100
commit07c240d783974970138ab94a4221935edf8ae9b6 (patch)
tree09cbdbc96781c44f1798509e03d5df5f5bed4e50 /4a-hal/4a-hal-controllers
parent03776c5a3fa9adb02a8ebb43dcc693d116390e64 (diff)
Add a function to get values of an alsa control
Rework communication with 'alsacore' binding to be able to get current ALSA controls values. Bug-AGL: SPEC-1313 Change-Id: If1b4b9bdc49849772075e184768f572ac88fe6c3 Signed-off-by: Jonathan Aillet <jonathan.aillet@iot.bzh>
Diffstat (limited to '4a-hal/4a-hal-controllers')
-rw-r--r--4a-hal/4a-hal-controllers/4a-hal-controllers-alsacore-link.c107
-rw-r--r--4a-hal/4a-hal-controllers/4a-hal-controllers-alsacore-link.h2
-rw-r--r--4a-hal/4a-hal-controllers/4a-hal-controllers-cb.c2
3 files changed, 86 insertions, 25 deletions
diff --git a/4a-hal/4a-hal-controllers/4a-hal-controllers-alsacore-link.c b/4a-hal/4a-hal-controllers/4a-hal-controllers-alsacore-link.c
index 01b4ab2..cc29dc9 100644
--- a/4a-hal/4a-hal-controllers/4a-hal-controllers-alsacore-link.c
+++ b/4a-hal/4a-hal-controllers/4a-hal-controllers-alsacore-link.c
@@ -182,7 +182,7 @@ int HalCtlsSubscribeToAlsaCardEvent(AFB_ApiT apiHandle, char *cardId)
return err;
}
-int HalCtlsGetAlsaCtlInfo(AFB_ApiT apiHandle, char *cardId, struct CtlHalAlsaCtl *currentAlsaCtl)
+int HalCtlsGetAlsaCtlInfo(AFB_ApiT apiHandle, char *cardId, struct CtlHalAlsaCtl *currentAlsaCtl, json_object **returnedDataJ)
{
int err = 0;
@@ -190,7 +190,9 @@ int HalCtlsGetAlsaCtlInfo(AFB_ApiT apiHandle, char *cardId, struct CtlHalAlsaCtl
enum CallError returnedError;
- json_object *queryJ, *returnedJ = NULL;
+ json_object *queryJ, *returnedJ;
+
+ *returnedDataJ = NULL;
if(! apiHandle) {
AFB_ApiError(apiHandle, "Api handle not available");
@@ -208,21 +210,21 @@ int HalCtlsGetAlsaCtlInfo(AFB_ApiT apiHandle, char *cardId, struct CtlHalAlsaCtl
}
if(currentAlsaCtl->name && currentAlsaCtl->numid > 0) {
- AFB_ApiError(apiHandle,
- "Can't have both a control name (%s) and a control uid (%i)",
+ AFB_ApiDebug(apiHandle,
+ "Both a control name (%s) and a control uid (%i) are specified, control uid will be used",
currentAlsaCtl->name,
currentAlsaCtl->numid);
- return -4;
+ }
+
+ if(currentAlsaCtl->numid > 0) {
+ wrap_json_pack(&queryJ, "{s:s s:i s:i}", "devid", cardId, "ctl", currentAlsaCtl->numid, "mode", 3);
}
else if(currentAlsaCtl->name) {
wrap_json_pack(&queryJ, "{s:s s:s s:i}", "devid", cardId, "ctl", currentAlsaCtl->name, "mode", 3);
}
- else if(currentAlsaCtl->numid > 0) {
- wrap_json_pack(&queryJ, "{s:s s:i s:i}", "devid", cardId, "ctl", currentAlsaCtl->numid, "mode", 3);
- }
else {
AFB_ApiError(apiHandle, "Need at least a control name or a control uid");
- return -5;
+ return -4;
}
if(AFB_ServiceSync(apiHandle, ALSACORE_API, ALSACORE_CTLGET_VERB, queryJ, &returnedJ)) {
@@ -234,35 +236,94 @@ int HalCtlsGetAlsaCtlInfo(AFB_ApiT apiHandle, char *cardId, struct CtlHalAlsaCtl
ALSACORE_API,
returnedStatus ? returnedStatus : "not returned",
returnedInfo ? returnedInfo : "not returned");
- err = -6;
+ return -5;
}
else if(currentAlsaCtl->name && wrap_json_unpack(returnedJ, "{s:{s:i}}", "response", "id", &currentAlsaCtl->numid)) {
AFB_ApiError(apiHandle, "Can't find alsa control 'id' from control 'name': '%s' on device '%s'", currentAlsaCtl->name, cardId);
- err = -7;
+ err = -6;
}
else if(! json_object_object_get_ex(returnedJ, "response", NULL)) {
AFB_ApiError(apiHandle, "Can't find alsa control 'id': %i on device '%s'", currentAlsaCtl->numid, cardId);
- err = -8;
+ err = -7;
+ }
+
+ if(err)
+ json_object_put(returnedJ);
+ else
+ *returnedDataJ = returnedJ;
+
+ return err;
+}
+
+int HalCtlsUpdateAlsaCtlProperties(AFB_ApiT apiHandle, char *cardId, struct CtlHalAlsaCtl *currentAlsaCtl)
+{
+ int err = 0;
+
+ json_object *returnedDataJ;
+
+ if((err = HalCtlsGetAlsaCtlInfo(apiHandle, cardId, currentAlsaCtl, &returnedDataJ))) {
+ return err;
}
// TBD JAI : get dblinear/dbminmax/... values
- else if(wrap_json_unpack(returnedJ, "{s:{s:{s?:i s?:i s?:i s?:i s?:i}}}",
- "response",
- "ctl",
- "type", (int *) &currentAlsaCtl->alsaCtlProperties.type,
- "count", &currentAlsaCtl->alsaCtlProperties.count,
- "min", &currentAlsaCtl->alsaCtlProperties.minval,
- "max", &currentAlsaCtl->alsaCtlProperties.maxval,
- "step", &currentAlsaCtl->alsaCtlProperties.step)) {
+ else if(wrap_json_unpack(returnedDataJ,
+ "{s:{s:{s?:i s?:i s?:i s?:i s?:i}}}",
+ "response",
+ "ctl",
+ "type", (int *) &currentAlsaCtl->alsaCtlProperties.type,
+ "count", &currentAlsaCtl->alsaCtlProperties.count,
+ "min", &currentAlsaCtl->alsaCtlProperties.minval,
+ "max", &currentAlsaCtl->alsaCtlProperties.maxval,
+ "step", &currentAlsaCtl->alsaCtlProperties.step)) {
AFB_ApiError(apiHandle,
"Didn't succeed to get control %i properties on device '%s' : '%s'",
currentAlsaCtl->numid,
cardId,
- json_object_get_string(returnedJ));
+ json_object_get_string(returnedDataJ));
+
+ err = -8;
+ }
+
+ if(returnedDataJ)
+ json_object_put(returnedDataJ);
+
+ return err;
+}
+
+int HalCtlsGetAlsaCtlValues(AFB_ApiT apiHandle, char *cardId, struct CtlHalAlsaCtl *currentAlsaCtl, json_object **returnedValuesJ)
+{
+ int err = 0;
+
+ json_object *returnedDataJ = NULL, *returnedValuesArrayJ;
+
+ *returnedValuesJ = NULL;
+
+ if((err = HalCtlsGetAlsaCtlInfo(apiHandle, cardId, currentAlsaCtl, &returnedDataJ))) {
+ return err;
+ }
+ else if(wrap_json_unpack(returnedDataJ, "{s:{s:o}}", "response", "val", &returnedValuesArrayJ)) {
+ AFB_ApiError(apiHandle,
+ "Didn't succeed to get control %i values on device '%s' : '%s'",
+ currentAlsaCtl->numid,
+ cardId,
+ json_object_get_string(returnedValuesArrayJ));
+
+ err = -8;
+ }
+ else if(! json_object_is_type(returnedValuesArrayJ, json_type_array)) {
+ AFB_ApiError(apiHandle,
+ "Json returned by control %i values on device '%s' are not an array ('%s')",
+ currentAlsaCtl->numid,
+ cardId,
+ json_object_get_string(returnedValuesArrayJ));
+
err = -9;
}
- if(returnedJ)
- json_object_put(returnedJ);
+ if(! err)
+ *returnedValuesJ = json_object_get(returnedValuesArrayJ);
+
+ if(returnedDataJ)
+ json_object_put(returnedDataJ);
return err;
}
diff --git a/4a-hal/4a-hal-controllers/4a-hal-controllers-alsacore-link.h b/4a-hal/4a-hal-controllers/4a-hal-controllers-alsacore-link.h
index b11993b..45dc996 100644
--- a/4a-hal/4a-hal-controllers/4a-hal-controllers-alsacore-link.h
+++ b/4a-hal/4a-hal-controllers/4a-hal-controllers-alsacore-link.h
@@ -81,7 +81,7 @@ uint8_t HalCtlsFreeAlsaCtlsMap(struct CtlHalAlsaMapT *alsaCtlsMap);
// HAL controllers alsacore calls funtions
int HalCtlsGetCardIdByCardPath(AFB_ApiT apiHandle, char *devPath);
int HalCtlsSubscribeToAlsaCardEvent(AFB_ApiT apiHandle, char *cardId);
-int HalCtlsGetAlsaCtlInfo(AFB_ApiT apiHandle, char *cardId, struct CtlHalAlsaCtl *currentAlsaCtl);
+int HalCtlsUpdateAlsaCtlProperties(AFB_ApiT apiHandle, char *cardId, struct CtlHalAlsaCtl *currentAlsaCtl);
int HalCtlsSetAlsaCtlValue(AFB_ApiT apiHandle, char *cardId, int ctlId, json_object *valuesJ);
int HalCtlsCreateAlsaCtl(AFB_ApiT apiHandle, char *cardId, struct CtlHalAlsaCtl *alsaCtlToCreate);
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 4527c23..b9ba537 100644
--- a/4a-hal/4a-hal-controllers/4a-hal-controllers-cb.c
+++ b/4a-hal/4a-hal-controllers/4a-hal-controllers-cb.c
@@ -233,7 +233,7 @@ int HalCtlsHandleOneHalMapObject(AFB_ApiT apiHandle, char *cardId, struct CtlHal
return -1;
}
}
- else if(HalCtlsGetAlsaCtlInfo(apiHandle, cardId, &alsaMap->ctl)) {
+ else if(HalCtlsUpdateAlsaCtlProperties(apiHandle, cardId, &alsaMap->ctl)) {
AFB_ApiError(apiHandle, "An error happened when trying to get existing alsa control info");
return -2;
}