summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStéphane Desneux <stephane.desneux@iot.bzh>2019-10-17 13:41:13 +0000
committerGerrit Code Review <gerrit@automotivelinux.org>2019-10-17 13:41:13 +0000
commite540db016bbdf0bbb5a647a62202a62e59308073 (patch)
tree55d667e8e8e2d0c5f578c5b8ae5369f20fb566f6
parentb93502de47c945ab80bba7baa8ab84da1ee08499 (diff)
parent8ae8dd09cc0059282a99156180cafab65e990580 (diff)
Merge "Add function to delete an ALSA control"
-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);