From 121ac1676034f10454190638c2590014dff3941c Mon Sep 17 00:00:00 2001 From: Romain Forlot Date: Thu, 26 Jul 2018 11:21:54 +0200 Subject: Some fixes Fix: No events defined in the mock apis Fix: new_api function has changed in binder Using the dynapi new_api function returned 0 in case of success and -1 on failure. New function since v3 returned NULL in case of failure or the api struct in case of success. Fix: wrong install_prefix variable used in CMake config file Fix: wrong variable used Typo after a copy/paste from event group handling. - Wrong use of table.insert - Wrong variable name used - only pass the data table, which is embed in another data table... - Fix aftereach and beforeeach function's call Change-Id: I9523ae50c170a3cdb9e5c3bc2b9e923c30f6ba39 Signed-off-by: Romain Forlot --- src/mapis.c | 60 ++++++++++++++++++++++++++++++------------------------------ 1 file changed, 30 insertions(+), 30 deletions(-) (limited to 'src') diff --git a/src/mapis.c b/src/mapis.c index 0c2a4aa..ba524a0 100644 --- a/src/mapis.c +++ b/src/mapis.c @@ -45,43 +45,45 @@ static int LoadOneMapi(void *data, AFB_ApiT apiHandle) { return -1; } - // Add actions to the section to be able to respond to defined events. - for(idx = 0; ctrlConfig->sections[idx].key != NULL; ++idx) { - if(! strcasecmp(ctrlConfig->sections[idx].key, "events")) { - savedActions = ctrlConfig->sections[idx].actions; - break; + if(mapisHandle->eventsJ) { + // Add actions to the section to be able to respond to defined events. + for(idx = 0; ctrlConfig->sections[idx].key != NULL; ++idx) { + if(! strcasecmp(ctrlConfig->sections[idx].key, "events")) { + savedActions = ctrlConfig->sections[idx].actions; + break; + } } - } - newActions = ActionConfig(apiHandle, mapisHandle->eventsJ, 0); + newActions = ActionConfig(apiHandle, mapisHandle->eventsJ, 0); - if(savedActions) { - while(savedActions[savedCount].uid != NULL) - savedCount++; - } + if(savedActions) { + while(savedActions[savedCount].uid != NULL) + savedCount++; + } + + while(newActions[count].uid != NULL) + count++; - while(newActions[count].uid != NULL) - count++; + int total = savedCount + count; + count = 0; + savedCount = 0; + CtlActionT * mergedActions = calloc(total + 1, sizeof(CtlActionT)); - int total = savedCount + count; - count = 0; - savedCount = 0; - CtlActionT * mergedActions = calloc(total + 1, sizeof(CtlActionT)); + if(savedActions) { + while(savedActions[count].uid != NULL) { + mergedActions[count] = savedActions[count]; + count++; + } + } - if(savedActions) { - while(savedActions[count].uid != NULL) { - mergedActions[count] = savedActions[count]; + while(newActions[savedCount].uid != NULL && count <= total) { + mergedActions[count] = newActions[savedCount]; count++; + savedCount++; } - } - while(newActions[savedCount].uid != NULL && count <= total) { - mergedActions[count] = newActions[savedCount]; - count++; - savedCount++; + ctrlConfig->sections[idx].actions = mergedActions; } - ctrlConfig->sections[idx].actions = mergedActions; - // declare an event event manager for this API; afb_api_on_event(apiHandle, CtrlDispatchApiEvent); @@ -112,10 +114,8 @@ static void OneMapiConfig(void *data, json_object *mapiJ) { json_object_object_del(mapiJ, "events"); mapisHandle->mapiJ = mapiJ; - if (afb_api_new_api(mapisHandle->mainApiHandle, uid, info, 1, LoadOneMapi, (void*)mapisHandle)) { + if (!afb_api_new_api(mapisHandle->mainApiHandle, uid, info, 1, LoadOneMapi, (void*)mapisHandle)) AFB_ApiError(mapisHandle->mainApiHandle, "Error creating new api: %s", uid); - return; - } } } -- cgit 1.2.3-korg