summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJonathan Aillet <jonathan.aillet@iot.bzh>2019-10-11 16:13:50 +0200
committerJonathan Aillet <jonathan.aillet@iot.bzh>2019-10-17 16:09:15 +0200
commit4185666931d92aef13ab6a61b3644f279c71f452 (patch)
treef70716671ff27cdda5f82508b66bcb11811c86f2
parent6b3269f8dbd7cf7bf16e6e73f397285b26b3c25b (diff)
Add function that prepare closing binder on exiticefish_8.99.2icefish_8.99.1icefish/8.99.2icefish/8.99.18.99.28.99.1
Add function that prepare closing binder when exit signal is received. That includes reverting hal api performed actions (e.g. removing added custom ALSA control, ...) and deleting all hal api. Register this function to be call at binder exit (using 'on_exit'). BUG-AGL: SPEC-2910 Change-Id: I49a5b65c303561bede4c93a2eb3284395fa9f1e7 Signed-off-by: Jonathan Aillet <jonathan.aillet@iot.bzh>
-rw-r--r--src/4a-hal-manager/4a-hal-manager.c36
-rw-r--r--src/4a-hal-manager/4a-hal-manager.h3
-rw-r--r--src/4a-internals-hal/4a-internals-hal-cb.c2
3 files changed, 40 insertions, 1 deletions
diff --git a/src/4a-hal-manager/4a-hal-manager.c b/src/4a-hal-manager/4a-hal-manager.c
index e21b948..84e39e5 100644
--- a/src/4a-hal-manager/4a-hal-manager.c
+++ b/src/4a-hal-manager/4a-hal-manager.c
@@ -65,7 +65,6 @@ static int HalMgrInitApi(afb_api_t apiHandle)
if(! apiHandle)
return -1;
- // Retrieve section config from api handle
halMgrData = (struct HalMgrData *) afb_api_get_userdata(apiHandle);
if(! halMgrData)
return -2;
@@ -103,6 +102,8 @@ static int HalMgrInitApi(afb_api_t apiHandle)
}
}
+ on_exit(&HalMgrPrepareClosingApi, (void *) apiHandle);
+
return 0;
}
@@ -144,6 +145,39 @@ int HalMgrCreateApi(afb_api_t apiHandle, struct HalMgrData *halMgrData)
return afb_api_new_api(apiHandle, HAL_MANAGER_API_NAME, HAL_MANAGER_API_INFO, 1, HalMgrLoadApi, halMgrData) ? 0 : -1;
}
+void HalMgrPrepareClosingApi(int code, void *closure)
+{
+ int err;
+
+ afb_api_t apiHandle = (afb_api_t) closure;
+
+ struct HalMgrData *halMgrData;
+
+ if(! apiHandle)
+ return;
+
+ AFB_API_ERROR(apiHandle,
+ "An interrupt signal has been received, prepare closing all hal api and 'hal-manager' api");
+
+ halMgrData = (struct HalMgrData *) afb_api_get_userdata(apiHandle);
+ if(! halMgrData) {
+ AFB_API_ERROR(apiHandle,
+ "Did not succeed to get 'hal-manager' data structure, will not be able "
+ "to close all hal api and 'hal-manager' api properly");
+ return;
+ }
+
+ err = InternalHalDeleteAllApi(apiHandle, halMgrData);
+ if(err) {
+ AFB_API_ERROR(apiHandle, "Error %i happened when tried to delete all hal api", err);
+ return;
+ }
+
+ HalUtlRemoveHalMgrData(halMgrData);
+
+ return;
+}
+
/*******************************************************************************
* Startup function *
******************************************************************************/
diff --git a/src/4a-hal-manager/4a-hal-manager.h b/src/4a-hal-manager/4a-hal-manager.h
index d5f11e5..3818a7c 100644
--- a/src/4a-hal-manager/4a-hal-manager.h
+++ b/src/4a-hal-manager/4a-hal-manager.h
@@ -23,4 +23,7 @@
#define HAL_MANAGER_API_NAME "4a-hal-manager"
#define HAL_MANAGER_API_INFO "Manager for 4A HAL APIs"
+// Function to be called when
+void HalMgrPrepareClosingApi(int code, void *closure);
+
#endif /* _HALMGR_BINDING_INCLUDE_ */ \ No newline at end of file
diff --git a/src/4a-internals-hal/4a-internals-hal-cb.c b/src/4a-internals-hal/4a-internals-hal-cb.c
index c1078a9..78bbcb4 100644
--- a/src/4a-internals-hal/4a-internals-hal-cb.c
+++ b/src/4a-internals-hal/4a-internals-hal-cb.c
@@ -1142,7 +1142,9 @@ int InternalHalUnmanageOneHalMapObject(afb_api_t apiHandle, struct InternalHalAl
halMapData->action = NULL;
if(halMapData->ctl.alsaCtlCreation) {
+ // TODO JAI : Enable next line when 'afb_api_call_sync' while in exit will be allowed
err = InternalHalDeleteAlsaCtl(apiHandle, cardNbString, &halMapData->ctl);
+ // err = 0;
if(err)
AFB_API_WARNING(apiHandle,
"Error %i returned when tried to custom ALSA control '%s', "