From bba4befcc57ff4eb106a01b416119da01accfcd1 Mon Sep 17 00:00:00 2001 From: Romain Forlot Date: Fri, 7 Sep 2018 10:10:38 +0200 Subject: Use controller new behavior that add objects Adding objects to events section using the controller function to create a mock-api. Change-Id: Ic538c02f08b2f4f3376ffa6e9b9ffcbef1592599 Signed-off-by: Romain Forlot --- app-controller-submodule | 2 +- src/mapis.c | 37 +++++-------------------------------- 2 files changed, 6 insertions(+), 33 deletions(-) diff --git a/app-controller-submodule b/app-controller-submodule index 82820f4..d6eb01e 160000 --- a/app-controller-submodule +++ b/app-controller-submodule @@ -1 +1 @@ -Subproject commit 82820f44b1307ef8c6e12a505f383037fdad9fcb +Subproject commit d6eb01e14f2340c950ff8476d7b112f91297aae2 diff --git a/src/mapis.c b/src/mapis.c index ba72857..e40f3aa 100644 --- a/src/mapis.c +++ b/src/mapis.c @@ -29,8 +29,7 @@ struct mapisHandleT { }; static int LoadOneMapi(void *data, AFB_ApiT apiHandle) { - int savedCount = 0, count = 0, idx = 0; - CtlActionT *savedActions = NULL, *newActions = NULL; + int idx = 0; struct mapisHandleT *mapisHandle = (struct mapisHandleT*)data; CtlConfigT *ctrlConfig = AFB_ApiGetUserData(mapisHandle->mainApiHandle); @@ -48,40 +47,14 @@ static int LoadOneMapi(void *data, AFB_ApiT apiHandle) { 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; + if(! strcasecmp(ctrlConfig->sections[idx].key, "events")) break; - } } - newActions = ActionConfig(apiHandle, mapisHandle->eventsJ, 0); - if(savedActions) { - while(savedActions[savedCount].uid != NULL) - savedCount++; + if( AddActionsToSection(apiHandle, &ctrlConfig->sections[idx], mapisHandle->eventsJ, 0) ) { + AFB_ApiError(apiHandle, "Wasn't able to add new events to %s", ctrlConfig->sections[idx].uid); + return -1; } - - while(newActions[count].uid != NULL) - count++; - - 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++; - } - } - - while(newActions[savedCount].uid != NULL && count <= total) { - mergedActions[count] = newActions[savedCount]; - count++; - savedCount++; - } - - ctrlConfig->sections[idx].actions = mergedActions; } // declare an event event manager for this API; -- cgit 1.2.3-korg