aboutsummaryrefslogtreecommitdiffstats
path: root/ALSA-afb/Alsa-AddCtl.c
diff options
context:
space:
mode:
Diffstat (limited to 'ALSA-afb/Alsa-AddCtl.c')
-rw-r--r--ALSA-afb/Alsa-AddCtl.c78
1 files changed, 4 insertions, 74 deletions
diff --git a/ALSA-afb/Alsa-AddCtl.c b/ALSA-afb/Alsa-AddCtl.c
index e30ebea..7593f2d 100644
--- a/ALSA-afb/Alsa-AddCtl.c
+++ b/ALSA-afb/Alsa-AddCtl.c
@@ -21,16 +21,14 @@
#include <systemd/sd-event.h>
#include "Alsa-ApiHat.h"
-STATIC int addOneSndCtl(struct afb_req request, snd_ctl_t *ctlDev, json_object *ctlJ) {
- snd_ctl_elem_info_t *cinfo;
+STATIC int addOneSndCtl(afb_req request, snd_ctl_t *ctlDev, json_object *ctlJ) {
int err;
- int i;
- unsigned int def_val;
json_object *jName, *jNumid, *jTmp;
const char *ctlName;
int ctlNumid, ctlMax, ctlMin, ctlStep, ctlCount, ctlSubDev;
snd_ctl_elem_type_t ctlType;
snd_ctl_elem_info_t *elemInfo;
+
// parse json ctl object
json_object_object_get_ex (ctlJ, "name" , &jName);
@@ -42,7 +40,7 @@ STATIC int addOneSndCtl(struct afb_req request, snd_ctl_t *ctlDev, json_object
ctlName = json_object_to_json_string(jName);
ctlNumid = json_object_get_int(jNumid);
-
+
// default for json_object_get_int is zero
json_object_object_get_ex (ctlJ, "min" , &jTmp);
ctlMin = json_object_get_int(jTmp);
@@ -80,7 +78,7 @@ STATIC int addOneSndCtl(struct afb_req request, snd_ctl_t *ctlDev, json_object
switch (ctlType) {
case SND_CTL_ELEM_TYPE_BOOLEAN:
- err = snd_ctl_add_boolean_elem_set(ctlDev, cinfo, 1, ctlCount);
+ err = snd_ctl_add_boolean_elem_set(ctlDev, elemInfo, 1, ctlCount);
if (err) {
afb_req_fail_f (request, "ctl-invalid-bool", "crl=%s invalid boolean data", json_object_to_json_string(ctlJ));
goto OnErrorExit;
@@ -104,77 +102,9 @@ STATIC int addOneSndCtl(struct afb_req request, snd_ctl_t *ctlDev, json_object
goto OnErrorExit;
}
-
- snd_ctl_elem_write(ctlDev, &ctlElem);
return 0;
OnErrorExit:
return -1;
}
-
-// Subscribe to every Alsa CtlEvent send by a given board
-PUBLIC void alsaAddCustomCtl (struct afb_req request) {
- snd_ctl_t *ctlDev;
- int err;
- const char *devid, *ctls;
- json_object *ctlsJ;
-
- devid = afb_req_value(request, "devid");
- if (!devid) {
- afb_req_fail_f (request, "missing-devid", "devid=xxx missing");
- goto OnErrorExit;
- }
-
- // open control interface for devid
- err = snd_ctl_open(&ctlDev, devid, 0);
- if (err < 0) {
- ctlDev=NULL;
- afb_req_fail_f (request, "devid-unknown", "SndCard devid=%s Not Found err=%s", queryValues.devid, snd_strerror(err));
- goto OnErrorExit;
- }
-
- ctls = afb_req_value(request, "ctls");
- if (!ctls) {
- afb_req_fail_f (request, "missing-ctls", "ctls=[{name:xxx, numdid=xx, ...}] missing");
- goto OnErrorExit;
- }
-
- ctlsJ = json_tokener_parse(ctls);
- if (!ctlsJ) {
- afb_req_fail_f (request, "ctls-notjson","ctls=%s not a valid json entry", ctls);
- goto OnErrorExit;
- };
-
- enum json_type jtype= json_object_get_type(ctlsJ);
- switch (jtype) {
- int error;
- json_object *ctlJ;
-
- case json_type_array:
- int count = json_object_array_length (ctlsJ);
- for (int idx=0; idx < count; idx ++) {
- ctlJ = json_object_array_get_idx (ctlsJ, idx);
- error = alsaAddCtrl (request, ctlDev, ctlsJ);
- if (error) goto OnErrorExit;
- }
- break;
-
- case json_type_object:
- error = alsaAddCtrl (request, ctlDev, ctlsJ);
- if (error) goto OnErrorExit;
- break;
-
- default:
- afb_req_fail_f (request, "ctls-notarray","ctls=%s not valid JSON control object", ctls);
- goto OnErrorExit;
- }
-
- snd_ctl_close(ctlDev);
- return;
-
- OnErrorExit:
- if (ctlDev) snd_ctl_close(ctlDev);
- return;
-}
-