diff options
author | Jonathan Aillet <jonathan.aillet@iot.bzh> | 2019-01-10 12:08:56 +0100 |
---|---|---|
committer | Jonathan Aillet <jonathan.aillet@iot.bzh> | 2019-01-28 15:38:43 +0100 |
commit | 9ea8f82f17fa57a0648eb9b16d24957bba22f9f2 (patch) | |
tree | 2c546905dead411f2197a380ed8e4682adc55602 /4a-hal | |
parent | 5f5c1a6460b3bf342d1c3a01ae296ecb14560fb5 (diff) |
Add event to indicate hal stream changes
This event can be used to be notified when a stream has been
added/removed from hal.
Change-Id: I0511b948accf4d3dc25e5603cbaaf5f1da741b49
Signed-off-by: Jonathan Aillet <jonathan.aillet@iot.bzh>
Diffstat (limited to '4a-hal')
-rw-r--r-- | 4a-hal/4a-hal-controllers/4a-hal-controllers-api-loader.c | 4 | ||||
-rw-r--r-- | 4a-hal/4a-hal-controllers/4a-hal-controllers-cb.c | 23 |
2 files changed, 27 insertions, 0 deletions
diff --git a/4a-hal/4a-hal-controllers/4a-hal-controllers-api-loader.c b/4a-hal/4a-hal-controllers/4a-hal-controllers-api-loader.c index 0f63be7..0691cb5 100644 --- a/4a-hal/4a-hal-controllers/4a-hal-controllers-api-loader.c +++ b/4a-hal/4a-hal-controllers/4a-hal-controllers-api-loader.c @@ -106,6 +106,10 @@ static int HalCtlsInitOneApi(AFB_ApiT apiHandle) currentCtlHalData->sndCardId = HalCtlsGetCardIdByCardPath(apiHandle, currentCtlHalData->sndCardPath); + currentCtlHalData->ctlHalSpecificData->streamUpdates = AFB_EventMake(apiHandle, HAL_STREAM_UPDATES_EVENT_NAME); + if(! AFB_EventIsValid(currentCtlHalData->ctlHalSpecificData->streamUpdates)) + return -4; + if(currentCtlHalData->sndCardId < 0) currentCtlHalData->status = HAL_STATUS_UNAVAILABLE; else 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 ec00056..f44ea6f 100644 --- a/4a-hal/4a-hal-controllers/4a-hal-controllers-cb.c +++ b/4a-hal/4a-hal-controllers/4a-hal-controllers-cb.c @@ -630,6 +630,7 @@ void HalCtlsSubscribeUnsubscribe(AFB_ReqT request, enum SubscribeUnsubscribeType requestJson = AFB_ReqJson(request); if(! requestJson) { AFB_ReqFail(request, "request_json", "Can't get request json"); + return; } if(wrap_json_unpack(requestJson, "{s:o}", "events", &requestedSubscriptionsJ)) { @@ -665,6 +666,28 @@ void HalCtlsSubscribeUnsubscribe(AFB_ReqT request, enum SubscribeUnsubscribeType subscriptionFound = 0; currentSubscriptionString = (char *) json_object_get_string(requestedSubscriptionJ); + if(! strcasecmp(currentSubscriptionString, HAL_STREAM_UPDATES_EVENT_NAME)) { + if(currentCtlHalData->ctlHalSpecificData->streamUpdates && + subscribeUnsubscribeType == SUBSCRIPTION && + afb_req_subscribe(request, currentCtlHalData->ctlHalSpecificData->streamUpdates)) { + AFB_ReqFailF(request, + "request_stream_list_updates_event", + "Error while trying to subscribe to stream list updates event"); + return; + } + else if(currentCtlHalData->ctlHalSpecificData->streamUpdates && + subscribeUnsubscribeType == UNSUBSCRIPTION && + afb_req_unsubscribe(request, currentCtlHalData->ctlHalSpecificData->streamUpdates)) { + AFB_ReqFailF(request, + "request_stream_list_updates_event", + "Error while trying to unsubscribe to stream list updates event"); + return; + } + + subscriptionFound = 1; + subscriptionDoneNb++; + } + currentStreamData = currentCtlHalData->ctlHalSpecificData->ctlHalStreamsData; while(currentStreamData && (! subscriptionFound)) { |