summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJonathan Aillet <jonathan.aillet@iot.bzh>2019-10-10 10:30:35 +0200
committerJonathan Aillet <jonathan.aillet@iot.bzh>2019-10-17 11:29:21 +0200
commit7dafc934fbe6eff77bb801717c6a64097b04978c (patch)
treea96f16b250e4c477fc4f00542d661dd6c70cb45f
parent041a50e3b11d545672d01e9d8985717a3dc90543 (diff)
Rework Alsacore subscription functions
Reworking of Alsacore subscription functions to ease adding new Alsacore events subscription. BUG-AGL: SPEC-2891 Change-Id: I8796bc5923e640cccd5a27167a0aa58ca4967609 Signed-off-by: Jonathan Aillet <jonathan.aillet@iot.bzh>
-rw-r--r--src/4a-internals-hal/4a-internals-hal-alsacore-link.c45
-rw-r--r--src/4a-internals-hal/4a-internals-hal-alsacore-link.h2
-rw-r--r--src/4a-internals-hal/4a-internals-hal-cb.c2
3 files changed, 38 insertions, 11 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 1a89b23..b910899 100644
--- a/src/4a-internals-hal/4a-internals-hal-alsacore-link.c
+++ b/src/4a-internals-hal/4a-internals-hal-alsacore-link.c
@@ -102,20 +102,17 @@ int InternalHalGetCardInfo(afb_api_t apiHandle, json_object *requestJ, json_obje
return errorToReturn;
}
-int InternalHalSubscribeToAlsaCardEvent(afb_api_t apiHandle, char *cardId)
+int InternalHalSubscribeToAlsacoreEvent(afb_api_t apiHandle,
+ json_object *subscribeQueryJ)
{
- int err = 0, wrapRet;
+ int err = 0;
char *returnedError = NULL, *returnedInfo = NULL;
- json_object *subscribeQueryJ, *responseJ = NULL;
+ json_object *responseJ = NULL;
- wrapRet = wrap_json_pack(&subscribeQueryJ,
- "{s:s, s:s}",
- "event", ALSACORE_CARD_CONTROL_EVENT_NAME,
- "devid", cardId);
- if(wrapRet) {
- AFB_API_ERROR(apiHandle, "Didn't succeed to allocate subscription query json object");
+ if(! apiHandle || ! subscribeQueryJ) {
+ AFB_API_ERROR(apiHandle, "Invalid argument(s)");
return -1;
}
@@ -144,6 +141,36 @@ int InternalHalSubscribeToAlsaCardEvent(afb_api_t apiHandle, char *cardId)
return err;
}
+int InternalHalSubscribeToAlsacoreCardEvent(afb_api_t apiHandle,
+ char *cardId)
+{
+ int err, wrapRet;
+
+ json_object *subscribeQueryJ = NULL;
+
+ wrapRet = wrap_json_pack(&subscribeQueryJ,
+ "{s:s, s:s}",
+ "event", ALSACORE_CARD_CONTROL_EVENT_NAME,
+ "devid", cardId);
+ if(wrapRet) {
+ AFB_API_ERROR(apiHandle, "Didn't succeed to allocate subscription query json object");
+ return -1;
+ }
+
+ err = InternalHalSubscribeToAlsacoreEvent(apiHandle, subscribeQueryJ);
+ if(err) {
+ AFB_API_ERROR(apiHandle,
+ "Error %i happened when tried to subscribe to %s card event",
+ err,
+ ALSACORE_API);
+ if(! subscribeQueryJ)
+ json_object_put(subscribeQueryJ);
+ return -2;
+ }
+
+ return 0;
+}
+
int InternalHalGetAlsaCtlInfo(afb_api_t apiHandle, char *cardId, struct InternalHalAlsaCtl *currentAlsaCtl, json_object **returnedDataJ)
{
int wrapRet;
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 dccf266..ee9adb2 100644
--- a/src/4a-internals-hal/4a-internals-hal-alsacore-link.h
+++ b/src/4a-internals-hal/4a-internals-hal-alsacore-link.h
@@ -45,7 +45,7 @@ snd_ctl_elem_type_t InternalHalMapsAlsaTypeToEnum(const char *label);
// Internals HAL alsacore calls funtions
int InternalHalGetCardInfo(afb_api_t apiHandle, json_object *requestJ, json_object **responseJ);
-int InternalHalSubscribeToAlsaCardEvent(afb_api_t apiHandle, char *cardId);
+int InternalHalSubscribeToAlsacoreCardEvent(afb_api_t apiHandle, char *cardId);
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);
diff --git a/src/4a-internals-hal/4a-internals-hal-cb.c b/src/4a-internals-hal/4a-internals-hal-cb.c
index cef8605..34fbe74 100644
--- a/src/4a-internals-hal/4a-internals-hal-cb.c
+++ b/src/4a-internals-hal/4a-internals-hal-cb.c
@@ -1116,7 +1116,7 @@ int InternalHalHandleOneHalMapObject(afb_api_t apiHandle, struct InternalHalAlsa
halMapData->action = toLoadAction;
}
- if(InternalHalSubscribeToAlsaCardEvent(apiHandle, cardNbString)) {
+ if(InternalHalSubscribeToAlsacoreCardEvent(apiHandle, cardNbString)) {
AFB_API_ERROR(apiHandle, "Error when trying to subscribe to alsacore event for audio card '%s'", cardNbString);
return -7;
}