-struct call_sync
-{
- struct api_so_v2 *desc;
- struct afb_xreq *xreq;
-};
-
-static void call_sync_cb_cb(int signum, void *closure)
-{
- struct call_sync *cs = closure;
- if (!signum)
- call_cb(cs->desc, cs->xreq);
- else {
- if (!cs->xreq->replied)
- afb_xreq_fail(cs->xreq, "aborted", "internal error");
- }
-}
-
-static void call_sync_cb(void *closure, struct afb_xreq *xreq)
-{
- struct call_sync cs = { .desc = closure, .xreq = xreq };
-
- if (jobs_call(closure, 0, call_sync_cb_cb, &cs))
- call_cb(closure, xreq);
-}
-
-static int service_start_cb(void *closure, int share_session, int onneed, struct afb_apiset *apiset)
-{
- int (*start)();
- void (*onevent)(const char *event, struct json_object *object);
-
- struct api_so_v2 *desc = closure;
-
- /* check state */
- if (desc->service != NULL) {
- /* not an error when onneed */
- if (onneed != 0)
- return 0;
-
- /* already started: it is an error */
- ERROR("Service %s already started", desc->binding->api);
- return -1;
- }
-
- /* get the initialisation */
- start = desc->binding->init;
- onevent = desc->binding->onevent;
- if (start == NULL && onevent == NULL) {
- /* not an error when onneed */
- if (onneed != 0)
- return 0;
-
- /* no initialisation method */
- ERROR("Binding %s is not a service", desc->binding->api);
- return -1;
- }
-
- /* get the event handler if any */
- desc->service = afb_svc_create_v2(desc->binding->api, apiset, share_session, start, onevent, desc->data);
- if (desc->service == NULL) {
- /* starting error */
- ERROR("Starting service %s failed", desc->binding->api);
- return -1;
- }
-
- return 0;
-}
-
-static void update_hooks_cb(void *closure)
-{
- struct api_so_v2 *desc = closure;
- afb_ditf_update_hook(&desc->ditf);
-}
-
-static int get_verbosity_cb(void *closure)
-{
- struct api_so_v2 *desc = closure;
- return desc->data->verbosity;
-}
-
-static void set_verbosity_cb(void *closure, int level)
-{
- struct api_so_v2 *desc = closure;
- 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)