Bindings V2: rename init functions
authorJosé Bollo <jose.bollo@iot.bzh>
Fri, 19 May 2017 10:05:29 +0000 (12:05 +0200)
committerJosé Bollo <jose.bollo@iot.bzh>
Fri, 19 May 2017 21:04:44 +0000 (23:04 +0200)
The new naming is closer to the functionnal design
and closer to V1 names.

Change-Id: I8970338056a30564b84eaa1a7da6df3a9e6aa579
Signed-off-by: José Bollo <jose.bollo@iot.bzh>
include/afb/afb-binding-v2.h
src/afb-api-so-v2.c
src/genskel/genskel.c
src/genskel/monitor-api.json
src/monitor-api.inc

index b949a2d..91d6469 100644 (file)
@@ -57,8 +57,8 @@ struct afb_binding_v2
        const char *api;                        /* api name for the binding */
        const char *specification;              /* textual specification of the binding */
        const struct afb_verb_v2 *verbs;        /* array of descriptions of verbs terminated by a NULL name */
-       int (*init)(struct afb_daemon daemon);
-       int (*start)(struct afb_service service);
+       int (*preinit)(struct afb_daemon daemon);
+       int (*init)(struct afb_service service);
        void (*onevent)(struct afb_service service, const char *event, struct json_object *object);
        unsigned concurrent: 1;                 /* allows concurrent requests to verbs */
 };
index e076921..6aa10cf 100644 (file)
@@ -119,7 +119,7 @@ static int service_start_cb(void *closure, int share_session, int onneed, struct
        }
 
        /* get the initialisation */
-       start = desc->binding->start;
+       start = desc->binding->init;
        if (start == NULL) {
                /* not an error when onneed */
                if (onneed != 0)
@@ -211,11 +211,11 @@ int afb_api_so_v2_add_binding(const struct afb_binding_v2 *binding, void *handle
        afb_ditf_init_v2(&desc->ditf, binding->api);
 
        /* init the binding */
-       if (binding->init) {
-               INFO("binding %s calling init function", binding->api);
-               rc = binding->init(desc->ditf.daemon);
+       if (binding->preinit) {
+               INFO("binding %s calling preinit function", binding->api);
+               rc = binding->preinit(desc->ditf.daemon);
                if (rc < 0) {
-                       ERROR("binding %s initialisation function failed...", binding->api);
+                       ERROR("binding %s preinit function failed...", binding->api);
                        goto error2;
                }
        }
index 60f0e3b..58f7a2c 100644 (file)
@@ -64,14 +64,15 @@ struct path
 struct json_object *root = NULL;
 struct json_object *d_perms = NULL;
 struct json_object *a_perms = NULL;
+const char *preinit = NULL;
 const char *init = NULL;
-const char *start = NULL;
 const char *onevent = NULL;
 const char *api = NULL;
 const char *scope = NULL;
 const char *prefix = NULL;
 const char *postfix = NULL;
 int priv = -1;
+int conc = -1;
 
 /**
  * Search for a reference of type "#/a/b/c" int the
@@ -586,13 +587,14 @@ void process(char *filename)
 
        /* get some names */
        getvar(&api, "#/info/x-binding-c-generator/api", NULL);
+       getvar(&preinit, "#/info/x-binding-c-generator/preinit", NULL);
        getvar(&init, "#/info/x-binding-c-generator/init", NULL);
-       getvar(&start, "#/info/x-binding-c-generator/start", NULL);
        getvar(&onevent, "#/info/x-binding-c-generator/onevent", NULL);
        getvar(&scope, "#/info/x-binding-c-generator/scope", "static");
        getvar(&prefix, "#/info/x-binding-c-generator/prefix", "afb_verb_");
        getvar(&postfix, "#/info/x-binding-c-generator/postfix", "_cb");
        getvarbool(&priv, "#/info/x-binding-c-generator/private", 0);
+       getvarbool(&conc, "#/info/x-binding-c-generator/concurrent", 0);
        getvar(&api, "#/info/title", "?");
 
        /* get the API name */
@@ -623,9 +625,10 @@ void process(char *filename)
                "    .api = \"%s\",\n"
                "    .specification = _afb_description_v2_%s,\n"
                "    .verbs = _afb_verbs_v2_%s,\n"
+               "    .preinit = %s,\n"
                "    .init = %s,\n"
-               "    .start = %s,\n"
                "    .onevent = %s,\n"
+               "    .concurrent = %d\n"
                "};\n"
                "\n"
                , priv ? "static " : ""
@@ -634,9 +637,10 @@ void process(char *filename)
                , api
                , api
                , api
+               , preinit ?: "NULL"
                , init ?: "NULL"
-               , start ?: "NULL"
                , onevent ?: "NULL"
+               , !!conc
        );
 
        /* clean up */
index 34161cb..9b99843 100644 (file)
@@ -9,11 +9,11 @@
       "version": 2,
       "prefix": "f_",
       "postfix": "",
-      "start": null,
-      "onevent": null,
+      "preinit": null,
       "init": null,
+      "onevent": null,
       "scope": "static",
-      "private": true      
+      "private": true
     }
   },
   "servers": [
index 71c2a02..30d1ede 100644 (file)
@@ -65,8 +65,8 @@ static const struct afb_binding_v2 _afb_binding_v2_monitor = {
     .api = "monitor",
     .specification = _afb_description_v2_monitor,
     .verbs = _afb_verbs_v2_monitor,
+    .preinit = NULL,
     .init = NULL,
-    .start = NULL,
     .onevent = NULL,
 };