aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJonathan Aillet <jonathan.aillet@iot.bzh>2019-10-11 14:54:52 +0200
committerJonathan Aillet <jonathan.aillet@iot.bzh>2019-10-17 11:29:18 +0200
commit4063c990f8b146504bcc49b2fb1d1082f58bf707 (patch)
tree0bc4a1c934d77f34948a03734e17fe1dddffcb0f
parent502b8d11008e2e7ac494d9fca0fe722d66755469 (diff)
Move hal api delete code into a function
BUG-AGL: SPEC-2885 Change-Id: I23c605440782f8caeef30c1fe41f4cac5b704dbb Signed-off-by: Jonathan Aillet <jonathan.aillet@iot.bzh>
-rw-r--r--src/4a-hal-manager/4a-hal-manager.c18
-rw-r--r--src/4a-internals-hal/4a-internals-hal-api-loader.c38
-rw-r--r--src/4a-internals-hal/4a-internals-hal-api-loader.h1
3 files changed, 46 insertions, 11 deletions
diff --git a/src/4a-hal-manager/4a-hal-manager.c b/src/4a-hal-manager/4a-hal-manager.c
index da33db8..c587e8a 100644
--- a/src/4a-hal-manager/4a-hal-manager.c
+++ b/src/4a-hal-manager/4a-hal-manager.c
@@ -78,30 +78,26 @@ static int HalMgrInitApi(afb_api_t apiHandle)
if(afb_api_require_api(apiHandle, currentHalData->apiName, 1) ||
currentHalData->status == HAL_STATUS_INIT_FAILED) {
- AFB_API_ERROR(apiHandle,
- "Error caught during '%s' api initialization, this api won't be reachable",
- currentHalData->apiName);
+ AFB_API_INFO(apiHandle,
+ "Error caught during '%s' api initialization, this api won't be reachable",
+ currentHalData->apiName);
toDeleteApiName = strdup(currentHalData->apiName);
if(! toDeleteApiName) {
AFB_API_ERROR(apiHandle, "Didn't succeed to store (allocate) 'apiName' string");
- return -5;
+ return -4;
}
- err = HalUtlRemoveHalDataAndDeleteHalApi(apiHandle, currentHalData, &halMgrData->halDataListHead);
+ err = InternalHalDeleteApi(apiHandle, &halMgrData->halDataListHead, currentHalData);
if(err) {
AFB_API_ERROR(apiHandle,
- "Error %i happened while trying to delete '%s' api and to remove all its data",
+ "Error %i happened when tried to delete %s api",
err,
toDeleteApiName);
free(toDeleteApiName);
- return -6;
+ return -5;
}
- AFB_API_ERROR(apiHandle,
- "Api '%s' and all its data has been deleted",
- toDeleteApiName);
-
free(toDeleteApiName);
}
}
diff --git a/src/4a-internals-hal/4a-internals-hal-api-loader.c b/src/4a-internals-hal/4a-internals-hal-api-loader.c
index 5334bdf..ba742f1 100644
--- a/src/4a-internals-hal/4a-internals-hal-api-loader.c
+++ b/src/4a-internals-hal/4a-internals-hal-api-loader.c
@@ -199,6 +199,44 @@ int InternalHalCreateApi(afb_api_t apiHandle, char *path, struct HalMgrData *hal
return 0;
}
+int InternalHalDeleteApi(afb_api_t apiHandle, struct cds_list_head *halDataListHead, struct HalData *toDeleteHalData)
+{
+ int err;
+
+ char *toDeleteApiName;
+
+ if(! apiHandle || ! toDeleteHalData) {
+ AFB_API_ERROR(apiHandle, "Invalid argument(s)");
+ return -1;
+ }
+
+ toDeleteApiName = strdup(toDeleteHalData->apiName);
+ if(! toDeleteApiName) {
+ AFB_API_ERROR(apiHandle, "Didn't succeed to store (allocate) 'apiName' string");
+ return -2;
+ }
+
+ err = HalUtlRemoveHalDataAndDeleteHalApi(toDeleteHalData->internalHalData->apiHandle,
+ toDeleteHalData,
+ halDataListHead);
+ if(err) {
+ AFB_API_ERROR(apiHandle,
+ "Error %i happened while trying to delete '%s' api and to remove all its data",
+ err,
+ toDeleteApiName);
+ free(toDeleteApiName);
+ return -3;
+ }
+
+ AFB_API_NOTICE(apiHandle,
+ "Api '%s' and all its data has been deleted",
+ toDeleteApiName);
+
+ free(toDeleteApiName);
+
+ return 0;
+}
+
int InternalHalCreateAllApi(afb_api_t apiHandle, struct HalMgrData *halMgrData)
{
int index;
diff --git a/src/4a-internals-hal/4a-internals-hal-api-loader.h b/src/4a-internals-hal/4a-internals-hal-api-loader.h
index fa878e2..1628e8a 100644
--- a/src/4a-internals-hal/4a-internals-hal-api-loader.h
+++ b/src/4a-internals-hal/4a-internals-hal-api-loader.h
@@ -26,6 +26,7 @@
// Verbs that can be use to create api
int InternalHalCreateApi(afb_api_t apiHandle, char *path, struct HalMgrData *halMgrData);
+int InternalHalDeleteApi(afb_api_t apiHandle, struct cds_list_head *halDataListHead, struct HalData *toDeleteHalData);
int InternalHalCreateAllApi(afb_api_t apiHandle, struct HalMgrData *halMgrData);
#endif /* _INTERNALS_HAL_API_LOADER_INCLUDE_ */ \ No newline at end of file