diff options
-rw-r--r-- | src/4a-internals-hal/4a-internals-hal-cb.c | 82 |
1 files changed, 54 insertions, 28 deletions
diff --git a/src/4a-internals-hal/4a-internals-hal-cb.c b/src/4a-internals-hal/4a-internals-hal-cb.c index ff916ff..14b3a1a 100644 --- a/src/4a-internals-hal/4a-internals-hal-cb.c +++ b/src/4a-internals-hal/4a-internals-hal-cb.c @@ -66,10 +66,20 @@ void InternalHalDispatchApiEvent(afb_api_t apiHandle, const char *evtLabel, json idx++; if(evtLabel[idx] != '\0' && - sscanf(&evtLabel[idx + 1], "%d", &cardidx) == 1 && + (sscanf(&evtLabel[idx + 1], "%d", &cardidx) == 1) && currentHalData->sndCardId == cardidx) { if(wrap_json_unpack(eventJ, "{s:i s:o !}", "id", &numid, "val", &valuesJ)) { - AFB_API_ERROR(apiHandle, "Invalid Alsa Event label=%s value=%s", evtLabel, json_object_get_string(eventJ)); + AFB_API_ERROR(apiHandle, + "Invalid alsacore event received label=%s value=%s", + evtLabel, + json_object_get_string(eventJ)); + return; + } + + if(! currentHalData->internalHalData->alsaMapT || + currentHalData->internalHalData->alsaMapT->ctlsCount <= 0 || + ! currentHalData->internalHalData->alsaMapT->ctls) { + AFB_API_ERROR(apiHandle, "No halmap data is available, cannot handle alsacore event"); return; } @@ -79,15 +89,23 @@ void InternalHalDispatchApiEvent(afb_api_t apiHandle, const char *evtLabel, json for(idx = 0; idx < currentHalAlsaCtlsT->ctlsCount; idx++) { if(currentHalAlsaCtlsT->ctls[idx].ctl.numid == numid) { if(currentHalAlsaCtlsT->ctls[idx].action) { + memset(&source, 0, sizeof(CtlSourceT)); source.uid = currentHalAlsaCtlsT->ctls[idx].action->uid; source.api = currentHalAlsaCtlsT->ctls[idx].action->api; - source.request = NULL; (void) ActionExecOne(&source, currentHalAlsaCtlsT->ctls[idx].action, valuesJ); } + else if(currentHalAlsaCtlsT->ctls[idx].actionJ) { + AFB_API_WARNING(apiHandle, + "The alsa control id '%i' is corresponding to a known control which" + "has a registered action, but action is not ready to be executed", + numid); + return; + } else { AFB_API_NOTICE(apiHandle, - "The alsa control id '%i' is corresponding to a known control but without any action registered", + "The alsa control id '%i' is corresponding to a known control" + "but without any action registered", numid); } @@ -254,6 +272,8 @@ int InternalHalHandleOneHalMapObject(afb_api_t apiHandle, char *cardId, struct I json_object *valueJ, *convertedValueJ = NULL; + CtlActionT *toLoadAction; + alsaMap->alsaControlEvent = afb_api_make_event(apiHandle, alsaMap->uid); if(! alsaMap->alsaControlEvent) { AFB_API_ERROR(apiHandle, @@ -273,19 +293,44 @@ int InternalHalHandleOneHalMapObject(afb_api_t apiHandle, char *cardId, struct I return -3; } + if(alsaMap->actionJ) { + toLoadAction = calloc(1, sizeof(CtlActionT)); + if(! toLoadAction) { + 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; + } + + if(ActionLoadOne(apiHandle, toLoadAction, alsaMap->actionJ, 0)) { + AFB_API_ERROR(apiHandle, + "Didn't succeed to load action using alsa object : '%s'", + json_object_get_string(alsaMap->actionJ)); + free(toLoadAction); + return -5; + } + + alsaMap->action = toLoadAction; + } + + if(InternalHalSubscribeToAlsaCardEvent(apiHandle, cardId)) { + AFB_API_ERROR(apiHandle, "Error when trying to subscribe to alsacore event for audio card '%s'", cardId); + return -6; + } + if(alsaMap->ctl.value) { // TBD JAI : handle alsa controls type valueJ = json_object_new_int(alsaMap->ctl.value); if(! valueJ) { AFB_API_ERROR(apiHandle, "Didn't succeed to allocate ALSA control value json string"); - return -4; + return -7; } err = 0; if(InternalHalConvertJsonValues(apiHandle, &alsaMap->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 = -5; + err = -8; } else if(InternalHalSetAlsaCtlValue(apiHandle, cardId, alsaMap->ctl.numid, convertedValueJ)) { AFB_API_ERROR(apiHandle, @@ -293,7 +338,7 @@ int InternalHalHandleOneHalMapObject(afb_api_t apiHandle, char *cardId, struct I alsaMap->ctl.numid, cardId, json_object_get_string(valueJ)); - err = -6; + err = -9; } json_object_put(valueJ); @@ -305,28 +350,11 @@ int InternalHalHandleOneHalMapObject(afb_api_t apiHandle, char *cardId, struct I return err; } - if(alsaMap->actionJ) { - alsaMap->action = calloc(1, sizeof(CtlActionT)); - if(! alsaMap->action) { - AFB_API_ERROR(apiHandle, - "Didn't succeed to allocate structure used to store action to perform" - "when the corresponding ALSA control is detected"); - return -7; - } - - if(ActionLoadOne(apiHandle, alsaMap->action, alsaMap->actionJ, 0)) { - AFB_API_ERROR(apiHandle, - "Didn't succeed to load action using alsa object : '%s'", - json_object_get_string(alsaMap->actionJ)); - return -8; - } - } - if(afb_api_add_verb(apiHandle, alsaMap->uid, alsaMap->info, InternalHalActionOnAlsaCtl, (void *) alsaMap, NULL, 0, 0)) { AFB_API_ERROR(apiHandle, - "Didn't succeed to create verb for current alsa control to load action using alsa object : '%s'", + "Didn't succeed to create verb for current alsa control : '%s'", json_object_get_string(alsaMap->actionJ)); - return -9; + return -10; } return 0; @@ -390,8 +418,6 @@ int InternalHalHandleAllHalMap(afb_api_t apiHandle, int sndCardId, struct Intern snprintf(cardIdString, 6, "hw:%i", sndCardId); - InternalHalSubscribeToAlsaCardEvent(apiHandle, cardIdString); - for(idx = 0; idx < currentInternalHalAlsaMapT->ctlsCount; idx++) { err = InternalHalHandleOneHalMapObject(apiHandle, cardIdString, ¤tInternalHalAlsaMapT->ctls[idx]); if(err) { |