aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJonathan Aillet <jonathan.aillet@iot.bzh>2019-01-10 12:08:56 +0100
committerJonathan Aillet <jonathan.aillet@iot.bzh>2019-01-28 15:38:43 +0100
commit9ea8f82f17fa57a0648eb9b16d24957bba22f9f2 (patch)
tree2c546905dead411f2197a380ed8e4682adc55602
parent5f5c1a6460b3bf342d1c3a01ae296ecb14560fb5 (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>
-rw-r--r--4a-hal-utilities/4a-hal-utilities-data.h3
-rw-r--r--4a-hal-utilities/4a-hal-utilities-hal-streams-handler.c22
-rw-r--r--4a-hal/4a-hal-controllers/4a-hal-controllers-api-loader.c4
-rw-r--r--4a-hal/4a-hal-controllers/4a-hal-controllers-cb.c23
4 files changed, 52 insertions, 0 deletions
diff --git a/4a-hal-utilities/4a-hal-utilities-data.h b/4a-hal-utilities/4a-hal-utilities-data.h
index a2f1f1a..62beac8 100644
--- a/4a-hal-utilities/4a-hal-utilities-data.h
+++ b/4a-hal-utilities/4a-hal-utilities-data.h
@@ -28,6 +28,8 @@
#include "4a-hal-utilities-alsa-data.h"
+#define HAL_STREAM_UPDATES_EVENT_NAME "stream-updates"
+
// Enum for sharing hal (controller or external) status
enum HalStatus {
HAL_STATUS_UNAVAILABLE=0,
@@ -52,6 +54,7 @@ struct CtlHalSpecificData {
json_object *halMixerJ;
struct CtlHalMixerData *ctlHalStreamsData;
+ AFB_EventT streamUpdates;
struct CtlHalMixerData *ctlHalPlaybacksData;
struct CtlHalMixerData *ctlHalCapturesData;
diff --git a/4a-hal-utilities/4a-hal-utilities-hal-streams-handler.c b/4a-hal-utilities/4a-hal-utilities-hal-streams-handler.c
index 4dbe35c..4d42b01 100644
--- a/4a-hal-utilities/4a-hal-utilities-hal-streams-handler.c
+++ b/4a-hal-utilities/4a-hal-utilities-hal-streams-handler.c
@@ -232,6 +232,8 @@ struct CtlHalMixerData *HalUtlAddStreamDataAndCreateStreamVerb(AFB_ApiT apiHandl
char *verbToCall,
char *streamCardId)
{
+ json_object *streamAddedEventJ;
+
CtlConfigT *ctrlConfig;
struct SpecificHalData *currentSpecificHalData;
@@ -278,6 +280,14 @@ struct CtlHalMixerData *HalUtlAddStreamDataAndCreateStreamVerb(AFB_ApiT apiHandl
return NULL;
}
+ wrap_json_pack(&streamAddedEventJ,
+ "{s:s, s:s, s:s}",
+ "action", "added",
+ "name", createdStreamData->verb,
+ "cardId", createdStreamData->streamCardId);
+
+ AFB_EventPush(currentSpecificHalData->ctlHalSpecificData->streamUpdates, streamAddedEventJ);
+
return createdStreamData;
}
@@ -288,6 +298,8 @@ int8_t HalUtlRemoveStreamDataAndDeleteStreamVerb(AFB_ApiT apiHandle,
{
int8_t returnedErr = 0;
+ json_object *streamRemovedEventJ;
+
CtlConfigT *ctrlConfig;
struct SpecificHalData *currentSpecificHalData;
@@ -307,15 +319,25 @@ int8_t HalUtlRemoveStreamDataAndDeleteStreamVerb(AFB_ApiT apiHandle,
streamCardId)))
return -3;
+ wrap_json_pack(&streamRemovedEventJ,
+ "{s:s, s:s, s:s}",
+ "action", "removed",
+ "name", toRemoveStreamData->verb,
+ "cardId", toRemoveStreamData->streamCardId);
+
if(afb_api_del_verb(apiHandle, verb, NULL)) {
AFB_ApiError(apiHandle,"Error while deleting verb for stream : '%s'", verb);
+ json_object_put(streamRemovedEventJ);
return -4;
}
if((returnedErr = HalUtlRemoveSelectedMixerData(&currentSpecificHalData->ctlHalSpecificData->ctlHalStreamsData, toRemoveStreamData))) {
AFB_ApiError(apiHandle,"Error %i while removing data for stream : '%s'", returnedErr, verb);
+ json_object_put(streamRemovedEventJ);
return -5;
}
+ AFB_EventPush(currentSpecificHalData->ctlHalSpecificData->streamUpdates, streamRemovedEventJ);
+
return 0;
} \ No newline at end of file
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)) {