diff options
author | Jonathan Aillet <jonathan.aillet@iot.bzh> | 2019-04-18 16:25:24 +0200 |
---|---|---|
committer | Jonathan Aillet <jonathan.aillet@iot.bzh> | 2019-05-24 16:28:53 +0200 |
commit | 9cb51ee3170262d8720d47708f483b4b38fd38e6 (patch) | |
tree | f4bf3940f3da01dd8e5f141becb97f96b074c33c /src/4a-internals-hal/4a-internals-hal-api-loader.c | |
parent | be68761ad6b10555ce410f1f0e42976014f7b259 (diff) |
Normalize coding style among repository
Normalize coding style among project :
- When possible, set the variable outside test in 'if' statement.
- Remove fanciful returns.
- Split too long lines.
- Remove unnecessary '\n' into prints.
- Normalize use of tabulation.
- Use 'afb_req_fail' instead of 'afb_req_fail_f' when possible.
- Add some error prints.
BUG-AGL: SPEC-2329
Change-Id: I14867e05e02b4c4c0389108c335fec2d2aa27495
Signed-off-by: Jonathan Aillet <jonathan.aillet@iot.bzh>
Diffstat (limited to 'src/4a-internals-hal/4a-internals-hal-api-loader.c')
-rw-r--r-- | src/4a-internals-hal/4a-internals-hal-api-loader.c | 34 |
1 files changed, 21 insertions, 13 deletions
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 94891b8..d70019e 100644 --- a/src/4a-internals-hal/4a-internals-hal-api-loader.c +++ b/src/4a-internals-hal/4a-internals-hal-api-loader.c @@ -82,7 +82,8 @@ static int InternalHalInitOneApi(afb_api_t apiHandle) AFB_default = apiHandle; // Retrieve section config from api handle - if(! (ctrlConfig = (CtlConfigT *) afb_api_get_userdata(apiHandle))) + ctrlConfig = (CtlConfigT *) afb_api_get_userdata(apiHandle); + if(! ctrlConfig) return -2; currentHalData = (struct HalData *) getExternalData(ctrlConfig); @@ -135,15 +136,18 @@ static int InternalHalLoadOneApi(void *cbdata, afb_api_t apiHandle) // Add static controls verbs if(HalUtlLoadVerbs(apiHandle, InternalHalApiStaticVerbs)) { AFB_API_ERROR(apiHandle, "Load Section : fail to register static V2 verbs"); - return 1; + return -2; } ctrlCurrentSections = malloc(sizeof(ctrlSectionsDefault)); memcpy(ctrlCurrentSections, ctrlSectionsDefault, sizeof(ctrlSectionsDefault)); // Load section for corresponding Api - if((err = CtlLoadSections(apiHandle, ctrlConfig, ctrlCurrentSections))) - return err; + err = CtlLoadSections(apiHandle, ctrlConfig, ctrlCurrentSections); + if(err) { + AFB_API_ERROR(apiHandle, "Didn't succeed to load current internal hal controller section"); + return -4; + } // Declare an event manager for this Api afb_api_on_event(apiHandle, InternalHalDispatchApiEvent); @@ -165,19 +169,21 @@ int InternalHalCreateApi(afb_api_t apiHandle, char *path, struct HalMgrData *hal // Create one Api per file ctrlConfig = CtlLoadMetaData(apiHandle, path); if(! ctrlConfig) { - AFB_API_ERROR(apiHandle, "No valid control config file in:\n-- %s", path); + AFB_API_ERROR(apiHandle, "No valid internal hal config file in : '%s'", path); return -2; } if(! ctrlConfig->api) { - AFB_API_ERROR(apiHandle, "API Missing from metadata in:\n-- %s", path); + AFB_API_ERROR(apiHandle, "API Missing from metadata in : '%s'", path); return -3; } - // Allocation of current hal controller data + // Allocation of current internal hal data currentHalData = HalUtlAddHalToHalList(&halMgrData->halDataList); - if(! currentHalData) + if(! currentHalData) { + AFB_API_ERROR(apiHandle, "Didn't succeed to add hal to hal list"); return -4; + } currentHalData->apiName = (char *) ctrlConfig->api; @@ -188,15 +194,17 @@ int InternalHalCreateApi(afb_api_t apiHandle, char *path, struct HalMgrData *hal currentHalData->internalHalData = calloc(1, sizeof(struct InternalHalData)); // Create one API - if(! afb_api_new_api(apiHandle, ctrlConfig->api, ctrlConfig->info, 1, InternalHalLoadOneApi, ctrlConfig)) - return -5; + if(! afb_api_new_api(apiHandle, ctrlConfig->api, ctrlConfig->info, 1, InternalHalLoadOneApi, ctrlConfig)) { + AFB_API_ERROR(apiHandle, "An error occurred at '%s' internal hal api creation", ctrlConfig->api); + return -6; + } return 0; } int InternalHalCreateAllApi(afb_api_t apiHandle, struct HalMgrData *halMgrData) { - int index, status = 0; + int index; char *dirList, *fileName, *fullPath; char filePath[CONTROL_MAXPATH_LEN]; @@ -236,8 +244,8 @@ int InternalHalCreateAllApi(afb_api_t apiHandle, struct HalMgrData *halMgrData) strncat(filePath, fileName, sizeof(filePath) - 1); if(InternalHalCreateApi(apiHandle, filePath, halMgrData) < 0) - status--; + return -3; } - return status; + return 0; }
\ No newline at end of file |