aboutsummaryrefslogtreecommitdiffstats
path: root/AlsaSound/CoreBinding
diff options
context:
space:
mode:
authorfulup <fulup.arfoll@iot.bzh>2017-03-30 22:08:53 +0200
committerfulup <fulup.arfoll@iot.bzh>2017-03-30 22:08:53 +0200
commit86fb6219e8142781f629d72b4c5f74592e27af82 (patch)
tree30880082bbdf683a8f4bd55c7257d52127dc69ab /AlsaSound/CoreBinding
parent36bea37e9781276e7162292ea6933a7f6404c5ee (diff)
Added Alsa Set Control
Diffstat (limited to 'AlsaSound/CoreBinding')
-rw-r--r--AlsaSound/CoreBinding/AlsaCoreBinding.c5
-rw-r--r--AlsaSound/CoreBinding/AlsaCoreBinding.h2
-rw-r--r--AlsaSound/CoreBinding/AlsaCtlSetGet.c57
3 files changed, 45 insertions, 19 deletions
diff --git a/AlsaSound/CoreBinding/AlsaCoreBinding.c b/AlsaSound/CoreBinding/AlsaCoreBinding.c
index 19a7f3b..d866daf 100644
--- a/AlsaSound/CoreBinding/AlsaCoreBinding.c
+++ b/AlsaSound/CoreBinding/AlsaCoreBinding.c
@@ -37,10 +37,11 @@ static const struct afb_verb_desc_v1 binding_verbs[] = {
/* VERB'S NAME SESSION MANAGEMENT FUNCTION TO CALL SHORT DESCRIPTION */
{ .name= "ping" , .session= AFB_SESSION_NONE, .callback= pingtest, .info= "Ping Binding" },
{ .name= "getinfo", .session= AFB_SESSION_NONE, .callback= alsaGetInfo, .info= "List All/One Sound Cards Info" },
- { .name= "getctls", .session= AFB_SESSION_NONE,.callback= alsaGetCtls, .info= "List All/One Controls from selected sndcard" },
+ { .name= "getctls", .session= AFB_SESSION_NONE, .callback= alsaGetCtls, .info= "Get Controls from selected sndcard" },
+ { .name= "setctls", .session= AFB_SESSION_NONE, .callback= alsaSetCtls, .info= "Set Controls from selected sndcard" },
{ .name= "subscribe", .session= AFB_SESSION_NONE, .callback= alsaSubcribe, .info= "Subscribe to events from selected sndcard" },
{ .name= "getcardid", .session= AFB_SESSION_NONE, .callback= alsaGetCardId, .info= "Get CardId from its short/long name" },
- { .name= "registerHal",.session= AFB_SESSION_NONE,.callback= alsaRegisterHal, .info= "Register Hal CardName/ApiPrefix" },
+ { .name= "registerHal",.session= AFB_SESSION_NONE, .callback= alsaRegisterHal, .info= "Register Hal CardName/ApiPrefix" },
{ .name= "ucmquery", .session= AFB_SESSION_NONE, .callback= alsaUseCaseQuery,.info= "Use Case Query" },
{ .name= "ucmset", .session= AFB_SESSION_NONE, .callback= alsaUseCaseSet, .info= "Use Case Set" },
{ .name= "ucmget", .session= AFB_SESSION_NONE, .callback= alsaUseCaseGet, .info= "Use Case Get" },
diff --git a/AlsaSound/CoreBinding/AlsaCoreBinding.h b/AlsaSound/CoreBinding/AlsaCoreBinding.h
index 0e5f84a..2852384 100644
--- a/AlsaSound/CoreBinding/AlsaCoreBinding.h
+++ b/AlsaSound/CoreBinding/AlsaCoreBinding.h
@@ -42,7 +42,7 @@ PUBLIC int alsaCheckQuery (struct afb_req request, queryValuesT *queryValues);
// AlseCoreSetGet exports
PUBLIC void alsaGetInfo (struct afb_req request);
PUBLIC void alsaGetCtls(struct afb_req request);
-PUBLIC void alsaSetCtrl(struct afb_req request);
+PUBLIC void alsaSetCtls(struct afb_req request);
PUBLIC void alsaSubcribe (struct afb_req request);
PUBLIC void alsaGetCardId (struct afb_req request);
PUBLIC void alsaRegisterHal (struct afb_req request);
diff --git a/AlsaSound/CoreBinding/AlsaCtlSetGet.c b/AlsaSound/CoreBinding/AlsaCtlSetGet.c
index a6cd45b..cd21724 100644
--- a/AlsaSound/CoreBinding/AlsaCtlSetGet.c
+++ b/AlsaSound/CoreBinding/AlsaCtlSetGet.c
@@ -71,8 +71,9 @@ PUBLIC void NumidsListParse (queryValuesT *queryValues, ctlRequestT *ctlRequest)
ctlRequest[idx].jValues = NULL;
ctlRequest[idx].used=0;
-
- switch (json_object_get_type(ctlRequest[idx].jToken)) {
+ 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
@@ -98,7 +99,20 @@ PUBLIC void NumidsListParse (queryValuesT *queryValues, ctlRequestT *ctlRequest)
// Value is an int or an array with potentially multiple subvalues
ctlRequest[idx].jValues = jValues;
}
- default:
+ 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)) {
+ NOTICE (afbIface,"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;
+ }
+
+
+ default:
ctlRequest[idx].used=-1;
}
}
@@ -488,17 +502,27 @@ STATIC int alsaSetSingleCtl (snd_ctl_t *ctlDev, snd_ctl_elem_id_t *elemId, ctlRe
goto OnErrorExit;
}
- count = snd_ctl_elem_info_get_count (elemInfo);
- if (!json_object_is_type (ctlRequest->jValues, json_type_array)) {
- length=1;
- valueIsArray=0;
- } else {
- length = json_object_array_length (ctlRequest->jValues);
- valueIsArray=1;
+ count = snd_ctl_elem_info_get_count (elemInfo);
+ if (count == 0) goto OnErrorExit;
+
+ enum json_type jtype= json_object_get_type(ctlRequest->jValues);
+ switch (jtype) {
+ case json_type_array:
+ length = json_object_array_length (ctlRequest->jValues);
+ valueIsArray=1;
+ break;
+ case json_type_int:
+ length=1;
+ valueIsArray=0;
+ break;
+ default:
+ count =0;
+ break;
}
+
if (count == 0 || count < length) {
- NOTICE (afbIface, "Invalid Values ALSA NUMID=%d Values=[%s] wanted count=%d", ctlRequest->numId, json_object_to_json_string(ctlRequest->jValues), count);
+ NOTICE (afbIface, "Invalid values NUMID='%d' Values='%s' count='%d' wanted='%d'", ctlRequest->numId, json_object_to_json_string(ctlRequest->jValues), length, count);
goto OnErrorExit;
}
@@ -517,9 +541,10 @@ STATIC int alsaSetSingleCtl (snd_ctl_t *ctlDev, snd_ctl_elem_id_t *elemId, ctlRe
value= json_object_get_int (element);
snd_ctl_elem_value_set_integer(elemData, index, value);
}
-
- if ((err = snd_ctl_elem_write(ctlDev, elemData)) < 0) {
- NOTICE (afbIface, "Fail to write ALSA NUMID=%d Values=[%s]", ctlRequest->numId, json_object_to_json_string(ctlRequest->jValues));
+
+ err = snd_ctl_elem_write(ctlDev, elemData);
+ if (err < 0) {
+ NOTICE (afbIface, "Fail to write ALSA NUMID=%d Values=[%s] Error=%s", ctlRequest->numId, json_object_to_json_string(ctlRequest->jValues), snd_strerror(err));
goto OnErrorExit;
}
@@ -556,7 +581,7 @@ STATIC int alsaGetSingleCtl (snd_ctl_t *ctlDev, snd_ctl_elem_id_t *elemId, ctlRe
if (snd_ctl_elem_read(ctlDev, elemData) < 0) goto OnErrorExit;
ctlRequest->jValues= json_object_new_object();
- json_object_object_add (ctlRequest->jValues,"numid" , ctlRequest->jToken);
+ json_object_object_add (ctlRequest->jValues,"id" , ctlRequest->jToken);
if (quiet < 2) json_object_object_add (ctlRequest->jValues,"name" , json_object_new_string(snd_ctl_elem_id_get_name (elemId)));
if (quiet < 1) json_object_object_add (ctlRequest->jValues,"iface" , json_object_new_string(snd_ctl_elem_iface_name(snd_ctl_elem_id_get_interface(elemId))));
if (quiet < 3) json_object_object_add (ctlRequest->jValues,"actif", json_object_new_boolean(!snd_ctl_elem_info_is_inactive(elemInfo)));
@@ -597,7 +622,7 @@ STATIC int alsaGetSingleCtl (snd_ctl_t *ctlDev, snd_ctl_elem_id_t *elemId, ctlRe
break;
}
}
- json_object_object_add (ctlRequest->jValues,"value",jsonValuesCtl);
+ json_object_object_add (ctlRequest->jValues,"val",jsonValuesCtl);
if (!quiet) { // in simple mode do not print usable values
json_object *jsonClassCtl = json_object_new_object();