summaryrefslogtreecommitdiffstats
path: root/alsa-binding
diff options
context:
space:
mode:
authorJonathan Aillet <jonathan.aillet@iot.bzh>2019-09-19 11:54:50 +0200
committerJonathan Aillet <jonathan.aillet@iot.bzh>2019-10-01 10:41:20 +0200
commitb829ccf57c83d0cad0b285fdd9a25e823ce2bbcd (patch)
tree1eac2edcb961df5bcf3920c1838a877c89b69cc2 /alsa-binding
parentb2a41422fa86e1c899328b0b768ad779c29e1ede (diff)
Rework verb request json parsing
Rework verb request json parsing to allow having request without 'devid' key in json. BUG-AGL: SPEC-2832 Change-Id: Id937d98c29d30b9298be3a1972f1a2cf5d0b722c Signed-off-by: Jonathan Aillet <jonathan.aillet@iot.bzh>
Diffstat (limited to 'alsa-binding')
-rw-r--r--alsa-binding/Alsa-ApiHat.h7
-rw-r--r--alsa-binding/Alsa-RegEvt.c76
-rw-r--r--alsa-binding/Alsa-SetGet.c85
-rw-r--r--alsa-binding/Alsa-Ucm.c145
4 files changed, 190 insertions, 123 deletions
diff --git a/alsa-binding/Alsa-ApiHat.h b/alsa-binding/Alsa-ApiHat.h
index b5d3866..ba0d054 100644
--- a/alsa-binding/Alsa-ApiHat.h
+++ b/alsa-binding/Alsa-ApiHat.h
@@ -71,11 +71,9 @@ typedef struct {
// generic structure to pass parsed query values
typedef struct {
- const char *devid;
json_object *numidsJ;
- queryModeE mode;
int count;
-} queryValuesT;
+} controlQueryValuesT;
// use to store crl numid user request
typedef struct {
@@ -88,7 +86,8 @@ typedef struct {
// import from AlsaAfbBinding
extern const struct afb_binding_interface *afbIface;
-PUBLIC json_object *alsaCheckQuery (afb_req_t request, queryValuesT *queryValues);
+PUBLIC char *alsaGetDevIdFromQuery(json_object *queryJ);
+PUBLIC queryModeE alsaGetModeFromQuery(json_object *queryJ);
// AlseCoreSetGet exports
PUBLIC int getCardNbFromCardPath(char *cardPath);
diff --git a/alsa-binding/Alsa-RegEvt.c b/alsa-binding/Alsa-RegEvt.c
index 28b66b1..7962963 100644
--- a/alsa-binding/Alsa-RegEvt.c
+++ b/alsa-binding/Alsa-RegEvt.c
@@ -22,6 +22,8 @@
#include <afb-timer.h>
+#include <wrap-json.h>
+
#include "Alsa-ApiHat.h"
// Defines for inotify events
@@ -93,29 +95,24 @@ STATIC int getHalIdxFromCardid (int cardid) {
return -1;
}
-PUBLIC json_object *alsaCheckQuery(afb_req_t request, queryValuesT *queryValues) {
-
- json_object *tmpJ;
- int done;
+PUBLIC char *alsaGetDevIdFromQuery(json_object *queryJ)
+{
+ char *devId = NULL;
- // get query from request
- json_object *queryInJ = afb_req_json(request);
+ if(wrap_json_unpack(queryJ, "{s:s}", "devid", &devId))
+ return NULL;
- 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);
+ return devId;
+}
- 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);
+PUBLIC queryModeE alsaGetModeFromQuery(json_object *queryJ)
+{
+ queryModeE mode = QUERY_QUIET;
- return queryInJ;
+ if(wrap_json_unpack(queryJ, "{s:i}", "mode", &mode))
+ return QUERY_QUIET;
-OnErrorExit:
- return NULL;
+ return mode;
}
STATIC void updateSelectedAlsaCardsAvailabilityAndFireEvents(sndCardsT *sndCards, int first, int last) {
@@ -438,23 +435,23 @@ OnErrorExit:
}
// Subscribe to every Alsa CtlEvent send by a given board
-STATIC afb_event_t alsaEvtSubscribeAlsaControlEvent(afb_req_t request, sndCardsT *sndCards, queryValuesT *queryValues) {
+STATIC afb_event_t alsaEvtSubscribeAlsaControlEvent(afb_req_t request, sndCardsT *sndCards, char* devId, queryModeE mode) {
sndHandleT *currentSndHandle = NULL;
snd_ctl_t *ctlDev = NULL;
int err, cardId;
snd_ctl_card_info_t *cardinfo;
// open control interface for devid
- err = snd_ctl_open(&ctlDev, queryValues->devid, SND_CTL_READONLY);
+ err = snd_ctl_open(&ctlDev, devId, SND_CTL_READONLY);
if (err < 0) {
- afb_req_fail_f(request, "devid-unknown", "SndCard devid=%s Not Found err=%s", queryValues->devid, snd_strerror(err));
+ afb_req_fail_f(request, "devid-unknown", "SndCard devid=%s Not Found err=%s", devId, snd_strerror(err));
goto OnErrorExit;
}
snd_ctl_card_info_alloca(&cardinfo);
err = snd_ctl_card_info(ctlDev, cardinfo);
if (err < 0) {
- afb_req_fail_f(request, "devid-invalid", "SndCard devid=%s Not Found err=%s", queryValues->devid, snd_strerror(err));
+ afb_req_fail_f(request, "devid-invalid", "SndCard devid=%s Not Found err=%s", devId, snd_strerror(err));
goto OnErrorExit;
}
@@ -471,12 +468,12 @@ STATIC afb_event_t alsaEvtSubscribeAlsaControlEvent(afb_req_t request, sndCardsT
if (! currentSndHandle->evtHandle) {
currentSndHandle->evtHandle = malloc(sizeof (ctrlEvtHandleT));
currentSndHandle->evtHandle->ctlDev = ctlDev;
- currentSndHandle->evtHandle->mode = queryValues->mode;
+ currentSndHandle->evtHandle->mode = mode;
// subscribe for sndctl events attached to devid
err = snd_ctl_subscribe_events(currentSndHandle->evtHandle->ctlDev, 1);
if (err < 0) {
- afb_req_fail_f(request, "subscribe-fail", "Cannot subscribe events from devid=%s err=%d", queryValues->devid, err);
+ afb_req_fail_f(request, "subscribe-fail", "Cannot subscribe events from devid=%s err=%d", devId, err);
goto OnErrorExit;
}
@@ -491,14 +488,14 @@ STATIC afb_event_t alsaEvtSubscribeAlsaControlEvent(afb_req_t request, sndCardsT
sndCtlEventCB,
currentSndHandle);
if (err < 0) {
- afb_req_fail_f(request, "register-mainloop", "Cannot hook events to mainloop devid=%s err=%d", queryValues->devid, err);
+ afb_req_fail_f(request, "register-mainloop", "Cannot hook events to mainloop devid=%s err=%d", devId, err);
goto OnErrorExit;
}
// create binder event attached to devid name
- currentSndHandle->evtHandle->afbevt = afb_daemon_make_event(queryValues->devid);
+ currentSndHandle->evtHandle->afbevt = afb_daemon_make_event(devId);
if (!afb_event_is_valid(currentSndHandle->evtHandle->afbevt)) {
- afb_req_fail_f(request, "register-event", "Cannot register new binder event name=%s", queryValues->devid);
+ afb_req_fail_f(request, "register-event", "Cannot register new binder event name=%s", devId);
goto OnErrorExit;
}
}
@@ -517,10 +514,15 @@ OnErrorExit:
// Subscribe to alsacore event
PUBLIC void alsaEvtSubcribe(afb_req_t request) {
+ int err;
+
+ queryModeE mode;
+
+ char *devId = NULL;
+
static sndCardsT *sndCards = NULL;
+
afb_event_t eventToSubscribe;
- int err;
- queryValuesT queryValues;
json_object *queryJ;
@@ -529,15 +531,21 @@ PUBLIC void alsaEvtSubcribe(afb_req_t request) {
sndCards->apiHandle = afb_req_get_api(request);
}
- queryJ = alsaCheckQuery(request, &queryValues);
- if (!queryJ) return;
+ queryJ = afb_req_json(request);
+
+ devId = alsaGetDevIdFromQuery(queryJ);
+ if (!devId) {
+ afb_req_fail_f(request, "devid-missing", "Invalid query='%s'", json_object_get_string(queryJ));
+ return;
+ }
- if(! strcasecmp(queryValues.devid, "added"))
+ mode = alsaGetModeFromQuery(queryJ);
+ if(! strcasecmp(devId, "added"))
eventToSubscribe = alsaEvtSubscribeSoundCardEvent(request, sndCards, SUBSCRIPTION_CARD_ADDED_EVENTS);
- else if(! strcasecmp(queryValues.devid, "removed"))
+ else if(! strcasecmp(devId, "removed"))
eventToSubscribe = alsaEvtSubscribeSoundCardEvent(request, sndCards, SUBSCRIPTION_CARD_REMOVED_EVENTS);
else
- eventToSubscribe = alsaEvtSubscribeAlsaControlEvent(request, sndCards, &queryValues);
+ eventToSubscribe = alsaEvtSubscribeAlsaControlEvent(request, sndCards, devId, mode);
if(! eventToSubscribe)
return;
diff --git a/alsa-binding/Alsa-SetGet.c b/alsa-binding/Alsa-SetGet.c
index 19b2164..78ac7e9 100644
--- a/alsa-binding/Alsa-SetGet.c
+++ b/alsa-binding/Alsa-SetGet.c
@@ -38,18 +38,18 @@
#define SNDRV_CTL_IOCTL_CARD_INFO(size) _IOR_HACKED('U', 0x01, size)
-PUBLIC void NumidsListParse(ActionSetGetT action, queryValuesT *queryValues, ctlRequestT *ctlRequest) {
+PUBLIC void NumidsListParse(ActionSetGetT action, controlQueryValuesT *queryControlValues, ctlRequestT *ctlRequest) {
int length;
- for (int idx = 0; idx < queryValues->count; idx++) {
+ for (int idx = 0; idx < queryControlValues->count; idx++) {
json_object *jId, *valuesJ;
ctlRequest[idx].used = 0;
ctlRequest[idx].tag = NULL;
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;
+ if (json_type_array == json_object_get_type(queryControlValues->numidsJ)) ctlRequest[idx].jToken = json_object_array_get_idx(queryControlValues->numidsJ, idx);
+ else ctlRequest[idx].jToken = queryControlValues->numidsJ;
enum json_type jtype = json_object_get_type(ctlRequest[idx].jToken);
switch (jtype) {
@@ -59,9 +59,9 @@ PUBLIC void NumidsListParse(ActionSetGetT action, queryValuesT *queryValues, ctl
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
+ if (action == ACTION_SET && queryControlValues->count == 2) {
+ ctlRequest[idx].valuesJ = json_object_array_get_idx(queryControlValues->numidsJ, 1);
+ queryControlValues->count = 1; //In this form count==2 , when only one numid is to set
idx++;
continue;
} else
@@ -1243,24 +1243,35 @@ OnErrorExit:
// assign multiple control to the same value
STATIC void alsaSetGetCtls(ActionSetGetT action, afb_req_t request) {
- ctlRequestT *ctlRequest;
int err = 0, done;
unsigned int ctlCount;
- snd_ctl_t *ctlDev=NULL;
+
+ queryModeE mode;
+
+ char *devId = NULL;
+
+ snd_ctl_t *ctlDev = NULL;
snd_ctl_elem_list_t *ctlList;
- queryValuesT queryValues;
+
json_object *queryJ, *numidsJ, *sndctls;
- queryJ = alsaCheckQuery(request, &queryValues);
- if (!queryJ) {
- afb_req_fail_f(request, "invalid-query", "Invalid Query=%s", json_object_get_string(queryJ));
+ controlQueryValuesT queryControlValues;
+ ctlRequestT *ctlRequest;
+
+ queryJ = afb_req_json(request);
+
+ devId = alsaGetDevIdFromQuery(queryJ);
+ if (!devId) {
+ afb_req_fail_f(request, "devid-missing", "Invalid query='%s'", json_object_get_string(queryJ));
return;
}
+ mode = alsaGetModeFromQuery(queryJ);
+
// Phrase Numids + optional values
done = json_object_object_get_ex(queryJ, "ctl", &numidsJ);
if (!done && action == ACTION_GET) {
- queryValues.count = 0;
+ queryControlValues.count = 0;
}
else if (!done && action == ACTION_SET) {
afb_req_fail_f(request, "invalid-set", "To set an ALSA control value(s), they must be specified in query=%s", json_object_get_string(queryJ));
@@ -1270,15 +1281,15 @@ STATIC void alsaSetGetCtls(ActionSetGetT action, afb_req_t request) {
enum json_type jtype = json_object_get_type(numidsJ);
switch (jtype) {
case json_type_array:
- queryValues.numidsJ = numidsJ;
- queryValues.count = (int) json_object_array_length(numidsJ);
+ queryControlValues.numidsJ = numidsJ;
+ queryControlValues.count = (int) json_object_array_length(numidsJ);
break;
case json_type_int:
case json_type_object:
case json_type_string:
- queryValues.count = 1;
- queryValues.numidsJ = numidsJ;
+ queryControlValues.count = 1;
+ queryControlValues.numidsJ = numidsJ;
break;
default:
@@ -1287,24 +1298,24 @@ STATIC void alsaSetGetCtls(ActionSetGetT action, afb_req_t request) {
}
}
- 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));
+ if ((err = snd_ctl_open(&ctlDev, devId, 0)) < 0) {
+ afb_req_fail_f(request, "sndcrl-notfound", "devid='%s' load fail error=%s\n", devId, snd_strerror(err));
goto close_ctl;
}
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", devId, snd_strerror(err));
goto close_ctl;
}
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", devId, snd_strerror(err));
goto close_ctl;
}
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", devId, snd_strerror(err));
goto free_elem_list;
}
@@ -1312,10 +1323,10 @@ STATIC void alsaSetGetCtls(ActionSetGetT action, afb_req_t request) {
ctlCount = snd_ctl_elem_list_get_used(ctlList);
// if more than one crl requested prepare an array for response
- if (queryValues.count != 1 && action == ACTION_GET) sndctls = json_object_new_array();
+ if (queryControlValues.count != 1 && action == ACTION_GET) sndctls = json_object_new_array();
else sndctls = NULL;
- if (queryValues.count == 0) {
+ if (queryControlValues.count == 0) {
ctlRequest = alloca(sizeof (ctlRequestT)*(ctlCount));
ctlRequest->tag = NULL;
@@ -1326,7 +1337,7 @@ STATIC void alsaSetGetCtls(ActionSetGetT action, afb_req_t request) {
snd_ctl_elem_list_get_id(ctlList, ctlIndex, elemId);
- err = alsaGetSingleCtl(ctlDev, elemId, &ctlRequest[ctlIndex], queryValues.mode);
+ err = alsaGetSingleCtl(ctlDev, elemId, &ctlRequest[ctlIndex], mode);
if (err) {
afb_req_fail_f(request,
"control_get",
@@ -1337,7 +1348,7 @@ STATIC void alsaSetGetCtls(ActionSetGetT action, afb_req_t request) {
ctlCount);
goto free_response_array;
}
- else if (queryValues.count == 1) {
+ else if (queryControlValues.count == 1) {
sndctls = ctlRequest[ctlIndex].valuesJ;
}
else {
@@ -1348,10 +1359,10 @@ STATIC void alsaSetGetCtls(ActionSetGetT action, afb_req_t request) {
else {
int found, ctlIndex;
- ctlRequest = alloca(sizeof (ctlRequestT)*(queryValues.count));
- NumidsListParse(action, &queryValues, ctlRequest);
+ ctlRequest = alloca(sizeof (ctlRequestT)*(queryControlValues.count));
+ NumidsListParse(action, &queryControlValues, ctlRequest);
- for (int jdx = 0; jdx < queryValues.count; jdx++) {
+ for (int jdx = 0; jdx < queryControlValues.count; jdx++) {
found = 0;
ctlIndex = 0;
while (ctlIndex < ctlCount) {
@@ -1381,7 +1392,7 @@ STATIC void alsaSetGetCtls(ActionSetGetT action, afb_req_t request) {
"Error while trying to find control using its name=%s (query %i out of %i)",
ctlRequest[jdx].tag,
(jdx + 1),
- queryValues.count);
+ queryControlValues.count);
goto free_response_array;
}
else {
@@ -1390,7 +1401,7 @@ STATIC void alsaSetGetCtls(ActionSetGetT action, afb_req_t request) {
"Error while trying to find control using its numid=%i (query %i out of %i)",
ctlRequest[jdx].numId,
(jdx + 1),
- queryValues.count);
+ queryControlValues.count);
goto free_response_array;
}
}
@@ -1401,7 +1412,7 @@ STATIC void alsaSetGetCtls(ActionSetGetT action, afb_req_t request) {
snd_ctl_elem_list_get_id(ctlList, ctlIndex, elemId);
switch (action) {
case ACTION_GET:
- err = alsaGetSingleCtl(ctlDev, elemId, &ctlRequest[jdx], queryValues.mode);
+ err = alsaGetSingleCtl(ctlDev, elemId, &ctlRequest[jdx], mode);
if (err) {
afb_req_fail_f(request,
"control_get",
@@ -1409,7 +1420,7 @@ STATIC void alsaSetGetCtls(ActionSetGetT action, afb_req_t request) {
snd_ctl_elem_list_get_numid(ctlList, ctlIndex),
snd_ctl_elem_list_get_name(ctlList, ctlIndex),
(jdx + 1),
- queryValues.count);
+ queryControlValues.count);
goto free_response_array;
}
break;
@@ -1424,7 +1435,7 @@ STATIC void alsaSetGetCtls(ActionSetGetT action, afb_req_t request) {
snd_ctl_elem_list_get_name(ctlList, ctlIndex),
json_object_get_string(ctlRequest[jdx].valuesJ),
(jdx + 1),
- queryValues.count);
+ queryControlValues.count);
goto free_response_array;
}
break;
@@ -1436,12 +1447,12 @@ STATIC void alsaSetGetCtls(ActionSetGetT action, afb_req_t request) {
snd_ctl_elem_list_get_numid(ctlList, ctlIndex),
snd_ctl_elem_list_get_name(ctlList, ctlIndex),
(jdx + 1),
- queryValues.count);
+ queryControlValues.count);
goto free_response_array;
}
if (action == ACTION_GET) {
- if (queryValues.count == 1)
+ if (queryControlValues.count == 1)
sndctls = ctlRequest[jdx].valuesJ;
else
json_object_array_add(sndctls, ctlRequest[jdx].valuesJ);
diff --git a/alsa-binding/Alsa-Ucm.c b/alsa-binding/Alsa-Ucm.c
index 3e0687c..fe4ad99 100644
--- a/alsa-binding/Alsa-Ucm.c
+++ b/alsa-binding/Alsa-Ucm.c
@@ -51,7 +51,7 @@ static ucmHandleT ucmHandles[MAX_SND_CARD];
// Cache opened UCM handles
-STATIC int alsaUseCaseOpen(afb_req_t request, queryValuesT *queryValues, int allowNewMgr) {
+STATIC int alsaUseCaseOpen(afb_req_t request, char *devId, int allowNewMgr) {
snd_ctl_t *ctlDev=NULL;
snd_ctl_card_info_t *cardinfo;
snd_use_case_mgr_t *ucmHandle;
@@ -59,16 +59,16 @@ STATIC int alsaUseCaseOpen(afb_req_t request, queryValuesT *queryValues, int all
int cardId, idx, idxFree = -1, err;
// open control interface for devid
- err = snd_ctl_open(&ctlDev, queryValues->devid, SND_CTL_READONLY);
+ err = snd_ctl_open(&ctlDev, devId, SND_CTL_READONLY);
if (err < 0) {
ctlDev = NULL;
- afb_req_fail_f(request, "devid-unknown", "SndCard devid=[%s] Not Found err=%d", queryValues->devid, err);
+ afb_req_fail_f(request, "devid-unknown", "SndCard devid=[%s] Not Found err=%d", devId, err);
goto OnErrorExit;
}
snd_ctl_card_info_alloca(&cardinfo);
if ((err = snd_ctl_card_info(ctlDev, cardinfo)) < 0) {
- afb_req_fail_f(request, "devid-invalid", "SndCard devid=[%s] Not Found err=%s", queryValues->devid, snd_strerror(err));
+ afb_req_fail_f(request, "devid-invalid", "SndCard devid=[%s] Not Found err=%s", devId, snd_strerror(err));
goto OnErrorExit;
}
@@ -81,12 +81,12 @@ STATIC int alsaUseCaseOpen(afb_req_t request, queryValuesT *queryValues, int all
};
if (!allowNewMgr) {
- afb_req_fail_f(request, "ucm-nomgr", "SndCard devid=[%s] no exiting UCM manager session", queryValues->devid);
+ afb_req_fail_f(request, "ucm-nomgr", "SndCard devid=[%s] no exiting UCM manager session", devId);
goto OnErrorExit;
}
if (idxFree < 0 && idx == MAX_SND_CARD) {
- afb_req_fail_f(request, "ucm-toomany", "SndCard devid=[%s] too many open UCM Max=%d", queryValues->devid, MAX_SND_CARD);
+ afb_req_fail_f(request, "ucm-toomany", "SndCard devid=[%s] too many open UCM Max=%d", devId, MAX_SND_CARD);
goto OnErrorExit;
}
@@ -94,7 +94,7 @@ STATIC int alsaUseCaseOpen(afb_req_t request, queryValuesT *queryValues, int all
cardName = snd_ctl_card_info_get_name(cardinfo);
err = snd_use_case_mgr_open(&ucmHandle, cardName);
if (err) {
- afb_req_fail_f(request, "ucm-open", "SndCard devid=[%s] name=[%s] No UCM Profile err=%s", queryValues->devid, cardName, snd_strerror(err));
+ afb_req_fail_f(request, "ucm-open", "SndCard devid=[%s] name=[%s] No UCM Profile err=%s", devId, cardName, snd_strerror(err));
goto OnErrorExit;
}
ucmHandles[idx].ucm = ucmHandle;
@@ -112,23 +112,32 @@ OnErrorExit:
PUBLIC void alsaUseCaseQuery(afb_req_t request) {
int verbCount, ucmIdx;
- const char **verbList;
+
+ char *devId = NULL;
+ const char *cardName, **verbList;
+
snd_use_case_mgr_t *ucmHandle;
- queryValuesT queryValues;
- json_object *ucmJs;
- const char *cardName;
- json_object *queryJ = alsaCheckQuery(request, &queryValues);
- if (!queryJ) goto OnErrorExit;
+ json_object *ucmJs, *queryJ;
+
+ queryJ = afb_req_json(request);
+
+ devId = alsaGetDevIdFromQuery(queryJ);
+ if (!devId) {
+ afb_req_fail_f(request, "devid-missing", "Invalid query='%s'", json_object_get_string(queryJ));
+ goto OnErrorExit;
+ }
+
+ ucmIdx = alsaUseCaseOpen(request, devId, TRUE);
+ if (ucmIdx < 0)
+ goto OnErrorExit;
- ucmIdx = alsaUseCaseOpen(request, &queryValues, TRUE);
- if (ucmIdx < 0) goto OnErrorExit;
ucmHandle = ucmHandles [ucmIdx].ucm;
cardName = ucmHandles [ucmIdx].cardName;
verbCount = snd_use_case_get_list(ucmHandle, "_verbs", &verbList);
if (verbCount < 0) {
- afb_req_fail_f(request, "ucm-list", "SndCard devid=[%s] name=[%s] No UCM Verbs", queryValues.devid, cardName);
+ afb_req_fail_f(request, "ucm-list", "SndCard devid=[%s] name=[%s] No UCM Verbs", devId, cardName);
goto OnErrorExit;
}
@@ -235,17 +244,26 @@ OnErrorExit:
PUBLIC void alsaUseCaseGet(afb_req_t request) {
int ucmIdx, labelCount;
- queryValuesT queryValues;
- json_object *jResponse = json_object_new_object();
- json_object *jWarnings = json_object_new_array();
+
+ char *devId = NULL;
const char *warnings = NULL;
- json_object *queryJ = alsaCheckQuery(request, &queryValues);
- if (!queryJ) goto OnErrorExit;
- ;
+ json_object *queryJ, *jResponse, *jWarnings;
+
+ jResponse = json_object_new_object();
+ jWarnings = json_object_new_array();
+
+ queryJ = afb_req_json(request);
- ucmIdx = alsaUseCaseOpen(request, &queryValues, TRUE);
- if (ucmIdx < 0) goto OnErrorExit;
+ devId = alsaGetDevIdFromQuery(queryJ);
+ if (!devId) {
+ afb_req_fail_f(request, "devid-missing", "Invalid query='%s'", json_object_get_string(queryJ));
+ goto OnErrorExit;
+ }
+
+ ucmIdx = alsaUseCaseOpen(request, devId, TRUE);
+ if (ucmIdx < 0)
+ goto OnErrorExit;
const char *cardName = ucmHandles[ucmIdx].cardName;
@@ -254,7 +272,7 @@ PUBLIC void alsaUseCaseGet(afb_req_t request) {
const char *dev = afb_req_value(request, "dev");
if (dev && mod) {
- afb_req_fail_f(request, "ucmget-labels", "SndCard devid=[%s] name=[%s] UCM mod+dev incompatible", queryValues.devid, cardName);
+ afb_req_fail_f(request, "ucmget-labels", "SndCard devid=[%s] name=[%s] UCM mod+dev incompatible", devId, cardName);
goto OnErrorExit;
}
@@ -263,7 +281,7 @@ PUBLIC void alsaUseCaseGet(afb_req_t request) {
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);
+ afb_req_fail_f(request, "ucmget-labels", "SndCard devid=[%s] name=[%s] UCM values name missing", devId, cardName);
goto OnErrorExit;
}
@@ -320,15 +338,28 @@ OnErrorExit:
PUBLIC void alsaUseCaseSet(afb_req_t request) {
int err, ucmIdx;
- queryValuesT queryValues;
- json_object *jResponse = json_object_new_object();
- json_object *queryJ = alsaCheckQuery(request, &queryValues);
- if (!queryJ) goto OnErrorExit;
+ queryModeE mode;
+
+ char *devId = NULL;
+
+ json_object *queryJ, *jResponse;
+ jResponse = json_object_new_object();
- ucmIdx = alsaUseCaseOpen(request, &queryValues, TRUE);
- if (ucmIdx < 0) goto OnErrorExit;
+ queryJ = afb_req_json(request);
+
+ devId = alsaGetDevIdFromQuery(queryJ);
+ if (!devId) {
+ afb_req_fail_f(request, "devid-missing", "Invalid query='%s'", json_object_get_string(queryJ));
+ goto OnErrorExit;
+ }
+
+ mode = alsaGetModeFromQuery(queryJ);
+
+ ucmIdx = alsaUseCaseOpen(request, devId, TRUE);
+ if (ucmIdx < 0)
+ goto OnErrorExit;
snd_use_case_mgr_t *ucmMgr = ucmHandles[ucmIdx].ucm;
const char *cardName = ucmHandles[ucmIdx].cardName;
@@ -341,7 +372,7 @@ PUBLIC void alsaUseCaseSet(afb_req_t request) {
if (verb) {
err = snd_use_case_set(ucmMgr, "_verb", verb);
if (err) {
- afb_req_fail_f(request, "ucmset-verb", "SndCard devid=[%s] name=[%s] Invalid UCM verb=[%s] err=%s", queryValues.devid, cardName, verb, snd_strerror(err));
+ afb_req_fail_f(request, "ucmset-verb", "SndCard devid=[%s] name=[%s] Invalid UCM verb=[%s] err=%s", devId, cardName, verb, snd_strerror(err));
goto OnErrorExit;
}
}
@@ -349,7 +380,7 @@ PUBLIC void alsaUseCaseSet(afb_req_t request) {
if (dev) {
err = snd_use_case_set(ucmMgr, "_enadev", dev);
if (err) {
- afb_req_fail_f(request, "ucmset-dev", "SndCard devid=[%s] name=[%s] Invalid UCMverb=[%s] dev=%s err=%s", queryValues.devid, cardName, verb, dev, snd_strerror(err));
+ afb_req_fail_f(request, "ucmset-dev", "SndCard devid=[%s] name=[%s] Invalid UCMverb=[%s] dev=%s err=%s", devId, cardName, verb, dev, snd_strerror(err));
goto OnErrorExit;
}
}
@@ -357,7 +388,7 @@ PUBLIC void alsaUseCaseSet(afb_req_t request) {
if (mod) {
err = snd_use_case_set(ucmMgr, "_enamod", mod);
if (err) {
- afb_req_fail_f(request, "ucmset-mod", "SndCard devid=[%s] name=[%s] Invalid UCM verb=[%s] mod=[%s] err=%s", queryValues.devid, cardName, verb, mod, snd_strerror(err));
+ afb_req_fail_f(request, "ucmset-mod", "SndCard devid=[%s] name=[%s] Invalid UCM verb=[%s] mod=[%s] err=%s", devId, cardName, verb, mod, snd_strerror(err));
goto OnErrorExit;
}
}
@@ -365,7 +396,7 @@ PUBLIC void alsaUseCaseSet(afb_req_t request) {
// label are requested transfert request to get
if (afb_req_value(request, "value")) return alsaUseCaseGet(request);
- if (queryValues.mode <= 3) {
+ if (mode <= 3) {
json_object *jValue;
jValue = ucmGetValue(&ucmHandles[ucmIdx], verb, dev, "OutputDspName");
@@ -385,17 +416,26 @@ OnErrorExit:
PUBLIC void alsaUseCaseReset(afb_req_t request) {
int err, ucmIdx;
- queryValuesT queryValues;
- json_object *queryJ = alsaCheckQuery(request, &queryValues);
- if (!queryJ) goto OnErrorExit;
+ char *devId = NULL;
+
+ json_object *queryJ;
+
+ queryJ = afb_req_json(request);
+
+ devId = alsaGetDevIdFromQuery(queryJ);
+ if (!devId) {
+ afb_req_fail_f(request, "devid-missing", "Invalid query='%s'", json_object_get_string(queryJ));
+ goto OnErrorExit;
+ }
- ucmIdx = alsaUseCaseOpen(request, &queryValues, FALSE);
- if (ucmIdx < 0) goto OnErrorExit;
+ ucmIdx = alsaUseCaseOpen(request, devId, FALSE);
+ if (ucmIdx < 0)
+ goto OnErrorExit;
err = snd_use_case_mgr_reset(ucmHandles[ucmIdx].ucm);
if (err) {
- afb_req_fail_f(request, "ucmreset-fail", "devid=%s Card Name=%s", queryValues.devid, ucmHandles[ucmIdx].cardName);
+ afb_req_fail_f(request, "ucmreset-fail", "devid=%s Card Name=%s", devId, ucmHandles[ucmIdx].cardName);
goto OnErrorExit;
}
@@ -407,17 +447,26 @@ OnErrorExit:
PUBLIC void alsaUseCaseClose(afb_req_t request) {
int err, ucmIdx;
- queryValuesT queryValues;
- json_object *queryJ = alsaCheckQuery(request, &queryValues);
- if (!queryJ) goto OnErrorExit;
+ char *devId = NULL;
+
+ json_object *queryJ;
+
+ queryJ = afb_req_json(request);
- ucmIdx = alsaUseCaseOpen(request, &queryValues, FALSE);
- if (ucmIdx < 0) goto OnErrorExit;
+ devId = alsaGetDevIdFromQuery(queryJ);
+ if (!devId) {
+ afb_req_fail_f(request, "devid-missing", "Invalid query='%s'", json_object_get_string(queryJ));
+ goto OnErrorExit;
+ }
+
+ ucmIdx = alsaUseCaseOpen(request, devId, FALSE);
+ if (ucmIdx < 0)
+ goto OnErrorExit;
err = snd_use_case_mgr_close(ucmHandles[ucmIdx].ucm);
if (err) {
- afb_req_fail_f(request, "ucmreset-close", "devid=%s Card Name=%s", queryValues.devid, ucmHandles[ucmIdx].cardName);
+ afb_req_fail_f(request, "ucmreset-close", "devid=%s Card Name=%s", devId, ucmHandles[ucmIdx].cardName);
goto OnErrorExit;
}