From 4f44ee8f17789ac27cd1e29a451ac450c7dbeb06 Mon Sep 17 00:00:00 2001 From: Jonathan Aillet Date: Mon, 7 Jan 2019 11:30:12 +0100 Subject: Turn '4a-hal-utilities' into an internal library That way, includes will be cleaner and '4a-hal-utilities' functions will be usable in plugin. Change-Id: I8a2146bd4e5dd5ef449b9ba7f2b1eed4d59045d3 Signed-off-by: Jonathan Aillet --- 4a-hal-utilities/4a-hal-utilities-alsa-data.c | 51 +++++ 4a-hal-utilities/4a-hal-utilities-alsa-data.h | 72 ++++++ .../4a-hal-utilities-appfw-responses-handler.c | 147 +++++++++++++ .../4a-hal-utilities-appfw-responses-handler.h | 45 ++++ 4a-hal-utilities/4a-hal-utilities-data.c | 243 ++++++++++++++++++++ 4a-hal-utilities/4a-hal-utilities-data.h | 108 +++++++++ 4a-hal-utilities/4a-hal-utilities-verbs-loader.c | 50 +++++ 4a-hal-utilities/4a-hal-utilities-verbs-loader.h | 28 +++ 4a-hal-utilities/CMakeLists.txt | 40 ++++ .../4a-hal-controllers-alsacore-link.c | 34 +-- .../4a-hal-controllers-alsacore-link.h | 45 +--- .../4a-hal-controllers-api-loader.c | 2 +- .../4a-hal-controllers-api-loader.h | 2 +- 4a-hal/4a-hal-controllers/4a-hal-controllers-cb.c | 6 +- .../4a-hal-controllers-mixer-link.c | 8 +- .../4a-hal-controllers-mixer-link.h | 2 +- .../4a-hal-controllers-value-handler.c | 2 + 4a-hal/4a-hal-manager/4a-hal-manager-cb.c | 2 +- 4a-hal/4a-hal-manager/4a-hal-manager-events.c | 3 +- 4a-hal/4a-hal-manager/4a-hal-manager.c | 5 +- .../4a-hal-utilities-appfw-responses-handler.c | 147 ------------- .../4a-hal-utilities-appfw-responses-handler.h | 45 ---- 4a-hal/4a-hal-utilities/4a-hal-utilities-data.c | 244 --------------------- 4a-hal/4a-hal-utilities/4a-hal-utilities-data.h | 108 --------- .../4a-hal-utilities-verbs-loader.c | 50 ----- .../4a-hal-utilities-verbs-loader.h | 28 --- 4a-hal/CMakeLists.txt | 4 +- plugins/lib/bluealsa/CMakeLists.txt | 1 + 28 files changed, 813 insertions(+), 709 deletions(-) create mode 100644 4a-hal-utilities/4a-hal-utilities-alsa-data.c create mode 100644 4a-hal-utilities/4a-hal-utilities-alsa-data.h create mode 100644 4a-hal-utilities/4a-hal-utilities-appfw-responses-handler.c create mode 100644 4a-hal-utilities/4a-hal-utilities-appfw-responses-handler.h create mode 100644 4a-hal-utilities/4a-hal-utilities-data.c create mode 100644 4a-hal-utilities/4a-hal-utilities-data.h create mode 100644 4a-hal-utilities/4a-hal-utilities-verbs-loader.c create mode 100644 4a-hal-utilities/4a-hal-utilities-verbs-loader.h create mode 100644 4a-hal-utilities/CMakeLists.txt delete mode 100644 4a-hal/4a-hal-utilities/4a-hal-utilities-appfw-responses-handler.c delete mode 100644 4a-hal/4a-hal-utilities/4a-hal-utilities-appfw-responses-handler.h delete mode 100644 4a-hal/4a-hal-utilities/4a-hal-utilities-data.c delete mode 100644 4a-hal/4a-hal-utilities/4a-hal-utilities-data.h delete mode 100644 4a-hal/4a-hal-utilities/4a-hal-utilities-verbs-loader.c delete mode 100644 4a-hal/4a-hal-utilities/4a-hal-utilities-verbs-loader.h diff --git a/4a-hal-utilities/4a-hal-utilities-alsa-data.c b/4a-hal-utilities/4a-hal-utilities-alsa-data.c new file mode 100644 index 0000000..ef2967a --- /dev/null +++ b/4a-hal-utilities/4a-hal-utilities-alsa-data.c @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2019 "IoT.bzh" + * Author Jonathan Aillet + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define _GNU_SOURCE + +#include + +#include + +#include "4a-hal-utilities-alsa-data.h" + +/******************************************************************************* + * Free contents of 'CtlHalAlsaMapT' data structure * + ******************************************************************************/ + +uint8_t HalUtlFreeAlsaCtlsMap(struct CtlHalAlsaMapT *alsaCtlsMap) +{ + int idx; + + if(! alsaCtlsMap) + return -1; + + if(alsaCtlsMap->ctlsCount > 0 && ! alsaCtlsMap->ctls) + return -2; + + for(idx = 0; idx < alsaCtlsMap->ctlsCount; idx++) { + free(alsaCtlsMap->ctls[idx].action); + free(alsaCtlsMap->ctls[idx].ctl.alsaCtlProperties.enums); + free(alsaCtlsMap->ctls[idx].ctl.alsaCtlProperties.dbscale); + } + + free(alsaCtlsMap->ctls); + + free(alsaCtlsMap); + + return 0; +} \ No newline at end of file diff --git a/4a-hal-utilities/4a-hal-utilities-alsa-data.h b/4a-hal-utilities/4a-hal-utilities-alsa-data.h new file mode 100644 index 0000000..5a998ae --- /dev/null +++ b/4a-hal-utilities/4a-hal-utilities-alsa-data.h @@ -0,0 +1,72 @@ +/* +* Copyright (C) 2019 "IoT.bzh" +* Author Jonathan Aillet +* +* Licensed under the Apache License, Version 2.0 (the "License"); +* you may not use this file except in compliance with the License. +* You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, software +* distributed under the License is distributed on an "AS IS" BASIS, +* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +* See the License for the specific language governing permissions and +* limitations under the License. +*/ + +#ifndef _HAL_UTILITIES_ALSA_DATA_INCLUDE_ +#define _HAL_UTILITIES_ALSA_DATA_INCLUDE_ + +#include + +#include + +#include + +#include + +struct CtlHalAlsaDBScale { + int min; + int max; + int step; + int mute; +}; + +struct CtlHalAlsaCtlProperties { + snd_ctl_elem_type_t type; + int count; + int minval; + int maxval; + int step; + // TBD JAI : use them + const char **enums; + struct CtlHalAlsaDBScale *dbscale; +}; + +struct CtlHalAlsaCtl { + char *name; + int numid; + int value; + struct CtlHalAlsaCtlProperties alsaCtlProperties; + struct CtlHalAlsaCtlProperties *alsaCtlCreation; +}; + +struct CtlHalAlsaMap { + const char *uid; + char *info; + AFB_EventT alsaControlEvent; + struct CtlHalAlsaCtl ctl; + json_object *actionJ; + CtlActionT *action; +}; + +struct CtlHalAlsaMapT { + struct CtlHalAlsaMap *ctls; + unsigned int ctlsCount; +}; + +// Free contents of 'CtlHalAlsaMapT' data structure +uint8_t HalUtlFreeAlsaCtlsMap(struct CtlHalAlsaMapT *alsaCtlsMap); + +#endif /* _HAL_UTILITIES_ALSA_DATA_INCLUDE_ */ \ No newline at end of file diff --git a/4a-hal-utilities/4a-hal-utilities-appfw-responses-handler.c b/4a-hal-utilities/4a-hal-utilities-appfw-responses-handler.c new file mode 100644 index 0000000..40581ef --- /dev/null +++ b/4a-hal-utilities/4a-hal-utilities-appfw-responses-handler.c @@ -0,0 +1,147 @@ +/* + * Copyright (C) 2018 "IoT.bzh" + * Author Jonathan Aillet + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define _GNU_SOURCE + +#include +#include + +#include "4a-hal-utilities-appfw-responses-handler.h" + +/******************************************************************************* + * Handle application framework response function * + ******************************************************************************/ + +enum CallError HalUtlHandleAppFwCallError(AFB_ApiT apiHandle, char *apiCalled, char *verbCalled, json_object *callReturnJ, char **returnedStatus, char **returnedInfo) +{ + json_object *returnedRequestJ, *returnedStatusJ, *returnedInfoJ; + + if(! apiHandle || ! apiCalled || ! verbCalled || ! callReturnJ) + return CALL_ERROR_INVALID_ARGS; + + if(! json_object_object_get_ex(callReturnJ, "request", &returnedRequestJ)) { + AFB_ApiWarning(apiHandle, "Couldn't get response request object"); + return CALL_ERROR_REQUEST_UNAVAILABLE; + } + + if(! json_object_is_type(returnedRequestJ, json_type_object)) { + AFB_ApiWarning(apiHandle, "Response request object is not valid"); + return CALL_ERROR_REQUEST_NOT_VALID; + } + + if(! json_object_object_get_ex(returnedRequestJ, "status", &returnedStatusJ)) { + AFB_ApiWarning(apiHandle, "Couldn't get response status object"); + return CALL_ERROR_REQUEST_STATUS_UNAVAILABLE; + } + + if(! json_object_is_type(returnedStatusJ, json_type_string)) { + AFB_ApiWarning(apiHandle, "Response status object is not valid"); + return CALL_ERROR_REQUEST_STATUS_NOT_VALID; + } + + *returnedStatus = (char *) json_object_get_string(returnedStatusJ); + + if(! strcmp(*returnedStatus, "unknown-api")) { + AFB_ApiWarning(apiHandle, "Api %s not found", apiCalled); + return CALL_ERROR_API_UNAVAILABLE; + } + + if(! strcmp(*returnedStatus, "unknown-verb")) { + AFB_ApiWarning(apiHandle, "Verb %s of api %s not found", verbCalled, apiCalled); + return CALL_ERROR_VERB_UNAVAILABLE; + } + + if(! json_object_object_get_ex(returnedRequestJ, "info", &returnedInfoJ)) { + AFB_ApiWarning(apiHandle, "Couldn't get response info object"); + return CALL_ERROR_REQUEST_INFO_UNAVAILABLE; + } + + if(! json_object_is_type(returnedInfoJ, json_type_string)) { + AFB_ApiWarning(apiHandle, "Response info object is not valid"); + return CALL_ERROR_REQUEST_INFO_NOT_VALID; + } + + *returnedInfo = (char *) json_object_get_string(returnedInfoJ); + + AFB_ApiWarning(apiHandle, + "Api %s and verb %s found, but this error was raised : '%s' with this info : '%s'", + apiCalled, + verbCalled, + *returnedStatus, + *returnedInfo); + + return CALL_ERROR_RETURNED; +} + +void HalUtlHandleAppFwCallErrorInRequest(AFB_ReqT request, char *apiCalled, char *verbCalled, json_object *callReturnJ, char *errorStatusToSend) +{ + char *returnedStatus = NULL, *returnedInfo = NULL; + + AFB_ApiT apiHandle; + + if(! request || ! apiCalled || ! verbCalled || ! callReturnJ) { + AFB_ReqFailF(request, "invalid_args", "Invalid arguments"); + return; + } + + apiHandle = (AFB_ApiT) AFB_ReqGetApi(request); + if(! apiHandle) { + AFB_ReqFailF(request, "api_handle", "Can't get hal manager api handle"); + return; + } + + switch(HalUtlHandleAppFwCallError(apiHandle, apiCalled, verbCalled, callReturnJ, &returnedStatus, &returnedInfo)) { + case CALL_ERROR_REQUEST_UNAVAILABLE: + case CALL_ERROR_REQUEST_NOT_VALID: + case CALL_ERROR_REQUEST_STATUS_UNAVAILABLE: + case CALL_ERROR_REQUEST_STATUS_NOT_VALID: + case CALL_ERROR_REQUEST_INFO_UNAVAILABLE: + case CALL_ERROR_REQUEST_INFO_NOT_VALID: + AFB_ReqFail(request, errorStatusToSend, "Error with response object"); + return; + + case CALL_ERROR_API_UNAVAILABLE: + AFB_ReqFailF(request, errorStatusToSend, "Api %s not found", apiCalled); + return; + + case CALL_ERROR_VERB_UNAVAILABLE: + AFB_ReqFailF(request, errorStatusToSend, "Verb %s of api %s not found", verbCalled, apiCalled); + return; + + case CALL_ERROR_RETURNED: + AFB_ReqFailF(request, + errorStatusToSend, + "Api %s and verb %s found, but this error was raised : '%s' with this info : '%s'", + apiCalled, + verbCalled, + returnedStatus ? returnedStatus : "not returned", + returnedInfo ? returnedInfo : "not returned"); + return; + + case CALL_ERROR_INVALID_ARGS: + AFB_ReqFailF(request, + errorStatusToSend, + "Api %s and verb %s found, but the arguments are invalid", + apiCalled, + verbCalled); + return; + + default: + AFB_ReqFailF(request, errorStatusToSend, "Unknown error happened during call to verb %s of api %s", verbCalled, apiCalled); + return; + } +} \ No newline at end of file diff --git a/4a-hal-utilities/4a-hal-utilities-appfw-responses-handler.h b/4a-hal-utilities/4a-hal-utilities-appfw-responses-handler.h new file mode 100644 index 0000000..923ca6b --- /dev/null +++ b/4a-hal-utilities/4a-hal-utilities-appfw-responses-handler.h @@ -0,0 +1,45 @@ +/* + * Copyright (C) 2018 "IoT.bzh" + * Author Jonathan Aillet + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef _HAL_UTILITIES_APPFW_RESP_HANDLER_INCLUDE_ +#define _HAL_UTILITIES_APPFW_RESP_HANDLER_INCLUDE_ + +#include + +#include + +#include + +// Enum for the type of error detected +enum CallError { + CALL_ERROR_INVALID_ARGS=-1, + CALL_ERROR_REQUEST_UNAVAILABLE=-2, + CALL_ERROR_REQUEST_NOT_VALID=-3, + CALL_ERROR_REQUEST_STATUS_UNAVAILABLE=-4, + CALL_ERROR_REQUEST_STATUS_NOT_VALID=-5, + CALL_ERROR_API_UNAVAILABLE=-6, + CALL_ERROR_VERB_UNAVAILABLE=-7, + CALL_ERROR_REQUEST_INFO_UNAVAILABLE=-8, + CALL_ERROR_REQUEST_INFO_NOT_VALID=-9, + CALL_ERROR_RETURNED=-10, +}; + +// Handle application framework response function +extern enum CallError HalUtlHandleAppFwCallError(AFB_ApiT apiHandle, char *apiCalled, char *verbCalled, json_object *callReturnJ, char **returnedStatus, char **returnedInfo); +void HalUtlHandleAppFwCallErrorInRequest(AFB_ReqT request, char *apiCalled, char *verbCalled, json_object *callReturnJ, char *errorStatusToSend); + +#endif /* _HAL_UTILITIES_APPFW_RESP_HANDLER_INCLUDE_ */ \ No newline at end of file diff --git a/4a-hal-utilities/4a-hal-utilities-data.c b/4a-hal-utilities/4a-hal-utilities-data.c new file mode 100644 index 0000000..4bb19a8 --- /dev/null +++ b/4a-hal-utilities/4a-hal-utilities-data.c @@ -0,0 +1,243 @@ +/* + * Copyright (C) 2018 "IoT.bzh" + * Author Jonathan Aillet + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define _GNU_SOURCE + +#include +#include + +#include + +#include "4a-hal-utilities-data.h" +#include "4a-hal-utilities-alsa-data.h" + +/******************************************************************************* + * Specfic Hal controller streams data handling functions * + ******************************************************************************/ + +uint8_t HalUtlRemoveAllCtlHalStreamsData(struct CtlHalMixerDataT *ctlHalStreamsData) +{ + unsigned int cpt; + + if(! ctlHalStreamsData) + return -1; + + if(! ctlHalStreamsData->count) + return -2; + + for(cpt = 0; cpt < ctlHalStreamsData->count; cpt++) { + free(ctlHalStreamsData->data[cpt].verb); + free(ctlHalStreamsData->data[cpt].verbToCall); + free(ctlHalStreamsData->data[cpt].streamCardId); + } + + free(ctlHalStreamsData->data); + + return 0; +} + +/******************************************************************************* + * Specfic Hal data handling functions * + ******************************************************************************/ + +struct SpecificHalData *HalUtlAddHalApiToHalList(struct SpecificHalData **firstHalData) +{ + struct SpecificHalData *currentApi; + + if(! firstHalData) + return NULL; + + currentApi = *firstHalData; + + if(! currentApi) { + currentApi = (struct SpecificHalData *) calloc(1, sizeof(struct SpecificHalData)); + if(! currentApi) + return NULL; + + *firstHalData = currentApi; + } + else { + while(currentApi->next) + currentApi = currentApi->next; + + currentApi->next = calloc(1, sizeof(struct SpecificHalData)); + if(! currentApi) + return NULL; + + currentApi = currentApi->next; + } + + memset(currentApi, 0, sizeof(struct SpecificHalData)); + + return currentApi; +} + +int8_t HalUtlRemoveSelectedHalFromList(struct SpecificHalData **firstHalData, struct SpecificHalData *apiToRemove) +{ + struct SpecificHalData *currentApi, *matchingApi; + + if(! firstHalData || ! apiToRemove) + return -1; + + currentApi = *firstHalData; + + if(currentApi == apiToRemove) { + *firstHalData = currentApi->next; + matchingApi = currentApi; + } + else { + while(currentApi && currentApi->next != apiToRemove) + currentApi = currentApi->next; + + if(currentApi) { + matchingApi = currentApi->next; + currentApi->next = currentApi->next->next; + } + else { + return -2; + } + } + + if(! matchingApi->internal) { + free(matchingApi->apiName); + free(matchingApi->sndCardPath); + free(matchingApi->info); + free(matchingApi->author); + free(matchingApi->version); + free(matchingApi->date); + } + else { + HalUtlRemoveAllCtlHalStreamsData(&matchingApi->ctlHalSpecificData->ctlHalStreamsData); + + HalUtlFreeAlsaCtlsMap(matchingApi->ctlHalSpecificData->ctlHalAlsaMapT); + + free(matchingApi->ctlHalSpecificData); + } + + free(matchingApi); + + return 0; +} + +int64_t HalUtlRemoveAllHalFromList(struct SpecificHalData **firstHalData) +{ + int8_t ret; + int64_t CtlHalApiRemoved = 0; + + while(*firstHalData) { + ret = HalUtlRemoveSelectedHalFromList(firstHalData, *firstHalData); + if(ret) + return (int64_t) ret; + + CtlHalApiRemoved++; + } + + return CtlHalApiRemoved; +} + +int64_t HalUtlGetNumberOfHalInList(struct SpecificHalData **firstHalData) +{ + int64_t numberOfCtlHal = 0; + struct SpecificHalData *currentApi; + + if(! firstHalData) + return -1; + + currentApi = *firstHalData; + + while(currentApi) { + currentApi = currentApi->next; + numberOfCtlHal++; + } + + return numberOfCtlHal; +} + +struct SpecificHalData *HalUtlSearchHalDataByApiName(struct SpecificHalData **firstHalData, char *apiName) +{ + struct SpecificHalData *currentApi; + + if(! firstHalData || ! apiName) + return NULL; + + currentApi = *firstHalData; + + while(currentApi) { + if(! strcmp(apiName, currentApi->apiName)) + return currentApi; + + currentApi = currentApi->next; + } + + return NULL; +} + + +struct SpecificHalData *HalUtlSearchReadyHalDataByCarId(struct SpecificHalData **firstHalData, int cardId) +{ + struct SpecificHalData *currentApi; + + if(! firstHalData) + return NULL; + + currentApi = *firstHalData; + while(currentApi) { + if(currentApi->status == HAL_STATUS_READY && currentApi->sndCardId == cardId) + return currentApi; + + currentApi = currentApi->next; + } + + return NULL; +} + +/******************************************************************************* + * Hal Manager data handling functions * + ******************************************************************************/ + +uint8_t HalUtlInitializeHalMgrData(AFB_ApiT apiHandle, struct HalMgrData *HalMgrGlobalData, char *apiName, char *info) +{ + if(! apiHandle || ! HalMgrGlobalData || ! apiName || ! info) + return -1; + + // Allocate and fill apiName and info strings + HalMgrGlobalData->apiName = strdup(apiName); + if(! HalMgrGlobalData->apiName) + return -2; + + HalMgrGlobalData->info = strdup(info); + if(! HalMgrGlobalData->apiName) + return -3; + + HalMgrGlobalData->apiHandle = apiHandle; + + return 0; +} + +void HalUtlRemoveHalMgrData(struct HalMgrData *HalMgrGlobalData) +{ + if(! HalMgrGlobalData) + return; + + if(HalMgrGlobalData->first) + HalUtlRemoveAllHalFromList(&HalMgrGlobalData->first); + + free(HalMgrGlobalData->apiName); + free(HalMgrGlobalData->info); + + free(HalMgrGlobalData); +} \ No newline at end of file diff --git a/4a-hal-utilities/4a-hal-utilities-data.h b/4a-hal-utilities/4a-hal-utilities-data.h new file mode 100644 index 0000000..031fa9b --- /dev/null +++ b/4a-hal-utilities/4a-hal-utilities-data.h @@ -0,0 +1,108 @@ +/* + * Copyright (C) 2018 "IoT.bzh" + * Author Jonathan Aillet + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef _HAL_UTILITIES_DATA_INCLUDE_ +#define _HAL_UTILITIES_DATA_INCLUDE_ + +#include + +#include + +#include + +#include + +#include "4a-hal-utilities-alsa-data.h" + +// Enum for sharing hal (controller or external) status +enum HalStatus { + HAL_STATUS_UNAVAILABLE=0, + HAL_STATUS_AVAILABLE=1, + HAL_STATUS_READY=2 +}; + +// Structure to store stream data +struct CtlHalMixerData { + char *verb; + char *verbToCall; + char *streamCardId; + AFB_EventT event; +}; + +// Structure to store stream data table +struct CtlHalMixerDataT { + struct CtlHalMixerData *data; + unsigned int count; +}; + +// Structure to store specific controller hal data +struct CtlHalSpecificData { + char *mixerApiName; + char *prefix; + json_object *halMixerJ; + + struct CtlHalMixerDataT ctlHalStreamsData; + struct CtlHalMixerDataT ctlHalPlaybacksData; + struct CtlHalMixerDataT ctlHalCapturesData; + struct CtlHalAlsaMapT *ctlHalAlsaMapT; + + AFB_ApiT apiHandle; + CtlConfigT *ctrlConfig; +}; + +// Structure to store specific hal (controller or external) data +struct SpecificHalData { + char *apiName; + enum HalStatus status; + char *sndCardPath; + int sndCardId; + char *info; + unsigned int internal; + + char *author; + char *version; + char *date; + // Can be beefed up if needed + + struct CtlHalSpecificData *ctlHalSpecificData; // Can be NULL if external api + + struct SpecificHalData *next; +}; + +// Structure to store hal manager data +struct HalMgrData { + char *apiName; + char *info; + + AFB_ApiT apiHandle; + + struct SpecificHalData *first; +}; + +// Exported verbs for 'struct SpecificHalData' handling +struct SpecificHalData *HalUtlAddHalApiToHalList(struct SpecificHalData **firstHalData); +int8_t HalUtlRemoveSelectedHalFromList(struct SpecificHalData **firstHalData, struct SpecificHalData *ApiToRemove); +int64_t HalUtlRemoveAllHalFromList(struct SpecificHalData **firstHalData); +int64_t HalUtlGetNumberOfHalInList(struct SpecificHalData **firstHalData); +struct SpecificHalData *HalUtlSearchHalDataByApiName(struct SpecificHalData **firstHalData, char *apiName); +struct SpecificHalData *HalUtlSearchReadyHalDataByCarId(struct SpecificHalData **firstHalData, int cardId); + +// Exported verbs for 'struct HalMgrData' handling +uint8_t HalUtlInitializeHalMgrData(AFB_ApiT apiHandle, struct HalMgrData *HalMgrGlobalData, char *apiName, char *info); +void HalUtlRemoveHalMgrData(struct HalMgrData *HalMgrGlobalData); + +#endif /* _HAL_UTILITIES_DATA_INCLUDE_ */ \ No newline at end of file diff --git a/4a-hal-utilities/4a-hal-utilities-verbs-loader.c b/4a-hal-utilities/4a-hal-utilities-verbs-loader.c new file mode 100644 index 0000000..f557f4c --- /dev/null +++ b/4a-hal-utilities/4a-hal-utilities-verbs-loader.c @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2018 "IoT.bzh" + * Author Jonathan Aillet + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#define _GNU_SOURCE + +#include +#include + +#include + +#include "4a-hal-utilities-verbs-loader.h" + +/******************************************************************************* + * Dynamic API common functions * + ******************************************************************************/ + +int HalUtlLoadVerbs(AFB_ApiT apiHandle, AFB_ApiVerbs *verbs) +{ + int idx, errCount = 0; + + if(! apiHandle || ! verbs) + return -1; + + for (idx = 0; verbs[idx].verb; idx++) { + errCount+= AFB_ApiAddVerb(apiHandle, + verbs[idx].verb, + NULL, + verbs[idx].callback, + (void *) &verbs[idx], + verbs[idx].auth, + 0, + 0); + } + + return errCount; +} \ No newline at end of file diff --git a/4a-hal-utilities/4a-hal-utilities-verbs-loader.h b/4a-hal-utilities/4a-hal-utilities-verbs-loader.h new file mode 100644 index 0000000..2bfa1cd --- /dev/null +++ b/4a-hal-utilities/4a-hal-utilities-verbs-loader.h @@ -0,0 +1,28 @@ +/* + * Copyright (C) 2018 "IoT.bzh" + * Author Jonathan Aillet + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef _HAL_UTILITIES_VERBS_LOADER_INCLUDE_ +#define _HAL_UTILITIES_VERBS_LOADER_INCLUDE_ + +#include + +#include + +// Verb that allows to add verb to a dynamic api +int HalUtlLoadVerbs(AFB_ApiT apiHandle, AFB_ApiVerbs *verbs); + +#endif /* _HAL_UTILITIES_VERBS_LOADER_INCLUDE_ */ \ No newline at end of file diff --git a/4a-hal-utilities/CMakeLists.txt b/4a-hal-utilities/CMakeLists.txt new file mode 100644 index 0000000..a45cb2c --- /dev/null +++ b/4a-hal-utilities/CMakeLists.txt @@ -0,0 +1,40 @@ +########################################################################### +# Copyright 2015, 2016, 2017, 2018, 2019 IoT.bzh +# +# author: Fulup Ar Foll +# contrib: Jonathan Aillet +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +########################################################################### + +# Add target to project dependency list +PROJECT_TARGET_ADD(4a-hal-utilities) + + # Define project Targets + ADD_LIBRARY(${TARGET_NAME} STATIC + 4a-hal-utilities-alsa-data.c + 4a-hal-utilities-appfw-responses-handler.c + 4a-hal-utilities-data.c + 4a-hal-utilities-verbs-loader.c) + + # Library dependencies (include updates automatically) + TARGET_LINK_LIBRARIES(${TARGET_NAME} + afb-helpers + ctl-utilities + ${link_libraries} + ) + + # Define target includes for this target client + TARGET_INCLUDE_DIRECTORIES(${TARGET_NAME} PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR} + ) diff --git a/4a-hal/4a-hal-controllers/4a-hal-controllers-alsacore-link.c b/4a-hal/4a-hal-controllers/4a-hal-controllers-alsacore-link.c index 4ae5a13..f1f99a6 100644 --- a/4a-hal/4a-hal-controllers/4a-hal-controllers-alsacore-link.c +++ b/4a-hal/4a-hal-controllers/4a-hal-controllers-alsacore-link.c @@ -24,10 +24,13 @@ #include +#include + #include -#include "../4a-hal-utilities/4a-hal-utilities-data.h" -#include "../4a-hal-utilities/4a-hal-utilities-appfw-responses-handler.h" +#include "4a-hal-utilities-alsa-data.h" +#include "4a-hal-utilities-data.h" +#include "4a-hal-utilities-appfw-responses-handler.h" #include "4a-hal-controllers-alsacore-link.h" #include "4a-hal-controllers-value-handler.h" @@ -63,33 +66,6 @@ snd_ctl_elem_type_t HalCtlsMapsAlsaTypeToEnum(const char *label) return SND_CTL_ELEM_TYPE_NONE; } -/******************************************************************************* - * Free contents of 'CtlHalAlsaMapT' data structure * - ******************************************************************************/ - -uint8_t HalCtlsFreeAlsaCtlsMap(struct CtlHalAlsaMapT *alsaCtlsMap) -{ - int idx; - - if(! alsaCtlsMap) - return -1; - - if(alsaCtlsMap->ctlsCount > 0 && ! alsaCtlsMap->ctls) - return -2; - - for(idx = 0; idx < alsaCtlsMap->ctlsCount; idx++) { - free(alsaCtlsMap->ctls[idx].action); - free(alsaCtlsMap->ctls[idx].ctl.alsaCtlProperties.enums); - free(alsaCtlsMap->ctls[idx].ctl.alsaCtlProperties.dbscale); - } - - free(alsaCtlsMap->ctls); - - free(alsaCtlsMap); - - return 0; -} - /******************************************************************************* * HAL controllers alsacore calls funtions * ******************************************************************************/ diff --git a/4a-hal/4a-hal-controllers/4a-hal-controllers-alsacore-link.h b/4a-hal/4a-hal-controllers/4a-hal-controllers-alsacore-link.h index 5d687aa..351ad59 100644 --- a/4a-hal/4a-hal-controllers/4a-hal-controllers-alsacore-link.h +++ b/4a-hal/4a-hal-controllers/4a-hal-controllers-alsacore-link.h @@ -26,6 +26,8 @@ #include +#include "4a-hal-utilities-alsa-data.h" + #define ALSACORE_API "alsacore" #define ALSACORE_SUBSCRIBE_VERB "subscribe" #define ALSACORE_GETINFO_VERB "infoget" @@ -33,52 +35,9 @@ #define ALSACORE_CTLSET_VERB "ctlset" #define ALSACORE_ADDCTL_VERB "addcustomctl" -struct CtlHalAlsaDBScale { - int min; - int max; - int step; - int mute; -}; - -struct CtlHalAlsaCtlProperties { - snd_ctl_elem_type_t type; - int count; - int minval; - int maxval; - int step; - // TBD JAI : use them - const char **enums; - struct CtlHalAlsaDBScale *dbscale; -}; - -struct CtlHalAlsaCtl { - char *name; - int numid; - int value; - struct CtlHalAlsaCtlProperties alsaCtlProperties; - struct CtlHalAlsaCtlProperties *alsaCtlCreation; -}; - -struct CtlHalAlsaMap { - const char *uid; - char *info; - AFB_EventT alsaControlEvent; - struct CtlHalAlsaCtl ctl; - json_object *actionJ; - CtlActionT *action; -}; - -struct CtlHalAlsaMapT { - struct CtlHalAlsaMap *ctls; - unsigned int ctlsCount; -}; - // Alsa control types map from string function snd_ctl_elem_type_t HalCtlsMapsAlsaTypeToEnum(const char *label); -// Free contents of 'CtlHalAlsaMapT' data structure -uint8_t HalCtlsFreeAlsaCtlsMap(struct CtlHalAlsaMapT *alsaCtlsMap); - // HAL controllers alsacore calls funtions int HalCtlsGetCardIdByCardPath(AFB_ApiT apiHandle, char *devPath); int HalCtlsSubscribeToAlsaCardEvent(AFB_ApiT apiHandle, char *cardId); 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 4cac346..72515e7 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 @@ -27,7 +27,7 @@ #include -#include "../4a-hal-utilities/4a-hal-utilities-verbs-loader.h" +#include "4a-hal-utilities-verbs-loader.h" #include "4a-hal-controllers-api-loader.h" #include "4a-hal-controllers-alsacore-link.h" diff --git a/4a-hal/4a-hal-controllers/4a-hal-controllers-api-loader.h b/4a-hal/4a-hal-controllers/4a-hal-controllers-api-loader.h index 70e61cd..f1d3bfd 100644 --- a/4a-hal/4a-hal-controllers/4a-hal-controllers-api-loader.h +++ b/4a-hal/4a-hal-controllers/4a-hal-controllers-api-loader.h @@ -22,7 +22,7 @@ #include -#include "../4a-hal-utilities/4a-hal-utilities-data.h" +#include "4a-hal-utilities-data.h" // Verbs that can be use to create api int HalCtlsCreateApi(AFB_ApiT apiHandle, char *path, struct HalMgrData *HalMgrGlobalData); 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 a8d0ee4..ba2454a 100644 --- a/4a-hal/4a-hal-controllers/4a-hal-controllers-cb.c +++ b/4a-hal/4a-hal-controllers/4a-hal-controllers-cb.c @@ -22,8 +22,10 @@ #include -#include "../4a-hal-utilities/4a-hal-utilities-data.h" -#include "../4a-hal-utilities/4a-hal-utilities-appfw-responses-handler.h" +#include + +#include "4a-hal-utilities-data.h" +#include "4a-hal-utilities-appfw-responses-handler.h" #include "4a-hal-controllers-cb.h" #include "4a-hal-controllers-alsacore-link.h" diff --git a/4a-hal/4a-hal-controllers/4a-hal-controllers-mixer-link.c b/4a-hal/4a-hal-controllers/4a-hal-controllers-mixer-link.c index 807dbb8..fd42899 100644 --- a/4a-hal/4a-hal-controllers/4a-hal-controllers-mixer-link.c +++ b/4a-hal/4a-hal-controllers/4a-hal-controllers-mixer-link.c @@ -22,9 +22,11 @@ #include -#include "../4a-hal-utilities/4a-hal-utilities-appfw-responses-handler.h" -#include "../4a-hal-utilities/4a-hal-utilities-data.h" -#include "../4a-hal-utilities/4a-hal-utilities-verbs-loader.h" +#include + +#include "4a-hal-utilities-appfw-responses-handler.h" +#include "4a-hal-utilities-data.h" +#include "4a-hal-utilities-verbs-loader.h" #include "../4a-hal-manager/4a-hal-manager.h" diff --git a/4a-hal/4a-hal-controllers/4a-hal-controllers-mixer-link.h b/4a-hal/4a-hal-controllers/4a-hal-controllers-mixer-link.h index 165b70d..9189664 100644 --- a/4a-hal/4a-hal-controllers/4a-hal-controllers-mixer-link.h +++ b/4a-hal/4a-hal-controllers/4a-hal-controllers-mixer-link.h @@ -24,7 +24,7 @@ #include "afb-helpers-utils.h" -#include "../4a-hal-utilities/4a-hal-utilities-data.h" +#include "4a-hal-utilities-data.h" #define MIXER_ATTACH_VERB "attach" #define MIXER_INFO_VERB "info" diff --git a/4a-hal/4a-hal-controllers/4a-hal-controllers-value-handler.c b/4a-hal/4a-hal-controllers/4a-hal-controllers-value-handler.c index 7a3dedd..4273def 100644 --- a/4a-hal/4a-hal-controllers/4a-hal-controllers-value-handler.c +++ b/4a-hal/4a-hal-controllers/4a-hal-controllers-value-handler.c @@ -25,6 +25,8 @@ #include +#include + #include "4a-hal-controllers-value-handler.h" #include "4a-hal-controllers-alsacore-link.h" diff --git a/4a-hal/4a-hal-manager/4a-hal-manager-cb.c b/4a-hal/4a-hal-manager/4a-hal-manager-cb.c index ae86474..ba01394 100644 --- a/4a-hal/4a-hal-manager/4a-hal-manager-cb.c +++ b/4a-hal/4a-hal-manager/4a-hal-manager-cb.c @@ -22,7 +22,7 @@ #include -#include "../4a-hal-utilities/4a-hal-utilities-data.h" +#include "4a-hal-utilities-data.h" #include "4a-hal-manager-cb.h" #include "4a-hal-manager-events.h" diff --git a/4a-hal/4a-hal-manager/4a-hal-manager-events.c b/4a-hal/4a-hal-manager/4a-hal-manager-events.c index 96299a0..2b58501 100644 --- a/4a-hal/4a-hal-manager/4a-hal-manager-events.c +++ b/4a-hal/4a-hal-manager/4a-hal-manager-events.c @@ -22,7 +22,8 @@ #include -#include "../4a-hal-utilities/4a-hal-utilities-data.h" +#include "4a-hal-utilities-data.h" + #include "4a-hal-manager-events.h" // TBD JAI: implement events handlers functions \ No newline at end of file diff --git a/4a-hal/4a-hal-manager/4a-hal-manager.c b/4a-hal/4a-hal-manager/4a-hal-manager.c index 43fbd49..c510d17 100644 --- a/4a-hal/4a-hal-manager/4a-hal-manager.c +++ b/4a-hal/4a-hal-manager/4a-hal-manager.c @@ -22,8 +22,9 @@ #include -#include "../4a-hal-utilities/4a-hal-utilities-data.h" -#include "../4a-hal-utilities/4a-hal-utilities-verbs-loader.h" +#include "4a-hal-utilities-data.h" +#include "4a-hal-utilities-verbs-loader.h" + #include "../4a-hal-controllers/4a-hal-controllers-api-loader.h" #include "4a-hal-manager.h" diff --git a/4a-hal/4a-hal-utilities/4a-hal-utilities-appfw-responses-handler.c b/4a-hal/4a-hal-utilities/4a-hal-utilities-appfw-responses-handler.c deleted file mode 100644 index 40581ef..0000000 --- a/4a-hal/4a-hal-utilities/4a-hal-utilities-appfw-responses-handler.c +++ /dev/null @@ -1,147 +0,0 @@ -/* - * Copyright (C) 2018 "IoT.bzh" - * Author Jonathan Aillet - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#define _GNU_SOURCE - -#include -#include - -#include "4a-hal-utilities-appfw-responses-handler.h" - -/******************************************************************************* - * Handle application framework response function * - ******************************************************************************/ - -enum CallError HalUtlHandleAppFwCallError(AFB_ApiT apiHandle, char *apiCalled, char *verbCalled, json_object *callReturnJ, char **returnedStatus, char **returnedInfo) -{ - json_object *returnedRequestJ, *returnedStatusJ, *returnedInfoJ; - - if(! apiHandle || ! apiCalled || ! verbCalled || ! callReturnJ) - return CALL_ERROR_INVALID_ARGS; - - if(! json_object_object_get_ex(callReturnJ, "request", &returnedRequestJ)) { - AFB_ApiWarning(apiHandle, "Couldn't get response request object"); - return CALL_ERROR_REQUEST_UNAVAILABLE; - } - - if(! json_object_is_type(returnedRequestJ, json_type_object)) { - AFB_ApiWarning(apiHandle, "Response request object is not valid"); - return CALL_ERROR_REQUEST_NOT_VALID; - } - - if(! json_object_object_get_ex(returnedRequestJ, "status", &returnedStatusJ)) { - AFB_ApiWarning(apiHandle, "Couldn't get response status object"); - return CALL_ERROR_REQUEST_STATUS_UNAVAILABLE; - } - - if(! json_object_is_type(returnedStatusJ, json_type_string)) { - AFB_ApiWarning(apiHandle, "Response status object is not valid"); - return CALL_ERROR_REQUEST_STATUS_NOT_VALID; - } - - *returnedStatus = (char *) json_object_get_string(returnedStatusJ); - - if(! strcmp(*returnedStatus, "unknown-api")) { - AFB_ApiWarning(apiHandle, "Api %s not found", apiCalled); - return CALL_ERROR_API_UNAVAILABLE; - } - - if(! strcmp(*returnedStatus, "unknown-verb")) { - AFB_ApiWarning(apiHandle, "Verb %s of api %s not found", verbCalled, apiCalled); - return CALL_ERROR_VERB_UNAVAILABLE; - } - - if(! json_object_object_get_ex(returnedRequestJ, "info", &returnedInfoJ)) { - AFB_ApiWarning(apiHandle, "Couldn't get response info object"); - return CALL_ERROR_REQUEST_INFO_UNAVAILABLE; - } - - if(! json_object_is_type(returnedInfoJ, json_type_string)) { - AFB_ApiWarning(apiHandle, "Response info object is not valid"); - return CALL_ERROR_REQUEST_INFO_NOT_VALID; - } - - *returnedInfo = (char *) json_object_get_string(returnedInfoJ); - - AFB_ApiWarning(apiHandle, - "Api %s and verb %s found, but this error was raised : '%s' with this info : '%s'", - apiCalled, - verbCalled, - *returnedStatus, - *returnedInfo); - - return CALL_ERROR_RETURNED; -} - -void HalUtlHandleAppFwCallErrorInRequest(AFB_ReqT request, char *apiCalled, char *verbCalled, json_object *callReturnJ, char *errorStatusToSend) -{ - char *returnedStatus = NULL, *returnedInfo = NULL; - - AFB_ApiT apiHandle; - - if(! request || ! apiCalled || ! verbCalled || ! callReturnJ) { - AFB_ReqFailF(request, "invalid_args", "Invalid arguments"); - return; - } - - apiHandle = (AFB_ApiT) AFB_ReqGetApi(request); - if(! apiHandle) { - AFB_ReqFailF(request, "api_handle", "Can't get hal manager api handle"); - return; - } - - switch(HalUtlHandleAppFwCallError(apiHandle, apiCalled, verbCalled, callReturnJ, &returnedStatus, &returnedInfo)) { - case CALL_ERROR_REQUEST_UNAVAILABLE: - case CALL_ERROR_REQUEST_NOT_VALID: - case CALL_ERROR_REQUEST_STATUS_UNAVAILABLE: - case CALL_ERROR_REQUEST_STATUS_NOT_VALID: - case CALL_ERROR_REQUEST_INFO_UNAVAILABLE: - case CALL_ERROR_REQUEST_INFO_NOT_VALID: - AFB_ReqFail(request, errorStatusToSend, "Error with response object"); - return; - - case CALL_ERROR_API_UNAVAILABLE: - AFB_ReqFailF(request, errorStatusToSend, "Api %s not found", apiCalled); - return; - - case CALL_ERROR_VERB_UNAVAILABLE: - AFB_ReqFailF(request, errorStatusToSend, "Verb %s of api %s not found", verbCalled, apiCalled); - return; - - case CALL_ERROR_RETURNED: - AFB_ReqFailF(request, - errorStatusToSend, - "Api %s and verb %s found, but this error was raised : '%s' with this info : '%s'", - apiCalled, - verbCalled, - returnedStatus ? returnedStatus : "not returned", - returnedInfo ? returnedInfo : "not returned"); - return; - - case CALL_ERROR_INVALID_ARGS: - AFB_ReqFailF(request, - errorStatusToSend, - "Api %s and verb %s found, but the arguments are invalid", - apiCalled, - verbCalled); - return; - - default: - AFB_ReqFailF(request, errorStatusToSend, "Unknown error happened during call to verb %s of api %s", verbCalled, apiCalled); - return; - } -} \ No newline at end of file diff --git a/4a-hal/4a-hal-utilities/4a-hal-utilities-appfw-responses-handler.h b/4a-hal/4a-hal-utilities/4a-hal-utilities-appfw-responses-handler.h deleted file mode 100644 index 923ca6b..0000000 --- a/4a-hal/4a-hal-utilities/4a-hal-utilities-appfw-responses-handler.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (C) 2018 "IoT.bzh" - * Author Jonathan Aillet - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef _HAL_UTILITIES_APPFW_RESP_HANDLER_INCLUDE_ -#define _HAL_UTILITIES_APPFW_RESP_HANDLER_INCLUDE_ - -#include - -#include - -#include - -// Enum for the type of error detected -enum CallError { - CALL_ERROR_INVALID_ARGS=-1, - CALL_ERROR_REQUEST_UNAVAILABLE=-2, - CALL_ERROR_REQUEST_NOT_VALID=-3, - CALL_ERROR_REQUEST_STATUS_UNAVAILABLE=-4, - CALL_ERROR_REQUEST_STATUS_NOT_VALID=-5, - CALL_ERROR_API_UNAVAILABLE=-6, - CALL_ERROR_VERB_UNAVAILABLE=-7, - CALL_ERROR_REQUEST_INFO_UNAVAILABLE=-8, - CALL_ERROR_REQUEST_INFO_NOT_VALID=-9, - CALL_ERROR_RETURNED=-10, -}; - -// Handle application framework response function -extern enum CallError HalUtlHandleAppFwCallError(AFB_ApiT apiHandle, char *apiCalled, char *verbCalled, json_object *callReturnJ, char **returnedStatus, char **returnedInfo); -void HalUtlHandleAppFwCallErrorInRequest(AFB_ReqT request, char *apiCalled, char *verbCalled, json_object *callReturnJ, char *errorStatusToSend); - -#endif /* _HAL_UTILITIES_APPFW_RESP_HANDLER_INCLUDE_ */ \ No newline at end of file diff --git a/4a-hal/4a-hal-utilities/4a-hal-utilities-data.c b/4a-hal/4a-hal-utilities/4a-hal-utilities-data.c deleted file mode 100644 index f3ee028..0000000 --- a/4a-hal/4a-hal-utilities/4a-hal-utilities-data.c +++ /dev/null @@ -1,244 +0,0 @@ -/* - * Copyright (C) 2018 "IoT.bzh" - * Author Jonathan Aillet - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#define _GNU_SOURCE - -#include -#include - -#include - -#include "4a-hal-utilities-data.h" - -#include "../4a-hal-controllers/4a-hal-controllers-alsacore-link.h" - -/******************************************************************************* - * Specfic Hal controller streams data handling functions * - ******************************************************************************/ - -uint8_t HalUtlRemoveAllCtlHalStreamsData(struct CtlHalMixerDataT *ctlHalStreamsData) -{ - unsigned int cpt; - - if(! ctlHalStreamsData) - return -1; - - if(! ctlHalStreamsData->count) - return -2; - - for(cpt = 0; cpt < ctlHalStreamsData->count; cpt++) { - free(ctlHalStreamsData->data[cpt].verb); - free(ctlHalStreamsData->data[cpt].verbToCall); - free(ctlHalStreamsData->data[cpt].streamCardId); - } - - free(ctlHalStreamsData->data); - - return 0; -} - -/******************************************************************************* - * Specfic Hal data handling functions * - ******************************************************************************/ - -struct SpecificHalData *HalUtlAddHalApiToHalList(struct SpecificHalData **firstHalData) -{ - struct SpecificHalData *currentApi; - - if(! firstHalData) - return NULL; - - currentApi = *firstHalData; - - if(! currentApi) { - currentApi = (struct SpecificHalData *) calloc(1, sizeof(struct SpecificHalData)); - if(! currentApi) - return NULL; - - *firstHalData = currentApi; - } - else { - while(currentApi->next) - currentApi = currentApi->next; - - currentApi->next = calloc(1, sizeof(struct SpecificHalData)); - if(! currentApi) - return NULL; - - currentApi = currentApi->next; - } - - memset(currentApi, 0, sizeof(struct SpecificHalData)); - - return currentApi; -} - -int8_t HalUtlRemoveSelectedHalFromList(struct SpecificHalData **firstHalData, struct SpecificHalData *apiToRemove) -{ - struct SpecificHalData *currentApi, *matchingApi; - - if(! firstHalData || ! apiToRemove) - return -1; - - currentApi = *firstHalData; - - if(currentApi == apiToRemove) { - *firstHalData = currentApi->next; - matchingApi = currentApi; - } - else { - while(currentApi && currentApi->next != apiToRemove) - currentApi = currentApi->next; - - if(currentApi) { - matchingApi = currentApi->next; - currentApi->next = currentApi->next->next; - } - else { - return -2; - } - } - - if(! matchingApi->internal) { - free(matchingApi->apiName); - free(matchingApi->sndCardPath); - free(matchingApi->info); - free(matchingApi->author); - free(matchingApi->version); - free(matchingApi->date); - } - else { - HalUtlRemoveAllCtlHalStreamsData(&matchingApi->ctlHalSpecificData->ctlHalStreamsData); - - HalCtlsFreeAlsaCtlsMap(matchingApi->ctlHalSpecificData->ctlHalAlsaMapT); - - free(matchingApi->ctlHalSpecificData); - } - - free(matchingApi); - - return 0; -} - -int64_t HalUtlRemoveAllHalFromList(struct SpecificHalData **firstHalData) -{ - int8_t ret; - int64_t CtlHalApiRemoved = 0; - - while(*firstHalData) { - ret = HalUtlRemoveSelectedHalFromList(firstHalData, *firstHalData); - if(ret) - return (int64_t) ret; - - CtlHalApiRemoved++; - } - - return CtlHalApiRemoved; -} - -int64_t HalUtlGetNumberOfHalInList(struct SpecificHalData **firstHalData) -{ - int64_t numberOfCtlHal = 0; - struct SpecificHalData *currentApi; - - if(! firstHalData) - return -1; - - currentApi = *firstHalData; - - while(currentApi) { - currentApi = currentApi->next; - numberOfCtlHal++; - } - - return numberOfCtlHal; -} - -struct SpecificHalData *HalUtlSearchHalDataByApiName(struct SpecificHalData **firstHalData, char *apiName) -{ - struct SpecificHalData *currentApi; - - if(! firstHalData || ! apiName) - return NULL; - - currentApi = *firstHalData; - - while(currentApi) { - if(! strcmp(apiName, currentApi->apiName)) - return currentApi; - - currentApi = currentApi->next; - } - - return NULL; -} - - -struct SpecificHalData *HalUtlSearchReadyHalDataByCarId(struct SpecificHalData **firstHalData, int cardId) -{ - struct SpecificHalData *currentApi; - - if(! firstHalData) - return NULL; - - currentApi = *firstHalData; - while(currentApi) { - if(currentApi->status == HAL_STATUS_READY && currentApi->sndCardId == cardId) - return currentApi; - - currentApi = currentApi->next; - } - - return NULL; -} - -/******************************************************************************* - * Hal Manager data handling functions * - ******************************************************************************/ - -uint8_t HalUtlInitializeHalMgrData(AFB_ApiT apiHandle, struct HalMgrData *HalMgrGlobalData, char *apiName, char *info) -{ - if(! apiHandle || ! HalMgrGlobalData || ! apiName || ! info) - return -1; - - // Allocate and fill apiName and info strings - HalMgrGlobalData->apiName = strdup(apiName); - if(! HalMgrGlobalData->apiName) - return -2; - - HalMgrGlobalData->info = strdup(info); - if(! HalMgrGlobalData->apiName) - return -3; - - HalMgrGlobalData->apiHandle = apiHandle; - - return 0; -} - -void HalUtlRemoveHalMgrData(struct HalMgrData *HalMgrGlobalData) -{ - if(! HalMgrGlobalData) - return; - - if(HalMgrGlobalData->first) - HalUtlRemoveAllHalFromList(&HalMgrGlobalData->first); - - free(HalMgrGlobalData->apiName); - free(HalMgrGlobalData->info); - - free(HalMgrGlobalData); -} \ No newline at end of file diff --git a/4a-hal/4a-hal-utilities/4a-hal-utilities-data.h b/4a-hal/4a-hal-utilities/4a-hal-utilities-data.h deleted file mode 100644 index 01b3db7..0000000 --- a/4a-hal/4a-hal-utilities/4a-hal-utilities-data.h +++ /dev/null @@ -1,108 +0,0 @@ -/* - * Copyright (C) 2018 "IoT.bzh" - * Author Jonathan Aillet - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef _HAL_UTILITIES_DATA_INCLUDE_ -#define _HAL_UTILITIES_DATA_INCLUDE_ - -#include - -#include - -#include - -#include - -#include "../4a-hal-controllers/4a-hal-controllers-alsacore-link.h" - -// Enum for sharing hal (controller or external) status -enum HalStatus { - HAL_STATUS_UNAVAILABLE=0, - HAL_STATUS_AVAILABLE=1, - HAL_STATUS_READY=2 -}; - -// Structure to store stream data -struct CtlHalMixerData { - char *verb; - char *verbToCall; - char *streamCardId; - AFB_EventT event; -}; - -// Structure to store stream data table -struct CtlHalMixerDataT { - struct CtlHalMixerData *data; - unsigned int count; -}; - -// Structure to store specific controller hal data -struct CtlHalSpecificData { - char *mixerApiName; - char *prefix; - json_object *halMixerJ; - - struct CtlHalMixerDataT ctlHalStreamsData; - struct CtlHalMixerDataT ctlHalPlaybacksData; - struct CtlHalMixerDataT ctlHalCapturesData; - struct CtlHalAlsaMapT *ctlHalAlsaMapT; - - AFB_ApiT apiHandle; - CtlConfigT *ctrlConfig; -}; - -// Structure to store specific hal (controller or external) data -struct SpecificHalData { - char *apiName; - enum HalStatus status; - char *sndCardPath; - int sndCardId; - char *info; - unsigned int internal; - - char *author; - char *version; - char *date; - // Can be beefed up if needed - - struct CtlHalSpecificData *ctlHalSpecificData; // Can be NULL if external api - - struct SpecificHalData *next; -}; - -// Structure to store hal manager data -struct HalMgrData { - char *apiName; - char *info; - - AFB_ApiT apiHandle; - - struct SpecificHalData *first; -}; - -// Exported verbs for 'struct SpecificHalData' handling -struct SpecificHalData *HalUtlAddHalApiToHalList(struct SpecificHalData **firstHalData); -int8_t HalUtlRemoveSelectedHalFromList(struct SpecificHalData **firstHalData, struct SpecificHalData *ApiToRemove); -int64_t HalUtlRemoveAllHalFromList(struct SpecificHalData **firstHalData); -int64_t HalUtlGetNumberOfHalInList(struct SpecificHalData **firstHalData); -struct SpecificHalData *HalUtlSearchHalDataByApiName(struct SpecificHalData **firstHalData, char *apiName); -struct SpecificHalData *HalUtlSearchReadyHalDataByCarId(struct SpecificHalData **firstHalData, int cardId); - -// Exported verbs for 'struct HalMgrData' handling -uint8_t HalUtlInitializeHalMgrData(AFB_ApiT apiHandle, struct HalMgrData *HalMgrGlobalData, char *apiName, char *info); -void HalUtlRemoveHalMgrData(struct HalMgrData *HalMgrGlobalData); - -#endif /* _HAL_UTILITIES_DATA_INCLUDE_ */ \ No newline at end of file diff --git a/4a-hal/4a-hal-utilities/4a-hal-utilities-verbs-loader.c b/4a-hal/4a-hal-utilities/4a-hal-utilities-verbs-loader.c deleted file mode 100644 index f557f4c..0000000 --- a/4a-hal/4a-hal-utilities/4a-hal-utilities-verbs-loader.c +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (C) 2018 "IoT.bzh" - * Author Jonathan Aillet - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#define _GNU_SOURCE - -#include -#include - -#include - -#include "4a-hal-utilities-verbs-loader.h" - -/******************************************************************************* - * Dynamic API common functions * - ******************************************************************************/ - -int HalUtlLoadVerbs(AFB_ApiT apiHandle, AFB_ApiVerbs *verbs) -{ - int idx, errCount = 0; - - if(! apiHandle || ! verbs) - return -1; - - for (idx = 0; verbs[idx].verb; idx++) { - errCount+= AFB_ApiAddVerb(apiHandle, - verbs[idx].verb, - NULL, - verbs[idx].callback, - (void *) &verbs[idx], - verbs[idx].auth, - 0, - 0); - } - - return errCount; -} \ No newline at end of file diff --git a/4a-hal/4a-hal-utilities/4a-hal-utilities-verbs-loader.h b/4a-hal/4a-hal-utilities/4a-hal-utilities-verbs-loader.h deleted file mode 100644 index 2bfa1cd..0000000 --- a/4a-hal/4a-hal-utilities/4a-hal-utilities-verbs-loader.h +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Copyright (C) 2018 "IoT.bzh" - * Author Jonathan Aillet - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef _HAL_UTILITIES_VERBS_LOADER_INCLUDE_ -#define _HAL_UTILITIES_VERBS_LOADER_INCLUDE_ - -#include - -#include - -// Verb that allows to add verb to a dynamic api -int HalUtlLoadVerbs(AFB_ApiT apiHandle, AFB_ApiVerbs *verbs); - -#endif /* _HAL_UTILITIES_VERBS_LOADER_INCLUDE_ */ \ No newline at end of file diff --git a/4a-hal/CMakeLists.txt b/4a-hal/CMakeLists.txt index 2968f23..5392075 100644 --- a/4a-hal/CMakeLists.txt +++ b/4a-hal/CMakeLists.txt @@ -23,9 +23,6 @@ PROJECT_TARGET_ADD(4a-hal) # Define project Targets add_library(${TARGET_NAME} MODULE - ${TARGET_NAME}-utilities/${TARGET_NAME}-utilities-appfw-responses-handler.c - ${TARGET_NAME}-utilities/${TARGET_NAME}-utilities-data.c - ${TARGET_NAME}-utilities/${TARGET_NAME}-utilities-verbs-loader.c ${TARGET_NAME}-manager/${TARGET_NAME}-manager.c ${TARGET_NAME}-manager/${TARGET_NAME}-manager-cb.c ${TARGET_NAME}-manager/${TARGET_NAME}-manager-events.c @@ -48,6 +45,7 @@ PROJECT_TARGET_ADD(4a-hal) TARGET_LINK_LIBRARIES(${TARGET_NAME} afb-helpers ctl-utilities + 4a-hal-utilities ${link_libraries} ) diff --git a/plugins/lib/bluealsa/CMakeLists.txt b/plugins/lib/bluealsa/CMakeLists.txt index 699ccc4..28a903a 100644 --- a/plugins/lib/bluealsa/CMakeLists.txt +++ b/plugins/lib/bluealsa/CMakeLists.txt @@ -39,6 +39,7 @@ PROJECT_TARGET_ADD(hal-bluealsa) TARGET_LINK_LIBRARIES(${TARGET_NAME} afb-helpers ctl-utilities + 4a-hal-utilities ${BLUEALSA_LIBRARIES} ${link_libraries} ) -- cgit 1.2.3-korg