aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJonathan Aillet <jonathan.aillet@iot.bzh>2019-10-10 10:26:34 +0200
committerJonathan Aillet <jonathan.aillet@iot.bzh>2019-10-17 11:29:21 +0200
commit8ae8dd09cc0059282a99156180cafab65e990580 (patch)
tree55d667e8e8e2d0c5f578c5b8ae5369f20fb566f6
parenta24105126a8293cd91216f45a91c4ae6f3b8263a (diff)
Add function to delete an ALSA control
Add function to delete a previously created ALSA control. BUG-AGL: SPEC-2893 Change-Id: If6890712b167bba021812e899ec878075d5472af Signed-off-by: Jonathan Aillet <jonathan.aillet@iot.bzh>
-rw-r--r--src/4a-internals-hal/4a-internals-hal-alsacore-link.c86
-rw-r--r--src/4a-internals-hal/4a-internals-hal-alsacore-link.h2
2 files changed, 88 insertions, 0 deletions
diff --git a/src/4a-internals-hal/4a-internals-hal-alsacore-link.c b/src/4a-internals-hal/4a-internals-hal-alsacore-link.c
index 774054c..353383e 100644
--- a/src/4a-internals-hal/4a-internals-hal-alsacore-link.c
+++ b/src/4a-internals-hal/4a-internals-hal-alsacore-link.c
@@ -679,6 +679,92 @@ int InternalHalCreateAlsaCtl(afb_api_t apiHandle, char *cardId, struct InternalH
return err;
}
+int InternalHalDeleteAlsaCtl(afb_api_t apiHandle, char *cardId, struct InternalHalAlsaCtl *alsaCtlToDelete)
+{
+ int err = 0, wrapRet;
+
+ char *returnedError = NULL, *returnedInfo = NULL, *removedControlName = NULL;
+
+ json_object *queryJ, *responseJ = NULL;
+
+ if(! apiHandle) {
+ AFB_API_ERROR(apiHandle, "Api handle not available");
+ return -1;
+ }
+
+ if(! cardId) {
+ AFB_API_ERROR(apiHandle, "Card id is not available");
+ return -2;
+ }
+
+ if(! alsaCtlToDelete) {
+ AFB_API_ERROR(apiHandle, "Alsa control data structure is not available");
+ return -3;
+ }
+
+ if(! alsaCtlToDelete->alsaCtlCreation) {
+ AFB_API_ERROR(apiHandle, "Alsa control data structure for deletion is not available");
+ return -4;
+ }
+
+ if(alsaCtlToDelete->alsaCtlCreation != alsaCtlToDelete->alsaCtlProperties) {
+ AFB_API_ERROR(apiHandle, "Alsa control was not previously created");
+ return -5;
+ }
+
+ wrapRet = wrap_json_pack(&queryJ,
+ "{s:s s:{s:s}}",
+ "devid", cardId,
+ "ctl",
+ "name", alsaCtlToDelete->name);
+ if(wrapRet) {
+ AFB_API_ERROR(apiHandle, "Didn't succeed to allocate delete ALSA control query json object");
+ return -6;
+ }
+
+ if(afb_api_call_sync(apiHandle,
+ ALSACORE_API,
+ ALSACORE_REMOVECTL_VERB,
+ queryJ,
+ &responseJ,
+ &returnedError,
+ &returnedInfo)) {
+ AFB_API_ERROR(apiHandle,
+ "Something went wrong during call to verb '%s' of api '%s' with error '%s' and info '%s'",
+ ALSACORE_REMOVECTL_VERB,
+ ALSACORE_API,
+ returnedError ? returnedError : "not returned",
+ returnedInfo ? returnedInfo : "not returned");
+ err = -6;
+ }
+ else if(! responseJ) {
+ AFB_API_ERROR(apiHandle,
+ "Seems that %s call to api %s succeed but no response was returned",
+ ALSACORE_REMOVECTL_VERB,
+ ALSACORE_API);
+ err = -7;
+ }
+ else if(wrap_json_unpack(responseJ, "{s:{s:s}}", "removed", "ctlName", &removedControlName)) {
+ AFB_API_ERROR(apiHandle,
+ "Can't get removed ALSA control name %s of %s api",
+ ALSACORE_REMOVECTL_VERB,
+ ALSACORE_API);
+ err = -8;
+ }
+
+ AFB_API_DEBUG(apiHandle, "Control %s successfully removed", removedControlName);
+
+ alsaCtlToDelete->alsaCtlProperties = NULL;
+
+ if(responseJ)
+ json_object_put(responseJ);
+
+ free(returnedError);
+ free(returnedInfo);
+
+ return err;
+}
+
/*******************************************************************************
* Internals HAL - Alsacore controls request callback *
******************************************************************************/
diff --git a/src/4a-internals-hal/4a-internals-hal-alsacore-link.h b/src/4a-internals-hal/4a-internals-hal-alsacore-link.h
index 0694a81..39b535d 100644
--- a/src/4a-internals-hal/4a-internals-hal-alsacore-link.h
+++ b/src/4a-internals-hal/4a-internals-hal-alsacore-link.h
@@ -41,6 +41,7 @@
#define ALSACORE_CTLGET_VERB "ctlget"
#define ALSACORE_CTLSET_VERB "ctlset"
#define ALSACORE_ADDCTL_VERB "addcustomctl"
+#define ALSACORE_REMOVECTL_VERB "removecustomctl"
#define ALSACORE_CARD_CONTROL_EVENT_NAME "controls"
@@ -78,6 +79,7 @@ int InternalHalUnsubscribeFromAlsacoreCardEvent(afb_api_t apiHandle, char *cardI
int InternalHalUpdateAlsaCtlProperties(afb_api_t apiHandle, char *cardId, struct InternalHalAlsaCtl *currentAlsaCtl);
int InternalHalSetAlsaCtlValue(afb_api_t apiHandle, char *cardId, int ctlId, json_object *valuesJ);
int InternalHalCreateAlsaCtl(afb_api_t apiHandle, char *cardId, struct InternalHalAlsaCtl *alsaCtlToCreate);
+int InternalHalDeleteAlsaCtl(afb_api_t apiHandle, char *cardId, struct InternalHalAlsaCtl *alsaCtlToDelete);
// Internals HAL alsacore controls request callback
void InternalHalActionOnAlsaCtl(afb_req_t request);