summaryrefslogtreecommitdiffstats
path: root/lib/4a-hal-utilities
diff options
context:
space:
mode:
authorJonathan Aillet <jonathan.aillet@iot.bzh>2019-07-18 14:41:59 +0200
committerJonathan Aillet <jonathan.aillet@iot.bzh>2019-07-18 17:32:26 +0200
commit7b37923625667b07ddade3a79c01ddbd358287a3 (patch)
tree07b6511b4f6c3d10d0a7e78462218466d8f54ded /lib/4a-hal-utilities
parent09f002d060078d53e443e0f5806e147e035ac357 (diff)
Add hal api handler utilities files
Add utilities files to create/delete hal apis while adding hal data to hal data list. Use it to create new hal apis. BUG-AGL: SPEC-2652 Change-Id: I62e99cda31bb2c6f597da27960102c036a25b733 Signed-off-by: Jonathan Aillet <jonathan.aillet@iot.bzh>
Diffstat (limited to 'lib/4a-hal-utilities')
-rw-r--r--lib/4a-hal-utilities/4a-hal-utilities-hal-api-handler.c154
-rw-r--r--lib/4a-hal-utilities/4a-hal-utilities-hal-api-handler.h42
-rw-r--r--lib/4a-hal-utilities/CMakeLists.txt1
3 files changed, 197 insertions, 0 deletions
diff --git a/lib/4a-hal-utilities/4a-hal-utilities-hal-api-handler.c b/lib/4a-hal-utilities/4a-hal-utilities-hal-api-handler.c
new file mode 100644
index 0000000..ac4b2ba
--- /dev/null
+++ b/lib/4a-hal-utilities/4a-hal-utilities-hal-api-handler.c
@@ -0,0 +1,154 @@
+/*
+ * Copyright (C) 2019 "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 <json-c/json.h>
+
+#include <urcu/list.h>
+
+#include <afb/afb-binding.h>
+
+#include <ctl-config.h>
+
+#include "4a-hal-utilities-data.h"
+#include "4a-hal-utilities-hal-api-handler.h"
+
+/*******************************************************************************
+ * Add/Remove hal data and create/delete api functions *
+ ******************************************************************************/
+
+int HalUtlAddHalDataAndCreateHalApi(afb_api_t apiHandle,
+ struct HalMgrData *halMgrData,
+ CtlConfigT *ctrlConfig,
+ int (*preinit)(void*, afb_api_t ))
+{
+ struct HalData *currentHalData;
+
+ if(! apiHandle || ! halMgrData || ! ctrlConfig) {
+ AFB_API_ERROR(apiHandle, "Invalid argument(s)");
+ return -1;
+ }
+
+ // Allocation of current internal hal data
+ currentHalData = HalUtlAddHalToHalList(&halMgrData->halDataListHead);
+ if(! currentHalData) {
+ AFB_API_ERROR(apiHandle, "Didn't succeed to add hal to hal list");
+ return -2;
+ }
+
+ currentHalData->apiName = (char *) ctrlConfig->api;
+
+ // Stores hal data in controller config
+ setExternalData(ctrlConfig, (void *) currentHalData);
+
+ // Allocation of the structure that will be used to store internal hal data
+ currentHalData->internalHalData = calloc(1, sizeof(struct InternalHalData));
+ if(! currentHalData->internalHalData) {
+ AFB_API_ERROR(apiHandle, "Didn't succeed to allocate internal hal data structure");
+ return -3;
+ }
+
+ CDS_INIT_LIST_HEAD(&currentHalData->internalHalData->probedDevicesListHead);
+ CDS_INIT_LIST_HEAD(&currentHalData->internalHalData->streamsDataListHead);
+ CDS_INIT_LIST_HEAD(&currentHalData->internalHalData->halMapListHead);
+
+ // Create one API
+ if(! afb_api_new_api(apiHandle, ctrlConfig->api, ctrlConfig->info, 1, preinit, ctrlConfig)) {
+ AFB_API_ERROR(apiHandle, "An error occurred at '%s' internal hal api creation", ctrlConfig->api);
+ return -4;
+ }
+
+ return 0;
+}
+
+int HalUtlRemoveHalDataAndDeleteHalApi(afb_api_t apiHandle,
+ struct HalData *halDataToDelete,
+ struct cds_list_head *halDataListHead)
+{
+ int err;
+
+ if(! apiHandle || ! halDataToDelete || ! halDataListHead) {
+ AFB_API_ERROR(apiHandle, "Invalid argument(s)");
+ return -1;
+ }
+
+ afb_api_delete_api(halDataToDelete->internalHalData->apiHandle);
+
+ err = HalUtlRemoveSelectedHalFromList(halDataListHead, halDataToDelete);
+ if(err) {
+ AFB_API_ERROR(apiHandle,
+ "Error %i happened while trying to remove '%s' internal hal data structure",
+ err,
+ halDataToDelete->apiName);
+ return -2;
+ }
+
+ return 0;
+}
+
+int HalUtlRemoveAllHalDataAndDeleteAllHalApi(afb_api_t apiHandle,
+ struct cds_list_head *halDataListHead)
+{
+ int err;
+ struct HalData *currentHalData, *savedHalData;
+
+ if(! apiHandle || ! halDataListHead) {
+ AFB_API_ERROR(apiHandle, "Invalid argument(s)");
+ return -1;
+ }
+
+ cds_list_for_each_entry_safe(currentHalData, savedHalData, halDataListHead, node) {
+ err = HalUtlRemoveHalDataAndDeleteHalApi(apiHandle, currentHalData, halDataListHead);
+ if(err) {
+ AFB_API_ERROR(apiHandle,
+ "Error %i happened while trying to delete '%s' api and to remove its internal hal data structure",
+ err,
+ currentHalData->apiName);
+ return -2;
+ }
+ }
+
+ return 0;
+}
+
+int HalUtlRemoveHalMgrDataAndDeleteAllHalApi(afb_api_t apiHandle,
+ struct HalMgrData *halMgrData)
+{
+ int err;
+
+ if(! apiHandle || ! halMgrData) {
+ AFB_API_ERROR(apiHandle, "Invalid argument(s)");
+ return -1;
+ }
+
+ err = HalUtlRemoveAllHalDataAndDeleteAllHalApi(apiHandle, &halMgrData->halDataListHead);
+ if(err) {
+ AFB_API_ERROR(apiHandle,
+ "Error %i happened while trying to remove all internal hal data structure and to delete all hal api",
+ err);
+ return -2;
+ }
+
+ free(halMgrData->apiName);
+ free(halMgrData->info);
+
+ free(halMgrData);
+
+ return 0;
+} \ No newline at end of file
diff --git a/lib/4a-hal-utilities/4a-hal-utilities-hal-api-handler.h b/lib/4a-hal-utilities/4a-hal-utilities-hal-api-handler.h
new file mode 100644
index 0000000..0350c50
--- /dev/null
+++ b/lib/4a-hal-utilities/4a-hal-utilities-hal-api-handler.h
@@ -0,0 +1,42 @@
+/*
+* Copyright (C) 2019 "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_HAL_API_HANDLER_INCLUDE_
+#define _HAL_UTILITIES_HAL_API_HANDLER_INCLUDE_
+
+#include <stdio.h>
+
+#include <afb/afb-binding.h>
+
+#include <ctl-config.h>
+
+#include "4a-hal-utilities-data.h"
+
+// Add/Remove hal data and create/delete api functions
+int HalUtlAddHalDataAndCreateHalApi(afb_api_t apiHandle,
+ struct HalMgrData *halMgrData,
+ CtlConfigT *ctrlConfig,
+ int (*preinit)(void*, afb_api_t ));
+int HalUtlRemoveHalDataAndDeleteHalApi(afb_api_t apiHandle,
+ struct HalData *halDataToDelete,
+ struct cds_list_head *halDataListHead);
+int HalUtlRemoveAllHalDataAndDeleteAllHalApi(afb_api_t apiHandle,
+ struct cds_list_head *halDataListHead);
+int HalUtlRemoveHalMgrDataAndDeleteAllHalApi(afb_api_t apiHandle,
+ struct HalMgrData *halMgrData);
+
+#endif /* _HAL_UTILITIES_HAL_API_HANDLER_INCLUDE_ */ \ No newline at end of file
diff --git a/lib/4a-hal-utilities/CMakeLists.txt b/lib/4a-hal-utilities/CMakeLists.txt
index 9689565..48a81c5 100644
--- a/lib/4a-hal-utilities/CMakeLists.txt
+++ b/lib/4a-hal-utilities/CMakeLists.txt
@@ -23,6 +23,7 @@ PROJECT_TARGET_ADD(4a-hal-utilities)
# Define project Targets
ADD_LIBRARY(${TARGET_NAME} STATIC
4a-hal-utilities-data.c
+ 4a-hal-utilities-hal-api-handler.c
4a-hal-utilities-hal-streams-handler.c)
# Define target includes for this target client