Bindings V2: reintroduce field 'info' for verbs
authorJosé Bollo <jose.bollo@iot.bzh>
Wed, 28 Jun 2017 13:51:54 +0000 (15:51 +0200)
committerJosé Bollo <jose.bollo@iot.bzh>
Wed, 28 Jun 2017 16:34:49 +0000 (18:34 +0200)
CAUTION, this breaks binary compatibility

Change-Id: I67acfffe1f04cdddee0ad1230b227b080da1ab06
Signed-off-by: José Bollo <jose.bollo@iot.bzh>
bindings/samples/HelloWorld.c
bindings/samples/tic-tac-toe.c
include/afb/afb-binding-v2.h
src/afb-api-so-v1.c
src/afb-api-so-v2.c
src/genskel/genskel.c
src/monitor-api.inc

index 0f58a43..77de24a 100644 (file)
@@ -411,25 +411,25 @@ static void onevent(const char *event, struct json_object *object)
 // NOTE: this sample does not use session to keep test a basic as possible
 //       in real application most APIs should be protected with AFB_SESSION_CHECK
 static const afb_verb_v2 verbs[]= {
-  { "ping"     ,    pingSample , NULL, AFB_SESSION_NONE },
-  { "pingfail" ,    pingFail   , NULL, AFB_SESSION_NONE },
-  { "pingnull" ,    pingNull   , NULL, AFB_SESSION_NONE },
-  { "pingbug"  ,    pingBug    , NULL, AFB_SESSION_NONE },
-  { "pingJson" ,    pingJson   , NULL, AFB_SESSION_NONE },
-  { "pingevent",    pingEvent  , NULL, AFB_SESSION_NONE },
-  { "subcall",      subcall    , NULL, AFB_SESSION_NONE },
-  { "subcallsync",  subcallsync, NULL, AFB_SESSION_NONE },
-  { "eventadd",     eventadd   , NULL, AFB_SESSION_NONE },
-  { "eventdel",     eventdel   , NULL, AFB_SESSION_NONE },
-  { "eventsub",     eventsub   , NULL, AFB_SESSION_NONE },
-  { "eventunsub",   eventunsub , NULL, AFB_SESSION_NONE },
-  { "eventpush",    eventpush  , NULL, AFB_SESSION_NONE },
-  { "call",         call       , NULL, AFB_SESSION_NONE },
-  { "callsync",     callsync   , NULL, AFB_SESSION_NONE },
-  { "verbose",      verbose    , NULL, AFB_SESSION_NONE },
-  { "broadcast",    broadcast  , NULL, AFB_SESSION_NONE },
-  { "exit",         exitnow    , NULL, AFB_SESSION_NONE },
-  { NULL}
+  { .verb="ping",        .callback=pingSample },
+  { .verb="pingfail",    .callback=pingFail },
+  { .verb="pingnull",    .callback=pingNull },
+  { .verb="pingbug",     .callback=pingBug },
+  { .verb="pingJson",    .callback=pingJson },
+  { .verb="pingevent",   .callback=pingEvent },
+  { .verb="subcall",     .callback=subcall },
+  { .verb="subcallsync", .callback=subcallsync },
+  { .verb="eventadd",    .callback=eventadd },
+  { .verb="eventdel",    .callback=eventdel },
+  { .verb="eventsub",    .callback=eventsub },
+  { .verb="eventunsub",  .callback=eventunsub },
+  { .verb="eventpush",   .callback=eventpush },
+  { .verb="call",        .callback=call },
+  { .verb="callsync",    .callback=callsync },
+  { .verb="verbose",     .callback=verbose },
+  { .verb="broadcast",   .callback=broadcast },
+  { .verb="exit",        .callback=exitnow },
+  { .verb=NULL}
 };
 
 const afb_binding_v2 afbBindingV2 = {
index 3cff9af..bf4904e 100644 (file)
@@ -564,16 +564,15 @@ static void wait(struct afb_req req)
  * array of the verbs exported to afb-daemon
  */
 static const struct afb_verb_v2 verbs[] = {
-   /* VERB'S NAME     SESSION MANAGEMENT          FUNCTION TO CALL  SHORT DESCRIPTION */
-   { "new",   new,   NULL, AFB_SESSION_NONE },
-   { "play",  play,  NULL, AFB_SESSION_NONE },
-   { "move",  move,  NULL, AFB_SESSION_NONE },
-   { "board", board, NULL, AFB_SESSION_NONE },
-   { "level", level, NULL, AFB_SESSION_NONE },
-   { "join",  join,  NULL, AFB_SESSION_NONE },
-   { "undo",  undo,  NULL, AFB_SESSION_NONE },
-   { "wait",  wait,  NULL, AFB_SESSION_NONE },
-   { NULL,    NULL,  NULL, AFB_SESSION_NONE } /* marker for end of the array */
+   { .verb="new",   .callback=new },
+   { .verb="play",  .callback=play },
+   { .verb="move",  .callback=move },
+   { .verb="board", .callback=board },
+   { .verb="level", .callback=level },
+   { .verb="join",  .callback=join },
+   { .verb="undo",  .callback=undo },
+   { .verb="wait",  .callback=wait },
+   { .verb=NULL }
 };
 
 /*
index e162aaa..8831a43 100644 (file)
@@ -36,9 +36,10 @@ struct json_object;
  */
 struct afb_verb_v2
 {
-       const char *verb;                       /* name of the verb */
+       const char *verb;                       /* name of the verb, NULL only at end of the array */
        void (*callback)(struct afb_req req);   /* callback function implementing the verb */
-       const struct afb_auth *auth;            /* required authorisation */
+       const struct afb_auth *auth;            /* required authorisation, can be NULL */
+       const char *info;                       /* some info about the verb, can be NULL */
        uint32_t session;                       /* authorisation and session requirements of the verb */
 };
 
@@ -48,7 +49,8 @@ struct afb_verb_v2
 struct afb_binding_v2
 {
        const char *api;                        /* api name for the binding */
-       const char *specification;              /* textual specification of the binding */
+       const char *specification;              /* textual specification of the binding, can be NULL */
+       const char *info;                       /* some info about the api, can be NULL */
        const struct afb_verb_v2 *verbs;        /* array of descriptions of verbs terminated by a NULL name */
        int (*preinit)();                       /* callback at load of the binding */
        int (*init)();                          /* callback for starting the service */
index 38f1b27..7e987c2 100644 (file)
@@ -183,8 +183,9 @@ static struct json_object *make_description_openAPIv3(struct api_so_v1 *desc)
 
        i = json_object_new_object();
        json_object_object_add(r, "info", i);
-       json_object_object_add(i, "title", json_object_new_string(desc->binding->v1.info));
+       json_object_object_add(i, "title", json_object_new_string(desc->binding->v1.prefix));
        json_object_object_add(i, "version", json_object_new_string("0.0.0"));
+       json_object_object_add(i, "description", json_object_new_string(desc->binding->v1.info ?: desc->binding->v1.prefix));
 
        p = json_object_new_object();
        json_object_object_add(r, "paths", p);
index 76bd233..bc5ecdf 100644 (file)
@@ -210,6 +210,7 @@ static struct json_object *make_description_openAPIv3(struct api_so_v2 *desc)
        json_object_object_add(r, "info", i);
        json_object_object_add(i, "title", json_object_new_string(desc->binding->api));
        json_object_object_add(i, "version", json_object_new_string("0.0.0"));
+       json_object_object_add(i, "description", json_object_new_string(desc->binding->info ?: desc->binding->api));
 
        p = json_object_new_object();
        json_object_object_add(r, "paths", p);
@@ -243,7 +244,7 @@ static struct json_object *make_description_openAPIv3(struct api_so_v2 *desc)
                json_object_object_add(g, "responses", a);
                f = json_object_new_object();
                json_object_object_add(a, "200", f);
-               json_object_object_add(f, "description", json_object_new_string(verb->verb));
+               json_object_object_add(f, "description", json_object_new_string(verb->info?:verb->verb));
                verb++;
        }
        return r;
index 8afb70b..d3d121f 100644 (file)
@@ -496,6 +496,7 @@ void print_struct_verb(const char *name, struct json_object *obj)
        printf(
                ",\n"
                "        .auth = %s,\n"
+               "        .info = NULL,\n"
                "        .session = "
                , p ? json_object_get_string(decl_perm(p)) : "NULL"
        );
@@ -624,6 +625,7 @@ void process(char *filename)
                "%sconst struct afb_binding_v2 %s%s = {\n"
                "    .api = \"%s\",\n"
                "    .specification = _afb_description_v2_%s,\n"
+               "    .info = NULL,\n"
                "    .verbs = _afb_verbs_v2_%s,\n"
                "    .preinit = %s,\n"
                "    .init = %s,\n"
index 30d1ede..e5fe5e5 100644 (file)
@@ -50,13 +50,15 @@ static const struct afb_verb_v2 _afb_verbs_v2_monitor[] = {
         .verb = "get",
         .callback = f_get,
         .auth = &_afb_auths_v2_monitor[2],
-        .session = 0,
+        .info = NULL,
+        .session = AFB_SESSION_NONE_V2
     },
     {
         .verb = "set",
         .callback = f_set,
         .auth = &_afb_auths_v2_monitor[0],
-        .session = 0,
+        .info = NULL,
+        .session = AFB_SESSION_NONE_V2
     },
     { .verb = NULL }
 };
@@ -64,9 +66,11 @@ static const struct afb_verb_v2 _afb_verbs_v2_monitor[] = {
 static const struct afb_binding_v2 _afb_binding_v2_monitor = {
     .api = "monitor",
     .specification = _afb_description_v2_monitor,
+    .info = NULL,
     .verbs = _afb_verbs_v2_monitor,
     .preinit = NULL,
     .init = NULL,
     .onevent = NULL,
+    .noconcurrency = 0
 };