diff options
Diffstat (limited to '4a-hal/4a-hal-utilities')
6 files changed, 0 insertions, 622 deletions
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 <jonathan.aillet@iot.bzh> - * - * 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 <stdio.h> -#include <string.h> - -#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 <jonathan.aillet@iot.bzh> - * - * 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 <stdio.h> - -#include <wrap-json.h> - -#include <afb-definitions.h> - -// 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 <jonathan.aillet@iot.bzh> - * - * 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 <stdio.h> -#include <string.h> - -#include <wrap-json.h> - -#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 <jonathan.aillet@iot.bzh> - * - * 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 <stdio.h> - -#include <wrap-json.h> - -#include <afb-definitions.h> - -#include <ctl-config.h> - -#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 <jonathan.aillet@iot.bzh> - * - * 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 <stdio.h> -#include <string.h> - -#include <afb-definitions.h> - -#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 <jonathan.aillet@iot.bzh> - * - * 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 <stdio.h> - -#include <afb-definitions.h> - -// 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 |