aboutsummaryrefslogtreecommitdiffstats
path: root/src/mapis.c
diff options
context:
space:
mode:
authorRomain Forlot <romain.forlot@iot.bzh>2018-07-26 11:21:54 +0200
committerRomain Forlot <romain.forlot@iot.bzh>2018-08-02 16:50:49 +0200
commit121ac1676034f10454190638c2590014dff3941c (patch)
tree26853f42456b635d4accd190e8f7f3cef560fba7 /src/mapis.c
parent3487157e3c71f089d9ff4ff555a893f2cdb066a3 (diff)
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 <romain.forlot@iot.bzh>
Diffstat (limited to 'src/mapis.c')
-rw-r--r--src/mapis.c60
1 files changed, 30 insertions, 30 deletions
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;
- }
}
}