diff options
Diffstat (limited to '4a-hal')
-rw-r--r-- | 4a-hal/4a-hal-controllers/4a-hal-controllers-alsacore-link.h | 1 | ||||
-rw-r--r-- | 4a-hal/4a-hal-controllers/4a-hal-controllers-cb.c | 61 |
2 files changed, 59 insertions, 3 deletions
diff --git a/4a-hal/4a-hal-controllers/4a-hal-controllers-alsacore-link.h b/4a-hal/4a-hal-controllers/4a-hal-controllers-alsacore-link.h index 45dc996..5d687aa 100644 --- a/4a-hal/4a-hal-controllers/4a-hal-controllers-alsacore-link.h +++ b/4a-hal/4a-hal-controllers/4a-hal-controllers-alsacore-link.h @@ -62,6 +62,7 @@ struct CtlHalAlsaCtl { struct CtlHalAlsaMap { const char *uid; char *info; + AFB_EventT alsaControlEvent; struct CtlHalAlsaCtl ctl; json_object *actionJ; CtlActionT *action; diff --git a/4a-hal/4a-hal-controllers/4a-hal-controllers-cb.c b/4a-hal/4a-hal-controllers/4a-hal-controllers-cb.c index 1f51fba..a8d0ee4 100644 --- a/4a-hal/4a-hal-controllers/4a-hal-controllers-cb.c +++ b/4a-hal/4a-hal-controllers/4a-hal-controllers-cb.c @@ -44,7 +44,7 @@ void HalCtlsDispatchApiEvent(AFB_ApiT apiHandle, const char *evtLabel, json_obje struct SpecificHalData *currentHalData; struct CtlHalAlsaMapT *currentHalAlsaCtlsT; - json_object *valuesJ; + json_object *valuesJ, *normalizedValuesJ; AFB_ApiDebug(apiHandle, "Evtname=%s [msg=%s]", evtLabel, json_object_get_string(eventJ)); @@ -90,6 +90,19 @@ void HalCtlsDispatchApiEvent(AFB_ApiT apiHandle, const char *evtLabel, json_obje numid); } + if((! currentHalAlsaCtlsT->ctls[idx].alsaControlEvent) || + HalCtlsConvertJsonValues(apiHandle, + ¤tHalAlsaCtlsT->ctls[idx].ctl.alsaCtlProperties, + valuesJ, + &normalizedValuesJ, + CONVERSION_ALSACORE_TO_NORMALIZED) || + (AFB_EventPush(currentHalAlsaCtlsT->ctls[idx].alsaControlEvent, normalizedValuesJ) < 0)) { + AFB_ApiError(apiHandle, + "Couldn't generate an event for known halmap %s (alsa control id %i)", + currentHalAlsaCtlsT->ctls[idx].uid, + currentHalAlsaCtlsT->ctls[idx].ctl.numid); + } + return; } } @@ -275,13 +288,21 @@ int HalCtlsHandleOneHalMapObject(AFB_ApiT apiHandle, char *cardId, struct CtlHal } } - if(AFB_ApiAddVerb(apiHandle, alsaMap->uid, alsaMap->info, HalCtlsActionOnAlsaCtl, (void *) alsaMap, NULL, 0, 0)) { + alsaMap->alsaControlEvent = AFB_EventMake(apiHandle, alsaMap->uid); + if(! AFB_EventIsValid(alsaMap->alsaControlEvent)) { AFB_ApiError(apiHandle, - "Didn't to create verb for current alsa control to load action using alsa object:\n-- %s", + "Didn't succeed to create event for current alsa control to load action using alsa object:\n-- %s", json_object_get_string(alsaMap->actionJ)); return -6; } + if(AFB_ApiAddVerb(apiHandle, alsaMap->uid, alsaMap->info, HalCtlsActionOnAlsaCtl, (void *) alsaMap, NULL, 0, 0)) { + AFB_ApiError(apiHandle, + "Didn't succeed to create verb for current alsa control to load action using alsa object:\n-- %s", + json_object_get_string(alsaMap->actionJ)); + return -7; + } + return 0; } @@ -772,6 +793,7 @@ void HalCtlsSubscribeUnsubscribe(AFB_ReqT request, enum SubscribeUnsubscribeType struct SpecificHalData *currentCtlHalData; struct CtlHalMixerDataT *halStreamsData; + struct CtlHalAlsaMapT *halAlsaMapT; json_object *requestJson, *requestedSubscriptionsJ, *requestedSubscriptionJ = NULL; json_type requestJsonType; @@ -800,6 +822,7 @@ void HalCtlsSubscribeUnsubscribe(AFB_ReqT request, enum SubscribeUnsubscribeType } halStreamsData = ¤tCtlHalData->ctlHalSpecificData->ctlHalStreamsData; + halAlsaMapT = currentCtlHalData->ctlHalSpecificData->ctlHalAlsaMapT; requestJson = AFB_ReqJson(request); if(! requestJson) { @@ -870,6 +893,38 @@ void HalCtlsSubscribeUnsubscribe(AFB_ReqT request, enum SubscribeUnsubscribeType searchIdx++; } + + searchIdx = 0; + while((searchIdx < (halAlsaMapT ? halAlsaMapT->ctlsCount : 0)) && + (! subscriptionFound)) { + if(! strcasecmp(currentSubscriptionString, halAlsaMapT->ctls[searchIdx].uid)) { + if(halAlsaMapT->ctls[searchIdx].alsaControlEvent && + subscribeUnsubscribeType == SUBSCRIPTION && + afb_req_subscribe(request, halAlsaMapT->ctls[searchIdx].alsaControlEvent)) { + AFB_ReqFailF(request, + "request_control_event", + "Error while trying to subscribe to %s halmap controls events", + halAlsaMapT->ctls[searchIdx].uid); + return; + } + else if(halAlsaMapT->ctls[searchIdx].alsaControlEvent && + subscribeUnsubscribeType == UNSUBSCRIPTION && + afb_req_unsubscribe(request, halAlsaMapT->ctls[searchIdx].alsaControlEvent)) { + AFB_ReqFailF(request, + "request_stream_event", + "Error while trying to unsubscribe to %s halmap controls events", + halAlsaMapT->ctls[searchIdx].uid); + return; + } + + subscriptionFound = 1; + subscriptionDoneNb++; + + break; + } + + searchIdx++; + } } if(subscriptionDoneNb == 0) |