diff options
author | José Bollo <jose.bollo@iot.bzh> | 2018-07-13 16:38:55 +0200 |
---|---|---|
committer | Jose Bollo <jose.bollo@iot.bzh> | 2018-07-16 17:09:23 +0200 |
commit | bebb8fa967f3b71b609119b293d2869d56036586 (patch) | |
tree | 213e124303fe9cec424283839d728d896da3cae0 /src/afb-export.c | |
parent | 2ab7061438040c68346124268ecf4081c835cbf2 (diff) |
Simplify starting of services
The previous version was confusing and was expecting
that onneed and share_session were always true.
Removing this parameter simplifies the code.
Also handle errors of required classes and apis at initialisation.
Change-Id: I7c99aa356cba41f368bd47cab797fa086a5740af
Signed-off-by: José Bollo <jose.bollo@iot.bzh>
Diffstat (limited to 'src/afb-export.c')
-rw-r--r-- | src/afb-export.c | 29 |
1 files changed, 11 insertions, 18 deletions
diff --git a/src/afb-export.c b/src/afb-export.c index 315cc950..799ad73e 100644 --- a/src/afb-export.c +++ b/src/afb-export.c @@ -1552,29 +1552,23 @@ static void do_init(int sig, void *closure) }; -int afb_export_start(struct afb_export *export, int share_session, int onneed) +int afb_export_start(struct afb_export *export) { struct init init; int rc; /* check state */ - if (export->state != Api_State_Pre_Init) { - /* not an error when onneed */ - if (onneed != 0) - goto done; + switch (export->state) { + case Api_State_Run: + return 0; - /* already started: it is an error */ - ERROR("Service of API %s already started", export->api.apiname); + case Api_State_Init: + /* starting in progress: it is an error */ + ERROR("Service of API %s required started while starting", export->api.apiname); return -1; - } - /* unshare the session if asked */ - if (!share_session) { - rc = afb_export_unshare_session(export); - if (rc < 0) { - ERROR("Can't unshare the session for %s", export->api.apiname); - return -1; - } + default: + break; } /* set event handling */ @@ -1616,7 +1610,6 @@ int afb_export_start(struct afb_export *export, int share_session, int onneed) return rc; } -done: return 0; } @@ -1668,11 +1661,11 @@ static struct json_object *api_describe_cb(void *closure) return result; } -static int api_service_start_cb(void *closure, int share_session, int onneed) +static int api_service_start_cb(void *closure) { struct afb_export *export = closure; - return afb_export_start(export, share_session, onneed); + return afb_export_start(export); } static void api_update_hooks_cb(void *closure) |