aboutsummaryrefslogtreecommitdiffstats
path: root/src/4a-internals-hal/4a-internals-hal-cb.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/4a-internals-hal/4a-internals-hal-cb.c')
-rw-r--r--src/4a-internals-hal/4a-internals-hal-cb.c71
1 files changed, 51 insertions, 20 deletions
diff --git a/src/4a-internals-hal/4a-internals-hal-cb.c b/src/4a-internals-hal/4a-internals-hal-cb.c
index 0050f11..19a1d4a 100644
--- a/src/4a-internals-hal/4a-internals-hal-cb.c
+++ b/src/4a-internals-hal/4a-internals-hal-cb.c
@@ -91,7 +91,8 @@ void InternalHalDispatchApiEvent(afb_api_t apiHandle, const char *evtLabel, json
// Search for corresponding numid in ALSA controls list, if found, launch callback (if available)
cds_list_for_each_entry(currentHalMapControl, &currentHalData->internalHalData->halMapListHead, node) {
- if(currentHalMapControl->ctl.numid == numid) {
+ if(currentHalMapControl->ctl.alsaCtlProperties &&
+ currentHalMapControl->ctl.numid == numid) {
if(currentHalMapControl->action) {
memset(&source, 0, sizeof(CtlSourceT));
source.uid = currentHalMapControl->action->uid;
@@ -115,7 +116,7 @@ void InternalHalDispatchApiEvent(afb_api_t apiHandle, const char *evtLabel, json
if(! currentHalMapControl->alsaControlEvent ||
InternalHalConvertJsonValues(apiHandle,
- &currentHalMapControl->ctl.alsaCtlProperties,
+ currentHalMapControl->ctl.alsaCtlProperties,
valuesJ,
&normalizedValuesJ,
CONVERSION_ALSACORE_TO_NORMALIZED) ||
@@ -219,7 +220,10 @@ int InternalHalProcessOneHalMapObject(afb_api_t apiHandle, struct InternalHalAls
"info", &info,
"alsa", &alsaJ,
"action", &action)) {
- AFB_API_ERROR(apiHandle, "Parsing error, map should only contains [label]|[uid]|[tag]|[info]|[alsa]|[action] in : '%s'", json_object_get_string(halMapJ));
+ AFB_API_ERROR(apiHandle,
+ "Parsing error, map should only contains "
+ "[label]|[uid]|[tag]|[info]|[alsa]|[action] in : '%s'",
+ json_object_get_string(halMapJ));
return -1;
}
@@ -242,7 +246,10 @@ int InternalHalProcessOneHalMapObject(afb_api_t apiHandle, struct InternalHalAls
"numid", &halMapData->ctl.numid,
"value", &halMapData->ctl.value,
"create", &createAlsaCtlJ)) {
- AFB_API_ERROR(apiHandle, "Parsing error, alsa json should only contains [name]|[numid]||[value]|[create] in : '%s'", json_object_get_string(alsaJ));
+ AFB_API_ERROR(apiHandle,
+ "Parsing error, alsa json should only contains "
+ "[name]|[numid]||[value]|[create] in : '%s'",
+ json_object_get_string(alsaJ));
return -4;
}
@@ -255,7 +262,12 @@ int InternalHalProcessOneHalMapObject(afb_api_t apiHandle, struct InternalHalAls
}
if(createAlsaCtlJ) {
- halMapData->ctl.alsaCtlCreation = &halMapData->ctl.alsaCtlProperties;
+ halMapData->ctl.alsaCtlCreation = calloc(1, sizeof(struct InternalHalAlsaCtlProperties));
+ if(! halMapData->ctl.alsaCtlCreation) {
+ AFB_API_ERROR(apiHandle,
+ "Didn't succeed to allocate alsa properties data structure for control to create");
+ return -6;
+ }
if(wrap_json_unpack(createAlsaCtlJ,
"{s:s s:i s:i s:i s:i !}",
@@ -264,8 +276,11 @@ int InternalHalProcessOneHalMapObject(afb_api_t apiHandle, struct InternalHalAls
"minval", &halMapData->ctl.alsaCtlCreation->minval,
"maxval", &halMapData->ctl.alsaCtlCreation->maxval,
"step", &halMapData->ctl.alsaCtlCreation->step)) {
- AFB_API_ERROR(apiHandle, "Parsing error, alsa creation json should only contains [type]|[count]|[minval]|[maxval]|[step] in : '%s'", json_object_get_string(alsaJ));
- return -6;
+ AFB_API_ERROR(apiHandle,
+ "Parsing error, alsa creation json should only contains "
+ "[type]|[count]|[minval]|[maxval]|[step] in : '%s'",
+ json_object_get_string(alsaJ));
+ return -7;
}
if(typename) {
@@ -275,7 +290,7 @@ int InternalHalProcessOneHalMapObject(afb_api_t apiHandle, struct InternalHalAls
"Couldn't get alsa type from string %s in : '%s'",
typename,
json_object_get_string(alsaJ));
- return -7;
+ return -8;
}
}
@@ -288,13 +303,13 @@ int InternalHalProcessOneHalMapObject(afb_api_t apiHandle, struct InternalHalAls
halMapData->ctl.name,
halMapData->ctl.numid,
json_object_get_string(alsaJ));
- return -8;
+ return -9;
}
else if(! halMapData->ctl.name && halMapData->ctl.numid <= 0) {
AFB_API_ERROR(apiHandle,
"Need at least a control name or a control uid in alsa object : '%s'",
json_object_get_string(alsaJ));
- return -9;
+ return -10;
}
if(action)
@@ -369,10 +384,22 @@ int InternalHalHandleOneHalMapObject(afb_api_t apiHandle, char *cardId, struct I
AFB_API_ERROR(apiHandle, "An error happened when trying to create a new alsa control");
return -2;
}
+ halMapData->ctl.alsaCtlProperties = halMapData->ctl.alsaCtlCreation;
}
- else if(InternalHalUpdateAlsaCtlProperties(apiHandle, cardId, &halMapData->ctl)) {
- AFB_API_ERROR(apiHandle, "An error happened when trying to get existing alsa control info");
- return -3;
+ else {
+ halMapData->ctl.alsaCtlProperties = calloc(1, sizeof(struct InternalHalAlsaCtlProperties));
+ if(! halMapData->ctl.alsaCtlProperties) {
+ AFB_API_ERROR(apiHandle,
+ "Didn't succeed to allocate alsa properties data structure for control");
+ return -3;
+ }
+
+ if(InternalHalUpdateAlsaCtlProperties(apiHandle, cardId, &halMapData->ctl)) {
+ AFB_API_ERROR(apiHandle, "An error happened when trying to get existing alsa control info");
+ free(halMapData->ctl.alsaCtlProperties);
+ halMapData->ctl.alsaCtlProperties = NULL;
+ return -4;
+ }
}
if(halMapData->actionJ) {
@@ -381,7 +408,7 @@ int InternalHalHandleOneHalMapObject(afb_api_t apiHandle, char *cardId, struct I
AFB_API_ERROR(apiHandle,
"Didn't succeed to allocate structure used to store action to perform "
"when the corresponding ALSA control is detected");
- return -4;
+ return -5;
}
if(ActionLoadOne(apiHandle, toLoadAction, halMapData->actionJ, 0)) {
@@ -389,7 +416,7 @@ int InternalHalHandleOneHalMapObject(afb_api_t apiHandle, char *cardId, struct I
"Didn't succeed to load action using alsa object : '%s'",
json_object_get_string(halMapData->actionJ));
free(toLoadAction);
- return -5;
+ return -6;
}
halMapData->action = toLoadAction;
@@ -397,7 +424,7 @@ int InternalHalHandleOneHalMapObject(afb_api_t apiHandle, char *cardId, struct I
if(InternalHalSubscribeToAlsaCardEvent(apiHandle, cardId)) {
AFB_API_ERROR(apiHandle, "Error when trying to subscribe to alsacore event for audio card '%s'", cardId);
- return -6;
+ return -7;
}
if(halMapData->ctl.value) {
@@ -405,14 +432,18 @@ int InternalHalHandleOneHalMapObject(afb_api_t apiHandle, char *cardId, struct I
valueJ = json_object_new_int(halMapData->ctl.value);
if(! valueJ) {
AFB_API_ERROR(apiHandle, "Didn't succeed to allocate ALSA control value json string");
- return -7;
+ return -8;
}
err = 0;
- if(InternalHalConvertJsonValues(apiHandle, &halMapData->ctl.alsaCtlProperties, valueJ, &convertedValueJ, CONVERSION_NORMALIZED_TO_ALSACORE)) {
+ if(InternalHalConvertJsonValues(apiHandle,
+ halMapData->ctl.alsaCtlProperties,
+ valueJ,
+ &convertedValueJ,
+ CONVERSION_NORMALIZED_TO_ALSACORE)) {
AFB_API_ERROR(apiHandle, "Error when trying to convert initiate value json '%s'", json_object_get_string(valueJ));
- err = -8;
+ err = -9;
}
else if(InternalHalSetAlsaCtlValue(apiHandle, cardId, halMapData->ctl.numid, convertedValueJ)) {
AFB_API_ERROR(apiHandle,
@@ -420,7 +451,7 @@ int InternalHalHandleOneHalMapObject(afb_api_t apiHandle, char *cardId, struct I
halMapData->ctl.numid,
cardId,
json_object_get_string(valueJ));
- err = -9;
+ err = -10;
}
json_object_put(valueJ);