summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosé Bollo <jose.bollo@iot.bzh>2017-06-28 15:51:54 +0200
committerJosé Bollo <jose.bollo@iot.bzh>2017-06-28 18:34:49 +0200
commite48b6fb595d90509d70f850244fc962f8440a14b (patch)
treef59f6f218761538278de3cbab842904c8bc18138
parent305d98f7b6db1a3207cc877bd2cda819e3b90656 (diff)
Bindings V2: reintroduce field 'info' for verbs
CAUTION, this breaks binary compatibility Change-Id: I67acfffe1f04cdddee0ad1230b227b080da1ab06 Signed-off-by: José Bollo <jose.bollo@iot.bzh>
-rw-r--r--bindings/samples/HelloWorld.c38
-rw-r--r--bindings/samples/tic-tac-toe.c19
-rw-r--r--include/afb/afb-binding-v2.h8
-rw-r--r--src/afb-api-so-v1.c3
-rw-r--r--src/afb-api-so-v2.c3
-rw-r--r--src/genskel/genskel.c2
-rw-r--r--src/monitor-api.inc8
7 files changed, 45 insertions, 36 deletions
diff --git a/bindings/samples/HelloWorld.c b/bindings/samples/HelloWorld.c
index 0f58a43b..77de24a2 100644
--- a/bindings/samples/HelloWorld.c
+++ b/bindings/samples/HelloWorld.c
@@ -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 = {
diff --git a/bindings/samples/tic-tac-toe.c b/bindings/samples/tic-tac-toe.c
index 3cff9afc..bf4904ea 100644
--- a/bindings/samples/tic-tac-toe.c
+++ b/bindings/samples/tic-tac-toe.c
@@ -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 }
};
/*
diff --git a/include/afb/afb-binding-v2.h b/include/afb/afb-binding-v2.h
index e162aaa8..8831a434 100644
--- a/include/afb/afb-binding-v2.h
+++ b/include/afb/afb-binding-v2.h
@@ -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 */
diff --git a/src/afb-api-so-v1.c b/src/afb-api-so-v1.c
index 38f1b275..7e987c22 100644
--- a/src/afb-api-so-v1.c
+++ b/src/afb-api-so-v1.c
@@ -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);
diff --git a/src/afb-api-so-v2.c b/src/afb-api-so-v2.c
index 76bd233b..bc5ecdf7 100644
--- a/src/afb-api-so-v2.c
+++ b/src/afb-api-so-v2.c
@@ -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;
diff --git a/src/genskel/genskel.c b/src/genskel/genskel.c
index 8afb70b6..d3d121f1 100644
--- a/src/genskel/genskel.c
+++ b/src/genskel/genskel.c
@@ -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"
diff --git a/src/monitor-api.inc b/src/monitor-api.inc
index 30d1ede6..e5fe5e53 100644
--- a/src/monitor-api.inc
+++ b/src/monitor-api.inc
@@ -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
};