diff options
Diffstat (limited to 'src/4a-hal-manager/4a-hal-manager.c')
-rw-r--r-- | src/4a-hal-manager/4a-hal-manager.c | 36 |
1 files changed, 35 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 * ******************************************************************************/ |