aboutsummaryrefslogtreecommitdiffstats
path: root/lib/4a-hal-utilities/4a-hal-utilities-hal-streams-handler.c
diff options
context:
space:
mode:
authorJonathan Aillet <jonathan.aillet@iot.bzh>2019-06-14 18:14:13 +0200
committerJonathan Aillet <jonathan.aillet@iot.bzh>2019-06-18 11:34:58 +0200
commit24046bfdb0568077a074b503d58a343a06f4234a (patch)
tree54ecdea5d0768d3d354a2ddbda1e309d574bbd14 /lib/4a-hal-utilities/4a-hal-utilities-hal-streams-handler.c
parent66f27bce6355cc7df978a9d7a6bc725542057a01 (diff)
Refactoring 'streams data' linked list
Refactoring 'streams data' linked list code using liburcu. BUG-AGL: SPEC-2329 Change-Id: Idf9367c015d73574d96d83c82a9e8f5b7588a45d Signed-off-by: Jonathan Aillet <jonathan.aillet@iot.bzh>
Diffstat (limited to 'lib/4a-hal-utilities/4a-hal-utilities-hal-streams-handler.c')
-rw-r--r--lib/4a-hal-utilities/4a-hal-utilities-hal-streams-handler.c251
1 files changed, 152 insertions, 99 deletions
diff --git a/lib/4a-hal-utilities/4a-hal-utilities-hal-streams-handler.c b/lib/4a-hal-utilities/4a-hal-utilities-hal-streams-handler.c
index 9e03f33..ffc5578 100644
--- a/lib/4a-hal-utilities/4a-hal-utilities-hal-streams-handler.c
+++ b/lib/4a-hal-utilities/4a-hal-utilities-hal-streams-handler.c
@@ -31,19 +31,116 @@
* Actions to be call when a stream verb is called *
******************************************************************************/
+json_object *HalUtlCallSingleStream(afb_req_t request,
+ afb_api_t apiHandle,
+ CtlConfigT *ctrlConfig,
+ struct HalData *currentHalData,
+ char *apiToCall,
+ struct InternalHalMixerData *currentMixerData,
+ json_object *requestJson)
+{
+ char *returnedError = NULL, *returnedInfo = NULL;
+
+ json_object *responseJ = NULL;
+
+ if(afb_api_call_sync(apiHandle,
+ apiToCall,
+ currentMixerData->verbToCall,
+ json_object_get(requestJson),
+ &responseJ,
+ &returnedError,
+ &returnedInfo)) {
+ if(responseJ)
+ json_object_put(responseJ);
+ AFB_API_ERROR(apiHandle,
+ "Something went wrong during call to verb '%s' of api '%s' "
+ "with error '%s' and info '%s' (stream '%s')",
+ currentMixerData->verbToCall,
+ apiToCall,
+ returnedError ? returnedError : "not returned",
+ returnedInfo ? returnedInfo : "not returned",
+ currentMixerData->verb);
+ free(returnedError);
+ free(returnedInfo);
+ return NULL;
+ }
+
+ if(! responseJ) {
+ AFB_API_ERROR(apiHandle,
+ "Seems that %s call to api %s succeed but no response was returned (stream '%s')",
+ currentMixerData->verbToCall,
+ apiToCall,
+ currentMixerData->verb);
+ free(returnedError);
+ free(returnedInfo);
+ return NULL;
+ }
+
+ // TBD JAI : When mixer events will be available, use them instead of generating events at calls
+ if(! currentMixerData->event ||
+ (afb_event_push(currentMixerData->event, json_object_get(responseJ)) < 0)) {
+ AFB_API_ERROR(apiHandle, "Could not generate an event for stream %s", currentMixerData->verb);
+ }
+
+ return responseJ;
+}
+
+json_object *HalUtlCallAllStream(afb_req_t request,
+ afb_api_t apiHandle,
+ CtlConfigT *ctrlConfig,
+ struct HalData *currentHalData,
+ char *apiToCall,
+ struct cds_list_head *streamsDataListHead,
+ json_object *requestJson)
+{
+ struct InternalHalMixerData *currentMixerData;
+
+ json_object *responseJ = NULL, *toReturnJ;
+
+ toReturnJ = json_object_new_object();
+ if(! toReturnJ) {
+ AFB_API_ERROR(apiHandle, "Didn't succeed to allocate response json object");
+ return NULL;
+ }
+
+ cds_list_for_each_entry(currentMixerData, streamsDataListHead, node) {
+ responseJ = HalUtlCallSingleStream(request,
+ apiHandle,
+ ctrlConfig,
+ currentHalData,
+ apiToCall,
+ currentMixerData,
+ requestJson);
+ if(! responseJ) {
+ AFB_API_ERROR(apiHandle,
+ "Seems that an error happened during %s call to api %s (stream '%s')",
+ currentMixerData->verbToCall,
+ apiToCall,
+ currentMixerData->verb);
+ json_object_put(toReturnJ);
+ return NULL;
+ }
+
+ json_object_object_add(toReturnJ, currentMixerData->verb, responseJ);
+ }
+
+ return toReturnJ;
+}
+
void HalUtlActionOnMixer(afb_req_t request, enum ActionOnMixerType actionType)
{
- int idx, count;
+ char *apiToCall;
- char *apiToCall, *returnedError = NULL, *returnedInfo = NULL;
+ struct cds_list_head *streamsDataListHead = NULL;
afb_api_t apiHandle;
CtlConfigT *ctrlConfig;
struct HalData *currentHalData;
+
struct InternalHalMixerData *currentMixerData = NULL;
- json_object *requestJson, *responseJ = NULL, *toReturnJ = NULL, *verboseBooleanJ;
+ json_object *requestJson, *verboseBooleanJ, *toReturnJ;
apiHandle = afb_req_get_api(request);
if(! apiHandle) {
@@ -92,97 +189,31 @@ void HalUtlActionOnMixer(afb_req_t request, enum ActionOnMixerType actionType)
return;
}
- currentMixerData = (struct InternalHalMixerData *) afb_req_get_vcbdata(request);
- if(! currentMixerData) {
- afb_req_fail(request, "hal_call_data", "Can't get current call data");
- return;
- }
-
switch(actionType) {
case ACTION_ON_MIXER_STREAM:
- count = 1;
- break;
+ currentMixerData = (struct InternalHalMixerData *) afb_req_get_vcbdata(request);
+ if(! currentMixerData) {
+ afb_req_fail(request, "hal_call_data", "Can't get stream to call data");
+ return;
+ }
- case ACTION_ON_MIXER_ALL_STREAM:
- count = (int) HalUtlGetNumberOfMixerDataInList(&currentMixerData);
- toReturnJ = json_object_new_object();
+ toReturnJ = HalUtlCallSingleStream(request,
+ apiHandle,
+ ctrlConfig,
+ currentHalData,
+ apiToCall,
+ currentMixerData,
+ requestJson);
if(! toReturnJ) {
- afb_req_fail(request,
- "response_json_object",
- "Didn't succeed to allocate response json object");
+ afb_req_fail_f(request,
+ "mixer_call",
+ "Seems that an error happened during %s call to api %s (stream '%s')",
+ currentMixerData->verbToCall,
+ apiToCall,
+ currentMixerData->verb);
return;
}
- break;
-
- default:
- afb_req_fail(request, "mixer_action_type", "Action type is unknown");
- return;
- }
-
- for(idx = 0; idx < count; idx++) {
- if(afb_api_call_sync(apiHandle,
- apiToCall,
- currentMixerData->verbToCall,
- json_object_get(requestJson),
- &responseJ,
- &returnedError,
- &returnedInfo)) {
- if(responseJ)
- json_object_put(responseJ);
- if(toReturnJ)
- json_object_put(toReturnJ);
- afb_req_fail_f(request,
- "mixer_call",
- "Something went wrong during call to verb '%s' of api '%s' with error '%s' and info '%s' (call to mixer %i out of %i)",
- currentMixerData->verbToCall,
- apiToCall,
- returnedError ? returnedError : "not returned",
- returnedInfo ? returnedInfo : "not returned",
- idx,
- count);
- free(returnedError);
- free(returnedInfo);
- return;
- }
-
- if(! responseJ) {
- if(toReturnJ)
- json_object_put(toReturnJ);
- afb_req_fail_f(request,
- "mixer_call",
- "Seems that %s call to api %s succeed but no response was returned (call to mixer %i out of %i)",
- currentMixerData->verbToCall,
- apiToCall,
- idx,
- count);
- free(returnedError);
- free(returnedInfo);
- return;
- }
-
- // TBD JAI : When mixer events will be available, use them instead of generating events at calls
- if(! currentMixerData->event ||
- (afb_event_push(currentMixerData->event, json_object_get(responseJ)) < 0)) {
- AFB_API_ERROR(apiHandle, "Could not generate an event for stream %s", currentMixerData->verb);
- }
-
- switch(actionType) {
- case ACTION_ON_MIXER_STREAM:
- toReturnJ = responseJ;
- break;
-
- case ACTION_ON_MIXER_ALL_STREAM:
- json_object_object_add(toReturnJ, currentMixerData->verb, responseJ);
- currentMixerData = currentMixerData->next;
- break;
- default:
- break;
- }
- }
-
- switch(actionType) {
- case ACTION_ON_MIXER_STREAM:
afb_req_success_f(request,
toReturnJ,
"Action %s correctly transferred to %s without any error raised",
@@ -191,13 +222,35 @@ void HalUtlActionOnMixer(afb_req_t request, enum ActionOnMixerType actionType)
break;
case ACTION_ON_MIXER_ALL_STREAM:
+ streamsDataListHead = (struct cds_list_head *) afb_req_get_vcbdata(request);
+ if(! streamsDataListHead) {
+ afb_req_fail(request, "hal_call_data", "Can't get stream list data");
+ return;
+ }
+
+ toReturnJ = HalUtlCallAllStream(request,
+ apiHandle,
+ ctrlConfig,
+ currentHalData,
+ apiToCall,
+ streamsDataListHead,
+ requestJson);
+ if(! toReturnJ) {
+ afb_req_fail_f(request,
+ "mixer_call",
+ "Seems that an error happened during call to all streams using api %s",
+ apiToCall);
+ return;
+ }
+
afb_req_success(request,
toReturnJ,
"Actions correctly transferred to all streams without any error raised");
break;
default:
- break;
+ afb_req_fail(request, "mixer_action_type", "Action type is unknown");
+ return;
}
}
@@ -241,7 +294,7 @@ struct InternalHalMixerData *HalUtlAddStreamDataAndCreateStreamVerb(afb_api_t ap
! currentHalData->internalHalData)
return NULL;
- createdStreamData = HalUtlAddMixerDataToMixerDataList(&currentHalData->internalHalData->streamsData);
+ createdStreamData = HalUtlAddMixerDataToMixerDataList(&currentHalData->internalHalData->streamsDataListHead);
if(! createdStreamData)
return NULL;
@@ -252,13 +305,13 @@ struct InternalHalMixerData *HalUtlAddStreamDataAndCreateStreamVerb(afb_api_t ap
if(! createdStreamData->verb ||
! createdStreamData->verbToCall ||
! createdStreamData->streamCardId) {
- HalUtlRemoveSelectedMixerData(&currentHalData->internalHalData->streamsData, createdStreamData);
+ HalUtlRemoveSelectedMixerData(&currentHalData->internalHalData->streamsDataListHead, createdStreamData);
return NULL;
}
createdStreamData->event = afb_api_make_event(apiHandle, createdStreamData->verb);
if(! createdStreamData->event) {
- HalUtlRemoveSelectedMixerData(&currentHalData->internalHalData->streamsData, createdStreamData);
+ HalUtlRemoveSelectedMixerData(&currentHalData->internalHalData->streamsDataListHead, createdStreamData);
return NULL;
}
@@ -271,7 +324,7 @@ struct InternalHalMixerData *HalUtlAddStreamDataAndCreateStreamVerb(afb_api_t ap
0,
0)) {
AFB_API_ERROR(apiHandle,"Error while creating verb for stream : '%s'", createdStreamData->verb);
- HalUtlRemoveSelectedMixerData(&currentHalData->internalHalData->streamsData, createdStreamData);
+ HalUtlRemoveSelectedMixerData(&currentHalData->internalHalData->streamsDataListHead, createdStreamData);
return NULL;
}
@@ -282,7 +335,7 @@ struct InternalHalMixerData *HalUtlAddStreamDataAndCreateStreamVerb(afb_api_t ap
"cardId", createdStreamData->streamCardId);
if(wrapRet) {
AFB_API_ERROR(apiHandle,"Didn't succeed to allocate added stream event json object");
- HalUtlRemoveSelectedMixerData(&currentHalData->internalHalData->streamsData, createdStreamData);
+ HalUtlRemoveSelectedMixerData(&currentHalData->internalHalData->streamsDataListHead, createdStreamData);
return NULL;
}
@@ -312,7 +365,6 @@ int HalUtlRemoveStreamDataAndDeleteStreamVerbUsingMixerData(afb_api_t apiHandle,
currentHalData = (struct HalData *) getExternalData(ctrlConfig);
if((! currentHalData) ||
(! currentHalData->internalHalData) ||
- (! currentHalData->internalHalData->streamsData) ||
(! currentHalData->internalHalData->streamUpdates))
return -3;
@@ -331,7 +383,7 @@ int HalUtlRemoveStreamDataAndDeleteStreamVerbUsingMixerData(afb_api_t apiHandle,
return -5;
}
- returnedErr = HalUtlRemoveSelectedMixerData(&currentHalData->internalHalData->streamsData, toRemoveStreamData);
+ returnedErr = HalUtlRemoveSelectedMixerData(&currentHalData->internalHalData->streamsDataListHead, toRemoveStreamData);
if(returnedErr) {
AFB_API_ERROR(apiHandle,
"Error %i while removing data for stream",
@@ -369,7 +421,7 @@ int HalUtlRemoveStreamDataAndDeleteStreamVerb(afb_api_t apiHandle,
! currentHalData->internalHalData)
return -3;
- toRemoveStreamData = HalUtlSearchMixerDataByProperties(&currentHalData->internalHalData->streamsData,
+ toRemoveStreamData = HalUtlSearchMixerDataByProperties(&currentHalData->internalHalData->streamsDataListHead,
verb,
verbToCall,
streamCardId);
@@ -395,6 +447,8 @@ int HalUtlRemoveAllStreamsDataAndDeleteAllStreamsVerb(afb_api_t apiHandle)
struct HalData *currentHalData;
+ struct InternalHalMixerData *currentMixerData, *savedMixerData;
+
if(! apiHandle)
return -1;
@@ -407,9 +461,8 @@ int HalUtlRemoveAllStreamsDataAndDeleteAllStreamsVerb(afb_api_t apiHandle)
(! currentHalData->internalHalData))
return -3;
- while(currentHalData->internalHalData->streamsData) {
- if(HalUtlRemoveStreamDataAndDeleteStreamVerbUsingMixerData(apiHandle,
- currentHalData->internalHalData->streamsData))
+ cds_list_for_each_entry_safe(currentMixerData, savedMixerData, &currentHalData->internalHalData->streamsDataListHead, node) {
+ if(HalUtlRemoveStreamDataAndDeleteStreamVerbUsingMixerData(apiHandle, currentMixerData))
return -4;
}