aboutsummaryrefslogtreecommitdiffstats
path: root/4a-hal
diff options
context:
space:
mode:
authorJonathan Aillet <jonathan.aillet@iot.bzh>2018-06-09 00:30:40 +0200
committerJonathan Aillet <jonathan.aillet@iot.bzh>2018-10-08 15:52:51 +0200
commit0f6d2131882e05e230f648626b81586c052b4da0 (patch)
treebe871b747128f8fe51c6a7d3ffb3aab6f3ac26b1 /4a-hal
parentcc1ec41093c3b0db3b8bdf8e8949ecdacceda190 (diff)
Move mixer attach at hal startup
Move mixer attach at hal startup instead of making attachment possible only with a verb. Now, if the hal audio device is detected at startup, it will automatically be attached to the mixer. As it is useless now, the verb used to attach mixer has been deleted. Change-Id: I32c8b829ac37fb31ede4fe8830a6f2a699c0835c 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.c9
-rw-r--r--4a-hal/4a-hal-controllers/4a-hal-controllers-cb.c79
-rw-r--r--4a-hal/4a-hal-controllers/4a-hal-controllers-cb.h1
-rw-r--r--4a-hal/4a-hal-controllers/4a-hal-controllers-mixer-handler.c109
-rw-r--r--4a-hal/4a-hal-controllers/4a-hal-controllers-mixer-handler.h8
5 files changed, 112 insertions, 94 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 f0ef696..404ecd2 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
@@ -31,6 +31,7 @@
#include "4a-hal-controllers-api-loader.h"
#include "4a-hal-controllers-alsacore-link.h"
#include "4a-hal-controllers-cb.h"
+#include "4a-hal-controllers-mixer-handler.h"
// Default api to print log when apihandle not available
AFB_ApiT AFB_default;
@@ -60,7 +61,6 @@ static struct HalUtlApiVerb CtlHalDynApiStaticVerbs[] =
{
/* VERB'S NAME FUNCTION TO CALL SHORT DESCRIPTION */
{ .verb = "list", .callback = HalCtlsListVerbs, .info = "List available verbs for this api"},
- { .verb = "init-mixer", .callback = HalCtlsInitMixer, .info = "Init Hal with 4a-softmixer"},
{ .verb = NULL } // Marker for end of the array
};
@@ -71,6 +71,8 @@ static struct HalUtlApiVerb CtlHalDynApiStaticVerbs[] =
static int HalCtlsInitOneApi(AFB_ApiT apiHandle)
{
+ int err;
+
CtlConfigT *ctrlConfig;
struct SpecificHalData *currentCtlHalData;
@@ -109,8 +111,11 @@ static int HalCtlsInitOneApi(AFB_ApiT apiHandle)
if(currentCtlHalData->sndCardId < 0)
currentCtlHalData->status = HAL_STATUS_UNAVAILABLE;
- else
+ else {
currentCtlHalData->status = HAL_STATUS_AVAILABLE;
+ if((err = HalCtlsAttachToMixer(apiHandle)))
+ AFB_ApiError(apiHandle, "%s: Error %i while attaching to mixer", __func__, err);
+ }
// TBD JAI: handle refresh of hal status for dynamic card (/dev/by-id)
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 5b9f2a8..98d2b0c 100644
--- a/4a-hal/4a-hal-controllers/4a-hal-controllers-cb.c
+++ b/4a-hal/4a-hal-controllers/4a-hal-controllers-cb.c
@@ -519,83 +519,4 @@ void HalCtlsListVerbs(AFB_ReqT request)
wrap_json_pack(&requestAnswer, "{s:o}", "streams", streamsArray);
AFB_ReqSucess(request, requestAnswer, "Requested data");
-}
-
-void HalCtlsInitMixer(AFB_ReqT request)
-{
- unsigned int err;
-
- char *apiToCall;
-
- AFB_ApiT apiHandle;
- CtlConfigT *ctrlConfig;
-
- struct SpecificHalData *currentCtlHalData;
-
- json_object *returnJ, *toReturnJ;
-
- apiHandle = (AFB_ApiT ) afb_request_get_dynapi(request);
- if(! apiHandle) {
- AFB_ReqFail(request, "api_handle", "Can't get current hal api handle");
- return;
- }
-
- ctrlConfig = (CtlConfigT *) afb_dynapi_get_userdata(apiHandle);
- if(! ctrlConfig) {
- AFB_ReqFail(request, "hal_controller_config", "Can't get current hal controller config");
- return;
- }
-
- currentCtlHalData = (struct SpecificHalData *) ctrlConfig->external;
- if(! currentCtlHalData) {
- AFB_ReqFail(request, "hal_controller_data", "Can't get current hal controller data");
- return;
- }
-
- apiToCall = currentCtlHalData->ctlHalSpecificData->mixerApiName;
- if(! apiToCall) {
- AFB_ReqFail(request, "mixer_api", "Can't get mixer api");
- return;
- }
-
- switch(currentCtlHalData->status) {
- case HAL_STATUS_UNAVAILABLE:
- AFB_ReqFail(request, "hal_unavailable", "Seems that the hal corresponding card was not found by alsacore at startup");
- return;
-
- case HAL_STATUS_READY:
- AFB_ReqSucess(request, NULL, "Seems that the hal mixer is already initialized");
- return;
-
- case HAL_STATUS_AVAILABLE:
- break;
- }
-
- if(AFB_ServiceSync(apiHandle, apiToCall, "create", json_object_get(currentCtlHalData->ctlHalSpecificData->halMixerJ), &returnJ)) {
- HalUtlHandleAppFwCallErrorInRequest(request, apiToCall, "create", returnJ, "mixer_create");
- }
- else if(json_object_object_get_ex(returnJ, "response", &toReturnJ)) {
- err = HalCtlsHandleMixerAttachResponse(request, &currentCtlHalData->ctlHalSpecificData->ctlHalStreamsData, toReturnJ);
- if(err != (int) MIXER_NO_ERROR) {
- AFB_ReqFailF(request,
- "handler_mixer_response",
- "Seems that create call to api %s succeed but this warning was risen by response decoder : %i",
- apiToCall,
- err);
- return;
- }
-
- AFB_ReqSucessF(request,
- toReturnJ,
- "Seems that create call to api %s succeed with no warning raised",
- apiToCall);
-
- currentCtlHalData->status = HAL_STATUS_READY;
- }
- else {
- AFB_ReqFailF(request,
- "invalid_response",
- "Seems that mix_new call to api %s succeed, but response is not valid",
- apiToCall);
- }
} \ No newline at end of file
diff --git a/4a-hal/4a-hal-controllers/4a-hal-controllers-cb.h b/4a-hal/4a-hal-controllers/4a-hal-controllers-cb.h
index e3eeeeb..014c539 100644
--- a/4a-hal/4a-hal-controllers/4a-hal-controllers-cb.h
+++ b/4a-hal/4a-hal-controllers/4a-hal-controllers-cb.h
@@ -34,6 +34,5 @@ int HalCtlsHalMapConfig(AFB_ApiT apiHandle, CtlSectionT *section, json_object *S
// HAL controllers verbs functions
void HalCtlsActionOnStream(AFB_ReqT request);
void HalCtlsListVerbs(AFB_ReqT request);
-void HalCtlsInitMixer(AFB_ReqT request);
#endif /* _HALMGR_CB_INCLUDE_ */ \ No newline at end of file
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 56a50a8..93901a4 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
@@ -21,31 +21,29 @@
#include <string.h>
#include <stdbool.h>
+#include "../4a-hal-utilities/4a-hal-utilities-appfw-responses-handler.h"
#include "../4a-hal-utilities/4a-hal-utilities-verbs-loader.h"
#include "4a-hal-controllers-mixer-handler.h"
#include "4a-hal-controllers-cb.h"
/*******************************************************************************
- * HAL controllers handle mixer response function *
+ * HAL controllers handle mixer calls functions *
******************************************************************************/
-int HalCtlsHandleMixerAttachResponse(AFB_ReqT request, struct CtlHalStreamsDataT *currentHalStreamsData, json_object *mixerResponseJ)
+int HalCtlsHandleMixerAttachResponse(AFB_ApiT apiHandle, struct CtlHalStreamsDataT *currentHalStreamsData, json_object *mixerResponseJ)
{
int err = (int) MIXER_NO_ERROR;
unsigned int idx;
char *currentStreamName, *currentStreamCardId;
- AFB_ApiT apiHandle;
-
struct HalUtlApiVerb *CtlHalDynApiStreamVerbs;
json_object *currentStreamJ;
- apiHandle = (AFB_ApiT) afb_request_get_dynapi(request);
if(! apiHandle) {
- AFB_ReqWarning(request, "%s: Can't get current hal api handle", __func__);
+ AFB_ApiError(apiHandle, "%s: Can't get current hal api handle", __func__);
return (int) MIXER_ERROR_API_UNAVAILABLE;
}
@@ -58,7 +56,7 @@ int HalCtlsHandleMixerAttachResponse(AFB_ReqT request, struct CtlHalStreamsDataT
break;
default:
currentHalStreamsData->count = 0;
- AFB_ReqWarning(request, "%s: no streams returned", __func__);
+ AFB_ApiWarning(apiHandle, "%s: no streams returned", __func__);
return (int) MIXER_ERROR_NO_STREAMS;
}
@@ -75,11 +73,11 @@ int HalCtlsHandleMixerAttachResponse(AFB_ReqT request, struct CtlHalStreamsDataT
currentStreamJ = mixerResponseJ;
if(wrap_json_unpack(currentStreamJ, "{s:s}", "uid", &currentStreamName)) {
- AFB_ReqWarning(request, "%s: can't find name in current stream object", __func__);
+ AFB_ApiError(apiHandle, "%s: can't find name in current stream object", __func__);
err += (int) MIXER_ERROR_STREAM_NAME_UNAVAILABLE;
}
else if(wrap_json_unpack(currentStreamJ, "{s:s}", "alsa", &currentStreamCardId)) {
- AFB_ReqWarning(request, "%s: can't find card id in current stream object", __func__);
+ AFB_ApiError(apiHandle, "%s: can't find card id in current stream object", __func__);
err += (int) MIXER_ERROR_STREAM_CARDID_UNAVAILABLE;
}
else {
@@ -93,9 +91,100 @@ int HalCtlsHandleMixerAttachResponse(AFB_ReqT request, struct CtlHalStreamsDataT
}
if(HalUtlLoadVerbs(apiHandle, CtlHalDynApiStreamVerbs)) {
- AFB_ReqWarning(request, "%s: error while creating verbs for streams", __func__);
+ AFB_ApiError(apiHandle, "%s: error while creating verbs for streams", __func__);
err += (int) MIXER_ERROR_COULDNT_ADD_STREAMS_AS_VERB;
}
return err;
+}
+
+int HalCtlsAttachToMixer(AFB_ApiT apiHandle)
+{
+ unsigned int err;
+
+ char *apiToCall, *returnedStatus = NULL, *returnedInfo = NULL;
+
+ enum CallError returnedError;
+
+ CtlConfigT *ctrlConfig;
+
+ struct SpecificHalData *currentCtlHalData;
+
+ json_object *returnJ, *toReturnJ;
+
+ ctrlConfig = (CtlConfigT *) afb_dynapi_get_userdata(apiHandle);
+ if(! ctrlConfig) {
+ AFB_ApiError(apiHandle, "%s: Can't get current hal controller config", __func__);
+ return -1;
+ }
+
+ currentCtlHalData = (struct SpecificHalData *) ctrlConfig->external;
+ if(! currentCtlHalData) {
+ AFB_ApiError(apiHandle, "%s: Can't get current hal controller data", __func__);
+ return -2;
+ }
+
+ apiToCall = currentCtlHalData->ctlHalSpecificData->mixerApiName;
+ if(! apiToCall) {
+ AFB_ApiError(apiHandle, "%s: Can't get mixer api", __func__);
+ return -3;
+ }
+
+ switch(currentCtlHalData->status) {
+ case HAL_STATUS_UNAVAILABLE:
+ AFB_ApiError(apiHandle, "%s: Seems that the hal corresponding card was not found by alsacore at startup", __func__);
+ return -4;
+
+ case HAL_STATUS_READY:
+ AFB_ApiNotice(apiHandle, "%s: Seems that the hal mixer is already initialized", __func__);
+ return 1;
+
+ case HAL_STATUS_AVAILABLE:
+ break;
+ }
+
+ if(AFB_ServiceSync(apiHandle, apiToCall, MIXER_ATTACH_VERB, json_object_get(currentCtlHalData->ctlHalSpecificData->halMixerJ), &returnJ)) {
+ returnedError = HalUtlHandleAppFwCallError(apiHandle, apiToCall, MIXER_ATTACH_VERB, returnJ, &returnedStatus, &returnedInfo);
+ AFB_ApiWarning(apiHandle,
+ "Error %i during call to verb %s of %s api with status '%s' and info '%s'",
+ (int) returnedError,
+ apiToCall,
+ MIXER_ATTACH_VERB,
+ returnedStatus ? returnedStatus : "not returned",
+ returnedInfo ? returnedInfo : "not returned");
+ return -6;
+ }
+ else if(json_object_object_get_ex(returnJ, "response", &toReturnJ)) {
+ err = HalCtlsHandleMixerAttachResponse(apiHandle, &currentCtlHalData->ctlHalSpecificData->ctlHalStreamsData, toReturnJ);
+ if(err != (int) MIXER_NO_ERROR) {
+ AFB_ApiError(apiHandle,
+ "%s: Seems that %s call to api %s succeed but this warning was risen by response decoder : %i '%s'",
+ __func__,
+ MIXER_ATTACH_VERB,
+ apiToCall,
+ err,
+ json_object_get_string(toReturnJ));
+ return -7;
+ }
+
+ AFB_ApiNotice(apiHandle,
+ "%s: Seems that %s call to api %s succeed with no warning raised : '%s'",
+ __func__,
+ MIXER_ATTACH_VERB,
+ apiToCall,
+ json_object_get_string(toReturnJ));
+
+ currentCtlHalData->status = HAL_STATUS_READY;
+ }
+ else {
+ AFB_ApiError(apiHandle,
+ "%s: Seems that %s call to api %s succeed, but response is not valid : '%s'",
+ __func__,
+ MIXER_ATTACH_VERB,
+ apiToCall,
+ json_object_get_string(returnJ));
+ return -8;
+ }
+
+ return 0;
} \ No newline at end of file
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 09e0dc7..74bca88 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
@@ -22,8 +22,12 @@
#include <wrap-json.h>
+#include "afb-helpers-utils.h"
+
#include "../4a-hal-utilities/4a-hal-utilities-data.h"
+#define MIXER_ATTACH_VERB "create"
+
// Enum for the type of error detected
enum MixerStatus {
MIXER_NO_ERROR=0,
@@ -34,7 +38,7 @@ enum MixerStatus {
MIXER_ERROR_COULDNT_ADD_STREAMS_AS_VERB =-100000,
};
-// HAL controllers handle mixer response function
-int HalCtlsHandleMixerAttachResponse(AFB_ReqT request, struct CtlHalStreamsDataT *currentHalStreamsData, json_object *MixerResponseJ);
+// HAL controllers handle mixer calls functions
+int HalCtlsAttachToMixer(AFB_ApiT apiHandle);
#endif /* _HAL_CTLS_SOFTMIXER_LINK_INCLUDE_ */ \ No newline at end of file