diff options
author | José Bollo <jose.bollo@iot.bzh> | 2017-05-22 16:37:28 +0200 |
---|---|---|
committer | José Bollo <jose.bollo@iot.bzh> | 2017-05-22 17:01:05 +0200 |
commit | 95c29ef579d6320a721f96d7146efd10f74a201b (patch) | |
tree | 2460427281fe724014033774a7786c857332cfb4 /src | |
parent | e9040472b72ff699964d89dda03ef07ce72b487b (diff) |
Bindings V2: Remove explicit references to daemon/service
Usage shown that managing daemon interface and service
interface wasn't obvious. This evolution hides the complexity
by setting up an internal hidden variable.
Change-Id: I667b1ee4e3a7b5ad29d712ee20ad5dd1878b97f3
Signed-off-by: José Bollo <jose.bollo@iot.bzh>
Diffstat (limited to 'src')
-rw-r--r-- | src/CMakeLists.txt | 1 | ||||
-rw-r--r-- | src/afb-api-so-v1.c | 33 | ||||
-rw-r--r-- | src/afb-api-so-v2.c | 143 | ||||
-rw-r--r-- | src/afb-api-so-v2.h | 3 | ||||
-rw-r--r-- | src/afb-api-so.c | 23 | ||||
-rw-r--r-- | src/afb-ditf.c | 28 | ||||
-rw-r--r-- | src/afb-ditf.h | 27 | ||||
-rw-r--r-- | src/afb-monitor.c | 11 | ||||
-rw-r--r-- | src/afb-svc.c | 67 | ||||
-rw-r--r-- | src/afb-svc.h | 8 | ||||
-rw-r--r-- | src/genskel/genskel.c | 8 | ||||
-rw-r--r-- | src/verbose.c | 2 |
12 files changed, 215 insertions, 139 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 0e39dc94..d253d388 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -118,7 +118,6 @@ TARGET_LINK_LIBRARIES(afb-daemon -ldl -lrt ) -link_directories( /opt/libmicrohttpd-0.9.54/lib/ ) INSTALL(TARGETS afb-daemon RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}) diff --git a/src/afb-api-so-v1.c b/src/afb-api-so-v1.c index c5f20b7f..c1f27093 100644 --- a/src/afb-api-so-v1.c +++ b/src/afb-api-so-v1.c @@ -24,7 +24,7 @@ #include <json-c/json.h> -#include <afb/afb-binding.h> +#include <afb/afb-binding-v1.h> #include "afb-api.h" #include "afb-api-so-v1.h" @@ -49,9 +49,10 @@ static const char afb_api_so_v1_service_event[] = "afbBindingV1ServiceEvent"; * Description of a binding */ struct api_so_v1 { - struct afb_binding *binding; /* descriptor */ + struct afb_binding_v1 *binding; /* descriptor */ void *handle; /* context of dlopen */ struct afb_svc *service; /* handler for service started */ + struct afb_binding_interface_v1 interface; struct afb_ditf ditf; /* daemon interface */ }; @@ -125,13 +126,13 @@ static void update_hooks_cb(void *closure) static int get_verbosity_cb(void *closure) { struct api_so_v1 *desc = closure; - return desc->ditf.interface.verbosity; + return desc->interface.verbosity; } static void set_verbosity_cb(void *closure, int level) { struct api_so_v1 *desc = closure; - desc->ditf.interface.verbosity = level; + desc->interface.verbosity = level; } struct json_object *describe_cb(void *closure) @@ -151,21 +152,21 @@ struct json_object *describe_cb(void *closure) a = json_object_new_array(); json_object_object_add(f, "name", json_object_new_string(verb->name)); json_object_object_add(f, "info", json_object_new_string(verb->info)); - if (verb->session & AFB_SESSION_CLOSE) + if (verb->session & AFB_SESSION_CLOSE_V1) json_object_array_add(a, json_object_new_string("session-close")); - if (verb->session & AFB_SESSION_RENEW) + if (verb->session & AFB_SESSION_RENEW_V1) json_object_array_add(a, json_object_new_string("session-renew")); - if (verb->session & AFB_SESSION_CHECK) + if (verb->session & AFB_SESSION_CHECK_V1) json_object_array_add(a, json_object_new_string("session-check")); - if (verb->session & AFB_SESSION_LOA_EQ) { + if (verb->session & AFB_SESSION_LOA_EQ_V1) { const char *rel = "?"; char buffer[80]; - switch (verb->session & AFB_SESSION_LOA_EQ) { - case AFB_SESSION_LOA_GE: rel = ">="; break; - case AFB_SESSION_LOA_LE: rel = "<="; break; - case AFB_SESSION_LOA_EQ: rel = "=="; break; + switch (verb->session & AFB_SESSION_LOA_EQ_V1) { + case AFB_SESSION_LOA_GE_V1: rel = ">="; break; + case AFB_SESSION_LOA_LE_V1: rel = "<="; break; + case AFB_SESSION_LOA_EQ_V1: rel = "=="; break; } - snprintf(buffer, sizeof buffer, "LOA%s%d", rel, (int)((verb->session >> AFB_SESSION_LOA_SHIFT) & AFB_SESSION_LOA_MASK)); + snprintf(buffer, sizeof buffer, "LOA%s%d", rel, (int)((verb->session >> AFB_SESSION_LOA_SHIFT_V1) & AFB_SESSION_LOA_MASK_V1)); json_object_array_add(a, json_object_new_string(buffer)); } json_object_object_add(f, "flags", a); @@ -187,7 +188,7 @@ static struct afb_api_itf so_v1_api_itf = { int afb_api_so_v1_add(const char *path, void *handle, struct afb_apiset *apiset) { struct api_so_v1 *desc; - struct afb_binding *(*register_function) (const struct afb_binding_interface *interface); + struct afb_binding_v1 *(*register_function) (const struct afb_binding_interface_v1 *interface); struct afb_api afb_api; /* retrieves the register function */ @@ -205,11 +206,11 @@ int afb_api_so_v1_add(const char *path, void *handle, struct afb_apiset *apiset) desc->handle = handle; /* init the interface */ - afb_ditf_init_v1(&desc->ditf, path); + afb_ditf_init_v1(&desc->ditf, path, &desc->interface); /* init the binding */ INFO("binding [%s] calling registering function %s", path, afb_api_so_v1_register); - desc->binding = register_function(&desc->ditf.interface); + desc->binding = register_function(&desc->interface); if (desc->binding == NULL) { ERROR("binding [%s] register function failed. continuing...", path); goto error2; diff --git a/src/afb-api-so-v2.c b/src/afb-api-so-v2.c index 6aa10cf5..8dadada5 100644 --- a/src/afb-api-so-v2.c +++ b/src/afb-api-so-v2.c @@ -22,7 +22,7 @@ #include <dlfcn.h> #include <assert.h> -#include <afb/afb-binding.h> +#include <afb/afb-binding-v2.h> #include <json-c/json.h> #include "afb-api.h" @@ -42,14 +42,14 @@ * names of symbols */ static const char afb_api_so_v2_descriptor[] = "afbBindingV2"; -static const char afb_api_so_v2_verbosity[] = "afbBindingV2verbosity"; +static const char afb_api_so_v2_data[] = "afbBindingV2data"; /* * Description of a binding */ struct api_so_v2 { const struct afb_binding_v2 *binding; /* descriptor */ - int *verbosity; /* verbosity */ + struct afb_binding_data_v2 *data; /* data */ void *handle; /* context of dlopen */ struct afb_svc *service; /* handler for service started */ struct afb_ditf ditf; /* daemon interface */ @@ -102,8 +102,8 @@ static void call_sync_cb(void *closure, struct afb_xreq *xreq) static int service_start_cb(void *closure, int share_session, int onneed, struct afb_apiset *apiset) { - int (*start)(struct afb_service service); - void (*onevent)(struct afb_service service, const char *event, struct json_object *object); + int (*start)(); + void (*onevent)(const char *event, struct json_object *object); struct api_so_v2 *desc = closure; @@ -120,7 +120,8 @@ static int service_start_cb(void *closure, int share_session, int onneed, struct /* get the initialisation */ start = desc->binding->init; - if (start == NULL) { + onevent = desc->binding->onevent; + if (start == NULL && onevent == NULL) { /* not an error when onneed */ if (onneed != 0) return 0; @@ -131,8 +132,7 @@ static int service_start_cb(void *closure, int share_session, int onneed, struct } /* get the event handler if any */ - onevent = desc->binding->onevent; - desc->service = afb_svc_create_v2(apiset, share_session, start, onevent, &desc->ditf); + desc->service = afb_svc_create_v2(apiset, share_session, start, onevent, desc->data); if (desc->service == NULL) { /* starting error */ ERROR("Starting service %s failed", desc->binding->api); @@ -151,19 +151,108 @@ static void update_hooks_cb(void *closure) static int get_verbosity_cb(void *closure) { struct api_so_v2 *desc = closure; - return *desc->verbosity; + return desc->data->verbosity; } static void set_verbosity_cb(void *closure, int level) { struct api_so_v2 *desc = closure; - *desc->verbosity = level; + desc->data->verbosity = level; +} + +static struct json_object *addperm(struct json_object *o, struct json_object *x) +{ + struct json_object *a; + + if (!o) + return x; + + if (!json_object_object_get_ex(o, "allOf", &a)) { + a = json_object_new_array(); + json_object_array_add(a, o); + o = json_object_new_object(); + json_object_object_add(o, "allOf", a); + } + json_object_array_add(a, x); + return o; +} + +static struct json_object *addperm_key_val(struct json_object *o, const char *key, struct json_object *val) +{ + struct json_object *x = json_object_new_object(); + json_object_object_add(x, key, val); + return addperm(o, x); +} + +static struct json_object *addperm_key_valstr(struct json_object *o, const char *key, const char *val) +{ + return addperm_key_val(o, key, json_object_new_string(val)); +} + +static struct json_object *addperm_key_valint(struct json_object *o, const char *key, int val) +{ + return addperm_key_val(o, key, json_object_new_int(val)); +} + +static struct json_object *make_description(struct api_so_v2 *desc) +{ + char buffer[256]; + const struct afb_verb_v2 *verb; + struct json_object *r, *f, *a, *i, *p, *g; + + r = json_object_new_object(); + json_object_object_add(r, "openapi", json_object_new_string("3.0.0")); + + i = json_object_new_object(); + 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")); + + p = json_object_new_object(); + json_object_object_add(r, "paths", p); + verb = desc->binding->verbs; + while (verb->verb) { + buffer[0] = '/'; + strncpy(buffer + 1, verb->verb, sizeof buffer - 1); + buffer[sizeof buffer - 1] = 0; + f = json_object_new_object(); + json_object_object_add(p, buffer, f); + g = json_object_new_object(); + json_object_object_add(f, "get", g); + + a = NULL; + if (verb->session & AFB_SESSION_CLOSE_V2) + a = addperm_key_valstr(a, "session", "close"); + if (verb->session & AFB_SESSION_CHECK_V2) + a = addperm_key_valstr(a, "session", "check"); + if (verb->session & AFB_SESSION_REFRESH_V2) + a = addperm_key_valstr(a, "token", "refresh"); + if (verb->session & AFB_SESSION_LOA_MASK_V2) + a = addperm_key_valint(a, "LOA", verb->session & AFB_SESSION_LOA_MASK_V2); +#if 0 + if (verb->auth) + a = +#endif + if (a) + json_object_object_add(g, "x-permissions", a); + + a = json_object_new_object(); + 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)); + verb++; + } + return r; } static struct json_object *describe_cb(void *closure) { struct api_so_v2 *desc = closure; - return desc->binding->specification ? json_tokener_parse(desc->binding->specification) : NULL; + struct json_object *r = desc->binding->specification ? json_tokener_parse(desc->binding->specification) : NULL; + if (!r) + r = make_description(desc); + return r; } static struct afb_api_itf so_v2_api_itf = { @@ -184,36 +273,37 @@ static struct afb_api_itf so_v2_sync_api_itf = { .describe = describe_cb }; -int afb_api_so_v2_add_binding(const struct afb_binding_v2 *binding, void *handle, struct afb_apiset *apiset, int *pver) +int afb_api_so_v2_add_binding(const struct afb_binding_v2 *binding, void *handle, struct afb_apiset *apiset, struct afb_binding_data_v2 *data) { int rc; struct api_so_v2 *desc; struct afb_api afb_api; /* basic checks */ + assert(binding); assert(binding->api); - assert(binding->specification); assert(binding->verbs); + assert(data); /* allocates the description */ - desc = malloc(sizeof *desc); + desc = calloc(1, sizeof *desc); if (desc == NULL) { ERROR("out of memory"); goto error; } desc->binding = binding; - desc->verbosity = pver; + desc->data = data; desc->handle = handle; desc->service = NULL; - memset(&desc->ditf, 0, sizeof desc->ditf); /* init the interface */ - afb_ditf_init_v2(&desc->ditf, binding->api); + desc->data->verbosity = verbosity; + afb_ditf_init_v2(&desc->ditf, binding->api, data); /* init the binding */ if (binding->preinit) { INFO("binding %s calling preinit function", binding->api); - rc = binding->preinit(desc->ditf.daemon); + rc = binding->preinit(); if (rc < 0) { ERROR("binding %s preinit function failed...", binding->api); goto error2; @@ -222,7 +312,7 @@ int afb_api_so_v2_add_binding(const struct afb_binding_v2 *binding, void *handle /* records the binding */ afb_api.closure = desc; - afb_api.itf = binding->concurrent ? &so_v2_api_itf : &so_v2_sync_api_itf; + afb_api.itf = binding->noconcurrency ? &so_v2_sync_api_itf : &so_v2_api_itf; if (afb_apiset_add(apiset, binding->api, afb_api) < 0) { ERROR("binding %s can't be registered to set %s...", binding->api, afb_apiset_name(apiset)); goto error2; @@ -239,19 +329,20 @@ error: int afb_api_so_v2_add(const char *path, void *handle, struct afb_apiset *apiset) { const struct afb_binding_v2 *binding; - int *pver; + struct afb_binding_data_v2 *data; /* retrieves the register function */ binding = dlsym(handle, afb_api_so_v2_descriptor); - pver = dlsym(handle, afb_api_so_v2_verbosity); - if (!binding && !pver) + data = dlsym(handle, afb_api_so_v2_data); + if (!binding && !data) return 0; INFO("binding [%s] looks like an AFB binding V2", path); /* basic checks */ - if (!binding || !pver) { - ERROR("binding [%s] incomplete symbols...", path); + if (!binding || !data) { + ERROR("binding [%s] incomplete symbol set: %s is missing", + path, binding ? afb_api_so_v2_data : afb_api_so_v2_descriptor); goto error; } if (binding->api == NULL || *binding->api == 0) { @@ -262,16 +353,18 @@ int afb_api_so_v2_add(const char *path, void *handle, struct afb_apiset *apiset) ERROR("binding [%s] invalid api name...", path); goto error; } +#if 0 if (binding->specification == NULL || *binding->specification == 0) { ERROR("binding [%s] bad specification...", path); goto error; } +#endif if (binding->verbs == NULL) { ERROR("binding [%s] no verbs...", path); goto error; } - return afb_api_so_v2_add_binding(binding, handle, apiset, pver); + return afb_api_so_v2_add_binding(binding, handle, apiset, data); error: return -1; diff --git a/src/afb-api-so-v2.h b/src/afb-api-so-v2.h index b60ebe66..82600fa4 100644 --- a/src/afb-api-so-v2.h +++ b/src/afb-api-so-v2.h @@ -20,6 +20,7 @@ struct afb_apiset; struct afb_binding_v2; +struct afb_binding_data_v2; extern int afb_api_so_v2_add(const char *path, void *handle, struct afb_apiset *apiset); -extern int afb_api_so_v2_add_binding(const struct afb_binding_v2 *binding, void *handle, struct afb_apiset *apiset, int *verbosity); +extern int afb_api_so_v2_add_binding(const struct afb_binding_v2 *binding, void *handle, struct afb_apiset *apiset, struct afb_binding_data_v2 *data); diff --git a/src/afb-api-so.c b/src/afb-api-so.c index b5da60f5..bee5fe80 100644 --- a/src/afb-api-so.c +++ b/src/afb-api-so.c @@ -45,26 +45,29 @@ static int load_binding(const char *path, int force, struct afb_apiset *apiset) goto error; } - /* retrieves the register function */ + /* try the version 2 */ rc = afb_api_so_v2_add(path, handle, apiset); if (rc < 0) { /* error when loading a valid v2 binding */ goto error2; } + if (rc) + return 0; /* yes version 2 */ + + /* try the version 1 */ rc = afb_api_so_v1_add(path, handle, apiset); if (rc < 0) { /* error when loading a valid v1 binding */ goto error2; } - if (rc == 0) { - /* not a v1 binding */ - if (force) - ERROR("binding [%s] is not an AFB binding", path); - else - INFO("binding [%s] is not an AFB binding", path); - goto error2; - } - return 0; + if (rc) + return 0; /* yes version 1 */ + + /* not a valid binding */ + if (force) + ERROR("binding [%s] is not an AFB binding", path); + else + INFO("binding [%s] is not an AFB binding", path); error2: dlclose(handle); diff --git a/src/afb-ditf.c b/src/afb-ditf.c index e6b6857c..474c58cf 100644 --- a/src/afb-ditf.c +++ b/src/afb-ditf.c @@ -16,14 +16,14 @@ */ #define _GNU_SOURCE -#define AFB_BINDING_PRAGMA_NO_VERBOSE_MACRO #include <string.h> #include <errno.h> #include <json-c/json.h> -#include <afb/afb-binding.h> +#include <afb/afb-binding-v1.h> +#include <afb/afb-binding-v2.h> #include "afb-ditf.h" #include "afb-evt.h" @@ -176,7 +176,8 @@ static int hooked_queue_job_cb(void *closure, void (*callback)(int signum, void } static const struct afb_daemon_itf daemon_itf = { - .vverbose = old_vverbose_cb, + .vverbose_v1 = old_vverbose_cb, + .vverbose_v2 = vverbose_cb, .event_make = event_make_cb, .event_broadcast = event_broadcast_cb, .get_event_loop = afb_common_get_event_loop, @@ -188,7 +189,8 @@ static const struct afb_daemon_itf daemon_itf = { }; static const struct afb_daemon_itf hooked_daemon_itf = { - .vverbose = hooked_old_vverbose_cb, + .vverbose_v1 = hooked_old_vverbose_cb, + .vverbose_v2 = hooked_vverbose_cb, .event_make = hooked_event_make_cb, .event_broadcast = hooked_event_broadcast_cb, .get_event_loop = hooked_get_event_loop, @@ -199,19 +201,21 @@ static const struct afb_daemon_itf hooked_daemon_itf = { .queue_job = hooked_queue_job_cb }; -void afb_ditf_init_v2(struct afb_ditf *ditf, const char *prefix) +void afb_ditf_init_v2(struct afb_ditf *ditf, const char *prefix, struct afb_binding_data_v2 *data) { ditf->version = 2; - ditf->daemon.closure = ditf; + ditf->v2 = data; + data->daemon.closure = ditf; afb_ditf_rename(ditf, prefix); } -void afb_ditf_init_v1(struct afb_ditf *ditf, const char *prefix) +void afb_ditf_init_v1(struct afb_ditf *ditf, const char *prefix, struct afb_binding_interface_v1 *itf) { ditf->version = 1; - ditf->interface.verbosity = verbosity; - ditf->interface.mode = AFB_MODE_LOCAL; - ditf->interface.daemon.closure = ditf; + ditf->v1 = itf; + itf->verbosity = verbosity; + itf->mode = AFB_MODE_LOCAL; + itf->daemon.closure = ditf; afb_ditf_rename(ditf, prefix); } @@ -226,11 +230,11 @@ void afb_ditf_update_hook(struct afb_ditf *ditf) int hooked = !!afb_hook_flags_ditf(ditf->prefix); switch (ditf->version) { case 1: - ditf->interface.daemon.itf = hooked ? &hooked_daemon_itf : &daemon_itf; + ditf->v1->daemon.itf = hooked ? &hooked_daemon_itf : &daemon_itf; break; default: case 2: - ditf->daemon.itf = hooked ? &hooked_daemon_itf : &daemon_itf; + ditf->v2->daemon.itf = hooked ? &hooked_daemon_itf : &daemon_itf; break; } } diff --git a/src/afb-ditf.h b/src/afb-ditf.h index 2af76d28..6bc84986 100644 --- a/src/afb-ditf.h +++ b/src/afb-ditf.h @@ -15,36 +15,23 @@ * limitations under the License. */ -#define _GNU_SOURCE -#define AFB_BINDING_PRAGMA_NO_VERBOSE_MACRO - -#include <string.h> -#include <dlfcn.h> -#include <assert.h> - -#include <afb/afb-binding.h> - -#include "afb-svc.h" -#include "afb-evt.h" -#include "afb-common.h" -#include "afb-context.h" -#include "afb-api-so.h" -#include "afb-xreq.h" -#include "verbose.h" +#pragma once +struct afb_binding_interface_v1; +struct afb_binding_data_v2; struct afb_ditf { int version; const char *prefix; union { - struct afb_binding_interface_v1 interface; - struct afb_daemon daemon; + struct afb_binding_interface_v1 *v1; + struct afb_binding_data_v2 *v2; }; }; -extern void afb_ditf_init_v1(struct afb_ditf *ditf, const char *prefix); -extern void afb_ditf_init_v2(struct afb_ditf *ditf, const char *prefix); +extern void afb_ditf_init_v1(struct afb_ditf *ditf, const char *prefix, struct afb_binding_interface_v1 *itf); +extern void afb_ditf_init_v2(struct afb_ditf *ditf, const char *prefix, struct afb_binding_data_v2 *data); extern void afb_ditf_rename(struct afb_ditf *ditf, const char *prefix); extern void afb_ditf_update_hook(struct afb_ditf *ditf); diff --git a/src/afb-monitor.c b/src/afb-monitor.c index a0618113..35d0e150 100644 --- a/src/afb-monitor.c +++ b/src/afb-monitor.c @@ -21,7 +21,7 @@ #include <string.h> #include <json-c/json.h> -#include <afb/afb-binding.h> +#include <afb/afb-binding-v2.h> #include "afb-api.h" #include "afb-apiset.h" @@ -34,10 +34,11 @@ extern struct afb_apiset *main_apiset; +static struct afb_binding_data_v2 datav2; + int afb_monitor_init() { - static int v; - return afb_api_so_v2_add_binding(&_afb_binding_v2_monitor, NULL, main_apiset, &v); + return afb_api_so_v2_add_binding(&_afb_binding_v2_monitor, NULL, main_apiset, &datav2); } /****************************************************************************** @@ -213,6 +214,8 @@ static void get_verbosity(struct json_object *resu, struct json_object *spec) n = json_object_array_length(spec); for (i = 0 ; i < n ; i++) get_verbosity_of(resu, json_object_get_string(json_object_array_get_idx(spec, i))); + } else if (json_object_is_type(spec, json_type_string)) { + get_verbosity_of(resu, json_object_get_string(spec)); } else if (json_object_get_boolean(spec)) { get_verbosity_of(resu, ""); get_verbosity_of(resu, "*"); @@ -274,6 +277,8 @@ static void get_apis(struct json_object *resu, struct json_object *spec) n = json_object_array_length(spec); for (i = 0 ; i < n ; i++) get_one_api(resu, json_object_get_string(json_object_array_get_idx(spec, i)), NULL); + } else if (json_object_is_type(spec, json_type_string)) { + get_one_api(resu, json_object_get_string(spec), NULL); } else if (json_object_get_boolean(spec)) { afb_apiset_enum(main_apiset, get_apis_of_all_cb, resu); } diff --git a/src/afb-svc.c b/src/afb-svc.c index 57173412..8976dc6c 100644 --- a/src/afb-svc.c +++ b/src/afb-svc.c @@ -22,8 +22,8 @@ #include <json-c/json.h> -#include <afb/afb-req-itf.h> -#include <afb/afb-service-itf.h> +#include <afb/afb-binding-v1.h> +#include <afb/afb-binding-v2.h> #include "afb-session.h" #include "afb-context.h" @@ -33,7 +33,6 @@ #include "afb-xreq.h" #include "afb-cred.h" #include "afb-apiset.h" -#include "afb-ditf.h" #include "verbose.h" /* @@ -51,13 +50,9 @@ struct afb_svc struct afb_evt_listener *listener; /* on event callback for the service */ - union { - void (*on_event_v1)(const char *event, struct json_object *object); - void (*on_event_v2)(struct afb_service service, const char *event, struct json_object *object); - }; + void (*on_event)(const char *event, struct json_object *object); - /* the daemon interface */ - struct afb_ditf *ditf; + struct afb_binding_data_v2 *v2; }; /* @@ -73,8 +68,7 @@ struct svc_req }; /* functions for services */ -static void svc_on_event_v1(void *closure, const char *event, int eventid, struct json_object *object); -static void svc_on_event_v2(void *closure, const char *event, int eventid, struct json_object *object); +static void svc_on_event(void *closure, const char *event, int eventid, struct json_object *object); static void svc_call(void *closure, const char *api, const char *verb, struct json_object *args, void (*callback)(void*, int, struct json_object*), void *cbclosure); @@ -84,13 +78,9 @@ static const struct afb_service_itf service_itf = { }; /* the interface for events */ -static const struct afb_evt_itf evt_itf_v1 = { - .broadcast = svc_on_event_v1, - .push = svc_on_event_v1 -}; -static const struct afb_evt_itf evt_itf_v2 = { - .broadcast = svc_on_event_v2, - .push = svc_on_event_v2 +static const struct afb_evt_itf evt_itf = { + .broadcast = svc_on_event, + .push = svc_on_event }; /* functions for requests of services */ @@ -192,8 +182,8 @@ struct afb_svc *afb_svc_create_v1( /* initialises the listener if needed */ if (on_event) { - svc->on_event_v1 = on_event; - svc->listener = afb_evt_listener_create(&evt_itf_v1, svc); + svc->on_event = on_event; + svc->listener = afb_evt_listener_create(&evt_itf, svc); if (svc->listener == NULL) goto error; } @@ -216,9 +206,9 @@ error: struct afb_svc *afb_svc_create_v2( struct afb_apiset *apiset, int share_session, - int (*start)(struct afb_service service), - void (*on_event)(struct afb_service service, const char *event, struct json_object *object), - struct afb_ditf *ditf + int (*start)(), + void (*on_event)(const char *event, struct json_object *object), + struct afb_binding_data_v2 *data ) { int rc; @@ -228,20 +218,23 @@ struct afb_svc *afb_svc_create_v2( svc = afb_svc_alloc(apiset, share_session); if (svc == NULL) goto error; - svc->ditf = ditf; + svc->v2 = data; + data->service = to_afb_service_v2(svc); /* initialises the listener if needed */ if (on_event) { - svc->on_event_v2 = on_event; - svc->listener = afb_evt_listener_create(&evt_itf_v2, svc); + svc->on_event = on_event; + svc->listener = afb_evt_listener_create(&evt_itf, svc); if (svc->listener == NULL) goto error; } - /* initialises the svc now */ - rc = start(to_afb_service_v2(svc)); - if (rc < 0) - goto error; + /* starts the svc if needed */ + if (start) { + rc = start(); + if (rc < 0) + goto error; + } return svc; @@ -253,20 +246,10 @@ error: /* * Propagates the event to the service */ -static void svc_on_event_v1(void *closure, const char *event, int eventid, struct json_object *object) -{ - struct afb_svc *svc = closure; - svc->on_event_v1(event, object); - json_object_put(object); -} - -/* - * Propagates the event to the service - */ -static void svc_on_event_v2(void *closure, const char *event, int eventid, struct json_object *object) +static void svc_on_event(void *closure, const char *event, int eventid, struct json_object *object) { struct afb_svc *svc = closure; - svc->on_event_v2(to_afb_service_v2(svc), event, object); + svc->on_event(event, object); json_object_put(object); } diff --git a/src/afb-svc.h b/src/afb-svc.h index 62b329df..347716d2 100644 --- a/src/afb-svc.h +++ b/src/afb-svc.h @@ -20,7 +20,7 @@ struct afb_svc; struct afb_service; struct afb_apiset; -struct afb_ditf; +struct afb_binding_data_v2; extern struct afb_svc *afb_svc_create_v1( struct afb_apiset *apiset, @@ -31,6 +31,6 @@ extern struct afb_svc *afb_svc_create_v1( extern struct afb_svc *afb_svc_create_v2( struct afb_apiset *apiset, int share_session, - int (*start)(struct afb_service service), - void (*on_event)(struct afb_service service, const char *event, struct json_object *object), - struct afb_ditf *ditf); + int (*start)(), + void (*on_event)(const char *event, struct json_object *object), + struct afb_binding_data_v2 *data); diff --git a/src/genskel/genskel.c b/src/genskel/genskel.c index 58f7a2c4..8afb70b6 100644 --- a/src/genskel/genskel.c +++ b/src/genskel/genskel.c @@ -72,7 +72,7 @@ const char *scope = NULL; const char *prefix = NULL; const char *postfix = NULL; int priv = -1; -int conc = -1; +int noconc = -1; /** * Search for a reference of type "#/a/b/c" int the @@ -594,7 +594,7 @@ void process(char *filename) 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); + getvarbool(&noconc, "#/info/x-binding-c-generator/noconcurrency", 0); getvar(&api, "#/info/title", "?"); /* get the API name */ @@ -628,7 +628,7 @@ void process(char *filename) " .preinit = %s,\n" " .init = %s,\n" " .onevent = %s,\n" - " .concurrent = %d\n" + " .noconcurrency = %d\n" "};\n" "\n" , priv ? "static " : "" @@ -640,7 +640,7 @@ void process(char *filename) , preinit ?: "NULL" , init ?: "NULL" , onevent ?: "NULL" - , !!conc + , !!noconc ); /* clean up */ diff --git a/src/verbose.c b/src/verbose.c index 88183c27..5b2611a7 100644 --- a/src/verbose.c +++ b/src/verbose.c @@ -99,7 +99,7 @@ void vverbose(int level, const char *file, int line, const char *function, const fprintf(stderr, "%s: ", prefixes[LEVEL(level)] + (tty ? 4 : 0)); vfprintf(stderr, fmt, args); - if (file != NULL && (!tty || verbosity >5)) + if (file != NULL && (!tty || verbosity > 2)) fprintf(stderr, " [%s:%d,%s]\n", file, line, function); else fprintf(stderr, "\n"); |