summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJonathan Aillet <jonathan.aillet@iot.bzh>2018-06-01 22:55:57 +0200
committerJonathan Aillet <jonathan.aillet@iot.bzh>2018-10-08 15:51:00 +0200
commit069f177dd6a06d5274beed509ab85792263fb5e8 (patch)
treeb5b79eb335af9fe304429a14c720f0b0e2d94b7d
parent8943be0ab8f315d935c9bfe7b46523c4e94b0025 (diff)
Handle mixer responses correctly
Use a function to handle mixer responses on stream action calls correctly. Before, there was no differencations between responses from api calls that didn't end well. Now, we print a different message if the api/verb is not found and if the request was transfered but an error occured during it. Change-Id: Ib4f9c3cf14b6612cd14762b74466ce484fdfb09d Signed-off-by: Jonathan Aillet <jonathan.aillet@iot.bzh>
-rw-r--r--4a-hal/4a-hal-controllers/4a-hal-controllers-cb.c22
-rw-r--r--4a-hal/4a-hal-controllers/4a-hal-controllers-mixer-handler.c66
-rw-r--r--4a-hal/4a-hal-controllers/4a-hal-controllers-mixer-handler.h1
3 files changed, 75 insertions, 14 deletions
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 f80063d..be08165 100644
--- a/4a-hal/4a-hal-controllers/4a-hal-controllers-cb.c
+++ b/4a-hal/4a-hal-controllers/4a-hal-controllers-cb.c
@@ -81,7 +81,7 @@ void HalCtlsActionOnStream(afb_request *request)
{
int verbToCallSize;
- char *apiToCall, *halSoftMixerVerb, *verbToCall;
+ char *apiToCall, *mixerVerbName, *verbToCall;
afb_dynapi *apiHandle;
CtlConfigT *ctrlConfig;
@@ -120,8 +120,8 @@ void HalCtlsActionOnStream(afb_request *request)
return;
}
- halSoftMixerVerb = currentCtlHalData->ctlHalSpecificData->mixerVerbName;
- if(! halSoftMixerVerb) {
+ mixerVerbName = currentCtlHalData->ctlHalSpecificData->mixerVerbName;
+ if(! mixerVerbName) {
afb_request_fail(request, "hal_softmixer_verb", "Can't get hal mixer verb prefix");
return;
}
@@ -129,20 +129,17 @@ void HalCtlsActionOnStream(afb_request *request)
// TODO JAI: check status of hal before doing anything
// TODO JAI : remove verb to call prefix, each hal should have its own api in softmixer, and each streams should be created as verb by mixer
- verbToCallSize = (int) strlen(halSoftMixerVerb) + (int) strlen(request->verb) + 2;
+ verbToCallSize = (int) strlen(mixerVerbName) + (int) strlen(request->verb) + 2;
verbToCall = (char *) alloca(verbToCallSize * sizeof(char));
verbToCall[0] = '\0';
verbToCall[verbToCallSize - 1] = '\0';
- strcat(verbToCall, halSoftMixerVerb);
+ strcat(verbToCall, mixerVerbName);
strcat(verbToCall, "/");
strcat(verbToCall, request->verb);
if(afb_dynapi_call_sync(apiHandle, apiToCall, verbToCall, json_object_get(requestJson), &returnJ)) {
- afb_request_fail_f(request, "action", "Action %s seemingly not correctly transfered to %s",
- verbToCall,
- apiToCall);
-
+ HalCtlsHandleMixerCallError(request, apiToCall, verbToCall, returnJ, "stream_action");
}
else if(json_object_object_get_ex(returnJ, "response", &toReturnJ)){
afb_request_success_f(request, toReturnJ, "Action %s correctly transfered to %s, and successfull",
@@ -256,11 +253,8 @@ void HalCtlsInitMixer(afb_request *request)
// TODO JAI: test hal status (card is detected)
- if(afb_dynapi_call_sync(apiHandle, apiToCall, "mixer_new", json_object_get(currentCtlHalData->ctlHalSpecificData->halMixerJ), &returnJ)) {
- afb_request_fail_f(request,
- "mixer_new_call",
- "Seems that mix_new call to api %s didn't end well",
- apiToCall);
+ if(afb_dynapi_call_sync(apiHandle, apiToCall, "create", json_object_get(currentCtlHalData->ctlHalSpecificData->halMixerJ), &returnJ)) {
+ HalCtlsHandleMixerCallError(request, apiToCall, "create", returnJ, "mixer_create");
}
else if(json_object_object_get_ex(returnJ, "response", &toReturnJ)) {
err = HalCtlsHandleMixerAttachResponse(request, &currentCtlHalData->ctlHalSpecificData->ctlHalStreamsData, toReturnJ);
diff --git a/4a-hal/4a-hal-controllers/4a-hal-controllers-mixer-handler.c b/4a-hal/4a-hal-controllers/4a-hal-controllers-mixer-handler.c
index 21c99af..180a878 100644
--- a/4a-hal/4a-hal-controllers/4a-hal-controllers-mixer-handler.c
+++ b/4a-hal/4a-hal-controllers/4a-hal-controllers-mixer-handler.c
@@ -30,6 +30,72 @@
* HAL controllers hanlde mixer responses functions *
******************************************************************************/
+void HalCtlsHandleMixerCallError(AFB_ReqT request, char *apiCalled, char *verbCalled, json_object *callReturnJ, char *errorStatus)
+{
+ char *returnedStatus, *returnedInfo;
+
+ json_object *returnedRequestJ, *returnedStatusJ, *returnedInfoJ;
+
+ if(! json_object_object_get_ex(callReturnJ, "request", &returnedRequestJ)) {
+ AFB_ReqFail(request, errorStatus, "Couldn't get response request object");
+ return;
+ }
+
+ if(! json_object_is_type(returnedRequestJ, json_type_object)) {
+ AFB_ReqFail(request, errorStatus, "Response request object is not valid");
+ return;
+ }
+
+ if(! json_object_object_get_ex(returnedRequestJ, "status", &returnedStatusJ)) {
+ AFB_ReqFail(request, errorStatus, "Couldn't get response status object");
+ return;
+ }
+
+ if(! json_object_is_type(returnedStatusJ, json_type_string)) {
+ AFB_ReqFail(request, errorStatus, "Response status object is not valid");
+ return;
+ }
+
+ returnedStatus = (char *) json_object_get_string(returnedStatusJ);
+
+ if(! strcmp(returnedStatus, "unknown-api")) {
+ AFB_ReqFailF(request,
+ errorStatus,
+ "Api %s not found",
+ apiCalled);
+ return;
+ }
+
+ if(! strcmp(returnedStatus, "unknown-verb")) {
+ AFB_ReqFailF(request,
+ errorStatus,
+ "Verb %s of api %s not found",
+ verbCalled,
+ apiCalled);
+ return;
+ }
+
+ if(! json_object_object_get_ex(returnedRequestJ, "info", &returnedInfoJ)) {
+ AFB_ReqFail(request, errorStatus, "Couldn't get response info object");
+ return;
+ }
+
+ if(! json_object_is_type(returnedInfoJ, json_type_string)) {
+ AFB_ReqFail(request, errorStatus, "Response info object is not valid");
+ return;
+ }
+
+ returnedInfo = (char *) json_object_get_string(returnedInfoJ);
+
+ AFB_ReqFailF(request,
+ errorStatus,
+ "Api %s and verb %s found, but this error was raised : '%s' with this info : '%s'",
+ apiCalled,
+ verbCalled,
+ returnedStatus,
+ returnedInfo);
+}
+
int HalCtlsHandleMixerAttachResponse(AFB_ReqT request, struct CtlHalStreamsDataT *currentHalStreamsData, json_object *mixerResponseJ)
{
int err = 0;
diff --git a/4a-hal/4a-hal-controllers/4a-hal-controllers-mixer-handler.h b/4a-hal/4a-hal-controllers/4a-hal-controllers-mixer-handler.h
index 4512996..9fb6127 100644
--- a/4a-hal/4a-hal-controllers/4a-hal-controllers-mixer-handler.h
+++ b/4a-hal/4a-hal-controllers/4a-hal-controllers-mixer-handler.h
@@ -24,6 +24,7 @@
#include "../4a-hal-utilities/4a-hal-utilities-data.h"
+void HalCtlsHandleMixerCallError(AFB_ReqT request, char *apiCalled, char *verbCalled, json_object *callReturnJ, char *errorStatus);
int HalCtlsHandleMixerAttachResponse(AFB_ReqT request, struct CtlHalStreamsDataT *currentHalStreamsData, json_object *MixerResponseJ);
#endif /* _HAL_CTLS_SOFTMIXER_LINK_INCLUDE_ */ \ No newline at end of file