summaryrefslogtreecommitdiffstats
path: root/alsa-binding/Alsa-Ucm.c
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/Alsa-Ucm.c
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/Alsa-Ucm.c')
-rw-r--r--alsa-binding/Alsa-Ucm.c145
1 files changed, 97 insertions, 48 deletions
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;
}