summaryrefslogtreecommitdiffstats
path: root/ALSA-afb
diff options
context:
space:
mode:
Diffstat (limited to 'ALSA-afb')
-rw-r--r--ALSA-afb/Alsa-AddCtl.c2
-rw-r--r--ALSA-afb/Alsa-ApiHat.h6
-rw-r--r--ALSA-afb/Alsa-RegEvt.c33
-rw-r--r--ALSA-afb/Alsa-SetGet.c236
-rw-r--r--ALSA-afb/Alsa-Ucm.c39
5 files changed, 161 insertions, 155 deletions
diff --git a/ALSA-afb/Alsa-AddCtl.c b/ALSA-afb/Alsa-AddCtl.c
index 4635503..b7e3d90 100644
--- a/ALSA-afb/Alsa-AddCtl.c
+++ b/ALSA-afb/Alsa-AddCtl.c
@@ -183,7 +183,7 @@ STATIC json_object * addOneSndCtl(afb_req request, snd_ctl_t *ctlDev, json_obje
OnSucessExit:
alsaGetSingleCtl (ctlDev, elemId, &ctlRequest, queryMode);
if (ctlRequest.used < 0) goto OnErrorExit;
- return ctlRequest.jValues;
+ return ctlRequest.valuesJ;
OnErrorExit:
return NULL;
diff --git a/ALSA-afb/Alsa-ApiHat.h b/ALSA-afb/Alsa-ApiHat.h
index 6c9f4c3..6e50e11 100644
--- a/ALSA-afb/Alsa-ApiHat.h
+++ b/ALSA-afb/Alsa-ApiHat.h
@@ -32,7 +32,7 @@ typedef enum {
// generic structure to pass parsed query values
typedef struct {
const char *devid;
- json_object *jNumIds;
+ json_object *numidsJ;
halQueryMode mode;
int count;
} queryValuesT;
@@ -41,13 +41,13 @@ typedef struct {
typedef struct {
unsigned int numId;
json_object *jToken;
- json_object *jValues;
+ json_object *valuesJ;
int used;
} ctlRequestT;
// import from AlsaAfbBinding
extern const struct afb_binding_interface *afbIface;
-PUBLIC int alsaCheckQuery (struct afb_req request, queryValuesT *queryValues);
+PUBLIC json_object *alsaCheckQuery (struct afb_req request, queryValuesT *queryValues);
// AlseCoreSetGet exports
PUBLIC int alsaGetSingleCtl (snd_ctl_t *ctlDev, snd_ctl_elem_id_t *elemId, ctlRequestT *ctlRequest, halQueryMode queryMode);
diff --git a/ALSA-afb/Alsa-RegEvt.c b/ALSA-afb/Alsa-RegEvt.c
index 7b0a722..df6570a 100644
--- a/ALSA-afb/Alsa-RegEvt.c
+++ b/ALSA-afb/Alsa-RegEvt.c
@@ -44,6 +44,31 @@ typedef struct {
cardRegistryT *cardRegistry[MAX_SND_CARD+1];
+PUBLIC json_object *alsaCheckQuery (afb_req request, queryValuesT *queryValues) {
+
+ json_object *tmpJ;
+ int done;
+
+ // get query from request
+ json_object *queryInJ = afb_req_json(request);
+
+ done= json_object_object_get_ex (queryInJ, "devid" , &tmpJ);
+ if (!done) {
+ afb_req_fail_f(request, "devid-missing", "Invalid query='%s'", json_object_get_string(queryInJ));
+ goto OnErrorExit;
+ }
+ queryValues->devid = json_object_get_string(tmpJ);
+
+ done= json_object_object_get_ex (queryInJ, "mode" , &tmpJ);
+ if (!done) queryValues->mode=QUERY_QUIET; // default quiet
+ else queryValues->mode = json_object_get_int (tmpJ);
+
+ return queryInJ;
+
+OnErrorExit:
+ return NULL;
+}
+
// This routine is called when ALSA event are fired
STATIC int sndCtlEventCB (sd_event_source* src, int fd, uint32_t revents, void* userData) {
int err;
@@ -97,7 +122,7 @@ STATIC int sndCtlEventCB (sd_event_source* src, int fd, uint32_t revents, void*
json_object_object_add(ctlEventJ, "iface" ,json_object_new_int (iface));
json_object_object_add(ctlEventJ, "devname",json_object_new_string (devname));
}
- if (ctlRequest.jValues) (json_object_object_add(ctlEventJ, "values" ,ctlRequest.jValues));
+ if (ctlRequest.valuesJ) (json_object_object_add(ctlEventJ, "value" ,ctlRequest.valuesJ));
AFB_DEBUG( "sndCtlEventCB=%s", json_object_get_string(ctlEventJ));
afb_event_push(evtHandle->afbevt, ctlEventJ);
}
@@ -119,10 +144,8 @@ PUBLIC void alsaEvtSubcribe (afb_req request) {
snd_ctl_card_info_t *cardinfo;
queryValuesT queryValues;
-
- err = alsaCheckQuery (request, &queryValues);
- if (err) goto OnErrorExit;
-
+ json_object *queryJ = alsaCheckQuery (request, &queryValues);
+ if (!queryJ) goto OnErrorExit;
// open control interface for devid
err = snd_ctl_open(&ctlDev, queryValues.devid, SND_CTL_READONLY);
diff --git a/ALSA-afb/Alsa-SetGet.c b/ALSA-afb/Alsa-SetGet.c
index 0815f35..50b62ce 100644
--- a/ALSA-afb/Alsa-SetGet.c
+++ b/ALSA-afb/Alsa-SetGet.c
@@ -21,62 +21,69 @@
http://alsa.opensrc.org/HowTo_access_a_mixer_control
https://github.com/gch1p/alsa-volume-monitor/blob/master/main.c
https://github.com/DongheonKim/android_hardware_alsa-sound/blob/master/ALSAControl.cpp (ALSA low level API)
+ https://www.kernel.org/doc/html/v4.11/sound/index.html
*/
#define _GNU_SOURCE // needed for vasprintf
-
#include "Alsa-ApiHat.h"
-PUBLIC void NumidsListParse (queryValuesT *queryValues, ctlRequestT *ctlRequest) {
- json_object *jValues;
+PUBLIC void NumidsListParse (ActionSetGetT action, queryValuesT *queryValues, ctlRequestT *ctlRequest) {
int length;
-
- for (int idx=0; idx < queryValues->count; idx ++) {
- ctlRequest[idx].jToken = json_object_array_get_idx (queryValues->jNumIds, idx);
- ctlRequest[idx].jValues = NULL;
- ctlRequest[idx].used=0;
+ for (int idx=0; idx < queryValues->count; idx ++) {
+ json_object *jId, *valuesJ;
+ ctlRequest[idx].used=0;
+ ctlRequest[idx].valuesJ = NULL;
+
+ // when only one NUMID is provided it might not be encapsulated in a JSON array
+ if (json_type_array == json_object_get_type(queryValues->numidsJ)) ctlRequest[idx].jToken = json_object_array_get_idx (queryValues->numidsJ, idx);
+ else ctlRequest[idx].jToken=queryValues->numidsJ;
+
enum json_type jtype=json_object_get_type(ctlRequest[idx].jToken);
switch (jtype) {
- json_object *jId, *jVal;
case json_type_int:
// if NUMID is not an array then it should be an integer numid with no value
ctlRequest[idx].numId = json_object_get_int (ctlRequest[idx].jToken);
+
+ // Special SET simple short numid form [numid, [VAL1...VALX]]
+ if (action == ACTION_SET && queryValues->count == 2) {
+ ctlRequest[idx].valuesJ = json_object_array_get_idx (queryValues->numidsJ, 1);
+ queryValues->count =1; //In this form count==2 , when only one numid is to set
+ idx ++;
+ continue;
+ } else
break;
case json_type_array:
// NUMID is an array 1st slot should be numid, optionally values may come after
length=json_object_array_length (ctlRequest[idx].jToken);
- if (length < 1 || length >2) {
- ctlRequest[idx].used=-1;
- continue;
- }
+ // numid must be in 1st slot of numid json array
ctlRequest[idx].numId =json_object_get_int(json_object_array_get_idx (ctlRequest[idx].jToken, 0));
+ if (action == ACTION_GET) continue;
- if (length == 2) {
- jValues = json_object_array_get_idx (ctlRequest[idx].jToken, 1);
- if (jValues == NULL) {
- ctlRequest[idx].used=-1;
- continue;
- }
- // Value is an int or an array with potentially multiple subvalues
- ctlRequest[idx].jValues = jValues;
+ // In Write mode second value should be the value
+ if (action == ACTION_SET && length == 2) {
+ ctlRequest[idx].valuesJ = json_object_array_get_idx (ctlRequest[idx].jToken, 1);
+ continue;
}
+
+ // no numid value
+ ctlRequest[idx].used=-1;
break;
case json_type_object:
// numid+values formated as {id:xxx, val:[aa,bb...,nn]}
- if (!json_object_object_get_ex (ctlRequest[idx].jToken,"id", &jId) || !json_object_object_get_ex (ctlRequest[idx].jToken,"val",&jVal)) {
+ if (!json_object_object_get_ex (ctlRequest[idx].jToken,"id", &jId) || !json_object_object_get_ex (ctlRequest[idx].jToken,"val",&valuesJ)) {
AFB_NOTICE("Invalid Json=%s missing 'id'|'val'", json_object_get_string(ctlRequest[idx].jToken));
ctlRequest[idx].used=-1;
} else {
ctlRequest[idx].numId =json_object_get_int(jId);
- ctlRequest[idx].jValues =jVal;
+ if (action == ACTION_SET) ctlRequest[idx].valuesJ=valuesJ;
}
-
+ break;
default:
ctlRequest[idx].used=-1;
@@ -84,59 +91,6 @@ PUBLIC void NumidsListParse (queryValuesT *queryValues, ctlRequestT *ctlRequest)
}
}
-PUBLIC int alsaCheckQuery (afb_req request, queryValuesT *queryValues) {
- queryValues->devid = afb_req_value(request, "devid");
- if (queryValues->devid == NULL) goto OnErrorExit;
- const char *numids;
- json_object *jNumIds;
-
- const char *rqtmode = afb_req_value(request, "mode");
- if (!rqtmode) queryValues->mode=QUERY_QUIET; // default quiet
- else if (rqtmode && ! sscanf (rqtmode, "%d", (int)&queryValues->mode)) {
- json_object *query = afb_req_json(request);
-
- afb_req_fail_f (request, "mode-notinteger","Query=%s mode not integer &mode=%s&", json_object_get_string(query), rqtmode);
- goto OnErrorExit;
- };
-
- // no NumId is interpreted as ALL for get and error for set
- numids = afb_req_value(request, "numid");
- if (numids == NULL) {
- queryValues->count=0;
- goto OnExit;
- }
-
- jNumIds = json_tokener_parse(numids);
- if (!jNumIds) {
- afb_req_fail_f (request, "numids-notjson","numids=%s not a valid json entry", numids);
- goto OnErrorExit;
- };
-
- enum json_type jtype= json_object_get_type(jNumIds);
- switch (jtype) {
- case json_type_array:
- queryValues->jNumIds = jNumIds;
- queryValues->count = json_object_array_length (jNumIds);
- break;
-
- case json_type_int:
- queryValues->count = 1;
- queryValues->jNumIds = json_object_new_array ();
- json_object_array_add (queryValues->jNumIds, jNumIds);
- break;
-
- default:
- afb_req_fail_f (request, "numid-notarray","NumId=%s NumId not valid JSON array", numids);
- goto OnErrorExit;
- }
-
-OnExit:
- return 0;
-
-OnErrorExit:
- return 1;
-}
-
STATIC json_object *DB2StringJsonOject (long dB) {
char label [20];
if (dB < 0) {
@@ -380,14 +334,14 @@ STATIC json_object* alsaCardProbe (const char *rqtSndId) {
int err;
if ((err = snd_ctl_open(&handle, rqtSndId, 0)) < 0) {
- AFB_INFO ("alsaCardProbe [%s] Not Found", rqtSndId);
+ AFB_INFO ("alsaCardProbe '%s' Not Found", rqtSndId);
return NULL;
}
snd_ctl_card_info_alloca(&cardinfo);
if ((err = snd_ctl_card_info(handle, cardinfo)) < 0) {
snd_ctl_close(handle);
- AFB_WARNING ("SndCard [%s] info error: %s", rqtSndId, snd_strerror(err));
+ AFB_WARNING ("SndCard '%s' info error: %s", rqtSndId, snd_strerror(err));
return NULL;
}
@@ -427,7 +381,7 @@ PUBLIC void alsaGetInfo (afb_req request) {
// only one card was requested let's probe it
ctlDev = alsaCardProbe (rqtSndId);
if (ctlDev != NULL) afb_req_success(request, ctlDev, NULL);
- else afb_req_fail_f (request, "sndscard-notfound", "SndCard [%s] Not Found", rqtSndId);
+ else afb_req_fail_f (request, "sndscard-notfound", "SndCard '%s' Not Found", rqtSndId);
} else {
// return an array of ctlDev
@@ -487,22 +441,22 @@ PUBLIC int alsaSetSingleCtl (snd_ctl_t *ctlDev, snd_ctl_elem_id_t *elemId, ctlRe
snd_ctl_elem_info_alloca(&elemInfo);
snd_ctl_elem_info_set_id(elemInfo, elemId); // map ctlInfo to ctlId elemInfo is updated !!!
if (snd_ctl_elem_info(ctlDev, elemInfo) < 0) {
- AFB_NOTICE( "Fail to load ALSA NUMID=%d Values=[%s]", ctlRequest->numId, json_object_get_string(ctlRequest->jValues));
+ AFB_NOTICE( "Fail to load ALSA NUMID=%d Values='%s'", ctlRequest->numId, json_object_get_string(ctlRequest->valuesJ));
goto OnErrorExit;
}
if (!snd_ctl_elem_info_is_writable(elemInfo)) {
- AFB_NOTICE( "Not Writable ALSA NUMID=%d Values=[%s]", ctlRequest->numId, json_object_get_string(ctlRequest->jValues));
+ AFB_NOTICE( "Not Writable ALSA NUMID=%d Values='%s'", ctlRequest->numId, json_object_get_string(ctlRequest->valuesJ));
goto OnErrorExit;
}
count = snd_ctl_elem_info_get_count (elemInfo);
if (count == 0) goto OnErrorExit;
-
- enum json_type jtype= json_object_get_type(ctlRequest->jValues);
+
+ enum json_type jtype= json_object_get_type(ctlRequest->valuesJ);
switch (jtype) {
case json_type_array:
- length = json_object_array_length (ctlRequest->jValues);
+ length = json_object_array_length (ctlRequest->valuesJ);
valueIsArray=1;
break;
case json_type_int:
@@ -510,14 +464,13 @@ PUBLIC int alsaSetSingleCtl (snd_ctl_t *ctlDev, snd_ctl_elem_id_t *elemId, ctlRe
valueIsArray=0;
break;
default:
- count =0;
length = 0;
break;
}
- if (count == 0 || count < length) {
- AFB_NOTICE( "Invalid values NUMID='%d' Values='%s' count='%d' wanted='%d'", ctlRequest->numId, json_object_get_string(ctlRequest->jValues), length, count);
+ if (length == 0) {
+ AFB_NOTICE( "Invalid values NUMID='%d' Values='%s' count='%d' wanted='%d'", ctlRequest->numId, json_object_get_string(ctlRequest->valuesJ), length, count);
goto OnErrorExit;
}
@@ -526,12 +479,16 @@ PUBLIC int alsaSetSingleCtl (snd_ctl_t *ctlDev, snd_ctl_elem_id_t *elemId, ctlRe
if (snd_ctl_elem_read(ctlDev, elemData) < 0) goto OnErrorExit;
// Loop on every control value and push to sndcard
- for (int index=0; index < count && index < length; index++) {
+ for (int index=0; index < count; index++) {
json_object *element;
int value;
-
- if (valueIsArray) element= json_object_array_get_idx(ctlRequest->jValues, index);
- else element= ctlRequest->jValues;
+
+ // when not enough value duplicate last provided one
+ if (!valueIsArray) element= ctlRequest->valuesJ;
+ else {
+ if (index < length) element= json_object_array_get_idx(ctlRequest->valuesJ, index);
+ else element= json_object_array_get_idx(ctlRequest->valuesJ, length-1);
+ }
value= json_object_get_int (element);
snd_ctl_elem_value_set_integer(elemData, index, value);
@@ -539,7 +496,7 @@ PUBLIC int alsaSetSingleCtl (snd_ctl_t *ctlDev, snd_ctl_elem_id_t *elemId, ctlRe
err = snd_ctl_elem_write(ctlDev, elemData);
if (err < 0) {
- AFB_NOTICE( "Fail to write ALSA NUMID=%d Values=[%s] Error=%s", ctlRequest->numId, json_object_get_string(ctlRequest->jValues), snd_strerror(err));
+ AFB_NOTICE( "Fail to write ALSA NUMID=%d Values='%s' Error=%s", ctlRequest->numId, json_object_get_string(ctlRequest->valuesJ), snd_strerror(err));
goto OnErrorExit;
}
@@ -576,11 +533,11 @@ PUBLIC int alsaGetSingleCtl (snd_ctl_t *ctlDev, snd_ctl_elem_id_t *elemId, ctlRe
int numid= snd_ctl_elem_info_get_numid(elemInfo);
- ctlRequest->jValues= json_object_new_object();
- json_object_object_add (ctlRequest->jValues,"numid" , json_object_new_int(numid));
- if (queryMode >= 1) json_object_object_add (ctlRequest->jValues,"name" , json_object_new_string(snd_ctl_elem_id_get_name (elemId)));
- if (queryMode >= 2) json_object_object_add (ctlRequest->jValues,"iface" , json_object_new_string(snd_ctl_elem_iface_name(snd_ctl_elem_id_get_interface(elemId))));
- if (queryMode >= 3) json_object_object_add (ctlRequest->jValues,"actif", json_object_new_boolean(!snd_ctl_elem_info_is_inactive(elemInfo)));
+ ctlRequest->valuesJ= json_object_new_object();
+ json_object_object_add (ctlRequest->valuesJ,"id" , json_object_new_int(numid));
+ if (queryMode >= 1) json_object_object_add (ctlRequest->valuesJ,"name" , json_object_new_string(snd_ctl_elem_id_get_name (elemId)));
+ if (queryMode >= 2) json_object_object_add (ctlRequest->valuesJ,"iface" , json_object_new_string(snd_ctl_elem_iface_name(snd_ctl_elem_id_get_interface(elemId))));
+ if (queryMode >= 3) json_object_object_add (ctlRequest->valuesJ,"actif", json_object_new_boolean(!snd_ctl_elem_info_is_inactive(elemInfo)));
json_object *jsonValuesCtl = json_object_new_array();
for (idx = 0; idx < count; idx++) { // start from one in amixer.c !!!
@@ -618,7 +575,7 @@ PUBLIC int alsaGetSingleCtl (snd_ctl_t *ctlDev, snd_ctl_elem_id_t *elemId, ctlRe
break;
}
}
- json_object_object_add (ctlRequest->jValues,"val",jsonValuesCtl);
+ json_object_object_add (ctlRequest->valuesJ,"val",jsonValuesCtl);
if (queryMode >= 1) { // in simple mode do not print usable values
json_object *jsonClassCtl = json_object_new_object();
@@ -653,18 +610,18 @@ PUBLIC int alsaGetSingleCtl (snd_ctl_t *ctlDev, snd_ctl_elem_id_t *elemId, ctlRe
}
// add collected class info with associated ACLs
- json_object_object_add (ctlRequest->jValues,"ctl", jsonClassCtl);
+ json_object_object_add (ctlRequest->valuesJ,"ctl", jsonClassCtl);
- if (queryMode >= QUERY_FULL) json_object_object_add (ctlRequest->jValues,"acl" , getControlAcl (elemInfo));
+ if (queryMode >= QUERY_FULL) json_object_object_add (ctlRequest->valuesJ,"acl" , getControlAcl (elemInfo));
// check for tlv [direct port from amixer.c]
if (snd_ctl_elem_info_is_tlv_readable(elemInfo)) {
- unsigned int *tlv = alloca(4096);
+ unsigned int *tlv = alloca(TLV_BYTE_SIZE);
if ((err = snd_ctl_elem_tlv_read(ctlDev, elemId, tlv, 4096)) < 0) {
fprintf (stderr, "Control %s element TLV read error\n", snd_strerror(err));
goto OnErrorExit;
} else {
- json_object_object_add (ctlRequest->jValues,"tlv", decodeTlv (tlv, 4096, queryMode));
+ json_object_object_add (ctlRequest->valuesJ,"tlv", decodeTlv (tlv, TLV_BYTE_SIZE, queryMode));
}
}
}
@@ -678,38 +635,61 @@ PUBLIC int alsaGetSingleCtl (snd_ctl_t *ctlDev, snd_ctl_elem_id_t *elemId, ctlRe
}
// assign multiple control to the same value
-STATIC void alsaSetGetCtls (afb_req request, ActionSetGetT action) {
+STATIC void alsaSetGetCtls (ActionSetGetT action, afb_req request) {
ctlRequestT *ctlRequest;
const char *warmsg=NULL;
- int err=0, status=0;
+ int err=0, status=0, done;
unsigned int ctlCount;
snd_ctl_t *ctlDev;
snd_ctl_elem_list_t *ctlList;
json_object *sndctls=json_object_new_array();;
queryValuesT queryValues;
+ json_object *queryJ, *numidsJ;
- err = alsaCheckQuery (request, &queryValues);
- if (err) goto OnErrorExit;
+ queryJ = alsaCheckQuery (request, &queryValues);
+ if (!queryJ) goto OnErrorExit;
+ // Prase Numids + optional values
+ done= json_object_object_get_ex (queryJ, "numid" , &numidsJ);
+ if (!done) queryValues.count=0;
+ else {
+ enum json_type jtype= json_object_get_type(numidsJ);
+ switch (jtype) {
+ case json_type_array:
+ queryValues.numidsJ = numidsJ;
+ queryValues.count = json_object_array_length (numidsJ);
+ break;
+ case json_type_int:
+ case json_type_object:
+ queryValues.count = 1;
+ queryValues.numidsJ = numidsJ;
+ break;
+
+ default:
+ afb_req_fail_f (request, "numid-notarray","NumId=%s NumId not valid JSON array", json_object_get_string(numidsJ));
+ goto OnErrorExit;
+ }
+ }
+
if ((err = snd_ctl_open(&ctlDev, queryValues.devid, 0)) < 0) {
- afb_req_fail_f (request, "sndcrl-notfound","devid=[%s] load fail error=%s\n", queryValues.devid, snd_strerror(err));
+ afb_req_fail_f (request, "sndcrl-notfound","devid='%s' load fail error=%s\n", queryValues.devid, snd_strerror(err));
goto OnErrorExit;
}
snd_ctl_elem_list_alloca(&ctlList);
if ((err = snd_ctl_elem_list (ctlDev, ctlList)) < 0) {
- afb_req_fail_f (request, "listInit-failed","devid=[%s] load fail error=%s\n", queryValues.devid, snd_strerror(err));
+ afb_req_fail_f (request, "listInit-failed","devid='%s' load fail error=%s\n", queryValues.devid, snd_strerror(err));
goto OnErrorExit;
}
if ((err = snd_ctl_elem_list_alloc_space(ctlList, snd_ctl_elem_list_get_count(ctlList))) < 0) {
- afb_req_fail_f (request, "listAlloc-failed","devid=[%s] load fail error=%s\n", queryValues.devid, snd_strerror(err));
+ afb_req_fail_f (request, "listAlloc-failed","devid='%s' load fail error=%s\n", queryValues.devid, snd_strerror(err));
goto OnErrorExit;
}
if ((err = snd_ctl_elem_list (ctlDev, ctlList)) < 0) {
- afb_req_fail_f (request, "listOpen-failed","devid=[%s] load fail error=%s\n", queryValues.devid, snd_strerror(err));
+ afb_req_fail_f (request, "listOpen-failed","devid='%s' load fail error=%s\n", queryValues.devid, snd_strerror(err));
goto OnErrorExit;
}
@@ -719,7 +699,7 @@ STATIC void alsaSetGetCtls (afb_req request, ActionSetGetT action) {
ctlRequest= alloca (sizeof(ctlRequestT)*(ctlCount));
} else {
ctlRequest= alloca (sizeof(ctlRequestT)*(queryValues.count));
- NumidsListParse (&queryValues, ctlRequest);
+ NumidsListParse (action, &queryValues, ctlRequest);
}
// Loop on all ctlDev controls
@@ -754,45 +734,47 @@ STATIC void alsaSetGetCtls (afb_req request, ActionSetGetT action) {
switch (action) {
case ACTION_GET:
err = alsaGetSingleCtl (ctlDev, elemId, &ctlRequest[jdx], queryValues.mode);
- break;
+ break;
case ACTION_SET:
err = alsaSetSingleCtl (ctlDev, elemId, &ctlRequest[jdx]);
+ break;
default:
err = 1;
}
if (err) status++;
else {
- json_object_array_add (sndctls, ctlRequest[jdx].jValues);
+ if (action == ACTION_GET) json_object_array_add (sndctls, ctlRequest[jdx].valuesJ);
}
}
}
// if we had error let's add them into response message info
- json_object *warnings = json_object_new_array();
+ json_object *warningsJ = json_object_new_array();
for (int jdx=0; jdx < queryValues.count; jdx++) {
if (ctlRequest[jdx].used <= 0) {
json_object *failctl = json_object_new_object();
json_object_object_add (failctl, "numid", ctlRequest[jdx].jToken);
- if (ctlRequest[jdx].jValues)
- json_object_object_add(failctl, "values", ctlRequest[jdx].jValues);
+ if (ctlRequest[jdx].valuesJ) json_object_object_add(failctl, "value", ctlRequest[jdx].valuesJ);
+
+ AFB_NOTICE ("*** jToken=%s value=%s", json_object_get_string(ctlRequest[jdx].jToken), json_object_get_string(ctlRequest[jdx].valuesJ));
- if (ctlRequest[jdx].numId == -1) json_object_object_add (failctl, "info", json_object_new_string ("Invalid NumID"));
+ if (ctlRequest[jdx].numId == -1) json_object_object_add (failctl, "error", json_object_new_string ("Numid Invalid"));
else {
- if (ctlRequest[jdx].used == 0) json_object_object_add (failctl, "info", json_object_new_string ("Does Not Exist"));
- if (ctlRequest[jdx].used == -1) json_object_object_add (failctl, "info", json_object_new_string ("Invalid Value"));
+ if (ctlRequest[jdx].used == 0) json_object_object_add (failctl, "error", json_object_new_string ("Numid Does Not Exist"));
+ if (ctlRequest[jdx].used == -1) json_object_object_add (failctl, "error", json_object_new_string ("Value invalid"));
}
- json_object_array_add (warnings, failctl);
+ json_object_array_add (warningsJ, failctl);
}
- /* WARNING!!!! Check with Jose why following put free jValues
+ /* WARNING!!!! Check with Jose why following put free valuesJ
if (ctlRequest[jdx].jToken) json_object_put(ctlRequest[jdx].jToken);
- if (ctlRequest[jdx].jValues) json_object_put(ctlRequest[jdx].jValues);
+ if (ctlRequest[jdx].valuesJ) json_object_put(ctlRequest[jdx].valuesJ);
*/
}
- if (json_object_array_length(warnings)) warmsg=json_object_get_string (warnings);
- else json_object_put(warnings);
+ if (json_object_array_length(warningsJ) > 0) warmsg=json_object_get_string (warningsJ);
+ else json_object_put(warningsJ);
// send response+warning if any
afb_req_success (request, sndctls, warmsg);
@@ -803,11 +785,11 @@ STATIC void alsaSetGetCtls (afb_req request, ActionSetGetT action) {
}
PUBLIC void alsaGetCtls (afb_req request) {
- alsaSetGetCtls (request, ACTION_GET);
+ alsaSetGetCtls (ACTION_GET, request);
}
PUBLIC void alsaSetCtls (afb_req request) {
- alsaSetGetCtls (request, ACTION_SET);
+ alsaSetGetCtls (ACTION_SET, request);
}
diff --git a/ALSA-afb/Alsa-Ucm.c b/ALSA-afb/Alsa-Ucm.c
index f512417..ee2b36d 100644
--- a/ALSA-afb/Alsa-Ucm.c
+++ b/ALSA-afb/Alsa-Ucm.c
@@ -111,16 +111,15 @@ STATIC int alsaUseCaseOpen (struct afb_req request, queryValuesT *queryValues, i
PUBLIC void alsaUseCaseQuery(struct afb_req request) {
- int err, verbCount, ucmIdx;
+ int verbCount, ucmIdx;
const char **verbList;
snd_use_case_mgr_t *ucmHandle;
queryValuesT queryValues;
json_object *ucmJs;
const char *cardName;
-
- err = alsaCheckQuery (request, &queryValues);
- if (err) goto OnErrorExit;
+ json_object *queryJ = alsaCheckQuery (request, &queryValues);
+ if (!queryJ) goto OnErrorExit;
ucmIdx = alsaUseCaseOpen (request, &queryValues, TRUE);
if (ucmIdx < 0) goto OnErrorExit;
@@ -158,7 +157,7 @@ PUBLIC void alsaUseCaseQuery(struct afb_req request) {
json_object_array_add (devsJ, devJ);
}
json_object_object_add(ucmJ,"devices", devsJ);
- snd_use_case_free_list(devList, err);
+ snd_use_case_free_list(devList, devCount);
}
snprintf (identifier, sizeof(identifier), "_modifiers/%s", verbList[idx]);
@@ -174,7 +173,7 @@ PUBLIC void alsaUseCaseQuery(struct afb_req request) {
json_object_array_add (modsJ, modJ);
}
json_object_object_add(ucmJ,"modifiers", modsJ);
- snd_use_case_free_list(modList, err);
+ snd_use_case_free_list(modList, modCount);
}
snprintf (identifier, sizeof(identifier), "TQ/%s", verbList[idx]);
@@ -190,14 +189,14 @@ PUBLIC void alsaUseCaseQuery(struct afb_req request) {
json_object_array_add (tqsJ, tqJ);
}
json_object_object_add(ucmJ,"tqs", tqsJ);
- snd_use_case_free_list(tqList, err);
+ snd_use_case_free_list(tqList, tqCount);
}
json_object_array_add (ucmJs, ucmJ);
}
afb_req_success (request, ucmJs, NULL);
- snd_use_case_free_list(verbList, err);
+ snd_use_case_free_list(verbList, verbCount);
OnErrorExit:
return;
@@ -235,14 +234,15 @@ STATIC json_object *ucmGetValue (ucmHandleT *ucmHandle, const char *verb, const
}
PUBLIC void alsaUseCaseGet (struct afb_req request) {
- int err, ucmIdx, labelCount;
+ int ucmIdx, labelCount;
queryValuesT queryValues;
json_object *jResponse = json_object_new_object();
json_object *jWarnings = json_object_new_array();
const char *warnings=NULL;
- err = alsaCheckQuery (request, &queryValues);
- if (err) goto OnErrorExit;
+ json_object *queryJ = alsaCheckQuery (request, &queryValues);
+ if (!queryJ) goto OnErrorExit;
+;
ucmIdx = alsaUseCaseOpen (request, &queryValues, TRUE);
if (ucmIdx < 0) goto OnErrorExit;
@@ -261,7 +261,7 @@ PUBLIC void alsaUseCaseGet (struct afb_req request) {
// device selection is handle as a modifier
if (dev) mod=dev;
- const char *labels = afb_req_value(request, "values");
+ const char *labels = afb_req_value(request, "value");
if (!labels) {
afb_req_fail_f (request, "ucmget-labels", "SndCard devid=[%s] name=[%s] UCM values name missing", queryValues.devid, cardName);
goto OnErrorExit;
@@ -323,8 +323,9 @@ PUBLIC void alsaUseCaseSet(struct afb_req request) {
queryValuesT queryValues;
json_object *jResponse = json_object_new_object();
- err = alsaCheckQuery (request, &queryValues);
- if (err) goto OnErrorExit;
+ json_object *queryJ = alsaCheckQuery (request, &queryValues);
+ if (!queryJ) goto OnErrorExit;
+
ucmIdx = alsaUseCaseOpen (request, &queryValues, TRUE);
if (ucmIdx < 0) goto OnErrorExit;
@@ -362,7 +363,7 @@ PUBLIC void alsaUseCaseSet(struct afb_req request) {
}
// label are requested transfert request to get
- if (afb_req_value(request, "values")) return alsaUseCaseGet(request);
+ if (afb_req_value(request, "value")) return alsaUseCaseGet(request);
if (queryValues.mode <= 3) {
json_object *jValue;
@@ -388,8 +389,8 @@ PUBLIC void alsaUseCaseReset (struct afb_req request) {
int err, ucmIdx;
queryValuesT queryValues;
- err = alsaCheckQuery (request, &queryValues);
- if (err) goto OnErrorExit;
+ json_object *queryJ = alsaCheckQuery (request, &queryValues);
+ if (!queryJ) goto OnErrorExit;
ucmIdx = alsaUseCaseOpen (request, &queryValues, FALSE);
if (ucmIdx < 0) goto OnErrorExit;
@@ -410,8 +411,8 @@ PUBLIC void alsaUseCaseClose (struct afb_req request) {
int err, ucmIdx;
queryValuesT queryValues;
- err = alsaCheckQuery (request, &queryValues);
- if (err) goto OnErrorExit;
+ json_object *queryJ = alsaCheckQuery (request, &queryValues);
+ if (!queryJ) goto OnErrorExit;
ucmIdx = alsaUseCaseOpen (request, &queryValues, FALSE);
if (ucmIdx < 0) goto OnErrorExit;